Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p03615 (python)

Fixed submission:
import sys
from collections import defaultdict

# sys.stdin = open('e1.in')


def read_int_list():
    return list(map(int, input().split()))


def read_int():
    return int(input())


def read_str_list():
    return input().split()


def read_str():
    return input()


def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


def solve():
    def collinear(x0, y0, x1, y1):
        return x0 * y1 == x1 * y0

    def aligned(i, j, k):
        return collinear(x[j] - x[i], y[j] - y[i], x[k] - x[i], y[k] - y[i])

    n = read_int()
    mod = 998244353
    res = pow(2, n, mod) - n - 1
    x, y = zip(*[read_int_list() for i in range(n)])
    lines = defaultdict(set)
    for i in range(n):
        for j in range(i + 1, n):
            a = y[i] - y[j]
            b = x[j] - x[i]
            g = gcd(a, b)
            a //= g
            b //= g
            if a < 0 or (a == 0 and b < 0):
                a, b = -a, -b
            c = -(a * x[i] + b * y[i])
            lines[(a, b, c)].add(i)
            lines[(a, b, c)].add(j)
    for k, v in lines.items():
        m = len(v)
        res -= pow(2, m, mod) - m - 1
    res %= mod
    return res


def main():
    res = solve()
    print(res)


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
4
0 0
0 1
1 0
1 1
Problem p03661 (python)

Fixed submission:
import sys

# sys.stdin = open('c1.in')


def read_int_list():
    return list(map(int, input().split()))


def read_int():
    return int(input())


def read_str_list():
    return input().split()


def read_str():
    return input()


def solve():
    n = read_int()
    a = read_int_list()
    res = 2 * 10 ** 10
    x = 0
    y = sum(a)
    for i in range(n - 1):
        x += a[i]
        y -= a[i]
        d = abs(x-y)
        if res > d:
            res = d
    return res


def main():
    res = solve()
    print(res)


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
import sys

# sys.stdin = open('a1.in')


def read_int_list():
    return list(map(int, input().split()))
import sys

# sys.stdin = open('a1.in')


def read_int_list():
    return list(map(int, input().split()))


def read_int():
    return int(input())


def read_str_list():
    return input().split()


def read_str():
    return input()


def solve():
    n = read_int()
    a = sorted(read_int_list())
    res = 2 * 10 ** 10
    for i in range(n):
        d = a[i+1] - a[i]
        if res > d:
            res = d
    return res


def main():
    res = solve()
    print(res)


if __name__ == '__main__':
    main()


def read_int():
    return int(input())


def read_str_list():
    return input().split()


def read_str():
    return input()


def solve():
    n = read_int()
    a = sorted(read_int_list())
    res = 2 * 10 ** 10
    for i in range(n):
        d = a[i+1] - a[i]
        if res > d:
            res = d
    return res


def main():
    res = solve()
    print(res)


if __name__ == '__main__':
    main()
Problem p03688 (python)

Fixed submission:
import sys
from collections import Counter

# sys.stdin = open('b1.in')


def read_int_list():
    return list(map(int, input().split()))


def read_int():
    return int(input())


def read_str_list():
    return input().split()


def read_str():
    return input()


yes, no = 'Yes', 'No'


def solve(n, a):
    s = set(a)
    c = Counter(a)
    if len(s) == 1:
        a = list(s)[0]
        n_colors = a + 1
        if n_colors == n:
            return yes
        n_colors = a
        if 2 * n_colors <= n:
            return yes
    if len(s) == 2:
        a, b = sorted(s)
        if a + 1 == b:
            n_colors = b
            appear_once = c[a]
            appear_twice_or_more = n_colors - appear_once
            if appear_once < n_colors:
                if c[b] >= 2 * appear_twice_or_more:
                    return yes
    return no

n = read_int()
a = read_int_list()
res = solve(n, a)
print(res)

Buggy submission (verdict: Runtime Error):
import sys
from collections import Counter

sys.stdin = open('b1.in')


def read_int_list():
    return list(map(int, input().split()))


def read_int():
    return int(input())


def read_str_list():
    return input().split()


def read_str():
    return input()


yes, no = 'Yes', 'No'


def solve(n, a):
    s = set(a)
    c = Counter(a)
    if len(s) == 1:
        a = list(s)[0]
        n_colors = a + 1
        if n_colors == n:
            return yes
        n_colors = a
        if 2 * n_colors <= n:
            return yes
    if len(s) == 2:
        a, b = sorted(s)
        if a + 1 == b:
            n_colors = b
            appear_once = c[a]
            appear_twice_or_more = n_colors - appear_once
            if appear_once < n_colors:
                if c[b] >= 2 * appear_twice_or_more:
                    return yes
    return no

n = read_int()
a = read_int_list()
res = solve(n, a)
print(res)
Problem p03689 (python)

Fixed submission:
import sys

# sys.stdin = open('c1.in')


def read_int_list():
    return list(map(int, input().split()))


def read_int():
    return int(input())


def read_str_list():
    return input().split()


def read_str():
    return input()


H, W, h, w = read_int_list()


def solve(H, W, h, w):
    if H % h == 0 and W % w == 0:
        return False, None
    a = [[0] * W for _ in range(H)]
    m = 10 ** 9 - 1
    M = m + 1
    for i in range(0, H, h):
        for j in range(0, W, w):
            a[i][j] = m
    for i in range(h - 1, H, h):
        for j in range(w - 1, W, w):
            a[i][j] = -M
    return True, a


possible, res = solve(H, W, h, w)
if possible:
    print('Yes')
    for row in res:
        print(' '.join(map(str, row)))
else:
    print('No')

Buggy submission (verdict: Runtime Error):
import sys

sys.stdin = open('c1.in')


def read_int_list():
    return list(map(int, input().split()))


def read_int():
    return int(input())


def read_str_list():
    return input().split()


def read_str():
    return input()


H, W, h, w = read_int_list()


def solve(H, W, h, w):
    if H % h == 0 and W % w == 0:
        return False, None
    a = [[0] * W for _ in range(H)]
    m = 10 ** 9 - 1
    M = m + 1
    for i in range(H, h):
        for j in range(W, w):
            a[i][j] = m
    for i in range(h - 1, H, h):
        for j in range(w - 1, W, w):
            a[i][j] = -M

    return True, a


possible, res = solve(H, W, h, w)
if possible:
    print('Yes')
    for row in res:
        print(' '.join(map(str, row)))
else:
    print('No')
Problem p03722 (python)

Fixed submission:
import sys

# sys.stdin = open('d1.in')

inf = 10 ** 20


def solve(n, m, weights):
    score = [-inf] * n
    score[0] = 0
    pred = [-1] * n

    for step in range(n):
        for edge, c in weights.items():
            a, b = edge
            if score[b] < score[a] + c:
                score[b] = score[a] + c
                pred[b] = a

    b = n - 1
    while b != 0:
        a = pred[b]
        c = weights[(a, b)]
        if score[b] < score[a] + c:
            return 'inf'
        b = a
    return score[n-1]


def solve2(n, m, weights):
    score = [-inf] * n
    score[0] = 0
    pred = [-1] * n

    for step in range(n):
        for edge, c in weights.items():
            a, b = edge
            if score[b] < score[a] + c:
                score[b] = score[a] + c
                pred[b] = a

    res = score[n-1]

    for step in range(n):
        for edge, c in weights.items():
            a, b = edge
            if score[b] < score[a] + c:
                score[b] = score[a] + c
                pred[b] = a

    if res < score[n-1]:
        return 'inf'
    return res


def main():
    n, m = map(int, input().split())
    weights = {}
    for _ in range(m):
        a, b, c = map(int, input().split())
        a -= 1
        b -= 1
        weights[(a, b)] = c

    res = solve(n, m, weights)
    print(res)

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
import sys

sys.stdin = open('d1.in')

inf = 10 ** 20


def solve(n, m, weights):
    score = [-inf] * n
    score[0] = 0
    pred = [-1] * n

    for step in range(n):
        for edge, c in weights.items():
            a, b = edge
            if score[b] < score[a] + c:
                score[b] = score[a] + c
                pred[b] = a

    b = n - 1
    while b != 0:
        a = pred[b]
        c = weights[(a, b)]
        if score[b] < score[a] + c:
            return 'inf'
        b = a
    return score[n-1]


def solve2(n, m, weights):
    score = [-inf] * n
    score[0] = 0
    pred = [-1] * n

    for step in range(n):
        for edge, c in weights.items():
            a, b = edge
            if score[b] < score[a] + c:
                score[b] = score[a] + c
                pred[b] = a

    res = score[n-1]

    for step in range(n):
        for edge, c in weights.items():
            a, b = edge
            if score[b] < score[a] + c:
                score[b] = score[a] + c
                pred[b] = a

    if res < score[n-1]:
        return 'inf'
    return res


def main():
    n, m = map(int, input().split())
    weights = {}
    for _ in range(m):
        a, b, c = map(int, input().split())
        a -= 1
        b -= 1
        weights[(a, b)] = c

    res = solve2(n, m, weights)
    print(res)

if __name__ == '__main__':
    main()
Problem p03781 (python)

Fixed submission:
from math import sqrt

x = int(input())
n = int(sqrt(2 * x)) - 10
while not (n - 1) * n // 2 < x <= n * (n + 1) // 2:
    n += 1
print(n)

Buggy submission (verdict: Runtime Error):
import sys
sys.stdin = open('d3.in')

n, k = map(int, input().split())
a = list(map(int, input().split()))
a.sort()

prefix = [set() for _ in range(n + 1)]
# suffix = [set() for _2 in range(n + 1)]

prefix[0] = {0}
for i in range(n):
    for v in prefix[i]:
        prefix[i+1].add(v)
        if v + a[i] <= k:
            prefix[i+1].add(v + a[i])

suffix_i = {0}

# Cumulative sums
c_suffix = [[0] * (k+1) for _3 in range(n + 1)]

for j in range(k):
    c_suffix[n][j + 1] = c_suffix[n][j] + (j in suffix_i)

for i in range(n - 1, -1, -1):
    to_add = set()
    for v in suffix_i:
        if v + a[i] <= k:
            to_add.add(v + a[i])
    suffix_i.update(to_add)
    for j in range(k):
        c_suffix[i][j + 1] = c_suffix[i][j] + (j in suffix_i)


def find(i):
    if k <= a[i]:
        return 0
    for s in prefix[i]:
        start = max(0, k - a[i] - s)
        stop = k - s
        if c_suffix[i + 1][stop] - c_suffix[i + 1][start] > 0:
            return 0
    return 1


res = 0
for i in range(n):
    res += find(i)
print(res)

Buggy submission (verdict: Runtime Error):
# import sys
# sys.stdin = open('d3.in')

n, k = map(int, input().split())
a = list(map(int, input().split()))
a.sort()

prefix = [set() for _ in range(n + 1)]
suffix = [set() for _2 in range(n + 1)]

prefix[0] = {0}
for i in range(n):
    for v in prefix[i]:
        if v + a[i] <= k:
            prefix[i+1].add(v + a[i])

suffix[n] = {0}
for i in range(n - 1, -1, -1):
    suffix[i] = set(suffix[i + 1])
    for v in suffix[i + 1]:
        if v + a[i] <= k:
            suffix[i].add(v + a[i])

# Cumulative sums
c_suffix = [[0] * (k+1) for _3 in range(n + 1)]
for i in range(n + 1):
    for j in range(k):
        c_suffix[i][j + 1] = c_suffix[i][j] + (j in suffix[i])


def find(i):
    if k <= a[i]:
        return 0
    for s in prefix[i]:
        start = max(0, k - a[i] - s)
        stop = k - s
        if c_suffix[i + 1][stop] - c_suffix[i + 1][start] > 0:
            return 0
    return 1


res = 0
for i in range(n):
    res += find(i)
print(res)
Problem p03079 (python)

Fixed submission:
A, B, C = map(int, input().split())
# max_ABC = max(A, max(B, C))
# rest = (A + B + C) - max_ABC

if A == B and B == C:
    print('Yes')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
import itertools
N, X = map(int, input().split())
S = list(map(int, input().split()))
ans = 0

for tpl in itertools.permutations(S):
    x = X
    if 1 in tpl:
        continue

    for y in tpl:
        x = x % y
        if x == 0 or x == 1:
            break
    ans += x
print(ans % (10**9 + 7))
Problem p02705 (python)

Fixed submission:
import math

radius = int(input())

print(2 * math.pi * radius)

Buggy submission (verdict: Runtime Error):
import math
radius = int(input())

print(2 * math.pi * radius
Problem p03434 (python)

Fixed submission:
n = int(input())
a = sorted(list(map(int, input().split())), reverse=True)
print(sum(a[::2]) - sum(a[1::2]))

Buggy submission (verdict: Runtime Error):
n = int(input())
a = sorted(list(map(int, input().split())), reverse=True)
print(sum(a[::2]) - sum(a[1::2])))
Problem p03457 (python)

Fixed submission:
n = int(input())

for i in range(n):
    t, x, y = map(int, input().split())
    if (x+y) > t or (x+y+t) % 2:
        print("No")
        exit()
print("Yes")

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

for i in range(n):
    t, x, y = map(int, input().split())
    if x+y > t or x+y+t % 2:
        print("NO")
        exit()
print("YES")
Problem p03469 (python)

Fixed submission:
print(input().replace("2017", "2018"))

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

d = []
for i in range(n):
    d.append(int(input()))

d_2 = sorted(d, reverse=True)
ans = 1
for i in range(1, n):
    if d_2[i] < d_2[i-1]:
        ans += 1
    else:
        continue

print(ans)
Problem p03478 (python)

Fixed submission:
n, a, b = map(int, input().split())
ans = 0
for i in range(n+1):
    if a <= sum(list(map(int, list(str(i))))) <= b:
        ans += i
print(ans)

Buggy submission (verdict: Runtime Error):
n, a, b = map(int, input().split())
ans = 0
 
for i in range(n+1):
  	if a <= sum(list(map(int, list(str(i))))) <= b:
      	ans += i
print(ans)
Problem p03493 (python)

Fixed submission:
print(input().count("1"))

Buggy submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
 
result = 0
les = 0
while les == 0:
  for i in range(n):
    les += a[i] % 2
    a[i] = a[i]/2
  result += 1
  
result -= 1
print(result)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = list(map(float, input().split()))
 
result = 0
les = 0
while les == 0:
  for i in range(n):
    les += a[i] % 2
    a[i] = a[i]/2
  result += 1
  
result -= 1
print(result)
Problem p03693 (python)

Fixed submission:
a, b, c = map(int, input().split())
num = 100 *a + 10*b + c
 
if num%4==0:
    print("YES")
else:
    print("NO")

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(200000)

a, b, c = map(int, input().sprit())
num = 100 *a + 10*b + c
 
if num%4==0:
    print("YES")
else:
    print("NO")

Buggy submission (verdict: Runtime Error):
a, b, c = map(int, input().sprit())
num = 100 *a + 10*b + c

if num%4==0:
    print("YES")
else:
    print("NO")
Problem p02713 (python)

Fixed submission:
import math

k = int(input())
cnt = 0
for a in range(k):
    for b in range(k):
        for c in range(k):
            cnt = cnt + math.gcd(math.gcd(a+1,b+1),c+1)
print(cnt)

Buggy submission (verdict: Runtime Error):
from fractions import gcd

k = int(input())
cnt = 0
for a in range(k):
    for b in range(k):
        for c in range(k):
            d = math.gcd(a+1,b+1)
            cnt = cnt + math.gcd(d,c+1)
print(cnt)
Problem p02706 (python)

Fixed submission:
n,m= map(int,input().split())
list = list(map(int,input().split()))
sum = 0

for i in list:
    sum += i

if sum>n:
    print("-1")
else:
    print(n-sum)

Buggy submission (verdict: Runtime Error):
n,m= input().split()
list = list(map(int,input().split()))
sum = 0

for i in list:
    sum += i

if sum>n:
    print("-1")
else:
    print(n-sum)
Problem p03000 (python)

Fixed submission:
n,x= input().split()
b_list= list(map(int, input().split()))
temp = 0
counter = 1
for i in range(int(n)):
    temp += b_list[i]
    if (temp<=int(x)):
        counter +=1
    else:
        break

print(counter)

Buggy submission (verdict: Runtime Error):
n,x= input().split()
b_list= list(map(int, input().split()))
temp = 0
counter = 0
for i in range(n):
    if (temp<=int(x)):
        counter +=1
    temp += b_list[i]

print(counter)

Buggy submission (verdict: Runtime Error):
n,x= int(input().split())
b_list= list(map(int, input().split()))
temp = 0
counter = 0
for i in b_list:
    if (temp<=x):
        counter +=1
    temp += i

print(counter)
Problem p02728 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10**6)
from collections import deque
MOD = 1000000007

N =  int(input())
childs = [[] for i in range(N+1)]
for i in range(N-1):
    a, b = map(int, input().split())
    childs[a].append(b)
    childs[b].append(a)

dp = [0] * (N + 1) # represent the # if i is the root (1)
tree_size = [0]*(N + 1)
ans = [0] * (N + 1)

n_inv = [1, 1]
n_j_mod = [1, 1]

for i in range(2, N+1):
    n_inv.append((pow(i, MOD-2, MOD) * n_inv[-1]) % MOD)
    n_j_mod.append((n_j_mod[-1] * i) % MOD)


def dfs(i, father=-1):
    method_num = 1
    t_size = 1
    for child in childs[i]:
        if child != father:
            num, size = dfs(child, i)
            method_num = (method_num * num * n_inv[size]) % MOD
            t_size += size
    method_num = (method_num * n_j_mod[t_size - 1]) % MOD
    dp[i] = method_num
    tree_size[i] = t_size
    return method_num, t_size

def rdfs(i, f_num, father=-1):
    ans[i] = (dp[i] * f_num * n_j_mod[N-1] * n_inv[N - tree_size[i]] * n_inv[tree_size[i] - 1]) % MOD

    for child in childs[i]:
        if child != father:
            cf_num = (ans[i] * n_j_mod[tree_size[child]] * n_j_mod[N - tree_size[child] - 1] * n_inv[N - 1] * pow(dp[child], MOD-2, MOD)) % MOD
            rdfs(child, cf_num, i)
dfs(1)

rdfs(1, 1)
print('\n'.join(list(map(str, ans[1:]))))

Buggy submission (verdict: Runtime Error):
from collections import deque
MOD = 1000000007

N =  int(input())
childs = [[] for i in range(N+1)]
for i in range(N-1):
    a, b = map(int, input().split())
    childs[a].append(b)
    childs[b].append(a)

dp = [0] * (N + 1) # represent the # if i is the root (1)
tree_size = [0]*(N + 1)
ans = [0] * (N + 1)

n_inv = [1, 1]
n_j_mod = [1, 1]

for i in range(2, N+1):
    n_inv.append((pow(i, MOD-2, MOD) * n_inv[-1]) % MOD)
    n_j_mod.append((n_j_mod[-1] * i) % MOD)


def dfs(i, father=-1):
    method_num = 1
    t_size = 1
    for child in childs[i]:
        if child != father:
            num, size = dfs(child, i)
            method_num = (method_num * num * n_inv[size]) % MOD
            t_size += size
    method_num = (method_num * n_j_mod[t_size - 1]) % MOD
    dp[i] = method_num
    tree_size[i] = t_size
    return method_num, t_size

def rdfs(i, f_num, father=-1):
    ans[i] = (dp[i] * f_num * n_j_mod[N-1] * n_inv[N - tree_size[i]] * n_inv[tree_size[i] - 1]) % MOD

    for child in childs[i]:
        if child != father:
            cf_num = (ans[i] * n_j_mod[tree_size[child]] * n_j_mod[N - tree_size[child] - 1] * n_inv[N - 1] * pow(dp[child], MOD-2, MOD)) % MOD
            rdfs(child, cf_num, i)
dfs(1)

rdfs(1, 1)
print('\n'.join(list(map(str, ans[1:]))))
Problem p02732 (python)

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

num_count = {}
for num in nums:
    num_count[num] = num_count.get(num, 0) + 1

total = 0
for num, ele in num_count.items():
    total += (ele * (ele - 1)) // 2

ans = []

for num in nums:
    ans.append(total - num_count[num] + 1)
print("\n".join(list(map(str, ans))))

Buggy submission (verdict: Runtime Error):
def check_block(comb, K):
    block = 0
    pre = (comb & 1) > 0
    mapping = {0: 0}
    cut_num = 0
    for i in range(1, K):
        cur = ((1 << i) & comb) > 0
        if pre != cur:
            block += 1
            pre = cur
            cut_num += 1
        mapping[i] = block
    return mapping, cut_num

H, W, K = map(int, input().split())
graph = [input() for ele in range(H)]
#
ans = 1319203291031903
for comb in range(1<<(H-1)):
    mapping, cut_num = check_block(comb, K)
    pre = [0] * (cut_num + 1)
    gg = False
    # preprocess 
    for j in range(H):
        pre[mapping[j]] += (graph[j][0] == '1')
    for ele in pre:
        if ele > K:
            gg = True
            break
    if gg: continue

    for i in range(1, W):
        cum = pre[:]
        for j in range(H):
            cum[mapping[j]] += (graph[j][i] == '1')
        for ii in range(len(cum)):
            if cum[ii] - pre[ii] > K:
                gg = True
                break
            if cum[ii] > K:
                cut_num += 1
                for idx in range(len(cum)):
                    cum[idx] -= pre[idx]
                break
        pre = cum
        if gg: break

    if not gg:
        ans = min(ans, cut_num)
print(ans)
Problem p03061 (python)

Fixed submission:
def gcd(a, b):
    while b:
        a %= b
        a, b = b, a
    return a


n = int(input())
nums = list(map(int, input().split()))

prefix_gcd = []

prefix_gcd.append(nums[0])

for i in nums[1:]:
    prefix_gcd.append(gcd(i,prefix_gcd[-1]))

postfix_gcd = []
postfix_gcd.append(nums[-1])

for j in range(n-2,-1,-1):
    postfix_gcd.append(gcd(nums[j],postfix_gcd[-1]))

postfix_gcd = postfix_gcd[::-1]

ans = 1

for i in range(n):
    # del i
    if i == 0:
        ans = max(ans,postfix_gcd[i+1])
    elif i == n-1:
        ans = max(ans,prefix_gcd[i-1])
    else:
        ans = max(ans, gcd(prefix_gcd[i-1], postfix_gcd[i+1]))
print(ans)

Buggy submission (verdict: Runtime Error):
from math import gcd
n = int(input())
nums = list(map(int, input().split()))

prefix_gcd = []

prefix_gcd.append(nums[0])

for i in nums[1:]:
    prefix_gcd.append(gcd(i,prefix_gcd[-1]))

postfix_gcd = []
postfix_gcd.append(nums[-1])

for j in range(n-2,-1,-1):
    postfix_gcd.append(gcd(nums[j],postfix_gcd[-1]))

postfix_gcd = postfix_gcd[::-1]

ans = 1

for i in range(n):
    # del i
    if i == 0:
        ans = max(ans,postfix_gcd[i+1])
    elif i == n-1:
        ans = max(ans,prefix_gcd[i-1])
    else:
        ans = max(ans, gcd(prefix_gcd[i-1], postfix_gcd[i+1]))
print(ans)
Problem p02705 (python)

Fixed submission:
import numpy as np

R = int(input())

print(2 * R *np.pi)

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

R = int(input())

print(2 * R *np.pi)
Problem p02706 (python)

Fixed submission:
N, M = map(int, input().split())
A = list(map(int,input().split()))

need_day = sum(A)

if N < need_day:
    print(-1)
else:
    print(N-need_day)

Buggy submission (verdict: Runtime Error):
import sys

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

A = []
for l in sys.stdin:
    A.append(int(l))
    
need_day = sum(A)
    
if N < need_day:
    print(-1)
else:
    print(N-need_day)