Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
import math
def resolve():
    a, b, x = list(map(int, input().split()))
    if (a**2)*b/2 > x:
        print(90-math.degrees(math.atan(2*x/((b**2)*a))))
    else:
        print(90-math.degrees(math.atan(a**3/(2*(a**2)*b-2*x))))
    

if '__main__' == __name__:
    resolve()


Fixed submission:
import math
def resolve():
    a, b, x = list(map(int, input().split()))
    if (a**2)*b/2 > x:
        print(90-math.degrees(math.atan(2*x/((b**2)*a))))
    else:
        if x == (a**2)*b:
            print(0)
        else:
            print(90-math.degrees(math.atan(a**3/(2*(a**2)*b-2*x))))
    

if '__main__' == __name__:
    resolve()
Buggy python submission (verdict: Time Limit Exceeded):
def resolve():
    N, K = list(map(int, input().split()))
    A = sorted(list(map(int, input().split())), reverse=True)
    F = sorted(list(map(int, input().split())))
    q = []
    for i in range(N):
        q.append((-A[i]*F[i], A[i], F[i]))
    import heapq
    heapq.heapify(q)
    for i in range(K):
        time, a, f = heapq.heappop(q)
        # print("###########")
        # print(time, a, f)
        if a <= 0:
            print(0)
            return
        heapq.heappush(q, (-(a-1)*f, a-1, f))
        # print(-(a-1)*f, a-1, f)
    time, _, __ = heapq.heappop(q)
    print(-time)

    
if __name__ == "__main__":
    resolve()


Fixed submission:
def resolve():
    N, K = list(map(int, input().split()))
    A = sorted(list(map(int, input().split())))
    F = sorted(list(map(int, input().split())), reverse=True)
    q = []
    for i in range(N):
        q.append((A[i]*F[i], A[i], F[i]))

    def isok(time):
        total = 0
        for t, a, f in q:
            acc = time // f
            if acc < a:
                total += a - acc
        return True if total <= K else False

    left = -1
    right = A[-1]*F[0]
    while (right - left > 1):
        mid = left + (right - left) // 2
        if isok(mid):
            right = mid
        else:
            left = mid
    print(right)

    
if __name__ == "__main__":
    resolve()
Buggy python submission (verdict: Runtime Error):
def is_prime(n):
    if n == 2 or n == 3: return True
    if n < 2 or n%2 == 0: return False
    if n < 9: return True
    if n%3 == 0: return False
    r = int(n**0.5)
    f = 5
    while f <= r:
        if n%f == 0: return False
        if n%(f+2) == 0: return False
        f +=6
    return True  

def resolve():
    A, B = list(map(int, input().split()))
    import sympy
    divs = sympy.divisors(A)
    i = 1
    cnt = 0
    while i < len(divs):
        if B%divs[i]==0 and is_prime(divs[i]):
            cnt += 1
        i += 1
    print(cnt+1)
    

if '__main__' == __name__:
    resolve()


Fixed submission:
def is_prime(n):
    if n == 2 or n == 3: return True
    if n < 2 or n%2 == 0: return False
    if n < 9: return True
    if n%3 == 0: return False
    r = int(n**0.5)
    f = 5
    while f <= r:
        if n%f == 0: return False
        if n%(f+2) == 0: return False
        f +=6
    return True  

def divisors(n):
    lower_divs , upper_divs = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divs.append(i)
            if i != n // i:
                upper_divs.append(n//i)
        i += 1
    return lower_divs + upper_divs[::-1]

def resolve():
    A, B = list(map(int, input().split()))
    divs = divisors(A)
    i = 1
    cnt = 0
    while i < len(divs):
        if B%divs[i]==0 and is_prime(divs[i]):
            cnt += 1
        i += 1
    print(cnt+1)
    

if '__main__' == __name__:
    resolve()
Buggy python submission (verdict: Time Limit Exceeded):
def resolve():
    N = int(input())
    S = input()
    d = {}
    for i in range(N):
        key = S[i]
        for j in range(i, N):
            if j != i:
                key += S[j]
            d.setdefault(key, [])
            if len(d[key]) > 0:
                if d[key][-1][1] < i:
                    d[key].append((i, j))    
            else:
                d[key].append((i, j))
    #print(d)
    ans = 0
    for k, v in d.items():
        if len(v) > 1:
            ans = max(ans, len(k))
    print(ans)





if '__main__' == __name__:
    resolve()

Fixed submission:
def resolve():
    N = int(input())
    S = input()
    dp = [[0]*(N+1) for _ in range(N+1)]
    for i in reversed(range(N)):
        for j in reversed(range(N)):
            if S[i] == S[j]:
                dp[i][j] = dp[i+1][j+1] + 1
    
    ans = 0
    for i in range(N):
        for j in range(i, N):
            ans = max(min(dp[i][j], j-i), ans)
    print(ans)


if __name__ == "__main__":
    resolve()

Buggy python submission (verdict: Time Limit Exceeded):
def resolve():
    N = int(input())
    S = input()
    d = {}
    for i in range(N):
        key = S[i]
        for j in range(i, N):
            if j != i:
                key += S[j]
            d.setdefault(key, [])
            if len(d[key]) > 0:
                if d[key][-1][1] < i:
                    d[key].append((i, j))    
            else:
                d[key].append((i, j))
    #print(d)
    ans = 0
    for k, v in d.items():
        if len(v) > 1:
            ans = max(ans, len(k))
    print(ans)





if '__main__' == __name__:
    resolve()

Fixed submission:
def resolve():
    N = int(input())
    S = input()
    dp = [[0]*(N+1) for _ in range(N+1)]
    for i in reversed(range(N)):
        for j in reversed(range(N)):
            if S[i] == S[j]:
                dp[i][j] = dp[i+1][j+1] + 1
    
    ans = 0
    for i in range(N):
        for j in range(i, N):
            ans = max(min(dp[i][j], j-i), ans)
    print(ans)


if __name__ == "__main__":
    resolve()

Buggy python submission (verdict: Time Limit Exceeded):
def resolve():
    N = int(input())
    S = input()
    d = {}
    for i in range(N):
        for j in range(i+1, N+1):
            key = S[i:j]
            d.setdefault(key, [])
            if len(d[key]) > 0:
                if d[key][-1][1] <= i:
                    d[key].append((i, j))    
            else:
                d[key].append((i, j))
    ans = 0
    for k, v in d.items():
        if len(v) > 1:
            ans = max(ans, len(k))
    print(ans)





if '__main__' == __name__:
    resolve()


Fixed submission:
def resolve():
    N = int(input())
    S = input()
    dp = [[0]*(N+1) for _ in range(N+1)]
    for i in reversed(range(N)):
        for j in reversed(range(N)):
            if S[i] == S[j]:
                dp[i][j] = dp[i+1][j+1] + 1
    
    ans = 0
    for i in range(N):
        for j in range(i, N):
            ans = max(min(dp[i][j], j-i), ans)
    print(ans)


if __name__ == "__main__":
    resolve()
Buggy python submission (verdict: Runtime Error):
def resolve():
    N = int(input())
    ary = [N] + list(range(1, N))
    print(N*(N-1)//2)



if '__main__' == __name__:
    resolve()

Fixed submission:
def resolve():
    N = int(input())
    print(int(N*(N-1)//2))



if '__main__' == __name__:
    resolve()
Buggy python submission (verdict: Time Limit Exceeded):
def resolve():
    S = list(input())
    MOD = 10**9+7
    dp = [[0 for _ in range(13)] for __ in range(len(S)+1)]
    dp[0][0] = 1
    for i in range(len(S)):
        for j in range(13):
            if S[i] == "?":
                for k in range(10):
                    dp[i+1][(j*10+k)%13] += dp[i][j]
                    if dp[i+1][(j*10+k)%13] > MOD:
                        dp[i+1][(j*10+k)%13] -= MOD
            else:
                k = int(S[i])
                dp[i+1][(j*10+k)%13] += dp[i][j]
                if dp[i+1][(j*10+k)%13] > MOD:
                    dp[i+1][(j*10+k)%13] -= MOD
    print(dp[len(S)][5])

if '__main__' == __name__:
    resolve()

Fixed submission:
def resolve():
    S = list(input())
    MOD = 10**9+7
    dp = [[0 for _ in range(13)] for __ in range(len(S)+1)]
    dp[0][0] = 1
    for i in range(len(S)):
        for j in range(13):
            if S[i] == "?":
                for k in range(10):
                    dp[i+1][(j*10+k)%13] += dp[i][j]
                    if dp[i+1][(j*10+k)%13] > MOD:
                        dp[i+1][(j*10+k)%13] -= MOD
            else:
                k = int(S[i])
                dp[i+1][(j*10+k)%13] += dp[i][j]
                if dp[i+1][(j*10+k)%13] > MOD:
                    dp[i+1][(j*10+k)%13] -= MOD
    print(dp[len(S)][5])

if '__main__' == __name__:
    resolve()
Buggy python submission (verdict: Time Limit Exceeded):
def resolve():
    L, R = list(map(int, input().split()))
    MOD = 2019
    ans = float("inf")
    l = list(map(lambda x: x%MOD, range(L, R+1)))
    import itertools
    for i, j in itertools.combinations(l, 2):
        ans = min(ans, (i*j)%MOD)
    print(ans)

if '__main__' == __name__:
    resolve()

Fixed submission:
def resolve():
    L, R = list(map(int, input().split()))
    MOD = 2019
    if R - L >= 2019:
        print(0)
        return
    import itertools
    ans = float("inf")
    for i, j in itertools.combinations(list(range(L, R+1)), 2):
        ans = min(ans, i*j%MOD)
    print(ans)

if '__main__' == __name__:
    resolve()
Buggy python submission (verdict: Runtime Error):
from collections import deque
def resolve():
    N = int(input())
    As = list(map(int, input().split(" ")))
    pos = []
    neg = []
    for a in As:
        if a >= 0:
            pos.append(a)
        else:
            neg.append(a)
    pos = deque(sorted(pos))
    neg = deque(sorted(neg))
    x = 0
    y = 0
    ops = []
    while True:
        if len(pos) > 0 and len(neg) > 0:
            if len(pos) > len(neg):
                x = neg.popleft()
                y = pos.pop()
            else:
                x = pos.pop()
                y = neg.popleft()
        elif len(pos) > 1 and len(neg) == 0:
                x = pos.popleft()
                y = pos.pop()
        elif len(neg) > 1 and len(pos) == 0:
                x = pos.pop()
                y = pos.popleft()
        else:
            raise Exception("Unreachable?")
        
        ops.append("{} {}".format(x, y))
        xmy = x - y

        if len(pos) == 0 and len(neg == 0):
            print(xmy)
            break

        if xmy >= 0:
            pos.append(xmy)
        else:
            neg.appendleft(xmy)
        
    [print(i) for i in ops]

if '__main__' == __name__:
    resolve()

Fixed submission:
def resolve():
    (N, K) = list(map(int, input().split(" ")))
    if K == 1:
        print(0)
    else:
        print((N-K))

if '__main__' == __name__:
    resolve()
Buggy python submission (verdict: Runtime Error):
def resolve():
    N, K = list(map(int, input().split()))
    S = input()
    S_small = ""
    cnt = 0
    for c in S:
        if c == "1":
            cnt += 1
        else:
            if cnt > 0:
                S_small += str(cnt)
                cnt = 0
            S_small += "0"
    if cnt > 0:
        S_small += str(cnt)
    S_small = list(S_small)
    #print(S_small)
    sizes = []
    opn = False
    cnt = 0
    idx = 0
    start = 0
    for end, c in enumerate(S_small):
        if c == "0":
            opn = True
            cnt += 1
        else:
            if opn:
                cnt += int(c)
                sizes.append((idx, cnt, start, end))
                idx += 1
                cnt = int(c)
                start = end
                opn = False
            else:
                cnt += int(c)
    if start != end:
        sizes.append((idx, cnt, start, None))
    #print(sizes)
    if sizes == []:
        print(N)
        return
    maxidx, maxcnt, _, __ = max(sizes, key=lambda x: x[1])
    leftidx = maxidx - 1 if maxidx > 0 else None
    rightidx = maxidx + 1 if maxidx < len(sizes)-1 else None
    ans = maxcnt
    for j in range(K-1):
        if leftidx is not None and leftidx >= 0:
            _, leftcnt, left_leftidx, left_rightidx = sizes[leftidx]
            left_leftedge, left_rightedge = int(S_small[left_leftidx]), int(S_small[left_rightidx])
            leftdiff = leftcnt - left_rightedge
        else:
            leftdiff = 0

        if rightidx is not None and rightidx <= len(sizes)-1:
            _, rightcnt, right_leftidx, right_rightidx = sizes[leftidx]
            right_leftedge, right_rightedge = int(S_small[right_leftidx]), int(S_small(right_rightidx))
            rightdiff = rightcnt - right_leftedge
        else:
            rightdiff = 0

        if leftidx < 0 and rightidx > len(sizes)-1:
            break

        if rightdiff < leftdiff:
            ans += leftdiff
            leftidx -= 1
        else:
            ans += rightdiff
            rightidx += 1
    print(ans)

    

if '__main__' == __name__:
    resolve()

Fixed submission:
def resolve():
    N, K = list(map(int, input().split()))
    S = input()
    seq = []
    cnt = 0
    for i in range(len(S)):
        if i == N-1 or S[i] != S[i+1]:
            seq.append([cnt+1, S[i]])
            cnt = 0
        else:
            cnt += 1
    #print(seq)
    left = 0
    right = 0
    maxlen = 0
    val = 0
    n_rev = 0
    for left in range(0, len(seq)):
        while (right < len(seq) and (n_rev < K or seq[right][1]=="1")):
            #print("left={}, right={}, n_rev={}".format(left, right, n_rev))
            cnt, state = seq[right]
            val += cnt
            if state == "0":
                n_rev += 1
            right += 1
        maxlen = max(maxlen, val)
        cnt, state = seq[left]
        val -= cnt
        if state == "0":
            n_rev -= 1
        if left == right:
            right += 1
    print(maxlen)
    

if '__main__' == __name__:
    resolve()
Buggy python submission (verdict: Time Limit Exceeded):
def resolve():
    X, Y, Z, K = list(map(int, input().split()))
    A = sorted(list(map(int, input().split())))
    B = sorted(list(map(int, input().split())))
    C = sorted(list(map(int, input().split())))

    AB = []
    for a in A:
        for b in B:
            AB.append(a+b)
    AB = sorted(AB, reverse=True)[:K]
    ABC = []
    for ab in AB:
        for c in C:
            ABC.append(ab+c)
    ABC = sorted(ABC, reverse=True)
    [print(ABC[i]) for i in range(K)]


if '__main__' == __name__:
    resolve()

Fixed submission:
def resolve():
    X, Y, Z, K = list(map(int, input().split()))
    A = sorted(list(map(int, input().split())))
    B = sorted(list(map(int, input().split())))
    C = sorted(list(map(int, input().split())))

    AB = []
    for a in A:
        for b in B:
            AB.append(a+b)
    AB = sorted(AB, reverse=True)[:K]
    ABC = []
    for ab in AB:
        for c in C:
            ABC.append(ab+c)
    ABC = sorted(ABC, reverse=True)
    [print(ABC[i]) for i in range(K)]


if '__main__' == __name__:
    resolve()
Buggy python submission (verdict: Runtime Error):
def resolve():
    S = int(input())
    zeros = S.count("0")
    print(min(zeros, len(zeros)*2)

if '__main__' == __name__:
    resolve()

Fixed submission:
def resolve():
    S = input()
    zeros = S.count("0")
    print(min(zeros, len(S)-zeros)* 2)

if '__main__' == __name__:
    resolve()
Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10000)

def resolve():
    N = int(input())
    hs = list(map(int, input().split(" ")))
    dps = [None] * N

    def rec(dest):
        if dest == 0:
            dps[dest] = 0
        if dest == 1:
            dps[dest] = abs(hs[1]-hs[0])

        if dps[dest] is None:
            dps[dest] = min(rec(dest-1)+abs(hs[dest]-hs[dest-1]), rec(dest-2)+abs(hs[dest]-hs[dest-2]))
        
        return dps[dest]

    print(rec(N-1))

if __name__ == '__main__':
    resolve()

Fixed submission:
def resolve():
    N = int(input())
    hs = list(map(int, input().split(" ")))
    dps = [0] * N

    dps[0] = 0
    dps[1] = abs(hs[1] - hs[0])
    for i in range(2, N):
        dps[i] = min(dps[i-1]+abs(hs[i]-hs[i-1]), dps[i-2]+abs(hs[i]-hs[i-2]))
    
    print(dps[-1])

if __name__ == '__main__':
    resolve()

Buggy python submission (verdict: Runtime Error):
def resolve():
    N = int(input())
    hs = list(map(int, input().split(" ")))
    dps = [None] * N

    def rec(dest):
        if dest == 0:
            dps[dest] = 0
        if dest == 1:
            dps[dest] = abs(hs[1]-hs[0])

        if dps[dest] is None:
            dps[dest] = min(rec(dest-1)+abs(hs[dest]-hs[dest-1]), rec(dest-2)+abs(hs[dest]-hs[dest-2]))
        
        return dps[dest]

    print(rec(N-1))

if __name__ == '__main__':
    resolve()

Fixed submission:
def resolve():
    N = int(input())
    hs = list(map(int, input().split(" ")))
    dps = [0] * N

    dps[0] = 0
    dps[1] = abs(hs[1] - hs[0])
    for i in range(2, N):
        dps[i] = min(dps[i-1]+abs(hs[i]-hs[i-1]), dps[i-2]+abs(hs[i]-hs[i-2]))
    
    print(dps[-1])

if __name__ == '__main__':
    resolve()

Buggy python submission (verdict: Runtime Error):
def resolve():
    N = int(input())
    hs = list(map(int, input().split(" ")))
    dps = [None] * N

    def rec(dest):
        if dest == 0:
            return 0
        if dest == 1:
            return abs(hs[1]-hs[0])

        if dps[dest] is None:
            dps[dest] = min(rec(dest-1)+abs(hs[dest]-hs[dest-1]), rec(dest-2)+abs(hs[dest]-hs[dest-2]))
        
        return dps[dest]

    print(rec(N-1))

if __name__ == '__main__':
    resolve()

Fixed submission:
def resolve():
    N = int(input())
    hs = list(map(int, input().split(" ")))
    dps = [0] * N

    dps[0] = 0
    dps[1] = abs(hs[1] - hs[0])
    for i in range(2, N):
        dps[i] = min(dps[i-1]+abs(hs[i]-hs[i-1]), dps[i-2]+abs(hs[i]-hs[i-2]))
    
    print(dps[-1])

if __name__ == '__main__':
    resolve()
Buggy python submission (verdict: Runtime Error):
def resolve():
    N = int(input())
    conds = [list(map(int, input().split(" "))) for i in range(N)]
    
    # [[cx, cy, H]]
    candidates = []

    first = sorted(conds, reverse=True, key=lambda x:x[2])[0]
    for cx in range(101):
        for cy in range(101):
            H = abs(first[0]-cx)+abs(first[1]-cy)+first[2]
            for n in range(1, N):
                cond = conds[n]
                if cond[2] == 0:
                    if abs(cond[0]-cx)+abs(cond[1]-cy) < cond[2]: 
                        ansflg = False
                        break
                else:
                    if abs(cond[0]-cand[0])+abs(cond[1]-cand[1])+cond[2] != H:
                        ansflg = False
                        break
            else:
                print("{} {} {}".format(cx, cy, H))
                exit()


if '__main__' == __name__:
    resolve()

Fixed submission:
def resolve():
    N = int(input())
    if N==1:
        print("Hello World")
        return
    A = int(input())
    B = int(input())
    print(A+B)


if '__main__' == __name__:
    resolve()
Buggy python submission (verdict: Runtime Error):
def resolve():
    S = input()
    T = input()
    chmap = {}
    # 2つのアルファベットを選んで入れ替えるという操作を何回繰り返しても、
    # 必ずalphabet26文字は自分以外のalphabetと一対一に対応し重複しない
    for i in range(len(S)):
        if S[i] != T[i]:
            if S[i] in chmap: 
                if chmap[S[i]] != T[i]:
                    print("No")
                    return
            else:
                chmap[S[i]] = T[i]

    import collections
    chmapMosts = collections.Counter(chmap.values()).most_common()
    if chmapMosts[0][1] > 1:
        print("No")
        return
    
    print("Yes")
    return


if '__main__' == __name__:
    resolve()

Fixed submission:
def resolve():
    S = input()
    T = input()
    smap = {}
    tmap = {}
    for i in range(len(S)):
        if S[i] in smap: 
            if smap[S[i]] != T[i]:
                print("No")
                return
        else:
            smap[S[i]] = T[i]
        
        if T[i] in tmap: 
            if tmap[T[i]] != S[i]:
                print("No")
                return
        else:
            tmap[T[i]] = S[i]

    print("Yes")
    return


if '__main__' == __name__:
    resolve()

Buggy python submission (verdict: Runtime Error):
def resolve():
    S = input()
    T = input()
    chmap = {}
    # 2つのアルファベットを選んで入れ替えるという操作を何回繰り返しても、
    # 必ずalphabet26文字は自分以外のalphabetと一対一に対応し重複しない
    for i in range(len(S)):
        if S[i] != T[i]:
            if S[i] in chmap: 
                if chmap[S[i]] != T[i]:
                    print("No")
                    return
            else:
                chmap[S[i]] = T[i]

    import collections
    chmapMosts = collections.Counter(chmap.values()).most_common()
    if chmapMosts[0][1] > 1:
        print("No")
        return
    
    print("Yes")
    return


if '__main__' == __name__:
    resolve()

Fixed submission:
def resolve():
    S = input()
    T = input()
    smap = {}
    tmap = {}
    for i in range(len(S)):
        if S[i] in smap: 
            if smap[S[i]] != T[i]:
                print("No")
                return
        else:
            smap[S[i]] = T[i]
        
        if T[i] in tmap: 
            if tmap[T[i]] != S[i]:
                print("No")
                return
        else:
            tmap[T[i]] = S[i]

    print("Yes")
    return


if '__main__' == __name__:
    resolve()
Buggy python submission (verdict: Runtime Error):
N, i = map(int, input().split(" "))
return N - i + 1

Fixed submission:
N, i = map(int, input().split(" "))
print(N - i + 1)
Buggy python submission (verdict: Runtime Error):
def resolve():
    S = input()
    K = int(input())
    cnt = 0
    
    for s in S:
        if s != "1":
            break
        cnt += 1
    if cnt > K:
        print("1")
    else:
        print(S[cnt])


if '__main__' == __name__:
    resolve()

Fixed submission:
def resolve():
    S = input()
    K = int(input())
    cnt = 0
    
    for s in S:
        if s != "1":
            break
        cnt += 1
    if cnt >= K:
        print("1")
    else:
        print(S[cnt])


if '__main__' == __name__:
    resolve()
Buggy python submission (verdict: Runtime Error):
import sys

def resolve():
    A, B, K = list(map(int, input().split(" ")))
    L = list(range(A, B+1))
    for s in sorted(list(set(L[:K]+L[-K:]))):
        print(s)

if '__main__' == __name__:
    resolve()

Fixed submission:
import sys

def resolve():
    A, B, K = list(map(int, input().split(" ")))
    out = []
    for i in range(A, A+K):
        if i <= B:
            out.append(i)
    for j in range(B-K+1, B+1):
        if j >= A and not j in out:
            out.append(j)
    
    [print(s) for s in out]

if '__main__' == __name__:
    resolve()