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


plus = False
minus = False
for a in A:
    if a > 0:
        plus = True
    elif a < 0:
        minus = True

ans = []


if plus == True and minus == True:
    max_a = max(A)
    min_a = min(A)
    max_idx = A.index(max_a)
    min_idx = A.index(min_a)
    
    if abs(max_a) >= abs(min_a):
        for i in range(N):
            A[i] += max_a
            ans.append([max_idx + 1, i + 1])
    
    else:
        for i in range(N):
            A[i] += min_a
            ans.append([min_idx + 1, i + 1])


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

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

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

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


plus = False
minus = False
for a in A:
    if a > 0:
        plus = True
    elif a < 0:
        minus = True

ans = []


if plus == True and minus == True:
    max_a = max(A)
    min_a = min(A)
    max_idx = A.index(max_a)
    min_idx = A.index(min_a)
    
    if abs(max_a) >= abs(min_a):
        for i in range(N):
            A[i] += max_a
            ans.append([max_idx + 1, i + 1])
    
    if abs(max_a) < abs(min_a):
        for i in range(N):
            A[i] += min_a
            ans.append([min_idx + 1, i + 1])



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

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

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

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

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


plus = False
minus = False
for a in A:
    if a > 0:
        plus = True
    elif a < 0:
        minus = True

ans = []


if plus == True and minus == True:
    max_a = max(A)
    min_a = min(A)
    max_idx = A.index(max_a)
    min_idx = A.index(min_a)
    
    if abs(max_a) >= abs(min_a):
        for i in range(N):
            A[i] += max_a
            ans.append([max_idx + 1, i + 1])
    
    if abs(max_a) < abs(min_a):
        for i in range(N):
            A[i] += min_a
            ans.append([min_idx + 1, i + 1])



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

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

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

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


plus = False
minus = False
for a in A:
    if a > 0:
        plus = True
    elif a < 0:
        minus = True

ans = []


if plus == True and minus == True:
    max_a = max(A)
    min_a = min(A)
    max_idx = A.index(max_a)
    min_idx = A.index(min_a)
    
    if abs(max_a) >= abs(min_a):
        for i in range(N):
            A[i] += max_a
            ans.append([max_idx + 1, i + 1])
    
    if abs(max_a) < abs(min_a):
        for i in range(N):
            A[i] += min_a
            ans.append([min_idx + 1, i + 1])



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

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

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

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


plus = False
minus = False
for a in A:
    if a > 0:
        plus = True
    elif a < 0:
        minus = True

ans = []


if plus == True and minus == True:
    max_a = max(A)
    min_a = min(A)
    max_idx = A.index(max_a)
    min_idx = A.index(min_a)
    
    if abs(max_a) >= abs(min_a):
        for i in range(N):
            A[i] += max_a
            ans.append([max_idx + 1, i + 1])
    
    if abs(max_a) < abs(min_a):
        for i in range(N):
            A[i] += min_a
            ans.append([min_idx + 1, i + 1])



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

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

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

Solution (Python):
n = int(input())
A = list(map(int, input().split()))
ans = []
maxa = max(A)
mina = min(A)
if abs(mina) > abs(maxa):
    for i in range(n)[:0:-1]:
        if A[i-1] > A[i]:
            while A[i-1] > A[i]:
                ma = min(A)
                argmina = A.index(ma)
                A[i-1] += ma
                ans.append((argmina+1, i-1+1))
else:
    for i in range(n-1):
        pa = A[i]
        aa = A[i+1]
        if pa > aa:
            while pa > A[i+1]:
                ma = max(A)
                argmaxa = A.index(ma)
                A[i+1] += ma
                ans.append((argmaxa+1, i+1+1))

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

Solution (Python):
n = int(input())
A = list(map(int, input().split()))
ans = []
maxa = max(A)
mina = min(A)
if abs(mina) > abs(maxa):
    for i in range(n)[:0:-1]:
        if A[i-1] > A[i]:
            while A[i-1] > A[i]:
                ma = min(A)
                argmina = A.index(ma)
                A[i-1] += ma
                ans.append((argmina+1, i-1+1))
else:
    for i in range(n-1):
        pa = A[i]
        aa = A[i+1]
        if pa > aa:
            while pa > A[i+1]:
                ma = max(A)
                argmaxa = A.index(ma)
                A[i+1] += ma
                ans.append((argmaxa+1, i+1+1))

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

Solution (Python):

import sys
sys.setrecursionlimit(10**6)

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

a_origin = a[:]

min_a = min(a)
min_a_index = a.index(min_a)
max_a = max(a)
max_a_index = a.index(max_a)

ans = []
if min_a < 0 and max_a > 0:

    if abs(min_a) > abs(max_a):
        a_new = []
        for i in range(len(a)):
            if a[i] > 0:
                a_new.append(a[i]+min_a)
                ans.append((min_a_index+1, i+1))
            else:
                a_new.append(a[i])
    else:
        a_new = []
        for i in range(len(a)):
            if a[i] < 0:
                a_new.append(a[i]+max_a)
                ans.append((max_a_index+1, i+1))
            else:
                a_new.append(a[i])

    
    
    a = a_new

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

if min_a >= 0 and max_a >= 0:
    a_new = [a[0]]
    for i in range(1, len(a)):
        a_new.append(a[i]+a_new[-1])
        ans.append((i-1+1, i+1))
elif min_a <= 0 and max_a <= 0:
    a_new = [a[-1]]
    for i in reversed(range(0, len(a)-1)):
        a_new.append(a[i]+a_new[-1])
        ans.append((i+1+1, i+1))
    a_new = list(reversed(a_new))



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

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
K = 0
t = 0
place = 0
for i in range(N):
    if abs(A[i]) > K:
        K = abs(A[i])
        place = i
        if A[i] >= 0:
            t = 0
        else:
            t = 1
print(2*N-2)
if t == 0:
    print(place+1, 2)
    print(place+1, 2)
    for i in range(2, N):
        print(i, i+1)
        print(i, i+1)
else:
    print(place+1, N-1)
    print(place+1, N-1)
    for i in range(N-2, 0, -1):
        print(i+1, i)
        print(i+1, i)

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

M = max(A)
m = min(A)
print(2*N-2)

if M+m >= 0:
  a = A.index(M)
  for i in range(N):
    if i != a:
      
      print(a+1, i+1)
  for i in range(N-1):
    
    print(i+1, i+2)
else:
  a = A.index(m)
  for i in range(N):
    if i != a:
      print(a+1, i+1)
  for i in range(N, 1, -1):
    print(i, i-1)

Solution (Python):

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

    amax = max(a)
    amin = min(a)
    OP = []
    if abs(amax) >= abs(amin):
        idx = a.index(amax) + 1
        OP += [(idx, i) for i in range(1,N+1)]
        OP += [(i, i+1) for i in range(1, N)]
    else:
        idx = a.index(amin) + 1
        OP += [(idx, i) for i in range(1,N+1)]
        OP += [(i+1, i) for i in reversed(range(1,N))]
    
    print(len(OP))
    for op in OP: print(*op)

main()

Solution (Python):
import sys
N = int(input())
a_ls = list(map(int, input().split()))

Maxabs = 0
indofmaxabs = -1
for i in range(N):
    if Maxabs < abs(a_ls[i]):
        Maxabs = abs(a_ls[i])
        indofmaxabs = i
if Maxabs == 0:
    print(0)
    sys.exit()

print(2*(N-1))

for i in range(N):
    if not i == indofmaxabs:
        print(indofmaxabs+1,i+1)


if a_ls[indofmaxabs] >= 0:
    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, = map(int, input().split())
minv = min(A)
maxv = max(A)
mini = A.index(minv)
maxi = A.index(maxv)

ans = []


def op(x, y):
    A[y] += A[x]
    ans.append([x, y])


if minv < 0 and maxv > 0:
    if abs(minv) <= maxv:
        for i in range(N):
            if A[i] < 0:
                op(maxi, i)
    else:
        for i in range(N):
            if A[i] > 0:
                op(mini, i)

minv = min(A)
maxv = max(A)
mini = A.index(minv)
maxi = A.index(maxv)

if maxv <= 0:
    op(mini, N-1)
    for i in range(N-2, -1, -1):
        op(i+1, i)
else:
    op(maxi, 0)
    for i in range(1, N):
        op(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()))

mina = min(A)
mini = A.index(mina)
maxa = max(A)
maxi = A.index(maxa)

if mina >= 0:
  print(N-1)
  for i in range(N-1):
    print("{} {}".format(i+1, i+2))
elif maxa < 0:
  print(N-1)
  for i in range(N-1):
    print("{} {}".format(N-i, N-i-1))
else:
  if -mina < maxa:
    print(2*N-1)
    for i in range(N):
      print("{} {}".format(maxi+1, i+1))
    for i in range(N-1):
      print("{} {}".format(i+1, i+2))
  else:
    print(2*N-1)
    for i in range(N):
      print("{} {}".format(mini+1, i+1))
    for i in range(N-1):
      print("{} {}".format(N-i, N-i-1))

Solution (Python):

import sys
from itertools import permutations 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N = int(readline())
A = list(map(int,readline().split()))

x = max(A)
x_ind = A.index(x)
y = min(A)
y_ind = A.index(y)

if x >= 0 and y >= 0:
    print(N-1)
    for i in range(1,N):
        print(i,i+1)
elif x <= 0 and y <= 0:
    print(N-1)
    for i in range(N-1,0,-1):
        print(i+1,i)
else:
    cnt = N-1
    ans = []
    if abs(x) >= abs(y):
        for i in range(N):
            if A[i] < 0:
                cnt += 1
                ans.append((x_ind+1,i+1))
        for i in range(1,N):
            ans.append((i,i+1))
    else:
        for i in range(N):
            if A[i] > 0:
                cnt += 1 
                ans.append((y_ind+1,i+1))
        for i in range(N-1,0,-1):
            ans.append((i+1,i))
    print(cnt)
    for x,y in ans: 
        print(x,y)

Solution (Python):
from numpy import *
N = int(input())
A = list(map(int,input().split()))
print(2*N-1)

if abs(max(A))<abs(min(A)):
  x = argmin(A)
  for n in range(N):
    print(x+1,n+1)
  for n in range(N-1):
    print(N-n,N-n-1)
else:
  x = argmax(A)
  for n in range(N):
    print(x+1,n+1)
  for n in range(N-1):
    print(n+1,n+2)

Solution (Python):
import bisect, copy

n = int(input())
a = list(map(int, input().split()))
b = copy.copy(a)
ans = []
num = 1
count = 0
while num != n:
    if max(a) < 0:
        break
    while a[num - 1] > a[num]:
        a2 = copy.copy(a)
        a2.sort()
        temp = a[num - 1] - a[num]
        temp2 = bisect.bisect_left(a2, temp)
        if temp2 == n:
            temp2 -= 1
        ans.append([a.index(a2[temp2]) + 1, num + 1])
        a[num] += a2[temp2]
        count += 1
        if count == n * 2 + 1:
            break
    num += 1
    if count == n * 2 + 1:
        break

ans2 = []
num = n - 2
count2 = 0
while num != -1:
    if min(b) > 0:
        break
    while b[num] > b[num + 1]:
        b2 = copy.copy(b)
        b2.sort()
        temp = b[num + 1] - b[num]
        temp2 = bisect.bisect_right(b2, temp)
        if temp2 == 0:
            temp2 += 1
        ans2.append([b.index(b2[temp2 - 1]) + 1, num + 1])
        b[num] += b2[temp2 - 1]
        count2 += 1
        if count2 == n * 2 + 1:
            break
    num -= 1
    if count2 == n * 2 + 1:
        break

if len(ans) == 0 and len(ans2) == 0:
    print(0)
elif len(ans) == 0:
    print(len(ans2))
    for i in ans2:
        print(i[0], i[1])
elif len(ans2) == 0:
    print(len(ans))
    for i in ans:
        print(i[0], i[1])
else:
    if len(ans) > len(ans2):
        print(len(ans2))
        for i in ans2:
            print(i[0], i[1])
    else:
        print(len(ans))
        for i in ans:
            print(i[0], i[1])

Solution (Python):
N = int(input())
A = [int(x) for x in input().split()]
maxA, minA = max(A), min(A)
if maxA >= abs(minA):
    OP = [(A.index(maxA)+1, i+1) for i in range(N)] + [(i, i+1) for i in range(1,N)]
else:
    OP = [(A.index(minA)+1, i+1) for i in range(N)] + [(i+1, i) for i in reversed(range(1,N))]
print(len(OP))
for op in OP: print(*op)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
print(2 * n - 2)
if abs(min(a)) <= abs(max(a)):
    x = a.index(max(a)) + 1
    for y in range(1, n + 1):
        if not x == y:
            print(x, y)
    for x in range(1, n):
        y = x + 1
        print(x, y)
else:
    x = a.index(min(a)) + 1
    for y in range(1, n + 1):
        if not x == y:
            print(x, y)
    for x in range(n, 1, -1):
        y = x - 1
        print(x, y)

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

M = max(A)
m = min(A)
for i, a in enumerate(A):
    if a == M:
        max_id = i
    if a == m:
        min_id = i

ans = []
if m >= 0:
    for i in range(n-1):
        ans.append((i+1, i+2))
elif M <= 0:
    for i in reversed(range(1, n)):
        ans.append((i+1, i))
else:
    if abs(M) >= abs(m):
        for i, a in enumerate(A):
            if a < 0:
                ans.append((max_id+1, i+1))
        for i in range(n-1):
            ans.append((i+1, i+2))
    else:
        for i, a in enumerate(A):
            if a > 0:
                ans.append((min_id+1, i+1))
        for i in reversed(range(1, n)):
            ans.append((i+1, i))
print(len(ans))
for i in range(len(ans)):
    print(*ans[i])

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

M = max(A)
m = min(A)
for i, a in enumerate(A):
    if a == M:
        max_id = i
    if a == m:
        min_id = i

ans = []
if m >= 0:
    for i in range(n-1):
        ans.append((i+1, i+2))
elif M <= 0:
    for i in reversed(range(1, n)):
        ans.append((i+1, i))
else:
    if abs(M) >= abs(m):
        for i, a in enumerate(A):
            if a < 0:
                ans.append((max_id+1, i+1))
        for i in range(n-1):
            ans.append((i+1, i+2))
    else:
        for i, a in enumerate(A):
            if a > 0:
                ans.append((min_id+1, i+1))
        for i in reversed(range(1, n)):
            ans.append((i+1, i))
print(len(ans))
for i in range(len(ans)):
    print(*ans[i])

Solution (Python):
N = int(input())
a = [0] + list(map(int,input().split()))

inde = 0
absmax = 0
for i in range(1,N+1,1):
    if absmax <= abs(a[i]):
        inde = i
        absmax = abs(a[i])

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

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

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

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

S = min(A)
L = max(A)

c = 0
B = []

if S == L:
    pass

elif S >= 0 and L > 0:
    for i in range(N-1):
        if A[i+1] >= A[i]:
            pass
        else:
            A[i+1] += A[i]
            c += 1
            B.append((i+1, i+2))

elif L <= 0 and S < 0:
    for i in range(N-1):
        if A[-i-2] <= A[-i-1]:
            pass
        else:
            A[-i-2] += A[-i-1]
            c += 1
            B.append((N-i, N-i-1))

else:
    if L >= -S:
        l = A.index(L)
        if A[0] < 0:
            A[0] += L
            c += 1
            B.append((l+1, 1))
        for i in range(N-1):
            if A[i+1] >= A[i]:
                pass
            else:
                if A[i+1] < 0:
                    A[i+1] += L
                    c += 1
                    B.append((l+1, i+2))
                A[i+1] += A[i]
                c += 1
                B.append((i+1, i+2))
                if i+1 == l:
                    L = A[l]
    else:
        s = A.index(S)
        if A[-1] > 0:
            A[-1] += S
            c += 1
            B.append((s+1, N))
        for i in range(N-1):
            if A[-i-2] <= A[-i-1]:
                pass
            else:
                if A[-i-2] > 0:
                    A[-i-2] += S
                    c += 1
                    B.append((s+1, N-i-1))
                A[-i-2] += A[-i-1]
                c += 1
                B.append((N-i, N-i-1))
                if -i-2 == s:
                    S = A[s]

if c == 0:
    print(c)
else:
    print(c)
    for i in range(c):
        print(B[i][0], B[i][1])

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

n,*a=map(int,read().split())
def output(x,y):
  
  print('{} {}'.format(x+1,y+1))
mx=max(a)
mxi=a.index(mx)
mn=min(a)
mni=a.index(mn)

print(2*n-1)
if abs(mx)>=abs(mn) and mx>=0:
  for i in range(n):
    if mxi!=i:
      output(mxi,i)
  output(mxi,mxi)
  for i in range(1,n):
    output(i-1,i)
elif abs(mx)<abs(mn) and mn<0:
  for i in range(n):
    if mni!=i:
      output(mni,i)
  output(mni,mni)
  for i in range(n-1,0,-1):
    output(i,i-1)

Solution (Python):

def f(n,ais):
	ma,mi = max(ais), min(ais)
	res = []
	if ma + mi > 0:
		j = [j for j in range(len(ais)) if ais[j] == ma][0]
		for i in range(len(ais)):
			if ais[i] != ma:
				ais[i] += ais[j]
				res.append([j+1,i+1])

		for i in range(1,len(ais)):
			if ais[i-1] > ais[i]:
				ais[i] += ais[i-1]
				res.append([i-1+1, i+1])
	else:
		j = [j for j in range(len(ais)) if ais[j] == mi][0]
		for i in range(len(ais)):
			if ais[i] != mi:
				ais[i] += ais[j]
				res.append([j+1, i+1])
		for i in range(len(ais)-1, 0, -1):
			if not(ais[i - 1] <= ais[i ]):
				ais[i-1] += ais[i]
				res.append([i+1, i-1+1])
	print len(res)
	for u,v in res:
		print u,v
f(int(raw_input()),map(int, raw_input().split()))

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

max_index = abs_a.index(max(abs_a))
max_value = a[max_index]
judge = True if max_value > 0 else False

ans = []
for i in range(n):
  if judge and a[i] < 0:
    a[i] += a[max_index]
    ans.append((max_index+1, i+1))
  if not judge and a[i] > 0:
    a[i] += a[max_index]
    ans.append((max_index+1, i+1))

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

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

Solution (Python):
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, *A = map(int, read().split())

    Amax, Amin = max(A), min(A)
    imax, imin = A.index(Amax), A.index(Amin)

    ans = []
    rev = False

    if Amax <= 0:
        rev = True
    elif Amax > 0 and Amin < 0:
        if Amax >= abs(Amin):
            for i in range(N):
                if A[i] < 0:
                    A[i] += Amax
                    ans.append((imax, i))
        else:
            rev = True
            for i in range(N):
                if A[i] > 0:
                    A[i] += Amin
                    ans.append((imin, i))

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

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

    return


if __name__ == '__main__':
    main()

Solution (Python):
def p_xy(x,y):
  ansl.append(f"{x} {y}")

n=int(input())
a=list(map(int,input().split()))
mina=min(a)
maxa=max(a)
powa= maxa if abs(mina)<abs(maxa) else mina
powa_i=a.index(powa)
ansl=[]
if powa<0:
  for i in range(n):
    if a[i]>0:
      p_xy(powa_i+1,i+1)
  for i in reversed(range(1,n)):
      p_xy(i+1,i)
else:
  for i in range(n):
    if a[i]<0:
      p_xy(powa_i+1,i+1)
  for i in range(1,n):
    p_xy(i,i+1)
print(len(ansl))
print("\n".join(ansl))

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
mina=min(a)
maxa=max(a)
powa= maxa if abs(mina)<abs(maxa) else mina
powa_i=a.index(powa)
ansl=[]
if powa<0:
  for i in range(n):
    if a[i]>=0:
      ansl.append(f"{powa_i+1} {i+1}")
  ansl.append(f"{powa_i+1} {n}")
  for i in reversed(range(1,n)):
    ansl.append(f"{i+1} {i}")
else:
  for i in range(n):
    if a[i]<=0:
      ansl.append(f"{powa_i+1} {i+1}")
  ansl.append(f"{powa_i+1} {1}")
  for i in range(1,n):
    ansl.append(f"{i} {i+1}")
print(len(ansl))
print("\n".join(ansl))

Solution (Python):
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  

N = I()
a = LI()
M,m = max(a),min(a)
b,c = a.index(M)+1,a.index(m)+1

if M > 0 and m < 0:  
    print(2*N-1)
    if M <= -m:
        for i in range(1,N+1):
            a[i-1] += m
            print(c,i)
    else:
        for i in range(1,N+1):
            a[i-1] += M
            print(b,i)
else:
    print(N-1)

if max(a) <= 0 :
    for i in range(N,1,-1):
        print(i,i-1)
else:
    for i in range(1,N):
        print(i,i+1)

Solution (Python):
N = int(input())
a = list(map(int, input().split()))
mina = min(a)
maxa = max(a)
if mina == maxa:
    print(0)
    exit()

sousa = 0
index = 0
if abs(mina) <= abs(maxa):
    sousa = maxa
    index = a.index(maxa)
else:
    sousa = mina
    index = a.index(mina)

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

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

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

ma=np.max(a)
pma=np.argmax(a)
mi=np.min(a)
pmi=np.argmin(a)
ans=[]

if ma*mi<0:
    if abs(ma)>abs(mi):
        for i in range(n):
            if i==pma:
                continue

            ans.append((pma+1,i+1))
            a[i]+=ma
        pos=1
    else:
        for i in range(n):
            if i==pmi:
                continue

            ans.append((pmi+1,i+1))
            a[i]+=mi
        pos=0
else:
    if ma>0:
        pos=1
    else:
        pos=0

if pos==1:
    for i in range(1,n):
        if a[i]>=a[i-1]:
            continue
        ans.append((i,i+1))
        a[i]+=a[i-1]
else:
    for i in range(n-2,-1,-1):
        if a[i+1]>=a[i]:
            continue
        ans.append((i+2,i+1))
        a[i]+=a[i+1]

print(len(ans))

for x,y in ans:
    print('{} {}'.format(x,y))

Solution (Python):
N=int(input())
a=[int(i) for i in input().split()]
M = max(a)
m = min(a)
print(2*N-1)
if abs(M) > abs(m):
  Mi = a.index(M)
  for i in range(N):
    print(Mi+1,i+1)
  for i in range(N-1):
    print(i+1,i+2)
else:
  mi = a.index(m)
  for i in range(N):
    print(mi+1,i+1)
  for i in range(N-1)[::-1]:
    print(i+2,i+1)

Solution (Python):
import sys
from collections import defaultdict
from heapq import *
def input(): return sys.stdin.readline().strip()


def main():
    n = int(input())
    A = list(map(int, input().split()))
    """
    すべて正の場合は簡単で、
        ai > a(i+1) <= a(i+2) <= ... <= aj > a(j+1) <= ...
    となっていたらa(i+1)~ajすべてにaiを加えればよい。

    実はすべて負の場合も同様で、上のようになっていたら
    ai~ajすべてにa(j+1)を加えればよい。

    「「部分問題が解けたのだから、一般の場合はここに帰着させる！！！」」
    すなわち正負が混ざっている場合は、Aの最大値もしくは最小値をすべての要素に
    足すことで、すべて正もしくはすべて負にすることができるので解けた。
    """
    M_idx, m_idx = 0, 0
    M, m = A[0], A[0]
    for i, a in enumerate(A):
        if a > M:
            M_idx, M = i, a
        if a < m:
            m_idx, m = i, a
    print(2 * n - 1)
    if M >= -m:
        for i in range(n): print(M_idx + 1, i + 1)
        for i in range(n - 1): print(i + 1, i + 2)
    else:
        for i in range(n): print(m_idx + 1, i + 1)
        for i in range(n, 1, -1): print(i, i - 1)
    



if __name__ == "__main__":
    main()

Solution (Python):
def solve1():
    for i in range(N-1):
        ans.append((i+1,i+2))
        A[i+1]+=A[i]
def solve2():
    for i in reversed(range(1,N)):
        ans.append((i+1,i))
        A[i-1]+=A[i]

N=int(input())
A=list(map(int,input().split()))
l=min(A);r=max(A)
wl=A.index(l);wr=A.index(r)

ans=[]
if l>=0:
    solve1()
elif r<0:
    solve2()
else:
    if abs(l)>abs(r):
        for i in range(N):
            if A[i]>0:
                ans.append((wl+1,i+1))
                A[i]+=l
        solve2()
    else:
        for i in range(N):
            if A[i]<0:
                ans.append((wr+1,i+1))
                A[i]+=r
        solve1()
print(len(ans))
for x,y in ans:
    print(x,y)

Solution (Python):
I = int(input())
L = list(map(int, input().split()))

print(2*I-1, flush=True)

m = 0
m_index = 0
for i, item in enumerate(L):
    if abs(item) > abs(m):
        m = item
        m_index = i

for i in range(I):
    print(m_index+1, i+1, flush=True)

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

Solution (Python):
import collections
def main():
    n = int(input())
    a=[int(i) for i in input().split()]
    res = []
    mina = min(a)
    maxa = max(a)
    min_ind,max_ind=0,0
    for i in range(n):
        if(a[i]==mina):
            min_ind = i+1
        if(a[i]==maxa):
            max_ind = i+1

    if(mina>=0):
        print(n-1)
        for i in range(n-1):
            print(i+1,i+2)
    elif(maxa<=0):
        print(n-1)
        for i in range(n-1):
            print(n-i,n-i-1)
    else:
        if(abs(mina)<=abs(maxa)):
            print(2*n-1)
            for i in range(n):
                print(max_ind,i+1)
            for i in range(n-1):
                print(i+1,i+2)
        else:
            print(2*n - 1)
            for i in range(n):
                print(min_ind,i+1)
            for i in range(n-1):
                print(n-i,n-i-1)

if __name__ == '__main__':
    main()

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

Solution (Python):

import io
import sys
import math

def format_multi_answer(lst):
    ans = ""
    ans += f"{len(lst)}\n"
    for y in lst:
        ans += f"{y[0]} {y[1]}\n"
    return ans

def is_condition_ok(lst):
    for i in range(len(lst)-1):
        if lst[i] > lst[i+1]:
            return False
    return True

def solve(n,a_lst):
    """
    D_2: 記述軽く、アルゴリズムやや悪い？バージョン
    """
    
    if is_condition_ok(a_lst):
        return 0

    
    i_max, a_max = -1,-1
    i_min, a_min = +1,+1
    for i in range(len(a_lst)):
        if a_max < a_lst[i]:
            a_max = a_lst[i]
            i_max = i
        if a_min > a_lst[i]:
            a_min = a_lst[i]
            i_min = i

    ans_lst = []
    if a_max >= 0 and a_max >= abs(a_min):
        
        if _DEB: logd(f"plus")
        for i in range(len(a_lst)):
            if a_lst[i] < 0:
                ans_lst.append([i_max+1,i+1])
        ans_lst.append([i_max+1,1])
        for i in range(len(a_lst)-1):
            ans_lst.append([i+1,i+2])
    else:
        
        if _DEB: logd(f"minus")
        for i in range(len(a_lst)):
            if a_lst[i] >= 0:
                ans_lst.append([i_min+1,i+1])
        ans_lst.append([i_min+1,len(a_lst)])
        for i in range(len(a_lst)-1,0,-1):
            ans_lst.append([i+1,i])

    return format_multi_answer(ans_lst)

def main():
    
    n = int(input())
    a_lst = list(map(int, input().split()))

    
    ans = str( solve(n,a_lst) ).strip()
    
    
    print(ans)
    return ans
        

_DEB = 0   

_INPUT = """\
2
-1 -3
"""
_EXPECTED = """\
2
2 3
3 3
"""

def logd(str):
    """usage:
    if _DEB: logd(f"{str}")
    """
    if _DEB: print(f"[deb] {str}")


if __name__ == "__main__":
    if _DEB:
        sys.stdin = io.StringIO(_INPUT)
        print("!! Debug Mode !!")

    ans = main()

    if _DEB:
        print()
        if _EXPECTED.strip() == ans.strip(): print("!! Success !!")
        else: print(f"!! Failed... !!\nANSWER:   {ans}\nExpected: {_EXPECTED}")