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


from collections import* 
from fractions import gcd
from functools import* 
from itertools import* 
from operator import mul
from bisect import* 
from heapq import* 
from math import factorial
from copy import deepcopy
import sys

sys.setrecursionlimit(10**6)


def main():
    n,*a=map(int,open(0).read().split())
    if abs(max(a))>abs(min(a)):
        b=a.index(max(a))
        print(2*n-1)
        for i in range(n):
            print(b+1,i+1)
        for i in range(n-1):
            print(i+1,i+2)
    else:
        b=a.index(min(a))
        print(2*n-1)
        for i in range(n):
            print(b+1,i+1)
        for i in reversed(range(n-1)):
            print(i+2,i+1)

if __name__ == '__main__':
    main()

Solution (Python):



















import sys
input=sys.stdin.readline
inf=float('inf')
mod = 10**9+7
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 [input() 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()
    A_copy = []
    for i, a in enumerate(A,start=1):
        A_copy.append((a,i))

    A_copy.sort()
    if A_copy[-1][0] <= 0:
        print(N-1)
        
        for i in range(1,N)[::-1]:
            print(i+1,i)
            
    elif A_copy[0][0] >= 0:
        print(N-1)
        
        for i in range(1,N):
            print(i, i + 1)
            
    elif abs(A_copy[0][0]) > abs(A_copy[-1][0]):
        print(2*N-1)
        min_index = A_copy[0][1]
        for i in range(N):
            print(min_index, i + 1)
            
        for i in range(1,N)[::-1]:
            print(i + 1, i)
            
    else:
        print(2*N-1)
        max_index = A_copy[-1][1]
        for i in range(N):
            print(max_index, i + 1)
            
        for i in range(1,N):
            print(i, i + 1)
            
    
    

if __name__ == '__main__':
    main()

Solution (Python):



















import sys
input=sys.stdin.readline
inf=float('inf')
mod = 10**9+7
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 [input() 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()
    A_copy = []
    for i, a in enumerate(A,start=1):
        A_copy.append((a,i))

    A_copy.sort()
    if A_copy[-1][0] <= 0:
        print(N-1)
        
        for i in range(1,N)[::-1]:
            print(i+1,i)
            
    elif A_copy[0][0] >= 0:
        print(N-1)
        
        for i in range(1,N):
            print(i, i + 1)
            
    elif abs(A_copy[0][0]) > abs(A_copy[-1][0]):
        print(2*N-1)
        min_index = A_copy[0][1]
        for i in range(N):
            print(min_index, i + 1)
            
        for i in range(1,N)[::-1]:
            print(i + 1, i)
            
    else:
        print(2*N-1)
        max_index = A_copy[-1][1]
        for i in range(N):
            print(max_index, i + 1)
            
        for i in range(1,N):
            print(i, i + 1)
            
    
    

    """A_copy = []
    for i, a in enumerate(A,start=1):
        A_copy.append((a,i))

    A_copy.sort()
    A_indexes = [i for (a, i) in A_copy]
    print(2*N)
    for i,j in enumerate(A_indexes,start=1):
        print(i,j)
        print(i, j)
        A[i-1] += 2 * A[j-1]
    print(A)"""
if __name__ == '__main__':
    main()

Solution (Python):
import sys






















input = sys.stdin.readline
def ii(): return int(input())
def mi(): return map(int, input().rstrip().split())
def lmi(): return list(map(int, input().rstrip().split()))
def li(): return list(input().rstrip())



def iterate_tokens():
    for line in sys.stdin:
        for word in line.split():
            yield word


if __name__ == '__main__':

    tokens = iterate_tokens()
    N = int(next(tokens))  
    a = [int(next(tokens)) for _ in range(N)]  

    
    anslist = []
    MAX_A = max(a)
    MIN_A = min(a)
    if MIN_A >= 0:
        for i in range(1, N):
            anslist.append((i,i+1))
    elif MAX_A < 0:
        for i in range(N, 1, -1):
            anslist.append((i, i - 1))
    else:
        if abs(MAX_A) >= abs(MIN_A):
            MAX_INDEX = a.index(MAX_A)
            for i in range(1,N+1):
                anslist.append((MAX_INDEX+1, i))
            for i in range(1, N):
                anslist.append((i, i + 1))
        else:
            MIN_INDEX = a.index(MIN_A)
            for i in range(1, N + 1):
                anslist.append((MIN_INDEX+1, i))
            for i in range(N, 1, -1):
                anslist.append((i, i - 1))

            
    print(len(anslist))
    for tup in anslist:
        print(tup[0],tup[1])

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
m=0
mi=1
ans=[0 for i in range(n+1)]
for i,z in enumerate(a,1):
    if(abs(z)>abs(m)):
        m=z
        mi=i
if(m>=0):
    ans[1]=[mi,1]
    for i in range(2,n+1):
        ans[i]=[i-1,i]
else:
    ans[1]=[mi,n]
    for i in range(2,n+1):
        ans[i]=[n-i+2,n+1-i]
print(2*n)
for i in ans[1:]:
    print(i[0],i[1])
    print(i[0],i[1])

Solution (Python):

import sys
INF = float("inf")


def argmax(a):
    index, value = -1, -float("inf")
    for i, v in enumerate(a):
        if value < v:
            index, value = i, v
    return index, value


def argmin(a):
    index, value = -1, float("inf")
    for i, v in enumerate(a):
        if value > v:
            index, value = i, v
    return index, value


def solve(N: int, a: "List[int]"):
    
    amin_arg, amin = argmin(a)
    amax_arg, amax = argmax(a)
    ans = []
    if abs(amin) <= abs(amax):
        for i in range(N):
            if a[i] < 0:
                ans.append([amax_arg+1, i+1])
                a[i] += amax
        
        
        
        for i in range(N-1):
            if a[i] > a[i+1]:
                ans.append([i+1, i+2])
                a[i+1] += a[i]
        

    else:
        for i in range(N):
            if a[i] > 0:
                ans.append([amin_arg+1, i+1])
                a[i] += amin
        
        
        
        for i in range(N-1, 0, -1):
            if a[i-1] > a[i]:
                ans.append([i+1, i])
                a[i-1] += a[i]
        
    print(len(ans))
    for a in ans:
        print(*a)
    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()))

j = -1
m = -1
for i in range(n):
  t = abs(a[i])
  if t > m:
    j = i
    m = t
print(2*(n-1))
for i in range(n):
  if i == j:
    continue
  print(str(j+1)+" "+str(i+1))

if a[j]>0:
  for i in range(n-1):
    print(str(i+1)+" "+str(i+1+1))
else:
  for i in range(n-1):
    print(str(n-1-i+1)+" "+str(n-1-(i+1)+1))

Solution (Python):
import sys

sys.setrecursionlimit(10000)
INF = float('inf')


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


def print_ans(start):
    print(N * 2)
    for y in range(start, N):
        x = max(start, y - 1)
        print(x + 1, y + 1)
        print(x + 1, y + 1)
    for y in reversed(range(0, start)):
        x = min(start - 1, y + 1)
        print(x + 1, y + 1)
        print(x + 1, y + 1)


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

for start in range(N + 1):
    result = A.copy()
    
    for y in range(start, N):
        x = max(start, y - 1)
        result[y] += result[x] * 2
    
    for y in reversed(range(0, start)):
        x = min(start - 1, y + 1)
        result[y] += result[x] * 2
    if ok(result):
        print_ans(start)
        break

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

Solution (Python):
n = int(input())
as_ = list(int(i) for i in input().split())


def output_history(history):
    print(len(history))
    for h in history:
        print('{0} {1}'.format(h[0], h[1]))


def distribute(list_, hstr, x, y):
    list_[y] += list_[x]
    hstr.append((x + 1, y + 1))  
    return list_, hstr


history = []



if abs(max(as_)) > abs(min(as_)):
    
    
    x = as_.index(max(as_))
    while not all([a >= 0 for a in as_]):
        for y, a in enumerate(as_):
            if a < 0:
                as_, history = distribute(as_, history, x, y)

    
    for x in range(len(as_) - 1):
        
        if as_[x + 1] - as_[x] < 0:
            as_, history = distribute(as_, history, x, x + 1)

else:
    
    
    x = as_.index(min(as_))
    while not all([a <= 0 for a in as_]):
        for y, a in enumerate(as_):
            if a > 0:
                as_, history = distribute(as_, history, x, y)

    
    for x in reversed(range(len(as_) - 1)):
        
        if as_[x + 1] - as_[x] < 0:
            as_, history = distribute(as_, history, x + 1, x)

output_history(history)

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

Amax = max(A)
Amin = min(A)
ans = []
if Amax >= -Amin:
    im = A.index(Amax)+1
    i = 2
    while i <= N:
        if A[i-2] > A[i-1]:
            ans.append(str(im) + " " + str(i))
            A[i-1] += Amax
            if Amax < A[i-1]:
                im = i
                Amax = A[i-1]
        else:
            i += 1
else:
    im = A.index(Amin)+1
    i = N-1
    while i >= 1:
        if A[i-1] > A[i]:
            ans.append(str(im) + " " + str(i))
            A[i-1] += Amin
            if Amin > A[i-1]:
                im = i
                Amin = A[i-1]
        else:
            i -= 1
print(len(ans))
for out in ans:
    print(out)

Solution (Python):
N = int(input())
A = [int(i) for i in 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):
        print(N-i+1, N-i)
else:
    if max(A) > - min(A):
        M = 0
        M_index = 0
        for i in range(N):
            if M < A[i]:
                M = A[i]
                M_index = i
        ans = []
        for i in range(N):
            if A[i] < 0:
                ans.append((M_index+1, i+1))
        print(len(ans)+N-1)
        for x, y in ans:
            print(x, y)
        for i in range(1, N):
            print(i, i + 1)

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

Solution (Python):

from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LS()
    return l
sys.setrecursionlimit(1000000)
mod = 1000000007


def A():
    n,a,b = LI()
    print(min(n*a,b))
    return


def B():
    s = S()
    print(s.count("1"))
    return


def C():
    n = list(map(int, S()))
    k = 0
    s = sum(n)
    for i in range(len(n)):
        k *= 10
        k += n[i]
    if k%s == 0:
        print("Yes")
    else:
        print("No")
    return


def D():
    n = I()
    a = LI()
    ans = float("inf")
    for i in range(n):
        m = 0
        while a[i]%2 == 0:
            m += 1
            a[i] //= 2
        ans = min(m,ans)
    print(ans)
    return


def E():
    n = I()
    f = LIR(n)
    p = LIR(n)

    return


def F():
    n,k = LI()
    a = LI()
    d = defaultdict(int)
    for i in a:
        d[i] += 1
    d = list(d.values())
    d.sort()
    ans = 0
    for i in range(len(d)-k):
        ans += d[i]
    print(ans)
    return


def G():
    n,c = LI()
    ch = LIR(n)
    T = [[0 for i in range(100002)] for j in range(c+1)]
    for s,t,cha in ch:
        T[cha-1][s] += 1
        T[cha-1][t+1] -= 1
    for i in range(c):
        for j in range(100000):
            T[i][j+1] += T[i][j]
            if T[i][j] >= 1:
                T[i][j] = 1
    ans = 0
    for i in range(100001):
        m = 0
        for j in range(c+1):
            m += T[j][i]
        ans = max(m,ans)
    print(ans)
    return


def H():
    n = I()
    a = LI()
    ma = a.index(max(a))
    mi = a.index(min(a))
    ans = []
    if abs(a[ma]) > abs(a[mi]):
        ans.append([ma+1,1])
        ans.append([ma+1,1])
        a[0] += 2*a[ma]
        for i in range(n-1):
            ans.append([i+1,i+2])
            ans.append([i+1,i+2])
            a[i+1] += 2*a[i]
    else:
        ans.append([mi+1,n])
        ans.append([mi+1,n])
        a[-1] += 2*a[mi]
        for i in range(n-1)[::-1]:
            ans.append([i+2,i+1])
            ans.append([i+2,i+1])
            a[i] += 2*a[i+1]
    print(len(ans))
    for i in ans:
        print(*i)
    return


def I_():
    return


def J():
    return


if __name__ == "__main__":
    H()

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

MAX_ABS = 0
MAX_ABS_NUMBER = 0
MAX_ABS_NUMBER_INDEX = 1

for i, a in enumerate(A, start=1):
    if abs(a) > MAX_ABS:
        MAX_ABS = abs(a)
        MAX_ABS_NUMBER = a
        MAX_ABS_NUMBER_INDEX = i


if MAX_ABS_NUMBER >= 0:
    print(2 * N - 1)
    for i in range(1, N + 1):
        print(MAX_ABS_NUMBER_INDEX, i)
    for i in range(1, N):
        print(i, i + 1)

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

Solution (Python):
import sys
 
stdin = sys.stdin
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

N =ni()
A=na()
ma = max(A)
ma_in = A.index(ma)
mi = min(A)
mi_in = A.index(mi)
P=[]
if(ma==mi):
    pass
elif(ma<=0):
    for i in reversed(range(1,N)):
        P.append([i+1,i])
elif(mi>=0):
    for i in range(1,N):
        P.append([i,i+1])
else:
    if(abs(ma)>=abs(mi)):
        for i in range(N):
            if(A[i]<0):
                A[i]+=ma
                P.append([ma_in+1,i+1])
        for i in range(1,N):
            P.append([i,i+1])
            
    elif(abs(ma)<=abs(mi)):
        for i in range(N):
            if(A[i]>0):
                A[i]+=mi
                P.append([mi_in+1,i+1])
        for i in reversed(range(1,N)):
            P.append([i+1,i])
print(len(P))
for p in P:
    print(p[0],p[1])

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

mina = min(a)
min_index = a.index(mina)
maxa = max(a)
max_index = a.index(maxa)

if abs(maxa) > abs(mina):
    sign = maxa
    sign_id = max_index
else:
    sign = mina
    sign_id = min_index

print(n + n-1)

if sign >= 0:
    for i in range(n):
        a[i] += sign
        print(sign_id+1, i+1)
    for i in range(n-1):
        a[i+1] += a[i]
        print(i+1, i+2)
else:
    for i in range(n):
        a[i] += sign
        print(sign_id+1, i+1)
    for i in range(n-1):
        a[n-i-2] += a[n-i-1]
        print(n-i, n-i-1)

Solution (Python):
N=int(input())
A=list(map(int,input().split()))
Min=min(A)
Max=max(A)
if Min>=0:
    cnt=N-1
    ans=[]
    for i in range(1,N):
        ans.append((i,i+1))
elif Max<=0:
    cnt=N-1
    ans=[]
    for i in range(N-1,0,-1):
        ans.append((i+1,i))
else:
    if abs(Min)>=abs(Max):
        idx=A.index(Min)
        ans=[]
        cnt=2*N-1
        for i in range(N):
            ans.append((idx+1,i+1))
        for i in range(N-1,0,-1):
            ans.append((i+1,i))
    elif abs(Min)<abs(Max):
        idx=A.index(Max)
        ans=[]
        cnt=2*N-1
        for i in range(N):
            ans.append((idx+1,i+1))
        for i in range(1,N):
            ans.append((i,i+1))
print(cnt)
for i in range(cnt):
    print(str(ans[i][0])+' '+str(ans[i][1]))

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
mi = min(A)
ma = max(A)
g = 1
if mi > 0:
    g = 1
elif ma < 0:
    g = -1
elif abs(mi) < abs(ma):
    g = 1
else:
    g = -1

print(2*N-1)
if g == 1:
    mai = A.index(ma)
    print(mai+1,mai+1)
    A[mai] += A[mai]
    
    for i in range(N):
        if i != mai:
            print(mai+1,i+1)
            A[i] += A[mai]
            
    for i in range(N-1):
        print(i+1,i+2)
        A[i+1] += A[i]
        
else:
    mii = A.index(mi)
    print(mii+1,mii+1)
    A[mii] += A[mii]
    
    for i in range(N):
        if i != mii:
            print(mii+1,i+1)
            A[i] += A[mii]
            
    for i in range(N-1,0,-1):
        print(i+1,i)
        A[i-1] += A[i]

Solution (Python):

n = int(input())
a = list(map(int,input().split()))
m = min(a)
M = max(a)
mi = a.index(m)
Mi = a.index(M)
if all(a[i]<0 for i in range(n)):
    print(n-1)
    for i in range(n-2,-1,-1):
        print(i+2,i+1)
elif all(a[i]>0 for i in range(n)):
    print(n-1)
    for i in range(0,n-1):
        print(i+1,i+2)
else:
    print(2*n-1)
    if abs(M)>=abs(m):
        for i in range(0,n):
            print(Mi+1,i+1)
        for i in range(0,n-1):
            print(i+1,i+2)
    else:
        for i in range(0,n):
            print(mi+1,i+1)
        for i in range(n-2,-1,-1):
            print(i+2,i+1)

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

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

maxabs =(a[0])
maxidx = 0
for i in range(n):
    if abs(a[i]) >abs(maxabs):
        maxabs = a[i]
        maxidx = i 
res = []
for i in range(n):
    if a[i]*maxabs<0:
        a[i] += maxabs
        res.append((maxidx+1,i+1)) 
if maxabs>0:
    for i in range(1,n):
        res.append((i,i+1))
elif maxabs<0:
    for i in range(n,1,-1):
        res.append((i,i-1))

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

Solution (Python):

from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
sys.setrecursionlimit(1000000)
mod = 1000000007



def A():
    return


def B():
    return


def C():
    return


def D():
    n = I()
    a = LI()
    if sorted(a) == a:
        print(0)
        quit()
    ans = []
    ma = a.index(max(a))
    mi = a.index(min(a))
    if a[ma] > abs(a[mi]):
        if ma != 0:
            for i in range(2):
                ans.append([ma+1,1])
        for i in range(n-1):
            for j in range(2):
                ans.append([i+1,i+2])
    else:
        if mi != n-1:
            for i in range(2):
                ans.append([mi+1,n])
        for i in range(n-1)[::-1]:
            for j in range(2):
                ans.append([i+2,i+1])
    print(len(ans))
    for i,j in ans:
        print(i,j)

def E():
    return


def F():
    return


def G():
    return


def H():
    return


if __name__ == "__main__":
    D()

Solution (Python):
def non_decreasing(N: int, A: list) -> list:
    res = []

    
    
    
    min_a, max_a = min(A), max(A)
    min_i, max_i = A.index(min_a), A.index(max_a)

    if min_a * max_a < 0:
        
        
        if abs(min_a) < abs(max_a):
            
            
            res = [(max_i + 1, i + 1) for i in range(N) if i != max_i]
            for i in range(N):
                if i != max_i:
                    A[i] += max_a
            min_a += max_a
        else:
            
            
            res = [(min_i + 1, i + 1) for i in range(N) if i != min_i]
            for i in range(N):
                if i != min_i:
                    A[i] += min_a
            max_a += min_a

    
    if max_a <= 0:
        
        
        res += [(i, i - 1) for i in range(N, 1, -1)]
        for i in range(N-1, 0, -1):
            A[i - 1] += A[i]

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

    

    return res


if __name__ == "__main__":
    N = int(input())
    A = [int(s) for s in input().split()]
    ans = non_decreasing(N, A)
    print(len(ans))
    for x, y in ans:
        print(x, y)

Solution (Python):
import sys

def main():
    input = sys.stdin.readline
    N = int(input())
    A = list(map(int, input().split()))

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

    max_i = A.index(max_a)
    min_i = A.index(min_a)

    ans = []
    if abs(max_a) >= abs(min_a):
        while A[0] < max_a:
            A[0] += max_a
            ans.append([max_i, 0])

        for i in range(N-1):
            while A[i+1] < A[i]:
                A[i+1] += A[i]
                ans.append([i, i+1])
    else:
        while A[N-1] > min_a:
            A[N-1] += min_a
            ans.append([min_i, N-1])

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

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


if __name__ == '__main__':
    main()

Solution (Python):
def main():
    N = int(input())
    A = list(map(int, input().split()))
    C = []
    if max(A) + min(A) >= 0:
        x = A.index(max(A))
        for i in range(N):
            C.append((x+1, i+1))
        for i in range(1, N):
            C.append((i, i+1))
    else:
        x = A.index(min(A))
        for i in range(N):
            C.append((x+1, i+1))
        for i in range(N, 1, -1):
            C.append((i, i-1))
    print(len(C))
    for x, y in C:
        print(x, y)

if __name__ == "__main__":
    main()

Solution (Python):
N = int(input())
a_list = list(map(int, input().split()))
max_num = max(a_list)
min_num = min(a_list)
result = []
if abs(max_num) >= abs(min_num):
    max_index = a_list.index(max_num)
    for i, a in enumerate(a_list):
        if a < 0:
            a_list[i] += max_num
            result.append((max_index + 1, i + 1))

    for i in range(N - 1):
        if a_list[i] > a_list[i + 1]:
            result.append((i + 1, i + 2))
            a_list[i + 1] += a_list[i]
    print(len(result))
    for v1, v2 in result:
        print(v1, v2)

else:
    min_index = a_list.index(min_num)
    for i, a in enumerate(a_list):
        if a > 0:
            a_list[i] += min_num
            result.append((min_index + 1, i + 1))

    for i in reversed(range(N - 1)):
        if a_list[i] > a_list[i + 1]:
            result.append((i + 2, i + 1))
            a_list[i] += a_list[i + 1]
    print(len(result))
    for v1, v2 in result:
        print(v1, v2)
    exit()

Solution (Python):
N = int(input())
a_list = list(map(int, input().split()))
plus = True
minus = True

for a in a_list:
    if a > 0:
        minus = False

    if a < 0:
        plus = False

if plus:
    result = []
    for i in range(N - 1):
        if a_list[i] > a_list[i + 1]:
            result.append((i + 1, i + 2))
            a_list[i + 1] += a_list[i]
    print(len(result))
    for v1, v2 in result:
        print(v1, v2)
    exit()

if minus:
    result = []
    for i in reversed(range(N - 1)):
        if a_list[i] > a_list[i + 1]:
            result.append((i + 2, i + 1))
            a_list[i] += a_list[i + 1]
    print(len(result))
    for v1, v2 in result:
        print(v1, v2)
    exit()

max_num = max(a_list)
min_num = min(a_list)
result = []
if abs(max_num) >= abs(min_num):
    max_index = a_list.index(max_num)
    for i, a in enumerate(a_list):
        if a < 0:
            a_list[i] += max_num
            result.append((max_index + 1, i + 1))

    for i in range(N - 1):
        if a_list[i] > a_list[i + 1]:
            result.append((i + 1, i + 2))
            a_list[i + 1] += a_list[i]
    print(len(result))
    for v1, v2 in result:
        print(v1, v2)

else:
    min_index = a_list.index(min_num)
    for i, a in enumerate(a_list):
        if a > 0:
            a_list[i] += min_num
            result.append((min_index + 1, i + 1))
            
    for i in reversed(range(N - 1)):
        if a_list[i] > a_list[i + 1]:
            result.append((i + 2, i + 1))
            a_list[i] += a_list[i + 1]
    print(len(result))
    for v1, v2 in result:
        print(v1, v2)
    exit()

Solution (Python):
N = int(input())
A = [int(a) for a in input().split()]
maxi, maxA, mini, minA = 0, A[0], 0, A[0]
for i in range(1, N):
    if A[i] > maxA: maxi, maxA = i, A[i]
    if A[i] < minA: mini, minA = i, A[i]

Ans = []
if abs(maxA) >= abs(minA):
    for i in range(N):
        if A[i] < 0:
            Ans.append((maxi+1, i+1))
            A[i] += maxA
    for i in range(1, N):
        if A[i] < A[i-1]:
            Ans.append((i, i+1))
            A[i] += A[i-1]
else:
    for i in range(N):
        if A[i] > 0:
            Ans.append((mini+1, i+1))
            A[i] += minA
    for i in reversed(range(N-1)):
        if A[i] > A[i+1]:
            Ans.append((i+2, i+1))
            A[i] += A[i+1]

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

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
s = min(a)
b = max(a)
si = a.index(s)
bi = a.index(b)
op = []
if s + b >= 0:
    for i in range(n):
        if a[i] < 0:
            op.append((bi+1, i+1))
    for i in range(n-1):
        op.append((i+1, i+2))
else:
    for i in range(n):
        if a[i] > 0:
            op.append((si+1, i+1))
    for i in reversed(range(n-1)):
        op.append((i+2, i+1))
print(len(op))
for x, y in op:
    print(x, y)

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

ANS = []
B=A[:]
B.sort()

if abs(B[0]) > abs(B[-1]) :
    absmax = B[0]
else :
    absmax = B[-1]

ind = A.index(absmax)

if absmax != 0 :
    fugou = absmax // abs(absmax)

    for i in range(n) :
        if A[i] * fugou < 0 :
            ANS.append([ind+1, i+1])

    if fugou == 1 :
        if ind+1 != 1 :
            ANS.append([ind+1, 1])
        for i in range(n-1) :
            ANS.append([i+1, i+2])
    else :
        if ind+1 != n :
            ANS.append([ind+1, n])
        for i in range(n,1,-1) :
            ANS.append([i, i-1])

    print(len(ANS))
    for i in range(len(ANS)) :
        print("{} {}".format(ANS[i][0], ANS[i][1]))
else :
    print(0)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
m = 0
id = -1
for i in range(n):
  if abs(a[i]) >= abs(m):
    m = a[i]
    id = i
ope = []
for i in range(n):
  a[i] += m
  ope.append([id+1, i+1])
if m >= 0:
  for i in range(1, n):
    a[i] += a[i-1]
    ope.append([i, i+1])
else:
  for i in range(1, n):
    a[n-i-1] += a[n-i]
    ope.append([n-i+1, n-i])
print(len(ope))
for x in ope:
  print(x[0], x[1])

Solution (Python):
n=int(input())
A=list(map(int,input().split()))
Amax=max(A)
Amin=min(A)
ans=0
B=[]
if Amin>=0:
    ans=n-1
    for i in range(n-1):
        B.append([i+1,i+2])
elif Amax<=0:
    ans=n-1
    for i in range(n-1):
        B.append([n-i,n-i-1])
elif Amax>=-Amin:
    a=A.index(Amax)
    for i in range(n):
        if A[i]!=Amax:
            ans+=1
            B.append([a+1,i+1])
    for i in range(n-1):
        ans+=1
        B.append([i+1,i+2])
else:
    a=A.index(Amin)
    for i in range(n):
        if A[i]!=Amin:
            ans+=1
            B.append([a+1,i+1])
    for i in range(n-1):
        ans+=1
        B.append([n-i,n-i-1])
print(ans)
for b in B:
    print(' '.join(map(str,b)))

Solution (Python):


N = int(input())
a = list(map(int, input().split()))
a = [ [ea, e] for e,ea in enumerate(a)]

min_ = min(a)
max_ = max(a)


if min_[0] < 0 and abs(min_[0]) > abs(max_[0]):
    cnt = 0
    for i in range(N):
        if a[i][0] > 0:
            cnt += 1
    cnt += N-1
    print(cnt)

    for i in range(N):
        if a[i][0] > 0:
            print(min_[1] +1, i+1)
    for i in range(N-1, 0,-1):
        print(i+1, i)

    
else:
    cnt = 0
    for i in range(N):
        if a[i][0] < 0:
            cnt += 1

    cnt += N-1
    print(cnt)


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