Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
import numpy as np

from sys import stdin


def main():
    n, m = map(int, stdin.readline().split())
    a = list(map(int, stdin.readline().split()))
    a = np.array(a)

    ans = n - np.sum(a)

    print(-1) if ans < 0 else print(ans)


if __name__ == "__main__":
    main()


Fixed submission:
import numpy as np

from sys import stdin


def main():
    n, m = map(int, stdin.readline().split())
    a = list(map(int, stdin.readline().split()))
    a = np.array(a)

    ans = n - np.sum(a)

    print(-1) if ans < 0 else print(ans)


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Runtime Error):
import numpy as np

from sys import stdin


def main():
    n, m = map(int, stdin.readline().split())
    a = list(map(int, stdin.readline().split()))

    ans = n - np.sum(a)

    print(-1) if ans < 0 else print(ans)


if __name__ == "__main__":
    main()


Fixed submission:
import numpy as np

from sys import stdin


def main():
    n, m = map(int, stdin.readline().split())
    a = list(map(int, stdin.readline().split()))
    a = np.array(a)

    ans = n - np.sum(a)

    print(-1) if ans < 0 else print(ans)


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

from sys import stdin


def main():
    n = int(stdin.readline())
    a = list(map(int, stdin.readline().split()))

    a2 = [[a[i], i] for i in range(n)]
    a2.sort(reverse=True)

    dp = [[0 for _ in range(n + 1)] for _ in range(n + 1)]

    ans = 0

    for i in range(n + 1):
        for j in range(n + 1 - i):
            s1 = s2 = 0
            if i > 0:
                s1 = dp[i - 1][j] + a2[i + j - 1][0] * (a2[i + j - 1][1] - (i - 1))
            if j > 0:
                s2 = dp[i][j - 1] + a2[i + j - 1][0] * ((n - j) - a2[i + j - 1][1])
            dp[i][j] = np.max([s1, s2])
        ans = np.max([ans, dp[i][n - i]])

    print(ans)


if __name__ == "__main__":
    main()


Fixed submission:
from sys import stdin


def main():
    n = int(stdin.readline())
    a = list(map(int, stdin.readline().split()))

    a2 = [[a[i], i] for i in range(n)]
    a2.sort(reverse=True)

    dp = [[0 for _ in range(n + 1)] for _ in range(n + 1)]

    ans = 0

    for i in range(n + 1):
        for j in range(n + 1 - i):
            s1 = s2 = 0
            if i > 0:
                s1 = dp[i - 1][j] + a2[i + j - 1][0] * (a2[i + j - 1][1] - (i - 1))
            if j > 0:
                s2 = dp[i][j - 1] + a2[i + j - 1][0] * ((n - j) - a2[i + j - 1][1])
            dp[i][j] = max(s1, s2)
        ans = max(ans, dp[i][n - i])

    print(ans)


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin, setrecursionlimit


def main():
    input = stdin.buffer.readline
    n = int(input())
    s = list(input()[:-1].decode())
    r = []
    g = []
    b = []
    for i in range(n):
        if s[i] == 'R':
            r.append(i)
        elif s[i] == 'G':
            g.append(i)
        elif s[i] == 'B':
            b.append(i)
    ans = len(r) * len(g) * len(b)

    def check(n):
        return b.count(n) > 0

    for ri in r:
        for gi in g:
            if check(2 * gi - ri):
                ans -= 1
            if check(2 * ri - gi):
                ans -= 1
            if (ri + gi) % 2 == 0 and check((ri + gi) // 2):
                ans -= 1
    print(ans)


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()


Fixed submission:
from sys import stdin


def main():
    n = int(stdin.readline())
    s = stdin.readline()[:-1]

    nr = 0
    ng = 0
    nb = 0
    nn = 0

    for i in range(n):
        if s[i] == 'R':
            nr += 1
        elif s[i] == 'G':
            ng += 1
        elif s[i] == 'B':
            nb += 1
        for j in range(i + 1, n):
            k = j + j - i
            if 0 <= k < n and s[i] != s[j] and s[j] != s[k] and s[k] != s[i]:
                nn += 1

    print(nr * ng * nb - nn)


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin, setrecursionlimit


def main():
    input = stdin.readline
    s = list(input()[:-1])
    Q = int(input())
    reverse = False
    for _ in range(Q):
        q = list(map(str, input().split()))
        t = q[0]
        if t == '1':
            reverse = not (reverse)
        else:
            if reverse ^ (q[1] == '1'):
                s.insert(0, q[2])
            else:
                s.append(q[2])
    if reverse:
        s.reverse()
    print(*s, sep='')


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()


Fixed submission:
from sys import stdin, setrecursionlimit


def main():
    input = stdin.readline
    s = list(input()[:-1])
    Q = int(input())
    reverse = False
    before = []
    after = []
    for _ in range(Q):
        q = list(map(str, input().split()))
        t = q[0]
        if t == '1':
            reverse = not (reverse)
        else:
            if reverse ^ (q[1] == '1'):
                before.append(q[2])
            else:
                after.append(q[2])
    if reverse:
        after.reverse()
        s.reverse()
        print(''.join(after + s + before))
    else:
        before.reverse()
        print(''.join(before + s + after))


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()

Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin, setrecursionlimit


def main():
    input = stdin.readline
    s = list(input()[:-1])
    Q = int(input())
    reverse = False
    for _ in range(Q):
        q = list(map(str, input().split()))
        t = q[0]
        if t == '1':
            reverse = not (reverse)
        else:
            if reverse ^ (q[1] == '1'):
                s.insert(0, q[2])
            else:
                s.append(q[2])
    if reverse:
        s.reverse()
    print(*s, sep='')


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()


Fixed submission:
from sys import stdin, setrecursionlimit


def main():
    input = stdin.readline
    s = list(input()[:-1])
    Q = int(input())
    reverse = False
    before = []
    after = []
    for _ in range(Q):
        q = list(map(str, input().split()))
        t = q[0]
        if t == '1':
            reverse = not (reverse)
        else:
            if reverse ^ (q[1] == '1'):
                before.append(q[2])
            else:
                after.append(q[2])
    if reverse:
        after.reverse()
        s.reverse()
        print(''.join(after + s + before))
    else:
        before.reverse()
        print(''.join(before + s + after))


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()
Buggy python submission (verdict: Runtime Error):
def main():
    input = stdin.buffer.readline
    n, k = map(int, input().split())
    r, s, p = map(int, input().split())
    t = input()[:-1].decode()

    ans = 0
    result = [False] * n
    for i in range(n):
        if k <= i and t[i] == t[i - k] and result[i - k]:
            continue
        if t[i] == 'r':
            ans += p
        elif t[i] == 's':
            ans += r
        elif t[i] == 'p':
            ans += s
        result[i] = True

    print(ans)


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()


Fixed submission:
from sys import stdin, setrecursionlimit


def main():
    input = stdin.buffer.readline
    n, k = map(int, input().split())
    r, s, p = map(int, input().split())
    t = input()[:-1].decode()

    ans = 0
    result = [False] * n
    for i in range(n):
        if k <= i and t[i] == t[i - k] and result[i - k]:
            continue
        if t[i] == 'r':
            ans += p
        elif t[i] == 's':
            ans += r
        elif t[i] == 'p':
            ans += s
        result[i] = True

    print(ans)


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()
Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin, setrecursionlimit


def main():
    mod = 10 ** 9 + 7
    input = stdin.buffer.readline
    n = int(input())
    a = list(map(int, input().split()))

    ans = 0

    for i in range(n - 1):
        for j in range(i + 1, n):
            ans += a[i] ^ a[j]
            ans %= mod

    print(ans % mod)


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()


Fixed submission:
from sys import stdin, setrecursionlimit


def main():
    mod = 10 ** 9 + 7
    input = stdin.buffer.readline
    n = int(input())
    a = list(map(int, input().split()))

    counts = [0] * 60

    for ai in a:
        for i in range(60):
            if ai & (1 << i):
                counts[i] += 1

    ans = 0
    base = 0

    for c in counts:
        ans += c * (n - c) * (1 << base)
        ans %= mod
        base += 1

    print(ans % mod)


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()
Buggy python submission (verdict: Runtime Error):
from sys import stdin, setrecursionlimit


def initialize_cmb(m, mod=10 ** 9 + 7):
    fac = [1]
    finv = [1]
    inv = [0] * (m + 1)
    if m > 1:
        fac.append(1)
        finv.append(1)
        inv[1] = 1
        pre_fac = 1
        pre_finv = 1
        for i in range(2, m + 1):
            pre_fac = pre_fac * i % mod
            fac.append(pre_fac)
            inv[i] = mod - inv[mod % i] * (mod // i) % mod
            pre_finv = pre_finv * inv[i] % mod
            finv.append(pre_finv)
    return fac, finv


def cmb(n, k, fac, finv, mod=10 ** 9 + 7):
    if n < k:
        return 0
    if n < 0 or k < 0:
        return 0
    return fac[n] * (finv[k] * finv[n - k] % mod) % mod


def main():
    mod = 10 ** 9 + 7
    input = stdin.buffer.readline
    x, y = map(int, input().split())

    if (x + y) % 3 != 0 or 2 * x < y or 2 * y < x:
        print(0)
    else:
        fac, finv = initialize_cmb((x + y) // 3, mod)

        x_min = (x + y) // 3
        y_max = 2 * (x + y) // 3

        print(cmb((x + y) // 3, x - x_min, fac, finv, mod))


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()


Fixed submission:
from sys import stdin, setrecursionlimit


def initialize_cmb(m, mod=10 ** 9 + 7):
    fac = [1]
    finv = [1]
    inv = [0] * (m + 1)
    if m >= 1:
        fac.append(1)
        finv.append(1)
        inv[1] = 1
        pre_fac = 1
        pre_finv = 1
        for i in range(2, m + 1):
            pre_fac = pre_fac * i % mod
            fac.append(pre_fac)
            inv[i] = mod - inv[mod % i] * (mod // i) % mod
            pre_finv = pre_finv * inv[i] % mod
            finv.append(pre_finv)
    return fac, finv


def cmb(n, k, fac, finv, mod=10 ** 9 + 7):
    if n < k:
        return 0
    if n < 0 or k < 0:
        return 0
    return fac[n] * (finv[k] * finv[n - k] % mod) % mod


def main():
    mod = 10 ** 9 + 7
    input = stdin.buffer.readline
    x, y = map(int, input().split())

    if (x + y) % 3 != 0 or 2 * x < y or 2 * y < x:
        print(0)
    else:
        fac, finv = initialize_cmb((x + y) // 3, mod)

        x_min = (x + y) // 3

        print(cmb((x + y) // 3, x - x_min, fac, finv, mod))


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()
Buggy python submission (verdict: Runtime Error):
from sys import stdin, setrecursionlimit


def main():
    input = stdin.buffer.readline
    n = int(input())
    l = list(map(int, input().split()))
    l.sort()

    l_c = [0] * 1001

    for li in l:
        l_c[li] += 1
    for i in range(1000):
        l_c[i + 1] += l_c[i]

    ans = 0

    for i in range(n - 2):
        for j in range(i + 1, n - 1):
            ans += l_c[l[i] + l[j] - 1] - j - 1

    print(ans)


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()


Fixed submission:
from sys import stdin, setrecursionlimit


def main():
    input = stdin.buffer.readline
    n = int(input())
    l = list(map(int, input().split()))
    l.sort()

    l_c = [0] * 2001

    for li in l:
        l_c[li] += 1
    for i in range(2000):
        l_c[i + 1] += l_c[i]

    ans = 0

    for i in range(n - 2):
        for j in range(i + 1, n - 1):
            ans += l_c[l[i] + l[j] - 1] - j - 1

    print(ans)


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()

Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin, setrecursionlimit


def main():
    input = stdin.buffer.readline
    n = int(input())
    l = list(map(int, input().split()))
    l.sort()

    ans = 0

    for i in range(n - 2):
        for j in range(i + 1, n - 1):
            a = l[i]
            b = l[j]
            k = j + 1
            while k < n and l[k] < a + b:
                ans += 1
                k += 1

    print(ans)


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()


Fixed submission:
from sys import stdin, setrecursionlimit


def main():
    input = stdin.buffer.readline
    n = int(input())
    l = list(map(int, input().split()))
    l.sort()

    l_c = [0] * 2001

    for li in l:
        l_c[li] += 1
    for i in range(2000):
        l_c[i + 1] += l_c[i]

    ans = 0

    for i in range(n - 2):
        for j in range(i + 1, n - 1):
            ans += l_c[l[i] + l[j] - 1] - j - 1

    print(ans)


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()
Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin, setrecursionlimit


def gcd(x, y):
    if x % y == 0:
        return y
    return gcd(y, x % y)


def is_prime(n):
    if n == 1:
        return False
    for i in range(2, int(n**0.5)+1):
        if n % i == 0:
            return False
    return True


def main():
    input = stdin.buffer.readline
    a, b = map(int, input().split())
    g = gcd(a, b)

    ans = 1
    for i in range(1, g + 1):
        if g % i == 0 and is_prime(i):
            ans += 1

    print(ans)


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()


Fixed submission:
from sys import stdin, setrecursionlimit


def gcd(x, y):
    if x % y == 0:
        return y
    return gcd(y, x % y)


def is_prime(n):
    if n == 1:
        return False
    for i in range(2, int(n ** 0.5) + 1):
        if n % i == 0:
            return False
    return True


def main():
    input = stdin.buffer.readline
    a, b = map(int, input().split())
    g = gcd(a, b)

    ans = 1
    for i in range(1, int(g ** 0.5) + 1):
        if g % i == 0:
            if is_prime(i):
                ans += 1
            if is_prime(g // i):
                ans += 1

    print(ans)


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()
Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin, setrecursionlimit
from bisect import insort


def main():
    input = stdin.buffer.readline
    n, m = map(int, input().split())
    a = list(map(int, input().split()))
    a.sort()

    for _ in range(m):
        tmp = a[n - 1] // 2
        insort(a, tmp)

    print(sum(a[:n]))


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()


Fixed submission:
from sys import stdin, setrecursionlimit
from heapq import heapify, heappop, heappush


def main():
    input = stdin.buffer.readline
    n, m = map(int, input().split())
    a = list(map(int, input().split()))
    a = [-ai for ai in a]
    heapify(a)

    for _ in range(m):
        tmp = -heappop(a)
        heappush(a, -(tmp // 2))

    print(-sum(a))


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()

Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin, setrecursionlimit


def main():
    input = stdin.buffer.readline
    n, m = map(int, input().split())
    a = list(map(int, input().split()))

    for _ in range(m):
        a.sort()
        a[-1] = a[-1] // 2

    print(sum(a))


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()


Fixed submission:
from sys import stdin, setrecursionlimit
from heapq import heapify, heappop, heappush


def main():
    input = stdin.buffer.readline
    n, m = map(int, input().split())
    a = list(map(int, input().split()))
    a = [-ai for ai in a]
    heapify(a)

    for _ in range(m):
        tmp = -heappop(a)
        heappush(a, -(tmp // 2))

    print(-sum(a))


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()
Buggy python submission (verdict: Runtime Error):
from sys import stdin, setrecursionlimit
import numpy as np


def main():
    input = stdin.buffer.readline
    n = int(input())
    a = list(map(int, input().split()))

    num = np.prod(a)

    den = sum([num // a[i] for i in range(n)])

    print(num / den)


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()


Fixed submission:
from sys import stdin, setrecursionlimit


def main():
    input = stdin.buffer.readline
    n = int(input())
    a = list(map(int, input().split()))

    num = 1
    for ai in a:
        num *= ai

    den = sum([num // a[i] for i in range(n)])

    print(num / den)


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()
Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin, setrecursionlimit


def main():
    input = stdin.buffer.readline
    n = int(input())
    a = list(map(int, input().split()))
    x_sum = sum(a) // 2
    x = [0] * n
    for i in range(n):
        tmp = x_sum
        idx = (i + 1) % n
        for _ in range((n - 1) // 2):
            tmp -= a[idx]
            idx += 2
            idx %= n
        x[i] = 2 * tmp
    print(*x)


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()


Fixed submission:
from sys import stdin, setrecursionlimit


def main():
    input = stdin.buffer.readline
    n = int(input())
    a = list(map(int, input().split()))
    x_sum = sum(a) // 2
    x = [0] * n
    tmp = x_sum
    idx = 1
    for _ in range((n - 1) // 2):
        tmp -= a[idx]
        idx += 2
        idx %= n
    x[0] = 2 * tmp
    for i in range(n - 1):
        x[i + 1] = 2 * (a[i] - x[i] // 2)
    print(*x)


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()
Buggy python submission (verdict: Runtime Error):
from sys import stdin, setrecursionlimit


def main():
    input = stdin.buffer.readline
    n, x = map(int, input().split())
    l = list(map(int, input().split()))

    ans = 1
    d = 0
    while True:
        d += l.pop(0)
        if d <= x:
            ans += 1
        else:
            break
    print(ans)


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()


Fixed submission:
from sys import stdin, setrecursionlimit


def main():
    input = stdin.buffer.readline
    n, x = map(int, input().split())
    l = list(map(int, input().split()))

    ans = 1
    d = 0
    for li in l:
        if d + li <= x:
            ans += 1
            d += li
        else:
            break
    print(ans)


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()
Buggy python submission (verdict: Runtime Error):
from sys import stdin, setrecursionlimit


def main():
    input = stdin.buffer.readline
    h, w = map(int, input().split())
    col = [[0, w + 1] for _ in range(h)]
    row = [[0, h + 1] for _ in range(w)]
    for i in range(h):
        s = list(input()[:-1].decode())
        for j in range(w):
            if s[j] == '#':
                col[i].append(j + 1)
                row[j].append(i + 1)

    cc = [[0] * (w + 2) for _ in range(h)]
    rc = [[0] * (h + 2) for _ in range(w)]

    for i in range(h):
        col[i].sort()
        for j in range(len(col[i]) - 1):
            cc[i][col[i][j] + 1:col[i][j + 1]] = [col[i][j + 1] - col[i][j] - 1] * (col[i][j + 1] - col[i][j] - 1)

    for i in range(w):
        row[i].sort()
        for j in range(len(row[i]) - 1):
            rc[i][row[i][j] + 1:row[i][j + 1]] = [row[i][j + 1] - row[i][j] - 1] * (row[i][j + 1] - row[i][j] - 1)

    ans = 0
    for i in range(1, h + 1):
        for j in range(1, w + 1):
            ans = max(ans, cc[i][j] + rc[j][i] - 1)

    print(ans)


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()


Fixed submission:
from sys import stdin, setrecursionlimit


def main():
    input = stdin.buffer.readline
    h, w = map(int, input().split())
    col = [[0, w + 1] for _ in range(h)]
    row = [[0, h + 1] for _ in range(w)]
    for i in range(h):
        s = list(input()[:-1].decode())
        for j in range(w):
            if s[j] == '#':
                col[i].append(j + 1)
                row[j].append(i + 1)

    cc = [[0] * (w + 2) for _ in range(h)]
    rc = [[0] * (h + 2) for _ in range(w)]

    for i in range(h):
        col[i].sort()
        for j in range(len(col[i]) - 1):
            cc[i][col[i][j] + 1:col[i][j + 1]] = [col[i][j + 1] - col[i][j] - 1] * (col[i][j + 1] - col[i][j] - 1)

    for i in range(w):
        row[i].sort()
        for j in range(len(row[i]) - 1):
            rc[i][row[i][j] + 1:row[i][j + 1]] = [row[i][j + 1] - row[i][j] - 1] * (row[i][j + 1] - row[i][j] - 1)

    ans = 0
    for i in range(h):
        for j in range(w):
            ans = max(ans, cc[i][j + 1] + rc[j][i + 1] - 1)

    print(ans)


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()
Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin, setrecursionlimit


def main():
    input = stdin.buffer.readline
    n, m = map(int, input().split())
    counts = [0] * n
    for _ in range(m):
        l, r = map(int, input().split())
        for i in range(l - 1, r):
            counts[i] += 1
    print(counts.count(m))


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()


Fixed submission:
from sys import stdin, setrecursionlimit


def main():
    input = stdin.buffer.readline
    n, m = map(int, input().split())
    l_max = 0
    r_min = float('inf')
    for _ in range(m):
        l, r = map(int, input().split())
        l_max = max(l_max, l)
        r_min = min(r_min, r)
    print(max(r_min + 1 - l_max, 0))


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()