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

Fixed submission:
# BFS version

#
H, W = list(map(int, input().split()))
M = []
for i in range(H):
    M.append(list(input().rstrip()))

#
def walk(pos):
    queue = [pos]

    while len(queue)>0:
        pos = queue.pop(0)
        x, y = pos
        val = M[y][x]
        #print(x,y,val)

        # up
        if y>0 and (M[y-1][x]=='.' or (isinstance(M[y-1][x], int) and val+1<M[y-1][x])):
            M[y-1][x] = val + 1
            queue += [(x, y-1)]
        # down
        if y<H-1 and (M[y+1][x]=='.' or (isinstance(M[y+1][x], int) and val+1<M[y+1][x])):
            M[y+1][x] = val + 1
            queue += [(x, y+1)]
        # left
        if x>0 and (M[y][x-1]=='.' or (isinstance(M[y][x-1], int) and val+1<M[y][x-1])):
            M[y][x-1] = val + 1
            queue += [(x-1, y)]
        # right
        if x<W-1 and (M[y][x+1]=='.' or (isinstance(M[y][x+1], int) and val+1<M[y][x+1])):
            M[y][x+1] = val + 1
            queue += [(x+1, y)]
        #print('B')

#
M[H-1][W-1] = 1
walk((W-1, H-1))
#print(M)
#exit()

#
if M[0][0]=='.':
    print(-1)
else:
    blocks = sum([m.count('#') for m in M])
    print(H*W - blocks - M[0][0])

Buggy submission (verdict: Runtime Error):
#
H, W = list(map(int, input().split()))
M = []
for i in range(H):
    M.append(list(input().rstrip()))

#
def walk(pos, steps=0):
    x, y = pos
    #print(pos, M)

    #
    if M[y][x]=='.' or steps<M[y][x]:
        M[y][x] = steps
    else:
        #print('A')
        return

    # up
    if y>0 and M[y-1][x]!='#':
        walk((x, y-1), steps+1)
    # down
    if y<H-1 and M[y+1][x]!='#':
        walk((x, y+1), steps+1)
    # left
    if x>0 and M[y][x-1]!='#':
        walk((x-1, y), steps+1)
    # right
    if x<W-1 and M[y][x+1]!='#':
        walk((x+1, y), steps+1)
    #print('B')

#
walk((W-1, H-1))
#print(M)
#exit()

#
if M[0][0]=='.':
    print(-1)
else:
    blocks = sum([m.count('#') for m in M])
    print(H*W - blocks - M[0][0] - 1)
Problem p03463 (python)

Fixed submission:
#
N, A, B = list(map(int, input().split()))

#
if (B-A-1)%2==0:
    print('Borys')
else:
    print('Alice')

Buggy submission (verdict: Runtime Error):
#
N, A, B = list(map(int, input().rstpir().split()))

#
if (B-A-1)%2==0:
    print('Borys')
else:
    print('Alice')
Problem p02936 (python)

Fixed submission:
# coding: utf-8
# Your code here!
import collections
N,Q = map(int,input().split())
Graph = [[] for i in range(N + 1)]

for i in range(N - 1):
    a,b = map(int,input().split())
    Graph[a].append(b)
    Graph[b].append(a)

counter = [0] * (N + 1)

for i in range(Q): #counterに値を入れていく．
    a,b = map(int,input().split())
    counter[a] += b

seen = [False] * (N + 1)
todo = collections.deque()

seen[1] = True
todo.append(1)

while len(todo) != 0:
    v = todo.pop()
    for next_v in Graph[v]:
        if seen[next_v]:
            continue
        seen[next_v] = True
        todo.append(next_v)
        counter[next_v] += counter[v]

print(*counter[1:])

Buggy submission (verdict: Runtime Error):
# coding: utf-8
# Your code here!
N,Q = map(int,input().split())
Graph = [[] for i in range(N + 1)]

for i in range(N - 1):
    a,b = map(int,input().split())
    Graph[a].append(b)
    Graph[b].append(a)

counter = [0] * (N + 1)

for i in range(Q): #counterに値を入れていく．
    a,b = map(int,input().split())
    counter[a] += b

seen = [False] * (N + 1)

def dfs(Graph, seen, v, counter): #s : 根から訪問している頂点までの累積和
    seen[v] = True
    for next_v in Graph[v]:
        if seen[next_v]:
            continue
        counter[next_v] += counter[v]
        dfs(Graph, seen, next_v, counter)
    
    
dfs(Graph, seen, 1, counter)
print(*counter[1:])

Buggy submission (verdict: Runtime Error):
# coding: utf-8
# Your code here!
N,Q = map(int,input().split())
Graph = [[] for i in range(N + 1)]

for i in range(N - 1):
    a,b = map(int,input().split())
    Graph[a].append(b)
    Graph[b].append(a)

counter = [0] * (N + 1)

for i in range(Q): #counterに値を入れていく．
    a,b = map(int,input().split())
    counter[a] += b

seen = [False] * (N + 1)

def dfs(Graph, seen, v, s): #s : 根から訪問している頂点までの累積和
    seen[v] = True
    s += counter[v]
    print(str(s) + " ", end = "")
    for next_v in Graph[v]:
        if seen[next_v]:
            continue
        dfs(Graph, seen, next_v, s)
    
    
dfs(Graph, seen, 1, 0)
Problem p03006 (python)

Fixed submission:
# coding: utf-8
# Your code here!
import sys
import itertools
N = int(input())
balls = []
for i in range(N):
    l = list(map(int,input().split()))	
    balls.append(l)

d = list(itertools.permutations(balls, 2))

#print(d)
if N == 1:
    print(1)
    sys.exit()
    

dic = {}

for i in range(len(d)):
   p = d[i][1][0] - d[i][0][0]
   q = d[i][1][1] - d[i][0][1]
   dic[str(p) + "," + str(q)] = 0
   
for i in range(len(d)):
   p = d[i][1][0] - d[i][0][0]
   q = d[i][1][1] - d[i][0][1]
   dic[str(p) + "," + str(q)] += 1

dic[str(0) + "," + str(0)] = -1


max_num = max(dic.values())
ans = N - max_num
p_q = max(dic.items(), key = lambda x:x[1])[0]
p,q = map(int,p_q.split(","))

#if p == 0 && q == 0:
    
#print(max_num)


print(ans)

Buggy submission (verdict: Runtime Error):
# coding: utf-8
# Your code here!
import itertools
N = int(input())
balls = []
for i in range(N):
    l = list(map(int,input().split()))	
    balls.append(l)

d = list(itertools.permutations(balls, 2))

#print(d)

dic = {}

for i in range(len(d)):
   p = d[i][1][0] - d[i][0][0]
   q = d[i][1][1] - d[i][0][1]
   dic[str(p) + "," + str(q)] = 0
   
for i in range(len(d)):
   p = d[i][1][0] - d[i][0][0]
   q = d[i][1][1] - d[i][0][1]
   
   dic[str(p) + "," + str(q)] += 1

max_num = max(dic.values())
#p_q = max(dic.items(), key = lambda x:x[1])[0]

#p,q = map(int,p_q.split(","))

#print(max_num)

ans = N - max_num
print(ans)

Buggy submission (verdict: Runtime Error):
# coding: utf-8
# Your code here!
import itertools
N = int(input())
balls = []
for i in range(N):
    l = list(map(int,input().split()))	
    balls.append(l)

d = list(itertools.permutations(balls, 2))

#print(d)

dic = {}

for i in range(len(d)):
   p = d[i][1][0] - d[i][0][0]
   q = d[i][1][1] - d[i][0][1]
   dic[str(p) + "," + str(q)] = 0
   
for i in range(len(d)):
   p = d[i][1][0] - d[i][0][0]
   q = d[i][1][1] - d[i][0][1]
   
   dic[str(p) + "," + str(q)] += 1

max_num = max(dic.values())
#p_q = max(dic.items(), key = lambda x:x[1])[0]

#p,q = map(int,p_q.split(","))

#print(max_num)

ans = N - max_num
print(ans)
Problem p03103 (python)

Fixed submission:
n, m = map(int,(input().split()))
d = []
for i in range(n):
    a, b = map(int,(input().split()))
    d.append([a,b])
d = sorted(d)
ans = 0
for i in range(n):
    if d[i][1] >= m: # 残り本数 >= この値段の本数
        ans += d[i][0]*m
        break
    else:
        ans += d[i][0]*d[i][1]
        m -= d[i][1]
        if m <= 0:
            break
print(ans)

Buggy submission (verdict: Runtime Error):
n, m = map(int,(input().split()))
d = {}
for i in range(n):
    a, b = map(int,(input().split()))
    d[a]=b
d = sorted(d.items())
ans = 0
for i in range(n):
    if d[i][1] >= m:
        ans += d[i][0]*m
        break
    else:
        ans += d[i][0]*d[i][1]
        m -= d[i][1]
        if m <= 0:
            break
print(ans)

Buggy submission (verdict: Runtime Error):
n, m = map(int,(input().split()))
d = {}
for i in range(n):
    a, b = map(int,(input().split()))
    d[a]=b
d = sorted(d.items())
ans = 0
for i in range(n):
    if d[i][1] >= m:
        ans += d[i][0]*m
        break
    else:
        ans += d[i][0]*d[i][1]
        m -= d[i][1]
print(ans)

Buggy submission (verdict: Runtime Error):
n, m = map(int,(input().split()))
d = {}
for i in range(n):
    a, b = map(int,(input().split()))
    d[a]=b
d = sorted(d.items())
ans = 0
for i in range(n):
    if d[i][1] >= m: # 残り本数 >= この値段の本数
        ans += d[i][0]*m
        print(ans)
        exit
    else:
        ans += d[i][0]*d[i][1]
        m -= d[i][1]

Buggy submission (verdict: Runtime Error):
n, m = map(int,(input().split()))
d = {}
for i in range(n):
    a, b = map(int,(input().split()))
    d[a]=b
d = sorted(d.items())
ans = 0
for i in range(n):
    if d[i][1] >= m: # 残り本数 >= この値段の本数
        ans += d[i][0]*m
        break
    else:
        ans += d[i][0]*d[i][1]
        m -= d[i][1]
print(ans)
Problem p03206 (python)

Fixed submission:
s=int(input())
if s==25:
    print("Christmas")
elif s==24:
    print("Christmas Eve")
elif s==23:
    print("Christmas Eve Eve")
elif s==22:
    print("Christmas Eve Eve Eve")

Buggy submission (verdict: Runtime Error):
n, k = map(int,(input().split()))
h = []
for i in range(n):
    h.append(int(input()))
h.sort()
min=h[-1]-h[0]
for i in range(n-k+1):
    if h[i+k-1]-h[i] < min:
        min = h[i+k-1]-h[i]
print(min)
Problem p03359 (python)

Fixed submission:
a, b = list(map(int, input().split()))
print(a if b >= a else a-1)

Buggy submission (verdict: Runtime Error):
def solve(g):
    for i in range(1, h+1):
        for j in range(1, w+1):
            if g[i][j] == '#' and g[i][j+1] == '.' \
                    and g[i+1][j] == '.' and g[i][j-1] == '.' \
                    and g[i-1][j] == '.':
                        return False
    return True

h, w = list(map(int, input().split()))
g = [['.']*(w+2)]
g += [['.'] + list(input()) + ['.'] for i in range(h)]
g.append(['.']*(w+2))

if solve(g):
    print('Yes')
else:
    print('No')
Problem p03471 (python)

Fixed submission:
N,Y = map(int,input().split())
ans = "-1 -1 -1"
 
for i in range(N+1):
  for j in range(N+1-i):
    if Y == 10000*i + 5000*j + 1000*(N - i - j):
      print(str(i)+" "+str(j)+" "+str(N-i-j))
      exit()
print(ans)

Buggy submission (verdict: Runtime Error):
N,Y = map(int,input().split())

ans = "-1 -1 -1"

for i in range(N+1):
  for j in range(N+1-j):
    if 0 <= Y - 10000*i - 5000*j <= 500*(N - i - j):
      print(i+" "+j+" "+N-i-j)
      exit()
print(ans)
Problem p03545 (python)

Fixed submission:
A = list(input())

for i in range(2**3):
  tmp=A[:]
  for j in range(3):
    if (i>>j)&1:
      tmp[j]+="-"
    else:
      tmp[j]+="+"
  if eval("".join(tmp)) == 7:
    tmp[-1]+="=7"
    for s in tmp:
      print(s,end="")
    exit()

Buggy submission (verdict: Runtime Error):
A = list(int(input()))

for i in range(2**3):
  tmp=A[:]
  for j in range(3):
    if (i>>j)&1:
      tmp[j]*=-1
  if sum(A) == 7:
    for s in tmp:
      print(s,end="")
    print("=7")
Problem p02934 (python)

Fixed submission:
N = int(input())
A = list(map(int,input().split()))
 
sum = 0
 
for i in range(len(A)):
	sum = (1/A[i]) + sum

a = 1/(sum)
 
print(a)

Buggy submission (verdict: Runtime Error):
N = int(input())
v = list(map(int,input().split()))

sum = 0

for i in range(v)
	sum = 1/v[i] + sum

ans = 1/(sum/N)

print(ans)
Problem p02845 (python)

Fixed submission:
import sys
from bisect import *
import math

input = sys.stdin.readline

N = int(input())
A = list(map(int,input().split()))
mod = 1000000007

cnum = A.count(0)
amax = max(A)

numind = [[] for i in range(amax+1)]
for i,ai in enumerate(A):
	numind[ai].append(i)

if cnum==0 or cnum>3:
	res = 0
else:
	res = 1
	for i in range(amax):
		if len(numind[i+1])==0 or len(numind[i+1])>3:
			res = 0
			break
		for order, j in enumerate(numind[i+1]):
			res = (res * (bisect(numind[i],j)-order)) % mod

	res = (res*math.factorial(3)//math.factorial(3-cnum)) % mod

print(res)

Buggy submission (verdict: Runtime Error):
import sys
from bisect import *
import math

input = sys.stdin.readline

N = int(input())
A = list(map(int,input().split()))
mod = 1000000007

cnum = A.count(0)
amax = max(A)

numind = [[] for i in range(amax+1)]
for i,ai in enumerate(A):
	numind[ai].append(i)

if cnum==0:
	res = 0
else:
	res = 1
	for i in range(amax):
		if len(numind[i+1])==0:
			res = 0
			break
		for order, j in enumerate(numind[i+1]):
			res = (res * (bisect(numind[i],j)-order)) % mod

	res = (res*math.factorial(3)//math.factorial(3-cnum)) % mod

print(res)

Buggy submission (verdict: Runtime Error):
import sys
from bisect import *
import math

input = sys.stdin.readline

N = int(input())
A = list(map(int,input().split()))
mod = 1000000007

cnum = A.count(0)
if cnum==0:
	res = 0
else:
	amax = max(A)
	numind = [[] for i in range(amax+1)]
	for i,ai in enumerate(A):
		numind[ai].append(i)

	res = 1
	for i in range(amax):
		for order, j in enumerate(numind[i+1]):
			res = (res * (bisect(numind[i],j)-order)) % mod

	res = (res*math.factorial(3)//math.factorial(3-cnum)) % mod

print(res)

Buggy submission (verdict: Runtime Error):
import sys
from bisect import *
import math

input = sys.stdin.readline

N = int(input())
A = list(map(int,input().split()))
mod = 1000000007

cnum = A.count(0)
amax = max(A)

numind = [[] for i in range(amax+1)]
for i,ai in enumerate(A):
	numind[ai].append(i)

res = 1
for i in range(amax):
	for order, j in enumerate(numind[i+1]):
		res = (res * (bisect(numind[i],j)-order)) % mod

res = (res*math.factorial(3)//math.factorial(3-cnum)) % mod

print(res)
Problem p02874 (python)

Fixed submission:
import sys

input = sys.stdin.readline

N = int(input())
L, R = [], []
length = []
for i in range(N):
	Li, Ri = map(int,input().split())
	L.append(Li)
	R.append(Ri)
	length.append(Ri-Li)

sindL = sorted(range(N), key=lambda k: L[k])
sindR = sorted(range(N), key=lambda k: R[k])
sind_len = sorted(range(N), key=lambda k: length[k])

indLmax = sindL[-1]
indRmin = sindR[0]

if N==2:
	ans = sum(length)+2
else:
	if indLmax==indRmin:
		ans = R[indRmin]-L[indLmax]+max(length)+2
	else:
		lenmax_ind = sind_len[-1]
		if lenmax_ind==indLmax or lenmax_ind==indRmin:
			lenmax_ind = sind_len[-2]
			if lenmax_ind==indLmax or lenmax_ind==indRmin:
				lenmax_ind = sind_len[-3]
		ans = max(0,R[indRmin]-L[indLmax]+1)+length[lenmax_ind]+1

		Qind = [0]*N
		Qind[indRmin] = 1
		ri = 1
		for li in range(0,N-1):
			QL, QR = L[sindL[li]], R[indRmin]
			Qind[sindL[li]] = 1
			while Qind[sindR[ri]]==1:
				ri += 1
			PL, PR = L[indLmax], R[sindR[ri]]

			ans = max(ans,max(0,PR-PL+1)+max(0,QR-QL+1))

print(ans)

Buggy submission (verdict: Runtime Error):
import sys

input = sys.stdin.readline

N = int(input())
L, R = [], []
length = []
for i in range(N):
	Li, Ri = map(int,input().split())
	L.append(Li)
	R.append(Ri)
	length.append(Ri-Li)

sindL = sorted(range(N), key=lambda k: L[k])
sindR = sorted(range(N), key=lambda k: R[k])
sind_len = sorted(range(N), key=lambda k: length[k])

indLmax = sindL[-1]
indRmin = sindR[0]

if indLmax==indRmin:
	ans = R[indRmin]-L[indLmax]+max(length)+2
else:
	lenmax_ind = sind_len[-1]
	if lenmax_ind==indLmax or lenmax_ind==indRmin:
		lenmax_ind = sind_len[-2]
		if lenmax_ind==indLmax or lenmax_ind==indRmin:
			lenmax_ind = sind_len[-3]
	ans = R[indRmin]-L[indLmax]+length[lenmax_ind]+2

	Qind = [0]*N
	Qind[indRmin] = 1
	ri = 1
	for li in range(0,N-1):
		QL, QR = L[sindL[li]], R[indRmin]
		Qind[sindL[li]] = 1
		while Qind[sindR[ri]]==1:
			ri += 1
			if ri==N: break
		PL, PR = L[indLmax], R[sindR[ri]]

		ans = max(ans,PR-PL+QR-QL+2)

print(ans)
Problem p02889 (python)

Fixed submission:
import sys


def main():
	input = sys.stdin.readline
	N, M, L = list(map(int,input().split()))
	P = [list(map(int,input().split())) for i in range(M)]
	Q = int(input())
	st = [list(map(int,input().split())) for i in range(Q)]

	neighbor = [[] for i in range(N)]
	for s,e,d in P:
		if d<=L:
			neighbor[s-1].append((e-1,d))
			neighbor[e-1].append((s-1,d))
		# if d<=L:
		# 	neighbor[s-1][e-1] = neighbor[e-1][s-1] = d

	# print(neighbor)
	# start, end = 2,1

	fuellist = [0]*N
	def bfs(start, end):
		# fuel = [[10000000,L+1] for i in range(N)]
		fuelc, fuelm = [10000000]*N, [L+1]*N
		# fuel[start][0] = 0
		# fuel[start][1] = L
		fuelc[start], fuelm[start] = 0, L
		queue = [start]
		while len(queue)>0:
			nq = []						# next target node
			nq_append = nq.append
			for i in queue:				# target node
				oc, om = fuelc[i], fuelm[i]
				for j, d in neighbor[i]:
				# for j, d in enumerate(neighbor[i]):	# next node
					# if d==10**10: continue
					if om<d:
						nc = oc+1
						nm = L-d
					else:
						nc = oc
						nm = om-d

					# print(i,j,nc,nm)

					if nc<fuelc[j]:
						fuelc[j], fuelm[j] = nc, nm
						nq_append(j)
					elif nc==fuelc[j] and nm>fuelm[j]:
						fuelm[j] = nm
						nq_append(j)

			queue = nq					# update target node

		# ans = fuel[end][0]
		ans = fuelc[end]
		if ans==10000000: ans = -1

		fuellist[start] = fuelc

		print(ans)

	for s, t in st:
		start, end = s-1, t-1

		if fuellist[start]!=0:
			ans = fuellist[start][end]
			if ans==10000000: ans = -1
			print(ans)
		elif fuellist[end]!=0:
			ans = fuellist[end][start]
			if ans==10000000: ans = -1
			print(ans)
		else:
			bfs(start,end)


if __name__ == '__main__':
	main()

Buggy submission (verdict: Runtime Error):
import sys

input = sys.stdin.readline

def main():
	N, M, L = list(map(int,input().split()))
	P = [list(map(int,input().split())) for i in range(M)]
	Q = int(input())
	st = [list(map(int,input().split())) for i in range(Q)]

	neighbor = [[] for i in range(N)]
	for pi in P:
		if pi[2]<=L:
			neighbor[pi[0]-1].append((pi[1]-1,pi[2]))
			neighbor[pi[1]-1].append((pi[0]-1,pi[2]))

	fuellist = [0]*N
	n_append = nq.append
	def bfs(start, end):
		fuel = [[10000000,L+1] for i in range(N)]
		fuel[start][0] = 0
		fuel[start][1] = L
		queue = [start]
		while len(queue)>0:
			nq = []						# next target node
			for i in queue:				# target node
				oc, om = fuel[i]
				for j, d in neighbor[i]:	# next node
					if om<d:
						nc = oc+1
						nm = L-d
					else:
						nc = oc
						nm = om-d

					# print(i,j,nc,nm)

					if (nc<fuel[j][0]) or (nc==fuel[j][0] and nm>fuel[j][1]):
						fuel[j][0], fuel[j][1] = nc, nm
						n_append(j)

			queue = nq					# update target node

		ans = fuel[end][0]
		if fuel[end][0]==10000000: ans = -1

		fuellist[start] = fuel

		print(ans)

	for s, t in st:
		start, end = s-1, t-1
		if fuellist[start]==0:
			bfs(start,end)
		else:
			ans = fuellist[start][end][0]
			if ans==10000000: ans = -1
			print(ans)


if __name__ == '__main__':
	main()
Problem p02900 (python)

Fixed submission:
import sys
# from math import gcd
from fractions import gcd

input = sys.stdin.readline

A, B = list(map(int,input().split()))

n = gcd(A,B)

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

frl = factorization(n)
if frl[0][0]==1:
	ans = 1
else:
	ans = len(frl)+1
print(ans)

Buggy submission (verdict: Runtime Error):
import sys
from math import gcd
# from fractions import gcd

input = sys.stdin.readline

A, B = list(map(int,input().split()))

n = gcd(A,B)

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

frl = factorization(n)
if frl[0][0]==1:
	ans = 1
else:
	ans = len(frl)+1
print(ans)
Problem p02903 (python)

Fixed submission:
import sys

input = sys.stdin.readline

H, W, A, B = list(map(int,input().split()))

out = [[0]*W for i in range(H)]

for y in range(B):
	for x in range(A):
		out[y][x] = 1

for y in range(B,H):
	for x in range(A,W):
		out[y][x] = 1

for i in out: print(*i, sep='')

Buggy submission (verdict: Runtime Error):
import sys
from fractions import Fraction

input = sys.stdin.readline

N = int(input()) # integer
A = list(map(int,input().split())) # list
M = 998244353

amax = max(A)
w = [1]*amax
for i in range(1,amax+1):
	n = 2
	j = i*n
	while j<=amax:
		w[j-1] -= w[i-1]*n
		n += 1
		j += i

count = [0]*amax
for i in range(N):
	count[A[i]-1] += 1

ans = 0
for i in range(1,amax+1):
	isum = 0
	isumr = 0
	sqsum = 0
	j = i
	while j<=amax:
		isum += j*count[j-1]
		sqsum += j*j*count[j-1]
		j += i

	ans += ((isum**2-sqsum)/2)*w[i-1]//i
	ans = ans%M

print(ans%M)
Problem p03496 (python)

Fixed submission:
import numpy as np


N = int(input().strip())
alist = list(map(int,input().strip().split()))

alist = np.array(alist)
alistp = np.abs(alist)
maxind = np.where(alistp==alistp.max())[0][0]

if alist[maxind]>0:
	positive = True
else:
	positive = False

count = 0
process = []
for i in range(N):
	if alist[i]*alist[maxind]<0:
		alist[i] = alist[i]+alist[maxind]
		count = count+1
		process.append([maxind,i])

if positive==True:
	for i in range(N-1):
		alist[i+1] = alist[i+1]+alist[i]
		count = count+1
		process.append([i,i+1])
else:
	for i in range(N-1,0,-1):
		alist[i-1] = alist[i-1]+alist[i]
		count = count+1
		process.append([i,i-1])

print(count)
for i in range(count):
	processi = process[i]
	print(processi[0]+1,processi[1]+1)

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


N = int(input().strip())
alist = list(map(int,input().strip().split()))

alist = np.array(alist)
alistp = np.abs(alist)
maxind = np.where(alistp==alistp.max())[0][0]

if alist[maxind]>0:
	positive = True
else:
	positive = False

count = 0
process = []
for i in range(N):
	if alist[i]*alist[maxind]<0:
		alist[i] = alist[i]+alist[maxind]
		count = count+1
		process.append([maxind,i])

if positive==True:
	for i in range(N-1):
		alist[i+1] = alist[i+1]+alist[i]
		count = count+1
		process.append([i,i+1])
else:
	for i in range(N,0,-1):
		alist[i-1] = alist[i-1]+alist[i]
		count = count+1
		process.append([i,i-1])

print(count)
for i in range(count):
	processi = process[i]
	print(processi[0]+1,processi[1]+1)
Problem p03251 (python)

Fixed submission:
N, M, X, Y = map(int, input().split())
x = list(map(int, input().split()))
y = list(map(int, input().split()))
x.append(X)
y.append(Y)

def check2():
    return max(x) >= min(y)

if check2():
    print("War")
else:
    print("No War")

Buggy submission (verdict: Runtime Error):
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define pb push_back
#define all(a) a.begin(), a.end()

int N, M;
vector<int> x, y;

int input() {
    int a;
    cin>>a;
    return a;
}

bool check() {
    return max_element(all(x)) < min_element(all(y));
}

int main() {
    
    cin >> N >> M;
    x.pb(input());
    y.pb(input());
    for( int i=0; i < N; ++i)x.pb(input());
    for( int i=0; i < M; ++i)y.pb(input());

    if(check())cout << "No War" << endl;
    else cout << "War" <<endl;

    return 0;
}
Problem p03262 (python)

Fixed submission:
import fractions

N, X = map(int, input().split())

x = list(map(int, input().split()))

t = abs(x[0] - X)
for a in x:
    t = fractions.gcd(t, abs(a - X))
print(t)

Buggy submission (verdict: Runtime Error):
import math
N, X = map(int, input().split())

x = list(map(int, input().split()))

t = abs(x[0] - X)
for a in x:
    t = math.gcd(t, abs(a - X))
print(t)
Problem p02995 (python)

Fixed submission:
def gcd(a, b):
    if a < b:
        a, b = b, a
    if b == 0:
        return a
    return gcd(b, a % b)
def resolve():
    a, b, c, d = list(map(int, input().split()))
    lcm = int(c * d / gcd(c, d))
    c_b = b - (b//c + b//d - b//(lcm))
    c_a = (a-1) - ((a-1)//c + (a-1)//d - (a-1)//(lcm))
    print(c_b - c_a)
    
resolve()

Buggy submission (verdict: Runtime Error):
import math
def resolve():
    a, b, c, d = list(map(int, input().split()))
    lcm = int(c * d / math.gcd(c, d))
    c_b = b - (b//c + b//d - b//(lcm))
    c_a = (a-1) - ((a-1)//c + (a-1)//d - (a-1)//(lcm))
    print(c_b - c_a)
    
resolve()

Buggy submission (verdict: Runtime Error):
import math
def resolve():
    a, b, c, d = list(map(int, input().split()))
    lcm = int(c * d / math.gcd(c, d))
    c_b = b - (b//c + b//d - b//(lcm))
    c_a = (a-1) - ((a-1)//c + (a-1)//d - (a-1)//(lcm))
    print(c_b - c_a)
    
resolve()