Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p03031 (python)

Fixed submission:
N, M = map(int, input().split())
switch_list=[input().split() for i in range(M)]
switch_list=[[int(i[m+1]) for m in range(len(i)-1)] for i in switch_list]
P_list=input().split()
P_list=[int(i) for i in P_list]
count=0
z=N
for i in range(1 << z):
    switch=[0 for i in range(N)]
    for j in range(z):
        if ((i >> j) & 1) == 1:
            switch[j]=1
    count+=sum([sum([switch[m-1] for m in switch_list[x]])%2==P_list[x] for x in range(M)])==M
print(count)

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
switch_list=[input().split() for i in range(M)]
switch_list=[[int(i[m+1]) for m in range(len(i)-1)] for i in switch_list]
P_list=input().split()
P_list=[int(i) for i in P_list]
for i in range(1 << z):
    switch=[0 for i in range(N)]
    for j in range(z):
        if ((i >> j) & 1) == 1:
            switch[j]=1
    count+=sum([sum([switch[m-1] for m in switch_list[x]])%2==P_list[x] for x in range(M)])==M
print(count)
Problem p03032 (python)

Fixed submission:
"""from collections import *
from itertools import *
from bisect import *
from heapq import *

import math
from fractions import gcd
import sys
#input = sys.stdin.readline


"""
import copy
from collections import *
from heapq import *
N,K=map(int,input().split())
VVV=list(map(int,input().split()))
value=0

VV=deque(VVV)
Llst=[[]]
V=copy.copy(VV)
for i in range(min(K,N)):
    Llst.append(copy.copy(Llst[-1]))
    a=V.popleft()
    Llst[-1].append(a)

Rlst=[[]]
V=copy.copy(VV)
for i in range(min(K,N)):
    Rlst.append(copy.copy(Rlst[-1]))
    a=V.pop()
    Rlst[-1].append(a)

#print(Llst,Rlst)
for l in range(min(K,N)+1):
    for r in range(min(K,N)+1-l):
        lst=Llst[l]+Rlst[r]
        lst.sort(reverse=True)
        for i in range(K-l-r):
            if lst:
                if lst[-1]<0:
                    lst.pop()
                else:
                    break
            else:
                break
        value=max(value,sum(lst))
print(value)

Buggy submission (verdict: Runtime Error):
"""from collections import *
from itertools import *
from bisect import *
from heapq import *

import math
from fractions import gcd
import sys
#input = sys.stdin.readline


"""
import copy
from collections import *
from heapq import *
N,K=map(int,input().split())
VVV=list(map(int,input().split()))
value=0

VV=deque(VVV)
Llst=[[]]
V=copy.copy(VV)
for i in range(min(K,N)):
    Llst.append(copy.copy(Llst[-1]))
    a=V.popleft()
    Llst[-1].append(a)

Rlst=[[]]
V=copy.copy(VV)
for i in range(min(K,N)):
    Rlst.append(copy.copy(Rlst[-1]))
    a=V.pop()
    Rlst[-1].append(a)

#print(Llst,Rlst)
for l in range(K):
    for r in range(K-l):
        lst=Llst[l]+Rlst[r]
        lst.sort(reverse=True)
        for i in range(K-l-r):
            if lst:
                if lst[-1]<0:
                    lst.pop()
                else:
                    break
            else:
                break
        value=max(value,sum(lst))
print(value)

Buggy submission (verdict: Runtime Error):
"""from collections import *
from itertools import *
from bisect import *
from heapq import *

import math
from fractions import gcd
import sys
#input = sys.stdin.readline


"""
#import copy
from collections import *
from heapq import *
N,K=map(int,input().split())
VVV=list(map(int,input().split()))
value=0

VV=deque(VVV)
Llst=[[]]
V=VV.copy()
for i in range(min(K,N)):
    Llst.append(Llst[-1].copy())
    a=V.popleft()
    Llst[-1].append(a)

Rlst=[[]]
V=VV.copy()
for i in range(min(K,N)):
    Rlst.append(Rlst[-1].copy())
    a=V.pop()
    Rlst[-1].append(a)

#print(Llst,Rlst)
for l in range(K):
    for r in range(K-l):
        lst=Llst[l]+Rlst[r]
        lst.sort(reverse=True)
        for i in range(K-l-r):
            if lst:
                if lst[-1]<0:
                    lst.pop()
                else:
                    break
            else:
                break
        value=max(value,sum(lst))
print(value)
Problem p03035 (python)

Fixed submission:
A,B=map(int,input().split())
if A<=5:
  print(0)
elif 6<=A<=12:
  print(int(B/2))
elif A>=13:
  print(B)

Buggy submission (verdict: Runtime Error):
A,B=map(int,input().split())
if A=<5:
  print(0)
elif 6<=A<=12:
  print(B/2)
elif A>=13:
  print(B)
Problem p03050 (python)

Fixed submission:
N=int(input())
value=0
if N==1:
    print(0)
    exit()
if N==2:
    print(0)
    exit()
for i in range(1,int(N**.5+10)):
    if N%i==0 and N//i>=i+2:
        value+=N//i-1
print(value)

Buggy submission (verdict: Runtime Error):
N=int(input())
value=0
if N==1:
    print(A)
    exit()
if N==2:
    print(0)
    exit()
for i in range(1,int(N**.5+10)):
    if N%i==0 and N//i>=i+1:
        value+=N//i-1
print(value)
Problem p03069 (python)

Fixed submission:
N=int(input())
S=input()
use=[0 if S[i]=="." else 1 for i in range(N)]
now=[0 for i in range(N)]
count=sum(use)
lst=set()
lst.add(count)


for i in range(N-1,-1,-1):
    now[i]=1
    if use[i]:
        use[i]=0
        count-=1
    else:
        use[i]=1
        count+=1
    lst.add(count)
print(min(lst))

Buggy submission (verdict: Runtime Error):
N = int(input())
S = input()
flag=(S[0]=="#")
count=0
for i in range(1,len(S)):
    if not flag:
        flag=(S[i]=="#" and S[i-1]==".")
    if flag:
        if S[i]=="." and S[i-1]=="#":
            count+=1
            s[i]="#"
print(count)
Problem p03074 (python)

Fixed submission:
N,K=map(int,input().split())
S=input()
if N==1:
    print(1)
    exit()


lst=[]
if S[0]!="1":
    lst.append([0,0])
flag=0
for i in range(N):
    if flag==0 and S[i]=="1":
        flag=1
        st=i
    elif flag and S[i]=="0":
        lst.append([st,i-1])
        flag=0
if S[-1]!="1":
    lst.append([N-1,N-1])

if flag:
    lst.append([st,N-1])

if K>=len(lst):
    print(N)
    exit()
else:
    value=0
    for i in range(len(lst)-K):
        a=lst[i+K][1]-lst[i][0] +1
        if a>value:
            value=a
print(value)

Buggy submission (verdict: Runtime Error):
N,K=map(int,input().split())
S=input()
if N==1:
    print(1)
    exit()

lst0=[]

lst1=[]
if S[0]!="1":
    lst1.append([0,0])
flag=0
for i in range(N):
    if flag==0 and S[i]=="1":
        flag=1
        st=i
    elif flag and S[i]=="0":
        lst1.append([st,i-1])
        flag=0
if S[-1]!="1":
    lst1.append([N-1,N-1])

if flag:
    lst1.append([st,N-1])
flag=0
for i in range(N):
    if flag==0 and S[i]=="0":
        flag=1
        st=i
    elif flag and S[i]=="1":
        lst0.append([st,i-1])
        flag=0
if flag:
    lst0.append([st,N-1])

if K>=len(lst1):
    print(N)
else:
    value=0
    for i in range(len(lst1)-K):
        a=lst1[i+K][1]-lst1[i][0] +1
        if a>value:
            value=a
print(value)
Problem p03111 (python)

Fixed submission:
from bisect import *
from collections import *
from fractions import gcd
from math import factorial
from itertools import *
N,A,B,C=map(int,input().split())
L=[int(input()) for i in range(N)]
value=10**10
itelst=[list(permutations(L,i)) for i in range(3,N+1)]
for n in range(N-2):
    for lst in itelst[n]:
        lstsum=sum(lst)
        a=0
        for i1 in range(len(lst)-2):
            a+=lst[i1]
            b=0
            for i2 in range(i1+1,len(lst)-1):
                b+=lst[i2]
                c=lstsum-a-b
                c1,b1,a1=sorted([a,b,c])
                a1=A-a1 if A-a1>0 else a1-A
                b1=B-b1 if B-b1>0 else b1-B
                c1=C-c1 if C-c1>0 else c1-C
                value=min(value, (len(lst)-3)*10 + a1+b1+c1)





print(value)

Buggy submission (verdict: Runtime Error):
N, A, B, C=map(int,input().split())2l=[int(input())foriinrange(N)]3INF=10**945defdfs(cur, a, b, c):6ifcur==N:7returnabs(a-A)+abs(b-B)+abs(c-C)-30ifmin(a, b, c)>0elseINF8ret0=dfs(cur+1, a, b, c)9ret1=dfs(cur+1, a+l[cur], b, c)+1010ret2=dfs(cur+1, a, b+l[cur], c)+1011ret3=dfs(cur+1, a, b, c+l[cur])+1012returnmin(ret0, ret1, ret2, ret3)1314print(dfs(0,0,0,0))
Problem p03112 (python)

Fixed submission:
from bisect import *
A,B,Q=map(int,input().split())
S=[int(input()) for i in range(A)]
T=[int(input()) for i in range(B)]
X=[int(input()) for i in range(Q)]
value1=2*(10**10)
for x in X:
    value=value1
    s1=bisect_left(S,x)
    for s in [s1-1,s1]:
        if -1< s < A:
            t1=bisect_left(T,S[s])
            for t in [t1-1,t1]:
                a=0
                if -1< t < B:
                    if x>S[s]:
                        a+=x-S[s]
                    else:
                        a+=S[s]-x
                    if S[s]>T[t]:
                        a+=S[s]-T[t]
                    else:
                        a+=T[t]-S[s]
                    if value>a:
                        value=a
    t1=bisect_left(T,x)
    for t in [t1-1,t1]:
        if -1< t < B:
            s1=bisect_left(S,T[t])
            for s in [s1-1,s1]:
                a=0
                if -1< s < A:
                    if x>T[t]:
                        a+=x-T[t]
                    else:
                        a+=T[t]-x
                    if S[s]>T[t]:
                        a+=S[s]-T[t]
                    else:
                        a+=T[t]-S[s]
                    if value>a:
                        value=a

    print(value)

Buggy submission (verdict: Runtime Error):
from bisect import *
A,B,Q=map(int,input().split())
S=[int(input()) for i in range(A)]
T=[int(input()) for i in range(B)]
X=[int(input()) for i in range(Q)]
value1=2*(10**10)
for x in range(X):
    value=value1
    s1=bisect_left(S,x)
    for s in [s1-1,s1]:
        if -1< s < A:
            t1=bisect_left(T,S[s])
            for t in [t1-1,t1]:
                a=0
                if -1< t < B:
                    if x>S[s]:
                        a+=x-S[s]
                    else:
                        a+=S[s]-x
                    if S[s]>T[t]:
                        a+=S[s]-T[t]
                    else:
                        a+=T[t]-S[s]
                    if value>a:
                        value=a
    t1=bisect_left(T,x)
    for t in [t1-1,t1]:
        if -1< t < B:
            s1=bisect_left(S,T[t])
            for s in [s1-1,s1]:
                a=0
                if -1< s < A:
                    if x>T[t]:
                        a+=x-T[t]
                    else:
                        a+=T[t]-x
                    if S[s]>T[t]:
                        a+=S[s]-T[t]
                    else:
                        a+=T[t]-S[s]
                    if value>a:
                        value=a

    print(value)
Problem p03142 (python)

Fixed submission:
"""from collections import *
from itertools import *
from bisect import *
from heapq import *

import math
from fractions import gcd
import sys
#input = sys.stdin.readline

import copy
"""
from collections import *
N,M=map(int,input().split())
AB=[list(map(int,input().split())) for i in range(N-1+M)]
data=[[] for i in range(N+1)]
lst=set()
came=[set() for i in range(N+1)]
for a,b in AB:
    data[a].append(b)
    lst.add(b)
    came[b].add(a)

st=list(set(range(1,N))-lst)[0]
stack=deque([st])
lst=[0 for i in range(N+1)]


while stack:
    a=stack.popleft()
    for p in data[a]:
        came[p].remove(a)
        if not came[p]:
            lst[p]=a
            stack.append(p)

for i in range(1,N+1):
    print(lst[i])

Buggy submission (verdict: Runtime Error):
40 90
Problem p03243 (python)

Fixed submission:
import bisect
x=int(input())
a=[i*111 for i in range(1,10)]
print(a[bisect.bisect_left(a,x)])

Buggy submission (verdict: Runtime Error):
import bisect
x=int(input())
a=[i*111 for i in range(1,9)]
print(a[bisect.bisect_left(a,x)])
Problem p03274 (python)

Fixed submission:
N,K=map(int,input().split())
X=list(map(int,input().split()))
if K==1 and 0 in X:
    print(0)
    exit()
if 0 in X:
    K-=1
left=sorted([i for i in X if i<0],reverse=True)
right=[i for i in X if i>0]

lst=set()
for l,L in enumerate(left):
    i=K-(l+1)-1
    if i>=0:
        if i<len(right):
            lst.add(right[i]-L*2)
    else:
        lst.add(-L)

for l,R in enumerate(right):
    i=K-(l+1)-1
    if i>=0:
        if i<len(left):
            lst.add(R*2-left[i])
    else:
        lst.add(R)

print(min(list(lst)))

Buggy submission (verdict: Runtime Error):
N,K=map(int,input().split())
X=list(map(int,input().split()))
if 0 in X:
    K-=1
left=[i for i in X if i<0]
right=[i for i in X if i>0]
lst=set()
for l,L in enumerate(left):
    i=K-(l+1)
    if i>=0:
        if i>=len(right):
            continue
        R=right[i]
        lst.add(R-L*2)
    else:
        lst.add(-L)

for l,R in enumerate(right):
    i=K-(l+1)
    if i>=0:
        if i>=len(left):
            continue
        L=left[i]
        lst.add(R*2-L)
    else:
        lst.add(R)

print(min(list(lst)))
Problem p03287 (python)

Fixed submission:
# input = sys.stdin.readline
from bisect import *
from collections import *
from heapq import *
# import functools
# import itertools
# import math

N,M=map(int,input().split())
A=list(map(int,input().split()))
#A=[i%M for i in A]
data=[0 for i in range(N)]
data[0]=A[0]%M
for i in range(1,N):
    data[i]=(data[i-1]+A[i])%M
data.append(0)
data=Counter(data)
print(sum([data[i]*(data[i]-1)//2 for i in data if data[i]>=2]))

Buggy submission (verdict: Runtime Error):
# input = sys.stdin.readline
from bisect import *
from collections import *
from heapq import *
# import functools
# import itertools
# import math
mod=10**9+7
ferumaC=10000
fac=[0 for i in range(ferumaC)]
fac[0]=1
ifac=[0 for i in range(ferumaC)]
ifac[0]=1
def mpow(x,n):
    num=1
    while n > 0:
        if n&1:
            num=num*x%mod
        x=x*x%mod
        n=n>>1
    return(num)
for i in range(0,ferumaC-1):
    fac[i+1]=(fac[i]*(i+1))%mod
    ifac[i+1]=ifac[i]*mpow(i+1,mod-2)%mod
def comb(a,b):
    if a==0 and b==0:return(1)
    if a<b or a<0:return(0)
    tmp=ifac[a-b]*ifac[b]%mod
    return(tmp*fac[a]%mod)
N,M=map(int,input().split())
A=list(map(int,input().split()))
#A=[i%M for i in A]
data=[0 for i in range(N)]
data[0]=A[0]%M
for i in range(1,N):
    data[i]=(data[i-1]+A[i])%M
data.append(0)
data=Counter(data)
print(sum([comb(data[i],2) for i in data if data[i]>=2]))
Problem p03297 (python)

Fixed submission:
from bisect import *
from collections import *
from fractions import gcd
from math import factorial
from itertools import *
from heapq import *
import copy

T=int(input())
ABCD=[list(map(int,input().split())) for i in range(T)]
for A,B,C,D in ABCD:
    if B>D or A<B:
        print("No")
    elif C>=B:
        print("Yes")
    else:
        F=D-B
        _gcd=gcd(D,B)
        st=(A-B)%_gcd
        #if A==14 and B==10 and C==8 and D==12:
        #    print(B-C-1)
        if B-_gcd+A%_gcd>C:
            print("No")
        else:
            print("Yes")

Buggy submission (verdict: Runtime Error):
from bisect import *
from collections import *
from fractions import gcd
from math import factorial
from itertools import *
from heapq import *
import copy

T=int(input())
ABCD=[list(map(int,input().split())) for i in range(T)]
for A,B,C,D in ABCD:
    if B>D or A<B:
        print("No")
    elif C>=B:
        print("Yes")
    else:
        F=D-B
        _gcd=gcd(D,B)
        st=(A-B)%_gcd
        #if A==14 and B==10 and C==8 and D==12:
        #    print(B-C-1)
        if ((B-A%_gcd)//g)*g+A%_gcd>C:
            print("No")
        else:
            print("Yes")
Problem p03324 (python)

Fixed submission:
D,N= (int(i) for i in input().split())
print(N*(100**D)) if N!=100 else print(101*(100**D))

Buggy submission (verdict: Runtime Error):
print(N*(100**D)) if N!=100 else print(101*(100**D))
Problem p03330 (python)

Fixed submission:
from itertools import *
N,C=map(int,input().split())
D=[list(map(int,input().split())) for i in range(C)]
c=[list(map(int,input().split())) for i in range(N)]

lst=[[],[],[]]

for y in range(N):
    for x in range(N):
        lst[(y+x)%3].append(c[y][x])


Revalue=10**18

valuelst=[[0 for i in range(C)] for i in range(3)]
for v in range(3):
    for Color in range(1,C+1):
        value=0
        for i in lst[v]:
            value+=D[i-1][Color-1]
        valuelst[v][Color-1]=value


for Color1,Color2,Color3 in list(permutations(list(range(1,C+1)),3)):
    value=valuelst[0][Color1-1]+valuelst[1][Color2-1]+valuelst[2][Color3-1]

    Revalue=min(Revalue,value)
print(Revalue)

Buggy submission (verdict: Runtime Error):
import numpy as np
from itertools import *

N,C=map(int,input().split())
D=[list(map(int,input().split())) for i in range(C)]
c=[list(map(int,input().split())) for i in range(N)]

lst=[[],[],[]]

for y in range(N):
    for x in range(N):
        lst[(y+x)%3].append(c[y][x])


Revalue=10**18
for Color1,Color2,Color3 in list(permutations(list(range(1,C+1)),3)):
    value=0
    for i in lst[0]:
        value+=D[i-1][Color1-1]
    for i in lst[1]:
        value+=D[i-1][Color2-1]
    for i in lst[2]:
        value+=D[i-1][Color3-1]
    Revalue=min(Revalue,value)
print(Revalue)
Problem p03393 (python)

Fixed submission:
alphabet=[chr(i+97) for i in range(0,26)]
S=input()
if S=="zyxwvutsrqponmlkjihgfedcba":
    print(-1)
else:
    for i in S:
        alphabet.remove(i)
    if alphabet:
        print(S+alphabet[0])
    else:
        motoS=S
        S=list(S)
        poplist=[]
        stringlist=[]
        while len(S)>=2:
            poplist.append(S[-1])
            S.pop()
            for s in poplist:
                _S=[i for i in S]
                _S[-1]=s
                string=""
                for ss in _S:
                    string+=ss
                stringlist.append(string)
        stringlist.append(motoS)
        stringlist.sort()
        try:print(stringlist[stringlist.index(motoS)+1])
        except:print(stringlist[stringlist.index(motoS)])

Buggy submission (verdict: Runtime Error):
alphabet=[chr(i+97) for i in range(0,26)]
S=input()

#S=    "zyawvutsrqponmlkjihgfedcbx"
if S=="zyxwvutsrqponmlkjihgfedcba":
    print(-1)
else:

    for i in S:
        alphabet.remove(i)
    if alphabet:
        print(S+alphabet[0])
    else:
        motoS=S
        S=list(S)
        poplist=[]
        stringlist=[]
        while len(S)>=2:
            poplist.append(S.pop())
            for s in poplist:
                _S=S
                _S[-1]=s
                string=""
                for ss in _S:
                    string+=ss
                stringlist.append(string)
        stringlist.append(motoS)
        stringlist.sort()
        print(stringlist[stringlist.index(motoS)+1])

Buggy submission (verdict: Runtime Error):
alphabet=[chr(i+97) for i in range(0,26)]
S=input()

#S=    "zyawvutsrqponmlkjihgfedcbx"
if S=="zyxwvutsrqponmlkjihgfedcba":
    print(-1)
else:

    for i in S:
        alphabet.remove(i)
    if alphabet:
        print(S+alphabet[0])
    else:
        motoS=S
        S=list(S)
        poplist=[]
        stringlist=[]
        while len(S)>=2:
            poplist.append(S.pop())
            for s in poplist:
                _S=S
                _S[-1]=s
                string=""
                for ss in _S:
                    string+=ss
                stringlist.append(string)
        stringlist.append(motoS)
stringlist.sort()
print(stringlist[stringlist.index(motoS)+1])
Problem p03394 (python)

Fixed submission:
from bisect import *
from collections import *
from fractions import gcd
from math import factorial
from itertools import *

N=int(input())

if N==3:
    print(2,5,63)
elif N==4:
    print(2,5,20,63)
elif N==5:
    print(2,5,20,63,30)
else:
    lst=[2,3,4,6,9,12]
    count=N-6
    div2=[i for i in range(10,30001,2) if i%6!=0]
    div2.append(8)
    #if len(div2)%2==1:
    #    div2.pop()
    div3=[i for i in range(15,30001,6)]
    #if len(div3)%2==1:
    #    div3.pop()
    div6=[i for i in range(18,30001,6)]
    #print(len(div2),len(div3),len(div6))
    while count>=2 and len(div2)>=2:
        lst.append(div2.pop())
        lst.append(div2.pop())
        count-=2
    while count>=2 and len(div3)>=2:
        lst.append(div3.pop())
        lst.append(div3.pop())
        count-=2
    while count>=1:
        lst.append(div6.pop())
        count-=1
    print(" ".join(list(map(str,lst))))

Buggy submission (verdict: Runtime Error):
from bisect import *
from collections import *
from fractions import gcd
from math import factorial
from itertools import *

N=int(input())

if N==3:
    print(2,5,63)
elif N==4:
    print(2,5,20,63)
elif N==5:
    print(2,5,20,63,30)
else:
    lst=[2,3,4,6,9,12]
    count=N-6
    div2=[i for i in range(14,30001,2) if i%6!=0]
    if len(div2)%2==1:
        div2.pop()
    div3=[i for i in range(15,30001,6)]
    if len(div3)%2==1:
        div3.pop()
    div6=[i for i in range(18,30001,6)]

    while count>=2 and div2:
        lst.append(div2.pop())
        lst.append(div2.pop())
        count-=2
    while count>=2 and div3:
        lst.append(div3.pop())
        lst.append(div3.pop())
        count-=2
    while count>=1:
        lst.append(div6.pop())
        count-=1
    print(" ".join(list(map(str,lst))))
Problem p03498 (python)

Fixed submission:
"""from collections import *
from itertools import *
from bisect import *
from heapq import *

import math
from fractions import gcd"""
import sys
#input = sys.stdin.readline

import copy

N=int(input())
Amoto=list(map(int,input().split()))
lst=[]
A=copy.copy(Amoto)
_min=A[0]
minidx=0
for i in range(1,N):
    if _min>A[i]:
        _min=A[i]
        minidx=i
if _min<0:
    for i in range(N)[::-1]:
        while _min<A[i] and len(lst)<=2*N+1:
            A[i]+=_min
            lst.append([minidx+1,i+1])
        minidx=i
        _min=A[i]

    if  len(lst)<=2*N:
        print(len(lst))
        for i in lst:
            print(" ".join([str(x) for x in i ]))
        exit()
A=copy.copy(Amoto)
_max=A[0]
maxidx=0
lst=[]
for i in range(1,N):
    if _max<A[i]:
        _max=A[i]
        maxidx=i
if _max>0:
    for i in range(N):
        while _max>A[i] and len(lst)<=2*N+1:
            A[i]+=_max
            lst.append([maxidx+1,i+1])
        maxidx=i
        _max=A[i]
    if  len(lst)<=2*N:
        print(len(lst))
        for i in lst:
            print(" ".join([str(x) for x in i ]))
        exit()
else:
    print(0)

Buggy submission (verdict: Runtime Error):
"""from collections import *
from itertools import *
from bisect import *
from heapq import *

import math
from fractions import gcd"""
import sys
#input = sys.stdin.readline

import copy

N=int(input())
Amoto=list(map(int,input().split()))
A=copy.copy(Amoto)
_min=A[0]
minidx=0
for i in range(1,N):
    if _min>A[i]:
        _min=A[i]
        minidx=i


lst=[]
if _min<0:
    for i in range(N)[::-1]:
        while _min<A[i] and len(lst)<=2*N+1:
            A[i]+=_min
            lst.append([minidx+1,i+1])
        minidx=i
        _min=A[i]

if not len(lst)>2*N:
    print(len(lst))
    for i in lst:
        print(" ".join([str(x) for x in i ]))
    exit()
A=copy.copy(Amoto)
_max=A[0]
maxidx=0
for i in range(1,N):
    if _max<A[i]:
        _max=A[i]
        maxidx=i
if _max>0:
    for i in range(N):
        while _max>A[i] and len(lst)<=2*N+1:
            A[i]+=_max
            lst.append([maxidx+1,i+1])
        maxidx=i
        _max=A[i]
if not len(lst)>2*N:
    print(len(lst))
    for i in lst:
        print(" ".join([str(x) for x in i ]))
    exit()
else:
    print(unko)
Problem p03565 (python)

Fixed submission:
Sz=list(input())
T=list(input())
Flag=0

for i in range(len(Sz)-len(T),-1,-1):
    Flag=1
    for s in range(len(T)):

        if not (Sz[i+s]=="?" or Sz[i+s]==T[s]):
            Flag=0
            break
    if Flag:
        for s in range(len(T)):
             Sz[i+s]=T[s]
        break
for i in range(len(Sz)):
    if Sz[i]=="?":Sz[i]="a"

if Flag:print("".join(Sz))
else:print("UNRESTORABLE ")

Buggy submission (verdict: Runtime Error):
Sz=list(input())
T=list(input())

for i in range(len(Sz)-len(T),-1,-1):
    Flag=1
    for s in range(len(T)):

        if not (Sz[i+s]=="?" or Sz[i+s]==T[s]):
            Flag=0
            break
    if Flag:
        for s in range(len(T)):
             Sz[i+s]=T[s]
        break
for i in range(len(Sz)):
    if Sz[i]=="?":Sz[i]="a"

if Flag:print("".join(Sz))
else:print("UNRESTORABLE ")