Buggy python submission (verdict: Runtime Error):
import math
n = int(input())
a = list(map(int,input().split()))
b = sorted(a)
count = 0

        
def expand_a():
    global a,b,count
    def find_i(k):
        for i in range(n):
            if a[i] == b[k]:
                return i+1
    for i in range(1,n):
        if a[i-1] > a[i]:
            for j in range(n):
                if b[j] >= a[i-1]-a[i]:
                    print (str(find_i(j)) +" " + str(i+1))
                    a[i] += b[j]
                    count += 1
                    b = sorted(a)
                    break
            else:
                mc = math.ceil((a[i-1]-a[i])/b[n-1])
                for _ in range(mc):
                    print(str(find_i(n-1)) +" "+ str(i+1))
                a[i] += b[n-1]*mc
                count += mc
                b = sorted(a)
expand_a()
print (count)

Fixed submission:
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])

Buggy python submission (verdict: Runtime Error):
import math
n = int(input())
a = list(map(int,input().split()))
b = sorted(a)
count = 0

def find_i(j):
    global a,b
    for i in range(n):
        if a[i] == b[j]:
            return i+1
        
def expand_a():
    global a,b,count
    for i in range(1,n):
        if a[i-1] > a[i]:
            for j in range(n):
                if b[j] >= a[i-1]-a[i]:
                    a[i] += b[j]
                    print (str(find_i(j)) +" " + str(i+1))
                    count += 1
                    break
            else:
                mc = math.ceil((a[i-1]-a[i])/b[n-1])
                a[i] += b[n-1]*mc
                count += mc
                for _ in range(mc):
                    print(str(find_i(n-1)) +" "+ str(i+1))
expand_a()
print (count)

Fixed submission:
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])