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

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

Buggy submission (verdict: Runtime Error):
class Imos:
    def __init__(self, n):
        self.B = [0] * n
        self.n = n
        from itertools import accumulate
        self.ac = accumulate

    def __call__(self, l, r):
        l, r = max(l, 0), min(r, self.n - 1)
        self.B[l] += 1
        if r + 1 != self.n:
            self.B[r + 1] -= 1

    def out(self):
        *res, = self.ac(self.B)
        return res

from collections import defaultdict
d = defaultdict(list)
imos = Imos(10 ** 5 + 1)

(N, C), *D = [[*map(int, o.split())] for o in open(0)]
for s, t, c in D:
    d[c] += (s, t),
for p in d.values():
    p.sort()
    ps, pt = p[0]
    for s, t in p[1:] + [[0,0]]:
        if pt == s:
            pt = t
        else:
            imos(ps, pt)
            ps, pt = s, t
print(max(imos.out()))
Problem p03547 (python)

Fixed submission:
a, b = input().split()
print(["<>"[a > b], "="][a == b])

Buggy submission (verdict: Runtime Error):
a, b = input().split()
print(["<>"[a > b], "="][a = b])
Problem p03563 (python)

Fixed submission:
print(-int(input()) + int(input())*2)

Buggy submission (verdict: Runtime Error):
print(-int(input()) + int(input()*2)
Problem p03565 (python)

Fixed submission:
import re
s, t = input().replace('?', '.'), input()
l, m = len(s), len(t)

if l < m:
    print("UNRESTORABLE")
    exit()

can = []  # candidates
for i in range(l - m + 1):
    if re.match(s[i:i + m], t):
        can.append((s[:i] + t + s[i + m:]).replace('.', 'a'))
print(min(can) if can else "UNRESTORABLE")

Buggy submission (verdict: Runtime Error):
s,t=input(),input();l,m=len(s),len(t)
for i in range(l-m+1):
 if all(c in"?"+d for c,d in zip(S[-i-m:],t)):s=s.replace(*"?a");exit(print(s[:-i-m]+t+s[l-i:]))
print("UNRESTORABLE")

Buggy submission (verdict: Runtime Error):
import re
s, t = input().replace('?', '.'), input()
l, m = len(s), len(t)

if l < m:
    print("UNRESTORABLE")
    exit()

can = []  # candidates
for i in range(l - m + 1):
    if re.match(s[i:i + m], t)
        can.append((s[:i] + t + s[i + m:]).replace('.', 'a'))
print(min(can) if can else "UNRESTORABLE")
Problem p03577 (python)

Fixed submission:
print(input()[:-8])

Buggy submission (verdict: Runtime Error):
from collections import*
i = eval("Counter(list(map(int, input().split()))),"*4)
print("YNEOS"[i[3]-i[1] != {}::2])
Problem p03583 (python)

Fixed submission:
N = int(input())
for h in range(3500):
  for n in range(h):
    try:w = (N*h*n) / (4*n*h - N*n - N*h)
    except ZeroDivisionError: continue
    if w>0 and w.is_integer():
      print(h, n, int(w))
      exit()

Buggy submission (verdict: Runtime Error):
N = int(input())
for h in range(3500):
  for n in range(n):
    try:w = (N*h*n) / (4*n*h - N*n - N*h)
    except ZeroDivisionError: continue
    if w>0 and w.is_integer():
      print(h, n, int(w))
      exit()

Buggy submission (verdict: Runtime Error):
N = int(input())
for h in range(3500):
  for n in range(3500):
    w = (N*h*n) / (4*n*h - N*n - N*h)
    if w>0 and w.is_integer():
      print(h, n, int(w))

Buggy submission (verdict: Runtime Error):
N = int(input())
for h in range(3500):
  for n in range(3500):
    w = (N*h*n) / (4*n*h - N*n - N*h)
    if w>0 and w.is_integer:
      print(h, n, int(w))
Problem p03612 (python)

Fixed submission:
#!/usr/bin/env python3
n, *p = map(int, open(0).read().split())
c = 0
for i in range(n):
    if p[i] == -~i:
        if i == ~-n:
            p[i], p[i-1] = p[i-1], p[i]
        else:
            p[i], p[i+1] = p[i+1], p[i]
        c += 1
print(c)

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3
n, *p = map(int, open(0).read().split())
c = 0
for i in range(n):
    if p[i] == i + 1:
        p[i], p[i+1] = p[i+1], p[i]
        c += 1
print(c)
Problem p03633 (python)

Fixed submission:
from functools import reduce
from fractions import gcd
def lcm(a,b):
    return a * b // gcd(a,b)
n = int(input())
print(reduce(lcm, [int(input()) for i in range(n)]))

Buggy submission (verdict: Runtime Error):
from fractions import gcd
def lcm(a,b):
    return a * b // gcd(a,b)
n = int(input())
print(reduce(lcm, [int(input()) for i in range(n)]))
Problem p03637 (python)

Fixed submission:
n, *a = map(int, open(0).read().split())
s = [i%4 for i in a]
f, t = s.count(0), s.count(2)
print("YNeos"[n-f-t+(t>0) > f+1::2])

Buggy submission (verdict: Runtime Error):
n, *a = map(int, open(0).read().split())
s = [i%4 for a]
f, k = s.count(0), s.count(2)
print("YNeos"[n-f-k > f+(k>0)::2])
Problem p03699 (python)

Fixed submission:
_, *s = map(int, open(0))
S = sum(s)
t = [i for i in s if i%10]
print(S if S%10 else S-min(t) if t else 0)

Buggy submission (verdict: Runtime Error):
_, s = map(int, open(0))
S = sum(s)
t = [i for i in s if i%10]
print(S if S%10 else S-min(t) if t else 0)
Problem p03711 (python)

Fixed submission:
p = "_acababaababa"
x, y = map(int, input().split())
print("YNeos"[p[x]!=p[y]::2])

Buggy submission (verdict: Runtime Error):
p = "_acababababa"
x, y = map(int, input().split())
print("YNeos"[p[x]!=p[y]::2])
Problem p03733 (python)

Fixed submission:
n, T, *t = map(int, open(0).read().split())
print(sum(min(t[i+1] - t[i], T) for i in range(n-1)) + T)

Buggy submission (verdict: Runtime Error):
n, T, *t = map(int, open(0).read().split())
print(sum(min(t[i+1] - t[i], T) for i in range(n)))
Problem p03738 (python)

Fixed submission:
a, b = map(int, open(0))
print([["LESS","GREATER"][a>b], "EQUAL"][a==b])

Buggy submission (verdict: Runtime Error):
s = open(0).read()
def t(c): return eval(s.replace("\n",c))
print([["LESS","GREATER"][t(">")], "EQUAL"][t("==")])

Buggy submission (verdict: Runtime Error):
s = open(0).read()
def t(c): return eval(s.replace("\n",c))
print([["LESS","GREATER"][t(">")], "EQUAL"][t("==")])

Buggy submission (verdict: Runtime Error):
s = open(0).read()
def t(c): return eval(s.replace("\n",c))
print([["LESS","GREATER"][t(">")], "EQUAL"][t("==")])
Problem p03814 (python)

Fixed submission:
s = input()
print(s.rfind("Z")-s.find("A")+1)

Buggy submission (verdict: Runtime Error):
s = input()
print(s.rfind(z)-s.find(a)+1)
Problem p03827 (python)

Fixed submission:
n = int(input())
s = input()
x = m = 0
for i in range(n): x += [-1,1][s[i] == "I"]; m = max(m,x)
print(m)

Buggy submission (verdict: Runtime Error):
n = int(input())
s = input()
x = m = 0
for i range(n): x += [-1,1][s[i] == I]; m = max(m,x)
print(m)
Problem p03919 (python)

Fixed submission:
_, w, *s = open(0).read().split()
a, b = divmod(s.index("snuke"), int(w))
print(chr(65+b), a+1, sep="")

Buggy submission (verdict: Runtime Error):
_, w, *s = open(0).read().split()
a, b = divmod(s.index("snuke"), int(w))
print("ABCDEFGHIJJ"[b], a+1, sep="")
Problem p03957 (python)

Fixed submission:
import re
print("Yes" if re.search("C\w*F", input()) else "No")

Buggy submission (verdict: Runtime Error):
k, _, *a = map(int, open(0).read().split())
print(max(a)*2 - k - 1)
Problem p03994 (python)

Fixed submission:
s, k, t = input(), int(input()), ""
for q in s:
    if (p := (123 - ord(q)) % 26) <= k:
        k -= p
        t += "a"
    else:
        t += q
print(t[:-1] + chr((ord(t[-1]) - 97 + k) % 26 + 97))

Buggy submission (verdict: Runtime Error):
s,k,t=input(),int(input()),""
for q in s:
 if(p:=(123-ord(q))%26)<=k:t+="a";k-=p
 else:t+=q
*a,b=t
print(a+chr((ord(b)-97+k)%26+97))

Buggy submission (verdict: Runtime Error):
s,k,t=input(),int(input()),""
for q in s:
 if(p:=(123-ord(q))%26)<=k:n+="a";K-=i
 else:n+=c
print(t[:-1]+chr((ord(t[-1])-97+k)%26+97))
Problem p04020 (python)

Fixed submission:
from itertools import*
_, *a = map(int, open(0))
print(sum(sum(l)//2 for _, l in groupby(a, key=lambda x:x>0)))

Buggy submission (verdict: Runtime Error):
k,s=open(0);n,r=map(int,k.split());a=0
while n>0:
 n-=1
 if s[n]<"o":n-=~-r;a=-~max(a,n)
print(a)
Problem p02555 (python)

Fixed submission:
n=int(input())
p=10**9+7
l=[1]*(2001)
l[1],l[2]=0,0
s=1
for i in range(6,2001):
    l[i]+=s
    l[i]%=p
    s+=l[i-2]
print(l[n])

Buggy submission (verdict: Runtime Error):
n=int(input())
r=[list(map(int,input().split())) for _ in range(n)]
a,c,b,d=0,10**10,0,10**10
for i in range(n):
    x,y=r[i]
    a=max(a,x+y)
    c=min(c,x+y)
    b=max(b,x-y)
    d=min(d,x-y)
    d=max(0,d)
print(abs(max(a-c,b-d)))
Problem p02621 (python)

Fixed submission:
a=int(input())
print(a+a**2+a**3)

Buggy submission (verdict: Runtime Error):
#include <iostream>
using namespace std;

int main()
{
	int a;
	cin >> a;
	cout << a * a + a + a * a * a <<endl;
}
Problem p02640 (python)

Fixed submission:
x,y=map(int,input().split())
for i in range(x+1):
    if 4*i+(x-i)*2==y:
        print("Yes")
        exit()
print("No")

Buggy submission (verdict: Runtime Error):
x,y=map(int,input().split())
for i in range(x+1):
    if 4*i+(x-i)*2=y:
        print("Yes")
        exit()
print("No")
Problem p02642 (python)

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
a.sort()
am=max(a)
dp=[[True,0] for _ in range(am+1)]
count=0
for i in a:
    if dp[i][0]==False:
        continue
    else:
        if dp[i][1]==1:
            dp[i][0]=False
            count-=1
        else:
            dp[i][1]=1
            count+=1
            for j in range(2*i,am+1,i):
                dp[j][0]=False
print(count)

Buggy submission (verdict: Runtime Error):
n=int(input())
a=list(map(int,input().split()))
a.sort()
am=a[-1]
count=0
trush=set()
for i in range(len(a)):
    if a[i] in trush:
        continue
    if i>=1:
        if a[i-1]==a[i]:
            continue
    elif a[i]==a[i+1]:
        continue
    count+=1
    for j in range(a[i],am+1,a[i]):
        trush.add(j)
print(count)
Problem p02658 (python)

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
if 0 in a:
    print("0")
    exit()
else:
    ans=1
    for i in range(n):
        ans*=a[i]
        if ans>10**18:
            print("-1")
            exit()
    print(ans)

Buggy submission (verdict: Runtime Error):
n=int(input())
a=list(map(int,input().split()))]
if 0 in a:
    print("0")
    exit()
else:
    ans=1
    for i in range(n):
        ans*=a[i]
        if ans>10**18:
            print("-1")
            exit()

Buggy submission (verdict: Runtime Error):
n=int(input())
a=list(map(int,input().split()))]
if 0 in a:
    print("0")
    exit()
else:
    ans=1
    for i in range(n):
        ans*=a[i]
        if ans>10**18:
            print("-1")
            exit()

Buggy submission (verdict: Runtime Error):
n=int(input())
a=list(map(int,input().split()))]
if 0 not in a:
    ans=1
    for i in range(n):
        ans*=a[i]
        if ans>10**18:
            print("-1")
            exit()
    print(ans)
    exit()
else:
    print("0")

Buggy submission (verdict: Runtime Error):
n=int(input())
a=list(map(int,input().split()))]
if 0 not in a:
    ans=1
    for i in range(n):
        ans*=a[i]
        if ans>10**18:
        print("-1")
        exit()
    print(ans)
else:
    print("0")

Buggy submission (verdict: Runtime Error):
n=int(input())
a=list(map(int,input().split()))]
if 0 not in a:
    ans=1
    for i in range(n):
        ans*=a[i]
        if ans>10**18:
        print("-1")
        exit()
    print(ans)
else:
    print("0")

Buggy submission (verdict: Runtime Error):
n=int(input())
a=list(map(int,input().split()))
ans=1
for i in range(n):
    if ans<=10**18:
        ans*=a[i]
    elif ans>10**18
        print("-1")
        exit()
print(ans)

Buggy submission (verdict: Runtime Error):
n=int(input())
a=list(map(int,input().split()))
ans=1
for i in range(n):
    if ans<=10**18:
        ans*=a[i]
    elif ans>10**18
        print("-1")
print(ans)

Buggy submission (verdict: Runtime Error):
n=int(input())
a=list(map(int,input().split()))
ans=1
for i in range(n):
    ans=ans*a[i]
if len(ans)>19:
    print("-1")
    exit()
print(ans)
Problem p02761 (python)

Fixed submission:
n,m=map(int,input().split())
l=[list(map(int,input().split())) for _ in range(m)]
for i in range(1001):
    i=str(i)
    if len(i)!=n:
        continue
    f=1
    for s,c in l:
        c=str(c)
        if len(i)<s:
            f=0
            break
        if not i[s-1]==c:
            f=0
            break
    if f:
        print(i)
        exit()
print("-1")

Buggy submission (verdict: Runtime Error):
n,m=map(int,input().split())
q=[list(map(int,input().split())) for _ in range(m)]
for i in range(10**n):
    i=str(i)
    f=1
    for j in q:
        if i[j[0]-1]!=str(j[1]):
            f=0
            break
    if f:
        print(i)
        exit()
print("-1")
Problem p02802 (python)

Fixed submission:
n,m=map(int,input().split())
a=[[0,0] for _ in range(n+1)]
x=[]
for i in range(m):
    x.append(list(input().split()))
    x[i][0]=int(x[i][0])
for i in range(m):
    if x[i][1]=="AC":
        a[x[i][0]][1]=1
    else:
        if a[x[i][0]][1]==1:
            continue
        else:
            a[x[i][0]][0]+=1
c=0
d=0
for i in range(n+1):
    c+=a[i][1]
    if a[i][1]:
        d+=a[i][0]
print(c,d)

Buggy submission (verdict: Runtime Error):
n,m=map(int,input().split())
a=[(0,0) for _ in range(n+1)]
x=[]
for i in range(m):
    x.append(list(input().split()))
    x[i][0]=int(x[i][0])
for i in range(m):
    if x[i][1]=="AC":
        a[x[i][0]][1]=1
    else:
        if a[x[i][0]][1]==1:
            continue
        else:
            a[x[i][0]][0]+=1
c=0
d=0
for i in range(n+1):
    c+=a[i][1]
    if a[i][1]:
        d+=a[i][0]
print(c,d)
Problem p02813 (python)

Fixed submission:
import itertools
n=int(input())
a=[]
for i in range(n):
    a.append(i+1)
b=[]
for per in itertools.permutations(a):
    b.append(list(per))
c=b.index(list(map(int,input().split())))
d=b.index(list(map(int,input().split())))
print(abs(c-d))

Buggy submission (verdict: Runtime Error):
import itertools
n=int(input())
a=[]
for i in range(n):
    a.append(i+1)
b=[]
for per in itertools.permutatiton(a):
    b.append(list(per))
c=b.index(list(map(int,input().split())))
d=b.index(list(map(int,input().split())))
print(abs(c-d))
Problem p02936 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10**7)
n,q=map(int,input().split())
edge=[[] for _ in range(n)]
for i in range(n-1):
    x,y=map(int,input().split())
    edge[x-1].append(y-1)
    edge[y-1].append(x-1)
ans=[0]*n
for i in range(q):
    p,x=map(int,input().split())
    ans[p-1]+=x
def dfs(c,p):
    for i in edge[c]:
        if i==p:
            continue
        ans[i]+=ans[c]
        dfs(i,c)
dfs(0,-1)
print(*ans)

Buggy submission (verdict: Runtime Error):
n,q=map(int,input().split())
edge=[[] for _ in range(n)]
for i in range(n-1):
    x,y=map(int,input().split())
    edge[x-1].append(y-1)
    edge[y-1].append(x-1)
ans=[0]*n
for i in range(q):
    p,x=map(int,input().split())
    ans[p-1]+=x
def dfs(c,p):
    for i in edge[c]:
        if i==p:
            continue
        ans[i]+=ans[c]
        dfs(i,c)
dfs(0,-1)
print(*ans)

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**5+5)
n,q=map(int,input().split())
edge=[[] for _ in range(n)]
for i in range(n-1):
    x,y=map(int,input().split())
    edge[x-1].append(y-1)
    edge[y-1].append(x-1)
ans=[0]*n
def count(p,x):
    ans[p]+=x
    for i in edge[p]:
        if i<p:
            continue
        count(i,x)
for i in range(q):
    p,x=map(int,input().split())
    count(p-1,x)
print(*ans)

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**10+5)
n,q=map(int,input().split())
edge=[[] for _ in range(n)]
for i in range(n-1):
    x,y=map(int,input().split())
    edge[x-1].append(y-1)
    edge[y-1].append(x-1)
ans=[0]*n
def count(p,x):
    ans[p]+=x
    for i in edge[p]:
        if i<p:
            continue
        count(i,x)
for i in range(q):
    p,x=map(int,input().split())
    count(p-1,x)
print(*ans)

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**10+5)
n,q=map(int,input().split())
edge=[[] for _ in range(n)]
for i in range(n-1):
    x,y=map(int,input().split())
    edge[x-1].append(y-1)
    edge[y-1].append(x-1)
ans=[0]*n
def count(p,x):
    ans[p]+=x
    for i in edge[p]:
        if i<p:
            continue
        count(i,x)
for i in range(q):
    p,x=map(int,input().split())
    count(p-1,x)
print(*ans)
Problem p03262 (python)

Fixed submission:
n,x=map(int,input().split())
a=list(map(int,input().split()))
b=[]
if n==1 and x==a[0]:
    print(max(x,10**9-x))
    exit()
for i in range(n):
    b.append(abs(a[i]-x))
import math
c=0
for i in range(n):
    c=math.gcd(c,b[i])
    if c==1:
        break
print(c)

Buggy submission (verdict: Runtime Error):
import math
def ggcd(a):
    if len(a)==0:
        return 0
    i=0
    return math.gcd(a[i],ggcd(a[i+1:]))
n,x=map(int,input().split())
a=list(map(int,input().split()))
b=[]
for i in range(n-1):
    b.append(abs(a[i]-a[i+1]))
c=ggcd(b)
d=abs(x-a[0])
print(math.gcd(c,d))
Problem p03698 (python)

Fixed submission:
s=input()
w=set()
for i in range(len(s)):
    w.add(s[i])
if len(s)==len(w):
    print("yes")
else:
    print("no")

Buggy submission (verdict: Runtime Error):
s=input()
w=set()
for i in (len(s)):
    w.add(s[i])
if len(s)==len(w):
    print("Yes")
else:
    print("No")
Problem p02564 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10**9)
def SCC(G):
  D=[]
  C=[len(G)-1]
  U=[1]*len(G)
  def DFS(x):
    if U[x]:
      U[x]=0
      for i in range(len(G[x])):
        DFS(G[x][i])
      D.append(x)
  
  for i in range(len(G)):
    if U[i]:
      DFS(i)
  GR=[[] for i in range(len(G))]
  for i in range(N):
    for j in range(len(G[i])):
      GR[G[i][j]].append(i)
  R=[]
  U=[1]*len(G)
  def DFSR(x):
    if U[x]:
      R[-1].append(x)
      U[x]=0
      for i in range(len(GR[x])):
        DFSR(GR[x][i])
  
  for i in range(len(G)-1,-1,-1):
    if U[D[i]]:
      R.append([])
      DFSR(D[i])
  return R

S=sys.stdin.readlines()
N,M=map(int,S[0].split())
G=[[] for i in range(N)]
a,b=0,0
for i in range(M):
  a,b=map(int,S[i+1].split())
  G[a].append(b)
P=SCC(G)
print(len(P))
for i in range(len(P)):
  print(*([len(P[i])]+P[i]))

Buggy submission (verdict: Runtime Error):
def SCC(G):
  D=[]
  C=[len(G)-1]
  U=[1]*len(G)
  def DFS(x):
    if U[x]:
      U[x]=0
      for i in range(len(G[x])):
        DFS(G[x][i])
      D.append(x)
  
  for i in range(len(G)):
    if U[i]:
      DFS(i)
  GR=[[] for i in range(len(G))]
  for i in range(N):
    for j in range(len(G[i])):
      GR[G[i][j]].append(i)
  R=[]
  U=[1]*len(G)
  def DFSR(x):
    if U[x]:
      R[-1].append(x)
      U[x]=0
      for i in range(len(GR[x])):
        DFSR(GR[x][i])
  
  for i in range(len(G)-1,-1,-1):
    if U[D[i]]:
      R.append([])
      DFSR(D[i])
  return R

import sys
S=sys.stdin.readlines()
N,M=map(int,S[0].split())
G=[[] for i in range(N)]
a,b=0,0
for i in range(M):
  a,b=map(int,S[i+1].split())
  G[a].append(b)
P=SCC(G)
print(len(P))
for i in range(len(P)):
  print(*([len(P[i])]+P[i]))
Problem p02614 (python)

Fixed submission:
H,W,K=map(int,input().split())
S=[input() for i in range(H)]
P=0
Q=0
for i in range(1<<H):
  for j in range(1<<W):
    Q=0
    for k in range(H):
      for l in range(W):
        if S[k][l]=='#' and i&(1<<k)!=0 and j&(1<<l)!=0:
          Q+=1
    if Q==K:
      P+=1
print(P)

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

def dft(f,x):
  if len(f)==1:
    return
  f0,f1=f[0::2],f[1::2]
  dft(f0,x)
  dft(f1,x)
  z=rect(1,x*2*acos(-1)/len(f))
  n=1+0j
  for i in range(len(f)):
    f[i]=f0[i%len(f0)]+n*f1[i%len(f1)]
    n=n*z

def pm(p,q):
  siz=1
  while len(p)+len(q)>siz:
    siz*=2
  np=[]
  nq=[]
  for i in range(len(p)):
    np.append(rect(p[i],0))
  for i in range(len(q)):
    nq.append(rect(q[i],0))
  while len(np)<siz:
    np.append(0+0j)
  while len(nq)<siz:
    nq.append(0+0j)
  dft(np,1)
  dft(nq,1)
  for i in range(siz):
    np[i]=np[i]*nq[i]
  dft(np,-1)
  EPS=0.1
  for i in range(siz):
    np[i]=int(np[i].real/siz+EPS)
  return np

H,W,K=map(int,input().split())
C=[input() for i in range(H)]
DP=0
X=[]
P=0

def poly(x):
  r=[0]*x
  r.append(1)
  r[0]+=1
  return r

def knapsack(L):
  if len(L)==1:
    return poly(L[0])
  a=knapsack(L[:len(L)//2])
  b=knapsack(L[len(L)//2:])
  return pm(a,b)[:K+1]

for i in range(1,1<<H):
  X=[0]*W
  for j in range(H):
    if i&(1<<j):
      for k in range(W):
        if C[j][k]=='#':
          X[k]+=1
  DP=knapsack(X)[K]
  if len(DP)>K:
    P+=DP[K]
print(P)

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

def dft(f,x):
  if len(f)==1:
    return
  f0,f1=f[0::2],f[1::2]
  dft(f0,x)
  dft(f1,x)
  z=rect(1,x*2*acos(-1)/len(f))
  n=1+0j
  for i in range(len(f)):
    f[i]=f0[i%len(f0)]+n*f1[i%len(f1)]
    n=n*z

def pm(p,q):
  siz=1
  while len(p)+len(q)>siz:
    siz*=2
  np=[]
  nq=[]
  for i in range(len(p)):
    np.append(rect(p[i],0))
  for i in range(len(q)):
    nq.append(rect(q[i],0))
  while len(np)<siz:
    np.append(0+0j)
  while len(nq)<siz:
    nq.append(0+0j)
  dft(np,1)
  dft(nq,1)
  for i in range(siz):
    np[i]=np[i]*nq[i]
  dft(np,-1)
  EPS=0.1
  for i in range(siz):
    np[i]=int(np[i].real/siz+EPS)
  return np

H,W,K=map(int,input().split())
C=[input() for i in range(H)]
DP=[0]*(K+1)
X=[]
P=0

def poly(x):
  r=[0]*x
  r.append(1)
  r[0]+=1
  return r

def knapsack(L):
  if len(L)==1:
    return poly(L[0])
  a=knapsack(L[:len(L)//2])
  b=knapsack(L[len(L)//2:])
  return pm(a,b)[:K+1]

for i in range(1,1<<H):
  X=[0]*W
  for j in range(H):
    if i&(1<<j):
      for k in range(W):
        if C[j][k]=='#':
          X[k]+=1
  P+=knapsack(X)[K]
print(P)
Problem p02675 (python)

Fixed submission:
print(('pphbhhphph'[int(input()[-1])])+'on')

Buggy submission (verdict: Runtime Error):
print(('pphbhhphph'[int(input())])+'on')
Problem p03148 (python)

Fixed submission:
from heapq import *
import sys
sys.setrecursionlimit(10**6)
I=sys.stdin.readlines()
N,K=map(int,I[0].split())
t,d=0,0
X=[]
for i in range(N):
  t,d=map(int,I[i+1].split())
  X.append((d,t))
X.sort()
Q=[]
heapify(Q)
C=[0]*N
V=0
S=0
for i in range(K):
  heappush(Q,X[-1])
  if C[X[-1][1]-1]==0:
    V+=1
  S+=X[-1][0]
  C[X[-1][1]-1]+=1
  del X[-1]
def f(q,c,s,x,v):
  y=0
  r=s+v*v
  for i in range(len(q)):
    y=heappop(q)
    if c[y[1]-1]>=2:
      s-=y[0]
      c[y[1]-1]-=1
      break
    if len(q)==0:
      return r
  for i in range(len(x)):
    if c[x[-1][1]-1]==0:
      heappush(q,x[-1])
      s+=x[-1][0]
      c[x[-1][1]-1]=1
      v+=1
      del x[-1]
      return max(r,f(q,c,s,x,v))
    del x[-1]
  return r
print(f(Q,C,S,X,V))

Buggy submission (verdict: Runtime Error):
from heapq import *
import sys
I=sys.stdin.readlines()
N,K=map(int,I[0].split())
t,d=0,0
X=[]
for i in range(N):
  t,d=map(int,I[i+1].split())
  X.append((d,t))
X.sort()
Q=[]
heapify(Q)
C=[0]*N
V=0
S=0
for i in range(K):
  heappush(Q,X[-1])
  if C[X[-1][1]-1]==0:
    V+=1
  S+=X[-1][0]
  C[X[-1][1]-1]+=1
  del X[-1]
def f(q,c,s,x,v):
  y=0
  r=s+v*v
  for i in range(len(q)):
    y=heappop(q)
    if c[y[1]-1]>=2:
      s-=y[0]
      c[y[1]-1]-=1
      break
    if len(q)==0:
      return r
  for i in range(len(x)):
    if c[x[-1][1]-1]==0:
      heappush(q,x[-1])
      s+=x[-1][0]
      c[x[-1][1]-1]=1
      v+=1
      del x[-1]
      return max(r,f(q,c,s,x,v))
    del x[-1]
  return r
print(f(Q,C,S,X,V))
Problem p03166 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10**9)
N,M=map(int,input().split())
G=[[] for i in range(N)]
a,b=0,0
for i in range(M):
  a,b=map(int,input().split())
  G[b-1].append(a-1)
DP=[-1]*N
def f(x):
  if DP[x]!=-1:
    return DP[x]
  DP[x]=0
  for i in range(len(G[x])):
    DP[x]=max(DP[x],f(G[x][i])+1)
  return DP[x]

for i in range(N):
  f(i)
print(max(DP))

Buggy submission (verdict: Runtime Error):
N,M=map(int,input().split())
G=[[] for i in range(N)]
a,b=0,0
for i in range(M):
  a,b=map(int,input().split())
  G[b-1].append(a-1)
DP=[-1]*N
def f(x):
  if DP[x]!=-1:
    return DP[x]
  DP[x]=0
  for i in range(len(G[x])):
    DP[x]=max(DP[x],f(G[x][i])+1)
  return DP[x]

for i in range(N):
  f(i)
print(max(DP))