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

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

ma = max(l)
mi = min(l)

ans = []

if abs(ma) >= abs(mi):
    ind = l.index(ma)
    if ind != 0:
        ans.append([ind+1,1])
        ans.append([ind+1,1])
    for i in range(1,n):
        
        ans.append([i,i+1])
        ans.append([i,i+1])
else:
    ind = l.index(mi)
    if ind != n-1:
        ans.append([ind+1,n])
        ans.append([ind+1,n])
    for i in range(n-2,-1,-1):
        
        ans.append([i+2,i+1])
        ans.append([i+2,i+1])
print(len(ans))
for i in ans:
    print(*i)

Solution (Python):
def main():
    N = int(input())
    a = list(map(int, input().split()))
    l = []
    if abs(max(a)) >= abs(min(a)):
        i = a.index(max(a))
        t = max(a)
        for j in range(1, N+1):
            l.append((i+1, j))
        for i in range(N):
            a[i] += t
        for i in range(N-1):
            if True:
                l.append((i+1, i+2))
                a[i+1] = a[i] + a[i+1]
    else:
        i = a.index(min(a))
        t = min(a)
        for j in range(1, N+1):
            l.append((i+1,j))
        for i in range(N):
            a[i] += t
        for i in range(N-1, 0, -1):
            if True:
                l.append((i+1, i))
                a[i-1] = a[i] + a[i-1]
    print(len(l))
    for i in l:
        print(i[0], i[1])
main()

Solution (Python):
def main():
    N = int(input())
    A = list(map(int, input().split()))
    r = []
    ma, mi = max(A), min(A)
    if ma * mi < 0:
        if abs(mi) > abs(ma):
            ma = mi
        mi = A.index(ma)
        for i, a in enumerate(A):
            if ma * a < 0:
                r.append((mi, i))
                A[i] += ma

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

    print(len(r))
    for rx, ry in r:
        print(rx + 1, ry + 1)

main()

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

Solution (Python):
def main():
    N = int(input())
    a = list(map(int, input().split()))
    l = []
    if abs(max(a)) >= abs(min(a)):
        i = a.index(max(a))
        t = max(a)
        for j in range(1, N+1):
            l.append((i+1, j))
        for i in range(1, N):
            l.append((i, i+1))
    else:
        i = a.index(min(a))
        t = min(a)
        for j in range(1, N+1):
            l.append((i+1,j))
        for i in range(N-1, 0, -1):
            l.append((i+1, i))
    print(len(l))
    for i in l:
        print(i[0], i[1])
main()

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
MAX = max(A)
MIN = min(A)

print(2 * N - 1)

if MAX >= -1 * MIN:
    j = A.index(MAX)
    for i in range(N):
        print(*[j+1, i+1])
    for i in range(N-1):
        print(*[i+1, i+2])
else:
    j = A.index(MIN)
    for i in range(N):
        print(*[j+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()))

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-i-1)
elif abs(max(a))>abs(min(a)):
    print(2*n-1)
    b = a.index(max(a))
    for i in range(n):
        print(b+1,i+1)
    for i in range(1,n):
        print(i,i+1)
else:
    print(2*n-1)
    b = a.index(min(a))
    for i in range(n):
        print(b+1,i+1)
    for i in range(n-1):
        print(n-i,n-i-1)

Solution (Python):
N, *A = map(int, open(0).read().split())

v_max = max(A)
v_min = min(A)

flg1 = v_max > 0 and v_min >= 0
flg2 = v_max <= 0 and v_min <= 0
flg3 = v_max * v_min < 0 and abs(v_max) >= abs(v_min)
flg4 = v_max * v_min < 0 and abs(v_max) < abs(v_min)

s = sorted([(i + 1, v) for i, v in enumerate(A)], key=lambda x: x[1])
ans = []
if flg1 or flg3:
    if flg3:
        i_max = s[-1][0]
        for j in range(1, N + 1):
            ans.append((i_max, j))
            
    for j in range(1, N):
        ans.append((j, j + 1))
else:
    if flg4:
        i_min = s[0][0]
        for j in range(1, N + 1):
            ans.append((i_min, j))
            
    for j in reversed(range(1, N)):
        ans.append((j + 1, j))
        
print(len(ans))
for v in ans:
    print(*v)

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

n = int(input())
a = [int(x) for x in input().split()]
ans = []

max_a = [-float('inf'), 100]
min_a = [float('inf'), 100]

for i in range(n):
    if a[i] >= max_a[0]:
        max_a = [a[i], i]
    if a[i] <= min_a[0]:
        min_a = [a[i], i]

if abs(max_a[0]) >= abs(min_a[0]):
    for i in range(n):
        if i != max_a[1]:
            a[i] += max_a[0]
            ans.append([max_a[1], i])
    for i in range(1, n):
        if a[i] < a[i - 1]:
            a[i] += a[i - 1]
            ans.append([i - 1, i])
else:
    for i in range(n):
        if i != min_a[1]:
            a[i] += min_a[0]
            ans.append([min_a[1], i])
    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 i in ans:
    x, y = i
    print(x + 1, y + 1)

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

def isAsc(lst):
  for i in range(1,len(lst)):
    if lst[i-1]>lst[i]:
      return False
  else:
    return True

min_a=min(alist)
max_a=max(alist)

answer_list=[]
if max_a>0 and max_a>-min_a:
  while(not isAsc(alist)):
    desc_index=-1
    
    for i in range(1,N):
      if alist[i-1]>alist[i]:
        desc_index=i
        break
  
    max_a=-10**9
    max_index=-1
    for i in range(N):
      if alist[i]>max_a:
        max_a=alist[i]
        max_index=i    
      
    while(alist[desc_index-1]>alist[desc_index]):
      alist[desc_index]+=max_a
      answer_list.append((max_index+1,desc_index+1))
else:
  while(not isAsc(alist)):
    desc_index=-1
    
    for i in reversed(range(1,N)):
      if alist[i-1]>alist[i]:
        desc_index=i-1
        break
  
    min_a=10**9
    min_index=-1
    for i in range(N):
      if alist[i]<min_a:
        min_a=alist[i]
        min_index=i    
      
    while(alist[desc_index]>alist[desc_index+1]):
      alist[desc_index]+=min_a
      answer_list.append((min_index+1,desc_index+1))


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

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

ma = max(a)
mi = min(a)

num = 0
ans = []

if ma >= -mi:
    ind = a.index(ma)
    for i in range(1, n):
        while a[i-1] > a[i]:
            num += 1
            ans.append(str(ind+1) + ' ' + str(i+1))
            a[i] += ma
            if a[i] > ma:
                ma = a[i]
                ind = i

else:
    ind = a.index(mi)
    for i in range(n-2, -1, -1):
        while a[i] > a[i+1]:
            num += 1
            ans.append(str(ind+1) + ' ' + str(i+1))
            a[i] += mi
            if a[i] < mi:
                mi = a[i]
                ind = i

print(num)
for i in ans:
    print(i)

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

ma = max(a)
mi = min(a)

num = 0
ans = []

if ma >= -mi:
    ind = a.index(ma)
    for i in range(1, n):
        while a[i-1] > a[i]:
            num += 1
            ans.append(str(ind+1) + ' ' + str(i+1))
            a[i] += ma
            if a[i] > ma:
                ma = a[i]
                ind = i

else:
    ind = a.index(mi)
    for i in range(n-2, -1, -1):
        while a[i] > a[i+1]:
            num += 1
            ans.append(str(ind+1) + ' ' + str(i+1))
            a[i] += mi
            if a[i] < mi:
                mi = a[i]
                ind = i

print(num)
for i in ans:
    print(i)

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
amax = max(a)
amin = min(a)

print(2*n-1)
if amax > abs(amin):
    a_i = a.index(amax)
else:
    amax += amin
    a_i = a.index(amin)
for i in range(n):
    print(a_i+1,i+1)

if amax > 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 io
import sys
import math
from itertools import accumulate as acc
import numpy as np
from collections import Counter

data = int(input())
array = list(map(int, input().split(" ")))

MIN = min(array)
MAX = max(array)

print(2 * data - 1)

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

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

b = 0
by = 0
flg = 0
for i,j in enumerate(a):
	if abs(j) > abs(b):
		b = j
		by = i+1
		if j > 0:
			flg = 1
		else:
			flg = 0
ans = []
if flg == 1:
	x = min(a)
	if x < 0:
		for i in range(n):
			if a[i] != b:
				a[i] += b
				ans.append([by,i+1])
	for i in range(1,n):
		a[i] += a[i-1]
		ans.append([i,i+1])
else:
	x = max(a)
	if x > 0:
		for i in range(n-1,-1,-1):
			if a[i] != b:
				a[i] += b
				ans.append([by,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):
import bisect
import copy
import heapq
import math
import sys
from collections import *
from itertools import accumulate, combinations, permutations, product

def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

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

tmp=[0,abs(a[0])]
for i in range(n):
    if tmp[1]<abs(a[i]):
        tmp[0]=i
        tmp[1]=abs(a[i])


lst=[]

for i in range(n):
    a[i]+=a[tmp[0]]
    lst.append([tmp[0]+1,i+1])


if a[tmp[0]]<0:
    for i in range(n-1):
        a[-2-i]+=a[-1-i]
        lst.append([n-i,n-i-1])
else:
    for i in range(n-1):
        a[i+1]+=a[i]
        lst.append([1+i,2+i])


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

Solution (Python):
N, *A = map(int, open(0).read().split())

ma = max(A)
mi = min(A)

if abs(mi) <= abs(ma):
    p = A.index(ma)
    ans = [(p, i) for i in range(N)]
    ans += [(i - 1, i) for i in range(1, N)]
else:
    p = A.index(mi)
    ans = [(p, i) for i in range(N)]
    ans += [(i, i - 1) for i in reversed(range(1, N))]

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

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

def solve_plus(out):
    for i in range(n-1):
        out.append([i+1, i+2])
    return out

def solve_minus(out):
    for i in range(n-1):
        out.append([n-i, n-i-1])
    return out

max_a = 0
max_i = 0
min_a = 10**7
min_i = 0
for i in range(n):
    if a[i] > max_a:
        max_a = a[i]
        max_i = i+1
    if a[i] < min_a:
        min_a = a[i]
        min_i = i+1

if min_a >= 0:
    out = solve_plus(out)
elif max_a < 0:
    out = solve_minus(out)
else:
    if abs(max_a) > abs(min_a):
        for i in range(n):
            if a[i] < 0:
                out.append([max_i, i+1])
        out = solve_plus(out)
    else:
        for i in range(n):
            if a[i] > 0:
                out.append([min_i, i+1])
        out = solve_minus(out)
print(len(out))
for x, y in out:
    print(x, y)

Solution (Python):




import sys
read = sys.stdin.readline
ra = range
enu = enumerate


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


N = read_a_int()
A = read_ints()
ma, mi = max(A), min(A)
print(2 * N - 2)
if abs(ma) > abs(mi):  
    x = A.index(ma)
    for y in range(N):
        if x == y:
            continue
        print(x + 1, y + 1)
    
    for i in range(1, N):
        print(i, i + 1)
else:  
    x = A.index(mi)
    for y in range(N):
        if x == y:
            continue
        print(x + 1, y + 1)
    for i in range(N, 1, -1):
        print(i, i - 1)

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
maxa = -float('inf')
mina = float('inf')
for i,a in enumerate(A):
    if maxa < a:
        maxa = a
        maxi = i
    if mina > a:
        mina = a
        mini = i

if abs(maxa) >= abs(mina):
    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,-1):
        print(i,i-1)

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

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

print(2 * N - 2)
if abs(M) >= abs(m):
    ind = A.index(M)
    for x in set(range(N)) - {ind}:
        print(ind + 1, x + 1)
    for x in range(1, N):
        print(x, x + 1)
else:
    ind = A.index(m)
    for x in set(range(N)) - {ind}:
        print(ind + 1, x + 1)
    for x in range(N - 1, 0, -1):
        print(x + 1, x)

Solution (Python):
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    
    from itertools import combinations, permutations, accumulate, groupby
    
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    

    
    

    n = int(input())
    a = list(map(int, input().split()))
    b = sorted(a)
    res = []
    if abs(b[0]) <= b[-1]:
        x = a.index(b[-1])
        for i in range(n):
            if a[i] < 0:
                res.append([x+1, i+1])
        print(n-1+len(res))
        for i in res:
            print(*i)
        for i in range(n-1):
            print(i+1, i+2)
    else:
        x = a.index(b[0])
        for i in range(n):
            if a[i] > 0:
                res.append([x+1, i+1])
        print(n-1+len(res))
        for i in res:
            print(*i)
        for i in range(n-1, 0, -1):
            print(i+1, i)
    

if __name__ == '__main__':
    main()

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
A=[]
for i in range(n):
  A.append(abs(a[i]))
m=A.index(max(A))
print(2*n-1)
for i in range(1,n+1):
  print(m+1,i)
if a[m]>=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, = map(int, input().split())
max_A, min_A = max(A), min(A)
max_idx, min_idx = A.index(max_A), A.index(min_A)
mode = None
if min_A >= 0: mode = 2
elif max_A <= 0: mode = 3
elif max_A >= abs(min_A): mode = 0
else: mode = 1
actions = []
if mode == 0:
    for i in range(N):
        if i != max_idx:
            A[i] += A[max_idx]; actions.append((max_idx+1, i+1))
    mode += 2
elif mode == 1:
    for i in range(N):
        if i != min_idx:
            A[i] += A[min_idx]; actions.append((min_idx+1, i+1))
    mode += 2
if mode == 2:
    for i in range(N-1):
        A[i+1] += A[i]; actions.append((i+1, i+2))
elif mode == 3:
    for i in range(N-1, 0, -1):
        A[i-1] += A[i]; actions.append((i+1, i))
print(len(actions))
for a in actions: print(*a)

Solution (Python):


def main():
    n = int(input())
    a = list(map(int, input().split()))
    absmaxindex = 0
    for i in range(1, n):
        if abs(a[i]) > abs(a[absmaxindex]):
            absmaxindex = i

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

if __name__ == "__main__":
    main()

Solution (Python):

import sys
try:
    from typing import List, Optional
except ImportError:
    pass


def solve(N: int, a: "List[int]"):
    amx = amn = None  
    imx = imn = -1
    for i, ai in enumerate(a):
        if amn is None or ai < amn:
            imn = i
            amn = ai
        if amx is None or ai > amx:
            imx = i
            amx = ai

    assert amx is not None and amn is not None

    if amx * amn < 0:
        print(2 * N - 1)
        if amx < -amn:
            for j in range(N):
                print(1 + imn, 1 + j)
            d = amn
        else:
            for j in range(N):
                print(1 + imx, 1 + j)
            d = amx
    else:
        print(N - 1)
        d = 0

    assert (amx + d) * (amn + d) >= 0

    if amx + d >= 0 and amn + d >= 0:
        for i in range(N - 1):
            print(1 + i, 1 + i + 1)
    else:
        for i in reversed(range(N - 1)):
            print(1 + i + 1, 1 + i)


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    a = [int(next(tokens)) for _ in range(N)]  
    solve(N, a)


if __name__ == '__main__':
    main()

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
amax = max(A)
max_idx = A.index(amax)
amin = min(A)
min_idx = A.index(amin)

ans_list = []
if amax*amin < 0:
    if abs(amax) >= abs(amin):
        for i in range(N):
            A[i] += amax
            ans_list.append([max_idx+1, i+1])
    else:
        for i in range(N):
            A[i] += amin
            ans_list.append([min_idx+1, i+1])


amax = max(A)
amin = min(A)

if amax > 0:
    for i in range(N-1):
        ans_list.append([i+1, i+2])
elif amin < 0:
    for i in range(N-1, 0, -1):
        ans_list.append([i+1, i])

print(len(ans_list))
for i in range(len(ans_list)):
    print(*ans_list[i])

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
ans=[]
if max(a)>-min(a):
  x=max(a)
  idx=0
  for i in range(n):
    if a[i]==x:
      idx=i
      break
  for i in range(n):
    if a[i]==a[idx]:
      continue
    ans.append((idx+1,i+1))
  for i in range(n-1):
    ans.append((i+1,i+2))
else:
  x=min(a)
  idx=0
  for i in range(n):
    if a[i]==x:
      idx=i
      break
  for i in range(n):
    if a[i]==a[idx]:
      continue
    ans.append((idx+1,i+1))
  for i in range(n-1)[::-1]:
    ans.append((i+2,i+1))
print(len(ans))
for i in ans:
  print(i[0],i[1])

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

max_a=max(a)
min_a=min(a)
max_ind=a.index(max_a)
min_ind=a.index(min_a)

ans=[]
if abs(max_a) >= abs(min_a):
    ans.append([max_ind+1,1])
    ans.append([max_ind+1,1])

    for i in range(n-1):
        ans.append([i+1,i+2])
        ans.append([i+1,i+2])
else:
    ans.append([min_ind+1,n])
    ans.append([min_ind+1,n])

    for i in reversed(range(n-1)):
        ans.append([i+2,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()))
m = 0
for i in range(n):
    if abs(a[i]) > abs(m):
        m = a[i]
        m_idx = i
        
if m == 0:
    print(0)
elif m > 0:
    print(2 * n)
    for i in range(1, n+1):
        if i == 1:
            print(m_idx+1, 1)
            print(m_idx+1, 1)
        else:
            print(i-1, i)
            print(i-1, i)
else:
    print(2 * n)
    for i in range(n, 0, -1):
        if i == n:
            print(m_idx+1, n)
            print(m_idx+1, n)
        else:
            print(i+1, i)
            print(i+1, i)

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

large = -float('inf')
small = float('inf')
for i, a in enumerate(A):
    if large < a:
        large = a
        idxL = i + 1
    if small > a:
        small = a
        idxS = i + 1

S = [(i + 1, i + 2) for i in range(N - 1)]
S_reverse = [(i, i - 1) for i in range(N, 1, -1)]

if small >= 0:
    ans = S
elif large <= 0:
    ans = S_reverse
elif abs(large) >= abs(small):
    ans = [(idxL, i) for i in range(1, N + 1) if i != idxL] + S
else:
    ans = [(idxS, i) for i in range(1, N + 1) if i != idxS] + S_reverse

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

Solution (Python):






n=int(input())
a=list(map(int,input().split()))
c,d=min(a),max(a)
ans=[]
if abs(c)>abs(d):
    c_=a.index(c)
    for i in range(n):
        if i!=c_ and a[i]>0:
            ans.append(str(c_+1)+" "+str(i+1))
    for i in range(n-1,0,-1):
        ans.append(str(i+1)+" "+str(i))
else:
    d_=a.index(d)
    for i in range(n):
        if i!=d_ and a[i]<0:
            ans.append(str(d_+1)+" "+str(i+1))
    for i in range(n-1):
        ans.append(str(i+1)+" "+str(i+2))
l=len(ans)
print(l)
for i in range(l):
    print(ans[i])

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
ans = 0
process = []

def cumsum(reverse=False):
    global A,ans,process
    if reverse == False:
        for i in range(len(A)-1):
            A[i+1] += A[i]
            ans += 1
            process.append([i+1,i+2])
    else:
        for i in reversed(range(len(A)-1)):
            A[i-1] += A[i]
            ans += 1
            process.append([i+2,i+1])

def addmax():
    global A,ans,process
    ind = A.index(max(A))
    m = max(A)
    for i in range(N):
        A[i] += m
        ans += 1
        process.append([ind+1,i+1])

def addmin():
    global A,ans,process
    ind = A.index(min(A))
    m = min(A)
    for i in range(N):
        A[i] += m
        ans += 1
        process.append([ind+1,i+1])

def main():
    global A,ans,process
    if max(A) <= 0:
        cumsum(reverse=True)
    elif min(A) >= 0:
        cumsum()
    else:
        if -1*min(A) < max(A):
            addmax()
            cumsum()
        else:
            addmin()
            cumsum(reverse=True)
    
    print(ans)
    for i in range(ans):
        print(*process[i])

if __name__ == "__main__":
    main()

Solution (Python):
import math
from collections import deque
def main():
    n = int(input())
    a = [int(t)for t in input().split()]

    if all([a_i>0 for a_i in a]):
        print(n-1)
        for i in range(1,n):
            print(i,i+1)
        
    elif all([a_i<=0 for a_i in a]):
        print(n-1)
        for i in range(1,n)[::-1]:
            print(i+1,i)

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


        else:
            print(2*n-1)
            pos = a.index(min(a))+1
            for i in range(n):
                print(pos,i+1)  
            
            for i in range(1,n)[::-1]:
                print(i+1,i)
if __name__ == "__main__":
    main()

Solution (Python):
import math
from collections import deque
def main():
    n = int(input())
    a = [int(t)for t in input().split()]

    if all([a_i>0 for a_i in a]):
        print(n-1)
        for i in range(n-1):
            print(i+1,i+2)
        
    elif all([a_i<=0 for a_i in a]):
        print(n-1)
        for i in range(2,n+1)[::-1]:
            print(i,i-1)
    else:
        if abs(min(a))<max(a):
            print(2*n-1)
            pos = a.index(max(a))  
            for i in range(n):
                print(pos+1,i+1)
            for i in range(n-1):
                print(i+1,i+2)


        else:
            print(2*n-1)
            pos = a.index(min(a))
            for i in range(n):
                print(pos+1,i+1)  
            
            for i in range(2,n+1)[::-1]:
                print(i,i-1)
    
if __name__ == "__main__":
    main()

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

m = 0
manu = []

for i in range(1,N):
    if abs(a[m]) < abs(a[i]):
        m = i

for i in range(N):
    if a[m]*a[i] < 0:
        a[i] += a[m]
        manu.append([m,i])

if a[m] >= 0:
    for i in range(N-1):
        if a[i] > a[i+1]:
            a[i+1] += a[i]
            manu.append([i,i+1])

else:
    for i in range(N-1):
        if a[N-i-2] > a[N-i-1]:
            a[N-i-2] += a[N-i-1]
            manu.append([N-i-1,N-i-2])
    
print(len(manu))
for i in range(len(manu)):
    manu[i][0] += 1
    manu[i][1] += 1
    print(" ".join(list(map(str,manu[i]))))

Solution (Python):
def solve():
    N = int(input())
    a = list(map(int, input().split()))
    
    max_idx, min_idx = -1, -1
    max_a, min_a = -10 ** 6, 10 ** 6
    for i, ai in enumerate(a):
        if max_a < ai:
            max_a = ai
            max_idx = i
        if ai < min_a:
            min_a = ai
            min_idx = i
    
    ans = []
    if abs(min_a) <= abs(max_a):
        for i in range(N):
            ans.append([max_idx + 1, i + 1])
        for i in range(N - 1):
            ans.append([i + 1, i + 2])
    else:
        for i in range(N):
            ans.append([min_idx + 1, 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)


if __name__ == '__main__':
    solve()

Solution (Python):
import sys
INF = 10 ** 9
MOD = 10 ** 9 + 7
from collections import deque
sys.setrecursionlimit(100000000)

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

    m = INF
    idx_m = -1
    M = -INF
    idx_M = -1
    for i in range(n):
        if M < a[i]:
            idx_M = i
            M = a[i]
        if m > a[i]:
            idx_m = i
            m = a[i]
    
    ans = []
    flag = False
    
    if m == 0 and M == 0:
        print(0)
        exit()
    elif m < 0 and M > 0:
        if abs(m) <= abs(M):
            flag = True
    elif m >= 0:
        flag = True
    
    
    if flag:
        for i in range(n):
            if a[i] < 0:
                a[i] += M
                ans.append((idx_M + 1, i + 1))
        for i in range(n-1):
            if a[i] > a[i+1]:
                a[i+1] += a[i]
                ans.append((i + 1, i + 2))
    else:
        for i in range(n):
            if a[i] > 0:
                a[i] += m
                ans.append((idx_m + 1, i + 1))
        for i in range(n-2,-1,-1):
            if a[i] > a[i + 1]:
                a[i] += a[i+1]
                ans.append((i + 2, i + 1))
    
    l = len(ans)
    print(l)
    for i in range(l):
        print(*ans[i])

if __name__=='__main__':
    main()

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

Solution (Python):
N, *A = map(int, open(0).read().split())
a = max(A,key=abs)
j = str(A.index(a)+1)
ans = []
if a>0:
  for i,c in enumerate(A):
    if c<0:
      ans.append(j+' '+str(i+1))
  for i in range(1,N):
    ans.append(str(i)+' '+str(i+1))
else:
  for i,c in enumerate(A):
    if c>0:
      ans.append(j+' '+str(i+1))
  for i in range(N,1,-1):
    ans.append(str(i)+' '+str(i-1))
print(len(ans))
print('\n'.join(ans))

Solution (Python):
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): 
    return list(map(int,input().split()))
def m(): 
    return map(int,input().split())
def onem(): 
    return int(input())
def s(x): 
    a = []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): 
    return " ".join(map(str,x))
def max2(x): 
    return max(map(max,x))
def In(x,a): 
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False
"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
"""

n = onem()

a = l()

p = -Max
po = 0

pp = Max
ppo = 0


for i in range(n):
    if a[i] >= p:
        p = a[i]
        po = i+1
    if a[i] <= pp:
        pp = a[i]
        ppo = i+1

if abs(p) >= abs(pp):

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

else:

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

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

max_a = max(A)
min_a = min(A)

max_a_ind = A.index(max_a)
min_a_ind = A.index(min_a)

if min_a >= 0:
    check = 'sei'
elif max_a > 0 and min_a < 0:
    check = 'seifu'
else:
    check = 'fu'

if check == 'sei':
    print(n-1)
    for i in range(n-1):
        print(str(i+1) + ' ' + str(i+2))
elif check == 'fu':
    print(n-1)
    for i in range(n-2, -1, -1):
        print(str(i+2) + ' ' + str(i+1))
else:
    if abs(max_a) >= abs(min_a):
        print(n+n-1)
        for i in range(n):
            print(str(max_a_ind+1) + ' ' + str(i+1))
        for i in range(n-1):
            print(str(i+1) + ' ' + str(i+2))
    else:
        print(n+n-1)
        for i in range(n):
            print(str(min_a_ind+1) + ' ' + str(i+1))
        for i in range(n-2, -1, -1):
            print(str(i+2) + ' ' + str(i+1))

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