Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
p = [int(i) for i in raw_input().split()]
a = [0 for i in range(n)]
b = [0 for i in range(n)]

for i in range(n):
	a[p[i]-1] = i + 1
	b[p[i]-1] = i + 1
for i in range(1,n):
	d = min(a[i] - a[i-1],b[i-1] - b[i])
	if d <= 0:
		a[i] -= d - 1
		b[i] += d - 1
a = [str(i+1-min(a)) for i in a] 
b = [str(i+1-min(b)) for i in b]

print(" ".join(a))
print(" ".join(b))

Fixed submission:
n = int(input())
p = [int(i) for i in raw_input().split()]
a = [0 for i in range(n)]
b = [0 for i in range(n)]
p.reverse()
for i in range(n):
	k = p.pop()
	a[k-1] = i + 1
	b[k-1] = i + 1
for i in range(1,n):
	d = min(a[i] - a[i-1],b[i-1] - b[i])
	if d <= 0:
		a[i] -= d - 1
		b[i] += d - 1
ma = min(a)
mb = min(b)
a = [str(i+1-ma) for i in a] 
b = [str(i+1-mb) for i in b]
print(" ".join(a))
print(" ".join(b))

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
p = [int(i) for i in input().split()]
a = [0 for i in range(n)]
b = [0 for i in range(n)]

for i in range(n):
	a[p[i]-1] = i + 1
	b[p[i]-1] = i + 1
for i in range(1,n):
	d = min(a[i] - a[i-1],b[i-1] - b[i])
	if d <= 0:
		a[i] -= d - 1
		b[i] += d - 1
a = [str(i+1-min(a)) for i in a] 
b = [str(i+1-min(b)) for i in b]

print(" ".join(a))
print(" ".join(b))

Fixed submission:
n = int(input())
p = [int(i) for i in raw_input().split()]
a = [0 for i in range(n)]
b = [0 for i in range(n)]
p.reverse()
for i in range(n):
	k = p.pop()
	a[k-1] = i + 1
	b[k-1] = i + 1
for i in range(1,n):
	d = min(a[i] - a[i-1],b[i-1] - b[i])
	if d <= 0:
		a[i] -= d - 1
		b[i] += d - 1
ma = min(a)
mb = min(b)
a = [str(i+1-ma) for i in a] 
b = [str(i+1-mb) for i in b]
print(" ".join(a))
print(" ".join(b))
Buggy python submission (verdict: Runtime Error):
a, b, c = [int(i) for i in input().split()]
if(max(a,b,c)*2 == sum(a,b,c)):
 print("Yes")
else:
 print("No")

Fixed submission:
a, b, c = [int(i) for i in input().split()]
if(max([a,b,c])*2 == sum([a,b,c])):
 print("Yes")
else:
 print("No")
Buggy python submission (verdict: Time Limit Exceeded):
s = input()
while "BB" in s or "WW" in s:
	s.replace("BB", "B")
	s.replace("WW", "W")

print(len(s)-1)

Fixed submission:
s = input()
ans = -1
b = ""
for l in s:
	if b != l:
		ans += 1
	b = l
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N, T = map(int, input().split())
a = [int(i) for i in input().split()]
d = [max(a[i:]) - a[i] for i in range(N-1)]
ans = d.count(max(d))
print(ans)

Fixed submission:
N, T = map(int, input().split())
a = [int(i) for i in input().split()]
b = [a[0]]
m = b[0]
for i in range(1,N):
	if m > a[i]:
		m = a[i]
	b.append(m)
c = [a[i] - b[i] for i in range(N)]
print(c.count(max(c)))
Buggy python submission (verdict: Runtime Error):
print(len(set([int(i) in input().split()])))

Fixed submission:
print(len(set([int(i) for i in input().split()])))
Buggy python submission (verdict: Time Limit Exceeded):
X = input()
stack = []
for l in X:
	if stack == []:
		stack.append(l)
	elif stack[-1] == "S" and l == "T":
		stack = stack[:-1]
	else:
		stack.append(l)
print(len(stack))

Fixed submission:
X = input()
stack = []
for l in X:
	if stack == []:
		stack.append(l)
	elif stack[-1] == "S" and l == "T":
		stack.pop()
	else:
		stack.append(l)
print(len(stack))

Buggy python submission (verdict: Time Limit Exceeded):
X = input()
N = 10**10000
for i in range(N):
	if "ST" in X:
		X = X.replace("ST","")
	else:
		print(len(X))
		break
else:
	print(len(X))


Fixed submission:
X = input()
stack = []
for l in X:
	if stack == []:
		stack.append(l)
	elif stack[-1] == "S" and l == "T":
		stack.pop()
	else:
		stack.append(l)
print(len(stack))

Buggy python submission (verdict: Time Limit Exceeded):
X = input()
X2 = ""
N = 10**10000
for i in range(N):
	if X2 == X:
		print(len(X))
		break
	else:
		X2 = X
		X = X.replace("ST","")
else:
	print(0)


Fixed submission:
X = input()
stack = []
for l in X:
	if stack == []:
		stack.append(l)
	elif stack[-1] == "S" and l == "T":
		stack.pop()
	else:
		stack.append(l)
print(len(stack))
Buggy python submission (verdict: Time Limit Exceeded):
s = input()
s += " "
K = int(input())
alphabet = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
k = 0
while K != k:
	k = K
	for i in range(len(s) - 1):
		gap = (26 - alphabet.index(s[i])) % 26
		if K >= gap:
			K -= gap
			s = s[:i] + "a" + s[i+1:]

s = s[:-1]
if K:
	n = alphabet.index(s[-1])
	n += K
	n %= 26
	s = s[:-1] + alphabet[n]


print(s)

Fixed submission:
s = input()
s += " "
K = int(input())
alphabet = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
k = 0

k = K
for i in range(len(s) - 1):
	gap = (26 - alphabet.index(s[i])) % 26
	if K >= gap:
		K -= gap
		s = s[:i] + "a" + s[i+1:]
s = s[:-1]

if K:
	n = alphabet.index(s[-1])
	n += K
	n %= 26
	s = s[:-1] + alphabet[n]

print(s)
Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**6)

R, C = map(int, input().split())
N = int(input())
r = []
c = []
a = []
for i in range(N):
	ri, ci, ai = map(int, input().split())
    	r.append(ri)
    	c.append(ci)
    	a.append(ai)
x = {}
y = {}
     
for i in range(N):
  	if r[i] in x:
   		if c[i] in y:
   			if x[r[i]] + y[c[i]] != a[i]:
   				print("No")
   				break
  		else:
   			y[c[i]] = a[i] - x[r[i]]
   	else:
   		if c[i] in y:
   			x[r[i]] = a[i] - y[c[i]]
   		else:
   			x[r[i]] = a[i]
   			y[c[i]] = 0
    
else:
   	if min(y.values()) + min(x.values()) >= 0:
   		print("Yes")
   	else:
   		print("No")

Fixed submission:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

from collections import defaultdict
import sys
sys.setrecursionlimit(10**6)

R, C = map(int, input().split())
N = int(input())
VectorSet = set()
Grid = defaultdict(list)
for i in range(N):
	r, c, a = map(int, input().split())
	Grid[("R", r)].append((("C", c), a))
	Grid[("C", c)].append((("R", r), a))
	VectorSet.add(("R", r))
	VectorSet.add(("C", c))

def iteration(vector):
	VectorSet.discard(vector)
	for (v, a) in Grid[vector]:
		temp = a - VectorCover[vector]
		if (v in VectorCover):
			if (temp != VectorCover[v]):
				print("No")
				exit()
		else:
			VectorCover[v] = temp
			iteration(v)

while VectorSet:
	vector = VectorSet.pop()
	VectorCover = dict()
	VectorCover[vector] = 0
	iteration(vector)
	minR = min(a for (p, a) in VectorCover.items() if (p[0] == "R"))
	minC = min(a for (p, a) in VectorCover.items() if (p[0] == "C"))
	if minR + minC < 0:
		print("No")
		exit()

print("Yes")
Buggy python submission (verdict: Time Limit Exceeded):
N, A = map(int, input().split())
d = [x-A for x in list(map(int, input().split()))]
n = d.count(0)
d = [x for x in d if x != 0]
d.sort()
if not d:
	print(2**n - 1)
else:
	stack = []
	stack.append([0,0])
	stack.append([0,d[0]])
	ans = 0
	while stack:
		(pos, s) = stack.pop()

		if s == 0 and pos == len(d) - 1:
			ans += 1
		elif pos < len(d) - 1 and s <= 0:
			stack.append([pos+1,s])
			stack.append([pos+1,s + d[pos+1]])
	ans = ans * 2 ** n -1
	print(ans)

Fixed submission:
N, A = map(int, input().split())
y = [int(i) - A for i in input().split()]
y = [0] + y
X = max(max(y) + A,A)
dp = []
for i in range(N+1):
	dp.append([])
	for j in range(2*N*X+1):
		if i == 0 and j == N*X:
			dp[i].append(1)
		elif i >= 1 and (j - y[i] < 0 or j - y[i] > 2*N*X):
			dp[i].append(dp[i-1][j])
		elif i >= 1 and 0 <= j - y[i] and j - y[i] <= 2*N*X:
			dp[i].append(dp[i-1][j]+dp[i-1][j-y[i]])
		else:
			dp[i].append(0)
print(dp[N][N*X]-1)

Buggy python submission (verdict: Time Limit Exceeded):
N, A = map(int, input().split())
x = list(map(int, input().split()))
y = [n - A for n in x]
p = [k for k in y if k > 0]
n = [k for k in y if k < 0]
z = y.count(0)
a = 2**z - 1

def c(n):
	i = n
	a = 0
	b = 0
	while i != 0:
		a += (i%2)*10**b
		b += 1
		i = int(i/2)
	return(a)

s = []
t = []
for i in range(1,2**len(p)):
	j = str(c(i))
	if len(j) < len(p):
		j = "0"*(len(p) - len(j)) + j
	s.append(j)

for i in range(1,2**len(n)):
	j = str(c(i))
	if len(j) < len(n):
		j = "0"*(len(n) - len(j)) + j
	t.append(j)

e = 0
for i in s:
	c = 0
	for u, j in enumerate(i):
		if j == "1":
			c += p[u]
	for k in t:
		d = c
		for m, l in enumerate(k):
			if l == "1":
				d += n[m]
		if d == 0:
			e += 1
a = a + e*(a+1)
print(a)


Fixed submission:
N, A = map(int, input().split())
y = [int(i) - A for i in input().split()]
y = [0] + y
X = max(max(y) + A,A)
dp = []
for i in range(N+1):
	dp.append([])
	for j in range(2*N*X+1):
		if i == 0 and j == N*X:
			dp[i].append(1)
		elif i >= 1 and (j - y[i] < 0 or j - y[i] > 2*N*X):
			dp[i].append(dp[i-1][j])
		elif i >= 1 and 0 <= j - y[i] and j - y[i] <= 2*N*X:
			dp[i].append(dp[i-1][j]+dp[i-1][j-y[i]])
		else:
			dp[i].append(0)
print(dp[N][N*X]-1)
Buggy python submission (verdict: Time Limit Exceeded):
s = input()
f = 0
for i in range(len(s)-1):
	if f == 0:
		l = s[i]
		if s.count(l) >= 2:
			t = s[i:]
			a = 0
			for j in range(t.count(l)-1):
				b = t[a+1:].index(l)
				u = t[:a+b+2]
				a += b
				if u.count(l) > len(u)/2:
					print(i+1, i+a+2)
					f = 1
					break
else:
	if f == 0:
		print("-1 -1")


Fixed submission:
s = input()
for i in range(len(s)-2):
	if s[i] == s[i+1]:
		print(i+1, i+2)
		break
	elif s[i] == s[i+2]:
		print(i+1, i+3)
		break
else:
	if s[-2] == s[-1]:
		print(len(s)-1, len(s))
	else:
		print(-1, -1)

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
f = 0
for i in range(len(s)-1):
	if f == 0:
		if s.count(s[i]) >= 2:
			t = s[i:]
			a = 0
			for j in range(t.count(s[i])-1):
				b = t[a+1:].index(s[i])
				u = t[:a+b+2]
				a += b
				if u.count(s[i]) > len(u)/2:
					print(i+1, i+a+2)
					f = 1
					break
else:
	if f == 0:
		print("-1 -1")



Fixed submission:
s = input()
for i in range(len(s)-2):
	if s[i] == s[i+1]:
		print(i+1, i+2)
		break
	elif s[i] == s[i+2]:
		print(i+1, i+3)
		break
else:
	if s[-2] == s[-1]:
		print(len(s)-1, len(s))
	else:
		print(-1, -1)

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
f = 0
for i in range(len(s)-1):
	if f == 0:
		for j in range(i+2,len(s)+1):
			t = s[i:j]
			if f == 0:
				for k in range(j-i):
					if t.count(t[k]) > len(t)/2:
						print(i+1,j)
						f = 1
						break
else:
	if f == 0:
		print("-1 -1")


Fixed submission:
s = input()
for i in range(len(s)-2):
	if s[i] == s[i+1]:
		print(i+1, i+2)
		break
	elif s[i] == s[i+2]:
		print(i+1, i+3)
		break
else:
	if s[-2] == s[-1]:
		print(len(s)-1, len(s))
	else:
		print(-1, -1)
Buggy python submission (verdict: Runtime Error):
N, L = map(int, input().split())
a = [map(int, input().split())]
b = 0
c = 0
for i in range(N-1):
	if a[i] + a[i+1] >= L:
		print("Possible")
		b = 1
		c = i
		break
else:
	print("Impossible")
if b = 1:
	for i in range(c+1):
		print(i+1)
	for i in range(N, c+1, -1):
		print(i+1)

Fixed submission:
N, L = map(int, input().split())
a = list(map(int, input().split()))
b = 0
c = 0
for i in range(N-1):
	if a[i] + a[i+1] >= L:
		print("Possible")
		b = 1
		c = i
		break
else:
	print("Impossible")
if b == 1:
	for i in range(1,c+1):
		print(i)
	for i in range(N-1, c, -1):
		print(i)

Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
x = []
y = []
for i in range(1,M+1):
	z = list(map(int,input().split()))
	x.append(z[0])
	y.append(z[1])
a = [0]
b = [1]*N
for i in range(M):
	b[x[i]-1] -= 1
	b[y[i]-1] += 1
	if x[i]-1 in a:
		a.append(y[i]-1)
		if b[x[i]-1] == 0:
			a.remove(x[i]-1)
c = 0
for i in range(len(a)):
	if b[a[i]] != 0:
		c += 1
print(c)

Fixed submission:
N, L = map(int, input().split())
a = list(map(int, input().split()))
b = 0
c = 0
for i in range(N-1):
	if a[i] + a[i+1] >= L:
		print("Possible")
		b = 1
		c = i
		break
else:
	print("Impossible")
if b == 1:
	for i in range(1,c+1):
		print(i)
	for i in range(N-1, c, -1):
		print(i)
Buggy python submission (verdict: Runtime Error):
from sys import stdin
import math

a=input()
if (a[0]<a[2]):
    print("<")
elif(a[0]==a[2])
    print("=")
else:
    print(">")

Fixed submission:
from sys import stdin
import math

a=input()
if (a[0]<a[2]):
    print("<")
elif(a[0]==a[2]):
    print("=")
else:
    print(">")
Buggy python submission (verdict: Runtime Error):
S = input()
if S.couut("a") == S.count("b") == S.count("c"):
  print("Yes")
else:
  print("No")

Fixed submission:
S = sorted(input())
if S == ["a", "b", "c"]:
  print("Yes")
else:
  print("No")
Buggy python submission (verdict: Time Limit Exceeded):
import math
K = int(input())
ans = 0
for a in range(K):
  for b in range(K):
    for c in range(K):
      ans += math.gcd(a+1, math.gcd(b+1, c+1))
print(ans)

Fixed submission:
import math
K = int(input())
ans = 0
for a in range(K):
  for b in range(K):
    for c in range(K):
      ans += math.gcd(a+1, math.gcd(b+1, c+1))
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()
R = S.count('R')
G = S.count('G')
B = S.count('B')
ans = R * G * B
for d in range(1, N):
  for i in range(N):
    j = i + d
    k = i + d + d
    if k < N and S[i] != S[j] and S[j] != S[k] and S[k] != S[i]:
      ans -= 1
print(ans)

Fixed submission:
N = int(input())
S = input()
R = S.count('R')
G = S.count('G')
B = S.count('B')
ans = R * G * B
for d in range(1, N):
  for i in range(N):
    j = i + d
    k = i + d + d
    if k < N and S[i] != S[j] and S[j] != S[k] and S[k] != S[i]:
      ans -= 1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
S = input()
N = len(S)

B = [0] * N
for i in range(N):
  if S[i] == 'R':
    B[i] = i+1;
  else:
    B[i] = i-1;

ans = [1] * N

def move(a, B):
  N = len(a)
  res = [0] * N
  for i in range(N):
    res[B[i]] += a[i]
  return res

step = 10 ** 100
while step > 0:
  if step % 2 == 1:
    ans = move(ans, B)
  BB = B[:]
  for i in range(N):
    BB[i] = B[B[i]]
  B = BB
  step //= 2

print(" ".join(map(str, ans)))


Fixed submission:
S = input()
N = len(S)

B = [0] * N
for i in range(N):
  if S[i] == 'R':
    B[i] = i+1;
  else:
    B[i] = i-1;

ans = [1] * N

def move(a, B):
  N = len(a)
  res = [0] * N
  for i in range(N):
    res[B[i]] += a[i]
  return res

step = 10 ** 10
while step > 0:
  if step % 2 == 1:
    ans = move(ans, B)
  BB = B[:]
  for i in range(N):
    BB[i] = B[B[i]]
  B = BB
  step //= 2

print(" ".join(map(str, ans)))
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(int,input().split()))
def solve(A):
  count = {}
  for x in A:
    if x not in count:
      count[x] = 0
    count[x] += 1
  if count[0] == N: return True
  if len(A) % 3 != 0: return False    
  xs = []
  for k, v in count.items():
    if v % (N//3) != 0: return False
    for _ in range(v // (N//3)):
      xs.append(k)
  return (xs[0] == xs[1] ^ xs[2]) or (xs[1] == xs[2] ^ xs[0]) or (xs[2] == xs[0] ^ xs[1])

print('Yes' if solve(A) else 'No')


Fixed submission:
N = int(input())
A = list(map(int,input().split()))
def solve(A):
  count = {}
  for x in A:
    if x not in count:
      count[x] = 0
    count[x] += 1
  if 0 in count and count[0] == N: return True
  if len(A) % 3 != 0: return False    
  xs = []
  for k, v in count.items():
    if v % (N//3) != 0: return False
    for _ in range(v // (N//3)):
      xs.append(k)
  return (xs[0] == xs[1] ^ xs[2]) or (xs[1] == xs[2] ^ xs[0]) or (xs[2] == xs[0] ^ xs[1])

print('Yes' if solve(A) else 'No')
Buggy python submission (verdict: Time Limit Exceeded):
R,G,B,N = map(int,input().split())
ans = 0
for r in range(N//R + 1):
  for g in range(N//G + 1):
    b = max(0, (N - r*R - g*G) // B)
    if r*R + g*G + b*B == N:
      ans += 1
    if r*R + g*G + b*B > N:
      break
print(ans)


Fixed submission:
R,G,B,N = map(int,input().split())
ans = 0
for r in range(N//R + 1):
  for g in range(N//G + 1):
    b = max(0, (N - r*R - g*G) // B)
    if r*R + g*G + b*B == N:
      ans += 1
print(ans)
Buggy python submission (verdict: Runtime Error):
S=input()
ans=700
for i in range(3):
  ans+=100 if S[i]=='o'
print(ans)

Fixed submission:
S=input()
ans=700
for i in range(3):
  if S[i]=='o': ans += 100
print(ans)
Buggy python submission (verdict: Runtime Error):
A,B = map(int,input())
ans = 0
for n in range(A,B+1):
  s = str(A)
  if s == s[::-1]: ans += 1
print(ans)

Fixed submission:
A,B = map(int,input().split())
ans = 0
for n in range(A,B+1):
  s = str(n)
  if s == s[::-1]: ans += 1
print(ans)
Buggy python submission (verdict: Runtime Error):
c=[0]*100010
N=int(input())
for _ in range(N):
  a,b=map(int,input().split())
  c[a] += 1
  c[b+1] -= 1
for i in range(len(c)-1):
  c[i+1] += c[i]
print(sum(c))

Fixed submission:
print('Yes' if '9' in input() else 'No')
Buggy python submission (verdict: Time Limit Exceeded):
import itertools

N,M,R=map(int,input().split())
r=list(map(int,input().split()))
for i in range(R): r[i] -= 1

g = [ [1001001001] * N for _ in range(N) ]
for i in range(N):
  g[i][i] = 0

for _ in range(M):
  A,B,C=map(int,input().split())
  A-=1
  B-=1
  g[A][B] = C
  g[B][A] = C

for k in range(N):
  for i in range(N):
    for j in range(N):
      g[i][j] = min(g[i][j], g[i][k] + g[k][j])

ans = 1001001001
for p in itertools.permutations(r):
  cur = 0
  for i in range(1, R):
    cur += g[p[i-1]][p[i]]
  ans = min(ans, cur)
print(ans)


Fixed submission:
import itertools

N,M,R=map(int,input().split())
r=list(map(int,input().split()))
for i in range(R): r[i] -= 1

g = [ [1001001001] * N for _ in range(N) ]
for i in range(N):
  g[i][i] = 0

for _ in range(M):
  A,B,C=map(int,input().split())
  A-=1
  B-=1
  g[A][B] = C
  g[B][A] = C

def md(beg):
  d = [1001001001] * N
  done = [False] * N
  d[beg] = 0
  while True:
    cur = 1001001001
    pos = -1
    for i in range(N):
      if not done[i] and cur > d[i]:
        cur = d[i]
        pos = i
    if pos == -1:
      break
    done[pos] = True
    for i in range(N):
      d[i] = min(d[i], d[pos] + g[pos][i])
  return d

for i in range(R):
  g[r[i]] = md(r[i])

ans = 1001001001
for p in itertools.permutations(r):
  cur = 0
  for i in range(1, R):
    cur += g[p[i-1]][p[i]]
  ans = min(ans, cur)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N,M,R=map(int,input().split())
r=list(map(int,input().split()))
for i in range(R):
  r[i] -= 1

g = [ [1001001001] * N for _ in range(N) ]
for i in range(N):
  g[i][i] = 0

for _ in range(M):
  A,B,C=map(int,input().split())
  A-=1
  B-=1
  g[A][B] = C
  g[B][A] = C

for k in range(N):
  for i in range(N):
    for j in range(N):
      g[i][j] = min(g[i][j], g[i][k] + g[k][j])
memo = {}

def f(s, l, c):
  if s + 1 == 1 << R:
    return c
  if (s,l) in memo:
    return memo[s,l];
  res = 1001001001
  for i in range(R):
    if (s >> i & 1) == 0:
      x = f(s | (1 << i), i, c + g[r[l]][r[i]])
      res = min(res, x)
  memo[s, l] = res
  return res

ans = min([ f(1 << i, i, 0) for i in range(R) ]) 
print(ans)

Fixed submission:
import itertools

N,M,R=map(int,input().split())
r=list(map(int,input().split()))
for i in range(R): r[i] -= 1

g = [ [1001001001] * N for _ in range(N) ]
for i in range(N):
  g[i][i] = 0

for _ in range(M):
  A,B,C=map(int,input().split())
  A-=1
  B-=1
  g[A][B] = C
  g[B][A] = C

def md(beg):
  d = [1001001001] * N
  done = [False] * N
  d[beg] = 0
  while True:
    cur = 1001001001
    pos = -1
    for i in range(N):
      if not done[i] and cur > d[i]:
        cur = d[i]
        pos = i
    if pos == -1:
      break
    done[pos] = True
    for i in range(N):
      d[i] = min(d[i], d[pos] + g[pos][i])
  return d

for i in range(R):
  g[r[i]] = md(r[i])

ans = 1001001001
for p in itertools.permutations(r):
  cur = 0
  for i in range(1, R):
    cur += g[p[i-1]][p[i]]
  ans = min(ans, cur)
print(ans)
Buggy python submission (verdict: Runtime Error):
import math
N=int(input())
A = [ int(input()) for _ in range(N) ]
ans = A[0]
for x in A[1:]:
  ans = ans * x // math.gcd(ans, x)
print(ans)


Fixed submission:

def gcd(a, b):
  if b == 0:
    return a
  else:
    return gcd(b, a % b)

N=int(input())
A = [ int(input()) for _ in range(N) ]
ans = A[0]
for x in A[1:]:
  ans = ans * x // gcd(ans, x)
print(ans)
Buggy python submission (verdict: Runtime Error):
n,m=map(int,input().split())
printf((n-1)*(m-1))

Fixed submission:
n,m=map(int,input().split())
print((n-1)*(m-1))
Buggy python submission (verdict: Runtime Error):
import sys
import fractions
N,K=map(int,input().split())
A=sorted(list(map(int,input().split())))
if N==1:
  print("POSSIBLE" if A[0] == K else "IMPOSSIBLE")
  sys.exit(0)
g=A[1]-A[0]
for i in range(1,len(A)-1):
  g = fractions.gcd(A[i+1]-A[i], g)
if K <= A[N-1] and (K-A[0]) % g == 0:
  print("POSSIBLE")
else:
  print("IMPOSSIBLE")

Fixed submission:
import sys
import fractions
N,K=map(int,input().split())
A=sorted(list(set(map(int,input().split()))))
N=len(A)
if N==1:
  print("POSSIBLE" if A[0] == K else "IMPOSSIBLE")
  sys.exit(0)
g=A[1]-A[0]
for i in range(1,len(A)-1):
  g = fractions.gcd(A[i+1]-A[i], g)
if K <= A[N-1] and (K-A[0]) % g == 0:
  print("POSSIBLE")
else:
  print("IMPOSSIBLE")
Buggy python submission (verdict: Runtime Error):
A,B,C=map(int,input().split())
ans='NO'
if A[-1]==B[0] and B[-1]==C[0]:
  ans='YES'
print(ans)

Fixed submission:
A,B,C=input().split()
ans='NO'
if A[-1]==B[0] and B[-1]==C[0]:
  ans='YES'
print(ans)

Buggy python submission (verdict: Runtime Error):
A,B,C=map(int,input().split())
ans='NO'
if A[-1]==B[0] and B[-1]==C[0]
  ans='YES'
print(ans)

Fixed submission:
A,B,C=input().split()
ans='NO'
if A[-1]==B[0] and B[-1]==C[0]:
  ans='YES'
print(ans)
Buggy python submission (verdict: Runtime Error):
a, b, x = map(int, input().split())
a -= 1
print ((b // x) - (a // x))

Fixed submission:
print('A'+input().split()[1][0]+'C')
Buggy python submission (verdict: Runtime Error):
s = raw_input()
print s[0:4] + " " + s[4:]


Fixed submission:
s = raw_input()
print s[0:4] + " " + s[4:]