Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
n, k = [int(x) for x in input().split()]

while n > abs(n-k):
    n = abs(n-k)
    if k == 1:
        n = 0
        break
    
    if n%k == 0:
        n = 0
        break

print(n)

Fixed submission:
n, k = [int(x) for x in input().split()]

while n > abs(n-k):
    if k == 1:
        n = 0
        break
    elif n%k == 0:
        n = 0
        break

    if n > k:
        n = n%k
    else:
        n = abs(n-k)    
    

print(n)

Buggy python submission (verdict: Time Limit Exceeded):
n, k = [int(x) for x in input().split()]

while n > abs(n-k):
    n = abs(n-k)
    if k == 1:
        n = 0
        break

print(n)

Fixed submission:
n, k = [int(x) for x in input().split()]

while n > abs(n-k):
    if k == 1:
        n = 0
        break
    elif n%k == 0:
        n = 0
        break

    if n > k:
        n = n%k
    else:
        n = abs(n-k)    
    

print(n)
Buggy python submission (verdict: Runtime Error):
x = input()

if x[2] == x[3] && x[4] == x[5]:
  print("Yes")
else:
  print("No")



Fixed submission:
x = input()

if x[2] == x[3] and x[4]==x[5]:
  print("Yes")
else:
  print("No")
Buggy python submission (verdict: Runtime Error):
N, A, B =[int(x) for x in input().split()]
line = []

for i in range(N/(A+B)):
    for x in range(A):
        line.append("b")
    for y in range(B):
        line.append("r")

print(line[0:N:].count("b"))

Fixed submission:
N, A, B =[int(x) for x in input().split()]

if A!=0:
    ans = N//(A+B)*A
    mod = N%(A+B)
    plus = min(mod, A)
    c = ans + plus 
else:
    c = 0
print(c)
Buggy python submission (verdict: Runtime Error):
line = ["0", "0", "0"]
number = ''

N,M=(int(x) for x in input().split())

for y in range(M):
    s,c=input().split()
    S =int(s)-1
    #if not line[S] == "0": #ミスあり
    line[S] = c
print('line'line)

for z in line:
    #if not line[z] == "0":
    number += z
print(number)

if N == 3 and number[0]=='0':
    print('-1')
elif N == 2 and number[1]=='0':
    print('-1')
elif N == 1 and not number[0]=='0':
    print('-1')
elif N == 1 and not number[1]=='0':
    print('-1')    
elif number[0]=='0' and N==3:
    print('-1')
elif number[1]=='0' and N==2:
    print('-1')
elif number[2]=='0' and N==1:
    print('-1')
else:
    number = int(number)
    print(number)


Fixed submission:
N,M=[int(x) for x in input().split()]
num_list = [None]*N
error = False
for y in range(M):
    s_,c = input().split()
    s = int(s_)
    if s == 1 and c == '0' and N > 1:
        error = True
    elif num_list[s-1] is not None and num_list[s-1]!=c:
        error = True
    else:
        num_list[s-1] = c
    #print(num_list)

if error:
    print('-1')
else:
    for y in range(N):
        if num_list[y] is None:
            if y==0 and N >1:
                num_list[y] = '1'   
            else:
                num_list[y] = '0'

    number = ''.join(num_list)
    print(number)
Buggy python submission (verdict: Runtime Error):
a, b, c = map(int, input().split())

if (5 in [a, b, c] and 7 in [a, b, c]) and a+b+c == 17:
  print("YES")
  else:
    print("NO")
  
  
  

Fixed submission:
a, b, c = map(int, input().split())

if a+b+c == 17 and (5 in [a,b,c] and 7 in [a,b,c]):
    print("YES")
else:
    print("NO")
Buggy python submission (verdict: Runtime Error):
l = int(input())

a = []
for i in range(1, l - 2 + 1):
    for j in range(1, i + 1):
        a.append(i * j * (l - i - j))
print(max(a))


Fixed submission:
l = int(input())

print(l**3 / 27)
Buggy python submission (verdict: Time Limit Exceeded):
import sys

A, B, M = [int(x) for x in sys.stdin.readline().strip().split(" ")]
list_a = [int(x) for x in sys.stdin.readline().strip().split(" ")]
list_b = [int(x) for x in sys.stdin.readline().strip().split(" ")]
dict_c = {}
for i in range(M):
    x, y, c = [int(x) for x in sys.stdin.readline().strip().split(" ")]
    if x not in dict_c:
        dict_c[x] = {}
    dict_c[x][y] = max(dict_c[x].get(y, 0), c)

s = 1e5
for i, a in enumerate(list_a):
    for j, b in enumerate(list_b):
        t = a + b - dict_c.get(i + 1, {}).get(j + 1, 0)
        if s > t:
            s = t
print(s)


Fixed submission:
import sys

A, B, M = [int(x) for x in sys.stdin.readline().strip().split(" ")]
list_a = [int(x) for x in sys.stdin.readline().strip().split(" ")]
list_b = [int(x) for x in sys.stdin.readline().strip().split(" ")]
min_a = sorted(list_a)[0]
min_b = sorted(list_b)[0]

dict_c = {}
idx = []
for i in range(M):
    x, y, c = [int(x) for x in sys.stdin.readline().strip().split(" ")]
    if x not in dict_c:
        dict_c[x] = {}
    if c > dict_c[x].get(y, 0):
        dict_c[x][y] = c

    idx.append(tuple([x, y]))

s = min_a + min_b
for (x, y) in idx:
    t = list_a[x - 1] + list_b[y - 1] - dict_c[x][y]
    if t < s:
        s = t
print(s)
Buggy python submission (verdict: Runtime Error):
import sys
readline = sys.stdin.readline
s = readline().strip()
n = int(readline())
rev = False
for i in range(n):
    q = readline()
    if q.startswith("1"):
        rev = not rev
    if q.startswith("2 1"):
        if not rev:
            s = q[-2] + s
        else:
            s = s + q[-2]
    if q.startswith("2 2"):
        if not rev:
            s = s + q[-2]
        else:
            s = q[-2] + s
if rev:
    print(s[::-1])
else:
    print(s)


Fixed submission:
import sys
import math
readline = sys.stdin.readline
a, b = [int(x) for x in readline().strip().split(" ")]
ans = -1
for i in range(13, 1001):
    if a == math.floor(i * 0.08) and b == math.floor(i * 0.1):
        ans = i
        break
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
readline = sys.stdin.readline
s = readline().strip()
n = int(readline())
rev = False
for i in range(n):
    q = readline()
    if q.startswith("1"):
        rev = not rev
    if q.startswith("2 1"):
        if not rev:
            s = q[-2] + s
        else:
            s = s + q[-2]
    if q.startswith("2 2"):
        if not rev:
            s = s + q[-2]
        else:
            s = q[-2] + s
if rev:
    print(s[::-1])
else:
    print(s)


Fixed submission:
import sys
readline = sys.stdin.readline
s = readline().strip()
n = int(readline())
rev = False
h = []
t = []
for i in range(n):
    q = readline()
    if q.startswith("1"):
        rev = not rev
    if q.startswith("2 1"):
        if not rev:
            h.append(q[-2])
        else:
            t.append(q[-2])
    if q.startswith("2 2"):
        if not rev:
            t.append(q[-2])
        else:
            h.append(q[-2])
s = "".join(h[::-1]) + s + "".join(t)
if rev:
    print(s[::-1])
else:
    print(s)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
readline = sys.stdin.readline
s = readline().strip()
n = int(readline())
for i in range(n):
    q = readline()
    if q.startswith("1"):
        s = s[::-1]
    else:
        a = q.strip().split(" ")
        if a[1] == "1":
            s = a[2] + s
        if a[1] == "2":
            s = s + a[2]
print(s)


Fixed submission:
import sys
readline = sys.stdin.readline
s = readline().strip()
n = int(readline())
rev = False
h = []
t = []
for i in range(n):
    q = readline()
    if q.startswith("1"):
        rev = not rev
    if q.startswith("2 1"):
        if not rev:
            h.append(q[-2])
        else:
            t.append(q[-2])
    if q.startswith("2 2"):
        if not rev:
            t.append(q[-2])
        else:
            h.append(q[-2])
s = "".join(h[::-1]) + s + "".join(t)
if rev:
    print(s[::-1])
else:
    print(s)
Buggy python submission (verdict: Runtime Error):
from sys import stdin
N,M = map(int,input().split())
A=  [int(x) for x in stdin.readline().rstrip().split()]
m = max(A)
s = sum(A)
if ( s / (4 * M) < m :
  print("no")
else:  
  print("yes")

Fixed submission:
from sys import stdin
a,b,c = map(int,input().split())
print("{} {} {}".format(c,a,b))

Buggy python submission (verdict: Runtime Error):
from sys import stdin
main
a,b,c = map(int,input().split())
print("{} {} {}".format(c,b,a))

Fixed submission:
from sys import stdin
a,b,c = map(int,input().split())
print("{} {} {}".format(c,a,b))

Buggy python submission (verdict: Runtime Error):
from sys import stdin
a,b,c = map(int,input().split())
print("{} {} {}".format(c,b,a)

Fixed submission:
from sys import stdin
a,b,c = map(int,input().split())
print("{} {} {}".format(c,a,b))

Buggy python submission (verdict: Runtime Error):
N,K=map(int,input().split())
if N%K==0:
    print(0)
    exit()
if N<K:
    print(N)
    exit()
ans=N%K
if ans>=abs(ans-K):
    print(abs(ans-K))
else:
    print(ans)

Fixed submission:
X,Y,Z=map(str,input().split())
print(Z+' '+X+' '+Y)
Buggy python submission (verdict: Time Limit Exceeded):
N,K=map(int,input().split())
if N%K==0:
    print(0)
    exit()
while N>abs(N-K):
    N=abs(N-K)
print(N)

Fixed submission:
N,K=map(int,input().split())
if N%K==0:
    print(0)
    exit()
ans=N%K
if ans>abs(ans-K):
    print(abs(ans-K))
else:
    print(ans)
Buggy python submission (verdict: Runtime Error):
A,B,M=map(int, input().split())
a=list(map(int, input().split()))
b=list(map(int, input().split()))
c=[]
wari=[]
warik=0
ans=0
for i in range(M):
    c+=list(map(int, input().split()))
for i in range(M):
    wari.append(a[c[i*3]]+b[c[(2*i+1)]]-c[2*i+2])
warik=min(wari)
ans=min(a)+min(b)
if ans>warik:
    print(warik)
else:
    print(ans)

Fixed submission:
A,B,M=map(int, input().split())
a=list(map(int, input().split()))
b=list(map(int, input().split()))
c=[]
wari=[]
warik=0
ans=0
for i in range(M):
    c+=list(map(int, input().split()))
for i in range(M):
    wari.append(a[c[i*3]-1]+b[c[2*i+(i+1)]-1]-c[2+3*i])    
warik=min(wari)
ans=min(a)+min(b)
if ans<warik:
    print(ans)
else:
    print(warik)
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
A=int(input())
P=int(input())
if A%2==0:
  A=A*3/2
  print(A+P)
else:
  A=(A*3+P)/2
  print(A)

Fixed submission:
import sys
input = sys.stdin.readline
a,p = map(int,input().split())
print((a*3+p)//2)
Buggy python submission (verdict: Runtime Error):
coin=[]
ans=0
for i in range(3):
    coin+=map(int,input().split())
X=int(input())
for a in range(coin[0]+1):
    for b in range(coin[1]+1):
        for c in range(coin[2]+1):
            total=a*500+b*100+c*50
            if total==X:
            

Fixed submission:
coin=[]
ans=0
for i in range(3):
    coin+=map(int,input().split())
X=int(input())
for a in range(coin[0]+1):
    for b in range(coin[1]+1):
        for c in range(coin[2]+1):
            total=a*500+b*100+c*50
            if total==X:
                ans +=1
print(ans)
Buggy python submission (verdict: Runtime Error):
a,b  = map(int(),input().split())
if a*b % == 0:
  print(Even)
else:
  print(0dd)

Fixed submission:
a,b = map(int,input().split())
if (a*b%2 == 0):
  print("Even")
else:
  print("Odd")
Buggy python submission (verdict: Runtime Error):
s = set(list(str(input())))
s1=list(sorted(s))
t=0
if len(s1)==26:
    print(None)
for i in range(len(s1)+1):
    if not i+97==ord(s1[i]):
        print(chr(i+97))
        break

Fixed submission:
s = set(list(str(input())))
s1=list(sorted(s))
for i in range(len(s1)+1):
    if not chr(i+97) in s1:
        print(chr(i+97))
        break
    elif chr(i+97)=='z':
        print(None)
        break
Buggy python submission (verdict: Runtime Error):
W,H,N=map(int,input().split())
x1=0
x2=W
y1=0
y2=H
for i in range(N):
    x,y,a=map(int,input().split())
    if a==1:
        x1=max(x1,x)
    elif a==2:
        x2=min(x,x2)
    elif a==3:
        y1=max(y1,y)
    elif a==4:
        y2=min(y,y2)
if x2<x1 or y2<y1:
    print(0)
    sys.exit()
xx=x2-x1
yy=y2-y1
print(xx*yy)

Fixed submission:
W,H,N=map(int,input().split())
x1=0
x2=W
y1=0
y2=H
for i in range(N):
    x,y,a=map(int,input().split())
    if a==1:
        x1=max(x1,x)
    elif a==2:
        x2=min(x,x2)
    elif a==3:
        y1=max(y1,y)
    elif a==4:
        y2=min(y,y2)
if x2<x1 or y2<y1:
    print(0)
    exit()
xx=x2-x1
yy=y2-y1
print(xx*yy)

Buggy python submission (verdict: Runtime Error):
W,H,N=map(int,input().split())
x1=0
x2=W
y1=0
y2=H
for i in range(N):
    x,y,a=map(int,input().split())
    if a==1:
        x1=max(x1,x)
    elif a==2:
        x2=min(x,x2)
    elif a==3:
        y1=max(y1,y)
    elif a==4:
        y2=min(y,y2)
if x2<x1 or y2<y1:
    print(0)
    sys.exit()
print(x1,x2,y1,y2)
xx=x2-x1
yy=y2-y1
print(xx*yy)

Fixed submission:
W,H,N=map(int,input().split())
x1=0
x2=W
y1=0
y2=H
for i in range(N):
    x,y,a=map(int,input().split())
    if a==1:
        x1=max(x1,x)
    elif a==2:
        x2=min(x,x2)
    elif a==3:
        y1=max(y1,y)
    elif a==4:
        y2=min(y,y2)
if x2<x1 or y2<y1:
    print(0)
    exit()
xx=x2-x1
yy=y2-y1
print(xx*yy)
Buggy python submission (verdict: Runtime Error):
X = int(input())
Y = int(input())
Z = int(input())
X, Y, Z = Z, X, Y
print(X, Y, Z)

Fixed submission:
X, Y, Z = list(map(int, input().split()))
X, Y, Z = Z, X, Y
print(X, Y, Z)

Buggy python submission (verdict: Runtime Error):
X = int(input())
Y = int(input())
Z = int(input())
print(Z, X, Y)

Fixed submission:
X, Y, Z = list(map(int, input().split()))
X, Y, Z = Z, X, Y
print(X, Y, Z)
Buggy python submission (verdict: Time Limit Exceeded):
S = input()
# print("Q=")
Q = int(input())

def problem_gksn(S,Q):
  for _ in range(Q):
    # print("queryを入力してください")
    query = input().split()
    # print("query= ",query)
    if len(query) == 1: #1の場合
      # print("文字を反転させます")
      S = S[::-1]
    else: #2の場合
      # print("文字をくっつけます")
      if int(query[1]) == 2:
        S = S + query[2]
      else:
        S = query[2] + S
  
  return S
print(problem_gksn(S,Q))

Fixed submission:
# print("S=")
S = input()
# print("Q=")
Q = int(input())

def problem_gksn(S,Q):
  check_reverse = 0 # 偶数のとき正常, 奇数の時反転
  atama = ""
  oshiri = ""
  for _ in range(Q):
    # print("queryを入力してください")
    query = input().split()
    # print("query= ",query)
    if len(query) == 1: #1の場合
      # print("文字を反転させます")
      check_reverse += 1
      # S = S[::-1]
    else: #2の場合
      # print("文字をくっつけます")
      if int(query[1]) == 2 - check_reverse % 2:
        oshiri += query[2]
      else:
        atama += query[2]
      # print("atama",atama)
      # print("oshiri",oshiri)
  S = atama[::-1] + S + oshiri
  if check_reverse % 2==1:
    S = S[::-1]
  
  return S

print(problem_gksn(S,Q))
Buggy python submission (verdict: Runtime Error):
def main(argv):
    k = int(sys.stdin.readline().rstrip("\n"))
    if k < 10:
        return print(k)
    d = {i: [i] for i in range(10)}

    counter = 9
    n = 1
    while counter < k:
        next_d = {}
        candidates = d[0]
        candidates.extend(d[1])
        next_d[0] = sorted([c for c in set(candidates)])
        for i in range(1, 10):
            candidates = d[i - 1]
            candidates.extend(d[i])
            candidates.extend(d.get(i + 1, []))
            next_d[i] = sorted([i * (10 ** n) + c for c in set(candidates)])
            n_candidates = len(next_d[i])
            if (counter + n_candidates) >= k:
                print(next_d[i][k - counter - 1])
                counter += n_candidates
                break
            counter += n_candidates
        d = next_d
        n += 1
    return 0

if __name__ == "__main__":
    sys.exit(main(sys.argv))

Fixed submission:
import sys

def main(argv):
    k = int(sys.stdin.readline().rstrip("\n"))
    if k < 10:
        return print(k)
    d = {i: [i] for i in range(10)}

    counter = 9
    n = 1
    while counter < k:
        next_d = {}
        candidates = d[0]
        candidates.extend(d[1])
        next_d[0] = sorted([c for c in set(candidates)])
        for i in range(1, 10):
            candidates = d[i - 1]
            candidates.extend(d[i])
            candidates.extend(d.get(i + 1, []))
            next_d[i] = sorted([i * (10 ** n) + c for c in set(candidates)])
            n_candidates = len(next_d[i])
            if (counter + n_candidates) >= k:
                print(next_d[i][k - counter - 1])
                counter += n_candidates
                break
            counter += n_candidates
        d = next_d
        n += 1
    return 0


if __name__ == "__main__":
    sys.exit(main(sys.argv))
Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/python

import sys

def main(argv):
    line = sys.stdin.readline()
    while line:
        N = int(line.rstrip("\n"))

        timestamps = [0]
        for i in xrange(N - 1):
            if i > 0:
                timestamps.append(0)

            c, s, f = map(
              lambda i: int(i), sys.stdin.readline().rstrip("\n").split(" "))

            for i in xrange(len(timestamps)):
                if timestamps[i] <= s:
                    timestamps[i] = s + c
                else:
                    next_s = s
                    while timestamps[i] > next_s:
                        next_s = next_s + f
                    timestamps[i] = next_s + c

        for timestamp in timestamps:
            print timestamp
        print 0

        line = sys.stdin.readline()

if __name__ == "__main__":
    main(sys.argv)

Fixed submission:
#!/usr/bin/python

import sys

def main(argv):
    line = sys.stdin.readline()
    while line:
        N = int(line.rstrip("\n"))

        timestamps = [0]
        for i in xrange(N - 1):
            if i > 0:
                timestamps.append(0)

            c, s, f = map(
              lambda i: int(i), sys.stdin.readline().rstrip("\n").split(" "))

            for i in xrange(len(timestamps)):
                if timestamps[i] <= s:
                    timestamps[i] = s + c
                else:
                    d = timestamps[i] % f
                    if d == 0:
                        timestamps[i] += c
                    else:
                        timestamps[i] += (f - d) + c

        for timestamp in timestamps:
            print timestamp
        print 0

        line = sys.stdin.readline()

if __name__ == "__main__":
    main(sys.argv)
Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/python

import itertools
import sys

def main(argv):
    line = sys.stdin.readline()
    while line:
        N, M, R = map(lambda x: int(x), line.split(" ", 3))
        r  = map(lambda x: int(x) - 1, sys.stdin.readline().split(" "))
        weights = [[0 for i in xrange(N)] for j in xrange(N)]
        for i in xrange(M):
            a, b, c = map(lambda x: int(x), sys.stdin.readline().split(" ", 3))
            weights[a - 1][b - 1] = c
            weights[b - 1][a - 1] = c

        for k in xrange(N):
            for i in xrange(N):
                for j in xrange(N):
                    if weights[i][k] > 0 and weights[k][j] > 0:
                        length = weights[i][k] + weights[k][j]
                        if weights[i][j] == 0 or weights[i][j] > length:
                            weights[i][j] = length

        min_length = -1
        for p in itertools.permutations(r):
            length = 0
            previous = p[0]
            for i in p[1:]:
                length += weights[previous][i]
                previous = i
            if min_length == -1:
                min_length = length
            elif min_length > length:
                min_length = length
        print min_length

        line = sys.stdin.readline()

if __name__ == "__main__":
    main(sys.argv)

Fixed submission:
#!/usr/bin/python

import itertools
import sys

def main(argv):
    line = sys.stdin.readline()
    while line:
        N, M, R = map(lambda x: int(x), line.split(" ", 3))
        r  = map(lambda x: int(x) - 1, sys.stdin.readline().split(" "))
        weights = [[0 for i in xrange(N)] for j in xrange(N)]
        for i in xrange(M):
            a, b, c = map(lambda x: int(x), sys.stdin.readline().split(" ", 3))
            weights[a - 1][b - 1] = c
            weights[b - 1][a - 1] = c

        for k in xrange(N):
            for i in xrange(N):
                for j in xrange(N):
                    if j > i:
                        if weights[i][k] > 0 and weights[k][j] > 0:
                            length = weights[i][k] + weights[k][j]
                            if weights[i][j] == 0 or weights[i][j] > length:
                                weights[i][j] = length
                                weights[j][i] = length

        min_length = -1
        for p in itertools.permutations(r):
            length = 0
            previous = p[0]
            for i in p[1:]:
                length += weights[previous][i]
                previous = i
            if min_length == -1:
                min_length = length
            elif min_length > length:
                min_length = length
        print min_length

        line = sys.stdin.readline()

if __name__ == "__main__":
    main(sys.argv)
Buggy python submission (verdict: Runtime Error):
#!/usr/bin/python

import sys

def main(argv):
    line = sys.stdin.readline()
    while line:
        N = int(line)
        P = map(lambda x: int(x), sys.stdin.readline().split(" "))

        counter = 0
        for i in xrange(len(P)):
            index = i + 1
            if P[i] == index:
                if i > 0:
                    if P[i - 1] == index - 1:
                        P[i] = P[i - 1]
                    elif P[i + 1] == index + 1:
                        P[i], P[i + 1] = P[i + 1], P[i]
                    else:
                        P[i] = P[i - 1]
                else:
                    P[i], P[i + 1] = P[i + 1], P[i]
                counter += 1
        print(counter)
        
        line = sys.stdin.readline()

if __name__ == "__main__":
    main(sys.argv)

Fixed submission:
#!/usr/bin/python

import sys

def main(argv):
    line = sys.stdin.readline()
    while line:
        N = int(line)
        P = map(lambda x: int(x), sys.stdin.readline().split(" "))

        counter = 0
        for i in xrange(len(P)):
            index = i + 1
            if P[i] == index:
                if i == 0:
                    P[i], P[i + 1] = P[i + 1], P[i]
                elif i > 0 and i < len(P) - 1:
                    pass
                    if P[i - 1] == index - 1:
                        P[i] = P[i - 1]
                    elif P[i + 1] == index + 1:
                        P[i], P[i + 1] = P[i + 1], P[i]
                    else:
                        P[i] = P[i - 1]
                counter += 1
        print(counter)
        
        line = sys.stdin.readline()

if __name__ == "__main__":
    main(sys.argv)