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

Solution (Python):











import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,sqrt,factorial,hypot,log 
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from fractions import gcd
from random import randint
def ceil(a,b): return (a+b-1)//b
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N = I()
    A = LI()
    MAX = max(A)
    MIN = min(A)
    print(2*N-1)
    if abs(MAX)<abs(MIN):
        
        min_idx = A.index(MIN) + 1
        for i in range(1,N+1):
            print(min_idx, i)
        
        for i in range(2,N+1)[::-1]:
            print(i,i-1)
    else:
        
        max_idx = A.index(MAX) + 1
        for i in range(1,N+1):
            print(max_idx, i)
        
        for i in range(1,N):
            print(i,i+1)


if __name__ == '__main__':
    main()

Solution (Python):

def nonDecreasing(N, A):
    Amin = min(A)
    Amax = max(A)
    Amin_index = A.index(Amin)+1
    Amax_index = A.index(Amax)+1

    res = []

    
    
    if abs(Amax) > abs(Amin):
        for i in range(1, N):
            while A[i - 1] > A[i]:
                A[i] += Amax
                res.append((Amax_index, i+1))
                if A[i] > Amax:
                    Amax = A[i]
                    Amax_index = i+1

    
    
    else:
        for i in range(N - 1, 0, -1):
            while A[i - 1] > A[i]:
                A[i - 1] += Amin
                res.append((Amin_index, i))
                if A[i - 1] < Amin:
                    Amin = A[i - 1]
                    Amin_index = i
    return res


if __name__ == "__main__":
    N = int(input())
    A = list(map(int, input().split()))
    ans = nonDecreasing(N, A)

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

Solution (Python):
import sys
input = sys.stdin.readline
N = int(input())
a = list(map(int, input().split()))
mx = max(a)
mn = min(a)
res = []
if abs(mx) >= abs(mn):
  t = 0
  for i in range(N):
    if a[i] == mx:
      t = i
      break
  for i in range(N):
    res.append((t + 1, i + 1))
    a[i] += a[t]
  for i in range(N):
    for j in range(N):
      if a[j] > a[t]: t = j
    res.append((t + 1, i + 1))
    a[i] += a[t]
  print(len(res))
  for r in res: print(*r)
else:
  t = 0
  for i in range(N):
    if a[i] == mn:
      t = i
      break
  for i in range(N):
    res.append((t + 1, i + 1))
    a[i] += a[t]
  for i in range(N - 1, -1, -1):
    for j in range(N):
      if a[j] < a[t]: t = j
    res.append((t + 1, i + 1))
    a[i] += a[t]
  print(len(res))
  for r in res: print(*r)

Solution (Python):
inpl = lambda: list(map(int,input().split()))
N = int(input())
a = inpl()
ans = []
c = []
l, r = 0, N-1
while l < r:
    if a[l] <= 0:
        c.append((0,l))
        l += 1
        continue
    elif a[r] >= 0:
        c.append((1,r))
        r -= 1
        continue
    elif a[l] + a[r] <= 0:
        c.append((0,l))
        ans.append((r+1, l+1))
        l += 1
    else:
        c.append((1,r))
        ans.append((l+1, r+1))
        r -= 1

for s, b in c[::-1]:
    if s == 0:
        ans.append((b+2, b+1))
    else:
        ans.append((b, b+1))

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

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
cmax = 0
a = 0
ind = -1
for i in range(N):
    if abs(A[i])>cmax:
        cmax = abs(A[i])
        a = A[i]
        ind = i
if a>0:
    B = []
    for i in range(N):
        if A[i]<0:
            A[i] += a
            B.append([ind+1,i+1])
    for i in range(1,N):
        A[i] += A[i-1]
        B.append([i,i+1])
    print(len(B))
    for j in range(len(B)):
        print(*B[j])
elif a<0:
    B = []
    for i in range(N):
        if A[i]>0:
            A[i] += a
            B.append([ind+1,i+1])
    for i in range(N-2,-1,-1):
        A[i] += A[i+1]
        B.append([i+2,i+1])
    print(len(B))
    for j in range(len(B)):
        print(*B[j])
else:
    print(0)

Solution (Python):
N, = map(int, input().split())
As = list(map(int, input().split()))
a,b = max(As), min(As)
ai = As.index(a)
bi = As.index(b)
print(N-1+N-1)
if a > -b:
    for i in range(N):
        if i != ai:
            print(ai+1, i+1)
    for i in range(N-1):
        print(i+1, i+2)
else:
    for i in range(N):
        if i != bi:
            print(bi+1, i+1)
    for i in range(N-1):
        print(N-i, N-i-1)

Solution (Python):
import sys


sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))


N = ir()
A = lr()
if abs(max(A)) >= abs(min(A)):
    i = A.index(max(A))
    print(2*(N-1))
    print(i+1, 2)
    print(i+1, 2)
    for i in range(2, N):
        print(i, i+1)
        print(i, i+1)
else:
    i = A.index(min(A))
    print(2*(N-1))
    print(i+1, N-1)
    print(i+1, N-1)
    for i in range(2, N):
        print(N-i+1, N-i)
        print(N-i+1, N-i)

Solution (Python):
n,*a=map(int,open(0).read().split())
ans=[str(2*n-1)]
if max(a)>-min(a):
	i=a.index(max(a))
	for k in range(n):
		ans.append("{} {}".format(i+1,k+1))
	for k in range(n-1):
		ans.append("{} {}".format(k+1,k+2))
else:
	i=a.index(min(a))
	for k in range(n):
		ans.append("{} {}".format(i+1,k+1))
	for k in range(n-1):
		ans.append("{} {}".format(n-k,n-k-1))
print("\n".join(ans))

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

ans = []
def f1():
  for i in range(1,N):
    mx = -(10**7)
    mxi = 0
    for j in range(N):
      if A[j] > mx:
        mx = A[j]
        mxi = j
    A[i] += mx
    ans.append((mxi,i))
def f2():
  for i in range(N-2,-1,-1):
    mn = 10**7
    mni = 0
    for j in range(N):
      if A[j] < mn:
        mn = A[j]
        mni = j
    A[i] += mn
    ans.append((mni,i))

mx = -(10**7)
mxi = 0
mn = 10**7
mni = 0
for i in range(N):
  if A[i] > mx:
    mx = A[i]
    mxi = i
  if A[i] < mn:
    mn = A[i]
    mni = i
if mn >= 0:
  f1()
elif mx <= 0:
  f2()
elif mx >= abs(mn):
  for i in range(N):
    if A[i] < 0:
      A[i] += mx
      ans.append((mxi,i))
  f1()
else:
  for i in range(N):
    if A[i] > 0:
      A[i] += mn
      ans.append((mni,i))
  f2()

print(len(ans))
for a1,a2 in ans:
  print(a1+1,a2+1)

Solution (Python):
import sys
input = sys.stdin.readline
N = int(input())
a = list(map(int, input().split()))
mx = -float("inf")
mn = float("inf")
mxi = 0
mni = 0
for i in range(N):
  x = a[i]
  if mx < x:
    mx = x
    mxi = i
  if mn > x:
    mn = x
    mni = i
print(2 * N - 1)
if abs(mx) > abs(mn):
  for i in range(N): print(mxi + 1, i + 1)
  for i in range(N - 1): print(i + 1, i + 2)
else:
  for i in range(N): print(mni + 1, i + 1)
  for i in range(N - 1, 0, -1): print(i + 1, i)

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

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

Solution (Python):
import sys
import math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N,num):
    if N<=0:
        return [[]]*num
    elif num==1:
        return [I() for _ in range(N)]
    else:
        read_all = [tuple(II()) for _ in range(N)]
        return map(list, zip(*read_all))



def my_sign(x):
    return (x > 0) - (x < 0)

N = I()
a = III()

max_val = 0
max_sign = 0
max_index = -1
for i,a0 in enumerate(a):
    if abs(a0)>max_val:
        max_val = abs(a0)
        max_sign = my_sign(a0)
        max_index = i

if max_sign==0:
    print(0)
elif max_sign==1:
    print(2*N-1)
    for i in range(N):
        print(max_index+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(max_index+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()))
maxA = max(A)
minA = min(A)

if minA >=0 or 2*abs(maxA)>abs(minA):
  maxi = A.index(maxA)
  print(2*N-1)
  print(maxi+1,maxi+1)

  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)
  print(2*N-1)
  print(mini+1,mini+1)
  for i in range(N):
    if i == mini: continue
    print(mini+1, i+1)
  
  for i in range(N-1, 0, -1):
    print(i+1,i)

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")

def main():
    n = int(input())
    aa = list(map(int, input().split()))
    inf = 10 ** 7
    max_a = -inf
    min_a = inf
    max_i = min_i = -1
    for i, a in enumerate(aa):
        if a > max_a:
            max_a = a
            max_i = i
        if a < min_a:
            min_a = a
            min_i = i
    print(2 * n - 1)
    if max_a + min_a >= 0:
        for i in range(n):
            print(max_i + 1, i + 1)
        for i in range(n - 1):
            print(i + 1, i + 2)
    else:
        for i in range(n):
            print(min_i + 1, i + 1)
        for i in range(n - 1, 0, -1):
            print(i + 1, i)

main()

Solution (Python):

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

ans = []

max_ = max(a)
min_ = min(a)
if max_ * min_ < 0:
    if abs(max_) >= abs(min_):
        ind = a.index(max_)
        for i in range(n):
            if i == ind:
                continue
            ans.append((ind, i))
        a = [a_ + max_ for a_ in a]

    else:
        ind = a.index(min_)
        for i in range(n):
            if i == ind:
                continue
            ans.append((ind, i))
        a = [a_ + min_ for a_ in a]

max_ = max(a)
min_ = min(a)
if min_ >= 0:
    for i in range(n - 1):
        ans.append((i, i + 1))
        a[i + 1] += a[i]
elif max_ <= 0:
    for i in range(n - 1, 0, -1):
        ans.append((i, i - 1))
        a[i - 1] += a[i]

print(len(ans))
for op in ans:
    print(*map(lambda x: x + 1, op))

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

min_a = 10**6+1
max_a = -10**6-1
for i in range(N):
    if a[i] < min_a:
        min_a = a[i]
        i_min = i
    if a[i] > max_a:
        max_a = a[i]
        i_max = i

print(2 * (N-1))
if abs(max_a) >= abs(min_a):
    for i in range(N):
        if i != i_max:
            print(i_max+1, i+1)
    for i in range(N-1):
        print(i+1, i+2)
else:
    for i in range(N):
        if i != i_min:
            print(i_min+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()))
if min(a) >= 0:
    print(n - 1)
    for i in range(n - 1):
        print(i + 1, i + 2)
elif max(a) <= 0:
    print(n - 1)
    for i in range(n - 1):
        print(n - i, n - i - 1)
else:
    print(2 * n - 1)
    if abs(min(a)) <= abs(max(a)):
        idx = a.index(max(a))
        for i in range(n):
            print(idx + 1, i + 1)
        for i in range(n - 1):
            print(i + 1, i + 2)
    else:
        idx = a.index(min(a))
        for i in range(n):
            print(idx + 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()))
m,M=10**7,-10**7
for i,a in enumerate(A):
    if a<m:
        mi,m=i+1,a
    if a>M:
        Mi,M=i+1,a
if m*M<0:
    print(2*N-1)
    if abs(m)<abs(M):
        print(*[str(Mi)+' '+str(i) for i in range(1,N+1)],sep='\n')
        m=0
    else:
        print(*[str(mi)+' '+str(i) for i in range(1,N+1)],sep='\n')
else:
    print(N-1)
if m>=0:
    print(*[str(i)+' '+str(i+1) for i in range(1,N)],sep='\n')
else:
    print(*[str(i+1)+' '+str(i) for i in range(N-1,0,-1)],sep='\n')

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

mina = 10**10
maxa = -10**10
for i, a in enumerate(A):
    if a < mina:
        l = i+1
        mina = a
    if a > maxa:
        r = i+1
        maxa = a


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

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

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

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

Solution (Python):
import numpy as np

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





i = max(range(N), key=lambda j: abs(a[j])) + 1
ans = '{}\n{}'.format(
    2 * N,
    '\n'.join(
        [
            '{} {}'.format(i, j)
            for j in range(1, N + 1)
            if j != i
        ] +
        [
            '{} {}'.format(i, i)
        ] +
        (
            [
                '{} {}'.format(i, 1)
            ] +
            [
                '{} {}' .format(j, j + 1)
                for j in range(1, N)
            ] if a[i - 1] >= 0 else
            [
                '{} {}'.format(i, N)
            ] +
            [
                '{} {}'.format(j + 1, j)
                for j in reversed(range(1, N))
            ]
        )
    )
)

print(ans)

Solution (Python):


from sys import stdout
from bisect import bisect_left as binl
from copy import copy, deepcopy
from collections import defaultdict
import math


mod = 1


def intin():
    input_tuple = input().split()
    if len(input_tuple) <= 1:
        return int(input_tuple[0])
    return tuple(map(int, input_tuple))


def intina():
    return [int(i) for i in input().split()]


def intinl(count):
    return [intin() for _ in range(count)]


def modadd(x, y):
    global mod
    return (x + y) % mod


def modmlt(x, y):
    global mod
    return (x * y) % mod


def mod_inv(x):
    
    global mod
    return pow(x, mod - 2, mod)


def gcm(x, y):
    while y != 0:
        z = x % y
        x = y
        y = z
    return x


def combination(x, y):
    assert(x >= y)

    ret = math.factorial(x)
    ret = ret // (math.factorial(x - y) * math.factorial(y))

    return ret


def get_divisors(x):
    retlist = []
    for i in range(1, int(x**0.5) + 3):
        if x % i == 0:
            retlist.append(i)
            retlist.append(x // i)
    return retlist


def get_factors(x):
    retlist = []
    for i in range(2, int(x**0.5) + 3):
        while x % i == 0:
            retlist.append(i)
            x = x // i
    retlist.append(x)
    return retlist


def make_linklist(xylist):
    linklist = {}
    for a, b in xylist:
        linklist.setdefault(a, [])
        linklist.setdefault(b, [])
        linklist[a].append(b)
        linklist[b].append(a)
    return linklist


def calc_longest_distance(linklist, v=1):
    distance_list = {}
    distance_count = 0
    distance = 0
    vlist_previous = []
    vlist = [v]
    nodecount = len(linklist)

    while distance_count < nodecount:
        vlist_next = []
        for v in vlist:
            distance_list[v] = distance
            distance_count += 1
            vlist_next.extend(linklist[v])
        distance += 1
        vlist_to_del = vlist_previous
        vlist_previous = vlist
        vlist = list(set(vlist_next) - set(vlist_to_del))

    max_distance = -1
    max_v = None
    for v, distance in distance_list.items():
        if distance > max_distance:
            max_distance = distance
            max_v = v

    return (max_distance, max_v)


def calc_tree_diameter(linklist, v=1):
    _, u = calc_longest_distance(linklist, v)
    distance, _ = calc_longest_distance(linklist, u)
    return distance


class UnionFind:

    def __init__(self, n):
        self.parent = [i for i in range(n)]

    def root(self, i):
        if self.parent[i] == i:
            return i
        self.parent[i] = self.root(self.parent[i])
        return self.parent[i]

    def unite(self, i, j):
        rooti = self.root(i)
        rootj = self.root(j)
        if rooti == rootj:
            return
        if rooti < rootj:
            self.parent[rootj] = rooti
        else:
            self.parent[rooti] = rootj

    def same(self, i, j):
        return self.root(i) == self.root(j)





def main():
    n = intin()
    alist = intina()

    absmax = -float('inf')
    absidx = -1

    for i, a in enumerate(alist):
        if abs(a) > absmax:
            absmax = abs(a)
            absidx = i

    if alist[absidx] == 0:
        print(0)
        return

    print(n * 2)

    if alist[absidx] > 0:
        for i in range(n):
            print('%d %d' % (absidx+1, i+1))
            print('%d %d' % (absidx+1, i+1))
            alist[i] += alist[absidx]
            alist[i] += alist[absidx]
            absidx = i

    else:
        for i in range(n-1, -1, -1):
            print('%d %d' % (absidx+1, i+1))
            print('%d %d' % (absidx+1, i+1))
            alist[i] += alist[absidx]
            alist[i] += alist[absidx]
            absidx = i


if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
mx = max(a)
mn = min(a)
ans = []
if abs(mx)>=abs(mn):
    mx_ind = a.index(mx)
    for i in range(n):
        a[i] += mx
        ans.append([mx_ind+1,i+1])
    for i in range(1,n):
        a[i] += a[i-1]
        ans.append([i,i+1])
else:
    mn_ind = a.index(mn)
    for i in range(n):
        a[i] += mn
        ans.append([mn_ind+1,i+1])
    for i in range(n-1,0,-1):
        a[i-1] += a[i]
        ans.append([i+1,i])
print(len(ans))
for x,y in ans:
    print(x,y)

Solution (Python):
import numpy as np

N = int(input())
A = np.array([0] + [int(x) for x in input().split()])

A_abs = np.abs(A)

x = A_abs.argmax()
if x == 0:
  x = 1
value = A[x]

answer = []

for j in range(1,N+1):
  if j == x:
    continue
  answer.append((x,j))


if value > 0:
  for j in range(1,N):
    answer.append((j,j+1))
else:
  for j in range(N,1,-1):
    answer.append((j,j-1))
    
print(len(answer))
for a,b in answer:
  print(a,b)

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

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 ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N=INT()
A=LIST()

ans=[]
mn=min(A)
mnidx=A.index(mn)+1
mx=max(A)
mxidx=A.index(mx)+1
if mn<0 and mx>0:
    if abs(mx)>=abs(mn):
        for i in range(N):
            A[i]+=mx
            ans.append((mxidx, i+1))
        mn=min(A)
    else:
        for i in range(N):
            A[i]+=mx
            ans.append((mnidx, i+1))
        mx=max(A)

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

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

Solution (Python):
n = int(input())
a = [int(i) for i in input().split(" ")]
cs = []

def argmax(a):
    m = a[0]
    mi = 0
    for i in range(1, len(a)):
        if m < a[i]:
            m = a[i]
            mi = i
    return (m, mi)

def argmin(a):
    m = a[0]
    mi = 0
    for i in range(1, len(a)):
        if m > a[i]:
            m = a[i]
            mi = i
    return (m, mi)


mx, argmx = argmax(a)
mi, argmi = argmin(a)

if mx + mi >= 0:
    for i in range(0, n):
        if a[i] < 0 and a[i] < mx:
            a[i] += mx
            cs.append((argmx, i))
    for i in range(1, n):
        a[i] += a[i - 1]
        cs.append((i - 1, i))
else:
    for i in range(0, n):
        if a[i] > 0 and a[i] > mi:
            a[i] += mi
            cs.append((argmi, i))
    for i in reversed(range(0, n - 1)):
        a[i] += a[i + 1]
        cs.append((i + 1, i))

print(len(cs))
for c in cs:
    print(c[0] + 1, c[1] + 1)

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

max_a = -float("inf")
max_index = 0 
min_a = float("inf")
min_index = 0
ans_li = []
for i in range(n):
    if a[i] >= max_a:
        max_a = a[i]
        max_index = i
    if a[i] <= min_a:
        min_a = a[i]
        min_index = i


if max_a == min_a:
    print(0)
elif 0 <= min_a:
    print(n-1)
    for i in range(n-1):
        print(i+1, i+2)
elif max_a <= 0:
    print(n-1)
    for i in range(n-1)[::-1]:
        print(i+2, i+1)
elif abs(min_a) <= abs(max_a):
    print(2*n-1)
    for i in range(n):
        print(max_index+1, i+1)
    for i in range(n-1):
        print(i+1, i+2)
elif abs(max_a) <= abs(min_a):
    print(2*n-1)
    for i in range(n):
        print(min_index+1, i+1)
    for i in range(n-1)[::-1]:
        print(i+2, i+1)

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

bool = True
cnt=a[0]
for i in range(len(a)-1):
    if a[i+1] != cnt:
        bool = False
if bool == True:
    print("0")
    exit()

def num_place(num,a):
    for i in range(len(a)):
        if num == a[i]:
            x = i
    return x

cnt_list=[]
max=max(a)
min=min(a)
if max >= abs(min):
    cnt_list.append([num_place(max,a),0])
    a[0] += max

    for i in range(len(a)-1):
        if a[i] > a[i+1]:
            a[i+1] += a[i]
            cnt_list.append([i,i+1])
        if a[i] > a[i+1]:
            a[i+1] += a[i]
            cnt_list.append([i,i+1])
else:
    cnt_list.append([num_place(min,a),N-1])
    a[N-1] += min
    for i in range(len(a)-1,0,-1):
        if a[i] < a[i-1]:
            a[i-1] += a[i]
            cnt_list.append([i,i-1])
        if a[i] < a[i-1]:
            a[i-1] += a[i]
            cnt_list.append([i,i-1])

print(len(cnt_list))
for i in  cnt_list:
    print("{} {}".format(i[0]+1,i[1]+1))

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
if all([a==0 for a in A]):
  print(0)
  exit()

answer = []
posA = [i for i, a in enumerate(A) if a>0]
negA = [i for i, a in enumerate(A) if a<0]

if sum(A) >= 0:
  key = posA[0]
  for a in posA[1:]:
    answer.append([a, key]) 
  for a in negA:
    answer.append([key, a]) 
  for i in range(N-1):
    answer.append([i,i+1]) 

if sum(A) < 0:
  key = negA[0]
  for a in negA[1:]:
    answer.append([a, key]) 
  for a in posA:
    answer.append([key, a]) 
  for i in range(N-1,0,-1):
    answer.append([i,i-1]) 

print(len(answer))

for a in answer:
  print(' '.join(map(lambda x: str(x+1), a)))

Solution (Python):
n = int(input())
alist = list(map(int, input().split()))
maxa, mina = max(alist), min(alist)

ans = []
if abs(maxa) >= abs(mina):
  p = alist.index(maxa) + 1
  for i in range(n):
    alist[i] += maxa
    ans.append((p, i+1))
  for i in range(n-1):
    alist[i+1] += alist[i]
    ans.append((i+1, i+2))
else:
  p = alist.index(mina) + 1
  for i in range(n):
    alist[i] += mina
    ans.append((p, i+1))
  for i in range(n-2, -1, -1):
    alist[i] += alist[i+1]
    ans.append((i+2, i+1))

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

Solution (Python):
import sys
n = int(input())
a = list(map(int, input().split()))
ans = []
Ma = 0
iMa = -1
for i in range(n):
	if abs(a[i]) > Ma:
		Ma = abs(a[i])
		iMa = i
if Ma == 0:
	print(0)
	sys.exit()
for i in range(n):
	if a[i] * a[iMa] < 0:
		a[i] += a[iMa]
		ans.append([iMa+1, i+1])
if a[iMa] > 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-1] > a[i]:
			a[i-1] += a[i]
			ans.append([i+1, i])

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

Solution (Python):
N = int( input())
A = list( map( int, input().split()))
B = [ ( abs(A[i]), i) for i in range(N)]
B.sort( key=None, reverse = True)
_,s = B[0]
ans = 0
ANS = []
if A[s] == 0:
    pass
else:
    for i in range(N):
        if i == s:
            continue
        ANS.append( str(s+1) + " " + str(i+1))
        ans += 1
    if A[s] > 0:
        for i in range(N-1):
            ANS.append( str(i+1) + " " + str(i+2))
            ans += 1
    else:
        for i in range(N-1, 0, -1):
            ANS.append( str(i+1) + " " + str(i))
            ans += 1
print(ans)
for i in range(ans):
    print( ANS[i])

Solution (Python):
N = int(input())
A = [int(i) for i in input().split()]
max_i = A.index(max(A))
min_i = A.index(min(A))
abs_max_i = max(max_i,min_i,key = lambda x:abs(A[x]))
print(2*N-2)
for i in range(N):
    [print("{} {}".format(abs_max_i+1, i+1)) if i != abs_max_i else None]
if A[abs_max_i] > 0:
    for i in range(N-1):
        print("{} {}".format(i+1, i+2))
else:
    for i in range(N-1,0,-1):
        print("{} {}".format(i+1, i))

Solution (Python):
N = int(input())
a = list(map(int,input().split()))
pos_max = max(a)
neg_max = min(a)
res = []
if abs(pos_max) >= abs(neg_max):
    
    pos = a.index(pos_max) + 1
    for i in range(N):
        a[i] += pos_max
        res.append([pos, i + 1])
    
    for i in range(N-1):
        a[i+1] += a[i]
        res.append([i + 1, i + 2])
else:
    
    pos = a.index(neg_max) + 1
    for i in range(N):
        a[i] += neg_max
        res.append([pos, i + 1])
    
    for i in range(N-2,-1,-1):
        a[i] += a[i+1]
        res.append([i + 2, i + 1])


print(len(res))
for l in res:
    print(*l)

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
syo = min(a)
dai = max(a)
ans = []
if abs(syo) >= abs(dai):
  ind = a.index(syo)
  ind += 1
  for i in range(n):
    ans.append([ind,i+1])
  for i in range(n,1,-1):
    ans.append([i,i-1])
  print(len(ans))
  for i in ans:
    print(*i)
else:
  ind = a.index(dai)
  ind += 1
  for i in range(n):
    ans.append([ind,i+1])
  for i in range(1,n):
    ans.append([i,i+1])
  print(len(ans))
  for i in ans:
    print(*i)

Solution (Python):
import sys

sys.stdin.readline()
lst = list(map(int, sys.stdin.readline().split()))
N = len(lst)

max_val, max_t = lst[0], 0
min_val, min_t = lst[0], 0

for t in range(1, len(lst)):
    if max_val < lst[t]:
        max_val = lst[t]
        max_t = t
    if min_val > lst[t]:
        min_val = lst[t]
        min_t = t

if max_val >= -min_val:
    print(2 * N - 2)
    for i in range(len(lst)):
        if i == max_t:
            continue
        print(max_t + 1, i + 1)
    for i in range(1, len(lst)):
        print(i, i + 1)
else:
    print(2 * N - 2)
    for i in range(len(lst)):
        if i == min_t:
            continue
        print(min_t + 1, i + 1)
    for i in range(len(lst), 1, -1):
        print(i, i - 1)

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