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()))
amin=min(a)
amax=max(a)
imin=a.index(min(a))+1
imax=a.index(max(a))+1
if amin>=0:
  print(n-1)
  for i in range(1,n):
    print("{} {}".format(i,i+1))
  exit()
if amax<=0:
  print(n-1)
  for i in range(1,n):
    print("{} {}".format(n-i+1,n-i))
  exit()
print(2*n-1)
if abs(amin)<=abs(amax):
  for i in range(1,n+1):
    print("{} {}".format(imax,i))
  for i in range(1,n):
    print("{} {}".format(i,i+1))
  exit()
if abs(amin)>=abs(amax):
  for i in range(1,n+1):
    print("{} {}".format(imin,i))
  for i in range(1,n):
    print("{} {}".format(n-i+1,n-i))

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

    amax = max(a)
    amax_arg = a.index(amax)
    amin = min(a)
    amin_arg = a.index(amin)

    output = []

    if abs(amax) >= abs(amin):
        for i in range(N):
            a[i] += amax
            output.append([amax_arg+1, i+1])
        for i in range(N-1):
            a[i+1] += a[i]
            output.append([i+1, i+2])
    else:
        for i in range(N):
            a[i] += amin
            output.append([amin_arg+1, i+1])
        for i in range(N-1):
            a[-i-2] += a[i-1]
            output.append([N-i, N-i-1])

    print(len(output))
    for i in range(len(output)):
        print(str(output[i][0])+" "+str(output[i][1]))


if __name__ == '__main__':
    main()

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

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

count = 0
ans = []
mi = min(a)
ma = max(a)
plus = True
if ma >= 0 and mi <= 0:
    if abs(mi) < ma:
        plus = True
        idx = a.index(ma)+1
    else:
        plus = False
        idx = a.index(mi)+1
    for i in range(1, n+1):
        if i == idx:
            continue
        ans.append([idx, i])
    count += n-1
else:
    plus = ma > 0
if plus:
    for i in range(1, n):
        ans.append([i, i+1])
else:
    for i in range(n-1):
        ans.append([n-i, n-i-1])
print(count+n-1)
for a in ans:
    print("{} {}".format(a[0], a[1]))

Solution (Python):
import numpy as np
n = input()
a = map(int, raw_input().split())
max_i = np.argmax(a)
min_i = np.argmin(a)
ans = []
if abs(a[max_i]) >= abs(a[min_i]):
    for i in range(n):
        ans.append((max_i, i))
    for i in range(n-1):
        ans.append((i, i+1))
else:
    for i in range(n):
        ans.append((min_i, i))
    for i in range(n-1, 0, -1):
        ans.append((i, i-1))
print len(ans)
for x, y in ans:
    print (x+1), (y+1)

Solution (Python):
def plass_only(a):
    for i in a:
        if i < 0:
            return 0
    return 1

def minus_only(a):
    for i in a:
        if i > 0:
            return 0
    return 1

def sarch(list, a):
    for i in range(len(list)):
        if a == list[i]:
            return i
            break

N = int(input())
a = list(map(int, input().split()))
if plass_only(a) == 1:
    for i in range(1, len(a)):
        a[i] += a[i - 1]
    print(len(a) - 1)
    for i in range(1, len(a)):
        print(i, i + 1)

elif minus_only(a) == 1:
    for i in range(len(a) - 2, -1, -1):
        a[i] += a[i + 1]
    print(len(a) - 1)
    for i in range(len(a), 1, -1):
        print(i, i - 1)

else:
    a_p = [i for i in a]
    a_m = [i for i in a]
    count_p = 0
    count_m = 0
    plass_print = []
    minus_print = []
    for i in range(len(a)):
        while a_p[i] < 0:
            a_p[i] += max(a_p)
            count_p += 1
            plass_print.append(str(sarch(a_p, max(a_p)) + 1) + " " + str(i + 1))
            if count_p > N: break
        while a_m[i] > 0:
            a_m[i] += min(a_m)
            count_m += 1
            minus_print.append(str(sarch(a_m, min(a_m)) + 1) + " " + str(i + 1))
            if count_m > N: break
    if count_p <= count_m:
        count = count_p
        a = a_p
        for i in range(1, len(a)):
            a[i] += a[i - 1]
            count += 1
        print(count)
        for i in plass_print:
            print(i)
        for i in range(1, len(a)):
            print(i, i + 1)

        
    else:
        count = count_m
        a = a_m
        for i in range(len(a) - 2, -1, -1):
            a[i] += a[i + 1]
            count += 1
        print(count)
        for i in minus_print:
            print(i)
        for i in range(len(a), 1, -1):
            print(i, i - 1)

Solution (Python):
n = int(input())
a = [int(i) for i in input().split()]
a_max = max(a)
a_min = min(a)

abs_max = a_min if abs(a_min) > abs(a_max) else a_max
abs_max_index = a.index(abs_max)


print(2*n-1)

total = 0

for i in range(n):

    print(abs_max_index+1, i+1)
    a[i] += abs_max

my_range, next_index_diff = (
    list(range(n-1)), 1) if abs_max > 0 else (list(range(n-1, 0, -1)), -1)


while my_range:

    index = my_range.pop(0)

    print(index+1, index+1+next_index_diff)
    a[index+next_index_diff] += a[index]

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

key = 0
for a in A:
    if abs(a) > abs(key):
        key = a
key_i = A.index(key)

m = 0
ans = []
if key > 0:
    for i in range(N):
        if A[i] < 0:
            m += 1
            A[i] += key
            ans.append([key_i+1, i+1])

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

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

elif key < 0:
    for i in range(N):
        if A[i] > 0:
            m += 1
            A[i] += key
            ans.append([key_i+1, i+1])

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

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

else:
    print(0)

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

maxA,minA = max(A),min(A)
maxAi,minAi = -1,-1
sign = ""
M = []

for i in range(N):
    if A[i] == maxA:
        maxAi = i
        break
for i in range(N):
    if A[i] == minA:
        minAi = i
        break

if abs(maxA) >= abs(minA):
    A = list(map(lambda x: x+maxA, A))
    sign = "+"
else:
    A = list(map(lambda x: x+minA, A))
    sign = "-"

if sign == "+":
    for i in range(N):
        if i != maxAi:
            M.append((maxAi,i))
    M.append((maxAi,maxAi))
    for i in range(N-1):
        M.append((i,i+1))
elif sign == "-":
    for i in range(N):
        if i != minAi:
            M.append((minAi,i))
    M.append((minAi,minAi))
    for i in range(N-1):
        M.append((N-i-1,N-i-2))

L = len(M)
print(L)
for i in range(L):
    x,y = M[i]
    print(x+1,y+1)

Solution (Python):
N=int(input())
a=[int(i) for i in input().split()]
argM=0
argm=0
for i in range(N):
    if a[argM]<a[i]:
        argM=i
    if a[argm]>a[i]:
        argm=i
if a[argM]<=0:
    print(N-1)
    for i in list(range(N-1))[::-1]:
        a[i]+=a[i+1]
        print(i+2,i+1)
elif a[argm]>=0:
    print(N-1)
    for i in range(N-1):
        a[i+1]+=a[i]
        print(i+1,i+2)
else:
    L=[]
    if a[argM]+a[argm]>=0:
        for i in range(N):
            if i==argM:
                continue
            L.append([argM+1,i+1])
            a[i]+=a[argM]
        for i in range(N-1):
            a[i+1]+=a[i]
            L.append([i+1,i+2])
        print(len(L))
        for p in L:
            print(p[0],p[1])
    else:
        for i in range(N):
            if i==argm:
                continue
            L.append([argm+1,i+1])
            a[i]+=a[argm]
        for i in list(range(N-1))[::-1]:
            a[i]+=a[i+1]
            L.append([i+2,i+1])
        print(len(L))
        for p in L:
            print(p[0],p[1])

Solution (Python):


import numpy as np

n = int(input())
a = list(map(int , input().split()))
print(2*n)
if a[np.argmax(a)] <= -a[np.argmin(a)]:
    cnt = len(a) - 1
    for i in range(0, len(a)):
        print(str(np.argmin(a) + 1) + " " + str(cnt + 1))
        a[cnt] += a[np.argmin(a)]
        print(str(np.argmin(a) + 1) + " " + str(cnt + 1))
        a[cnt] += a[np.argmin(a)]
        cnt -= 1;
else:
    cnt = 0
    for i in range(0, len(a)):
        print(str(np.argmax(a) + 1) + " " + str(cnt + 1))
        a[cnt] += a[np.argmax(a)]
        print(str(np.argmax(a) + 1) + " " + str(cnt + 1))
        a[cnt] += a[np.argmax(a)]
        cnt += 1

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
ans=0
a_max=max(a)
a_min=min(a)
if a_min>=0:
    adding=a_max
elif a_min<0 and a_max>0:
    if abs(a_max)>=abs(a_min):
        adding=a_max
    else:
        adding=a_min
else:
    adding=a_min
ind=a.index(adding)
proc=[]
for i in range(n):
    ans+=1
    a[i]+=adding
    proc.append([ind+1,i+1])
if adding==a_max:
    for i in range(n-1):
        ans+=1
        a[i+1]+=a[i]
        proc.append([i+1,i+2])
else:
    for i in range(n-1):
        ans+=1
        a[-(i+2)]+=a[-(i+1)]
        proc.append([n-i,n-i-1])
print(ans)
for i in range(len(proc)):
    print(proc[i][0],proc[i][1])

Solution (Python):
def main():
    """
    2<= N <= 50

    a_x += a_y: 2N回まで

    a_1 <= a_2 <= ... <= a_N にする
    """
    N = int(input())
    A = map(int, input().split())
    A = list(A)

    solve(N, A)


def solve(N, A):
    if A == sorted(A):
        print(0)
        return

    p = [i for i, a in enumerate(A) if a >= 0]
    m = [i for i, a in enumerate(A) if a < 0]

    
    operations = []
    plus = len(p) > 0
    if p and m:
        p_max_a = max(A[i] for i in p)
        m_min_a = min(A[i] for i in m)

        if abs(m_min_a) > abs(p_max_a):
            idx_list = p
            idx = A.index(m_min_a)
        else:
            idx_list = m
            idx = A.index(p_max_a)

        for i in idx_list:
            A[i] += A[idx]
            operations.append((idx+1, i+1))

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

    print(len(operations))
    for src, dst in operations:
        print(src, dst)

    debug = False
    if debug:
        print(A)
        assert A == sorted(A)
        assert len(operations) <= N * 2


if __name__ == '__main__':
    main()

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

def find_i():
    for i in range(n):
        if a[i] == max(a):
            return i+1
        
def find_m():
    for i in range(n):
        if a[i] == min(a):
            return i+1
        
maxi = find_i()
mini = find_m()

if min(a) < 0:
    if abs(min(a)) <= abs(max(a)):
        for _ in range(n):
            a[_] += max(a)
            s.append(str(maxi) + ' ' + str(_+1))
            count += 1
        for i in range(n-1):
            a[i+1] += a[i]
            s.append(str(i+1) + ' ' + str(i+2))
            count += 1
            
    else:
        for _ in range(n):
            a[_] += min(a)
            s.append(str(mini) + ' ' + str(_+1))
            count += 1
        for i in range(n-2,-1,-1):
            a[i] += a[i+1]
            s.append(str(i+2) + ' ' + str(i+1))
            count += 1

else:
    for i in range(n-1):
        a[i+1] += a[i]
        s.append(str(i+1) + ' ' + str(i+2))
        count += 1
print(count)
for i in range(len(s)):
    print (s[i])

Solution (Python):
def ans():
    N = int(input())
    A = list(map(int, input().split()))
    result = []
    MAX = max(A)
    MAX_INDEX = A.index(MAX)
    MIN = min(A)
    MIN_INDEX = A.index(MIN)

    if abs(MAX) > abs(MIN):
        
        B = []
        for i, v in enumerate(A):
            b = v + MAX
            B.append(b)
            result.append((MAX_INDEX, i))

        for i in range(N):
            if i == 0: continue
            B[i] = B[i] + B[i - 1]
            result.append((i - 1, i))
    else:
        B = []
        for i, v in enumerate(A):
            b = v + MIN
            B.append(b)
            result.append((MIN_INDEX, i))

        for i in range(N - 1, -1, -1):
            if i == N-1: continue
            B[i] = B[i] + B[i + 1]
            result.append((i + 1, i))

    print(len(result))
    for r in result:
        print(r[0]+1, r[1]+1)


ans()

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

mi=100000000
ma=-100000000
mi_n=0
ma_n=0
for i in range(N):
  if A[i]>ma:
    ma=A[i]
    ma_n=i+1
  if A[i]<mi:
    mi=A[i]
    mi_n=i+1

if mi>=0:
  print(N-1)
  for i in range(N-1):
    print(i+1,i+2)
elif ma<=0:
  print(N-1)
  for i in range(N-1):
    print(N-i,N-i-1)
else:
  print(N+N-1)
  if abs(ma)>abs(mi):
    for i in range(N):
      print(ma_n,i+1)
    for j in range(N-1):
      print(j+1,j+2)
  else:
    for i in range(N):
      print(mi_n,i+1)
    for j in range(N-1):
      print(N-j,N-j-1)

Solution (Python):
import numpy as np
N = int(input())
a = np.array(list(map(int, input().split())))
a_max = a.max()
a_min = a.min()
if abs(a_max) >= abs(a_min):
	add_idx = a.argmax() + 1
else:
	add_idx = a.argmin() + 1
if a_max + a_min >= 0:
	rng_idx = range(1, N)
	sgn = 1
else:
	rng_idx = range(N, 1, -1)
	sgn = -1
print(2 * N - 1)
for i in range(1, N + 1):
	print(add_idx, i)
for i in rng_idx:
	print(i, i + sgn)

Solution (Python):

"""
https://beta.atcoder.jp/contests/abc081/tasks/arc086_b

"""
import sys
from sys import stdin
input = stdin.readline


def solve(A, N):
    steps = []

    min_A = min(A)
    min_pos = A.index(min_A) + 1
    max_A = max(A)
    max_pos = A.index(max_A) + 1

    if min_A >= 0:
        steps.append([max_pos, 1])
        for i in range(2, N+1):
            steps.append([i-1, i])
    else:
       if (abs(min_A) < abs(max_A)):
           for i in range(1, N+1):
               steps.append([max_pos, i])
           steps.append([max_pos, 1])
           for i in range(2, N+1):
               steps.append([i-1, i])
       else:
           for i in range(1, N+1):
               steps.append([min_pos, i])
           steps.append([min_pos, N])
           for i in range(N, 1, -1):
               steps.append([i, i-1])
    return steps


def main(args):
    N = int(input())
    A = [int(x) for x in input().split()]
    ans = solve(A, N)
    print(len(ans))
    for x, y in ans:
        print(x, y)




if __name__ == '__main__':
    main(sys.argv[1:])

Solution (Python):
n = int(input())
lis = list(map(int, input().split()))
if abs(max(lis)) >= abs(min(lis)):
    ind = lis.index(max(lis)) + 1
else:
    ind = lis.index(min(lis)) + 1
opere = []
if lis[ind-1] > 0:
    for i in range(1, n+1):
        opere.append([ind, i])
    for i in range(1, n):
        opere.append([i, i + 1])
else:
    for i in range(1, n+1):
        opere.append([ind, i])
    for i in range(n-1):
        opere.append([n-i, n-i-1])

print(2*n-1)
if opere:
    for i in opere:
        print(" ".join(list(map(str, i))))

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
Amax = max(A)
Amin = min(A)
outlis=[];

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

amin = min(a)
amax = max(a)
if abs(amin) < abs(amax):
    index = a.index(amax)
    a = list(map(lambda x: x + amax, a))
else:
    index = a.index(amin)
    a = list(map(lambda x: x + amin, a))

ans = [(index+1, i+1) for i in range(N)]
if a[0] > 0:
    ans += [(i+1, i+2) for i in range(N-1)]
else:
    ans += [(i+1, i) for i in range(N-1, 0, -1)]
print(len(ans))
print('\n'.join(map(lambda xy: '%d %d' % xy, ans)))

Solution (Python):


def foo(xs, n):
    largest = - 10**6
    smallest = 10**6
    largest_i = -1
    smallest_i = -1
    for i, x in enumerate(xs):
        if largest < x:
            largest = x
            largest_i = i
        if smallest > x:
            smallest = x
            smallest_i = i

    ys = []
    if smallest < 0 and abs(smallest) > largest:
        for i in range(n-2, -1, -1):
            while xs[i+1] < xs[i]:
                xs[i] += smallest
                ys.append((smallest_i, i))
                if xs[i] < smallest:
                    smallest_i = i
                    smallest = xs[i]
    else:
        for i in range(1, n):
            while xs[i-1] > xs[i]:
                xs[i] += largest
                ys.append((largest_i, i))
                if xs[i] > largest:
                    largest_i = i
                    largest = xs[i]
    return ys



if __name__ == "__main__":
    n = int(input())
    xs = list(map(int, input().split()))
    ys = foo(xs, n)
    print(len(ys))
    for i, j in ys:
        print("%d %d"%(i+1, j+1))

Solution (Python):
import sys
import numpy as np
N=int(input())
nums=list(map(int,input().split(" ")))
ans_array=[]

add=0
mode=0
if min(nums)>0: 
    mode=0
elif max(nums)<0: 
    mode=1
elif max(nums)==min(nums)==0: 
    print("0")
    sys.exit()
else: 
    mode=2
count=0

if mode==2: 
    temp=[]
    if abs(max(nums))<abs(min(nums)):
        mode=1 
        add=min(nums)
        ind=np.argmin(nums)
    elif abs(max(nums))>=abs(min(nums)):
        mode=0
        add=max(nums)
        ind=np.argmax(nums)
    for i in range(len(nums)):
        nums[i]+=add
        ans_array.append("{0} {1}".format(ind+1,i+1))
        count+=1
        
        

if mode==0: 
    for i in range(len(nums)-1):
        nums[i+1]+=nums[i]
        count+=1
        ans_array.append("{0} {1}".format(i+1,i+2))
    print(count)
    for i in ans_array:
       print(i)
                

elif mode==1:
    nums.reverse()
    for i in range(len(nums)-1):
        nums[i+1]+=nums[i]
        count+=1    
        ans_array.append("{0} {1}".format(len(nums)-i,len(nums)-i-1))

    print(count)
    for i in ans_array:
       print(i)

Solution (Python):
n=int(input())
a=[int(i) for i in input().split()]
ans=[]
positive_flag=True


if 0<=min(a):
        positive_flag=True
elif max(a)<=0:
        positive_flag=False
elif min(a)*(-1) <= max(a):
        positive_flag=True
        maxId=a.index(max(a))
        for i in range(n):
                if i!=maxId:
                        ans.append([maxId+1,i+1])
else:
        positive_flag=False
        minId=a.index(min(a))
        for i in range(n):
                if i!=minId:
                        ans.append([minId+1,i+1])

if positive_flag:
        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 num in ans:
        print(str(num[0])+" "+str(num[1]))

Solution (Python):



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


res = []
mx = max(a)
mx_idx = a.index(mx)
mn = min(a)
mn_idx = a.index(mn)

if abs(mx) >= abs(mn):
    for i in range(n):
        res.append((mx_idx, i))
    for i in range(0, n - 1):
        res.append((i, i + 1))
else:
    for i in range(n):
        res.append((mn_idx, i))
    for i in range(n - 1, 0, -1):
        res.append((i, i - 1))

print(len(res))

for i, j in res:
    print("%d %d" % (i + 1, j + 1))

Solution (Python):


import math

N = int(raw_input())
a = map(int, raw_input().split())
a_abs = [ math.fabs(i) for i in a ]
a_start = a_abs.index(max(a_abs))

if a[a_start] > 0:
  print N*2
  for message in range(2): print str(a_start+1) + " 1"
  for i in range(1, N):
    for message in range(2): print str(i) + " " + str(i+1)
elif a[a_start] < 0:
  print N*2
  for message in range(2): print str(a_start+1) + " " + str(N)
  for i in range(N-1, 0, -1):
    for message in range(2): print str(i+1) + " " + str(i)
else: print 0

Solution (Python):

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

print(2*N-2)
aa=list(map(abs,a))
nmax=aa.index(max(aa))
for i in range(N):
  if i==nmax:
    pass
  else:
    print("{} {}".format(nmax+1,i+1))
if a[nmax]>0:
  for i in range(N-1):
    print("{} {}".format(i+1,i+2))
else:
  for i in range(N-1):
    print("{} {}".format(N-i,N-i-1))

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


series_sorted = series[:]
series_sorted.sort()

def make_no_decrease(condition, series):
    if condition == 0:
        for i in range(1,N):
            print(i, i+1)
    elif condition == 1:
        for i in range(1,N):
            print(N-i+1, N-i)
            
if series_sorted[0]  >= 0: 
    print(len(series)-1)
    make_no_decrease(0, series)
elif series_sorted[-1] < 0: 
    print(len(series)-1)
    make_no_decrease(1, series)
else:
    if abs(series_sorted[-1]) <= abs(series_sorted[0]): 
        print(2*len(series)-1)
        min = series.index(series_sorted[0])
        for i in range(len(series)):
            print(min+1, i+1)
        make_no_decrease(1, series)
    elif abs(series_sorted[0]) < abs(series_sorted[-1]): 
        print(2*len(series)-1)
        max = series.index(series_sorted[-1])
        for i in range(len(series)):
            print(max+1, i+1)
        make_no_decrease(0, series)

Solution (Python):
import numpy as np

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

if abs(max(a)) >= abs(min(a)):
  ma  = max(a)
  ma_i= np.argmax(a)
  mi  = 0
  mi_i= 0
else:
  mi  = min(a)
  mi_i= np.argmin(a)
  ma  = 0
  ma_i= 0

xa=[]
if ma == 0:
  for i in range(n):
    if a[i] > 0:
      a[i] = a[i] + mi
      xa.append([mi_i+1, i+1])
  for i in reversed(range(1,n)):
    if a[i-1] > a[i]:
      a[i-1] = a[i-1] + a[i]
      xa.append([i+1, i-1+1])
else:
  for i in range(n):
    if a[i] < 0:
      a[i] = a[i] + ma
      xa.append([ma_i+1, i+1])
  for i in range(1,n):
    if a[i-1] > a[i]:
      a[i] = a[i] + a[i-1]
      xa.append([i-1+1,i+1])

print(len(xa))
for i in range(len(xa)):
  print(xa[i][0],xa[i][1])

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

maxa = max(a)
mina = min(a)
add = None
if abs(maxa) > abs(mina):
    add = maxa
else:
    add = mina

index = a.index(add)
ans = [(index, i) for i in range(N) if i != index]
if add > 0:
    ans += [(i, i+1) for i in range(N-1)]
else:
    ans += [(i, i-1) for i in range(N-1, 0, -1)]

ans = list(map(lambda x: (x[0]+1, x[1]+1), ans))
print(len(ans))
print('\n'.join(map(lambda x: '%d %d' % x, ans)))

Solution (Python):
N = int(input())
alist = [int(x) for x in input().split()]
positive =  max(alist)+min(alist) >=0
if positive:
	argmaxabs = alist.index(max(alist))
else:
	argmaxabs = alist.index(min(alist))
print(2*N-2)
for i in range(1,N+1):
	if not argmaxabs+1 == i:
		print(str(argmaxabs+1)+" "+str(i))
if positive:
	for i in range(1,N):
		print(str(i)+" "+str(i+1))
else:
	for i in range(N,1,-1):
		print(str(i)+" "+str(i-1))

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

C = []
max_A = max(A)
max_idx = A.index(max_A)
min_A = min(A)
min_idx = A.index(min_A)

if abs(max_A) >= abs(min_A):
    for i in range(n):
        A[i] += max_A
        C.append([max_idx+1, i+1])
    for i in range(1, n):
        A[i] += A[i-1]
        C.append([i, i+1])
else:
    for i in range(n):
        A[i] += min_A
        C.append([min_idx+1, i+1])
    for i in range(n, 1, -1):
        A[i-2] += A[i-1]
        C.append([i, i-1])


print(len(C))
for i, j in C:
    print('{0} {1}'.format(i, j))

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

C = []
max_A = max(A)
max_idx = A.index(max_A)
min_A = min(A)
min_idx = A.index(min_A)

if abs(max_A) >= abs(min_A):
    for i in range(n):
        
        C.append([max_idx+1, i+1])
    for i in range(1, n):
        
        C.append([i, i+1])
else:
    for i in range(n):
        
        C.append([min_idx+1, i+1])
    for i in range(n, 1, -1):
        
        
        C.append([i, i-1])

print(len(C))
for i, j in C:
    print('{0} {1}'.format(i, j))

Solution (Python):
N,*A=map(int,open(0).read().split());M=max(A);m=min(A);s=range(1,N+1);p=print;p(2*N-1);v,d=-m<M and(M,1)or(m,-1);r=s[::d]
for i in s:p(A.index(v)+1,i)
for z in zip(r,r[1:]):p(*z)

Solution (Python):
N,*A=map(int,open(0).read().split())
M = max(A); m = min(A)
ans = []
if -m < M:
    idx = A.index(M)
    for i in range(N):
        A[i] += A[idx]
        ans.append((idx, i))
    for i in range(1, N):
        A[i] += A[i-1]
        ans.append((i-1, i))
else:
    idx = A.index(m)
    for i in range(N):
        A[i] += A[idx]
        ans.append((idx, i))
    for i in range(N-1, 0, -1):
        A[i-1] += A[i]
        ans.append((i, i-1))

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

Solution (Python):

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

cnt = 0
op = []
mx = {'i':a.index(max(a)), 'v':max(a)}
mn = {'i':a.index(min(a)), 'v':min(a)}
for i in range(N):
    if mx['v'] > 0 and mn['v'] < 0:
        if abs(mx['v']) > abs(mn['v']):
            if a[i] < 0:
                cnt += 1
                op.append([mx['i'] + 1, i + 1])
                a[i] += mx['v']
        else:
            if a[i] > 0:
                cnt += 1
                op.append([mn['i'] + 1, i + 1])
                a[i] += mn['v']

if abs(mx['v']) > abs(mn['v']):
    for i in range(N - 1):
        if a[i] > a[i + 1]:
            cnt += 1
            op.append([i + 1, i + 2])
            a[i + 1] += a[i]
else:
    for i in range(N - 1)[::-1]:
        if a[i] > a[i + 1]:
            cnt += 1
            op.append([i + 2, i + 1])
            a[i] += a[i + 1]

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

Solution (Python):
import sys
N=input()

a=[]
a=map(int,raw_input().split())


if max(a)==min(a):
	print 0
	sys.exit()
elif abs(max(a))>abs(min(a)):
	num=(max(a),a.index(max(a)))
else:
	num=(min(a),a.index(min(a)))


ans=[]
for i in range(N):
	a[i]+=num[0]
	ans.append((num[1]+1,i+1))

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

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

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

count = 0
ans = ""

max_num = max(a)
max_idx = a.index(max_num)
min_num = min(a)
min_idx = a.index(min_num)

if abs(max_num) >= abs(min_num):
    for i in range(len(a)):
        a[i] += max_num
        ans += "{} {}\n".format(max_idx+1, i+1)
        count += 1
    for i in range(len(a)-1):
        a[i+1] += a[i]
        ans += "{} {}\n".format(i+1, i+1+1)
        count += 1
else:
    for i in range(len(a)):
        a[i] += min_num
        ans += "{} {}\n".format(min_idx+1, i+1)
        count += 1
    for i in range(len(a)-1):
        a[len(a)-(i+2)] += a[len(a)-(i+1)]
        ans += "{} {}\n".format(len(a)-(i+1)+1, len(a)-(i+2)+1)
        count += 1
print(count)
print(ans)

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

a_max = max(a)
max_idx = a.index(a_max)
a_mix = min(a)
min_idx = a.index(a_mix)

ans = ''

if abs(a_max) >= abs(a_mix):
	ans += '{}\n'.format(2 * N - 1)
	for i in range(N):
		ans += '{} {}\n'.format(max_idx + 1, i + 1)
	for i in range(1, N):
		ans += '{} {}\n'.format(i, i + 1)
else:
	ans += '{}\n'.format(2 * N - 1)
	for i in range(N):
		ans += '{} {}\n'.format(min_idx + 1, i + 1)
	for i in range(N, 1, -1):
		ans += '{} {}\n'.format(i, i - 1)

print(ans,end="")

Solution (Python):
from numpy import argmax, argmin
N = int(input())
a = list(map(int,input().split()))

a_max = max(a)
a_argmax = argmax(a)
a_min = min(a)
a_argmin = argmin(a);

ans = ''
if abs(a_max) >= abs(a_min):
	ans += '{}\n'.format(2 * N - 1)
	for i in range(N):
		ans += '{} {}\n'.format(a_argmax + 1, i + 1)
	for i in range(1, N):
		ans += '{} {}\n'.format(i, i + 1)
else:
	ans += '{}\n'.format(2 * N - 1)
	for i in range(N):
		ans += '{} {}\n'.format(a_argmin + 1, i + 1)
	for i in range(N, 1, -1):
		ans += '{} {}\n'.format(i, i - 1)
ans=ans[:-1]

print(ans)

Solution (Python):
def d_non_decreasing(N, A):
    from numpy import argmax, argmin
    a = A[:]
    a_max = max(a)
    a_argmax = argmax(a) + 1
    a_min = min(a)
    a_argmin = argmin(a) + 1  
    ans = ''
    if abs(a_max) >= abs(a_min):
        ans += '{}\n'.format(2 * N - 1)  
        for i in range(N):
            ans += '{} {}\n'.format(a_argmax, i + 1)  
        for i in range(1, N):
            ans += '{} {}\n'.format(i, i + 1)  
    else:
        ans += '{}\n'.format(2 * N - 1)
        for i in range(N):
            ans += '{} {}\n'.format(a_argmin, i + 1)  
        for i in range(N, 1, -1):
            ans += '{} {}\n'.format(i, i - 1)  
    ans=ans[:-1] 
    return ans
  
N = int(input())
A = [int(i) for i in input().split()]
print(d_non_decreasing(N, A))

Solution (Python):
n = input()
num = map(int, raw_input().split())
ma = max(num)
mi = min(num)
l = list()
if ma*mi < 0:
    if ma > abs(mi):
        index = num.index(ma)
    else:
        index = num.index(mi)
    for i in xrange(n):
        l.append("%d %d" % (index+1, i+1))
    b = num[index]
else:
    b = 0
    for i in num:
        if i:
            b = i
            break

if b == 0:
    pass
elif b < 0:
    for i in xrange(n-1, 0, -1):
        l.append("%d %d" % (i+1, i))
else:
    for i in xrange(0, n-1):
        l.append("%d %d" % (i+1, i+2))

print len(l)
for i in l:
    print i

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

mi = 10 ** 7
ma = -(10 ** 7)
mi_idx = 0
ma_idx = 0
for i,v in enumerate(a):
  if v < mi:
    mi = v
    mi_idx = i
  if v > ma:
    ma = v
    ma_idx = i

print(2 * n - 1)
if abs(ma) >= abs(mi):
  for i in range(1, len(a) + 1):
    print(ma_idx + 1, i)
  for i in range(1, len(a)):
    print(i, i + 1)
else:
  for i in range(1, len(a) + 1):
    print(mi_idx + 1, i)
  for i in range(len(a), 1, -1):
    print(i, i - 1)