Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
import sys
w,h,n = map(int, sys.stdin.readline().split())

x_min = 0
x_max = w
y_min = 0
y_max = h

for i in range(n):
    x,y,a = map(int, input().split())
    if a == 1:
        x_min = max(x, x_min)
    elif a == 2:
        x_max = min(x, x_max)
    elif a == 3:
        y_min = max(y, y_min)
    else:
        y_max = mix(y, y_max)

print(x_min, x_max, y_min, y_max)
if x_min >= x_max or y_min >= y_max:
    print(0)
else:
    print((x_max - x_min) * (y_max - y_min))

Fixed submission:
import sys
w,h,n = map(int, sys.stdin.readline().split())

x_min = 0
x_max = w
y_min = 0
y_max = h

for i in range(n):
    x,y,a = map(int, input().split())
    if a == 1:
        x_min = max(x, x_min)
    elif a == 2:
        x_max = min(x, x_max)
    elif a == 3:
        y_min = max(y, y_min)
    else:
        y_max = min(y, y_max)

if x_min >= x_max or y_min >= y_max:
    print(0)
else:
    print((x_max - x_min) * (y_max - y_min))
Buggy python submission (verdict: Time Limit Exceeded):
x = input()

while x.find("ST") != -1:
    index = x.find("ST")
    x = x[:index] + x[index+2:]

print(len(x))


Fixed submission:
x = input()

counter = 0
stack = []

for i in range(len(x)):
    if x[i] == "S":
        stack.append("S")
    elif stack:
        stack.pop()
        counter += 1

print(len(x) - 2 * counter)
Buggy python submission (verdict: Runtime Error):
s = dict()
s["a"] = list(input())[::-1]
s["b"] = list(input())[::-1]
s["c"] = list(input())[::-1]

index = s.pop()

while s[index]:
    index = s.pop()

print(index.upper())

Fixed submission:
s = dict()
s["a"] = list(input())[::-1]
s["b"] = list(input())[::-1]
s["c"] = list(input())[::-1]

index = s["a"].pop()

while s[index]:
    index = s[index].pop()

print(index.upper())
Buggy python submission (verdict: Runtime Error):
from collections import Counter
w = input()

c = Counter(l)

flag = True

for i in c.values():
    if i % 2 == 1:
        flag = False
        break

if flag:
    print("Yes")
else:
    print("No")

Fixed submission:
from collections import Counter
w = input()

c = Counter(w)

flag = True

for i in c.values():
    if i % 2 == 1:
        flag = False
        break

if flag:
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Runtime Error):
if x=1:
  print(0)
if x=0:
  print(1)

Fixed submission:
x = int(input())

if x == 1:
  print(0)
if x == 0:
  print(1)
Buggy python submission (verdict: Runtime Error):
a, b, c = map(int, input().split())

if a=5, b=5, c=7:
  print("Yes")
elif a=5, b=7, c=5:
  print("Yes")
elif a=7, b=5, c=5:
  print("Yes")
else:
  print("No")


Fixed submission:
a, b, c = map(int, input().split())
iroha = [a, b, c]
if iroha.count(5) == 2 and iroha.count(7) == 1:
  print("YES")
else:
  print("NO")
Buggy python submission (verdict: Runtime Error):
from heapq import heappop, heappush


n, k = map(int, input().split())
A = list(map(int, input().split()))
B = []

mod = 10 ** 9 + 7

for a in A:
    num = a
    sign = True
    if a < 0:
        sign = False
        num *= -1

    heappush(B, (-num, sign))

candidate = []
neg_stock = False
keep_neg = 0
count = 0
ans = 1
pos_stock = False

while B and count < k:
    num, sign = heappop(B)
    num *= -1
    if not sign:
        if neg_stock:
            if count == k-1:
                continue
            neg_stock = 0
            ans = ans * num * keep_neg % mod
            count += 2

        else:
            neg_stock += 1
            keep_neg = num

    else:
        if count > k-2:
            ans = ans * num % mod
            count += 1

        else:
            if pos_stock:
                candidate.append(pos_stock*num)
                count -= 1

            else:
                pos_stock = num
                count -= 1

if neg_stock:
    if candidate:
        B.sort()
        if B[0] < 0:
            if neg_stock * -B[0] > candidate[0]:
                ans = ans * neg_stock * -B[0] % mod

    else:
        A.sort(key=lambda x: abs(x))
        ans = 1
        for i in range(k):
            ans = ans * A[i] % mod

print(ans % mod)




Fixed submission:
def get_neg(neg_list, k, mod):
    ans = 1
    neg_list.sort(reverse=True)
    for num in neg_list[:k]:
        ans = ans * num % mod
    return ans


def get_pos(pos_list, neg_list, k, mod):
    ans = 1
    nums = []
    neg_iter = iter(sorted(neg_list))
    pos_iter = iter(sorted(pos_list, reverse=True))
    if k % 2 == 1:
        ans *= pos_iter.__next__()
        k -= 1
        
    for a, b in zip(pos_iter, pos_iter):
        nums.append(a * b)

    for a, b in zip(neg_iter, neg_iter):
        nums.append(a * b)

    nums.sort(reverse=True)
    for num in nums[:k//2]:
        ans *= num
        ans %= mod
    return ans


def get_all(num_list, mod):
    ans = 1
    for num in num_list:
        ans = ans * num % mod
    return ans


def main():
    n, k = map(int, input().split())
    A = list(map(int, input().split()))
    mod = 10 ** 9 + 7
    
    if n == k:
        ans = get_all(A, mod)
        print(ans)
        return
    
    pos_list = []
    neg_list = []

    for a in A:
        if a >= 0:
            pos_list.append(a)
        else:
            neg_list.append(a)

    if k % 2 and not pos_list:
        ans = get_neg(neg_list, k, mod)
    else:
        ans = get_pos(pos_list, neg_list, k, mod)

    print(ans)


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())

ans = 0
for num in range(1, n+1):
    count = n // num
    last = count * num
    total = count * (num + last) // 2
    ans += total

print(ans)


Fixed submission:
n = int(input())

ans = 0
for num in range(1, n+1):
    count = n // num
    last = count * num
    total = count * (num + last) // 2
    ans += total

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np


n = int(input())
count = np.zeros(n+1, dtype=np.int64)
for num in range(1, n+1):
    count[num::num] += 1

print((np.arange(n+1) * count).sum())

Fixed submission:
n = int(input())

ans = 0
for num in range(1, n+1):
    count = n // num
    last = count * num
    total = count * (num + last) // 2
    ans += total

print(ans)
Buggy python submission (verdict: Runtime Error):
IN = iter(Input.split('\n')).__next__
def input():
    return IN()

###################################################

x, n = map(int, input().split())
if n == 0:
    print(x)
    exit()
P = set(map(int, input().split()))

d_min = 1000
ans = 1000
for num in range(-1, 102):
    if num in P:
        continue
    
    d = abs(x-num)
    if d < d_min:
        d_min = d
        ans = num

print(ans)

Fixed submission:
x, n = map(int, input().split())
if n == 0:
    print(x)
    exit()
    
P = set(map(int, input().split()))

d_min = 1000
ans = 1000
for num in range(-1, 102):
    if num in P:
        continue
    
    d = abs(x-num)
    if d < d_min:
        d_min = d
        ans = num

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

n, s = map(int, input().split())
A = list(map(int, input().split()))
DP = np.zeros(3001, dtype=np.int64)

for num, a in enumerate(A):
    double = DP * 2
    shift = np.hstack([np.zeros(a), DP[:-a]]).astype(np.int64)
    DP = double + shift
    DP[a] += 2 ** num

print(DP[s])


Fixed submission:
import numpy as np

mod = 998244353

n, s = map(int, input().split())
A = list(map(int, input().split()))
DP = np.zeros(3005, dtype=np.int64)

for num, a in enumerate(A):
    double = DP * 2
    shift = np.hstack([np.zeros(a), DP[:-a]]).astype(np.int64)
    DP = double + shift
    DP[a] += pow(2, num, mod)
    DP %= mod

print(DP[s])
Buggy python submission (verdict: Time Limit Exceeded):
x = int(input())


def divisors(num):
    array = []
    limit = int(num ** 0.5) + 1
    for i in range(1, limit):
        if num % i == 0:
            div1 = i
            div2 = num//i
            array.append(div1)
            if div1 != div2:
                array.append(div2)
    array.sort()
    return array


divs = divisors(x)

for div in divs:
    for a in range(div+1):
        b = a - div
        if a ** 5 - b ** 5 == x:
            print(a, b)
            exit()


Fixed submission:
x = int(input())

for a in range(-200, 200):
    for b in range(-200, 200):
        if a**5 - b**5 == x:
            print(a, b)
            exit()
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

n, a, b, c = map(int, input().split())
count = {
    'A': a,
    'B': b,
    'C': c
}
queries = []
for _ in range(n):
    query = tuple(input())
    queries.append(query)


def solve(plus, minus):
    count[plus] += 1
    count[minus] += 1
    ans.append(plus)


ans = []
for idx, (x, y) in enumerate(queries):
    if count[x] == count[y] == 0:
        print('No')
        exit()

    if count[x] == count[y] == 1:
        if idx == n-1:
            solve(x, y)
            break

        nex = queries[idx+1]
        if x in nex:
            solve(x, y)
        else:
            solve(y, x)
    
    elif count[x] >= count[y]:
        solve(x, y)
        
    else:
        solve(y, x)

print('Yes')
for c in ans:
    print(c)


Fixed submission:
import sys
input = sys.stdin.readline

n, a, b, c = map(int, input().split())
count = {
    'A': a,
    'B': b,
    'C': c
}
queries = []
for _ in range(n):
    query = tuple(input().replace('\n', ''))
    queries.append(query)


def solve(plus, minus):
    count[plus] += 1
    count[minus] -= 1
    ans.append(plus)


ans = []
for idx, (x, y) in enumerate(queries):
    if count[x] == count[y] == 0:
        print('No')
        exit()

    if count[x] == count[y] == 1:
        if idx == n-1:
            solve(x, y)
            break

        nex = queries[idx+1]
        if x in nex:
            solve(x, y)
        else:
            solve(y, x)

    elif count[x] >= count[y]:
        solve(y, x)

    else:
        solve(x, y)

print('Yes')
for c in ans:
    print(c)
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

mod = 2019
mods_count = np.zeros(2019, dtype=np.int64)
indexes = list(range(2019))
indexes_10 = [index * 10 % mod for index in indexes]

mod = 2019
ans = 0
S = input()
for s in S:
    num = int(s)
    new = np.roll(mods_count, num)
    new[num] += 1

    ans += new[0]
    mods_count = np.zeros(2019, dtype=np.int64)
    mods_count[indexes_10] += new[indexes]

print(ans)


Fixed submission:
from collections import Counter


mod = 2019
S = map(int, reversed(input()))

mods = [0]
num = 0
digit = 1
for s in S:
    num += s * digit
    num %= mod
    mods.append(num)
    digit = digit * 10 % mod

counter = Counter(mods)
ans = 0
for count in counter.values():
    ans += count * (count-1) // 2
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
mods_count = [0] * 2019

mod = 2019
ans = 0
S = input()
for s in S:
    num = int(s)
    new = [0] * 2019
    for i in range(2019):
        index = i + num
        count = mods_count[i]
        new[index % 2019] += count
    new[num] += 1

    ans += new[0]
    nexts = [0] * 2019
    for i in range(2019):
        index = i * 10
        count = new[i]
        nexts[index % 2019] += count

    mods_count = nexts

print(ans)


Fixed submission:
from collections import Counter


mod = 2019
S = map(int, reversed(input()))

mods = [0]
num = 0
digit = 1
for s in S:
    num += s * digit
    num %= mod
    mods.append(num)
    digit = digit * 10 % mod

counter = Counter(mods)
ans = 0
for count in counter.values():
    ans += count * (count-1) // 2
print(ans)
Buggy python submission (verdict: Runtime Error):
def main():
    import heapq

    n, m, s = map(int, input().split())

    edges = [[] for _ in range(n)]
    max_cost = 0
    for _ in range(m):
        from_, to, cost, time = map(int, input().split())
        edges[from_-1].append((to-1, cost, time))
        edges[to-1].append((from_-1, cost, time))
        if cost > max_cost:
            max_cost = cost

    banks = []
    for i in range(n):
        coin, time = map(int, input().split())
        banks.append((coin, time))

    max_coin = max_cost * (n-1)
    if s > max_coin:
        s = max_coin

    INF = float('INF')
    DP = [[INF] * max_coin for _ in range(n)]
    DP[0][s] = 0
    ans = [INF] * n

    def push_todo(node, coin, time):
        if coin < 0:
            return
        if time >= DP[node][coin]:
            return
        heapq.heappush(todo, (time, node, coin))
        DP[node][coin] = time

    def charge(node, current_coin, current_time):
        coin, time = banks[node]
        new_coin = current_coin + coin
        if new_coin >= max_coin:
            new_coin = max_coin-1
        push_todo(node, new_coin, current_time+time)

    todo = [(0, 0, s)]  # time, node, coin
    while todo:
        current_time, node, current_coin = heapq.heappop(todo)
        if current_time > DP[node][current_coin]:
            continue

        if current_time < ans[node]:
            ans[node] = current_time

        charge(node, current_coin, current_time)

        for to, cost, time in edges[node]:
            push_todo(to, current_coin-cost, current_time+time)

    for a in ans[1:]:
        print(a)


if __name__ == '__main__':
    main()


Fixed submission:
import heapq


n, m, s = map(int, input().split())
if s >= 2500:
    s = 2499

edges = [[] for _ in range(n)]
for _ in range(m):
    from_, to, cost, time = map(int, input().split())
    edges[from_-1].append((to-1, cost, time))
    edges[to-1].append((from_-1, cost, time))

banks = [(0, 0) for _ in range(n)]
for i in range(n):
    coin, time = map(int, input().split())
    banks[i] = (coin, time)

INF = float('INF')
DP = [INF] * (n * 2500)
ans = [INF] * n


def to_one_dimension(node, coin):
    return node * 2500 + coin


def push_todo(node, coin, time):
    if coin < 0:
        return
    if time >= DP[to_one_dimension(node, coin)]:
        return
    heapq.heappush(todo, (time, node, coin))


def charge(node, current_coin, current_time):
    coin, time = banks[node]
    new_coin = current_coin + coin
    if new_coin >= 2500:
        new_coin = 2499
    push_todo(node, new_coin, current_time+time)


todo = [(0, 0, s)]
while todo:
    current_time, node, current_coin = heapq.heappop(todo)
    if current_time < ans[node]:
        ans[node] = current_time

    one_d_idx = to_one_dimension(node, current_coin)
    if current_time >= DP[one_d_idx]:
        continue

    DP[one_d_idx] = current_time
    charge(node, current_coin, current_time)

    for to, cost, time in edges[node]:
        push_todo(to, current_coin-cost, current_time+time)

for a in ans[1:]:
    print(a)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
S = input()

if n <= 3:
    print(0)
    exit()

Rs = []
Gs = []
Bs = []

r = 0
g = 0
b = 0

for s in S:
    if s == 'R':
        r += 1
    if s == 'G':
        g += 1
    if s == 'B':
        b += 1

    Rs.append(r)
    Gs.append(g)
    Bs.append(b)

ans = 0
for i in range(n-2):
    for j in range(i+1, n-1):
        if S[i] == S[j]:
            continue
        color = {'R', 'G', 'B'}
        color.discard(S[i])
        color.discard(S[j])
        desire = color.pop()

        pattern = 0
        if desire == 'R':
            pattern = Rs[-1] - Rs[j]
        elif desire == 'G':
            pattern = Gs[-1] - Gs[j]
        elif desire == 'B':
            pattern = Bs[-1] - Bs[j]
        delta = j-i
        if j+delta < n:
            if S[j+delta] == desire:
                pattern -= 1
        ans += pattern

print(ans)

Fixed submission:
n = int(input())
S = input()

if n <= 3:
    print(0)
    exit()

Rs = []
Gs = []
Bs = []

r = 0
g = 0
b = 0

for s in S:
    if s == 'R':
        r += 1
    if s == 'G':
        g += 1
    if s == 'B':
        b += 1

    Rs.append(r)
    Gs.append(g)
    Bs.append(b)

ans = 0
for i in range(n-2):
    for j in range(i+1, n-1):
        if S[i] == S[j]:
            continue
        color = {'R', 'G', 'B'}
        color.discard(S[i])
        color.discard(S[j])
        desire = color.pop()

        pattern = 0
        if desire == 'R':
            pattern = Rs[-1] - Rs[j]
        elif desire == 'G':
            pattern = Gs[-1] - Gs[j]
        elif desire == 'B':
            pattern = Bs[-1] - Bs[j]
        delta = j-i
        if j+delta < n:
            if S[j+delta] == desire:
                pattern -= 1
        ans += pattern

print(ans)
Buggy python submission (verdict: Runtime Error):
n, k = map(int, input().split())
P = list(map(int, input().split()))


E = [0] * 1001

total = 0
for i in range(1, 1001):
    total += i
    e = total / i
    E[i] = e

P_to_E = [E[p] for p in P]

candidates = []
candidate = sum(P_to_E[:k])

for i in range(n-k):
    drop = P_to_E[i]
    add = P_to_E[i+k]
    candidate += add - drop
    candidates.append(candidate)

print(max(candidates))

Fixed submission:
n, k = map(int, input().split())
P = list(map(int, input().split()))


E = [0] * 1001

total = 0
for i in range(1, 1001):
    total += i
    e = total / i
    E[i] = e

P_to_E = [E[p] for p in P]


candidate = sum(P_to_E[:k])
candidates = [candidate]

for i in range(n-k):
    drop = P_to_E[i]
    add = P_to_E[i+k]
    candidate += add - drop
    candidates.append(candidate)

print(max(candidates))
Buggy python submission (verdict: Runtime Error):
import numpy as np
import sys
input = sys.stdin.readline


max_size = 10**4 + 2 * 10**3
h, n = map(int, input().split())
DP = np.ones(max_size, dtype=np.int64) * 10**9
DP[0] = 0

for _ in range(n):
    power, cost = map(int, input().split())
    for i in range((h+power-1)//power):
        np.minimum(DP[(i+1)*power: (i+2)*power], DP[(i)*power: (i+1)*power] + cost, DP[(i+1)*power: (i+2)*power])

print(DP[h:].min())

Fixed submission:
import sys
input = sys.stdin.readline

max_size = 2*10**4 + 1
h, n = map(int, input().split())
DP = [float('INF')] * max_size
DP[0] = 0

for _ in range(n):
    damage, cost = map(int, input().split())
    for idx in range(damage, max_size):
        DP[idx] = min(DP[idx], DP[idx-damage] + cost)

print(min(DP[h:]))

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np


max_size = 2 * 10**4
h, n = map(int, input().split())
DP = np.ones(max_size, dtype=np.int64) * 10**9
DP[0] = 0

for _ in range(n):
    power, cost = map(int, input().split())
    for i in range((h+power-1)//power):
        DP[(i+1)*power: (i+2)*power] = np.minimum(DP[(i+1)*power: (i+2)*power], DP[(i)*power: (i+1)*power] + cost)

print(DP[h:].min())


Fixed submission:
import sys
input = sys.stdin.readline

max_size = 2*10**4 + 1
h, n = map(int, input().split())
DP = [float('INF')] * max_size
DP[0] = 0

for _ in range(n):
    damage, cost = map(int, input().split())
    for idx in range(damage, max_size):
        DP[idx] = min(DP[idx], DP[idx-damage] + cost)

print(min(DP[h:]))

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

max_size = 2*10**4 + 1
h, n = map(int, input().split())
DP = [float('INF')] * max_size
DP[0] = 0

for _ in range(n):
    damage, cost = map(int, input().split())
    for idx in range(damage, max_size):
        DP[idx] = min(DP[idx], DP[idx-damage] + cost)

print(min(DP[h:]))


Fixed submission:
import sys
input = sys.stdin.readline

max_size = 2*10**4 + 1
h, n = map(int, input().split())
DP = [float('INF')] * max_size
DP[0] = 0

for _ in range(n):
    damage, cost = map(int, input().split())
    for idx in range(damage, max_size):
        DP[idx] = min(DP[idx], DP[idx-damage] + cost)

print(min(DP[h:]))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

res = []
# 0 = A , 1 = B
for bit in range(2 ** n):
    if str(bin(bit)).count('1') % 2 == 1:
        continue

    odds = []
    evens = []
    for i in range(n):
        if (bit >> i) & 1:
            card = B[i]
            check = (i + 1) % 2

        else:
            card = A[i]
            check = i % 2

        if check == 1:
            odds.append([card, i+1])
        else:
            evens.append([card, i+1])

    if 0 <= len(evens) - len(odds) <= 1:
        odds.sort(reverse=True)
        evens.sort(reverse=True)
        now = 0
        pattern = []
        for _ in range(len(evens)):
            num1, idx1 = evens.pop()

            if now <= num1:
                now = num1
                pattern.append(idx1)
                if odds:
                    num2, idx2 = odds.pop()
                    if now <= num2:
                        now = num2
                        pattern.append(idx2)
                    else:
                        break

            else:
                break
        else:
            res.append(pattern)


if not res:
    print(-1)
    exit()

ans = []
for pattern in res:
    count = 0
    for i in range(n-1):
        num = pattern[i]
        check = pattern[i+1:]
        for t in check:
            if t < num:
                count += 1

    ans.append(count)

print(min(ans))

Fixed submission:
n = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

res = []
# 0 = A , 1 = B
for bit in range(2 ** n):
    if str(bin(bit)).count('1') % 2 == 1:
        continue

    odds = []
    evens = []
    for i in range(n):
        if (bit >> i) & 1:
            card = B[i]
            check = (i + 1) % 2

        else:
            card = A[i]
            check = i % 2

        if check == 1:
            odds.append([card, i+1])
        else:
            evens.append([card, i+1])

    if 0 <= len(evens) - len(odds) <= 1:
        odds.sort(reverse=True)
        evens.sort(reverse=True)
        now = 0
        pattern = []
        for _ in range(len(evens)):
            num1, idx1 = evens.pop()

            if now <= num1:
                now = num1
                pattern.append(idx1)
                if odds:
                    num2, idx2 = odds.pop()
                    if now <= num2:
                        now = num2
                        pattern.append(idx2)
                    else:
                        break

            else:
                break
        else:
            res.append(pattern)


if not res:
    print(-1)
    exit()

ans = []
for pattern in res:
    count = 0
    for i in range(n-1):
        num = pattern[i]
        check = pattern[i+1:]
        for t in check:
            if t < num:
                count += 1

    ans.append(count)

print(min(ans))