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):
import math
N = int(input())
a = list(map(int,input().split()))
if min(a) >= 0:
    print(N-1)
    for i in range(N-1):
        print((i+1),(i+2))
elif max(a) < 0:
    print(N-1)
    for i in range(N-1):
        print((N-i),(N-i-1))
else:
    if abs(max(a)) >= abs(min(a)):
        print(2*N-1)
        mindex = a.index(max(a))
        for i in range(N):
            print(mindex+1,i+1)
        for j in range(N-1):
            print((j+1),(j+2))
    else:
        print(2*N-1)
        mindex = a.index(min(a))
        for i in range(N):
            print(mindex+1,i+1)
        for j in range(N-1):
            print((N-j),(N-j-1))

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

op = []
maxa = -10**7
argmaxa = -1
for i in range(N):
    if a[i] > maxa:
        maxa = a[i]
        argmaxa = i

mina = 10**7
argmina = -1
for i in range(N):
    if a[i] < mina:
        mina = a[i]
        argmina = i

if mina >= 0:
    pass
elif maxa <= 0:
    pass
elif abs(maxa) > abs(mina):
    for i in range(N):
        a[i] += maxa
        op.append((argmaxa, i))
else:
    for i in range(N):
        a[i] += mina
        op.append((argmina, i))
if abs(maxa) > abs(mina):
    for i in range(N-1):
        a[i+1] += a[i]
        op.append((i, i+1))
else:
    for i in reversed(range(1, N)):
        a[i-1] += a[i]
        op.append((i, i-1))

print(len(op))
for elem in op:
    print(' '.join(map(lambda x: str(x+1), elem)))

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

Ans = []
maxA,minA,maxAi,minAi = A[0],A[0],0,0
for i in range(1,N):
    if A[i] > maxA:
        maxA = A[i]
        maxAi = i
    if A[i] < minA:
        minA = A[i]
        minAi = i

if abs(maxA) >= abs(minA):
    for i in range(N):
        if i != maxAi:
            Ans.append((maxAi,i))
    for i in range(N-1):
        Ans.append((i,i+1))
else:
    for i in range(N):
        if i != minAi:
            Ans.append((minAi,i))
    for i in range(N-1):
        Ans.append((N-1-i,N-1-i-1))

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

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

M, Mi = 0, 0
for i, a in enumerate(A):
    if abs(a) > abs(M):
        M = a
        Mi = i

ans = []
if M > 0:
    for i in range(N):
        ans.append((Mi, i))
        A[i] += A[Mi]

    for i in range(N - 1):
        if A[i] > A[i + 1]:
            ans.append((i, i + 1))
            A[i + 1] += A[i]

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

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

Solution (Python):


def main():
    N = int(input())
    a = [int(s) for s in input().split(' ')]

    result = []

    max_a = max(a)
    min_a = min(a)

    if 0 <= max_a + min_a:
        k = a.index(max_a)
        sk = str(k + 1) + ' '
        for i in range(N):
            if a[i] < 0:
                result.append(sk + str(i + 1))
        for i in range(1, N):
            result.append(str(i) + ' ' + str(i + 1))
    else:
        k = a.index(min_a)
        sk = str(k + 1) + ' '
        for i in range(N):
            if a[i] > 0:
                result.append(sk + str(i + 1))
        for i in range(N - 1, 0, -1):
            result.append(str(i + 1) + ' ' + str(i))

    print(len(result))
    for s in result:
        print(s)

if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
a = input().split()
a = [int(m) for m in a]
li = []
cnt = 0
if abs(min(a)) <= abs(max(a)):
    for i in range(1, n):
        while True:
            if a[i - 1] <= a[i]:
                break
            else:
                li.append([a.index(max(a)) + 1, i + 1])
                a[i] += max(a)
                cnt += 1

else:
    for i in range(1, n):
        while True:
            if a[-i] >= a[-i-1]:
                break
            else:
                li.append([a.index(min(a)) + 1, n - i])
                a[-i-1] += min(a)
                cnt += 1


print(cnt)
for i in range(cnt):
    print(li[i][0], li[i][1])

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

M, X, Xi = 0, 0, 1
for i, a in enumerate(A, start=1):
    if abs(a) > M:
        M = abs(a)
        X = a
        Xi = i

if X > 0:
    ans = []
    for i in range(N):
        A[i] += X
        ans.append((Xi, i + 1))

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

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

else:
    ans = []
    for i in range(N):
        A[i] += X
        ans.append((Xi, i + 1))

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

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

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

k = 0
if max(a) == min(a):
    print(0)
    exit()
elif max(a) * min(a) < 0:
    print((n - 1) * 2)
    if max(a) + min(a) >= 0:
        k = a.index(max(a)) + 1
    else:
        k = a.index(min(a)) + 1
    for i in range(1, n + 1):
        if i != k:
            print(k, i)
else:
    print(n - 1)
    if max(a) > 0:
        k = a.index(max(a)) + 1
    else:
        k = a.index(min(a)) + 1

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

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

a_abs = [abs(x) for x in a]
abs_max_index = a_abs.index(max(a_abs))
abs_max = a[abs_max_index]
print(2*N)
for i in range(N):
    print('{} {}'.format(abs_max_index+1,i+1))
if abs_max >= 0:
    print('{} {}'.format(abs_max_index+1,1))
    for i in range(1,N):
        print('{} {}'.format(i,i+1))
else:
    print('{} {}'.format(abs_max_index+1,N))
    for i in range(N-1):
        print('{} {}'.format(N-i,N-i-1))

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
rec = 0
ind = 0
mi = False
for i in range(N):
    if A[i] < 0 and abs(A[i]) > rec:
        rec = abs(A[i])
        ind = i
        mi = True
    elif A[i] > 0 and A[i] > rec:
        rec = A[i]
        ind = i
        mi = False

ans = []
if mi:
    for i in range(N):
        ans.append((ind + 1, i + 1))
    for i in range(N - 1, 0, -1):
        ans.append((i + 1, i))
else:
    for i in range(N):
        ans.append((ind + 1, i + 1))
    for i in range(1, N):
        ans.append((i, i + 1))

print(len(ans))
for i in ans:
    print(i[0], i[1])

Solution (Python):
import numpy as np
from collections import Counter

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

MIN = min(A)
MAX = max(A)

print(2 * N - 1)

if abs(MAX) > abs(MIN):
    index = np.argsort(A)[-1] + 1
    for i in range(1, N + 1):
        if i != index:
            print(index, i)
    print(index, index)
    for i in range(1, N):
        print(i, i + 1)
else:
    index = np.argsort(A)[0] + 1
    for i in range(1, N + 1):
        if i != index:
            print(index, i)
    print(index, index)
    for i in range(1, N)[::-1]:
        print(i + 1, i)

Solution (Python):
def getN():
    return int(input())

def getMN():
    a = input().split()
    b = [int(i) for i in a]
    return b[0],b[1]

def getlist():
    a = input().split()
    b = [int(i) for i in a]
    return b

n = getN()
nums = getlist()
ln = len(nums)
maxn, minn = max(nums), min(nums)
already = False

if minn >= 0:
    plus = True

if maxn < 0:
    plus = False

if maxn >= 0 and minn < 0:
    print(ln*2-1)
    already = True
    if abs(maxn) > abs(minn):
        source = nums.index(maxn)
        plus = True
    else:
        source = nums.index(minn)
        plus = False
    for i in range(len(nums)):
        print(source+1, i+1)

if not already:
    print(ln-1)

if plus:
    for i in range(ln-1):
        print(i+1, i+2)
else:
    for i in range(ln-1):
        print(ln-i, ln-i-1)

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

sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

n = ni()
a = list(li())

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

if nml < 0:
    for j in range(n,1,-1):
        print(j, j-1)
else:
    for j in range(1,n):
        print(j, j+1)

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

max_a = max(a)
min_a = min(a)
count = 0
ans = []
if abs(min_a) <= abs(max_a):
    max_i = 0
    for i in range(n):
        if a[i] == max_a:
            max_i = i
    for i in range(n):
        ans.append([max_i+1, i+1])
        count += 1
    for i in range(n-1):
        ans.append([i+1, i+2])
        count += 1
else:
    min_i = 0
    for i in range(n):
        if a[i] == min_a:
            min_i = i
    for i in range(n):
        ans.append([min_i+1, i+1])
        count += 1
    for i in range(n-1, 0, -1):
        ans.append([i+1, i])
        count += 1

print(count)
for i in ans:
    print(*i)

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


ABS=[abs(A[i]) for i in range(N)]

x=max(ABS)
ki=ABS.index(x)

ANSLIST=[]
for i in range(ki):
    ANSLIST.append((ki+1,i+1))

for j in range(ki+1,N):
    ANSLIST.append((ki+1,j+1))

if A[ki]>0:
    for i in range(N-1):
        ANSLIST.append((i+1,i+2))
elif A[ki]<0:
    for i in range(N-1,0,-1):
        ANSLIST.append((i+1,i))

print(len(ANSLIST))

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

Solution (Python):
import copy
N=int(input())
a=[int(i) for i in input().split()]
B=copy.deepcopy(a)
A=0
for i in range(N):
    if a[i] < 0:
        a[i]*=-1
    else:
        continue


q=0
absmax=max(a)
print(2*N-1)
for i in range(N):
    if max(a)==a[i]:
        q=i
        break
if B[q]>=0:
    for i in range(N):
        B[i]+=absmax
        print("{} {}".format(q+1,i+1))
    for j in range(1,N):
        print("{} {}".format(j,j+1))
else:
    for i in range(N):
        B[i]-=absmax
        print("{} {}".format(q+1,i+1))
    for j in range(1,N):
        print("{} {}".format(N-j+1,N-j))

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

print(2*n-1)

if abs(max(a))<abs(min(a)):
	x = a.index(min(a))
	for i in range(n):
		print(x+1,"",i+1)
	for i in range(n-1):
		print(n-i,"",n-i-1)
else:
	x =a. index(max(a))
	for i in range(n):
		print(x+1,"",i+1)
	for i in range(n-1):
		print(i+1,"",i+2)

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

mx_v = 0
mn_v = 0

for i in range(n):
    if aa[i] > mx_v:
        mx_v = aa[i]
        mx_i = i + 1
    if aa[i] < mn_v:
        mn_v = aa[i]
        mn_i = i + 1

ans = []

if abs(mx_v) >= abs(mn_v) and mx_v != 0:
    for i in range(n):
        if aa[i] < 0:
            ans.append((mx_i, i + 1))
    for i in range(1, n):
        ans.append((i, i + 1))

if abs(mx_v) < abs(mn_v):
    for i in range(n):
        if aa[i] > 0:
            ans.append((mn_i, i + 1))
    for i in range(n, 1, -1):
        ans.append((i, i - 1))

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

Solution (Python):
N=int(input())

arr = [0]+list(map(int,input().split()))

max_index = 0
max_ = 0
for i in range(N+1):
    if abs(arr[i]) >= max_:
        max_ = abs(arr[i])
        max_index = i

print(2*N-2)
for i in range(1,N+1):
    if i != max_index:
        print('{0} {1}'.format(max_index, i))

if arr[max_index] > 0:
    for i in range(1,N):
        print('{0} {1}'.format(i, i+1))
else:
    for i in range(N, 1,-1):
        print('{0} {1}'.format(i, i-1))

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

ans = []

a_min = 10**6+1
a_max = -(10**6+1)
for i in range(n):
    if a[i] > a_max:
        a_max = a[i]
        i_max = i
    if a[i] < a_min:
        a_min = a[i]
        i_min = i

if a_max > abs(a_min):
    for i in range(n):
        if a[i] < 0:
            a[i] += a_max
            ans.append(str(i_max+1)+' '+str(i+1))
    for i in range(1, n):
        a[i] += a[i-1]
        ans.append(str(i)+' '+str(i+1))
else:
    for i in range(n):
        if a[i] > 0:
            a[i] -= a_min
            ans.append(str(i_min+1)+' '+str(i+1))
    for i in range(n-2, -1, -1):
        a[i] += a[i+1]
        ans.append(str(i+2)+' '+str(i+1))

print(len(ans))
for i in range(len(ans)):
    print(ans[i])

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

def li(): return [int(x) for x in stdin.readline().split()]
def li_(): return [int(x)-1 for x in stdin.readline().split()]
def lf(): return [float(x) for x in stdin.readline().split()]
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(ns())
def nf(): return float(ns())

n = ni()
a = li()


amax = max(a)
amin = min(a)
key = 0
key_idx = 0

if abs(amax) >= abs(amin):
    key = amax
    key_idx = a.index(amax) + 1
else:
    key = amin
    key_idx = a.index(amin) + 1
    
anew = [ai + key for ai in a]

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

Solution (Python):
N = int(input())
A = [int(x) for x in input().split()]
cnt = 0
a_max = max(A + [0])
a_min = min(A + [0])
cnt = 0
S = []
if a_max + a_min >= 0:
  k = A.index(a_max)
  while A[0] < a_max:
    A[0] += a_max
    cnt += 1
    S += [[k + 1, 1]]
  for i in range(N - 1):
    while A[i + 1] < A[i]:
      A[i + 1] += A[i]
      cnt += 1
      S += [[i + 1, i + 2]]
else:
  k = A.index(a_min)
  while A[-1] > a_min:
    A[-1] += a_min
    cnt += 1
    S += [[k + 1, N]]
  for i in range(N - 1, 0, -1):
    while A[i - 1] > A[i]:
      A[i - 1] += A[i]
      cnt += 1
      S += [[i + 1, i]]
print(cnt)
for s in S:
  print(s[0], s[1])

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

a_min, a_max = float('inf'), -float('inf')
a_min_idx, a_max_idx = -1, -1

if min(a) == max(a):
    print(0)
    exit()

ascend = True
for i in range(N - 1):
    if a[i] < a_min:
        a_min = a[i]
        a_min_idx = i + 1
    elif a_max < a[i]:
        a_max = a[i]
        a_max_idx = i + 1
    if a[i+1] < a[i]:
        ascend = False
if ascend:
    print(0)
    exit()

count = 0
message = ''
if a_min < 0 and 0 < a_max:
    if abs(a_min) < abs(a_max):
        for i in range(N):
            if a[i] < a_max:
                a[i] += a_max
                count += 1
                message += '{} {}\n'.format(a_max_idx, i + 1)
    else:
        for i in range(N):
            if a_min < a[i]:
                a[i] += a_min
                count += 1
                message += '{} {}\n'.format(a_min_idx, i + 1)

if min(a) >= 0:
    for i in range(1, N+1):
        count += 1
        message += '{} {}\n'.format(i, min(i+1, N))
else:
    for i in range(N, 1, -1):
        count += 1
        message += '{} {}\n'.format(i, max(i-1, 1))
print(count)
print(message, end='')

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

M, m = max(seq), min(seq)
for i in range(N):
    if seq[i] == M:
        x = i
    if seq[i] == m:
        y = i
print(2 * N - 1)
if M + m >= 0:
    for i in range(N):
        print(x + 1, i + 1)
    for i in range(N - 1):
        print(i + 1, i + 2)
else:
    for i in range(N):
        print(y + 1, i + 1)
    for i in range(N - 1, 0, -1):
        print(i + 1, i)

Solution (Python):
import numpy as np
N = int(input())
seq = np.array(list(map(int, input().split())))

M, m, x, y = seq.max(), seq.min(), seq.argmax(), seq.argmin()
print(2 * N - 1)
if M + m >= 0:
    for i in range(N):
        print(x + 1, i + 1)
    for i in range(N - 1):
        print(i + 1, i + 2)
else:
    for i in range(N):
        print(y + 1, i + 1)
    for i in range(N - 1, 0, -1):
        print(i + 1, i)

Solution (Python):
import numpy as np
N = int(input())
seq = list(map(int, input().split()))

M, m = max(seq), min(seq)
for i in range(N):
    if seq[i] == M:
        x = i
    if seq[i] == m:
        y = i

print(2 * N - 2)

if M + m >= 0:
    for i in range(N - 1):
        seq[i + 1] += M
        print(x + 1, i + 2)
        if seq[i + 1] > M:
            M = seq[i + 1]
            x = i + 1
        seq[i + 1] += M
        print(x + 1, i + 2)
        if seq[i + 1] > M:
            M = seq[i + 1]
            x = i + 1
else:
    for i in range(N - 1, 0, -1):
        seq[i - 1] += m
        print(y + 1, i)
        if seq[i - 1] < m:
            m = seq[i - 1]
            y = i - 1
        seq[i - 1] += m
        print(y + 1, i)
        if seq[i - 1] < m:
            m = seq[i - 1]
            y = i - 1

Solution (Python):
n=int(input())
*l,=map(int,input().split())
a,b=max(l),min(l)
pa,pb=l.index(a),l.index(b)

print(2*n-1)
if abs(a)>=abs(b):
  for i in range(n):
    print(pa+1,i+1)
  for i in range(n-1):
    print(i+1,i+2)
else:
  for i in range(n):
    print(pb+1,i+1)
  for i in range(n-1):
    print(n-i,n-i-1)

Solution (Python):


from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


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

    m, m_idx = abs(A[0]), 0
    for i, a in enumerate(A):
        if abs(a) > m:
            m = abs(a)
            m_idx = i

    ans = []
    for i in range(N):
        A[i] += A[m_idx]
        ans.append((m_idx + 1, i + 1))

    if A[m_idx] >= 0:
        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 - 1 + 1))

    print(len(ans))
    for x in ans:
        print(*x)


if __name__ == '__main__':
    main()

Solution (Python):
def d_non_decreasing(N, A):
    a_max = max(A)
    a_argmax = A.index(a_max) + 1
    a_min = min(A)
    a_argmin = A.index(a_min) + 1  

    if abs(a_max) >= abs(a_min):
        plus_index = a_argmax
        cumsum_range = range(1, N)
        cumsum_direction = +1
    else:
        plus_index = a_argmin
        cumsum_range = range(N, 1, -1)
        cumsum_direction = -1

    ans = [str(2 * N - 1)]  
    for k in range(1, N + 1):
        ans.append('{} {}'.format(plus_index, k))  
    for k in cumsum_range:
        ans.append('{} {}'.format(k, k + cumsum_direction))  
    ans = '\n'.join(ans)
    return ans
  
N = int(input())
A = [int(i) for i in input().split()]
print(d_non_decreasing(N, A))

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

maxA = max(A)
minA = min(A)
argmax = -1
argmin = -1
print(2*N - 1)

for i in range(N):
  if maxA == A[i]:
    argmax = i
  if minA == A[i]:
    argmin = i

if abs(maxA) >= abs(minA):
  for i in range(N):
    print(argmax+1, i+1)
  for i in range(N-1):
    print(i+1,i+2)

else:
  for i in range(N):
    print(argmin+1, i+1)
  for i in range(N-1):
    print(N-i,N-1-i)

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

max_A = max(A)
min_A = min(A)


if min_A == max_A == 0:
    print(0)


elif min_A >= 0:
    print(N - 1)
    for i in range(N - 1):
        print(i + 1, i + 2)


elif max_A <= 0:
    print(N - 1)
    for i in range(N - 1)[::-1]:
        print(i + 2, i + 1)


else:
    print(2 * N - 1)
    if abs(max_A) >= abs(min_A):
        index = A.index(max_A)
        for i in range(N):
            print(index + 1, i + 1)
        for i in range(N - 1):
            print(i + 1, i + 2)
    else:
        index = A.index(min_A)
        for i in range(N):
            print(index + 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()))

adj = 0
path = []


if any([ai > 0 for ai in a]) and any([ai < 0 for ai in a]):
    
    
    if abs(max(a)) >= abs(min(a)):
        max_a = max(a)
        max_idx = a.index(max_a) + 1
        
        for i, ai in enumerate(a):
            if i+1 == max_idx:
                pass
            else:
                a[i] += max_a    
                path.append((max_idx, i+1))
                
        adj = n-1
    
    
    else:
        min_a = min(a)
        min_idx = a.index(min_a) + 1
        
        for i, ai in enumerate(a):
            if i+1 == min_idx:
                pass
            else:
                a[i] += min_a   
                path.append((min_idx, i+1))
            
        adj = n-1
        
        


if all([ai >= 0 for ai in a]):
    print(n-1 + adj)
    for i in range(1,n):
        path.append((i, i+1))
        
    for x,y in path:
        print(x,y)
        

elif all([ai <= 0 for ai in a]):
    print(n-1 + adj)
    for i in range(n,1,-1):
        path.append((i, i-1))
        
    for x,y in path:
        print(x,y)

Solution (Python):
import sys
import math
import collections
import itertools
import array
import inspect


sys.setrecursionlimit(10000)



def chkprint(*args):
    names = {
        id(v): k
        for k, v in inspect.currentframe().f_back.f_locals.items()
    }
    print(', '.join(
        names.get(id(arg), '???') + ' = ' + repr(arg) for arg in args))



def to_bin(x):
    return bin(x)[2:]


def li_input():
    return [int(_) for _ in input().split()]




dp = None

ans = []


def f_positive(N, A):
    global ans

    for i in range(len(A) - 1):
        ans.append((i, i + 1))


def f_negative(N, A):
    global ans

    for i in range(len(A) - 1, 0, -1):
        ans.append((i, i - 1))


def main():
    global ans

    N = int(input())
    A = li_input()

    if min(A) >= 0:
        f_positive(N, A)
    else:
        
        if abs(max(A)) >= abs(min(A)):
            maxi = A.index(max(A))
            maxv = max(A)

            for i in range(len(A)):
                A[i] += maxv
                ans.append((maxi, i))

            f_positive(N, A)
        else:
            mini = A.index(min(A))
            minv = min(A)

            for i in range(len(A)):
                A[i] += minv
                ans.append((mini, i))

            f_negative(N, A)

    print(len(ans))
    for a in ans:
        print(a[0] + 1, a[1] + 1)


main()

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

def op(x, y):
    print(x, y)
    A[y - 1] += A[x - 1]

mn, mx = min(A), max(A)
base = mx if abs(mn) < abs(mx) else mn
bi = A.index(base) + 1

print(N * 2 - 1)
for i in range(N):
    op(bi, i + 1)
if 0 < base:
    for i in range(1, N):
        op(i, i+1)
else:
    for i in range(N, 1, -1):
        op(i, i-1)

Solution (Python):
N, = map(int, raw_input().split())
a = map(int, raw_input().split())
mi = 0
ma = abs(a[0])
for i in range(1,N):
  if abs(a[i])>ma:
    ma = abs(a[i])
    mi = i
print 2*N
if a[mi]>=0:
  print mi+1, N
  print mi+1, N
  for i in range(N-1):
    print N, i+1
    print N, N
else:
  print mi+1, 1
  print mi+1, 1
  for i in range(N-1, 0, -1):
    print 1, i+1
    print 1, 1

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

mn, mx = min(A), max(A)

def op(x, y):
    print(x, y)
    print(x, y)
    A[y - 1] += A[x - 1]
    A[y - 1] += A[x - 1]

print(N * 2)
if abs(mn) < abs(mx):
    base = mx
    bi = A.index(base) + 1
    op(bi, 1)
    for i in range(N-1):
        op(i+1, i+2)
else:
    base = mn
    bi = A.index(base) + 1
    op(bi, N)
    for i in range(N, 1, -1):
        op(i, i-1)

Solution (Python):
from collections import defaultdict
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, input().split()))
def inpl_s(): return list(input().split())

N = int(input())
aa = inpl()
MAX = max(aa)
MIN = min(aa)
MAXind = aa.index(MAX)
MINind = aa.index(MIN)
ans_list = []

def calc_pl():
	global aa
	global ans_list

	for i in range(1,N):
		ba,na = aa[i-1],aa[i]
		if na >= ba:
			continue
		else:
			aa[i] += ba
			ans_list.append([i,i+1])

def calc_mn():
	global aa
	global ans_list

	for i in reversed(range(N-1)):
		ba,na = aa[i+1],aa[i]
		if na <= ba:
			continue
		else:
			aa[i] += ba
			ans_list.append([i+2,i+1])

if MIN<0 and 0<MAX:
	if abs(MIN) < abs(MAX):
		for i in range(N):
			if i == MAXind: continue
			ans_list.append([MAXind+1,i+1])
			aa[i] += MAX
		calc_pl()
	else:
		for i in range(N):
			if i == MINind: continue
			ans_list.append([MINind+1,i+1])
			aa[i] += MIN
		calc_mn()
elif 0 <= MIN:
	calc_pl()
elif MAX <= 0:
	calc_mn()

print(len(ans_list))
for azu,nyan in ans_list:
	print(azu,nyan)

Solution (Python):
n = int(input())
a = [int(i) for i in input().split()]
num,num2 = 0,0
for i in range(n):
	if abs(a[i])>abs(num): num,num2=a[i],i
print(2*n-2)
for i in range(n):
	if i!=num2: print(num2+1,i+1)
if num<0:
	for i in range(n-1,0,-1): print(i+1,i)
else:
	for i in range(n-1): print(i+1,i+2)

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

s = max(a)
t = min(a)

if s == t:
    print(0)
elif abs(s) > abs(t):
    ss = a.index(s)
    print(2*n-2)
    for i in range(0,n):
        if i != ss:
            print(str(ss+1) + ' ' + str(i+1))
    for i in range(1,n):
        print(str(i) + ' '+str(i+1))
else:
    tt = a.index(t)
    print(2*n-2)
    for i in range(n):
        if i != tt:
            print(str(tt+1) + ' ' + str(i+1))
    for i in range(1,n):
        print(str(n-i+1) + ' ' + str(n-i))

Solution (Python):
N = int(input())
a = list(map(int, input().split()))
max_a = max(a)
min_a = min(a)
print(2 * N - 1)
if abs(max_a) >= abs(min_a):
    for i in range(1, N + 1):
        print(a.index(max_a) + 1, i)
    for i in range(1, N):
        print(i, i + 1)
else:
    for i in range(1, N + 1):
        print(a.index(min_a) + 1, i)
    for i in range(N, 1, -1):
        print(i, i - 1)

Solution (Python):

import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul

sys.setrecursionlimit(10000)


def read_int():
    return int(input())


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


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


move = None
tx = None
ty = None


@mt
def slv(N, A):
    mx = max(A)
    mn = min(A)
    ans = []
    if abs(mx) > abs(mn):
        idx = A.index(mx)
        for i in range(N):
            if A[i] < 0:
                ans.append((idx, i))
                A[i] += mx
        for i in range(1, N):
            ans.append((i-1, i))
            A[i] += A[i-1]
    else:
        idx = A.index(mn)
        for i in range(N):
            if A[i] > 0:
                ans.append((idx, i))
                A[i] += mn
        for i in range(N-1, 0, -1):
            ans.append((i, i-1))
            A[i-1] += A[i]

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


def main():
    N = read_int()
    A = read_int_n()
    slv(N, A)


if __name__ == '__main__':
    main()

Solution (Python):
N = int(input())
a = list(map(int, input().split()))
ma = a.index(max(a))+1
mi = a.index(min(a))+1
print(2*N-1)

if (abs(max(a)) >= abs(min(a))):
    for i in range(1, N+1):
        print(str(ma) + " " + str(i))
    for i in range(1, N):
        print(str(i) + " " + str(i+1))
else:
    for i in range(1, N+1):
        print(str(mi) + " " + str(i))
    for i in reversed(range(2, N+1)):
        print(str(i) + " " + str(i-1))

Solution (Python):


N=int(input())
A=list(map(int,input().split()))
flug = False
kaizen=0

for i in range(1,N):
    if A[i-1]>A[i]:
        kaizen=i
        flug=True
        break
    
if flug==False:
    print(0)
    exit()

keisu=0
keisuichi=0
for i in range(N):
    if abs(A[i])>abs(keisu):
        keisu=A[i]
        keisuichi=i
if keisu>0:
    Ansx=[]
    Ansy=[]
    for i in range(N):
        Ansx.append(keisuichi)
        Ansy.append(i)
        Ansx.append(keisuichi)
        Ansy.append(i)
        A[i]=A[i]+A[keisuichi]*2
        keisuichi=i
        
        
    print(len(Ansx))
    for i in range(len(Ansx)):
        print(Ansx[i]+1,Ansy[i]+1)
    
else:
    Ansx=[]
    Ansy=[]
    for i in range(N):
        Ansx.append(keisuichi)
        Ansy.append(N-i)
        Ansx.append(keisuichi)
        Ansy.append(N-i)
        A[N-i-1]=A[N-i-1]+A[keisuichi]*2
        keisuichi=N-i-1
        
        
    print(len(Ansx))
    for i in range(len(Ansx)):
        print(Ansx[i]+1,Ansy[i])

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

min_A = min(A)
max_A = max(A)

if min_A == max_A:
    print(0)
elif max_A < 0:
    print(N - 1)
    for i in range(N - 1, 0, -1):
        print(i + 1, i)
elif min_A > 0:
    print(N - 1)
    for i in range(N - 1):
        print(i + 1, i + 2)
else:
    if abs(min_A) > max_A:
        index = A.index(min_A)
    else:
        index = A.index(max_A)

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

    if abs(min_A) > max_A:
        for i in range(N - 1, 0, -1):
            print(i + 1, i)
    else:
        for i in range(N - 1):
            print(i + 1, i + 2)