Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
from itertools import combinations_with_replacement

N, M, Q = map(int, input().split())
L = []
for _ in range(Q):
    L.append(tuple(map(int, input().split())))

ans = 0
for A in combinations_with_replacement(range(1, M + 1), min(N, M)):
    tmp = 0
    for a, b, c, d in L:
        if A[b - 1] - A[a - 1] == c:
            tmp += d

    if tmp > ans:
        ans = tmp

print(ans)


Fixed submission:
from itertools import combinations_with_replacement

N, M, Q = map(int, input().split())
L = []
for _ in range(Q):
    L.append(tuple(map(int, input().split())))

ans = 0
_N = N
if N < M:
    _N = M

for A in combinations_with_replacement(range(1, M + 1), _N):
    tmp = 0
    for a, b, c, d in L:
        if a <= _N and b <= _N and A[b - 1] - A[a - 1] == c:
            tmp += d

    if tmp > ans:
        ans = tmp

print(ans)
Buggy python submission (verdict: Runtime Error):
a, b, c, d = map(int, input().split())

n1 = (a + d - 1) // d
n2 = (c + b - 1) // b

if n1 => n2:
    print('Yes')
else:
    print('No')

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

n1 = (a + d - 1) // d
n2 = (c + b - 1) // b

if n1 >= n2:
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Time Limit Exceeded):
import queue
INF = 10**10


H, W = map(int, input().split())

def next_field (a):
    ret = []
    if a[0] < H-1 :
        ret.append((a[0] + 1, a[1]))
    
    if a[1] < W-1:
        ret.append((a[0], a[1] + 1))
    
    return ret

field = {}
dist = {}
for h in range(H):
    f = input()
    for w, c in enumerate(f):
        field[(h,w)] = c
        dist[(h,w)] = INF

que = queue.PriorityQueue()

if field[(0,0)] == ".":
    dist[(0,0)] = 0
else:
    dist[(0,0)] = 1

que.put((0,0))


while not que.empty():
    cur = que.get()

    for nxt in next_field(cur):

        if field[cur] == field[nxt] or field[nxt] == ".":
            dist[nxt] = min(dist[nxt], dist[cur])
        else:
            dist[nxt] = min(dist[nxt], 1 + dist[cur])

        que.put(nxt)
    
print(dist[(H-1,W-1)])


Fixed submission:
INF = 10**10


H, W = map(int, input().split())

def next_field (a):
    ret = []
    if a[0] < H-1 :
        ret.append((a[0] + 1, a[1]))
    
    if a[1] < W-1:
        ret.append((a[0], a[1] + 1))
    
    return ret

field = {}
dist = {}
for h in range(H):
    f = input()
    for w, c in enumerate(f):
        field[(h,w)] = c
        dist[(h,w)] = INF

s = set()

if field[(0,0)] == ".":
    dist[(0,0)] = 0
else:
    dist[(0,0)] = 1

s.add((0,0))

while len(s) > 0:
    cur = s.pop()

    for nxt in next_field(cur):

        if field[cur] == field[nxt] or field[nxt] == ".":
            dist[nxt] = min(dist[nxt], dist[cur])
        else:
            dist[nxt] = min(dist[nxt], 1 + dist[cur])

        s.add(nxt)
    
print(dist[(H-1,W-1)])
Buggy python submission (verdict: Runtime Error):
class Solution:
    def solve(self, H: int, W: int) -> int:

        if H == 1 or W == 1:
            return 1
        else:
            return (H*W + 1) // 2


if __name__ == '__main__':

    # standard input
    H, W = map(int, input().split())

    # solve
    solution = Solution()
    print(solution.solve(H, W))


Fixed submission:

class Solution:

    def solve(self, N: int):

        def dfs(prev_str, num_used_char):
            if len(prev_str) == N:
                print(prev_str)
                return

            for i in range(num_used_char):
                c = chr(ord('a') + i)
                dfs(prev_str + c, num_used_char)

            c = chr(ord('a') + num_used_char)
            dfs(prev_str + c, num_used_char + 1)

        dfs('a', 1)


if __name__ == '__main__':

    # standard input
    N = int(input())
    # solve
    solution = Solution()
    answer = solution.solve(N)
Buggy python submission (verdict: Runtime Error):
import unittest
from solution import Solution


class TestSolution(unittest.TestCase):

    def test_001(self):
        # class under test
        solution = Solution()

        # actual
        N, A, B = 6, 2, 4

        actual = solution.solve(N, A, B)

        # expect
        expect = 2

        # assert
        self.assertEqual(actual, expect)

    def test_002(self):
        # class under test
        solution = Solution()

        # actual
        N, A, B = 10**18, 5, 5

        actual = solution.solve(N, A, B)

        # expect
        expect = 5 * 10**17

        # assert
        self.assertEqual(actual, expect)


if __name__ == '__main__':
    unittest.main()


Fixed submission:
class Solution:
    def solve(self, N: int, A: int, B: int) -> int:

        return (N // (A+B)) * A + min(N % (A+B), A)


if __name__ == '__main__':

    # standard input
    N, A, B = map(int, input().split())

    # solve
    solution = Solution()
    print(solution.solve(N, A, B))
Buggy python submission (verdict: Time Limit Exceeded):
class Solution:

    def solve(self, N: int, P: int, S: str):

        if P == 2 or P == 5:
            answer = 0
            for idx, s in enumerate(S):
                if int(s) % P == 0:
                    answer += idx + 1

        else:
            answer = 0
            U = [0] * P  # int(S[i,N] mod P
            U[0] += 1
            for i in range(N):
                U[int(S[i:N]) % P] += 1

            for u in U:
                answer += u * (u-1) // 2

        return answer


if __name__ == '__main__':

    # standard input
    N, P = map(int, input().split())
    S = input()

    # solve
    solution = Solution()
    answer = solution.solve(N, P, S)
    print(answer)


Fixed submission:
class Solution:

    def solve(self, N: int, P: int, S: str):

        if P == 2 or P == 5:
            answer = 0
            for idx, s in enumerate(S):
                if int(s) % P == 0:
                    answer += idx + 1

        else:
            answer = 0
            U = [0] * P  # int(S[i,N] mod P
            U[0] += 1

            num = 0
            base10_mod_p = 1
            for i in range(N):
                num = (num + int(S[N-i-1]) * base10_mod_p) % P
                base10_mod_p = (base10_mod_p * 10) % P

                U[num] += 1

            for u in U:
                answer += u * (u-1) // 2

        return answer


if __name__ == '__main__':

    # standard input
    N, P = map(int, input().split())
    S = input()

    # solve
    solution = Solution()
    answer = solution.solve(N, P, S)
    print(answer)
Buggy python submission (verdict: Runtime Error):
from typing import List


class Solution:
    def solve(self, N: int, A) -> str:

        for a in A:
            if a % 2 == 0:
                if a % 3 != 0 and a % 5 != 0:
                    return "DENIED"

        return "APPROVED"


if __name__ == '__main__':

    # standard input
    N = int(input())
    A = list(map(int, input().split()))

    # solve
    solution = Solution()
    print(solution.solve(N, A))


Fixed submission:
class Solution:
    def solve(self, N: int, A) -> str:

        for a in A:
            if a % 2 == 0:
                if a % 3 != 0 and a % 5 != 0:
                    return "DENIED"

        return "APPROVED"


if __name__ == '__main__':

    # standard input
    N = int(input())
    A = list(map(int, input().split()))

    # solve
    solution = Solution()
    print(solution.solve(N, A))
Buggy python submission (verdict: Runtime Error):
import sys
from collections import defaultdict

readline = sys.stdin.buffer.readline


def geta(fn=lambda s: s.decode()):
    return map(fn, readline().split())


def gete(fn=lambda s: s.decode()):
    return fn(readline().rstrip())


sys.setrecursionlimit(10**5)


def main():
    h, n = geta(int)
    a, b = [0] * (n + 1), [0] * (n + 1)
    for i in range(n):
        a[i + 1], b[i + 1] = geta(int)

    INF = 10**9
    dp = [[INF] * (h + 1) for _ in range(n + 1)]

    for i in range(1, n + 1):
        for j in range(0, a[i] + 1):
            dp[i][j] = min(b[i], dp[i - 1][j])

        for j in range(a[i] + 1, h + 1):
            dp[i][j] = min(dp[i][j - a[i]] + b[i], dp[i - 1][j])

    print(dp[n][h])


if __name__ == "__main__":
    main()

Fixed submission:
import sys
from collections import defaultdict

readline = sys.stdin.buffer.readline


def geta(fn=lambda s: s.decode()):
    return map(fn, readline().split())


def gete(fn=lambda s: s.decode()):
    return fn(readline().rstrip())


sys.setrecursionlimit(10**5)


def main():
    h, n = geta(int)
    a, b = [0] * (n + 1), [0] * (n + 1)
    for i in range(n):
        a[i + 1], b[i + 1] = geta(int)

    INF = 10**9
    dp = [[INF] * (h + 1) for _ in range(n + 1)]

    for i in range(1, n + 1):
        for j in range(0, h + 1):
            if j <= a[i]:
                dp[i][j] = min(b[i], dp[i - 1][j])
            else:
                dp[i][j] = min(dp[i][j - a[i]] + b[i], dp[i - 1][j])

    print(dp[n][h])


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
from typing import List


class Solution:
    def solve(self, N: int, M: int) -> str:
        if N == M:
            return 'Yes'
        else:
            return 'No'


if __name__ == '__main__':

    # standard input
    N, M = map(int, input().split())

    # solve
    solution = Solution()
    print(solution.solve(N, M))


Fixed submission:

class Solution:
    def solve(self, N: int, M: int) -> str:
        if N == M:
            return 'Yes'
        else:
            return 'No'


if __name__ == '__main__':

    # standard input
    N, M = map(int, input().split())

    # solve
    solution = Solution()
    print(solution.solve(N, M))
Buggy python submission (verdict: Runtime Error):
from typing import List


class Solution:
    def solve(self, N: int, P: List[int]) -> int:

        max_p = N
        answer = 0

        for pn in P:
            if pn <= max_p:
                answer += 1
                max_p = pn

        return answer


if __name__ == '__main__':

    # standard input
    N = int(input())

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

    # solve
    solution = Solution()
    print(solution.solve(N, P))


Fixed submission:
class Solution:
#    def solve(self, N: int, P: List[int]) -> int:
    def solve(self, N, P) :
        max_p = N
        answer = 0

        for pn in P:
            if pn <= max_p:
                answer += 1
                max_p = pn

        return answer


if __name__ == '__main__':

    # standard input
    N = int(input())

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

    # solve
    solution = Solution()
    print(solution.solve(N, P))

Buggy python submission (verdict: Runtime Error):

class Solution:
    def solve(self, N: int, P: List[int]) -> int:

        max_p = N
        answer = 0

        for pn in P:
            if pn <= max_p:
                answer += 1
                max_p = pn

        return answer


if __name__ == '__main__':

    # standard input
    N = int(input())

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

    # solve
    solution = Solution()
    print(solution.solve(N, P))

Fixed submission:
class Solution:
#    def solve(self, N: int, P: List[int]) -> int:
    def solve(self, N, P) :
        max_p = N
        answer = 0

        for pn in P:
            if pn <= max_p:
                answer += 1
                max_p = pn

        return answer


if __name__ == '__main__':

    # standard input
    N = int(input())

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

    # solve
    solution = Solution()
    print(solution.solve(N, P))
Buggy python submission (verdict: Runtime Error):
t = []
index = {}
for n in range(N):
    si, ti = input().split()
    ti = int(ti)
    index[si] = n
    t.append(ti)

X = input()

ans = 0
for i in range(index[X]+1, N):
    ans += t[i]

print(ans)

Fixed submission:
N = int(input())
t = []
index = {}
for n in range(N):
    si, ti = input().split()
    ti = int(ti)
    index[si] = n
    t.append(ti)

X = input()

ans = 0
for i in range(index[X]+1, N):
    ans += t[i]

print(ans)
Buggy python submission (verdict: Runtime Error):
import sys
from collections import defaultdict
import bisect
import itertools
readline = sys.stdin.buffer.readline
# sys.setrecursionlimit(10**5)


def geta(fn=lambda s: s.decode()):
    return map(fn, readline().split())


def gete(fn=lambda s: s.decode()):
    return fn(readline().rstrip())


import numpy as np


def main():
    N, M = geta(int)
    A = np.array(list(geta(int)))
    A.sort()

    def c(x):
        """
        @return  # of handshake where hapiness >= x
        """
        X = np.searchsorted(A, x - A)
        return N * N - X.sum()

    left, right = 0, 2 * A[-1] + 1

    while left + 1 < right:
        middle = (left + right) // 2
        if c(middle) >= M:
            left = middle
        else:
            right = middle

    ans = 0
    Acum = np.zeros(N + 1, np.int64)
    Acum[:-1] = np.cumsum(A[::-1])[::-1]
    X = np.searchsorted(A, right - A)

    ans = Acum[X].sum() + (A * (N - X)).sum()

    ans += left * (M - (N * N - X.sum()))

    print(ans)


if __name__ == "__main__":
    main()

Fixed submission:
import sys
from collections import defaultdict
import bisect
import itertools
readline = sys.stdin.buffer.readline
# sys.setrecursionlimit(10**5)


def geta(fn=lambda s: s.decode()):
    return map(fn, readline().split())


def gete(fn=lambda s: s.decode()):
    return fn(readline().rstrip())


def main():
    N, M = geta(int)
    A = list(geta(int))
    A.sort()

    def c(x):
        """
        @return  # of handshake where hapiness >= x
        """
        ret = 0
        for a in A:
            ret += bisect.bisect_left(A, x - a)
        return N * N - ret

    left, right = 0, 2 * A[-1] + 1

    while left + 1 < right:
        middle = (left + right) // 2
        if c(middle) >= M:
            left = middle
        else:
            right = middle

    ans = 0
    Acum = list(itertools.accumulate(A[::-1]))[::-1]
    for a in A:
        idx = bisect.bisect_left(A, right - a)
        if idx < N:
            ans += Acum[idx] + a * (N - idx)
    ans += left * (M - c(right))

    print(ans)


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):

class Solution:
    def solve(self, a: int, b: int) -> int:

        return a * b // math.gcd(a, b)


if __name__ == '__main__':

    # standard input
    a, b = map(int, input().split())

    # solve
    solution = Solution()
    print(solution.solve(a, b))


Fixed submission:
import fractions


class Solution:
    def solve(self, a: int, b: int) -> int:

        return a * b // fractions.gcd(a, b)


if __name__ == '__main__':

    # standard input
    a, b = map(int, input().split())

    # solve
    solution = Solution()
    print(solution.solve(a, b))

Buggy python submission (verdict: Runtime Error):
import math


class Solution:
    def solve(self, a: int, b: int) -> int:

        return a * b // math.gcd(a, b)


if __name__ == '__main__':

    # standard input
    a, b = map(int, input().split())

    # solve
    solution = Solution()
    print(solution.solve(a, b))


Fixed submission:
import fractions


class Solution:
    def solve(self, a: int, b: int) -> int:

        return a * b // fractions.gcd(a, b)


if __name__ == '__main__':

    # standard input
    a, b = map(int, input().split())

    # solve
    solution = Solution()
    print(solution.solve(a, b))
Buggy python submission (verdict: Runtime Error):
from typing import List
import math


class Solution:
    def solve(self, n: int, points: List[List[int]]) -> int:

        s = 0.

        for i in range(n):
            p = points[i]
            for j in range(i+1, n):
                q = points[j]
                s += math.sqrt((p[0]-q[0])**2 + (p[1] - q[1])**2)

        return 2 * s / n


if __name__ == '__main__':

    # standard input
    n = int(input())
    points = []

    for i in range(n):
        x, y = map(int, input().split())
        points.append([x, y])

    # solve
    solution = Solution()
    print(solution.solve(n, points))


Fixed submission:
import math


class Solution:
    def solve(self, n: int, points: list) -> int:

        s = 0.

        for i in range(n):
            p = points[i]
            for j in range(i+1, n):
                q = points[j]
                s += math.sqrt((p[0]-q[0])**2 + (p[1] - q[1])**2)

        return 2 * s / n


if __name__ == '__main__':

    # standard input
    n = int(input())
    points = []

    for i in range(n):
        x, y = map(int, input().split())
        points.append([x, y])

    # solve
    solution = Solution()
    print(solution.solve(n, points))

Buggy python submission (verdict: Runtime Error):
import math


class Solution:
    def solve(self, n: int, points: List[List[int]]) -> int:

        s = 0.

        for i in range(n):
            p = points[i]
            for j in range(i+1, n):
                q = points[j]
                s += math.sqrt((p[0]-q[0])**2 + (p[1] - q[1])**2)

        return 2 * s / n


if __name__ == '__main__':

    # standard input
    n = int(input())
    points = []

    for i in range(n):
        x, y = map(int, input().split())
        points.append([x, y])

    # solve
    solution = Solution()
    print(solution.solve(n, points))


Fixed submission:
import math


class Solution:
    def solve(self, n: int, points: list) -> int:

        s = 0.

        for i in range(n):
            p = points[i]
            for j in range(i+1, n):
                q = points[j]
                s += math.sqrt((p[0]-q[0])**2 + (p[1] - q[1])**2)

        return 2 * s / n


if __name__ == '__main__':

    # standard input
    n = int(input())
    points = []

    for i in range(n):
        x, y = map(int, input().split())
        points.append([x, y])

    # solve
    solution = Solution()
    print(solution.solve(n, points))
Buggy python submission (verdict: Runtime Error):
class Solution:
    def solve(self, x: int, y: int) -> int:

        if (2*x - y) % 3 != 0 or (-x + 2*y) % 3 != 0:
            return 0

        m = (2*x - y) // 3
        n = (-x + 2*y) // 3

        # calculate {m+n}C{n}

        mod = 10**9 + 7

        # power
        def fastPow(x: int, n: int) -> int:
            ans = 1
            while n > 0:
                if n & 1 == 1:
                    ans = ans * x % mod
                x = x * x % mod
                n >>= 1

            return ans

        # factorial and its inverse
        fact = [1]
        inv = [1]
        for i in range(1, m+n+1):
            fact.append(0)
            inv.append(0)
            fact[i] = fact[i-1] * i % mod
            inv[i] = fastPow(fact[i], mod - 2) % mod

        return fact[n+m] * inv[n] % mod * inv[m] % mod


if __name__ == '__main__':

    # standard input
    x, y = map(int, input().split())

    # solve
    solution = Solution()
    print(solution.solve(x, y))


Fixed submission:
class Solution:
    def solve(self, x: int, y: int) -> int:

        if (2*x - y) % 3 != 0 or (-x + 2*y) % 3 != 0:
            return 0

        m = (2*x - y) // 3
        n = (-x + 2*y) // 3

        if m < 0 or n < 0:
            return 0

        # calculate {m+n}C{n}
        def egcd(a, b):
            if a == 0:
                return b, 0, 1
            else:
                g, y, x = egcd(b % a, a)
                return g, x - (b // a) * y, y

        def modinv(a, m):
            g, x, y = egcd(a, m)
            if g != 1:
                raise Exception('modular inverse does not exist')
            else:
                return x % m

        def convination(n: int, r: int, mod: int = 10**9+7) -> int:
            r = min(r, n-r)
            res = 1
            for i in range(r):
                res = res * (n-i) * modinv(i+1, mod) % mod
            return res

        return convination(n+m, m)


if __name__ == '__main__':

    # standard input
    x, y = map(int, input().split())

    # solve
    solution = Solution()
    print(solution.solve(x, y))
Buggy python submission (verdict: Runtime Error):
from typing import List


class Solution:
    def solve(self, a: int, b: int) -> int:

        if 1 <= a <= 9 and 1 <= b <= 9:
            return a*b
        else:
            return -1


if __name__ == '__main__':

    # standard input
    a, b = map(int, input().split())

    # solve
    solution = Solution()
    print(solution.solve(a, b))


Fixed submission:
class Solution:
    def solve(self, a: int, b: int) -> int:

        if 1 <= a <= 9 and 1 <= b <= 9:
            return a*b
        else:
            return -1


if __name__ == '__main__':

    # standard input
    a, b = map(int, input().split())

    # solve
    solution = Solution()
    print(solution.solve(a, b))
Buggy python submission (verdict: Runtime Error):

class Solution:
    def solve(self, n: int) -> int:

        maxDivisor = int(math.sqrt(n) + 0.5)

        for i in range(1, maxDivisor + 1):
            if n % i == 0:
                p = i

        q = n // p

        return p+q-2


if __name__ == '__main__':

    # standard input
    n = int(input())

    # solve
    solution = Solution()
    print(solution.solve(n))


Fixed submission:
import math


class Solution:
    def solve(self, n: int) -> int:

        maxDivisor = int(math.sqrt(n) + 0.5)

        for i in range(1, maxDivisor + 1):
            if n % i == 0:
                p = i

        q = n // p

        return p+q-2


if __name__ == '__main__':

    # standard input
    n = int(input())

    # solve
    solution = Solution()
    print(solution.solve(n))
Buggy python submission (verdict: Runtime Error):
5 4 4
1 2 2
2 3 2
3 4 3
4 5 2
20
2 1
3 1
4 1
5 1
1 2
3 2
4 2
5 2
1 3
2 3
4 3
5 3
1 4
2 4
3 4
5 4
1 5
2 5
3 5
4 5

Fixed submission:
import sys
from collections import defaultdict
from queue import deque
readline = sys.stdin.buffer.readline
#sys.setrecursionlimit(10**8)


def geta(fn=lambda s: s.decode()):
    return map(fn, readline().split())


def gete(fn=lambda s: s.decode()):
    return fn(readline().rstrip())


def main():
    N, M, L = geta(int)
    INF = 10**10

    d = [[INF] * (N + 1) for _ in range(N + 1)]

    for i in range(1, N + 1):
        d[i][i] = 0

    for _ in range(M):
        a, b, c = geta(int)
        d[a][b] = c
        d[b][a] = c

    def warshall_froyd(_d):
        for k in range(1, N + 1):
            for i in range(1, N + 1):
                for j in range(1, N + 1):
                    l = _d[i][k] + _d[k][j]
                    if _d[i][j] > l:
                        _d[i][j] = l

    warshall_froyd(d)

    f = [[INF] * (N + 1) for _ in range(N + 1)]
    for i in range(N + 1):
        f[i][i] = 0
        for j in range(N + 1):
            if d[i][j] <= L:
                f[i][j] = 1

    warshall_froyd(f)

    for _ in range(gete(int)):
        s, t = geta(int)
        ret = f[s][t]
        print(ret - 1 if ret != INF else -1)


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
import sys
from collections import defaultdict
readline = sys.stdin.buffer.readline
#sys.setrecursionlimit(10**8)


def geta(fn=lambda s: s.decode()):
    return map(fn, readline().split())


def gete(fn=lambda s: s.decode()):
    return fn(readline().rstrip())


def main():
    a = gete(int)
    s = gete()

    if s < 3200:
        print(a)
    else:
        print('red')


if __name__ == "__main__":
    main()

Fixed submission:
import sys
from collections import defaultdict
readline = sys.stdin.buffer.readline
#sys.setrecursionlimit(10**8)


def geta(fn=lambda s: s.decode()):
    return map(fn, readline().split())


def gete(fn=lambda s: s.decode()):
    return fn(readline().rstrip())


def main():
    a = gete(int)
    s = gete()

    if a < 3200:
        print('red')
    else:
        print(s)


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
s = input()

ans = 'Good'

for i in range(len(s)-1):
    if s[i] == s[i+1]:
        ans='Bad'

print(ans

Fixed submission:
s = input()

ans = 'Good'

for i in range(len(s)-1):
    if s[i] == s[i+1]:
        ans='Bad'

print(ans)