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 io
import sys
import math


def add_x_to_y():
    pass

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

def check_plus_minus(lst):
    
    
    p_flag = False
    m_flag = False
    for a in lst:
        if a >= 0:
            p_flag = True
        else:
            m_flag = True
        if p_flag and m_flag:
            return 0
    return 1 if p_flag else -1


def format_multi_answer(lst):
    ans = ""
    ans += f"{len(lst)}\n"
    for y in lst:
        ans += f"{y[0]} {y[1]}\n"
    return ans

def solve(n,a_lst):
    """
    戦略A：
    [全て正の場合]
    ・左から、NGとなる値のiを得る。
    ・その値に正の値を足し込む
    　・リスト中、最大の正の値を足し込む
    　　・iの値が最大となる
    　・以後、右の値を全て更新する。最大でN-1回のオペレーションになる。
    [全て負の場合]
    ・同様に、右から探査し、最小の負の数を更新していく。最大でN-1回のオペレーションになる。
    [正負混在する場合]
    ・最大値/最小値を取る。
    ・正負いずれかに揃える。（絶対値の大きい側に、全ての値を揃える）（最大でN-1回）
    ・上記の正負処理をする。（最大でN-1回）
    """
    
    if is_condition_ok(a_lst):
        return 0

    plus_minus = check_plus_minus(a_lst)

    ans_lst = []
    if plus_minus == 1:
        y = 0
        for i in range(len(a_lst)-1):
            if a_lst[i] > a_lst[i+1]:
                y = i+1
                break
        x = -1
        a_max = -1
        for i in range(len(a_lst)):
            if a_max < a_lst[i]:
                a_max = a_lst[i]
                x = i
        ans_lst.append([x+1,y+1])
        for i in range(y, len(a_lst)-1):
            ans_lst.append([i+1,i+2])
    
    elif plus_minus == -1:
        y = 0
        for i in range(len(a_lst)-1,0,-1):
            if a_lst[i] < a_lst[i-1]:
                y = i-1
                break
        x = +1
        a_min = +1
        for i in range(len(a_lst)):
            if a_min > a_lst[i]:
                a_min = a_lst[i]
                x = i
        ans_lst.append([x+1,y+1])
        for i in range(y,0,-1):
            ans_lst.append([i+1,i])
    
    elif plus_minus == 0:
        
        i_max, a_max = -1,-1
        i_min, a_min = +1,+1
        for i in range(len(a_lst)):
            if a_max < a_lst[i]:
                a_max = a_lst[i]
                i_max = i
            if a_min > a_lst[i]:
                a_min = a_lst[i]
                i_min = i

        if a_max > abs(a_min):
            
            
            for i in range(len(a_lst)):
                if a_lst[i] < 0:
                    a_lst[i] += a_max
                    ans_lst.append([i_max+1,i+1])
            if _DEB: logd(f"lst: {a_lst}")

            y = -1
            for i in range(len(a_lst)-1):
                if a_lst[i] > a_lst[i+1]:
                    y = i+1
                    break
            if y != -1:
                ans_lst.append([i_max+1,y+1])
                for i in range(y, len(a_lst)-1):
                    ans_lst.append([i+1,i+2])
        else:
            
            for i in range(len(a_lst)):
                if a_lst[i] >= 0:
                    a_lst[i] += a_min
                    ans_lst.append([i_min+1,i+1])
            if _DEB: logd(f"lst: {a_lst}")

            y = -1
            for i in range(len(a_lst)-1,0,-1):
                if a_lst[i] < a_lst[i-1]:
                    y = i-1
                    break
            if y != -1: 
                ans_lst.append([i_min+1,y+1])
                for i in range(y,0,-1):
                    ans_lst.append([i+1,i])

    return format_multi_answer(ans_lst)

def main():
    
    n = int(input())
    a_lst = list(map(int, input().split()))

    
    if _DEB: logd(f"a_lst: {a_lst}") 
    ans = str( solve(n,a_lst) ).strip()
    
    
    print(ans)
    return ans
        

_DEB = 0   

_INPUT = """\
2
-1 -3
"""
_EXPECTED = """\
2
2 3
3 3
"""

def logd(str):
    """usage:
    if _DEB: logd(f"{str}")
    """
    if _DEB: print(f"[deb] {str}")


if __name__ == "__main__":
    if _DEB:
        sys.stdin = io.StringIO(_INPUT)
        print("!! Debug Mode !!")

    ans = main()

    if _DEB:
        print()
        if _EXPECTED.strip() == ans.strip(): print("!! Success !!")
        else: print(f"!! Failed... !!\nANSWER:   {ans}\nExpected: {_EXPECTED}")

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

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

m = 0
im = 0
for i, ai in enumerate(a):
  if abs(ai) >= abs(m):
    m = ai
    im = i
print(2*n-1)

for i in range(n):
  print(im+1, i+1)

if m > 0:
  for i in range(0, n-1):
    print(i+1, i+2)
else:
  for i in reversed(range(1, n)):
    print(i+1, i)

Solution (Python):




import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,factorial
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

n=I()
lis=LI()
mxabs=-1
pos=0
for i in range(n):
    if abs(lis[i])>mxabs:
        pos=i
        mxabs=abs(lis[i])
answers=[]
if lis[pos]>0:
    x=lis[pos]
    for i in range(n):
        if lis[i]<x:
            lis[i]+=x
            answers.append((pos+1,i+1))
    for i in range(n-1):
        if lis[i+1]<lis[i]:
            lis[i+1]+=lis[i]
            answers.append((i+1,i+2))
elif lis[pos]<0:
    x=lis[pos]
    for i in range(n):
        if lis[i]>x:
            lis[i]+=x
            answers.append((pos+1,i+1))
    for i in range(n-1):
        j=n-i-1
        if lis[j-1]>lis[j]:
            lis[j-1]+=lis[j]
            answers.append((j+1,j))
print(len(answers))
for i in range(len(answers)):
    print(*answers[i])

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

mx = max(A)
mn = min(A)

ans = []
if abs(mx) > abs(mn):
    for i in range(1, N+1):
        ans += [[A.index(mx)+1, i]]
    for i in range(1, N):
        ans += [[i, i+1]]
else:
    for i in range(1, N+1):
        ans += [[A.index(mn)+1, i]]
    for i in range(N, 1, -1):
        ans += [[i, i-1]]

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

Solution (Python):
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns)

def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query)

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
import heapq
import math
from fractions import gcd
import random
import string
import copy
from itertools import combinations, permutations, product
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7






N = getN()
A = getList()

abs_max = A[0]
max_index = 0
ans = []
for i in range(1, N):
    opt = abs(A[i])
    if opt >= abs_max:
        abs_max = opt
        max_index = i

for i in range(N):
    if i != max_index:
        A[i] += A[max_index]
        ans.append([max_index + 1, i + 1])

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

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

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
out = []
cnt = 0
Amax = max(A)
Amaxi = A.index(Amax)
Amin = min(A)
Amini = A.index(Amin)
if abs(Amax)>=abs(Amin):
    for i in range(N):
        if i==Amaxi:
            continue
        else:
            A[i] = A[i]+Amax
            out.append([Amaxi+1,i+1])
            cnt+=1
    for i in range(1,N):
        A[i] = A[i-1]+A[i]
        out.append([i,i+1])
        cnt+=1
else:
    for i in range(N):
        if i==Amini:
            continue
        else:
            A[i] = A[i]+Amin
            out.append([Amini+1,i+1])
            cnt+=1
    for i in range(1,N):
        A[N-i-1] = A[N-i]+A[N-i-1]
        out.append([N-i+1,N-i])
        cnt+=1

print(cnt)
for i in range(len(out)):
    X = out[i]
    print(*X)

Solution (Python):
def main():
    n, *a = map(int, open(0).read().split())
    p, q = min(a), max(a)

    if p == q:
        print(0)
        exit()

    x = []
    f, g = a.index(p) + 1, a.index(q) + 1
    if abs(p) > abs(q):
        for i in range(n):
            if a[i] > 0:
                x.append((f, i + 1))
        for i in range(n - 1):
            x.append((n - i, n - i - 1))

    else:
        for i in range(n):
            if a[i] < 0:
                x.append((g, i + 1))
        for i in range(n - 1):
            x.append((i + 1, i + 2))

    print(len(x))
    print('\n'.join(['{} {}'.format(i[0], i[1]) for i in x]))


if __name__ == '__main__':
    main()

Solution (Python):
def main():
    n, *a = map(int, open(0).read().split())
    p, q = min(a), max(a)

    if p == q:
        print(0)
        exit()

    x = []
    f, g = a.index(p) + 1, a.index(q) + 1
    if abs(p) > abs(q):
        for i in range(n):
            if a[i] > 0:
                x.append((f, i + 1))
        for i in range(n - 1):
            x.append((n - i, n - i - 1))

    else:
        for i in range(n):
            if a[i] < 0:
                x.append((g, i + 1))
        for i in range(n - 1):
            x.append((i + 1, i + 2))

    print(len(x))
    y = ['{} {}'.format(i[0], i[1]) for i in x]
    print('\n'.join(y))


if __name__ == '__main__':
    main()

Solution (Python):
def main():
    n, *a = map(int, open(0).read().split())
    p, q = min(a), max(a)

    if p == q:
        print(0)
        exit()

    x = []
    f, g = a.index(p) + 1, a.index(q) + 1
    if abs(p) > abs(q):
        for i in range(n):
            if a[i] > 0:
                x.append((f, i + 1))
        for i in range(n - 1):
            x.append((n - i, n - i - 1))

    else:
        for i in range(n):
            if a[i] < 0:
                x.append((g, i + 1))
        for i in range(n - 1):
            x.append((i + 1, i + 2))

    print(len(x))
    y = ['{} {}'.format(i[0], i[1]) for i in x]
    print('\n'.join(y))


if __name__ == '__main__':
    main()

Solution (Python):






import sys
input = sys.stdin.readline

import math

import bisect
import heapq
from collections import defaultdict
from collections import deque
from collections import Counter
from functools import lru_cache





MOD = 10**9+7
INF = float('inf')
AZ = "abcdefghijklmnopqrstuvwxyz"






def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]


def P(arg): print(arg); return
def Y(): print("Yes"); return
def N(): print("No"); return
def E(): exit()
def PE(arg): print(arg); exit()
def YE(): print("Yes"); exit()
def NE(): print("No"); exit()


def DD(arg): return defaultdict(arg)


def inv(n): return pow(n, MOD-2, MOD)


kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n): return kaijo_memo[n]
  if(len(kaijo_memo) == 0): kaijo_memo.append(1)
  while(len(kaijo_memo) <= n): kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n): return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0): gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n): gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if n == r: return 1
  if n < r or r < 0: return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret


def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0: 
        cnt+=1 
        temp //= i
      arr.append([i, cnt])
  if temp!=1: arr.append([temp, 1])
  if arr==[]: arr.append([n, 1])
  return arr


def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  return divisors


def make_primes(N):
  max = int(math.sqrt(N))
  seachList = [i for i in range(2,N+1)]
  primeNum = []
  while seachList[0] <= max:
    primeNum.append(seachList[0])
    tmp = seachList[0]
    seachList = [i for i in seachList if i % tmp != 0]
  primeNum.extend(seachList)
  return primeNum


def gcd(a, b):
    while b: a, b = b, a % b
    return a


def lcm(a, b):
    return a * b // gcd (a, b)


def count_bit(n):
  count = 0
  while n:
    n &= n-1
    count += 1
  return count


def base_10_to_n(X, n):
  if X//n: return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i-1])*n**i for i in range(len(str(X))))

def base_10_to_n_without_0(X, n):
  X -= 1
  if X//n: return base_10_to_n_without_0(X//n, n)+[X%n]
  return [X%n]


def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count





N = I()
A = IL()

MAX = max(A)
MIN = min(A)
ma = A.index(MAX)
mi = A.index(MIN)
print(2*N-1)
if MAX + MIN >= 0:
  for i in range(N):
    print(ma+1,i+1)
  for i in range(N-1):
    print(i+1,i+2)
else:
  for i in range(N):
    print(mi+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()))
maxa=max(a)
mina=min(a)
if abs(mina)<=abs(maxa):
  idx=a.index(maxa)
  print(2*(n-1))
  pre=idx+1
  for i in range(1,n):
    print(pre,i+1)
    print(pre,i+1)
    pre=i+1
elif abs(mina)>abs(maxa):
  idx=a.index(mina)
  print(2*(n-1))
  pre=idx+1
  for i in range(n-1,0,-1):
    print(pre,i)
    print(pre,i)
    pre=i

Solution (Python):
def resolve():
    N = int(input())
    A = list(map(int, input().split()))
    maximum, minimum = max(A), min(A)
    maxidx = A.index(maximum)
    minidx = A.index(minimum)
    ops = []

    for i in range(N):
        if abs(maximum) > abs(minimum):
            A[i] += maximum
            ops.append((maxidx, i))
        else:
            A[i] += minimum
            ops.append((minidx, i))
    
    

    if abs(maximum) > abs(minimum):
        for i in range(0, N-1):
            ops.append((i, i+1))
            A[i+1] += A[i]
    else:
        for i in range(N-1, 0, -1):
            ops.append((i, i-1))
    
    
    print(len(ops))
    [print(v[0]+1, v[1]+1) for v in ops]
    

if '__main__' == __name__:
    resolve()

Solution (Python):
n = int(input())
a = [int(i) for i in input().split()]
M = max(a)
m = min(a)
print(2*n-1)
if abs(M) > abs(m):
    Mi = a.index(M)
    for i in range(n):
        
        print(Mi+1,i+1)
    for i in range(n-1):
        
        print(i+1,i+2)
else:
    mi = a.index(m)
    for i in range(n):
        
        print(mi+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()))
pos,zero,neg=0,0,0
maxi=-10**10
mini=10**10
for num in a:
    if num>0:
        pos+=1
    elif num==0:
        zero+=1
    else:
        neg+=1
    maxi=max(maxi,num)
    mini=min(mini,num)
maxidx=a.index(maxi)
minidx=a.index(mini)
if neg==0:
    print(n-1)
    for i in range(1,n):
        print(i,i+1)
elif pos==0:
    print(n-1)
    for i in reversed(range(1,n)):
        print(i+1,i)
else:
    print(2*n-2)
    if abs(maxi)>=abs(mini):
        for i in range(n):
            if i!=maxidx:
                print(maxidx+1,i+1)
        for i in range(1,n):
            print(i,i+1)
    else:
        for i in range(n):
            if i!=minidx:
                print(minidx+1,i+1)
        for i in reversed(range(1,n)):
            print(i+1,i)

Solution (Python):
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n = int(readline())
    a = list(map(int, readline().split()))
    b = list(map(abs, a))
    idx = b.index(max(b))

    res = []
    for i, x in enumerate(a):
        a[i] += a[idx]
        res.append((idx + 1, i + 1))

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

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


if __name__ == '__main__':
    main()

Solution (Python):
from sys import stdin
def main():
    
    readline=stdin.readline
    n=int(readline())
    a=list(map(int,readline().split()))

    max_i=0
    for i in range(n):
        if abs(a[max_i])<abs(a[i]):
            max_i=i
    
    a=list(map(lambda x:x+a[max_i],a))
    ans=[]
    for i in range(n):
        ans.append([max_i+1,i+1])
    
    if a[0]>=0:
        for i in range(n-1):
            ans.append([i+1,i+2])
    else:
        for i in range(n-1,0,-1):
            ans.append([i+1,i])

    print(2*n-1)
    for i in range(2*n-1):
        print(*ans[i])

if __name__=="__main__":
    main()

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
amax = -10**7
amin = 10**7
indexmax = 51
indexmin = 51
print(2*N-1)
for i in range(N):
	if amax < A[i]:
		amax = A[i]
		indexmax = i
	if amin > A[i]:
		amin = A[i]
		indexmin = i
if abs(amax) >= abs(amin):
	for i in range(N):
		print(indexmax+1, end=' ')
		print(i+1)
	for i in range(N-1):
		print(i+1, end=' ')
		print(i+2)
else:
	for i in range(N):
		print(indexmin+1, end=' ')
		print(i+1)
	for i in range(N-1):
		print(N-i, end=' ')
		print(N-i-1)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
max_A = -10**9
max_num = 0
min_A = 10**9
min_num = 0
for i in range(N):
  if(max_A < A[i]):
    max_A = A[i]
    max_num = i
  if(min_A > A[i]):
    min_A = A[i]
    min_num = i
if(max_A > 0 and min_A < 0):
  if(abs(max_A) >= abs(min_A)):
    print(2*N-1)
    for i in range(N):
      A[i] += max_A
      print(max_num+1, i+1)
    for i in range(N-1):
      print(i+1, i+2)
  else:
    print(2*N-1)
    for i in range(N):
      A[i] += min_A
      print(min_num+1, i+1)
    for i in range(N-1, 0, -1):
      print(i+1, i)
elif(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, 0, -1):
    print(i+1, i)
else:
  print(0)

Solution (Python):
A = int(input())
a = list(map(int, input().split()))
mx = max(a)
mn = min(a)

if mn >= 0:
    print(A-1)
    for i in range(1, A):
        print(i, i+1)
elif mx <= 0:
    print(A-1)
    for i in range(A, 1, -1):
        print(i, i-1)
else:
    print(A*2-1)
    if mx >= abs(mn):
        index = a.index(mx) + 1
        for i in range(1, A+1):
            print(index, i)
        for i in range(1, A):
            print(i, i+1)
    else:
        index = a.index(mn) + 1
        for i in range(1, A+1):
            print(index, i)
        for i in range(A, 1, -1):
            print(i, i-1)

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

min1 = min(a)
max1 = max(a)
idx1 = a.index(min1)
idx2 = a.index(max1)

print(2*n-2)

if abs(min1) < abs(max1):
    for i in range(n):
        if i != idx2:
            print(idx2+1, i+1)
    for i in range(n-1):
        print(i+1, i+2)

else:
    for i in range(n):
        if i != idx1:
            print(idx1+1, i+1)
    for i in range(n-1):
        print(n-i, n-i-1)

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())
    A = list(map(int, input().split()))

    max_num = 0
    max_idx = 0
    for i in range(n):
        if abs(A[i]) > abs(max_num):
            max_num = A[i]
            max_idx = i

    res = []
    if max_num >= 0:
        for i in range(n):
            if A[i] < 0:
                A[i] += max_num
                res.append([max_idx + 1, i + 1])

        for i in range(1, n):
            A[i] += A[i - 1]
            res.append([i, i + 1])
    else:
        for i in range(n):
            if A[i] > 0:
                A[i] += max_num
                res.append([max_idx + 1, i + 1])

        for i in reversed(range(n - 1)):
            A[i] += A[i + 1]
            res.append([i + 2, i + 1])

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


if __name__ == '__main__':
    resolve()

Solution (Python):


import sys






























def main():
    mod = 1000000007                
    inf = float('inf')              
    
    sys.setrecursionlimit(10**6)    
    def input(): return sys.stdin.readline().rstrip()
    def ii():    return int(input())
    def mi():    return map(int, input().split())
    def mi_0():  return map(lambda x: int(x)-1, input().split())
    def lmi():   return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():    return list(input())
    
    def change_to_all_pos_or_all_neg(L):
        n = len(L)
        M = max(L)
        M_ind = L.index(M)
        m = min(L)
        m_ind = L.index(m)
        assert M > 0 and m < 0
        if M >= abs(m):
            for i in range(n):
                L[i] += M
            command = [[M_ind+1, i+1] for i in range(n)]
        else:
            for i in range(n):
                L[i] += m
            command = [[m_ind+1, i+1] for i in range(n)]
        
        return command
    
    def change_to_non_increasing(L):
        assert all(map(lambda x: x>=0, L)) or all(map(lambda x: x<=0, L))
        all_positive = all(map(lambda x: x>=0, L))
        pivot = max(L) if all_positive else min(L)
        pivot_ind = L.index(pivot)
        if all_positive:
            command = [[pivot_ind+1, 1]] + [[i, i+1] for i in range(1, n)]
        else:
            command = [[pivot_ind+1, n]] + [[i, i-1] for i in range(n, 1, -1)]
        return command


    
    n = ii()
    L = lmi()
    command = []
    if all(map(lambda x: x>=0, L)):
        cnt = n
        command += change_to_non_increasing(L)
    elif all(map(lambda x: x<=0, L)):
        cnt = n
        command += change_to_non_increasing(L)
    else:
        cnt = 2 * n
        command += change_to_all_pos_or_all_neg(L)
        command += change_to_non_increasing(L)
    
    print(cnt)
    for a, b in command:
        print("{} {}".format(a, b))
        
    




if __name__ == "__main__":
    main()

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
min_a, max_a = min(A), max(A)
min_idx, max_idx = A.index(min_a)+1, A.index(max_a)+1

ans = []
if abs(min_a) <= abs(max_a):
  for i in range(1, N+1):
    ans.append([max_idx, i])
  for i in range(1, N):
    ans.append([i, i+1])
else:
  for i in range(1, N+1):
    ans.append([min_idx, i])
  for i in range(N, 1, -1):
    ans.append([i, i-1])

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

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
M=a.index(max(a))
m=a.index(min(a))
if max(a)>=-min(a):
	r=max(a)
	for i in range(n):
		a[i]+=r
	print(n*2-2)
	for i in range(n):
		if i!=M:
			print(M+1,i+1)
	for i in range(n-1):
		print(i+1,i+2)
else:
	print(n*2-2)
	r=min(a)
	for i in range(n):
		a[i]+=r
	for i in range(n):
		if i!=m:
			print(m+1,i+1)
	for i in range(n-1):
		print(n-i,n-i-1)

Solution (Python):
def main():
    N = int(input())
    A = list(map(int, input().split(' ')))
    ans = list()
    
    max_A, min_A = max(A), min(A)
    all_positive = (min(A) > 0)
    if max_A >= 0 >= min_A:
        if max_A > abs(min_A):
            max_index = A.index(max_A)
            for i in range(N):
                if i == max_index:
                    continue
                ans.append('{} {}'.format(max_index + 1, i + 1))
            all_positive = True
        else:
            min_index = A.index(min_A)
            for i in range(N):
                if i == min_index:
                    continue
                ans.append('{} {}'.format(min_index + 1, i + 1))
            all_positive = False
    
    if all_positive:
        for i in range(N - 1):
            ans.append('{} {}'.format(i + 1, i + 2))
    else:
        for i in range(N - 1):
            ans.append('{} {}'.format(N - i, N - i - 1))
    print(len(ans))
    for a in ans:
        print(a)


if __name__ == '__main__':
    main()

Solution (Python):

import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    N=int(input())
    a=tuple(map(int,input().split()))
    MAX=max(a)
    MIN=min(a)
    MAX_i=a.index(MAX)
    MIN_i=a.index(MIN)
    ans=[]
    if MAX>abs(MIN):
        for i in range(N):
            if i==MAX_i:
                continue
            ans.append((MAX_i,i))
        for i in range(N-1):
            ans.append((i,i+1))
    else:
        for i in range(N):
            if i==MIN_i:
                continue
            ans.append((MIN_i,i))
        for i in range(N-1,0,-1):
            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):
n = int(input())
print(2 * (n - 1))
a = list(map(int, input().split()))
index = 0
for i in range(1, n):
  if abs(a[i]) > abs(a[index]):
    index = i
if a[index] >= 0:
  for i in range(1, n):
    a[i] += a[index]
    print(index + 1, i + 1)
    if abs(a[i]) > abs(a[index]):
      index = i
    a[i] += a[index]
    print(index + 1, i + 1)
    if abs(a[i]) > abs(a[index]):
      index = i
else:
  for i in range(n - 2, -1, -1):
    a[i] += a[index]
    print(index + 1, i + 1)
    if abs(a[i]) > abs(a[index]):
      index = i
    a[i] += a[index]
    print(index + 1, i + 1)
    if abs(a[i]) > abs(a[index]):
      index = i

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

MAX=max(a)
MIN=min(a)
m=0
operation=[]
if abs(MAX)>=abs(MIN):
    n=a.index(MAX)
    for i in range(N):
        a[i]+=MAX
        m+=1
        operation.append([n+1,i+1])
    for i in range(N-1):
        a[i+1]+=a[i]
        m+=1
        operation.append([i+1,i+2])
else:
    n=a.index(MIN)
    for i in range(N):
        a[i]+=MIN
        m+=1
        operation.append([n+1,i+1])
    for i in range(N-1,0,-1):
        a[i-1]+=a[i]
        m+=1
        operation.append([i+1,i])

print(m)
for i in range(m):
    print(*operation[i])

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

import sys
N=int(sys.stdin.readline().strip())
A=map(int, sys.stdin.readline().split())
A_max=max(A)
A_max_idx=A.index(A_max)    
A_min=min(A)
A_min_idx=A.index(A_min)    

if 0<=A_min:    
    print N-1
    for i in range(1,N):
        print i,i+1
else:    
    if 0<=A_max:
        if abs(A_min)<=abs(A_max):  
            print 2*N-1
            for i in range(1,N+1):  
                print A_max_idx+1,i
            for i in range(1,N):    
                print i,i+1
        elif abs(A_min)>abs(A_max):  
            print 2*N-1
            for i in range(1,N+1):  
                print A_min_idx+1,i
            for i in range(N,1,-1): 
                print i,i-1
    elif A_max<0:   
        print N-1
        for i in range(N,1,-1): 
            print i,i-1

Solution (Python):

import sys
N=int(sys.stdin.readline().strip())
A=map(int, sys.stdin.readline().split())
A_max=max(A)
A_max_idx=A.index(A_max)    
A_min=min(A)
A_min_idx=A.index(A_min)    

if 0<=A_min:    
    print N-1
    for i in range(1,N):
        print i,i+1
else:    
    if 0<=A_max:
        if abs(A_min)<=abs(A_max):  
            print 2*N-1
            for i in range(1,N+1):  
                print A_max_idx+1,i
            for i in range(1,N):    
                print i,i+1
        elif abs(A_min)>abs(A_max):  
            print 2*N-1
            for i in range(1,N+1):  
                print A_min_idx+1,i
            for i in range(N,1,-1): 
                print i,i-1
    elif A_max<0:   
        print N-1
        for i in range(N,1,-1): 
            print i,i-1