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

Fixed submission:
#典型ナップザック
#10**9はMLE(pypyではRE)

def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10000000)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations
    #from itertools import accumulate, product
    from bisect import bisect_left,bisect_right
    from math import floor, ceil
    #from operator import itemgetter

    #mod = 1000000007

    N, W = map(int, input().split())
    w = [0]*N
    v = [0]*N
    for i in range(N):
        w[i], v[i] = map(int, input().split())
    V = 10**5+1
    inf = float('inf')
    dp = [inf]*V
    dp[0] = 0
    for i in range(N):
        for j in range(V, v[i]-1, -1):
            if dp[j-v[i]]+w[i]<=W:
                dp[j] = min(dp[j], dp[j-v[i]]+w[i])
    for i in range(V):
        if dp[-(i+1)]<=W:
            print(V-(i+1))
            exit()
            
if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10000000)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations
    #from itertools import accumulate, product
    from bisect import bisect_left,bisect_right
    from math import floor, ceil
    #from operator import itemgetter

    #mod = 1000000007
    
    N, W = map(int,input().split())
    wv = [tuple(map(int,input().split())) for i in range(N)]
    dp = [0]*(W+1)
    for i in range(N):
        for j in range(W, wv[i][0]-1, -1):
            dp[j] = max(dp[j], dp[j-wv[i][0]]+wv[i][1])
    print(max(dp))

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10000000)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations
    #from itertools import accumulate, product
    from bisect import bisect_left,bisect_right
    from math import floor, ceil
    #from operator import itemgetter

    #mod = 1000000007

    N, W = map(int,input().split())
    w = [0]*N
    v = [0]*N
    for i in range(N):
        w[i], v[i] = map(int, input().split())
    dp = [0]*(W+1)
    for i in range(N):
        for j in range(W, w[i]-1, -1):
            dp[j] = max(dp[j], dp[j-w[i]]+v[i])
    print(max(dp))

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

Fixed submission:
def main():
    import sys
    #input = sys.stdin.readline
    sys.setrecursionlimit(10000000)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations
    #from itertools import accumulate, product, permutations
    from math import floor, ceil

    #mod = 1000000007

    s = input()
    k = int(input())
    n = 0
    while n<=k-1:
        if not s[n]=='1':
            print(s[n])
            exit()
        else:
            n += 1
    print('1')


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def main():
    import sys
    #input = sys.stdin.readline
    sys.setrecursionlimit(10000000)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations
    #from itertools import accumulate, product, permutations
    from math import floor, ceil

    #mod = 1000000007

    s = input()
    k = int(input())
    n = 0
    while n<=k:
        if not s[n]=='1':
            print(s[n])
            exit()
        else:
            n += 1
    print('1')


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def main():
    import sys
    #input = sys.stdin.readline
    sys.setrecursionlimit(10000000)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations
    #from itertools import accumulate, product, permutations
    from math import floor, ceil

    #mod = 1000000007

    s = input()
    k = int(input())
    if s[0]=='1':
        print(s[1])
    else:
        print(s[0])

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

Fixed submission:
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby
    #from itertools import product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

    n,m = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(accumulate(a))
    for i in range(n):
        b[i] %= m
    b = [0] + b
    c = Counter(b)
    res = 0
    for k, v in c.items():
            res += v*(v-1)//2
    print(res)
    
if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def main():
    import sys
    input = sys.stdin.readline
    from collections import Counter
    from itertools import accumulate

    n,m = map(int, input().split())
    a = [0] + list(map(lambda x: x % M, accumulate(map(int, input().split()))))
    c = Counter(a)
    res = 0
    for k, v in c.items():
            res += v*(v-1)//2
    print(res)
    
if __name__ == '__main__':
    main()
Problem p03323 (python)

Fixed submission:
a, b = list(map(int, input().split()))
print('Yay!') if a<=8 and b<=8 else print(':(')

Buggy submission (verdict: Runtime Error):
a, b = list(map(int, input()))
print('Yay!') if a<=8 and b<=8 else print(':(')
Problem p03338 (python)

Fixed submission:
n = int(input())
s = input()
l = []
for i in range(1, n):
    cnt = 0
    for j in set(s[:i]):
        if j in list(s[i:]):
            cnt += 1
    l.append(cnt)
print(max(l))

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

ans = 0

for i in range(n):
    ans = max(ans, len(set[:i] & set[i:]))
print(ans)
Problem p03352 (python)

Fixed submission:
#pypyは内包表記使わない, rstrip注意
#提出前に見返すこと！
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10000000)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate
    #from itertools import product
    from bisect import bisect_left,bisect_right
    import heapq
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 1000000007

    x = int(input())
    for i in range(x, 0, -1):
        for b in range(1, 35):
            for p in range(2, 10):
                if b**p==i:
                    print(i)
                    exit()

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
#pypyは内包表記使わない, rstrip注意
#提出前に見返すこと！
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10000000)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate
    #from itertools import product
    from bisect import bisect_left,bisect_right
    import heapq
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 1000000007

    x = int(input())
    for i in range(x, 0, -1):
        for b in range(1, 35):
            for p in range(2, 10):
                if b**p==i:
                    print(i)
                    eixt()

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

Fixed submission:
n = int(input())
a = int(input())
print('Yes') if n%500 <= a else print('No')

Buggy submission (verdict: Runtime Error):
n = int(input())
a = int(input())
print('Yes') if n%500 <= a print('No')
Problem p03485 (python)

Fixed submission:
a,b = map(int, input().split())
s = (a+b)//2
if (a+b)%2:
  print(s+1)
else:
  print(s)

Buggy submission (verdict: Runtime Error):
s = input()
t = input()
s = sorted(s)
t = sorted(t, reverse=1)
if s<t:
    print('Yes')
else:
    print('No')
Problem p03486 (python)

Fixed submission:
s = list(input())
t = list(input())
if s==t:
    print('No')
    exit()

s = sorted(s)
s = ''.join(s)
t = sorted(t, reverse=1)
t = ''.join(t)
l = [s,t]
k = sorted(l)
if l==k:
    print('Yes')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
s = input()
s.sort()
t = input()
t.sort(reverse=True)
if s<t:
    print('Yes')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
s = input()
s = s.sort()
t = input()
t = t.sort(reverse=True)
if s<t:
    print('Yes')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
s = input().sort()
t = input().sort(reverse=True)
if s<t:
    print('Yes')
else:
    print('No')
Problem p03487 (python)

Fixed submission:
from collections import Counter
from collections import deque

n = int(input())
a = list(map(int, input().split()))
c = Counter(a)
c = c.most_common()
ans = 0
for num, cnt in c:
    if cnt>=num:
        ans += cnt - num
    else:
        ans += cnt
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
c = Counter(a)
ans = 0
for num, cnt in c.items():
    if cnt>=num:
        ans += cnt - num
    else:
        ans += cnt
print(ans)
Problem p03501 (python)

Fixed submission:
n,a,b = map(int, input().split())
if n*a<b:
  print(n*a)
else:
  print(b)

Buggy submission (verdict: Runtime Error):
n = int(input())
F = [int(input().replace(' ',''), 2) for _ in range(n)]
P = [list(map(int, input().split())) for _ in range(n)]
ans=-10**7*n
for sp in range(1, 1033):
  total = 0
  for i in range(n):
    total += P[i][bin(F[i] & sp).count('1')]
  if total>ans:
    ans = total
  else:
    ans = ans
print(ans)
Problem p03545 (python)

Fixed submission:
n = input()
a = int(n[0])
b = int(n[1])
c = int(n[2])
d = int(n[3])

if a+b+c+d==7:
    print('{}+{}+{}+{}=7'.format(a, b, c, d))
elif a+b+c-d==7:
    print('{}+{}+{}-{}=7'.format(a, b, c, d))
elif a+b-c+d==7:
    print('{}+{}-{}+{}=7'.format(a, b, c, d))
elif a-b+c+d==7:
    print('{}-{}+{}+{}=7'.format(a, b, c, d))
elif a-b-c+d==7:
    print('{}-{}-{}+{}=7'.format(a, b, c, d))
elif a-b+c-d==7:
    print('{}-{}+{}-{}=7'.format(a, b, c, d))
elif a+b-c-d==7:
    print('{}+{}-{}-{}=7'.format(a, b, c, d))
elif a-b-c-d==7:
    print('{}-{}-{}-{}=7'.format(a, b, c, d))

Buggy submission (verdict: Runtime Error):
n = input()
a = int(n[0])
b = int(n[1])
c = int(n[2])
d = int(n[3])

if a+b+c+d==7:
    print(f'{a}+{b}+{c}+{d}=7')
    exit()
if a+b+c-d==7:
    print(f'{a}+{b}+{c}-{d}=7')
    exit()
if a+b-c+d==7:
    print(f'{a}+{b}-{c}+{d}=7')
    exit()
if a-b+c+d==7:
    print(f'{a}-{b}+{c}+{d}=7')
    exit()
if a-b-c+d==7:
    print(f'{a}-{b}-{c}+{d}=7')
    exit()
if a-b+c-d==7:
    print(f'{a}-{b}+{c}-{d}=7')
    exit()
if a+b-c-d==7:
    print(f'{a}+{b}-{c}-{d}=7')
    exit()
if a-b-c-d==7:
    print(f'{a}-{b}-{c}-{d}=7')
    exit()
Problem p03550 (python)

Fixed submission:
#どっちで出すか注意, rstrip注意
#提出前に見返すこと！
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate
    #from itertools import product
    from bisect import bisect_left,bisect_right
    import heapq
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

    N,Z,W = map(int, input().split())
    a = list(map(int, input().split()))
    if N>=2:
        print(max(abs(a[-1]-W), abs(a[-1]-a[-2])))
    else:
        print(abs(a[0]-W))


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
#どっちで出すか注意, rstrip注意
#提出前に見返すこと！
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate
    #from itertools import product
    from bisect import bisect_left,bisect_right
    import heapq
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

    N,Z,W = map(int, input().split())
    a = list(map(int, input().split()))
    print(max(abs(a[-1]-W), abs(a[-1]-a[-2])))


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

Fixed submission:
def main():
    import sys
    #input = sys.stdin.readline
    sys.setrecursionlimit(10000000)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations
    #from itertools import accumulate, product
    from bisect import bisect_left,bisect_right
    from math import floor, ceil
    #from operator import itemgetter

    #mod = 1000000007

    n = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    C = list(map(int, input().split()))
    A.sort()
    C.sort()

    res = 0
    for j in B:
        res += bisect_left(A, j) * (n-bisect_right(C, j))
    print(res)

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
'''
https://atcoder.jp/contests/abc077/tasks/arc084_a
'''
def main():
    import sys
    #input = sys.stdin.readline
    sys.setrecursionlimit(10000000)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations
    #from itertools import accumulate, product
    from math import floor, ceil
    #from operator import itemgetter

    #mod = 1000000007

    n = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    C = list(map(int, input().split()))
    A.sort()
    B.sort()
    C.sort()

    def nibu(num, l):
        L = 0
        R = n-1
        mid = (L+R)//2
        if l[L]>num:
            return n, L
        if l[R]<num:
            return 0, n
        while 1:
            if l[L]<=num and num<l[L+1]:
                return n-(L+1), L+1
            elif l[mid]<=num:
                L = mid
            else:
                R = mid
            mid = (L+R)//2
    res = 0
    for i in A:
        x, na = nibu(i, B)
        for j in B[na:]:
            y, nb = nibu(j, C)
            res += y
    print(res)

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

Fixed submission:
a, b, c = list(map(int, input().split()))
if a==b:
  print(c)
elif a==c:
  print(b)
else:
  print(a)

Buggy submission (verdict: Runtime Error):
a, b, c = list(map(int, input().split()))
if a==b:
  print(c)
elif a==c:
  print(b):
else:
  print(a)
Problem p03597 (python)

Fixed submission:
#pypyは内包表記使わない
def main():
    import sys
    #input = sys.stdin.readline
    sys.setrecursionlimit(10000000)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations
    #from itertools import accumulate, product
    from bisect import bisect_left,bisect_right
    from math import floor, ceil
    #from operator import itemgetter

    #mod = 1000000007

    N = int(input())
    A = int(input())
    print(N**2-A)

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
#pypyは内包表記使わない
def main():
    import sys
    #input = sys.stdin.readline
    sys.setrecursionlimit(10000000)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations
    #from itertools import accumulate, product
    from bisect import bisect_left,bisect_right
    from math import floor, ceil
    #from operator import itemgetter

    #mod = 1000000007

    A, B, C, D, E, F = map(int, input().split())
    rate = 0
    res_water = min(A, B) * 100
    res_sugar = 0
    for i in range(30//A+1):
        for j in range(30//B+1):
            if i==0 and j==0:
                continue
            water = A*i + B*j
            if water*100 > F:
                continue
            limit = water * E
            for s in range(limit//C+1):
                sugar = limit - (limit-C*s)%D
                if water*100 + sugar > F:
                    continue
                if rate < sugar/(sugar+water*100):
                    rate = sugar/(sugar+water*100)
                    res_water = water * 100
                    res_sugar = sugar
    print(res_water+res_sugar, res_sugar)

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

Fixed submission:
s = input()
print('{}{}{}'.format(s[0], len(s)-2, s[-1]))

Buggy submission (verdict: Runtime Error):
s = input()
print('{}{}{}'.format(s[0], len(s)-2, s[-1])
Problem p03759 (python)

Fixed submission:

a,b,c = map(int, input().split())
if b-a==c-b:
    print('YES')
else:
    print('NO')

Buggy submission (verdict: Runtime Error):

a,b,c = map(int, input().split())
if b-a==c-b:
    pirnt('YES')
else:print('NO')
Problem p03798 (python)

Fixed submission:
def main():
    import sys
    #input = sys.stdin.readline
    sys.setrecursionlimit(10000000)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations
    #from itertools import accumulate, product
    from bisect import bisect_left,bisect_right
    from math import floor, ceil
    #from operator import itemgetter

    #mod = 1000000007

    N = int(input())
    s = list(input())

    def check(p):
        for i in range(1, N):
            if s[i]=='o' and p[i]=='S':
                p += p[i-1]
            elif s[i]=='o' and p[i]=='W':
                if p[i-1]=='S':
                    p += 'W'
                else:
                    p += 'S'
            elif s[i]=='x' and p[i]=='S':
                if p[i-1]=='S':
                    p += 'W'
                else:
                    p += 'S'
            else:
                p += p[i-1]
        if p[0]==p[N]:
            if s[0]=='o' and p[0]=='S':
                if p[N-1]==p[1]:
                    print(p[:N])
                    exit()
            elif s[0]=='x' and p[0]=='S':
                if p[N-1]!=p[1]:
                    print(p[:N])
                    exit()
            elif s[0]=='o' and p[0]=='W':
                if p[N-1]!=p[1]:
                    print(p[:N])
                    exit()
            else:
                if p[N-1]==p[1]:
                    print(p[:N])
                    exit()

    for i in ['SS', 'SW', 'WS', 'WW']:
        check(i)
    print(-1)
    


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
#始めの2匹が決まるとあとは自動的に決まるので矛盾していないかどうか判定

def main():
    import sys
    #input = sys.stdin.readline
    sys.setrecursionlimit(10000000)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations
    #from itertools import accumulate, product
    from bisect import bisect_left,bisect_right
    from math import floor, ceil
    #from operator import itemgetter

    #mod = 1000000007

    N = int(input())
    s = list(input())
    s += s[0]

    def check(p):
        for i in range(1, N):
            if s[i]=='o' and p[i]=='S':
                p += p[i-1]
            elif s[i]=='o' and p[i]=='W':
                if p[i-1]=='S':
                    p += 'W'
                else:
                    p += 'S'
            elif s[i]=='x' and p[i]=='S':
                if p[i-1]=='S':
                    p += 'W'
                else:
                    p += 'S'
            else:
                p += p[i-1]
        if p[0]==p[N] and p[1]==p[N+1]:
            print(p[:-2])
            exit()

    for i in ['SS', 'SW', 'WS', 'WW']:
        check(i)
    print(-1)

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

Fixed submission:
n = int(input())
s, ans, num = 1, 1, 2
for i in range(2, n+1):
  s *= i
l = []
while s != 1:
  if not s % num:
    l.append(num)
    s //= num
  else:
    num += 1
for i in set(l):
  ans *= l.count(i)+1
print(ans%(10**9+7))

Buggy submission (verdict: Runtime Error):
n = int(input())
for i in range(1, n+1):
    num = 2
    while i != 1:
        if i % num==0:
            i //= num
            l.append(num)
        else:
            num += 1
ans = 1
for i in set(l):
    ans *= (l.count(i) + 1) % (10**9+7)
print(ans)
Problem p03852 (python)

Fixed submission:
print('vowel') if input() in ['a', 'i', 'u', 'e', 'o'] else print('consonant')

Buggy submission (verdict: Runtime Error):
print('vowel') if input() in ['a', 'i', 'u', 'e', 'o'] print('consonant')
Problem p02658 (python)

Fixed submission:
def solve(N, A):
    ret = 1
    upper = 10**18
    if 0 in A:
      return 0
    for a in A:
        ret *= a
        if upper < ret:
          return -1
    return ret
 
if __name__ == "__main__":
    N = int(input())
    A = list(map(int, input().split()))
    print(solve(N, A))

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

if __name__ == "__main__":
    N = int(input())
    A = np.array(list(map(int, input().split())))
    ret = A.prod()
    print(ret if ret < pow(10, 18) else -1)
Problem p02727 (python)

Fixed submission:
def solve(X, Y, p, q, r):
    red_apples = sorted(p, reverse=True)[: X]
    green_apples = sorted(q, reverse=True)[: Y]
    white_apples = sorted(r)

    ret = 0
    while red_apples and green_apples:
        if not white_apples or (white_apples[-1] < red_apples[-1] and white_apples[-1] < green_apples[-1]):
            return ret + sum(red_apples) + sum(green_apples)

        ret += white_apples.pop(-1)
        if red_apples[-1] < green_apples[-1]:
            red_apples.pop(-1)
        else:
            green_apples.pop(-1)


    if not red_apples:
        while green_apples and white_apples and (green_apples[-1] < white_apples[-1]):
            ret += white_apples.pop(-1)
            green_apples.pop(-1)
        return ret + sum(green_apples)

    else:
        while red_apples and white_apples and (red_apples[-1] < white_apples[-1]):
            ret += white_apples.pop(-1)
            red_apples.pop(-1)
        return ret + sum(red_apples)

if __name__ == '__main__':
    X, Y, A, B, C = map(int, input().split())
    p = list(map(int, input().split()))
    q = list(map(int, input().split()))
    r = list(map(int, input().split()))
    print(solve(X, Y, p, q, r))

Buggy submission (verdict: Runtime Error):
def solve(X, Y, C, p, q, r):
    red_apples = sorted(p, reverse=True)[: X]
    green_apples = sorted(q, reverse=True)[: Y]
    white_apples = sorted(r)

    ret = 0
    while white_apples:
        if white_apples[-1] <= red_apples[-1] and white_apples[-1] <= green_apples[-1]:
            break

        ret += white_apples.pop(-1)
        if red_apples[-1] < green_apples[-1]:
            red_apples.pop(-1)
        else:
            green_apples.pop(-1)
    return ret + sum(red_apples) + sum(green_apples)

if __name__ == '__main__':
    X, Y, A, B, C = map(int, input().split())
    p = list(map(int, input().split()))
    q = list(map(int, input().split()))
    r = list(map(int, input().split()))
    print(solve(X, Y, C, p, q, r))