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())
ans=[]
l=list(map(int,input().split()))
if min(l)>=0:
    m=1
if max(l)<=0:
    m=-2
if max(l)>0 and min(l)<0:
    if max(l)>=-min(l):
        m=max(l)
    else:
        m=min(l)
    mi=l.index(m)
    for i in range(n):
        if m>0:
            if l[i]<0:
                ans.append([mi+1,i+1])
        else:
            if l[i]>0:
                ans.append([mi+1,i+1])
if m>0:
    for i in range(n-1):
        ans.append([i+1,i+2])
else:
    for i in range(n,1,-1):
        ans.append([i,i-1])
print(len(ans))
for i in ans:
    print(*i)

Solution (Python):
def main():
    _ = int(input())
    a = list(map(int, input().split()))
    ans = []
    max_a = max(a)
    min_a = min(a)
    unify_plus = True
    if max_a + min_a < 0:
        unify_plus = False
    if unify_plus:
        index = -1
        for i in range(len(a)):
            if max_a == a[i]:
                index = i
                break
        for i in range(len(a)):
            if a[i] < 0:
                a[i] += a[index]
                ans.append([index+1, i+1])
        for i in range(1, len(a)):
            if a[i-1] > a[i]:
                a[i] += a[i-1]
                ans.append([i-1+1, i+1])
    else:
        index = -1
        for i in range(len(a)):
            if min_a == a[i]:
                index = i
                break
        for i in range(len(a)):
            if a[i] > 0:
                a[i] += a[index]
                ans.append([index+1, i+1])
        for i in reversed(range(1, len(a))):
            if a[i-1] > a[i]:
                a[i-1] += a[i]
                ans.append([i+1, i-1+1])
    print(len(ans))
    for i in range(len(ans)):
        print(ans[i][0], ans[i][1])

if __name__ == "__main__":
    main()

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





ans = []
if max(a) * min(a) < 0:
    if abs(max(a)) > abs(min(a)):
        for i in range(n):
            if i != a.index(max(a)):
                ans.append([a.index(max(a))+1, i+1])
                a[i] += max(a)
    else:
        for i in range(n):
            if i != a.index(min(a)):
                ans.append([a.index(min(a))+1, i+1])
                a[i] += min(a)
if max(a) > 0:
    
    for i in range(1,n):
        ans.append([i,i+1])
else:
    
    for i in range(n-1,0,-1):
        ans.append([i+1,i])
print(len(ans))
for i in range(len(ans)):
    print("{} {}".format(*ans[i]))

Solution (Python):
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
mod=10**9+7

N=I()
a=LI()

M=0
index=0
for i in range(N):
    if abs(M)<abs(a[i]):
        M=a[i]
        index=i
        
ans=[]
cnt=0
if M>0:
    for i in range(N-1):
        if a[i]>a[i+1]:
            ans.append([index+1,i+2])
            ans.append([index+1,i+2])
            a[i+1]+=M*2
            cnt+=2
            M=a[i+1]
            index=i+1
            
else:
    for i in range(N-1):
        if a[N-i-2]>a[N-i-1]:
            ans.append([index+1,N-i-1])
            ans.append([index+1,N-i-1])
            a[N-i-2]+=M*2
            cnt+=2
            M=a[N-i-2]
            index=N-i-2
            
print(cnt)
for i in range(len(ans)):
    print(' '.join(map(str, ans[i])))

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

Solution (Python):
import sys
from collections import deque
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
n = int(readline())
lst1 = list(map(int,readline().split()))
ans = []
if abs(max(lst1)) > abs(min(lst1)):
    a = lst1.index(max(lst1)) + 1
    for i in range(n):
        ans.append([a,i+1])
    for i in range(n-1):
        ans.append([i+1,i+2])
else:
    a = lst1.index(min(lst1)) + 1
    for i in range(n):
        ans.append([a,i+1])
    for i in range(n-1,0,-1):
        ans.append([i+1,i])
print(len(ans))
for i,j in ans:
    print(i,j)

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

flag = 1
for i in range(1, N):
  if A[i] < A[i - 1]:
    flag = 0
    break
if flag:
  print(0)
  exit()

abs_max = -1
index = 0
for i, a in enumerate(A):
  if abs(a) > abs_max:
    abs_max = abs(a)
    index = i
    
answer = []
if A[index] > 0:
  for i in range(1, N):
    for _ in range(2):
      if A[i - 1] > A[i]:
        A[i] += abs_max
        answer.append((index + 1, i + 1))
        if A[i] > abs_max:
          abs_max = A[i]
          index = i
else:
  abs_max = -abs_max
  for i in range(N - 2, -1, -1):
    for _ in range(2):
      if A[i] > A[i + 1]:
        A[i] += abs_max
        answer.append((index + 1, i + 1))
        if A[i] < abs_max:
          abs_max = A[i]
          index = i

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

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

ans = []
if abs(min(a))<=max(a):
  ans += [(a.index(max(a)), 0)]
  ans += [(a.index(max(a)), 0)]
  for i in range(1, N):
    ans += [(i-1, i)]
    ans += [(i-1, i)]
else:
  ans += [(a.index(min(a)), N-1)]
  ans += [(a.index(min(a)), N-1)]
  for i in range(N-1)[::-1]:
    ans += [(i+1, i)]
    ans += [(i+1, i)]
print len(ans)
for t in ans:
  print t[0]+1, t[1]+1

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

print(2*N-2)

maxa = max(A)
mina = min(A)

if abs(maxa) > abs(mina):
    maxi = A.index(maxa)
    for i in range(N):
        if i==maxi:
            continue
        print(maxi+1,i+1)
    for i in range(N-1):
        print(i+1,i+2)
        
else:
    mini = A.index(mina)
    for i in range(N):
        if i==mini:
            continue
        print(mini+1,i+1)
    for i in range(N-1):
        print(N-i,N-i-1)

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

ans = []
if max(a) >= -min(a):
    ans.append([a.index(max(a))+1, 1])
    ans.append([a.index(max(a))+1, 1])
    for i in range(n-1):
        ans.append([i+1, i+2])
        ans.append([i+1, i+2])

else:
    ans.append([a.index(min(a))+1, n])
    ans.append([a.index(min(a))+1, n])
    for i in range(n-1):
        ans.append([n-i, n-i-1])
        ans.append([n-i, n-i-1])

print(len(ans))
for i in range(len(ans)):
    print(" ".join(map(str, ans[i])))

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
maxi = max((abs(a), i) for i, a in enumerate(A))[1]
if A[maxi] == 0:
    print(0)
    exit()
print(2*(N-1))
for i in range(N):
    if i == maxi: continue
    print(maxi+1, i+1)
if A[maxi] > 0:
    for i in range(N-1):
        print(i+1, i+2)
else:
    for i in range(N-1)[::-1]:
        print(i+2, i+1)

Solution (Python):

from collections import defaultdict,deque
from heapq import heappush, heappop
from itertools import permutations
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    n = I()
    a = LI()
    m = max(a)
    M = min(a)
    if abs(M) <= abs(m):
        for i in range(n):
            if a[i] == m:
                break
        x = i+1
        print(2*n-1)
        for i in range(n):
            print(x,i+1)
        for i in range(n-1):
            print(i+1,i+2)
    else:
        for i in range(n):
            if a[i] == M:
                break
        x = i+1
        print(2*n-1)
        for i in range(n):
            print(x,i+1)
        for i in range(n-1)[::-1]:
            print(i+2,i+1)
    return


if __name__ == "__main__":
    solve()

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

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

Solution (Python):
n=int(input())
lists=list(map(int,input().split()))
maxi=0
gives=0
index=0

for i in range(n):
    if abs(lists[i])>maxi:
        maxi=abs(lists[i])
        gives=lists[i]
        index=i
if gives<0:
    print(2*n-2)
    for i in range(n):
        if i!=index:
            print(index+1,i+1)
    for i in range(n-1):
        print(n-i,n-1-i)
elif gives>=0:
    print(2*n-2)
    for i in range(n):
        if i!=index:
            print(index+1,i+1)
    for i in range(n-1):
        print(i+1,i+2)

Solution (Python):
import sys
input = sys.stdin.readline
N=int(input())
a=list(map(int,input().split()))
A=0
amax=0
imax=1
for i in range(N):
    if A<abs(a[i]):
        A=abs(a[i])
        amax=a[i]
        imax=i+1

ans=[]
for i in range(N):
    ans.append([imax,i+1])
if amax>=0:
    for i in range(1,N):
        ans.append([i,i+1])
else:
    for i in range(1,N):
        ans.append([N-i+1,N-i])
print(len(ans))
for i in ans:
    print(*i)

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

def main():
    N = int(input())
    A = list(map(int,input().split()))
    a,b = max(A), min(A)
    ap,bp = A.index(a),A.index(b)
    ans = []
    if a >= -b:
        for i in range(N):
            if A[i] < 0:
                A[i] += a
                ans.append([ap+1,i+1])
        for i in range(N-1):
            A[i+1] += A[i]
            ans.append([i+1,i+2])
    else:
        for i in range(N):
            if A[i] > 0:
                A[i] += b
                ans.append([bp+1,i+1])
        for i in range(N-1):
            A[-i-2] += A[-i-1]
            ans.append([N-i,N-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( )))

mx = max(a)

manu = []
mn = min(a)


if abs(mx)>abs(mn):
    for i in range(n-1):
        if a[i]>a[i+1]:
            mx = max(a)
            mx_id = a.index(mx)
            manu.append((i+1,mx_id))
            a[i+1] += mx
            
            mx = max(a)
            mx_id = a.index(mx)
            manu.append((i+1,mx_id))
            a[i+1] += mx
else:
    
    for i in range(n-1,0,-1):
        if a[i-1]>a[i]:
            mn = min(a)
            mn_id = a.index(mn)
            manu.append((i-1,mn_id))
            a[i-1] += mn
            
            mn = min(a)
            mn_id = a.index(mn)
            manu.append((i-1,mn_id))
            a[i-1] += mn
print(len(manu))
for i,j in manu:
    print(j+1,i+1)
"""
print(*a)

for i in range(n-1):
    if a[i]>a[i+1]:
        print("false")
        exit()
print("true")
"""

Solution (Python):
import sys

n, *a = map(int, sys.stdin.read().split())

def main():
    ma = 0
    idx = 0
    for i in range(n):
        cur = abs(a[i])
        if cur > ma:
            ma = cur
            idx = i

    if a[idx] == 0:
        print(0)
        sys.exit()

    procedures = []
    for i in range(n):
        a[i] += a[idx]
        procedures.append('{0} {1}'.format(idx+1, i+1))

    if a[idx] > 0:
        for i in range(n-1):
            if a[i] > a[i+1]:
                a[i+1] += a[i]
                procedures.append('{0} {1}'.format(i+1, i+2))
    else:
        for i in range(n-1, 0, -1):
            if a[i] < a[i-1]:
                a[i-1] += a[i]
                procedures.append('{0} {1}'.format(i+1, i))

    procedures = [len(procedures)] + procedures
    return procedures
    
if __name__ == '__main__':
    ans = main()
    print(*ans, sep='\n')

Solution (Python):


import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

N = INT()
A = LIST()


mn = min(A)
mx = max(A)
if abs(mx) >= abs(mn):
    flag = 1
    base = mx
    baseidx = A.index(mx)
else:
    flag = 0
    base = mn
    baseidx = A.index(mn)


ans = []
for i in range(N):
    if i == baseidx:
        continue
    A[i] += base
    ans.append((baseidx, i))


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

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

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

maxim = max(A)
mini = min(A)

if maxim == mini:
    print(0)
    exit()

if abs(maxim) >= abs(mini):
    max_idx = A.index(maxim) + 1
    print(2*n)
    print(max_idx, 1)
    print(max_idx, 1)
    for i in range(1, n):
        print(i, i+1)
        print(i, i+1)

else:
    min_idx = A.index(mini) + 1
    print(2*n)
    print(min_idx, n)
    print(min_idx, n)
    for i in range(n, 1, -1):
        print(i, i-1)
        print(i, i-1)

Solution (Python):
def get_min_idx_val(A, N):
    min_val = A[0]
    min_idx = 0
    for i in range(N):
        if min_val > A[i]:
            min_val = A[i]
            min_idx = i
            
    return min_idx, min_val

def get_max_idx_val(A, N):
    max_val = A[0]
    max_idx = 0
    for i in range(N):
        if max_val < A[i]:
            max_val = A[i]
            max_idx = i
            
    return max_idx, max_val

def solve():
    N = int(input())
    A = list(map(int, input().split()))
    min_idx, min_A = get_min_idx_val(A, N)
    max_idx, max_A = get_max_idx_val(A, N)
    sign = 0
    if abs(min_A) <= abs(max_A):
        sign = 1
    else:
        sign = -1
            
    ret = 0
    query = []
    
    additive_idx = max_idx if sign > 0 else min_idx
    additive_val = max_A if sign > 0 else min_A 
    
    for i in range(N):
        if A[i]*sign < 0:
            ret += 1
            query.append('{0} {1}'.format(additive_idx+1, i+1))
            A[i] += additive_val
    
    if sign > 0:
        for i in range(1,N):
            first = i-1
            second = i
            if A[first] > A[second]:
                
                ret += 1
                query.append('{0} {1}'.format(first+1, second+1))
                A[second] += A[first]
    elif sign < 0:
        for i in range(0,N-1)[::-1]:
            first = i
            second = i+1
            
            if A[first] > A[second]:
                
                ret += 1
                query.append('{0} {1}'.format(second+1, first+1))
                A[first] += A[second]
    
    
    output = """{0}
{1}""".format(ret, '\n'.join(query))
    print(output)
    
solve()

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N = INT()
a = LIST()

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, -1):
		print(i, i-1)
else:
	print(2*N-1)
	if abs(min(a)) < abs(max(a)):  
		idx = a.index(max(a))+1
		for i in range(1, N+1):
			print(idx, i)
			a[i-1] += a[idx-1]
		for i in range(1, N):
			print(i, i+1)
	else:
		idx = a.index(min(a))+1
		for i in range(1, N+1):
			print(idx, i)
			a[i-1] += a[idx-1]
		for i in range(N, 1, -1):
			print(i, i-1)

Solution (Python):
from itertools import chain, product

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

a_abs_max = 0
for i in range(N):
    if a_abs_max < abs(a[i]):
        a_abs_max = abs(a[i])
        a_abs_max_index = i

result = []
if a_abs_max > 0:
    if a[a_abs_max_index] > 0:
        result = list(chain(iter([(a_abs_max_index + 1, a_abs_max_index + 1)]), product([a_abs_max_index + 1], range(1, N + 1)), map(lambda i: (i + 1, i + 2), range(N - 1)))) 
    elif a[a_abs_max_index] < 0:
        result = list(chain(iter([(a_abs_max_index + 1, a_abs_max_index + 1)]), product([a_abs_max_index + 1], range(1, N + 1)), map(lambda i: (i + 1, i), range(N - 1, 0, -1)))) 

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

Solution (Python):
import sys
n = int(input())
INF = 10**18
a_ls = [int(i) for i in sys.stdin.readline().split()]
max_ind = 1
_max = a_ls[0]
min_ind = 1
_min = a_ls[0]

for i, a in enumerate(a_ls, 1):
    if a > _max:
        _max = a
        max_ind = i
    if a < _min:
        _min = a
        min_ind = i


flg = abs(_max) >= abs(_min)
ls = []
if flg:
    for i in range(1,n+1):
        if i != max_ind:
            ls.append((max_ind, i))
    for i in range(1,n):
        ls.append((i, i+1))
else:
    for i in range(1, n + 1):
        if i != min_ind:
            ls.append((min_ind, i))
    for i in range(n, 1, -1):
        ls.append((i, i - 1))
print(len(ls))
for x, y in ls:
    print(x, y)

Solution (Python):

import sys


def solve(N: int, a: "List[int]"):
    abs_min = 0
    abs_min_index = 0
    for i in range(N):
        if abs(a[i])>abs_min:
            abs_min = abs(a[i])
            abs_min_index = i
    
    print(2*N-1)
    for j in range(1,N+1):
        print(abs_min_index+1,j)

    if a[abs_min_index] >= 0:
        for j in range(1,N):
            print(j,j+1)
    else:
        for j in range(N,1,-1):
            print(j,j-1)
    return


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

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

pos = ""
max_abs = 0
value = ""
for idx, a in enumerate(al):
    if abs(a) >= max_abs:
        pos = idx + 1 
        max_abs = abs(a)
        value = a

print(2*n - 2)
if value >= 0:
    print(pos)
    print(2)
    print(pos)
    print(2)
    for i in range(2, n):
        print(i)
        print(i+1)
        print(i)
        print(i+1)

else:
    print(pos)
    print(n-1)
    print(pos)
    print(n-1)
    for i in range(n-1, 1, -1):
        print(i)
        print(i-1)
        print(i)
        print(i-1)

Solution (Python):


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

A_min = min(A)
A_max = max(A)

ans = []

if abs(A_max) >= abs(A_min):
    A_max_idx = A.index(A_max)
    for i in range(1,N+1):
        ans.append([A_max_idx + 1, i])
    for i in range(1,N):
        ans.append([i, i+1])
else:
    A_min_idx = A.index(A_min)
    for i in range(1,N+1):
        ans.append([A_min_idx + 1, i])
    for i in reversed(range(2,N+1)):
        ans.append([i, i-1])
        
print(len(ans))
for x in ans:
    print(*x)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
im, m = 0, 0
for i,a in enumerate(A):
    if abs(a)>abs(m):
        m = a
        im = i

operations = []
for i in range(N):
    if i==im: continue
    operations.append((im+1, i+1))
    A[i] += A[im]

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

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

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

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

a_max = -10**7
a_max_idx = -1
a_min = 10**7
a_max_idx = -1
for i, ai in enumerate(a):
    if a_max < ai:
        a_max = ai
        a_max_idx = i
    if a_min > ai:
        a_min = ai
        a_min_idx = i

operation = []
if abs(a_max) > abs(a_min):
    for i, ai in enumerate(a):
        if ai < 0:
            operation.append((a_max_idx + 1, i + 1))
    
    for i in range(1, n):
        operation.append((i, i + 1))
else:
    for i, ai in enumerate(a):
        if ai > 0:
            operation.append((a_min_idx + 1, i + 1))
    
    for i in reversed(range(1, n)):
        operation.append((i + 1, i))

print(len(operation))
for opi in operation:
    print(*opi)

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

ans = []
if abs(max(A)) > abs(min(A)):
    num = max(A)
    idx = A.index(num)
    for i in range(1, N):
        while A[i-1] > A[i]:
            A[i] += num
            ans.append([str(idx+1), str(i+1)])
            if A[i] > num:
                num = A[i]
                idx = i
else:
    num = min(A)
    idx = A.index(num)
    for i in range(N-2, -1, -1):
        while A[i] > A[i+1]:
            A[i] += num
            ans.append([str(idx+1), str(i+1)])
            if A[i] < num:
                num = A[i]
                idx = i
                
m = len(ans)
print(m)
for i in range(m):
    print(" ".join(ans[i]))

Solution (Python):

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


max_a = max(a)
min_a = min(a)
sign = lambda x: 1 if x >= 0 else -1

ans = []

if sign(max_a) == sign(min_a):
    
    if max_a > 0:
        for j in range(N-1):
            ans.append((j, j+1))

    else:
        for j in range(N-1, 0, -1):
            ans.append((j, j-1))


else:
    
    if abs(max_a) >= abs(min_a):
        
        i = a.index(max_a)
        for j in range(N):
            if i != j:
                ans.append((i, j))

        for j in range(N-1):
            ans.append((j, j+1))


    else:
        
        i = a.index(min_a)
        for j in range(N):
            if i != j:
                ans.append((i, j))

        for j in range(N-1, 0, -1):
            ans.append((j, j-1))

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

Solution (Python):
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    n=int(input())
    A=list(map(int,input().split()))
    m=min(A); M=max(A)
    mi=A.index(m)+1; Mi=A.index(M)+1
    print(2*n-2)
    
    if(-m<=M):
        for i in range(1,n+1):
            if(i==Mi): continue
            print(Mi,i)
        for i in range(1,n):
            print(i,i+1)
    
    else:
        for i in range(1,n+1):
            if(i==mi): continue
            print(mi,i)
        for i in range(n,1,-1):
            print(i,i-1)
resolve()

Solution (Python):
N=int(input())
a=list(map(int,input().split()))
b=[]
c=[]
count=0
minus=0

for i in range(len(a)):
    if a[i]<0: minus+=1

if minus==0:
    for i in range(N-1):
        if a[i+1]-a[i]<0:
            a[i+1]+=a[i]
            b.append(i+1)
            c.append(i+2)
            count+=1
elif minus==len(a):
    for i in reversed(range(0,N-1)):
        if a[i+1]-a[i]<0:
            a[i]+=a[i+1]
            b.append(i+2)
            c.append(i+1)
            count+=1
else:
    count+=N
    if abs(max(a))>=abs(min(a)):
        ind=a.index(max(a))
        for i in range(N):
            b.append(ind+1)
            c.append(i+1)
        a2=list(map(lambda x:x+max(a),a))
        for i in range(N-1):
            if a2[i+1]-a2[i]<0:
                a2[i+1]+=a2[i]
                b.append(i+1)
                c.append(i+2)
                count+=1
    else:
        ind=a.index(min(a))
        for i in range(N):
            b.append(ind+1)
            c.append(i+1)
        a2=list(map(lambda x:x+min(a),a))
        for i in reversed(range(0,N-1)):
            if a2[i+1]-a2[i]<0:
                a2[i]+=a2[i+1]
                b.append(i+2)
                c.append(i+1)
                count+=1
print(count)
for i in range(len(b)):
    print(b[i]," ",c[i])

Solution (Python):
N=int(input())
a=[int(t.strip()) for t in input().split()]
cnt=0
p=[[0 for i in range(2)] for j in range(2*N)]

if min(a) >= 0:
	for i in range(N-1):
		if a[i] > a[i+1]:
			
			p[cnt][0]=i+1
			p[cnt][1]=i+2
			
			a[i+1] += a[i]
			cnt+=1
elif max(a)<0:
	for i in reversed(range(1,N)):
		if a[i] < a[i-1]:
			a[i-1] += a[i]
			
			p[cnt][0]=i+1
			p[cnt][1]=i
			cnt+=1
else:
	if max(a) > min(a)*-1:
		tmp=max(a)
		ind = a.index(max(a))
		for i in range(N):
			a[i] +=tmp
			
			p[cnt][0]=ind+1
			p[cnt][1]=i+1
			cnt+=1
		for i in range(N-1):
			if a[i] > a[i+1]:
				
				p[cnt][0]=i+1
				p[cnt][1]=i+2
				cnt+=1
				a[i+1] += a[i]
	else:
		tmp=min(a)
		ind = a.index(min(a))
		for i in range(N):
			a[i] +=tmp
			
			p[cnt][0]=ind+1
			p[cnt][1]=i+1
			cnt+=1
		for i in reversed(range(1,N)):
			if a[i] < a[i-1]:
				a[i-1] += a[i]
				
				p[cnt][0]=i+1
				p[cnt][1]=i
				cnt+=1

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

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

mx = max(a)
mn = min(a)

proc = []
if mx >= (-1) * mn:
    i = a.index(mx)
    for j in range(len(a)):
        if a[j] < 0:
            proc.append([i+1,j+1])
            a[j] += a[i]

    for j in range(len(a)-1):
        if a[j] > a[j+1]:
            proc.append([j+1,j+2])
            a[j+1] += a[j]

else:
    
    i = a.index(mn)
    for j in range(len(a)):
        if a[j] > 0:
            proc.append([i+1,j+1])
            a[j] += a[i]

    for j in reversed(range(len(a)-1)):
        if a[j] > a[j+1]:
            proc.append([j+2,j+1])
            a[j] += a[j+1]



print(len(proc))
for k in proc:
    print(k[0], k[1])

Solution (Python):
def examD():
    N = I(); A = LI()
    ans = -1; cur = []
    minA = 0; minAlocate = 0
    maxA = 0; maxAlocate = 0
    for i in range(N):
        if minA>A[i]:
            minA = A[i]; minAlocate = i
        if maxA<A[i]:
            maxA = A[i]; maxAlocate = i
    if maxA==minA==0:
        ans = 0
    elif abs(minA)<=abs(maxA):
        flag = True
        for i in range(N):
            if i!=maxAlocate:
                A[i] +=maxA
                cur.append((maxAlocate+1, i+1))
    else:
        flag = False
        for i in range(N):
            if i!=minAlocate:
                A[i] +=minA
                cur.append((minAlocate+1, i+1))
    if ans==-1:
        if flag:
            for i in range(N - 1):
                cur.append((i + 1, i + 2))
        else:
            for i in range(N-2,-1,-1):
                cur.append((i + 2, i + 1))
        print(len(cur))
        for v in cur:
            print(" ".join(map(str, v)))
    else:
        print(ans)


import sys,copy,bisect,itertools,heapq
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examD()

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

max_a = [-1, -1]
for i in range(n):
  if abs(list_a[i]) > max_a[1]:
    max_a = [i, abs(list_a[i])]

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

Solution (Python):
N = int(input())
A = [int(a) for a in input().split()]
ma = -1
mai = -1
for i in range(N):
    if abs(A[i]) > ma:
        ma = abs(A[i])
        mai = i

print(2*N-1)
for i in range(N):
    print(mai+1, i+1)
if A[mai] > 0:
    for i in range(N-1):
        print(i+1, i+2)
else:
    for i in range(N-1)[::-1]:
        print(i+2, i+1)

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

MAX = max(a)
MIN = min(a)

if MIN < 0:
    print(2 * N - 1)
    if abs(MAX) >= abs(MIN):
        idx = a.index(MAX) + 1
        for i in range(1, N + 1):
            print(idx, i)
        for i in range(1, N):
            print(i, i + 1)
    else:
        idx = a.index(MIN) + 1
        for i in range(1, N + 1):
            print(idx, i)
        for i in range(N, 1, -1):
            print(i, i - 1)
else:
    print(N - 1)
    for i in range(1, N):
        print(i, i + 1)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
inf=float("inf")
M=max(a)
m=min(a)
data=[]
if abs(m)>abs(M):
    b=a.index(m)
    for i in range(n):
        data.append(str(b+1)+" "+str(i+1))
    for i in range(n-1):
        data.append(str(n-i)+" "+str(n-i-1))
else:
    b=a.index(M)
    for i in range(n):
        data.append(str(b+1)+" "+str(i+1))
    for i in range(1,n):
        data.append(str(i)+" "+str(i+1))
print(len(data))
for u in data:
    print(u)