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

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

def main():
    N,A,B,C = map(int, input().split())
    L = []
    for _ in range(N):
        L.append(int(input()))
    mi = 1000*N
    for i in range(4**N):
        mp = 0
        a = b = c = 0
        x = 0
#        print(bin(i) + " ", end="")
        while i > 0:
            if i%4 == 1:
                if a > 0:
                    mp += 10
                a += L[x]
            if i%4 == 2:
                if b > 0:
                    mp += 10
                b += L[x]
            if i%4 == 3:
                if c > 0:
                    mp += 10
                c += L[x]
            i >>= 2
            x += 1
        if a > 0 and b > 0 and c > 0:
            mi = min(mi, mp + abs(A-a) + abs(B-b) + abs(C-c))
#            print(a,b,c,mi)
    print(mi)

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
import sys
input=sys.stdin.readline

def func(dst, src, mp):
    if len(dst) == 0: # dst が空になったら終了
        return mp
    for s in src: # 長さが一致していたら何もせず除外
        if s in dst:
            src.remove(s)
            dst.remove(s)
#            print("removed", s, src, dst, mp)
    for i in dst: # 持っているどの竹よりも短い dst には、短縮魔法を使うしかない
        if i < min(src):
            tmp = min(src)
            mp += min(src) - i
            src.remove(tmp)
            dst.remove(i)
#            print("shorten", tmp, src, dst, mp)
    # 持っている竹のうち、mp 消費が10未満で処理できるものがあれば、その中で最小のものを延長
    mi = 10
    dd = None
    ss = None
    for s in src:
        for d in dst:
            tmp = mi
            mi = min(mi, abs(d-s))
            if mi != tmp:
                dd = d
                ss = s
    if mi < 10:
        mp += dd - ss
        src.remove(ss)
        dst.remove(dd)
#        print("extend", ss, src, dst, mp)
    # 結合した時に、目標に近くなる 2 本を結合
    mi = 1000
    for s in src:
        for d in dst:
            mi = min(mi, abs(s-d))
    s1 = s2 = None
    for i in range(len(src)):
        for j in range(i+1,len(src)):
            for d in dst:
                tmp = mi
                mi = min(mi, abs(d - (src[i] + src[j])))
                if mi != tmp:
                    s1 = src[i]
                    s2 = src[j]
    if s1 != None and s2 != None:
        src.remove(s1)
        src.remove(s2)
        mp += 10
#        print("synthesize", s1, s2, src, dst,mp)
        src.append(s1+s2)
    else:
        # 結合しても意味が無い場合、最も差が小さいものを変更
        mi = 1000
        ss = None
        dd = None
        for s in src:
            for d in dst:
                tmp = mi
                mi = min(mi, abs(s-d))
                if tmp != mi:
                    ss = s
                    dd = d
        if ss != None and dd != None:
            mp += abs(s-d)
            src.remove(s)
            dst.remove(d)
    return func(dst, src, mp)

def main():
    N,A,B,C = map(int, input().split())
    T = [A,B,C]
    L = []
    for _ in range(N):
        L.append(int(input()))
    print(func(T,L,0))

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

Fixed submission:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10000000)

N, M = map(int, input().split())
G = [[] for _ in range(N)]
for _ in range(M):
    a, b = map(int, input().split())
    G[a-1].append(b-1)
dp = [-1]*N


def dfs(n):
    global dp
    if dp[n] > 0:
        return dp[n]

    ma = 0
    for b in G[n]:
        ma = max(ma, dfs(b) + 1)
    dp[n] = ma
    return ma


def main():
    global dp
    for i in range(N):
        dp[i] = dfs(i)
    print(max(dp))


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline


N, M = map(int, input().split())
G = [[] for _ in range(N)]
for _ in range(M):
    a, b = map(int, input().split())
    G[a-1].append(b-1)
dp = [-1]*N


def dfs(n):
    global dp
    if dp[n] > 0:
        return dp[n]

    ma = 0
    for b in G[n]:
        ma = max(ma, dfs(b) + 1)
    dp[n] = ma
    return ma


def main():
    global dp
    for i in range(N):
        dp[i] = dfs(i)
    print(max(dp))


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

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


def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a


def main():
    N, P = map(int, input().split())
    p = prime_factorize(P)
    import collections
    ans = 1
    for k, v in collections.Counter(p).most_common():
        while v >= N:
            ans *= k
            v -= N
    print(ans)


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline


def main():
    N, P = map(int, input().split())
    if N == 1:
        print(P)
        return
    ans = 0
    for i in range(1, 10**6+1):
        y = i**N
        if y > P:
            break
        if P % y == 0:
            ans = i
    print(ans)


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
N, P = map(int, input().split())
if N == 1:
    print(P)
    exit()

x = ans = 1
while True:
    y = x**N
    if y > P:
        break
    if P % y == 0:
        ans = x
    x += 1
print(ans)

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline


def main():
    N, P = map(int, input().split())
    if N == 1:
        print(P)
        return
    x = ans = 1
    while True:
        y = x**N
        if y > P:
            break
        if P % y == 0:
            ans = x
        x += 1
    print(ans)

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

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

def main():
    N = int(input())
    V1 = {}
    V2 = {}
    V = list(map(int, input().split()))
    for i,v in enumerate(V):
        if i%2 == 0:
            V1[v] = V1[v] + 1 if v in V1 else 1
        else:
            V2[v] = V2[v] + 1 if v in V2 else 1

    V1 = sorted(V1.items(), key=lambda x:x[1], reverse=True)
    V2 = sorted(V2.items(), key=lambda x:x[1], reverse=True)

    if V1[0] != V2[0]:
        ans = 0
        for v in V1[1:]:
            ans += v[1]
        for v in V2[1:]:
            ans += v[1]
        print(ans)
    else:
        a1 = 0
        for v in V1[1:]:
            a1 += v[1]
        a1 += V2[0][1]
        for v in V2[2:]:
            a1 += v[1]
        a2 = 0
        a2 += V1[0][1]
        for v in V1[2:]:
            a2 += v[1]
        for v in V2[1:]:
            a2 += v[1]
        print(min(a1,a2))

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
import sys
input=sys.stdin.readline

input = open(sys.argv[1], "r").readline

def main():
    N = int(input())
    V1 = {}
    V2 = {}
    V = list(map(int, input().split()))
    for i,v in enumerate(V):
        if i%2 == 0:
            V1[v] = V1[v] + 1 if v in V1 else 1
        else:
            V2[v] = V2[v] + 1 if v in V2 else 1

    V1 = sorted(V1.items(), key=lambda x:x[1], reverse=True)
    V2 = sorted(V2.items(), key=lambda x:x[1], reverse=True)

    if V1[0] != V2[0]:
        ans = 0
        for v in V1[1:]:
            ans += v[1]
        for v in V2[1:]:
            ans += v[1]
        print(ans)
    else:
        a1 = 0
        for v in V1[1:]:
            a1 += v[1]
        a1 += V2[0][1]
        for v in V2[2:]:
            a1 += v[1]
        a2 = 0
        a2 += V1[0][1]
        for v in V1[2:]:
            a2 += v[1]
        for v in V2[1:]:
            a1 += v[1]
        print(min(a1,a2))

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

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

def main():
    N,K = map(int, input().split())
    X = list(map(int, input().split()))
    ans = 3*10**8
    for i in range(0,N-K+1):
        l = X[i]
        r = X[i+K-1]
        if l*r < 0:
            ans = min(ans, 2*min(abs(l),abs(r)) + max(abs(l),abs(r)))
        else:
            ans = min(ans, max(abs(l),abs(r)))

    print(ans)

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
import sys
input=sys.stdin.readline

input = open(sys.argv[1],"r").readline

def main():
    N,K = map(int, input().split())
    X = list(map(int, input().split()))
    ans = 3*10**8
    for i in range(0,N-K+1):
        l = X[i]
        r = X[i+K-1]
        if l*r < 0:
            ans = min(ans, 2*min(abs(l),abs(r)) + max(abs(l),abs(r)))
        else:
            ans = min(ans, max(abs(l),abs(r)))

    print(ans)

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

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

H,W=map(int, input().split())
C = [[] for i in range(H)]

for h in range(H):
    C[h] = list(input().strip())
#print(*C)

for h in range(H):
    for w in range(W):
        if C[h][w] == "#":
            if h == 0 or (h>0 and C[h-1][w] == "."):
                if w == 0 or (w>0 and C[h][w-1] == "."):
                    if w == W-1 or (w<W-1 and C[h][w+1] == "."):
                        if h == H-1 or (h<H-1 and C[h+1][w] == "."):
                            print("No")
                            exit()
print("Yes")

Buggy submission (verdict: Runtime Error):
import sys
input=sys.stdin.readline

H,W=map(int, input().split())
C = [[] for i in range(H)]

for h in range(H):
    C[h] = list(input().strip())
#print(*C)

for h in range(H):
    for w in range(W):
        if C[w][h] == "#":
            if h == 0 or (h>0 and C[h-1][w] == "."):
                if w == 0 or (w>0 and C[h][w-1] == "."):
                    if w == W-1 or (w<W-1 and C[h][w+1] == "."):
                        if h == H-1 or (h<H-1 and C[h+1][w] == "."):
                            print("No")
                            exit()
print("Yes")

Buggy submission (verdict: Runtime Error):
import sys
input=sys.stdin.readline

H,W=map(int, input().split())
C = [[] for i in range(H)]

for h in range(H):
    C[h] = list(input().strip())
#print(*C)

for h in range(H):
    for w in range(W):
        if C[w][h] == "#":
            if h == 0 or (h>0 and C[h-1][w] == "."):
                if w == 0 or (w>0 and C[h][w-1] == "."):
                    if w == W-1 or (w+1<W and C[h][w+1] == "."):
                        if h == H-1 or (h+1<h and C[h+1][w] == "."):
                            print("No")
                            exit()
print("Yes")
Problem p03425 (python)

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

n = int(input())
a = [0]*5
for i in range(n):
    s = input().strip()
    c = s[0]
    if c == "M":
        a[0] += 1
    elif c == "A":
        a[1] += 1
    elif c == "R":
        a[2] += 1
    elif c == "C":
        a[3] += 1
    elif c == "H":
        a[4] += 1
#print(a)

ans = 0
for i in range(0, len(a)-2):
    for j in range(i+1, len(a)):
        for k in range(j+1, len(a)):
#            print(i,j,k, a[i]*a[j]*a[k])
            ans += a[i]*a[j]*a[k]
print(ans)

Buggy submission (verdict: Runtime Error):
import sys
input=sys.stdin.readline

h = {}
for c in "MARCH":
    h[c] = 0

n = int(input())
for i in range(n):
    s = input().strip()
    h[s[0]] += 1
#print(h)

import itertools
ans = 0
for i,j,k in itertools.combinations("MARCH", 3):
    ans += h[i]*h[j]*h[k]
print(ans)
Problem p03625 (python)

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

def main():
    N = int(input())
    A = list(map(int,input().split()))
    d = collections.defaultdict(int)
    for a in A:
        d[a] += 1
    for k,v in list(d.items()):
        if v < 2:
            d.pop(k)
    d = sorted(d.items(), key=lambda x: x[0], reverse=True)
    if len(d) >= 1 and d[0][1] >= 4:
        print(d[0][0]**2)
    elif len(d) >= 2:
        print(d[0][0]*d[1][0])
    else:
        print(0)

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
import sys
input=sys.stdin.readline
import collections

input = open(sys.argv[1], "r").readline

def main():
    N = int(input())
    A = list(map(int,input().split()))
    d = collections.defaultdict(int)
    for a in A:
        d[a] += 1
    for k,v in list(d.items()):
        if v < 2:
            d.pop(k)
    d = sorted(d.items(), key=lambda x: x[0], reverse=True)
    if len(d) >= 1 and d[0][1] >= 4:
        print(d[0][0]**2)
    elif len(d) >= 2:
        print(d[0][0]*d[1][0])
    else:
        print(0)

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

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


def main():
    N, M = map(int, input().split())
    mod = (10**9)+7
    if abs(N-M) >= 2:
        print(0)
    else:
        ans = 1
        for n in range(1, N+1):
            ans = ans * n % mod
        for m in range(1, M+1):
            ans = ans * m % mod
        if N == M:
            ans = ans * 2 % mod
        print(ans)


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
    import sys
    input = sys.stdin.readline


    def main():
        N, M = map(int, input().split())
        mod = (10**9)+7
        if abs(N-M) >= 2:
            print(0)
        else:
            ans = 1
            for n in range(1, N+1):
                ans = ans * n % mod
            for m in range(1, M+1):
                ans = ans * m % mod
            if N == M:
                ans = ans * 2 % mod
            print(ans)


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

Fixed submission:
import sys
input=sys.stdin.readline
#input = open(sys.argv[1], "r").readline

def main():
    N = int(input())
    A = list(map(int, input().split()))
    tmp = A.copy()
    mi = -1
    for j in range(2):
        A = tmp.copy()
        s = 0
        n = 0
        if j == 0: # 偶数番目までの和が正 ⇒ A[0] を負にする
            if A[0] >= 0:
                n += abs(A[0] +1)
                A[0] = -1
        else:   # 奇数番目までの和が正 ⇒ A[0] を正にする
            if A[0] <= 0:
                n += abs(A[0] -1)
                A[0] = 1
        s = A[0]
#        print(A)
        for i in range(1,N):
            if s * (s+A[i]) >= 0:
                if s < 0:
                    n += abs(-s+1 -A[i])
                    A[i] = -s+1
                else:
                    n += abs(-s-1 -A[i])
                    A[i] = -s-1
            s += A[i]
        if mi == -1:
            mi = n
        else:
            mi = min(mi, n)
    print(mi)

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
import sys
input=sys.stdin.readline
input = open(sys.argv[1], "r").readline

def main():
    N = int(input())
    A = list(map(int, input().split()))
    tmp = A.copy()
    mi = -1
    for j in range(2):
        A = tmp.copy()
        s = 0
        n = 0
        if j == 0: # 偶数番目までの和が正 ⇒ A[0] を負にする
            if A[0] > 0:
                n += abs(A[0] +1)
                A[0] = -1
        else:   # 奇数番目までの和が正 ⇒ A[0] を正にする
            if A[0] < 0:
                n += abs(A[0] -1)
                A[0] = 1
        s = A[0]
#        print(A)
        for i in range(1,N):
            if s * (s+A[i]) >= 0:
                if s < 0:
                    n += abs(-s+1 -A[i])
                    A[i] = -s+1
                else:
                    n += abs(-s-1 -A[i])
                    A[i] = -s-1
            s += A[i]
        if mi == -1:
            mi = n
        else:
            mi = min(mi, n)
    print(mi)

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

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


def main():
    N, A = map(int, input().split())
    X = list(map(int, input().split()))

    M = max(max(X), A)*N
    dp = [[[0 for k in range(M+1)] for j in range(N+1)] for i in range(N+1)]
    dp[0][0][0] = 1
    for i in range(N):
        for j in range(N):
            for k in range(M):
                if dp[i][j][k]:
                    dp[i+1][j][k] += dp[i][j][k]
                    dp[i+1][j+1][k+X[i]] += dp[i][j][k]
    ans = 0
    for j in range(1, N+1):
        ans += dp[N][j][A*j]
    print(ans)


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline


def main():
    N, A = map(int, input().split())
    X = list(map(int, input().split()))

    M = max(X)*N
    dp = [[[0 for k in range(M+1)] for j in range(N+1)] for i in range(N+1)]
    dp[0][0][0] = 1
    for i in range(N):
        for j in range(N):
            for k in range(M):
                if dp[i][j][k]:
                    dp[i+1][j][k] += dp[i][j][k]
                    dp[i+1][j+1][k+X[i]] += dp[i][j][k]
    ans = 0
    for j in range(1, N+1):
        ans += dp[N][j][A*j]
    print(ans)


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

Fixed submission:
N, S = map(int, input().split())
A = map(int, input().split())
 
def solve(length, target, nums):
  
  dp = [[0]*(target+1) for i in range(length+1)]
  dp[0][0] = 1
  for i, n in enumerate(nums):
    for j, comb_num in enumerate(dp[i]):
      sub = j - n
      dp[i + 1][j] += comb_num * 2
      #print(i, j, sub, dp[i])
      if sub >= 0:
        dp[i + 1][j] += dp[i][sub]
      dp[i + 1][j] %= 998244353
  #print(dp)
  print(dp[length][target])
  
solve(N, S, A)

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

def solve(length, target, nums):
  
  dp = [[0]*(target+1)]*(length+1)
  
  for i, n in enumerate(nums):
    for j, comb_num in enumerate(dp[i]):
      sub = j - n
      dp[i + 1][j] += comb_num
      if sub >= 0::
        dp[i + 1][j] += dp[i][sub]
        
  print(dp[length][target])
  
solve(N, S, A)
Problem p02665 (python)

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
  
def solve(N, A):
  
  if N == 0 and A[0] > 1 or N > 0 and A[0] > 0:
    print(-1)
    return

  total = sum(A[1:])
  #t = A[-1] + A[-2]
  par = 1 - A[0]
  rt = 1
  for i, a in enumerate(A[1:]):
    total -= a
    max_node = par * 2
    cur = max_node - a
    if cur < 0:
      print(-1)
      return
    cur = min(total, cur)
    #print(i+1, a, cur)
    rt += a
    if i + 1 < N:
      rt += cur
    par = cur  
   
  print(rt)
  
solve(N, A)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input.split()))
 
def solve(N, A):
	if not A or A[0] != 1:
      print(-1)
      return
 
    prev = 1
    rt = 1
    for a in A[1:]:
        if a > prev * 2:
          print(-1)
          return
        rt += (prev * 2 - a) % (prev * 2)
        prev = a

    print(rt)
    
solve(N, A)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input.split()))
 
def solve(N, A):
  if not A or A[0] != 1:
    print(-1)
    return
 
  prev = 1
  rt = 1
  for a in A[1:]:
    if a > prev * 2:
      print(-1)
      return
    rt += (prev * 2 - a) % (prev * 2)
    prev = a
 
  print(rt)
 
solve(N, A)

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

def solve(N, A):
  if not A or A[0] != 1:
    print(-1)
    return

  prev = 1
  rt = 1
  for a in A[1:]:
    if a > prev * 2:
      print(-1)
      return
    rt += (prev * 2 - a) % (prev * 2)
    prev = a

  print(rt)

solve(N, A)
Problem p02885 (python)

Fixed submission:
def main():
 A, B = map(int, input().split())
 print(A-2*B) if A > 2*B else print(0)
  
main()

Buggy submission (verdict: Runtime Error):
A, B = map(int, input().split())
 print(A-2*B) if A > 2*B else print(0)

Buggy submission (verdict: Runtime Error):
def main():
A, B = map(int, input().split())
 print(A-2*B) if A > 2*B else print(0)
  
main()

Buggy submission (verdict: Runtime Error):
def main():
A, B = map(int, input().split())
 print(A-2*B) if A > 2*B else print("0")
  
mail()

Buggy submission (verdict: Runtime Error):
A, B = map(int, input().split())
 print(A-2*B) if A > 2*B else print("0")
Problem p02953 (python)

Fixed submission:
n = int(input())
h = list(map(int, input().split()))
for i in reversed(range(n-1)):
    if h[i+1] == h[i] - 1:
        h[i] = h[i] - 1
flag = True
for i in range(n-1):
    if h[i+1] < h[i]:
        flag = False
        break
if flag == True:
    print('Yes')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
n = int(input())
h = list(map(int, input().split()))
for i in range(n-1):
    if h[i+1] == h[i] - 1:
        h[i] = h[i] - 1
flag = True
for i in range(n):
    if h[i+1] < h[i]:
        flag = False
        break
if flag == True:
    print('Yes')
else:
    print('No')
Problem p03000 (python)

Fixed submission:
n, x = map(int, input().split())
l =list(map(int, input().split()))
d = [0]
for i in range(n):
    d.append(d[i]+l[i])
ans = 0
for i in range(n+1):
    if d[i] <= x:
        ans += 1
print(ans)

Buggy submission (verdict: Runtime Error):
n, x = map(int, input().split())
l =list(map(int, input().split()))
d = [0]
for i in range(n+1):
    d.append(d[i]+l[i])
ans = 0
for i in range(n+1):
    if d[i] <= x:
        ans += 1
print(ans)
Problem p02717 (python)

Fixed submission:
x = list(map(int, input().split()))
print(x[2],x[0],x[1])

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
a = list(map(int, input().split()))
ans = "Yes"

a.sort(reverse=True)

for i in range(m):
    if a[i] < sum(a)*(1/(4*m)):
        ans = "No"
        break

print(ans)

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
a = list(map(int, input().split()))
a.sort(reverse = True)
ans = "Yes"
for i in range(m):
    if a[i] < sum(a)*(1/(4*m)):
        ans = "No"
        break
print(ans)
Problem p02888 (python)

Fixed submission:
def d():
    n = int(input())
    ls = list(map(int, input().split()))
    ls.sort()
    count = 0
    for i in range(n-1):
        k = i + 2
        for j in range(i+1, n-1):
            while k < n and ls[i] + ls[j] > ls[k]:
                k += 1
            count += k - j - 1

    print(count)


if __name__ == '__main__':
    d()

Buggy submission (verdict: Runtime Error):
from _bisect import bisect_right


def d():
    n = int(input())
    ls = list(map(int, input().split()))
    ls.sort()
    count = 0
    for i in range(n-1, -1, -1):
        for j in range(i-1, -1, -1):
            k = bisect_right(ls, ls[i]-ls[j])
            if j >= k:
                count += j - k

    print(count)
    

if __name__ == '__main__':
    d()