Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

def bfs(maze):
    h = len(maze)
    w = len(maze[0])
    visited = [[-1 for _ in range(w)] for _ in range(h)]
    d = deque()
    
    last =[-1, -1]
    for y in range(h):
        for x in range(w):
            if maze[y][x] == '#':
                d.append([y, x])
                visited[y][x] = 0
                last[0] = y
                last[1] = x
    
    while d:
        y, x = d.popleft()
        
        for l, k in ([1, 0], [0, 1], [-1, 0], [0, -1]):
            new_y, new_x = y + l, x + k
            
            if new_y < 0 or h <= new_y or new_x < 0 or w <= new_x:
                continue
            elif visited[new_y][new_x] != -1:
                continue
            elif maze[new_y][new_x] == '#':
                continue
            
            d.append([new_y, new_x])
            visited[new_y][new_x] = visited[y][x] + 1

        last[0] = y
        last[1] = x
        
    ''' 確認用
    print(last)
    for i in range(h):
        print(visited[i])
    '''
        
    return visited[last[0]][last[1]]

if __name__ == "__main__":
    h, w = map(int, input().split())
    maze = []
    for i in range(h):
        maze.append(list(input()))
    ''' 確認用
    for i in range(h):
        print(maze[i])
    '''
    
    print(bfs(maze))

Fixed submission:
from collections import deque

def bfs(maze):
    h = len(maze)
    w = len(maze[0])
    visited = [[-1 for _ in range(w)] for _ in range(h)]
    d = deque()
    
    last =[-1, -1]
    for y in range(h):
        for x in range(w):
            if maze[y][x] == '#':
                d.append([y, x])
                visited[y][x] = 0
                last[0] = y
                last[1] = x
    
    while d:
        y, x = d.popleft()
        
        for l, k in ([1, 0], [0, 1], [-1, 0], [0, -1]):
            new_y, new_x = y + l, x + k
            
            if new_y < 0 or h <= new_y or new_x < 0 or w <= new_x:
                continue
            elif visited[new_y][new_x] != -1:
                continue
            elif maze[new_y][new_x] == '#':
                continue
            
            d.append([new_y, new_x])
            visited[new_y][new_x] = visited[y][x] + 1

        last[0] = y
        last[1] = x
        
    ''' 確認用
    print(last)
    for i in range(h):
        print(visited[i])
    '''
        
    return visited[last[0]][last[1]]

if __name__ == "__main__":
    h, w = map(int, input().split())
    maze = []
    for i in range(h):
        maze.append(list(input()))
    ''' 確認用
    for i in range(h):
        print(maze[i])
    '''
    
    print(bfs(maze))
Buggy python submission (verdict: Runtime Error):
b = input()
base = ['A', 'C', 'G', ' T']
versus = ['T', 'G', 'C', 'A']

print(versus[base.index(b)])

Fixed submission:
b = input()
base = ['A', 'C', 'G', 'T']
versus = ['T', 'G', 'C', 'A']

print(versus[base.index(b)])
Buggy python submission (verdict: Runtime Error):
n, m, c =map(int, input().split())
b = [int(x) for x in input().split()]
a = [[int (x) for x in input().split()] for _ in range(n)]

ans = 0
for i in range(n):
    cnt = 0
    for j in range(m):
        cnt += a[i][j] * b[j]
    
    cnt += c
    
    if 0 < cnt:
        ans += 1
        
print(ans)n

Fixed submission:
n, m, c =map(int, input().split())
b = [int(x) for x in input().split()]
a = [[int (x) for x in input().split()] for _ in range(n)]

ans = 0
for i in range(n):
    cnt = 0
    for j in range(m):
        cnt += a[i][j] * b[j]
    
    cnt += c
    
    if 0 < cnt:
        ans += 1
        
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
h = [int(i) for i in input().split()]

dp = [0] * n
for i in range(1, n):
    for j in range(1, k + 1):
        if j == 1:
            dp[i] = dp[i - j] + abs(h[i] - h[i - j])
        
        if i - j < 0:
            continue
        
        dp[i] = min(dp[i], dp[i - j] + abs(h[i] - h[i - j]))

print(dp[n - 1])

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

dp = [0] * n
for i in range(1, n):
    for j in range(1, k + 1):
        if j == 1:
            dp[i] = dp[i - j] + abs(h[i] - h[i - j])
        
        if i - j < 0:
            continue
        
        dp[i] = min(dp[i], dp[i - j] + abs(h[i] - h[i - j]))

print(dp[n - 1])
Buggy python submission (verdict: Time Limit Exceeded):
s = list(input())

ans = 0
flg = True
while flg:
    flg = False
    for i in range(len(s) - 1):
        if s[i] == 'B' and s[i + 1] == 'W':
            s[i] = 'W'
            s[i + 1] = 'B'
            ans += 1
            flg = True

print(ans)

Fixed submission:
import sys

s = input()
first = s.find('B')

if first == -1:
    print(0)
    sys.exit()

ans = 0
for i in range(first + 1, len(s)):
    if s[i] == 'W':
        ans += i - first
        first += 1

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

if n == 2:
	a = int(input())
    b = int(input())
    print(a + b)
else:
	print('Hello World')

Fixed submission:
n = int(input())

if n == 2:
  a = int(input())
  b = int(input())
  print(a + b)
else:
  print('Hello World')

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

if n == 2:
	a = int(input())
    b = int(input())
    print(a + b)
else:
	print('Hello World')

Fixed submission:
n = int(input())

if n == 2:
  a = int(input())
  b = int(input())
  print(a + b)
else:
  print('Hello World')
Buggy python submission (verdict: Runtime Error):
mport collections
n = int(input())

d = collections.Counter(input())
for i in range(n - 1):
    words = collections.Counter(input())
    for w in words.keys():
        d[w] = min(words[w], d[w])
        
    for w in d.keys():
        d[w] = min(words[w], d[w])

ans = []
for char in d.keys():
    for i in range(d[char]):
        ans.append(char)

ans.sort()

print(''.join(ans))

Fixed submission:
import collections
n = int(input())

d = collections.Counter(input())
for i in range(n - 1):
    words = collections.Counter(input())
    for w in words.keys():
        d[w] = min(words[w], d[w])
        
    for w in d.keys():
        d[w] = min(words[w], d[w])

ans = []
for char in d.keys():
    for i in range(d[char]):
        ans.append(char)

ans.sort()

print(''.join(ans))
Buggy python submission (verdict: Runtime Error):
import numpy as np

x = int(input())

t = (-1 + np.sqrt(1 + 8 * x)) /? 2
t = int(t)

print(t + 1)

Fixed submission:
import numpy as np

x = int(input())

numerator = (-1 + np.sqrt(1 + 8 * x))
t = int(numerator // 2)

if numerator % 2 == 0:
    print(t)
else:
    print(t + 1)
Buggy python submission (verdict: Runtime Error):
import sys
from collections import deque
import copy
import math
def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline



def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [W, H, x, y] = [long(input_raw[0]), long(input_raw[1]), long(input_raw[2]), long(input_raw[3])]
    if (H /2 == y) and (W/2 == x) and (H % 2 == 0) and (W % 2 == 0):
        ans2 = 1
    else:
        ans2 = 0

    if(W * y == H * x or y * W ==  (-H * x) + W * H):
        print "%20.15f %d" % (float(W)/2.0 * H , ans2)
        return

    ans = max(min(float(H - y), float(y)) * float(W), min(float(W - x), float(x)) * float(H))
    if (H /2 == y) and (W/2 == x) and (H % 2 == 0) and (W % 2 == 0):
        ans2 = 1
    else:
        ans2 = 0
    print "%20.15f %d" % (ans, ans2)

if __name__ == '__main__':
    main()


Fixed submission:
import sys
from collections import deque
import copy
import math
def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline



def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [N, X] = [int(input_raw[0]), int(input_raw[1])]
    input_raw = read_func().strip().split()
    L = [int(input_raw[i]) for i in range(N)]
    D = 0
    ans = 1
    for i in range(N):
        D = D + L[i]
        if D <= X:
            ans += 1
    print ans
if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
import sys
from collections import deque
import copy
import math
def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline



def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [W, H, x, y] = [long(input_raw[0]), long(input_raw[1]), long(input_raw[2]), long(input_raw[3])]
    if (H /2 == y) and  (H % 2 == 0)  and (W/2 == x) and (W % 2 == 0):
        ans2 = 1
    else:
        ans2 = 0

    if(W * y == H * x or y * W ==  (-H * x) + W * H):
        print "%20.15f %d" % (float(H)/2.0 * W , ans2)
        return

    if (H /2 == y) and  (H % 2 == 0)  and (W/2 == x) and (W % 2 == 0):
        ans2 = 1
    else:
        ans2 = 0
    throw()
    ans = max(min(H - y, y) * W, min(W - x, x) * H)
    print "%20.15f %d" % (float(ans), ans2)

if __name__ == '__main__':
    main()


Fixed submission:
import sys
from collections import deque
import copy
import math
def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline



def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [W, H, x, y] = [long(input_raw[0]), long(input_raw[1]), long(input_raw[2]), long(input_raw[3])]
    if (H /2 == y) and  (H % 2 == 0)  and (W/2 == x) and (W % 2 == 0):
        ans2 = 1
    else:
        ans2 = 0

    #if(W * y == H * x or y * W ==  (-H * x) + W * H):
    print "%20.15f %d" % (float(H)/2.0 * W , ans2)
    return

    if (H /2 == y) and  (H % 2 == 0)  and (W/2 == x) and (W % 2 == 0):
        ans2 = 1
    else:
        ans2 = 0

    ans = max(min(H - y, y) * W, min(W - x, x) * H)
    print "%20.15f %d" % (float(ans), ans2)

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
import sys
from collections import deque
import copy
import math
def get_read_func(fileobject):
    if fileobject == None :
        return  sys.stdin.readline
    else:
        return fileobject.readline

def calc(field, H, W):
    ret =  [[0] * (W + 1) for i in range(H + 1)]
    for i in range(H):
        cnt = 0
        cnt_list = []
        for j in range(W + 1):
            if field[i][j] == "#":
                cnt_list.append(cnt)
                cnt = 0
            else:
                cnt += 1
        k = 0
        for j in range(W + 1):
            if field[i][j] == ".":
                ret[i][j] = cnt_list[k]
            else:
                ret[i][j] = 0
                k+=1
    return ret





def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [H, W] = [int(input_raw[0]), int(input_raw[1])]
    field = [["#"] * (W + 1) for i in range(H + 1)]
    field_T = [["#"] * (H + 1) for i in range(W + 1)]
    for i in range(H):
        input_raw = read_func().strip().split()
        for j in range(W):
            field[i][j] = input_raw[0][j]
            field_T[j][i] = field[i][j]
    ret1 = calc(field, H, W)
    ret2 = calc(field_T, W, H)
    ans = 0
    for i in range(H):
        for j in range(W):
            ans = max(ans, ret1[i][j] + ret2[j][i] - 1)
    print ans

if __name__ == '__main__':
    main()


Fixed submission:
import sys
from collections import deque
import copy
import math
def get_read_func(fileobject):
    if fileobject == None :
        return  sys.stdin.readline
    else:
        return fileobject.readline

def calc(field, H, W):
    ret =  [[0] * (W + 1) for i in range(H + 1)]
    for i in range(H):
        cnt = 0
        cnt_list = []
        for j in range(W + 1):
            if field[i][j] == "#":
                cnt_list.append(cnt)
                cnt = 0
            else:
                cnt += 1
        k = 0
        for j in range(W + 1):
            if field[i][j] == ".":
                ret[i][j] = cnt_list[k]
            else:
                ret[i][j] = 0
                k+=1
    return ret





def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [H, W] = [int(input_raw[0]), int(input_raw[1])]
    field = [["#"] * (W + 1) for i in range(H + 1)]
    field_T = [["#"] * (H + 1) for i in range(W + 1)]
    for i in range(H):
        input_raw = read_func().strip().split()
        for j in range(W):
            field[i][j] = input_raw[0][j]
            field_T[j][i] = field[i][j]
    ret1 = calc(field, H, W)
    ret2 = calc(field_T, W, H)
    ans = 0
    for i in range(H):
        for j in range(W):
            ans = max(ans, ret1[i][j] + ret2[j][i] - 1)
    print ans

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
import sys
from collections import deque
import copy
import math
def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline



def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    A = []
    input_raw = read_func().strip().split()
    A.append(int(input_raw[0]))
    input_raw = read_func().strip().split()
    A.append(int(input_raw[0]))
    input_raw = read_func().strip().split()
    A.append(int(input_raw[0]))
    input_raw = read_func().strip().split()
    A.append(int(input_raw[0]))
    input_raw = read_func().strip().split()
    A.append(int(input_raw[0]))
    input_raw = read_func().strip().split()

    max_idx = 0
    max_mod = 0
    for i in range(5):
        if abs(10 - A[i] % 10)% 10> max_mod:
            max_mod = abs(10 - A[i] % 10) % 10
            max_idx = i
    time = 0
    for i in range(5):
        if i != max_idx:
            time += A[i] + (abs(10 - A[i] % 10)% 10)
    time += A[max_idx]
    print time


if __name__ == '__main__':
    main()


Fixed submission:
import sys
from collections import deque
import copy
import math

def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline

def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    A = []
    input_raw = read_func().strip().split()
    A.append(int(input_raw[0]))
    input_raw = read_func().strip().split()
    A.append(int(input_raw[0]))
    input_raw = read_func().strip().split()
    A.append(int(input_raw[0]))
    input_raw = read_func().strip().split()
    A.append(int(input_raw[0]))
    input_raw = read_func().strip().split()
    A.append(int(input_raw[0]))


    max_idx = 0
    max_mod = 0
    for i in range(5):
        if abs(10 - A[i] % 10)% 10> max_mod:
            max_mod = abs(10 - A[i] % 10) % 10
            max_idx = i
    time = 0
    for i in range(5):
        if i != max_idx:
            time += A[i] + (abs(10 - A[i] % 10)% 10)
    time += A[max_idx]
    print time


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
import sys
from collections import deque
import copy
import math
def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline

def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [A, B, K] = [int(input_raw[0]), int(input_raw[1]), int(input_raw[2])]
    count = 0

    if max(A, B) == 1:
        print 1
        return

    num_list = []
    for x in range(1, max(A, B)):
        if A%x == 0 and B%x == 0:
            num_list.append(x)
    num_list.sort(reverse = True)
    print num_list[K - 1]

if __name__ == '__main__':
    main()


Fixed submission:
import sys
from collections import deque
import copy
import math
def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline

def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [A, B, K] = [int(input_raw[0]), int(input_raw[1]), int(input_raw[2])]
    count = 0

    if max(A, B) == 1:
        print 1
        return

    num_list = []
    for x in range(1, max(A, B) + 1):
        if A%x == 0 and B%x == 0:
            num_list.append(x)
    num_list.sort(reverse = True)
    print num_list[K - 1]

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
import sys
from collections import deque
import copy
import math
def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline

def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [N, M] = [int(input_raw[0]), int(input_raw[1])]
    dic = {}
    for m in range(1, M + 1):
        dic[m] = 0

    for i in range(N):
        input_raw = read_func().strip().split()
        K = int(input_raw[0])
        for j in range(K):
            dic[int(input_raw[i])] += 1

    count = 0
    for m in dic:
        if dic[m] == N:
            count += 1
    print count


if __name__ == '__main__':
    main()


Fixed submission:
import sys
from collections import deque
import copy
import math
def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline

def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [N, M] = [int(input_raw[0]), int(input_raw[1])]
    dic = {}
    for m in range(1, M + 1):
        dic[m] = 0

    for i in range(N):
        input_raw = read_func().strip().split()
        K = int(input_raw[0])
        for j in range(K):
            dic[int(input_raw[j + 1])] += 1

    count = 0
    for m in dic:
        if dic[m] == N:
            count += 1
    print count


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
import sys
from collections import deque
import copy
import math
def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline

def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [N, M] = [int(input_raw[0]), int(input_raw[1])]
    input_raw = read_func().strip().split()
    A = []
    A_num = {}
    A_num[1] = 2
    A_num[2] = 5
    A_num[3] = 5
    A_num[4] = 4
    A_num[5] = 5
    A_num[6] = 6
    A_num[7] = 3
    A_num[8] = 7
    A_num[9] = 6
    for i in range(M):
        A.append(int(input_raw[i]))

    dp = [0] * (N + 1)
    A.sort(reverse = True)

    for i in range(1, N + 1):
        max_num = -sys.maxint
        for a in A:
            if i - A_num[a] >= 0 and dp[i - A_num[a]] >= 0:
                max_num = max(max_num, dp[i - A_num[a]] + 1)
        dp[i] = max_num

    remain = N
    s = ""
    for i in range(dp[N]):
        for a in A:
            if dp[remain - A_num[a]] == dp[remain] - 1:
                s += str(a)
                remain = remain - A_num[a]
                break
    print s



if __name__ == '__main__':
    main()


Fixed submission:
import sys
from collections import deque
import copy
import math
def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline

def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [N, M] = [int(input_raw[0]), int(input_raw[1])]
    input_raw = read_func().strip().split()
    A = []
    A_num = {}
    A_num[1] = 2
    A_num[2] = 5
    A_num[3] = 5
    A_num[4] = 4
    A_num[5] = 5
    A_num[6] = 6
    A_num[7] = 3
    A_num[8] = 7
    A_num[9] = 6
    for i in range(M):
        A.append(int(input_raw[i]))

    dp = [0] * (N + 1)
    A.sort(reverse = True)

    for i in range(1, N + 1):
        max_num = -sys.maxint
        for a in A:
            if i - A_num[a] >= 0 and dp[i - A_num[a]] >= 0:
                max_num = max(max_num, dp[i - A_num[a]] + 1)
        dp[i] = max_num

    remain = N
    s = ""
    for i in range(dp[N]):
        for a in A:
            if remain - A_num[a] >= 0:
                if dp[remain - A_num[a]] == dp[remain] - 1:
                    s += str(a)
                    remain = remain - A_num[a]
                    break
    print s



if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
import sys
from collections import deque
import copy
import math
def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline

def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [N, M] = [long(input_raw[0]), long(input_raw[1])]
    input_raw = read_func().strip().split()
    X = []
    for i in range(M):
        X.append(int(input_raw[i]))

    if len(X) == 1:
        print 0
        return
    if N == 1:
        print max(X) - min(X)
        return

    X.sort()

    subX = []
    for i in range(M - 1):
        subX.append((X[i + 1] - X[i], i + 1))

    subX.sort(reverse = True)

    count = 0
    for i in range(N):
        if i == N - 1:
            count += X[M - 1] - X[subX[i - 1][1]]
        elif i != 0:
            count += X[subX[i][1] - 1] - X[subX[i - 1][1]]
        else:
            count += X[subX[i][1] - 1] - X[0]
    print count


if __name__ == '__main__':
    main()


Fixed submission:
import sys
from collections import deque
import copy
import math
def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline

def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [N, M] = [long(input_raw[0]), long(input_raw[1])]
    input_raw = read_func().strip().split()
    X = []
    for i in range(M):
        X.append(int(input_raw[i]))

    if len(X) <= N:
        print 0
        return
    if N == 1:
        print max(X) - min(X)
        return

    X.sort()

    subX = []
    for i in range(M - 1):
        subX.append((X[i + 1] - X[i], i + 1))

    subX.sort(reverse = True)

    count = 0
    for i in range(N):
        if i == N - 1:
            count += X[M - 1] - X[subX[i - 1][1]]
        elif i != 0:
            count += X[subX[i][1] - 1] - X[subX[i - 1][1]]
        else:
            count += X[subX[i][1] - 1] - X[0]
    print count


if __name__ == '__main__':
    main()