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):
count = int(input())

pls_flg = False
mns_flg = False
srt_flg = True
tmp = input().split()
num = []
work_max = 0
work_min = 0
index_max = 0
index_min = 0

for i in range(count):
    if int(tmp[i])>0:
        num.append(int(tmp[i]))
        pls_flg = True
        if work_max < num[i]:
            work_max = num[i]
            index_max = i
    elif int(tmp[i])<0:
        num.append(int(tmp[i]))
        mns_flg = True
        if abs(work_min) < abs(num[i]):
            work_min = num[i]
            index_min = i
    else:
        num.append(int(tmp[i]))
    
    if srt_flg and i > 0:
        if num[i-1] > num[i]:
            srt_flg = False

if srt_flg:
    print(0)
else:
    if pls_flg and not mns_flg:
        print(count-1)
        for j in range(count-1):
            print(str(j+1)+" "+str(j+2))
    elif not pls_flg and mns_flg:
        print(count-1)
        for j in range(count-1):
            print(str(count-j)+" "+str(count-1-j))
    elif pls_flg and mns_flg:
        print(2*count-1)
        if work_max >= abs(work_min):
            for x in range(count):
                print(str(index_max+1)+" "+str(x+1))
            for y in range(count-1):
                print(str(y+1)+" "+str(y+2))
        else:
            for x in range(count):
                print(str(index_min+1)+" "+str(x+1))
            for y in range(count-1):
                print(str(count-y)+" "+str(count-y-1))
    else:
        print(0)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
A_abs = []
for a in A:
    A_abs.append(abs(a))

ans = []
m = max(A_abs)
midx = A_abs.index(m)

print(2 * N - 2)

for i in range(N):
    if not i == midx:
        print(str(midx + 1) + ' ' + str(i + 1))

for i in range(N - 1):
    if A[midx] >= 0:
        print(str(i + 1) + ' ' + str(i + 2))
    else:
        print(str(N - i) + ' ' + str(N - i - 1))

Solution (Python):
def judge(L):
    cnt_plus = 0
    cnt_minus = 0
    for l in L:
        if l >= 0:
            cnt_plus += 1
        else:
            cnt_minus += 1

    if cnt_plus == len(L):
        return 1
    elif cnt_minus == len(L):
        return -1
    else:
        return 0


def solve():
    N = int(input())
    A = list(map(int, input().split(" ")))

    if judge(A) == 1:
        print(N - 1)
        for i in range(1, N):
            print(i, i + 1)
    elif judge(A) == -1:
        print(N - 1)
        for i in range(N, 1, -1):
            print(i, i - 1)
    elif judge(A) == 0:
        print(2 * N - 1)
        MAX = max(A)
        MAX_INDEX = A.index(MAX) + 1
        MIN = min(A)
        MIN_INDEX = A.index(MIN) + 1
        if abs(MAX) >= abs(MIN):
            for i in range(1, N + 1):
                print(MAX_INDEX, i)
            for i in range(1, N):
                print(i, i + 1)
        elif abs(MAX) < abs(MIN):
            for i in range(1, N + 1):
                print(MIN_INDEX, i)
            for i in range(N, 1, -1):
                print(i, i - 1)


solve()

Solution (Python):
import numpy as np
n = int(input())
a = np.array(list(map(int, input().split())))
data = []
if np.sum(a >= 0) == n:
    flag = 1
elif np.sum(a >= 0) == 0:
    flag = -1
else:
    max_a = np.max(a)
    max_ind = np.argmax(a)
    min_a = np.min(a)
    min_ind = np.argmin(a)
    if np.abs(max_a) > np.abs(min_a):
        flag = 1
        a = a + max_a
        for i in range(n):
            data.append([max_ind+1, i+1])
    else:
        flag = -1
        a = a + min_a
        for i in range(n):
            data.append([min_ind+1, i+1])
if flag == 1:
    for i in range(n-1):
        data.append([i+1, i+2])
else:
    for i in range(n-1, 0, -1):
        data.append([i+1, i])
print (len(data))
for i in range(len(data)):
    print (data[i][0], data[i][1])

Solution (Python):
def main():
    N = int(input())
    A = tuple(map(int, input().split()))

    a = list(A)
    m = 0
    xy = []
    apnd = xy.append
    if min(a) == max(a):
        print(0)
        return
    elif min(a) < 0 and max(a) >= 0:
        if abs(min(a)) > max(a):
            x = min(a)
        else:
            x = max(a)
        idx = a.index(x)
        for i, j in enumerate(a):
            if j != x:
                a[i] += x
                m += 1
                apnd((idx + 1, i + 1))

    if min(a) >= 0:
        for i in range(N - 1):
            a[i+1] += a[i]
            m += 1
            apnd((i + 1, i + 2))
    elif max(a) < 0:
        for i in range(N - 1, 0, -1):
            a[i-1] += a[i]
            m += 1
            apnd((i + 1, i))

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

main()

Solution (Python):
n = int(raw_input())
a = map(int,raw_input().split(" "))

ans = []
aa = sorted(a)

if aa[0] < 0 and aa[n-1] > 0:
  bt = aa[0]
  up = aa[n-1]
  if abs(bt) > abs(up):
    r = a.index(bt)
    for x in range(n):
      if x != r:
        a[x] += bt
        ans.append([r+1,x+1])
  else:
    r = a.index(up)
    for x in range(n):
      if x != r:
        a[x] += up
        ans.append([r+1,x+1])

aa = sorted(a)

if aa[0] == aa[n-1]:
  print 0
  exit()

if aa[0] >= 0: 
  for x in range(n-1):
    a[x+1] += a[x]
    ans.append([x+1,x+2])
elif aa[n-1] <= 0: 
  for x in range(n-2,-1,-1):
    a[x] += a[x+1]
    ans.append([x+2,x+1])

print len(ans)
for q in ans:
  print "%d %d" % (q[0],q[1])

Solution (Python):
if __name__=="__main__":
    N = int(input())
    l = list(map(int,input().split(" ")))
    record = []
    dic = {i:l[i] for i in range(N)}
    sorted_list = sorted(dic.items(),key=lambda d:d[1],reverse=True)
    if sorted_list[N-1][1]>=0:
        for i in range(N-1):
            record.append([i, i+1])
    elif sorted_list[0][1]<0:
        for i in range(N-1,0,-1):
            record.append([i, i-1])
    elif sorted_list[0][1]+sorted_list[N-1][1]>=0:
        record.append([sorted_list[0][0], 0])
        record.append([sorted_list[0][0], 1])
        record.append([0,1])
        for i in range(1,N-1):
            record.append([sorted_list[0][0], i+1])
            record.append([i,i+1])
    elif sorted_list[0][1]+sorted_list[N-1][1]<0:
        record.append([sorted_list[N-1][0], N-1])
        record.append([sorted_list[N-1][0], N-2])
        record.append([N-1,N-2])
        for i in range(N-2,0,-1):
            record.append([sorted_list[N-1][0], i-1])
            record.append([i,i-1])
    print(len(record))
    for i in range(len(record)):
         print(str(record[i][0]+1)+" "+str(record[i][1]+1))

Solution (Python):


N=int(input())
AAA=input().split()

A = [int(i) for i in AAA]

max_abs_index = -1

indexbox = [[-1 for i in range(2)] for j in range(2*N)]
i=0
j=0
c=-1
max_abs_index=max(range(N), key=lambda i: abs(A[i]))
while(0!=c):
    max_abs_index=max(range(N), key=lambda i: abs(A[i]))

    indexbox[i][0] = A[max_abs_index]
    indexbox[i][1] = max_abs_index
    c = A[max_abs_index]
    if indexbox[i][0] < 0:
        for p in range(max_abs_index+1):
            A[p] =0
    if indexbox[i][0] > 0:
        for p in range(max_abs_index,N):
            A[p] =0
    i = i+1






if i == 1:
    print(0)
else:
    a = indexbox[i-2][1]

 
    if (a == 0 and indexbox[i-2][0]>0) or (a == N-1 and indexbox[i-2][0] < 0):
        pp=2*N-2
    else:
        pp = 2*N-4
    print(pp)
    if indexbox[i-2][0] > 0:
 
        for j in range(a,N-1):
            print(j+1, j+2)
            print(j+1, j+2)
        for j in range(a,1,-1):
            print(j, j-1)
            print(j, j-1)
    else:
  
        for j in range(a+1,N-1):
            print(j+1, j+2)
            print(j+1, j+2)
        for j in range(a+1,1,-1):
            print(j, j-1)
            print(j, j-1)

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

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

count = 0
ans = []

def showans():
	global count
	global ans
	print(count)
	for i,j in ans:
		print(str(i) + " " + str(j))


def allplus():
	global count
	global ans
	for i in range(N-1):
		if a[i] > a[i+1]:
			a[i+1] += a[i]
			count += 1
			ans.append((i+1,i+2))

			

def allminas():
	global count
	global ans
	for i in range(N-1,0,-1):
		if a[i] < a[i-1]:
			a[i-1] += a[i]
			count += 1
			ans.append((i+1,i))


if abs(MAX) >= abs(MIN) and MAX > 0:
	ind = a.index(MAX)
	for i in range(N):
		if a[i] < 0:
			while a[i] < 0:
				a[i] += MAX
				count += 1
				ans.append((ind+1,i+1))

	allplus()
	showans()
	exit(0)

elif abs(MIN) > abs(MAX) and MIN < 0:
	ind = a.index(MIN)
	for i in range(N):
		if a[i] > 0:
			while a[i] > 0:
				a[i] += MIN
				count += 1
				ans.append((ind+1,i+1))

	allminas()
	showans()
	exit(0)

elif MAX <= 0:
	allminas()
	showans()

elif MIN >=  0:
	allplus()
	showans()

Solution (Python):

N = int(input())
a = list(map(int,input().split()))
maxa  = max(a)
mina  = min(a)

print(2*N-1)
r = False
if abs(maxa) >= abs(mina):
    d = maxa
else:
    r = True
    d = mina
ind = a.index(d) + 1

for i in range(N):
    print(ind, i+1)

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

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

flg=0
if abs(max(a))>=abs(min(a)):
  m=max(a)
  flg=1
else:
  m=min(a)

for i in range(len(a)):
  if a[i]==m:
    p=i
    break

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

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

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

k = 0
for i in range(N):
  if abs(A[i]) > abs(A[k]):
    k = i
ans = []
if A[k] > 0:
  for i in range(N):
    if i != k:
      A[i] += A[k]
      ans.append((k+1, i+1))
  for i in range(N-1):
    A[i+1] += A[i]
    ans.append((i+1, i+2))
else:
  for i in range(N):
    if i != k:
      A[i] += A[k]
      ans.append((k+1, i+1))
  for i in range(N-1)[::-1]:
    A[i] += A[i+1]
    ans.append((i+2, i+1))
print(len(ans))
for x, y in ans:
  print(str(x) + " " + str(y))

Solution (Python):
def a(xs):
    k = 0
    m = 0
    ops = []
    for i, x in enumerate(xs):
        if x > m:
            k = i
            m = x
    for i, x in enumerate(xs):
        if xs[i] < 0:
            xs[i] += m
            ops.append((k, i))
    for i in range(len(xs) - 1):
        if xs[i] > xs[i + 1]:
            xs[i + 1] += xs[i]
            ops.append((i, i + 1))
    return ops

def b(xs):
    k = 0
    m = 0
    ops = []
    for i, x in enumerate(xs):
        if x < m:
            k = i
            m = x
    for i, x in enumerate(xs):
        if xs[i] > 0:
            xs[i] += m
            ops.append((k, i))
    for i in range(len(xs) - 2, -1, -1):
        if xs[i] > xs[i + 1]:
            xs[i] += xs[i + 1]
            ops.append((i + 1, i))
    return ops
            
n = input()
xs = map(int, raw_input().split())
m = min(xs)
M = max(xs)
if abs(M) >= abs(m):
    ops = a(xs)
else:
    ops = b(xs)
print len(ops)
for a, b in ops:
    print a + 1, b + 1

Solution (Python):
n=int(input())
a=[int(i) for i in input().split()]
count=0
ans=[[0 for i in range(2)] for j in range(2*n)]
aaa=0

a_max=max(a)
a_min=min(a)
if abs(a_max)>=abs(a_min):
    delta=a_max
else:
    delta=a_min
if delta>0:
    seifu=1
else:
    seifu=-1

for i in range(n):
    if delta==a[i]:
        aaa=i+1
        break




if seifu==1:

  for i in range(n-1):
    while a[i]>a[i+1]:
        if seifu==1:
            a[i+1]=a[i+1]+delta
            ans[count][0], ans[count][1]=aaa, i+2
        count=count+1
        a_max=max(a)
        delta=a_max
        for k in range(n):
            if delta==a[k]:
                aaa=k+1

else:
  for i in range(n-1):
    while a[n-2-i]>a[n-1-i]:
        if seifu==-1:
            a[n-2-i]=a[n-2-i]+delta
            ans[count][0], ans[count][1]=aaa, n-2-i+1
        count=count+1

        a_min=min(a)
        delta=a_min
        for k in range(n):
            if delta==a[k]:
                aaa=k+1


print(count)
for i in range(count):
    print(ans[i][0],ans[i][1])

Solution (Python):
import sys

line = sys.stdin.readline().strip()
N = int(line)
line = sys.stdin.readline().strip()
A = [int(x) for x in line.split()]







vs = sorted([(x, i) for i, x in enumerate(A)])
k = vs[0] if abs(vs[0][0]) > abs(vs[-1][0]) else vs[-1]


tejun = []

def mv(i, j):
    tejun.append((i, j))
    A[j] += A[i]
    

if k[0] > 0:
  mv(k[1], 0)
  mv(k[1], 0)
  for i in range(1, N):
      mv(i - 1, i)
      mv(i - 1, i)
elif k[0] < 0:
  mv(k[1], N - 1)
  mv(k[1], N - 1)
  for i in range(N, 1, -1):
      mv(i - 1, i - 2)
      mv(i - 1, i - 2)
else:
    pass

print(len(tejun))
for t in tejun:
    print(t[0] + 1, t[1] + 1)

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


max_a=-100000000
min_a=100000000
max_index=-1
min_index=-1
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

tezyun=[]

if min_a==max_a:
    None

elif min_a>=0:
    for i in range(1,N):
        tezyun.append([i,i+1])

elif max_a<=0:
    for i in reversed(range(1,N)):
        tezyun.append([i+1,i])

else:
    count=0
    if abs(max_a)>=abs(min_a):
        for i in range(N):
            if a[i]<0:
                a[i]=a[i]+a[max_index]
                tezyun.append([max_index+1,i+1])
                count+=1
        for i in range(1,N):
            tezyun.append([i,i+1])
    elif abs(max_a)<abs(min_a):
        for i in range(N):
            if a[i]>0:
                a[i]=a[i]+a[min_index]
                tezyun.append([min_index+1,i+1])
                count+=1
        for i in reversed(range(1,N)):
            tezyun.append([i+1,i])

print(len(tezyun))
for te in tezyun:
    print(te[0],te[1])