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

Fixed submission:
N = int(input())
XY = [list(map(int, input().split())) for _ in range(N)]

min_diff = 10**9
max_diff = -10**9
min_sum = 2 * 10**9
max_sum = 2

for x,y in XY:
    min_diff = min(x-y, min_diff)
    max_diff = max(x-y, max_diff)
    min_sum = min(x+y, min_sum)
    max_sum = max(x+y, max_sum)

print(max(max_sum-min_sum, max_diff-min_diff))

Buggy submission (verdict: Runtime Error):
from itertools import combinations
import sys

N = int(input())
XY = [list(map(int, input().split())) for _ in range(N)]

min_diff = 10**9
max_diff = 1
min_sum = 2 * 10**9
max_sum = 2

for x,y in XY:
    min_diff = min(x-y, min_diff)
    max_diff = max(x-y, max_diff)
    min_sum = min(x+y, min_sum)
    max_sum = max(x+y, max_sum)

cand_set = set()
for x,y in XY:
    if x-y in (min_diff, max_diff) or x+y in (min_sum, max_sum):
        cand_set.add((x, y))

if len(cand_set) == N:
    print(max(max_sum-min_sum, mad_diff - min_diff))
    sys.exit()

dist = 0
for p1, p2 in combinations(cand_set, 2):
    dist = max(dist, abs(p1[0]-p2[0]) + abs(p1[1]-p2[1]))
    
print(dist)

Buggy submission (verdict: Runtime Error):
from itertools import combinations

N = int(input())
XY = [list(map(int, input().split())) for _ in range(N)]

min_diff = 10**9
max_diff = 1
min_sum = 2 * 10**9
max_sum = 2

for x,y in XY:
    min_diff = min(x-y, min_x)
    max_diff = max(x-y, max_x)
    min_sum = min(x+y, min_sum)
    max_sum = max(x+y, max_sum)

cand_set = set()
for x,y in XY:
    if x-y in (min_diff, max_diff) or x+y in (min_sum, max_sum):
        cand_set.add((x, y))

dist = 0
for p1, p2 in combinations(cand_set, 2):
    print(p1, p2)
    dist = max(dist, abs(p1[0]-p2[0]) + abs(p1[1]-p2[1]))
    
print(dist)
Problem p02609 (python)

Fixed submission:
def popcount(n):
    return bin(n).count('1')


def main():
    N = int(input())
    X = input()

    X_int = int(X, 2)

    pcount_X = popcount(X_int)

    pcount_X_pls1 = pcount_X + 1
    pcount_X_mns1 = pcount_X - 1
    
    X_mod_pcount_X_pls1 = X_int % pcount_X_pls1
    if pcount_X_mns1 != 0:
        X_mod_pcount_X_mns1 = X_int % pcount_X_mns1

    for i,bit in enumerate(X):
        bit = int(bit)
        if bit == 0:
            n = (X_mod_pcount_X_pls1 + pow(2, N-i-1, pcount_X_pls1)) % pcount_X_pls1
        else:
            if pcount_X_mns1 == 0:
                print(0)
                continue
            n = (X_mod_pcount_X_mns1 - pow(2, N-i-1, pcount_X_mns1)) % pcount_X_mns1

        ans = 1
        while n > 0:
            ans += 1
            n %= popcount(n)
        print(ans)
        
main()

Buggy submission (verdict: Runtime Error):
def popcount(n):
    return bin(n).count('1')


def main():
    N = int(input())
    X = input()

    X_int = int(X, 2)

    pcount_X = popcount(X_int)

    pcount_X_pls1 = pcount_X + 1
    pcount_X_mns1 = pcount_X - 1
    
    X_pls1_mod = X_int % pcount_X_pls1
    X_mns1_mod = X_int % pcount_X_mns1

    for i,bit in enumerate(X):
        bit = int(bit)
        if bit == 0:
            pcount_Xi = pcount_X_pls1
        else:
            pcount_Xi = pcount_X_mns1
            if pcount_Xi == 0:
                print(0)
                continue

        if bit == 0:
            n = (X_pls1_mod + pow(2, N-i-1, pcount_Xi)) % pcount_Xi
        else:
            n = (X_mns1_mod - pow(2, N-i-1, pcount_Xi)) % pcount_Xi

        ans = 1
        while n > 0:
            ans += 1
            n %= popcount(n)
        print(ans)
        
main()

Buggy submission (verdict: Runtime Error):
def popcount(x):
    x = x - ((x >> 1) & 0x5555555555555555)

    x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)

    x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f
    x = x + (x >> 8)
    x = x + (x >> 16)
    x = x + (x >> 32)
    return x & 0x0000007f


N = int(input())
X = input()

X_int = int(X, 2)

for i in range(N):
    mask = ['0']*N
    mask[i] = '1'
    mask = int(''.join(mask), 2)
    Xi = X_int ^ mask
    
    n = Xi
    ans = 0
    while n > 0:
        ans += 1
        n %= popcount(n)
    print(ans)
Problem p02641 (python)

Fixed submission:
import sys

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

if N == 0:
    print(X)
    sys.exit()

p_set = set(P)

if not (X in p_set):
    print(X)
    sys.exit()

for i in range(1, 100):
    if not (X-i in p_set):
        print(X-i)
        break
    if not (X+i in p_set):
        print(X+i)
        break

Buggy submission (verdict: Runtime Error):
X, N = map(int, input().split())
P = list(map(int, input().split()))

if N == 0:
    print(X)
    sys.exit()

p_set = set(P)

if not (X in p_set):
    print(X)
    sys.exit()

for i in range(1, 100):
    if not (X-i in p_set):
        print(X-i)
        break
    if not (X+i in p_set):
        print(X+i)
        break
Problem p02658 (python)

Fixed submission:
import sys

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

if 0 in A:
    print(0)
    sys.exit();

ans = 1
for a in sorted(A, reverse=True):
    ans *= a
    if ans > 10**18:
        print(-1)
        break
else:
    print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = [list(map(int, input().split())) for _ in range(N)]
ans = 1
for a in A:
    ans *= a
if ans > 10**18:
    print(-1)
else:
    print(ans)
Problem p02660 (python)

Fixed submission:
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

def main():
    import sys
    N = int(input())
    fact = factorization(N)
    if fact[0][0] == 1:
        print(0)
        sys.exit()
    ans = 0
    for f, num in fact:
        for i in range(1, num+1):
            if num < i:
                break
            num -= i
            ans += 1
    print(ans)
main()

Buggy submission (verdict: Runtime Error):
import sys
N = int(input())
fact = factorization(N)
if fact[0][0] == 1:
    print(0)
    sys.exit()
ans = 0
for f, num in fact:
    for i in range(1, num+1):
        if num < i:
            break
        num -= i
        ans += 1
print(ans)

Buggy submission (verdict: Runtime Error):
import sys
N = int(input())
fact = factorization(N)
if fact[0][0] == 1:
    print(0)
    sys.exit()
print(fact)
ans = 0
for f, num in fact:
    print(f'{f=}, {num=}')
    for i in range(1, num+1):
        print(f'{i=}')
        if num < i:
            break
        num -= i
        ans += 1
print(ans)
Problem p02936 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10**7)

def input():
    return sys.stdin.readline()[:-1]

def dfs(now, parent, total):
    result[now] = total + counter[now]
    for child in tree[now]:
        if child == parent:
            continue
        dfs(child, now, result[now])

N, Q = map(int, input().split())
edge = [list(map(int, input().split())) for _ in range(N-1)]
P = [list(map(int, input().split())) for _ in range(Q)]

tree = [[] for _ in range(N+1)]
counter = [0 for _ in range(N+1)]

for a,b in edge:
    tree[a].append(b)
    tree[b].append(a)

for p,x in P:
    counter[p] += x

result = [0]*(N+1)
dfs(1, 0, 0)

print(' '.join(map(str, result[1:])))

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**7)

def input():
    return sys.stdin.readline()[:-1]

def dfs(now, parent, total):
    result[now] = total + counter[now]
    for child in tree[now]:
        if child == parent:
            continue
        dfs(child, result[now])

        
N, Q = map(int, input().split())
edge = [list(map(int, input().split())) for _ in range(N-1)]
P = [list(map(int, input().split())) for _ in range(Q)]

tree = [[] for _ in range(N+1)]
counter = [0 for _ in range(N+1)]

for a,b in edge:
    tree[a].append(b)
    tree[b].append(a)

for p,x in P:
    counter[p] += x

result = [0]*(N+1)
dfs(1, 0, 0)

print(' '.join(map(str, result[1:])))
Problem p02947 (python)

Fixed submission:
def nC2(n):
    if n < 2:
        return 0
    return n * (n-1) // 2

def main():
    N = int(input())
    S = [''.join(sorted(input())) for _ in range(N)]
    counter = {}
    for s in S:
        if s in counter:
            counter[s] += 1
        else:
            counter[s] = 1
    ans = sum([nC2(v) for v in counter.values()])
    print(ans)

main()

Buggy submission (verdict: Runtime Error):
def nC2(n):
    x = 1
    for i in range(2, n+1):
        x *= i
    return x//2

def main():
    N = int(input())
    S = [sorted(input()) for _ in range(N)]
    counter = {}
    for s in S:
        if s in counter:
            counter[s] += 1
        else:
            counter[s] = 1
    ans = sum([nC2(v) for v in counter.values()])
    print(ans)

main()
Problem p02995 (python)

Fixed submission:
from fractions import gcd

A, B, C, D = map(int, input().split())
A -= 1
lcm = int(C*D / gcd(C, D))
nA = A - (A//C + A//D - A//lcm)  
nB = B - (B//C + B//D - B//lcm)
print(nB - nA)

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

lcm = int(C*D / gcd(C, D))
nA = A - (int(A/C) + int(A/D) - int(A/lcm))  
nB = B - (int(B/C) + int(B/D) - int(B/lcm))
print(nB - nA)
Problem p03044 (python)

Fixed submission:
import sys
sys.setrecursionlimit(100000)

class Graph():
    def __init__(self):
        self.adjacency_dict = {}

    def add_vertex(self, v):
        self.adjacency_dict[v] = []
    
    def add_edge(self, v1, v2, dist):
        self.adjacency_dict[v1].append([v2, dist])
        self.adjacency_dict[v2].append([v1, dist])
    
    def next_edges(self, v):
        return self.adjacency_dict[v]

N = int(input())
dists = [list(map(int, input().split())) for _ in range(N-1)]

graph = Graph()
for i in range(1, N+1):
    graph.add_vertex(i)
for v1, v2, dist in dists:
    graph.add_edge(v1, v2, dist)

def dfs(start, group):
    if visited[start] is not None:
        return
    visited[start] = group
    for v, dist in graph.next_edges(start):
        if dist % 2 == 0:
            dfs(v, group)
        else:
            dfs(v, 1-group)

visited = [None]*(N+1)
dfs(1, 0)
for i in visited[1:]:
    print(i)

Buggy submission (verdict: Runtime Error):
class Graph():
    def __init__(self):
        self.adjacency_dict = {}

    def add_vertex(self, v):
        self.adjacency_dict[v] = []
    
    def add_edge(self, v1, v2, dist):
        self.adjacency_dict[v1].append([v2, dist])
        self.adjacency_dict[v2].append([v1, dist])
    
    def next_edges(self, v):
        return self.adjacency_dict[v]

    def __str__(self):
        return self.adjacency_dict.__str__()
      
N = int(input())
dists = [list(map(int, input().split())) for _ in range(N-1)]

graph = Graph()
for i in range(1, N+1):
    graph.add_vertex(i)
for v1, v2, dist in dists:
    graph.add_edge(v1, v2, dist)
    
def dfs(start, group):
    if visited[start] is not None:
        return
    visited[start] = group
    for v, dist in graph.next_edges(start):
        if dist % 2 == 0:
            dfs(v, group)
        else:
            dfs(v, 1-group)

visited = [None]*(N+1)
dfs(1, 0)

for i in visited[1:]:
  print(i)
Problem p02675 (python)

Fixed submission:
class ATherefore:
    def solve(self, tc=0):
        n = int(input())
        if n % 10 in [2, 4, 5, 7, 9]:
            print("hon")
        elif n % 10 in [0, 1, 6, 8]:
            print("pon")
        else:
            print("bon")


x = ATherefore()
x.solve()

Buggy submission (verdict: Runtime Error):
class ATherefore:
    def solve(self, tc=0):
        n = int(input())
        if n % 10 in [2, 4, 5, 7, 9]:
            print("hon")
        elif n % 10 in [0, 1, 6, 8]:
            print("pon")
        else:
            print("bon")

x = Atherefore()
x.solve()
Problem p02684 (python)

Fixed submission:
# @author 

import sys

class DTeleporter:
    def solve(self, tc=0):
        n, k = [int(_) for _ in input().split()]
        a = [int(_) - 1 for _ in input().split()]
        done = dict()
        cur = 0
        steps = 0
        while cur not in done and steps < k:
            done[cur] = steps
            cur = a[cur]
            steps += 1
        
        if steps == k:
            print(cur + 1)
            return

        d = steps - done[cur]
        steps = steps + ((k - steps) // d) * d

        while steps < k:
            cur = a[cur]
            steps += 1

        print(cur + 1)


solver = DTeleporter()
input = sys.stdin.readline

solver.solve()

Buggy submission (verdict: Runtime Error):
# @author 

import sys

class DTeleporter:
    def solve(self, tc=0):
        n, k = [int(_) for _ in input().split()]
        a = [int(_) - 1 for _ in input().split()]
        done = dict()
        cur = 0
        steps = 0
        while cur not in done and steps < k:
            done[cur] = steps
            cur = a[cur]
            steps += 1

        d = steps - done[cur]
        steps = steps + ((k - steps) // d) * d

        while steps < k:
            cur = a[cur]
            steps += 1

        print(cur + 1)


solver = DTeleporter()
input = sys.stdin.readline

solver.solve()
Problem p03043 (python)

Fixed submission:
from math import *

n, k = [int(item) for item in input().split()]
ans = 0
for p in range(1, n + 1):

    if p >= k:
        ans += 1;
    else:
        x = ceil(log2(k) - log2(p))
        ans += 1.0 / (1 << x);
print(ans / n)

Buggy submission (verdict: Runtime Error):
from math import *

n, k = [int(item) for item in input().split()]
ans = 0
for p in range(1, n + 1):

    if p >= k:
        ans += 1;
    else:
        x = ceil(log2(k / p))
        ans += 1.0 / (1 << x);
print(ans / n)
Problem p03050 (python)

Fixed submission:
n = int(input())

ans = 0

for i in range(1, int(n ** .5) + 1):
    if n % i == 0:
        m = n // i - 1
        if m > 0 and n % m == n // m:
            ans += m

print(ans)

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

ans = 0

for i in range(1, int(n ** .5) + 1):
    if n % i == 0:
        m = n // i - 1
        if n % m == n // m:
            ans += m

print(ans)
Problem p03060 (python)

Fixed submission:
n = int(input())
v = [int(item) for item in input().split()]
c = [int(item) for item in input().split()]

d = [[v[i], c[i]] for i in range(n)]
d.sort(key=lambda x: x[0] - x[1], reverse=True)

ans = 0
i = 0
while i < n and d[i][0] - d[i][1] > 0:
    ans += d[i][0] - d[i][1]
    i += 1

print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
v = [int(item) for item in input().split()]
c = [int(item) for item in input().split()]

d = [[v[i], c[i]] for i in range(n)]
d.sort(key=lambda x: x[0] - x[1], reverse=True)

ans = 0
i = 0
while d[i][0] - d[i][1] > 0:
    ans += d[i][0] - d[i][1]
    i += 1

print(ans)
Problem p03166 (python)

Fixed submission:
# @author 

import sys

class GLongestPath:
    def dfs(self, s):
        if self.done[s]:
            return self.dp[s]

        self.done[s] = 1

        ans = 0
        for x in self.adj[s]:
            ans = max(ans, 1 + self.dfs(x))

        self.dp[s] = ans
        return ans

    def solve(self):
        import sys
        sys.setrecursionlimit(10 ** 5 + 5)
        from collections import defaultdict
        n, m = [int(_) for _ in input().split()]
        self.adj = defaultdict(list)
        self.dp = [0] * (n + 1)
        self.done = [0] * (n + 1)
        for i in range(m):
            u, v = [int(_) for _ in input().split()]
            self.adj[u].append(v)

        ans = 0
        for i in range(1, n + 1):
            ans = max(ans, self.dfs(i))

        print(ans)

solver = GLongestPath()
input = sys.stdin.readline

solver.solve()

Buggy submission (verdict: Runtime Error):
# @author 

import sys

class GLongestPath:
    def dfs(self, s):
        if self.done[s]:
            return self.dp[s]

        self.done[s] = 1

        ans = 0
        for x in self.adj[s]:
            ans = max(ans, 1 + self.dfs(x))

        self.dp[s] = ans
        return ans

    def solve(self):
        from collections import defaultdict
        n, m = [int(_) for _ in input().split()]
        self.adj = defaultdict(list)
        self.dp = [0] * (n + 1)
        self.done = [0] * (n + 1)
        for i in range(m):
            u, v = [int(_) for _ in input().split()]
            self.adj[u].append(v)

        ans = 0
        for i in range(1, n + 1):
            ans = max(ans, self.dfs(i))

        print(ans)

solver = GLongestPath()
input = sys.stdin.readline

solver.solve()
Problem p03175 (python)

Fixed submission:
# @author 

import sys


class PIndependentSet:
    def solve(self):
        from collections import defaultdict
        import sys
        sys.setrecursionlimit(10 ** 5 + 5)
        MOD = 10 ** 9 + 7

        def dfs(s):
            done[s] = 1
            dp[s][0] = 1
            dp[s][1] = 1
            for x in adj[s]:
                if done[x]:
                    continue
                dfs(x)
                dp[s][0] = (dp[s][0] * dp[x][1]) % MOD
                dp[s][1] = (dp[s][1] * (dp[x][0] + dp[x][1])) % MOD

        n = int(input())
        adj = defaultdict(list)

        for i in range(n - 1):
            x, y = [int(_) for _ in input().split()]
            x -= 1
            y -= 1
            adj[x].append(y)
            adj[y].append(x)

        dp = [[0, 0] for _ in range(n)]
        done = [0] * n
        dfs(0)

        print((dp[0][0] + dp[0][1]) % MOD)

solver = PIndependentSet()
input = sys.stdin.readline

solver.solve()

Buggy submission (verdict: Runtime Error):
# @author 

import sys


class PIndependentSet:
    def solve(self):
        from collections import defaultdict

        MOD = 10 ** 9 + 7

        def dfs(s):
            done[s] = 1
            dp[s][0] = 1
            dp[s][1] = 1
            for x in adj[s]:
                if done[x]:
                    continue
                _in = True
                dfs(x)
                dp[s][0] = (dp[s][0] * dp[x][1]) % MOD
                dp[s][1] = (dp[s][1] * (dp[x][0] + dp[x][1])) % MOD

        n = int(input())
        adj = defaultdict(list)

        for i in range(n - 1):
            x, y = [int(_) for _ in input().split()]
            x -= 1
            y -= 1
            adj[x].append(y)
            adj[y].append(x)

        dp = [[0, 0] for _ in range(n)]
        done = [0] * n
        dfs(0)

        print(dp[0][0] + dp[0][1])

solver = PIndependentSet()
input = sys.stdin.readline

solver.solve()
Problem p02553 (python)

Fixed submission:
a,b,c,d=map(int,input().split())
ans = a*c
for i in [a,b]:
  for j in [c,d]:
    ans = max(ans, i*j)

print(ans)

Buggy submission (verdict: Runtime Error):
a,b,c,d=map(int,input().split())
ans = -10**9
for i in range([a,b]):
  for j in range([c,d]):
    ans = max(ans, i*j)

print(ans)
Problem p02642 (python)

Fixed submission:
n = int(input())
A = sorted(list(map(int, input().split())))
from collections import Counter
c = Counter(A)

dp = [1]*(max(A)+1)
#print(dp)
for i in c.keys():
    j = i*2
    while j<len(dp):
        dp[j] = 0
        j += i
        #print(j, end=',')
ans = 0
for i in c.keys():
    if c[i] == 1:
        if dp[i] == 1:
            ans += 1
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
A = list(map(int, input().split()))
from collections import Counter
c = Counter(A)
sorted_key = sorted(c.keys(),reverse=True)
res = [0]*len(sorted_key)
ans = n
#print(sorted_key)
#for i,key in enumerate(sorted_key):
for key in sorted_key:
    if c[key]>1:
        ans -= c[key]
        continue
    for j in range(len(sorted_key)-1, i, -1):
        #print(i,key,j,sorted_key[j])
        if (key/sorted_key[j]>=1) and (key%sorted_key[j])==0:
            #res[i] = 1
            ans -= c[key]
            #print('===========',)
            break

#print('res', res)
#print(c)
'''ans = 0
for i,v in enumerate(sorted_key):
    if res[i]:
        ans += c[sorted_key[i]]
    else:
        if c[v] >1:
            ans += c[sorted_key[i]]'''
print(ans)
Problem p02684 (python)

Fixed submission:
n,k = map(int, input().split())
b = list(map(int, input().split()))
a=0
for i in range(n):
    b[i] -= 1
if k<n:
    for i in range(k):
        a = b[a]
    print(a+1)
    exit()
c = [-1]*n
cc = 0
se = set()
while a not in se:
    c[a] = cc
    cc += 1
    se.add(a)
    a = b[a]
for i in range((k-c[a])%(cc-c[a])):
    a = b[a]
print(a+1)

Buggy submission (verdict: Runtime Error):
n,k = map(int,input().split())
A=list(map(int, input().split()))
now = 1
if n>=k:
    for i in k:
        now = A[now-1]
        exit()
past = [-1]*n
cnt = 0
while now not in past:
    past[cnt] = now
    now = A[now-1]
    cnt +=1
loop_size = cnt-past.index(now)
surplus = (k-past.index(now))%loop_size
for i in range(surplus):
    now = A[now-1]
print(now)

Buggy submission (verdict: Runtime Error):
n,k = map(int,input().split())
A=list(map(int, input().split()))
now = 1
if n>=k:
    for i in k:
        now = A[now-1]
        exit()
past = []
while now not in past:
    past.append(now)
    now = A[now-1]
loop_size = len(past)-past.index(now)
surplus = (k-past.index(now))%loop_size
for i in range(surplus):
    now = A[now-1]
print(now)

Buggy submission (verdict: Runtime Error):
n,k = map(int, input().split())
A = list(map(int, input().split()))
now = 1
f = 0
past = [0]*k
if n>k:
	for i in range(k):
		now = A[now-1]
	print(now)
	exit()
c = 0
for i in range(n):
	past[c] = now
	now = A[now-1]
	c+=1
	if now in past:
		f = 1
		break


loop_end = c
loop_start = past.index(now)
#print(past, now, loop_end, loop_start)
res = (k-loop_start)%(loop_end-loop_start)
now = past[loop_start]
for i in range(res):
	now = A[now-1]
print(now)

Buggy submission (verdict: Runtime Error):
n,k = map(int, input().split())
A = list(map(int, input().split()))
import collections
res = collections.deque('1')
rep = [0,0]
for i in range(n):
    print(res)
    if str(A[int(res[-1])-1]) not in res:
        res.append(str(A[int(res[-1])-1]))
    else:
        rep[0] = res.index(str(A[int(res[-1])-1]))
        rep[1] = len(res)
        break

#print(res)
#print(rep)
if k < len(res):
    print(res[k])
else:
    rep_num = rep[1] - rep[0]
    remainder = (k-rep[0])%rep_num
    print(res[rep[0] +remainder])
Problem p02706 (python)

Fixed submission:
N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
if N- sum(A) >= 0:
    print(N- sum(A))
else:
    print('-1')

Buggy submission (verdict: Runtime Error):
314 15
9 26 5 35 8 9 79 3 23 8 46 2 6 43 3
Problem p02718 (python)

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

lmt = sum(A) /(4*m)
A.sort(reverse=True)
if A[m-1] >= lmt:
  print('Yes')
else:
  print('No')

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

lmt = sum(A) /(4*m)
A.sort(reverse=True)
if A[m] >= lmt:
  print('Yes')
else:
  print('No')

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

sumA = sum(A)
lmt = sum(A) /(4*m)
#print(sumA, lmt)
A.sort(reverse=True)
if A[m] > lmt:
  print('Yes')
else:
  print('No')