Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
import collections
def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))

    c = collections.Counter(A)

    i = 0
    ans = 0
    for num, cnt in c.most_common()[::-1]:
        if i >= len(set(A)) - K:
            break
        ans += cnt
        i += 1

    print(ans)

main()

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

TMP = [0] * N

for i in A:
    TMP[i-1] += 1

filter_TMP = sorted([i for i in TMP if i > 0], reverse=True)

max_ball = 0
cnt = 1
for i in filter_TMP:
    if cnt <= K:
        max_ball += i
        cnt += 1
    else:
        break
    

print(N - max_ball)

Buggy python submission (verdict: Time Limit Exceeded):
import collections
def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))

    c = collections.Counter(A)

    i = 0
    ans = 0
    for num, cnt in c.most_common()[::-1]:
        if i >= len(set(A)) - K:
            break
        ans += cnt
        i += 1

    print(ans)

main()

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

TMP = [0] * N

for i in A:
    TMP[i-1] += 1

filter_TMP = sorted([i for i in TMP if i > 0], reverse=True)

max_ball = 0
cnt = 1
for i in filter_TMP:
    if cnt <= K:
        max_ball += i
        cnt += 1
    else:
        break
    

print(N - max_ball)

Buggy python submission (verdict: Time Limit Exceeded):
import collections

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

c = collections.Counter(A)

i = 0
ans = 0
for num, cnt in c.most_common()[::-1]:
    if i >= len(set(A)) - K:
        break
    ans += cnt
    i += 1

print(ans)

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

TMP = [0] * N

for i in A:
    TMP[i-1] += 1

filter_TMP = sorted([i for i in TMP if i > 0], reverse=True)

max_ball = 0
cnt = 1
for i in filter_TMP:
    if cnt <= K:
        max_ball += i
        cnt += 1
    else:
        break
    

print(N - max_ball)

Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
A = list(map(int, input().split()))

TMP = [0] * N

for i in A:
    TMP[i-1] += 1

filter_TMP = sorted([i for i in TMP if i > 0])

n = sum( x > 0 for x in filter_TMP)

cnt = 0
ans = 0
while n > K:
    ans += filter_TMP[cnt]
    del filter_TMP[cnt]
    cnt += 1
    n -= 1

print(ans)

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

TMP = [0] * N

for i in A:
    TMP[i-1] += 1

filter_TMP = sorted([i for i in TMP if i > 0], reverse=True)

max_ball = 0
cnt = 1
for i in filter_TMP:
    if cnt <= K:
        max_ball += i
        cnt += 1
    else:
        break
    

print(N - max_ball)
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    N, K = map(int, input().split())
    dots = []
    for _ in range(N):
        x, y = map(int, input().split())
        dots.append((x,y))

    ans = float('inf')

    for i in range(N):
        for j in range(N):
            for k in range(N):
                for l in range(N):
                    if i == j == k == l:
                        continue
                    right = max(dots[i][0],dots[j][0],dots[k][0],dots[l][0])
                    left = min(dots[i][0],dots[j][0],dots[k][0],dots[l][0])
                    bottom = min(dots[i][1],dots[j][1],dots[k][1],dots[l][1])
                    top = max(dots[i][1],dots[j][1],dots[k][1],dots[l][1])

                    cnt = 0
                    for x, y in dots:
                        if left <= x <= right and bottom <= y <= top:
                            cnt += 1

                    if cnt >= K:
                        ans = min(ans, (top - bottom) * (right - left))
    print(ans)



if __name__ == "__main__":
    main()

Fixed submission:
def main():
    N, K = map(int, input().split())
    x = [0] * N
    y = [0] * N

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

    ans = float('inf')
    for i in range(N):
        for j in range(N):
            for k in range(N):
                for l in range(N):
                    if x[i] < x[j] and y[k] < y[l]:
                        cnt = 0
                        lx = x[i]
                        rx = x[j]
                        by = y[k]
                        uy = y[l]

                        for n in range(N):
                            if lx <= x[n] and x[n] <= rx and by <= y[n] and y[n] <= uy:
                                cnt += 1

                        if cnt >= K:
                            ans = min(ans, (rx - lx) * (uy - by))

    print(ans)

main()
Buggy python submission (verdict: Time Limit Exceeded):
from fractions import Fraction

def main():
    N = int(input())
    a = Fraction(4, N)
    ans = [0,0,0]
    for h in range(N//2,3501):
        b = Fraction(1, h)
        for n in range(N//2,3501):
            c = Fraction(1,n)
            d = a - b - c
            if d > 0 and d.numerator == 1:
                print(h, n, d.denominator)
                exit()






if __name__ == "__main__":
    main()

Fixed submission:

def main():
    N = int(input())
    for h in range(1,3501):
        for n in range(1,3501):
            if 4 * h * n - N * n - N * h == 0:
                continue
            w = (N * h * n) / (4 * h * n - N * n - N * h)
            if w > 0 and w.is_integer():
                print(h,n,int(w))
                exit()




if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = [int(input()) for i in range(N)]
A = sorted(A)
set_A = set(A)
ans = 0

for a in set_A:
    if A.count(a) % 2 == 1:
        ans += 1

print(ans)

Fixed submission:
# 要素であるかの確認は配列じゃなくsetを使う
# setはハッシュで実装されているため

N = int(input())
s = set()
 
for i in range(N):
    a=int(input())
    if a in s:
        s.remove(a)
    else:
        s.add(a)
 
print(len(s))

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = [int(input()) for i in range(N)]

B = []

for a in A:
    if a in B:
        B.remove(a)
    else:
        B.append(a)

print(len(B))

Fixed submission:
# 要素であるかの確認は配列じゃなくsetを使う
# setはハッシュで実装されているため

N = int(input())
s = set()
 
for i in range(N):
    a=int(input())
    if a in s:
        s.remove(a)
    else:
        s.add(a)
 
print(len(s))
Buggy python submission (verdict: Runtime Error):
X, t = map(int, input().spilt())

if X - t > 0:
    print(X - t)
else:
    print(0)

Fixed submission:
X, t = map(int, input().split())

if X - t > 0:
    print(X - t)
else:
    print(0)
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    N = int(input())
    a = list(map(int, input().split()))

    cnt = 0

    for i in range(min(a),max(a)+1):
        cnt = max(cnt,a.count(i-1)+a.count(i)+a.count(i+1))
    
    print(cnt)

main()

Fixed submission:
# 辞書を用意して最大値を取得する

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

cnt = {}

for i in a:
    for j in [-1,0,1]:
        cnt.setdefault(i+j, 0)
        cnt[i+j] += 1

print(max(cnt.values()))

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    N = int(input())
    a = list(map(int, input().split()))

    cnt = 0

    for i in range(min(a),max(a)+1):
        cnt = max(cnt,a.count(i-1)+a.count(i)+a.count(i+1))
    
    print(cnt)

main()

Fixed submission:
# 辞書を用意して最大値を取得する

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

cnt = {}

for i in a:
    for j in [-1,0,1]:
        cnt.setdefault(i+j, 0)
        cnt[i+j] += 1

print(max(cnt.values()))

Buggy python submission (verdict: Runtime Error):
# 空の配列を用意して各要素の-1,0,+1を試して
# 値のインデックスに+1して最大値をとる

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

cnt = [0] * 100000

for i in a:
    for j in [-1,0,1]:
        cnt[i+j] += 1

print(max(cnt))

Fixed submission:
# 辞書を用意して最大値を取得する

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

cnt = {}

for i in a:
    for j in [-1,0,1]:
        cnt.setdefault(i+j, 0)
        cnt[i+j] += 1

print(max(cnt.values()))

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
a = list(map(int, input().split()))

cnt = 0
X = []

for k in a:
    X.append(k+1)
    X.append(k)
    X.append(k-1)

for i in X:
    tmplist = []
    for j in a:
        tmplist.append(i-j)
        if cnt < tmplist.count(1) + tmplist.count(0) + tmplist.count(-1):
            cnt = tmplist.count(1) + tmplist.count(0) + tmplist.count(-1)

print(cnt)

Fixed submission:
# 辞書を用意して最大値を取得する

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

cnt = {}

for i in a:
    for j in [-1,0,1]:
        cnt.setdefault(i+j, 0)
        cnt[i+j] += 1

print(max(cnt.values()))

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
a = list(map(int, input().split()))

cnt = 0

for i in range(min(a)-1, max(a)+2):
    tmplist = []
    for j in a:
        tmplist.append(i-j)
        if cnt < tmplist.count(1) + tmplist.count(0) + tmplist.count(-1):
            cnt = tmplist.count(1) + tmplist.count(0) + tmplist.count(-1)

print(cnt)

Fixed submission:
# 辞書を用意して最大値を取得する

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

cnt = {}

for i in a:
    for j in [-1,0,1]:
        cnt.setdefault(i+j, 0)
        cnt[i+j] += 1

print(max(cnt.values()))
Buggy python submission (verdict: Runtime Error):
def main():
    N = int(input())
    P = list(map(int, input().split()))    
    cnt = 0
    i = 0
    while i < N:
        if i + 1 == P[i]:
            if i + 2 == P[i+1]:
                cnt += 1
                i += 2
            else:
                cnt += 1
                i += 1
        else:
            i += 1

    print(cnt)

if __name__ == "__main__":
    main()

Fixed submission:
def main():
    N = int(input())
    P = list(map(int, input().split()))    
    cnt = 0
    i = 0
    while i < N:
        if i + 1 == P[i]:
            if i == N - 1:
                cnt += 1
                i += 1
            else:
                if i + 2 == P[i+1]:
                    cnt += 1
                    i += 2
                else:
                    cnt += 1
                    i += 1
        else:
            i += 1

    print(cnt)

if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    N = int(input())
    A = list(map(int, input().split()))
    set_A = sorted(set(A), reverse=True)

    max_num = 0

    for a in set_A:
        if A.count(a) >= 2:
            if max_num == 0:
                max_num = a
                if A.count(a) >= 4:
                    print(a * a)
                    exit()
            else:
                print(max_num * a)
                exit()

    print(0)

main()

Fixed submission:
import collections

def main():
    N = int(input())
    A = list(map(int, input().split()))
    
    B = collections.Counter(A)

    c = []

    for k, v in B.items():
        if v >= 2:
            c.append(k)
        if v >= 4:
            c.append(k)
    if len(c) < 2:
        print(0)
    else:
        c.sort()
        print(c[-1] * c[-2])

main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    N = int(input())
    A = list(map(int, input().split()))
    sort_A = sorted(A, reverse=True)
    set_A = sorted(set(sort_A), reverse=True)

    max_num = 0

    for a in set_A:
        if sort_A.count(a) >= 2:
            if max_num == 0:
                max_num = a
                if sort_A.count(a) >= 4:
                    print(a * a)
                    exit()
            else:
                print(max_num * a)
                exit()

    print(0)

main()

Fixed submission:
import collections

def main():
    N = int(input())
    A = list(map(int, input().split()))
    
    B = collections.Counter(A)

    c = []

    for k, v in B.items():
        if v >= 2:
            c.append(k)
        if v >= 4:
            c.append(k)
    if len(c) < 2:
        print(0)
    else:
        c.sort()
        print(c[-1] * c[-2])

main()
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    N = int(input())
    a = list(map(int, input().split()))

    sum_a = sum(a)
    min_diff = float('inf')
    for i in range(1,N):
        if min_diff > abs(sum_a-2 * sum(a[i:])):
            min_diff = abs(sum_a-2 * sum(a[i:]))

    print(min_diff)

main()

Fixed submission:
def main():
    N = int(input())
    a = list(map(int, input().split()))

    sum_a = sum(a)
    min_diff = float('inf')
    sum_first = 0
    for i in range(N-1):
        sum_first += a[i]
        if min_diff > abs(sum_a - 2 * sum_first):
            min_diff = abs(sum_a - 2 * sum_first)

    print(min_diff)

main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    N = int(input())
    a = list(map(int, input().split()))

    min_diff = float('inf')
    for i in range(1,N):
        if min_diff > abs(sum(a[i:])-sum(a[:i])):
            min_diff = abs(sum(a[i:])-sum(a[:i]))

    print(min_diff)

main()

Fixed submission:
def main():
    N = int(input())
    a = list(map(int, input().split()))

    sum_a = sum(a)
    min_diff = float('inf')
    sum_first = 0
    for i in range(N-1):
        sum_first += a[i]
        if min_diff > abs(sum_a - 2 * sum_first):
            min_diff = abs(sum_a - 2 * sum_first)

    print(min_diff)

main()
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    n = int(input())
    A = list(map(int, input().split()))
    b = []

    for a in A:
        b.append(a)
        b.reverse()
    print(*b)

main()

Fixed submission:
from collections import deque
def main():
    n = int(input())
    a = [0] + list(map(int, input().split()))
    b = deque(maxlen=n+1)
    for i in range(1,n+1):
        if (i % 2 == 0 and n % 2 == 0 ) or (i % 2 != 0 and n % 2 != 0 ):
            b.appendleft(a[i])
        else:
            b.append(a[i])

    print(*b)

main()

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
A = list(map(int, input().split()))
b = []

for a in A:
    b.append(a)
    b.reverse()
print(*b)

Fixed submission:
from collections import deque
def main():
    n = int(input())
    a = [0] + list(map(int, input().split()))
    b = deque(maxlen=n+1)
    for i in range(1,n+1):
        if (i % 2 == 0 and n % 2 == 0 ) or (i % 2 != 0 and n % 2 != 0 ):
            b.appendleft(a[i])
        else:
            b.append(a[i])

    print(*b)

main()
Buggy python submission (verdict: Runtime Error):
N,M = map(int, input().split())

ans = [0] * M

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

print(*ans, sep='\n')

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

a = [0] * M
b = [0] * M
for i in range(M):
    a[i],b[i] = map(int, input().split())

for i in range(1, N+1):
    print(a.count(i) + b.count(i))
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    N, K = map(int, input().split())
    ans = []
    for i in range(N):
        a, b = map(int, input().split())
        for i in range(b):
            ans.append(a)
    sort_ans = sorted(ans)
    print(sort_ans[K-1])
    
main()

    

Fixed submission:
def main():
    N, K = map(int, input().split())
    ans = [0] * (10 ** 5 + 1) 
    for i in range(N):
        a, b = map(int, input().split())
        ans[a] += b
    for i in range(10 ** 5 + 1):
        if K <= ans[i]:
            print(i)
            exit()
        else:
            K -= ans[i]
    
main()
Buggy python submission (verdict: Runtime Error):
def main():
    N, M = map(int, input().split())
    edges = []
    
    for _ in range(M):
        a, b, c = map(int, input().split())
        a -= 1
        b -= 1
        edges.append([a,b,c])

    d = [float('inf')] * N
    d[0] = 0

    for i in range(N-1):
        for edge in edges:
            d[edge[1]] = min(d[edge[1]], d[edge[0]] - edge[2])

    ans = d[N-1]
    for edge in edges:
        d[edge[1]] = min(d[edge[1]], d[edge[0]] - edge[2])

    if ans == d[N-1]:
        print(-ans)
    else:
        print(inf)


main()

Fixed submission:

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

edges = []

for i in range(M):
    a, b, c = map(int, input().split())
    edges.append([a,b,c])

dist = [float('inf')] * (N + 1)
dist[1] = 0

for _ in range(N - 1):
    for a, b, c in edges:
        dist[b] = min(dist[b], dist[a] - c)

ans = dist[N]
for a, b, c in edges:
    dist[b] = min(dist[b], dist[a] - c)

if ans == dist[N]:
    print(-ans)
else:
    print('inf')

Buggy python submission (verdict: Runtime Error):
def main():
    N, M = map(int, input().split())
    d = [[float('inf')] * N for _ in range(N)]
    edges = []
    
    for _ in range(M):
        a, b, c = map(int, input().split())
        a -= 1
        b -= 1
        edges.append([a,b,c])

    d = [float('inf')] * N
    d[0] = 0

    for i in range(N-1):
        for edge in edges:
            d[edge[1]] = min(d[edge[1]], d[edge[0]] - edge[2])

    ans = d[N]
    for edge in edges:
        d[edge[1]] = min(d[edge[1]], d[edge[0]] - edge[2])

    if ans == d[N]:
        print(-ans)
    else:
        print(-1)


    

    
main()

Fixed submission:

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

edges = []

for i in range(M):
    a, b, c = map(int, input().split())
    edges.append([a,b,c])

dist = [float('inf')] * (N + 1)
dist[1] = 0

for _ in range(N - 1):
    for a, b, c in edges:
        dist[b] = min(dist[b], dist[a] - c)

ans = dist[N]
for a, b, c in edges:
    dist[b] = min(dist[b], dist[a] - c)

if ans == dist[N]:
    print(-ans)
else:
    print('inf')
Buggy python submission (verdict: Runtime Error):
from operator import mul
from functools import reduce

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

def main():
    N, A, B = map(int, input().split())
    v = list(map(int, input().split()))
    sort_v = sorted(v, reverse=True)
    ave = 0
    ans = 0
    if sort_v[0] == sort_v[A-1]:
        cnt = v.count(sort_v[A-1])
        ave = sort_v[0]
        for i in range(A, min(cnt,B)+1):
            ans += cmb(cnt,i)
    else:
        cnt = v.count(sort_v[A-1])
        ind = sort_v.index(sort_v[A-1])
        for i in range(ind, A):
            ans += cmb(cnt, i)
        tmp = 0
        for i in range(A):
            tmp += sort_v[i]
        ave = tmp / A
    print(ave)
    print(ans)


if __name__ == "__main__":
    main()

Fixed submission:
from math import factorial

def combinations_count(n, r):
    ''' 組み合わせ '''
    return factorial(n) // (factorial(n - r) * factorial(r))

def max_ave():
    N, A, B = map(int, input().split())
    v = list(map(int, input().split()))
    sort_v = sorted(v, reverse=True)

    # 平均の最大値を求める
    sum_A = 0
    for i in range(A):
        sum_A += sort_v[i]
    max_ave_v = sum_A / A

    print(max_ave_v)

    # 選び方を求める
    V = sort_v[:A]
    num = v.count(min(V))
    a = V.count(min(V))
    cnt = 0
    if max(V) == min(V):
        for i in range(A,B+1):
            if num < i:
                continue
            cnt += combinations_count(num,i)
    else:
        cnt = combinations_count(num,a)
    
    print(cnt)

max_ave()

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

def combinations_count(n, r):
    ''' 組み合わせ '''
    return factorial(n) // (factorial(n - r) * factorial(r))

def max_ave():
    N, A, B = map(int, input().split())
    v = list(map(int, input().split()))
    sort_v = sorted(v, reverse=True)

    # 平均の最大値を求める
    sum_A = 0
    for i in range(A):
        sum_A += sort_v[i]
    max_ave_v = sum_A / A

    print(max_ave_v)

    # 選び方を求める
    V = sort_v[:A]
    num = v.count(min(V))
    a = V.count(min(V))
    cnt = 0
    if max(V) == min(V):
        if num == 1:
            print(1)
            exit()
        for i in range(A,B+1):
            cnt += combinations_count(num,i)
    else:
        cnt = combinations_count(num,a)
    
    print(cnt)

max_ave()

Fixed submission:
from math import factorial

def combinations_count(n, r):
    ''' 組み合わせ '''
    return factorial(n) // (factorial(n - r) * factorial(r))

def max_ave():
    N, A, B = map(int, input().split())
    v = list(map(int, input().split()))
    sort_v = sorted(v, reverse=True)

    # 平均の最大値を求める
    sum_A = 0
    for i in range(A):
        sum_A += sort_v[i]
    max_ave_v = sum_A / A

    print(max_ave_v)

    # 選び方を求める
    V = sort_v[:A]
    num = v.count(min(V))
    a = V.count(min(V))
    cnt = 0
    if max(V) == min(V):
        for i in range(A,B+1):
            if num < i:
                continue
            cnt += combinations_count(num,i)
    else:
        cnt = combinations_count(num,a)
    
    print(cnt)

max_ave()
Buggy python submission (verdict: Time Limit Exceeded):
K, S = map(int, input().split())

count = 0
for i in range(K+1):
    for j in range(K+1):
        for m in range(K+1):
            if (i + j + m ) == S:
                count += 1

print(count)

Fixed submission:
K, S = map(int, input().split())

count = 0
for i in range(K+1):
    for j in range(K+1):
        z = S - i - j
        if 0 <= z <= K:
            count += 1

print(count)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))

if N % 2 == 0:
    for i in range(1, N, 2):
        if A.count(i) != 2:
            print(0)
            exit()
    print(int((2 ** (N/2)) % (10*9 + 7)))
else:
    for j in range(0, N, 2):
        if j == 0:
            if int(A.count(j)) != 1:
                print(0)
                exit()
        else:
            if A.count(j) != 2:
                print(0)
                exit() 
    print(int(2 ** ((N-1)/2) % (10*9 + 7)))


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

#if N % 2 == 0:
#    for i in range(1, N, 2):
#        if A.count(i) != 2:
#            print(0)
#            exit()
#    print(int((2 ** (N/2)) % (10*9 + 7)))
#else:
#    for j in range(0, N, 2):
#        if j == 0:
#            if int(A.count(j)) != 1:
#                print(0)
#                exit()
#        else:
#            if A.count(j) != 2:
#                print(0)
#                exit() 
#    print(int(2 ** ((N-1)/2) % (10*9 + 7)))

# 全探索でやると間に合わなかったので正しい場合の和の値を求めてそれを配列の和と比較する

K = N if N % 2 == 0 else N + 1
S = N // 2
if sum(A) == K * S:
    ans = 2 ** S % (10 ** 9 + 7)
else:
    ans = 0

print(ans)