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

MIN,MAX = 10**7,-10**7
ans = []
for i in range(N):
    if MIN > A[i]:
        MIN =A[i]
        min_i = i
    if MAX < A[i]:
        MAX = A[i]
        max_i = i

if abs(MIN) <= abs(MAX):
    for i in range(N):
        if A[i] < 0:
            A[i] += MAX
            ans.append([max_i+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] += MIN
            ans.append([min_i+1,i+1])
    

    for i in range(N-1,0,-1):
        if A[i] < A[i-1]:
            A[i-1] += A[i]
            ans.append([i+1,i])
print(len(ans))
for a in ans:
    print(*a)

Solution (Python):
N = int(input())
Z = list(map(int,input().split()))
A = []
for i in range(N):
  A.append([Z[i],i])
MIN = min(A)
MAX = max(A)


ans = []
num = 0
if abs(MIN[0]) > abs(MAX[0]):
  Flag = False
  minloc = MIN[1]
  for i in range(N):
    
    ans.append((minloc+1,i+1))
    num += 1
    A[i][0] += MIN[0]
else:
  Flag = True
  maxloc = MAX[1]
  for i in range(N):
    
    ans.append((maxloc+1,i+1))
    num +=1
    A[i][0] += MAX[0]

for i in range(N-1):
  if Flag == True:
    ans.append((i+1,i+2))
  else:
    ans.append((N-i,N-1-i))
  num+=1
print(num)
for i in range(len(ans)):
  print(*ans[i])

Solution (Python):
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,copy
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n = inp()
a = inpl()
mx = 0
pl = None
ind = -1
res = []
for i,x in enumerate(a):
    if abs(x) > mx:
        mx = abs(x)
        ind = i
        pl = True if x > 0 else False
if mx == 0:
    print(0)
    quit()
if not pl: mx *= -1
for i in range(n):
    if i == ind: continue
    res.append([ind+1,i+1])
    a[i] += mx
if pl:
    for i in range(n-1):
        res.append([i+1,i+2])
else:
    for i in range(n-1)[::-1]:
        res.append([i+2,i+1])
print(len(res))
for x in res:
    print(*x)

Solution (Python):
def main():
    MAX_ = 10 ** 6

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

    mi = MAX_
    mii = -1

    ma = -MAX_
    mai = -1

    for i, x in enumerate(A):
        if mi > x:
            mi = x
            mii = i + 1
        if ma < x:
            ma = x
            mai = i + 1

    if mi >= 0:
        print(N - 1)
        for i in range(1, N):
            print(i, i + 1)
        return

    if ma <= 0:
        print(N - 1)
        for i in range(N - 1, 0, -1):
            print(i + 1, i)
        return

    print((N - 1) * 2)
    if ma + mi >= 0:
        for i in range(1, N + 1):
            if i == mai: continue
            print(mai, i)
        for i in range(1, N):
            print(i, i + 1)
        return
    else:
        for i in range(1, N + 1):
            if i == mii: continue
            print(mii, i)
        for i in range(N - 1, 0, -1):
            print(i + 1, i)
        return


if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
lis = list(map(int,input().split()))
AngeKatrina = 0
LizeHelesta = 0
for i,InuiToko in list(enumerate(lis)):
  if InuiToko >= 0:
    if InuiToko >= AngeKatrina:
      AngeKatrina = InuiToko
      AngeSoko = i+1
  else:
    if -InuiToko >= LizeHelesta:
      LizeHelesta = -InuiToko
      LizeHiyoko = i+1
print(2*n-1)
if AngeKatrina >= LizeHelesta:
  for i in range(1,n+1):
    print(AngeSoko,i)
  for i in range(1,n):
    print(i,i+1)
else:
  for i in range(1,n+1):
    print(LizeHiyoko,i)
  for i in range(n,1,-1):
    print(i,i-1)

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
amin = min(A)
indmin = A.index(amin)+1
amax = max(A)
indmax = A.index(amax)+1
if amin>=0:
    print(N-1)
    for i in range(1,N):
        print(i,i+1)
elif amax<=0:
    print(N-1)
    for i in range(N,1,-1):
        print(i,i-1)
elif amax+amin>=0:
    print(2*(N-1))
    for i in range(1,N+1):
        if i!=indmax:
            print(indmax,i)
    for i in range(1,N):
        print(i,i+1)
elif amax+amin<0:
    print(2*(N-1))
    for i in range(1,N+1):
        if i!=indmin:
            print(indmin,i)
    for i in range(N,1,-1):
        print(i,i-1)

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

a = sorted(b)

a.sort()

max_i = 0
min_i = 0
maxv = -1<<60
minv = 1<<60
for i in range(n):
    if maxv < b[i]:
        maxv = b[i]
        max_i = i
    if minv > b[i]:
        minv = b[i]
        min_i = i

if (a[0] >= 0):
    print(n-1)
    for i in range(n-1):
        print(i+1,i+2)
elif (a[-1] <= 0):
    print(n-1)
    for i in reversed(range(n-1)):
        print(i+2,i+1)
elif (abs(a[0]) < abs(a[-1])):
    print(2*n-2)
    for i in range(n):
        if max_i == i:continue;
        print(max_i+1, i+1)
    for i in range(n-1):
        print(i+1,i+2)
else:
    print(2*n-2)
    for i in range(n):
        if min_i == i:continue;
        print(min_i+1, i+1)
    for i in reversed(range(n-1)):
        print(i+2,i+1)

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

if all(a==0 for a in A):
    print(0)
    exit()

INF = float('inf')
mn = INF
mx = -INF
mni = mxi = -1
for i,a in enumerate(A):
    if a > mx:
        mx = a
        mxi = i
    if a < mn:
        mn = a
        mni = i

ans = []
if mn >= 0:
    p = True
elif mx <= 0:
    p = False
else:
    if mx > -mn:
        for i,a in enumerate(A):
            if a < 0:
                ans.append((mxi+1, i+1))
        p = True
    else:
        for i,a in enumerate(A):
            if a > 0:
                ans.append((mni+1, i+1))
        p = False

if p:
    for i in range(1,N):
        ans.append((i,i+1))
else:
    for i in range(N,1,-1):
        ans.append((i,i-1))

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

Solution (Python):
import bisect
import copy
import heapq
import sys
import itertools
import math
import queue
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
mod = 10 ** 9 + 7

def read_values(): return map(int, input().split())
def read_index(): return map(lambda x: int(x) - 1, input().split())
def read_list(): return list(read_values())
def read_lists(N): return [read_list() for n in range(N)]


def main():
    N = int(input())
    A = read_list()
    M = max(A)
    m = min(A)

    T = M if abs(M) >= abs(m) else m
    i = A.index(T) + 1
    ans = []
    if T >= 0:
        for j, a in enumerate(A):
            if a < 0:
                ans.append((i, j + 1))
        for i in range(N - 1):
            ans.append((i + 1, i + 2))
    else:
        for j, a in enumerate(A):
            if a > 0:
                ans.append((i, j + 1))
        for i in range(N - 1, 0, -1):
            ans.append((i + 1, i))


    print(len(ans))
    for a, b in ans:
        A[b - 1] += A[a - 1]
        print(a, b)


if __name__ == "__main__":
    main()

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

Solution (Python):
import sys,queue,math,copy,itertools,bisect,collections,heapq

def main():
    sys.setrecursionlimit(10**7)
    INF = 10**7
    MOD = 10**9 + 7
    LI = lambda : [int(x) for x in sys.stdin.readline().split()]
    NI = lambda : int(sys.stdin.readline())
    SI = lambda : sys.stdin.readline().rstrip()

    N = NI()
    A = LI()
    ans = []

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

    if max_a * min_a < 0:
        p = max_a if abs(max_a) > abs(min_a) else min_a
        q = A.index(p)
        for i in range(N):
            ans.append((q+1,i+1))
            A[i] += p
        min_a = min(A)

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

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

if __name__ == '__main__':
    main()

Solution (Python):
def main():

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

    ans = []
    if min(A) >= 0:
        v = float('-inf')
        max_i = None
        for i in range(N):
            if A[i] > v:
                max_i = i
                v = A[i]

        ans.append([max_i, 0])
        for i in range(1, N):
            ans.append([i-1, i])
    elif max(A) <= 0:
        v = float('inf')
        min_i = None
        for i in range(N):
            if A[i] < v:
                min_i = i
                v = A[i]
        ans.append([min_i, N-1])
        for i in range(N-2, -1, -1):
            ans.append([i+1, i])
    elif abs(max(A)) >= abs(min(A)):
        v = float('-inf')
        max_i = None
        for i in range(N):
            if A[i] > v:
                max_i = i
                v = A[i]
        for i in range(N):
            if i != max_i:
                ans.append([max_i, i])
        ans.append([max_i, max_i])
        ans.append([max_i, 0])
        for i in range(1, N):
            ans.append([i-1, i])
    else:
        v = float('inf')
        min_i = None
        for i in range(N):
            if A[i] < v:
                min_i = i
                v = A[i]
        for i in range(N):
            if i != min_i:
                ans.append([min_i, i])
        ans.append([min_i, min_i])
        ans.append([min_i, N-1])
        for i in range(N-2, -1, -1):
            ans.append([i+1, i])

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

if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
A = list(map(int, input().split()))
M = max(A)
m = min(A)
M_idx = A.index(M) + 1
m_idx = A.index(m) + 1
print(2*n-1)
if abs(M) >= abs(m):
  for i in range(1, n+1):
    print(M_idx, i)
  for i in range(1, n):
    print(i, i+1)
else:
  for i in range(1, n+1):
    print(m_idx, i)
  for i in range(n-1, 0, -1):
    print(i+1, i)

Solution (Python):


import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))


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

m = max([abs(item) for item in a if item<=0] + [0])
M = max([abs(item) for item in a if item>=0] + [0])

def sub(i, j, a):
    print(i, j)
    a[j-1] += a[i-1]
    
print(2*n-1)
if M >= m:
    ind = a.index(M)+1
    for i in range(1,n+1):
        if i==ind:
            continue
        sub(ind, i, a)
    sub(ind, 1, a)
    for i in range(1, n):
        sub(i, i+1, a)
else:
    ind = a.index(-m)+1
    for i in range(1,n+1):
        if i==ind:
            continue
        sub(ind, i, a)
    sub(ind, n, a)
    for i in range(n, 1, -1):
        sub(i, i-1, a)

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

maxi = max(range(n), key=lambda x: a[x])
maxa = a[maxi]
mini = min(range(n), key=lambda x: a[x])
mina = a[mini]
out = []
if maxa > -mina:
    for i in range(1, n):
        while a[i] < a[i-1]:
            out.append((maxi+1, i+1))
            a[i] = a[i] + maxa
        if a[i] > maxa:
            maxa = a[i]
            maxi = i
else:
    for i in range(n-2, -1, -1):
        while a[i+1] < a[i]:
            out.append((mini+1, i+1))
            a[i] = a[i] + mina
        if a[i] < mina:
            mina = a[i]
            mini = i

print(len(out))
for o in out:
    print(o[0], o[1])

Solution (Python):

import sys
input = sys.stdin.buffer.readline


from collections import defaultdict

con = 10 ** 9 + 7

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


def main():
	N = int(input())
	A = getlist()
	M = max(A)
	p = A.index(M)
	m = min(A)
	q = A.index(m)
	if m >= 0:
		print(N - 1)
		for i in range(N - 1):
			print(i + 1, i + 2)
	else:
		if abs(M) > abs(m):
			print(2 * N - 1)
			for i in range(N):
				print(p + 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(q + 1, i + 1)
			for i in range(N - 1):
				print(N - i, N - 1 - i)

if __name__ == '__main__':
	main()

Solution (Python):



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


def main():
    mx = max(A)
    mn = min(A)
    idx = A.index(mn) if abs(mx) < abs(mn) else A.index(mx)
    idx += 1
    ans = []
    for i in range(N):
        ans.append((idx, i + 1))
    
    if A[idx - 1] > 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))
    
    n = len(ans)
    print(n)
    for i in range(n):
        print(*ans[i])


if __name__ == "__main__":
    main()

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

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

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

if(ma*mi < 0):
    print(2*n-1)
    if ma > -1*mi:
        for i in range(n):
            print(a.index(ma)+1, i+1)
        for i in range(n-1):
            print(i+1, i+2)
    else:
        for i in range(n):
            print(a.index(mi)+1, i+1)
        for i in range(n-1):
            print(n-i, n-i-1)
else:
    print(n-1)
    if(ma > 0):
        for i in range(n-1):
            print(i+1, i+2)
    else:
        for i in range(n-1):
            print(n-i, n-i-1)

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

if all(v>=0 for v in A):
    print(N-1)
    for i in range(1,N):
        print(i,i+1)
elif all(v<0 for v in A):
    print(N-1)
    for i in reversed(range(1,N)):
        print(i+1,i)
else:
    max_ind=A.index(max(A))+1
    min_ind = A.index(min(A))+1
    if abs(max(A))>=abs(min(A)):
        print(2*N-1)
        for i in range(1,N+1):
            print(max_ind,i)
        for i in range(1,N):
            print(i,i+1)
    else:
        print(2*N-1)
        for i in range(1,N+1):
            print(min_ind,i)
        for i in reversed(range(1,N)):
            print(i+1,i)

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

m=0
index=-1
for i in range(0,N):
    if abs(A[i])>m:
        m=abs(A[i])
        index=i

if index==-1:
    print(0)
else:
    if A[index]>0:
        operate=[]
        for i in range(0,N):
            if i!=index:
                operate.append((index+1,i+1))
                A[i]+=A[index]

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

        print(len(operate))
        for x,y in operate:
            print(x,y)
    else:
        operate=[]
        for i in range(0,N):
            if i!=index:
                operate.append((index+1,i+1))
                A[i]+=A[index]

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

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

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

print(2*n - 2)

M = a.index(max(a))
m = a.index(min(a))
if abs(a[m]) <= abs(a[M]):
    for i in range(n):
        if i != M:
            print(M+1,i+1)
    for i in range(n-1):
        print(i+1,i+2)
else:
    for i in range(n):
        if i != m:
            print(m+1,i+1)
    for i in range(1,n)[::-1]:
        print(i+1,i)

Solution (Python):
N = int(input())
a = list(map(int, input().split()))
if abs(max(a)) >= abs(min(a)):
    for i in range(N):
        if a[i] == max(a):
            num = i
            break
    print(2*N-1)
    for i in range(N):
        if num != i:
            print(num+1, i+1)
    print(num+1, num+1)
    for i in range(1,N):
        print(i, i+1)
else:
    for i in range(N):
        if a[i] == min(a):
            num = i
            break
    print(2*N-1)
    for i in range(N):
        if num != i:
            print(num+1, i+1)
    print(num+1, num+1)
    for i in range(N-1):
        print(N-i, N-i-1)

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

A.insert(0,-10000000)
B = copy(A)
ans = []
bns = []

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

A = B
for i in range(1,N)[::-1]:
    if A[i] > A[i+1]:
        if A[i] >= 0 and A[i+1] >= 0:
            A[i+1] += A[i]
            bns.append([i,i+1])
        elif A[i] <= 0 and A[i+1] <= 0:
            A[i] += A[i+1]
            bns.append([i+1,i])
        else:
            if abs(A[i]) <= abs(A[i+1]):
                A[i] += A[i+1]
                bns.append([i+1,i])
                A[i] += A[i+1]
                bns.append([i+1,i])
            else:
                A[i+1] += A[i]
                bns.append([i,i+1])
                A[i+1] += A[i]
                bns.append([i,i+1])
for i in range(1,N):
    if A[i] > A[i+1]:
        if A[i] >= 0 and A[i+1] >= 0:
            A[i+1] += A[i]
            bns.append([i,i+1])
        elif A[i] <= 0 and A[i+1] <= 0:
            A[i] += A[i+1]
            bns.append([i+1,i])
        else:
            if abs(A[i]) <= abs(A[i+1]):
                A[i] += A[i+1]
                bns.append([i+1,i])
                A[i] += A[i+1]
                bns.append([i+1,i])
            else:
                A[i+1] += A[i]
                bns.append([i,i+1])
                A[i+1] += A[i]
                bns.append([i,i+1])

M = len(ans)
L = len(bns)
if M <= L:
    print(M)
    for i in range(M):
        print(*ans[i])
else:
    print(L)
    for i in range(L):
        print(*bns[i])

Solution (Python):
N = int(input())
a = list(map(int, input().split()))
cnt1 = 0
li1 = []
for i in range(1,N):
    M = max(a)
    num = 0
    for j in range(N):
        if a[j] == M:
            n = j
    if a[i] < a[i-1]:
        if M <= 0:
            cnt1= -1
            break
        num += -((-a[i-1]+a[i])//M)
        if num < 0 or num > 2*N:
            cnt1 = -1
            break
        a[i] += num*M
        for j in range(num):
            li1.append([n+1, i+1])
        cnt1 += num
cnt2 = 0
li2 = []
for i in range(1,N):
    M = min(a)
    num = 0
    for j in range(N):
        if a[j] == M:
            n = j
    if a[N-i] < a[N-i-1]:
        if M >= 0:
            cnt2 = -1
            break
        num += -((-a[N-i-1]+a[N-i])//(-M))
        if num < 0 or num > 2*N:
            cnt2 = -1
            break
        a[N-i-1] += num *M
        for j in range(num):
            li2.append([n+1, N-i])
        cnt2 += num
if cnt1 <= 2*N and cnt1 >= 0:
    print(cnt1)
    for x in li1:
        print(*x)
else:
    print(cnt2)
    for x in li2:
        print(*x)

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

mx_i = 0
for i, e in enumerate(a):
    if abs(e) > abs(a[mx_i]):
        mx_i = i

ans = []
for i in range(n):
    if i == mx_i:
        continue
    a[i] += a[mx_i]
    ans.append([mx_i + 1, i + 1])

if a[mx_i] > 0:
    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 - 1, 0, -1):
        if a[i] < a[i-1]:
            a[i-1] += a[i]
            ans.append([i + 1, i])

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

Solution (Python):
from collections import defaultdict

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

for i in range(N):
    idx[a[i]] = i
    
m = min(a)
M = max(a)
ans = []

if abs(M)>abs(m):
    for i in range(N):
        ans.append((idx[M], i))
    
    for i in range(1, N):
        ans.append((i-1, i))
else:
    for i in range(N):
        ans.append((idx[m], i))
    
    for i in range(N-2, -1, -1):
        ans.append((i+1, i))

print(len(ans))

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

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

pair =[(a,i) for i,a in enumerate(As)]
pair.sort()
min_info = pair[0]
max_info = pair[-1]



print(2*N-1)
if abs(min_info[0]) > abs(max_info[0]):
    ind = pair[0][1]
    for i in range(N):
        print(ind+1, i+1)
    for i in range(N-1,0,-1):
        print(i+1,i)
else:
    ind = pair[-1][1]
    for i in range(N):
        print(ind+1, i+1)
    for i in range(1,N):
        print(i,i+1)

Solution (Python):
"""from collections import *
from itertools import *
from bisect import *
from heapq import *

import math
from fractions import gcd"""
import sys


import copy

N=int(input())
Amoto=list(map(int,input().split()))
lst=[]
A=copy.copy(Amoto)
_min=A[0]
minidx=0
for i in range(1,N):
    if _min>A[i]:
        _min=A[i]
        minidx=i
if _min<0:
    for i in range(N)[::-1]:
        while _min<A[i] and len(lst)<=2*N+1:
            A[i]+=_min
            lst.append([minidx+1,i+1])
        minidx=i
        _min=A[i]

    if  len(lst)<=2*N:
        print(len(lst))
        for i in lst:
            print(" ".join([str(x) for x in i ]))
        exit()
A=copy.copy(Amoto)
_max=A[0]
maxidx=0
lst=[]
for i in range(1,N):
    if _max<A[i]:
        _max=A[i]
        maxidx=i
if _max>0:
    for i in range(N):
        while _max>A[i] and len(lst)<=2*N+1:
            A[i]+=_max
            lst.append([maxidx+1,i+1])
        maxidx=i
        _max=A[i]
    if  len(lst)<=2*N:
        print(len(lst))
        for i in lst:
            print(" ".join([str(x) for x in i ]))
        exit()
else:
    print(0)

Solution (Python):

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



p = 0
m = 0
for i in range(N):
    if A[i] >= 0:
        p += 1
    else:
        m += 1



ans = []
if m == 0:
    for i in range(N-1):
        ans.append((i+1, i+2))
    print(len(ans))
    for x,y in ans:
        print(x,y)

elif p == 0:
    for i in range(N-1, 0, -1):
        ans.append((i+1, i))
    print(len(ans))
    for x,y in ans:
        print(x,y)
else:
    
    big = -1 * float("inf")
    big_idx = 0
    small = float("inf")
    small_idx = 0
    for i in range(N):
        if big < A[i]:
            big = A[i]
            big_idx = i

        if small > A[i]:
            small = A[i]
            small_idx = i

    
    if abs(big) >= abs(small): 
        for i in range(N):
            if A[i] < 0:
                ans.append((big_idx+1, i+1))

        for i in range(N-1):
            ans.append((i+1, i+2))
        print(len(ans))
        for x,y in ans:
            print(x,y)
    
    else:
        for i in range(N):
            if A[i] > 0:
                ans.append((small_idx+1, i+1))
        for i in range(N-1, 0, -1):
            ans.append((i+1, i))
        print(len(ans))
        for x,y in ans:
            print(x,y)

Solution (Python):
N = int(input())
a = list(map(int, input().split()))
m = min(a)
M = max(a)


flag = 1
plus = 0
minus = 0
for x in a:
    if x > 0:
        plus += 1
    elif x < 0:
        minus += 1
if m*M < 0:
    if m + M >= 0:
        id = a.index(M)
        print(minus + N-1)
        for i in range(N):
            if a[i] < 0:
                a[i] += M
                print(id+1, i+1)

    else:
        id = a.index(m)
        print(plus + N-1)
        for i in range(N):
            if a[i] > 0:
                a[i] += m
                print(id+1, i+1)

        flag = 0

else:
    print(N-1)
    if m < 0:
        flag = False


if flag:  
    
    
    for i in range(1, N):
        
        
        
        
        a[i] += a[i-1]
        print(i, i+1)

else:
    
    
    for i in range(N-2, -1, -1):
        
        
        
        
        a[i] += a[i+1]
        print(i+2, i+1)

Solution (Python):
from sys import stdout
printn = lambda x: stdout.write(str(x))
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True 
BIG = 999999999
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

n = inn()
a = inl()
mx = max([abs(x) for x in a])
p = [i for i in range(n) if abs(a[i])==mx][0]
seq = []
if a[p]>0:
    for i in range(1,n):
        while a[i-1]>a[i]:
            a[i] += a[p]
            seq.append((p,i))
        if a[i]>a[p]:
            p = i
elif a[p]<0:
    for i in range(n-2,-1,-1):
        while a[i]>a[i+1]:
            a[i] += a[p]
            seq.append((p,i))
        if a[i]<a[p]:
            p = i
print(len(seq))
for a,b in seq:
    print("{} {}".format(a+1,b+1))

Solution (Python):
n=int(input())
arr=list(map(int,input().split()))
arr=[[arr[i],i+1] for i in range(n)]
mins=10**18
minpos=0
maxs=-10**18
maxpos=0
for i in range(n):
  a=arr[i][0]
  if a<mins:
    mins=a
    minpos=i+1
  if maxs<a:
    maxs=a
    maxpos=i+1
ans=[]
if maxs<=0:
  flag=False
elif mins>=0:
  flag=True
else:
  if maxs>=abs(mins):
    flag=True
    for i in range(n):
      arr[i][0]+=maxs
      ans.append([maxpos,arr[i][1]])
  else:
    flag=False
    for i in range(n):
      arr[i][0]+=mins
      ans.append([minpos,arr[i][1]])
if flag==True:
  for i in range(1,n):
    ans.append([i,i+1])
else:
  for i in range(n,1,-1):
    ans.append([i,i-1])
print(len(ans))
for i in range(len(ans)):
  print(*ans[i])

Solution (Python):
n=int(input())
arr=list(map(int,input().split()))
arr=[[arr[i],i+1] for i in range(n)]
mins=[10**18,0]
maxs=[-10**18,0]
flag=True
for i in range(n):
  if arr[i][0]<mins[0]:
    mins=[arr[i][0],arr[i][1]]
  if arr[i][0]>maxs[0]:
    maxs=[arr[i][0],arr[i][1]]
cnt=0
ans=[]
if maxs[0]<0:
  for i in range(n):
    flag=False
elif mins[0]>=0:
  pass
else:
  if abs(mins[0])>maxs[0]:
    flag=False
    for i in range(n):
      if arr[i][0]>0:
        arr[i][0]+=mins[0]
        cnt+=1
        ans.append([mins[1],arr[i][1]])
  else:
    for i in range(n):
      if arr[i][0]<0:
        arr[i][0]+=maxs[0]
        cnt+=1
        ans.append([maxs[1],arr[i][1]])
rows=[]
tmp=[[arr[0][0],arr[0][1]]]
for i in range(1,n):
  if arr[i-1][0]<=arr[i][0]:
    tmp.append([arr[i][0],arr[i][1]])
  else:
    rows.append(tmp)
    tmp=[[arr[i][0],arr[i][1]]]
if len(tmp)!=0:
  rows.append(tmp)
if flag==True:
  for i in range(len(rows)-1):
    if len(rows[i])==1:
      if len(rows[i+1])==1:
        rows[i+1][0][0]+=rows[i][0][0]
        ans.append([rows[i][0][1],rows[i+1][0][1]])
  for i in range(len(rows)-1):
    if len(rows[i])==1:
      if len(rows[i+1])==1:
        continue
      else:
        for j in range(len(rows[i+1])):
          rows[i+1][j][0]+=rows[i][0][0]
          ans.append([rows[i][0][1],rows[i+1][j][1]])
    else:
      if len(rows[i+1])==1:
        for j in range(i+1,len(rows)):
          if len(rows[j])==1:
            rows[j][0][0]+=rows[i][-1][0]
            ans.append([rows[i][-1][1],rows[j][0][1]])
          else:
            break
      else:
        for j in range(len(rows[i+1])):
          rows[i+1][j][0]+=rows[i][-1][0]
          ans.append([rows[i][-1][1],rows[i+1][j][1]])
else:
  for i in range(len(rows)-1,0,-1):
    if len(rows[i])==1:
      if len(rows[i-1])==1:
        rows[i-1][0][0]+=rows[i][0][0]
        ans.append([rows[i][0][1],rows[i-1][0][1]])
  for i in range(len(rows)-1,0,-1):
    if len(rows[i])==1:
      if len(rows[i-1])==1:
        continue
      else:
        for j in range(len(rows[i-1])):
          rows[i-1][j][0]+=rows[i][0][0]
          ans.append([rows[i][0][1],rows[i-1][j][1]])
    else:
      if len(rows[i-1])==1:
        for j in range(i-1,-1,-1):
          if len(rows[j])==1:
            rows[j][0][0]+=rows[i][0][0]
            ans.append([rows[i][0][1],rows[j][0][1]])
          else:
            break
      else:
        for j in range(len(rows[i-1])):
          rows[i-1][j][0]+=rows[i][0][0]
          ans.append([rows[i][0][1],rows[i-1][j][1]])
print(len(ans))
for i in range(len(ans)):
  print(*ans[i])