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

Fixed submission:
MOD = 998244353

def zeta_gcd(a,primes):
    n = len(a)-1
    for p in primes:
        for i in range(n//p,0,-1):
            a[i] += a[p*i]
            a[i] %= MOD
def mobius_gcd(a,primes):
    n = len(a)
    for p in primes:
        for i in range(1,n):
            if i*p >= n: break
            a[i] -= a[p*i] 
            a[i] %= MOD
def get_primes(n):
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    return [i for i in range(n + 1) if is_prime[i]]

NNN = 10**6 + 1
inverse = [0, 1]
for i in range( 2, NNN + 1 ):
    inverse.append( ( -inverse[MOD % i] * (MOD//i) ) % MOD )

N, = map(int, input().split())
X = list(map(int, input().split()))
primes = get_primes(NNN)
fs = [0]*NNN
for x in X:
    fs[x] += x
#print(fs)
zeta_gcd(fs, primes)
#print(fs)
for i, x in enumerate(fs):
    fs[i] = x**2
#print(fs)
mobius_gcd(fs, primes)
#print(fs)
r = 0
for i, f in enumerate(fs[1:]):
    i += 1
    r = (r + f*inverse[i]) % MOD
for x in X:
    r = (r - x) % MOD

print((r*inverse[2])%MOD)

Buggy submission (verdict: Runtime Error):
MOD = 998244353

def zeta_gcd(a,primes):
    n = len(a)-1
    for p in primes:
        for i in range(n//p,0,-1):
            a[i] += a[p*i]
            a[i] %= MOD
def mobius_gcd(a,primes):
    n = len(a)
    for p in primes:
        for i in range(1,n):
            if i*p >= n: break
            a[i] -= a[p*i] 
            a[i] %= MOD
def get_primes(n):
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    return [i for i in range(n + 1) if is_prime[i]]

NNN = 10**6
inverse = [0, 1]
for i in range( 2, NNN + 1 ):
    inverse.append( ( -inverse[MOD % i] * (MOD//i) ) % MOD )

N, = map(int, input().split())
X = list(map(int, input().split()))
primes = get_primes(NNN)
fs = [0]*NNN
for x in X:
    fs[x] += x
#print(fs)
zeta_gcd(fs, primes)
#print(fs)
for i, x in enumerate(fs):
    fs[i] = x**2
#print(fs)
mobius_gcd(fs, primes)
#print(fs)
r = 0
for i, f in enumerate(fs[1:]):
    i += 1
    r = (r + f*inverse[i]) % MOD
for x in X:
    r = (r - x) % MOD

print((r*inverse[2])%MOD)
Problem p02920 (python)

Fixed submission:
import sys
def b(bs, cs):
    d = set()
    bl, cl = len(bs), len(cs)
    bi, ci = 0, 0
    ncs = []
    while True:
      if bs[bi] > cs[ci]:
        bs.append(cs[ci])
        bi += 1
      else:
        ncs.append(cs[ci])
      ci += 1
      if bi == bl or ci == cl:
        break
    if len(bs) != 2 * bl:
      print("No")
      sys.exit()
    return bs, ncs + cs[ci:]

n=int(input())
xs = sorted(list(map(int,input().split())))[::-1]
bs, cs = xs[:1], xs[1:]
for _ in range(n):
    bs, cs = b(sorted(bs)[::-1], cs)

print("Yes")

Buggy submission (verdict: Runtime Error):
import sys
def b(bs, cs):
    #print(bs, xs[len(bs):])
    d = set()
    bl, cl = len(bs), len(cs)
    bi, ci = 0, 0
    while True:
      if bs[bi] > cs[ci]:
        bi += 1
        bs.append(cs[ci])
        del cs[ci]
      else:
        ci += 1
      if bi == bl or ci == len(cs):
        break
    if len(bs) != 2 * bl:
      print("No")
      sys.exit()
    return bs, cs

n=int(input())
xs = sorted(list(map(int,input().split())))[::-1]
bs, cs = xs[:1], xs[1:]
for _ in range(n):
    bs, cs = b(sorted(bs)[::-1], sorted[cs][::-1])

print("Yes")

Buggy submission (verdict: Runtime Error):
import sys
def b(bs, cs):
    #print(bs, xs[len(bs):])
    d = set()
    bl, cl = len(bs), len(cs)
    bi, ci = 0, 0
	while True:
      if bs[bi] > cs[ci]:
        bi += 1
        bs.append(cs[ci])
        del cs[i]
      else:
        ci += 1
      if bi == bl or ci == cs:
        break
    if len(bs) != 2 * bl:
      print("No")
      sys.exit()
    return bs, cs

n=int(input())
xs = sorted(list(map(int,input().split())))[::-1]
bs, cs = xs[:1], xs[1:]
for _ in range(n):
    bs, cs = b(bs, cs)

print("Yes")
Problem p02930 (python)

Fixed submission:
N=int(input())
for i in range(N):
    i = i + 1
    for j in range(N-i):
        j = i+j+1
        for k in range(9):
            if i % (2**(k+1)) != j % (2**(k+1)):
                print(k+1, end=" ")
                break
    print()

Buggy submission (verdict: Runtime Error):
n=int(input())
for i in range(N):
    i = i + 1
    for j in range(N-i):
        j = i+j+1
        for k in range(9):
            if i % (2**(k+1)) != j % (2**(k+1)):
                print(k+1, end=" ")
                break
    print()
Problem p02936 (python)

Fixed submission:
import sys
sys.setrecursionlimit(300000)
input = sys.stdin.readline
n,q=map(int,input().strip().split())
d=[[] for _ in range(n)]

for _ in range(n-1):
    a,b=map(int,input().split())
    d[a-1].append(b-1)
    d[b-1].append(a-1)
l=[0]*n
for _ in range(q):
    a,b=map(int,input().split())
    l[a-1]+=b
rs=[0]*n

def rr(pa,s,dd,d):
    for c in d[s]:
        if c == pa:
            continue
        rs[c]=l[c]+dd
#        print(c,rs[c],dd)
        rr(s,c,dd+l[c],d)

s,dd=0,l[0]
rs[0] = l[0]
rr(None,s,dd,d)
for r in rs:
    print(r)

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(100000)
input = sys.stdin.readline
n,q=map(int,input().strip().split())
d=[[] for _ in range(n)]

for _ in range(n-1):
    a,b=map(int,input().split())
    d[a-1].append(b-1)
    d[b-1].append(a-1)
l=[0]*n
for _ in range(q):
    a,b=map(int,input().split())
    l[a-1]+=b
rs=[0]*n

def rr(pa,s,dd,d):
    for c in d[s]:
        if c == pa:
            continue
        rs[c]=l[c]+dd
#        print(c,rs[c],dd)
        rr(s,c,dd+l[c],d)

s,dd=0,l[0]
rs[0] = l[0]
rr(None,s,dd,d)
for r in rs:
    print(r)
Problem p02957 (python)

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

Buggy submission (verdict: Runtime Error):
k = int(input())
x, y = [int(x) for x in input().strip().split(" ")]
x, y = x-y, x+y

def main():
    if k % 2 == 0:
        if x % 2 != 0:
            return -1
    return to(x,y)

def cc(x, xs):
        if abs(x-xs) <= 2*k:
            if abs(x+k-xs) % 2 == k % 2:
                if abs(x+k-xs) <= abs(x-k-xs):
                    xs = x+k
                else:
                    xs = x-k
                return (True,xs)
            else:
                if x > xs:
                    xs += k
                else:
                    xs -= k
        else:
            if x > xs:
                xs += k
            else:
                xs -= k
        return (False,xs)


def to(x, y):
    rs = []
    xs, ys = 0, 0
    while True:
        if abs(x-xs) == k or abs(y-ys) == k:
            if abs(x-xs) <= k and abs(y-ys) <= k:
                return rs + [(x, y)]
        mm, ys = cc(y, ys)
        if mm:
            if x > xs:
                xs += k
            else:
                xs -= k
        else:
            mm, xs = cc(x, xs)
        rs.append((xs, ys))

if __name__ == '__main__':
    jj = main()
    if jj == -1:
        print(-1)
    else:
        print(len(jj))
        for r in jj:
            print((r[0]+r[1])//2, (r[1]-r[0])//2)
Problem p02985 (python)

Fixed submission:
import sys
mod = 1000000007

sys.setrecursionlimit(10**7)
readline = sys.stdin.readline
N, K = map(int, readline().split())

def P(x, y):
    r = 1
    for i in range(y):
        r = (r * (x - i)) % mod
    return r

G = [[] for _ in range(N)]
for v in range(N-1):
    a, b = map(int, readline().split())
    a, b = a-1, b-1
    G[a].append(b)
    G[b].append(a)

def dfs(bb, v):
    cn = 0
    r = 1
    for u in G[v]:
        if u == bb:
            continue
        cn += 1
        r = (r * dfs(v, u)) % mod
    if cn == 0:
        return 1
    else:
        if bb == None:
            return P(K-1, cn) * r % mod
        else:
            return P(K-2, cn) * r % mod

print((K*dfs(None, 0))%mod)

Buggy submission (verdict: Runtime Error):
Q,E,v,m=input,exec,[],10**9+7;N,K=map(int,Q().split());from collections import Counter as C;E("v+=Q().split();"*(N-1)+"g,v,r=list(C(v).values()),0,K*(K-1);"+"E(\"i=0;\"+\"r=(r*(K-2-i))%m;i+=1;\"*(g[v]-1));v+=1;"*N);print(r)

Buggy submission (verdict: Runtime Error):
Q,E,v,m=input,exec,[],10**9+7;N,K=map(int,Q().split());from collections import Counter as C;E("v+=Q().split();"*(N-1)+"g,v,r=list(C(v).values()),0,K*(K-1);"+"E(\"i=0;\"+\"r=(r*(K-2-i))%m;i+=1;\"*(g[v]-1));v+=1;"*N);print(r)
Problem p02997 (python)

Fixed submission:
n, k = [int(x) for x in input().strip().split(" ")]
m=~-n*(n-2)//2
if k>m:
    print(-1)
else:
    m-=k
    print(m+n-1)
    for i in range(1, n):
        print(i, n)
    for i in range(1, n):
        for j in range(i+1, n):
            if m==0:
                break
            print(i, j)
            m-=1

Buggy submission (verdict: Runtime Error):
N, M = [int(x) for x in input().strip().split(" ")]

vs = set()
def dfs_w(v, d, t):
    # dfs while版 
    r = -1
    stack = [v]
    path = []
    while True:
        if len(stack) == 0:
            break
        v = stack.pop()
        if v < 0:
            path.pop()
        else:
            path.append(v)
            vs.add(v)
            for u in d[v]:
                if u == t:
                    if r != -1:
                        r = min(len(path)//3, r)
                    else:
                        r = len(path)//3
                    continue
                if u in vs:
                    continue
                stack += [-v, u]
    return r

d = [set() for _ in range(3*N+1)]
for _ in range(M):
    a, b = [int(x) for x in input().strip().split(" ")]
    d[a].add(N+b)
    d[N+a].add(2*N+b)
    d[2*N+a].add(b)

s, t = [int(x) for x in input().strip().split(" ")]
print(dfs_w(s, d, t))
Problem p03014 (python)

Fixed submission:
H, W = map(int, input().split())
import sys
input = sys.stdin.readline
def sc(s):
    b = None
    nc = 0
    kk = [0]*len(s)
    for i, c in enumerate(s):
        if c == ".":
            if c == b:
                nc += 1
            else:
                si = i
        else:
            if b == ".":
                for j in range(si, i):
                    kk[j] = i - si
            nc = 0
        b = c
    return kk
d = []
d2 = []
d3 = []
for h in range(H):
    s = input().strip()
    d.append(s)
    d2.append(sc(s+"#"))

d = list(zip(*d))
for s in d:
    d3.append(sc("".join(s)+"#"))
r = 0
for i in range(H):
    for j in range(W):
        r = max(r, d2[i][j] + d3[j][i]-1)
print(r)

Buggy submission (verdict: Runtime Error):
import sys
input=sys.stdin.readline
H, W = map(int, input().split())
d = []
d2 = []
d3 = []
for h in range(H):
    s = input().strip() + "#"
    d.append(s)
    d2.append(sc(s))

for i in range(W):
    s = ""
    for j in range(H):
        s += d[j][i]
    s += "#"
    d3.append(sc(s))

Buggy submission (verdict: Runtime Error):
H, W = map(int, input().split())
import sys
input = sys.stdin.readline
def sc(s):
    b = None
    nc = 0
    kk = [0]*len(s)
    for i, c in enumerate(s):
        if c == ".":
            if c == b:
                nc += 1
            else:
                si = i
        else:
            if b == ".":
                for j in range(si, i):
                    kk[j] = i - si
            nc = 0
        b = c
    return kk
d = []
d2 = []
d3 = [[0]*W for _ in range(H)]
for h in range(H):
    s = input().strip() + "#"
    d.append(s)
    d2.append(sc(s))

r = 0
for i in range(H):
    for j in range(W):
        r = max(r, d2[i][j] + d3[j][i]-1)
print(r)
Problem p03021 (python)

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

def f(v, vs):
    kminmax = 0
    r = 0
    rkoma = 0
    fff = 0
    ffmx = 0
    for u in d[v]:
        if u in vs:
            continue
        vs.add(u)
        k1, koma, ff = f(u, vs)
        if k1 > kminmax:
            kminmax = k1
            ffmx = ff
        kminmax = max(kminmax, k1)
        rkoma += koma
        fff += ff
    if kminmax > fff - ffmx:
        r1 = kminmax+ffmx-fff
    else:
        r1 = fff % 2
    rkoma += km[v]
#    print(v, r1 + rkoma, rkoma, fff + rkoma)
    return r1 + rkoma, rkoma, fff + rkoma

N = int(input())
km = [0] + [int(i) for i in str(input().strip())]
d = [set() for _ in range(N+1)]
for _ in range(N-1):
    x, y = map(int, input().split())
    d[x].add(y)
    d[y].add(x)

r = 10**10
#print(f(4, {4}))
for i in range(N):
    a, c, fff = f(i+1, {i+1})
#    print(i, a, c)
    if a == c:
        r = min(r, (fff-c)//2)
print(r if r != 10**10 else -1)

Buggy submission (verdict: Runtime Error):

def g(l):
    if not l:
        return 0, 0
    m,s = max(l), sum(l)
    if 2*m > s:
        return 2*m - s, (s-m)
    return s % 2, s//2

def f(v, vs):
    ks = []
    r = 0
    rkoma = 0
    for u in d[v]:
        if u in vs:
            continue
        vs.add(u)
        k1, k2, koma = f(u, vs)
        ks.append(k1)
        rkoma += koma
        r += k2
    r1, r2 = g(ks)
    # r1 深さの和、r2 操作の回数
    rkoma += km[v]
#    print(v, r1 + rkoma, r + r2, rkoma)
    return r1 + rkoma, r + r2, rkoma

N = int(input())
km = [0] + [int(i) for i in input()]
d = [set() for _ in range(N+1)]

for _ in range(N-1):
    x, y = map(int, input().split())
    d[x].add(y)
    d[y].add(x)

r = -1
for i in range(N):
    a, b, c = f(i+1, {i+1})
    if a == c:
        r = b
print(r)
Problem p03032 (python)

Fixed submission:
n,k=map(int,input().split())
xs=[0]+list(map(int,input().split()))
from itertools import accumulate
As=list(accumulate(xs))
r = 0
for i in range(k+1):
    for j in range(i, k+1):
        x = i, j-i, k-j
        if j > n:
            continue
        m1 = As[i] + As[n] - As[n-j+i]
        m = m1 - sum(sorted(z for z in (xs[:i]+xs[n-j+i+1:]) if z < 0)[:k-j])
#        if m > r:
#            print(x, m, m1)
        r = max(r, m)
print(r)

Buggy submission (verdict: Runtime Error):
n,k=map(int,input().split())
xs=[0]+list(map(int,input().split()))
from itertools import accumulate
As=list(accumulate(xs))
r = 0
for i in range(k+1):
    for j in range(i, k+1):
        x = i, j-i, k-j
        m1 = As[i] + As[n] - As[n-j+i]
        ss = sorted(z for z in (xs[:i]+xs[n-j+i+1:]) if z < 0)
        m = m1 - sum(ss[:min(k-j,len(ss))])
#        if m > r:
#            print(x, m, m1)
        r = max(r, m)
print(r)

Buggy submission (verdict: Runtime Error):
n,k=map(int,input().split())
xs=[0]+list(map(int,input().split()))
from itertools import accumulate
As=list(accumulate(xs))
r = 0
for i in range(k+1):
    for j in range(i, k+1):
        x = i, j-i, k-j
        m = As[i] + As[n] - As[n-j+i]
        #m = m1 - sum(sorted(z for z in (xs[:i]+xs[n-j+i+1:]) if z < 0)[:k-j])
#        if m > r:
#            print(x, m, m1)
        r = max(r, m)
print(r)

Buggy submission (verdict: Runtime Error):
n,k=map(int,input().split())
xs=[0]+list(map(int,input().split()))
from itertools import accumulate
As=list(accumulate(xs))
r = 0
for i in range(k+1):
    for j in range(i, k+1):
        x = i, j-i, k-j
        m1 = As[i] + As[n] - As[n-j+i]
        m = m1 - sum(sorted(z for z in (xs[:i]+xs[n-j+i+1:]) if z < 0)[:k-j])
#        if m > r:
#            print(x, m, m1)
        r = max(r, m)
print(r)
Problem p03035 (python)

Fixed submission:
N, W = map(int, input().split())
if N >=13:
  print(W)
elif N >=6:
  print(W//2)
else:
  print(0)

Buggy submission (verdict: Runtime Error):
import sys
mod = pow(10, 9) + 7
def C(n, r):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod
NNN = (10**6)
g1 = [1, 1]
g2 = [1, 1]
inverse = [0, 1]
for i in range(2, NNN+1):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )
n,m,k=map(int,input().split())
#n=m=k=2
print(C(n*m,k)*C(k,2)%mod*(n+m)*inverse[3]%mod)
Problem p03044 (python)

Fixed submission:
N, = map(int, input().split())
import sys
sys.setrecursionlimit(10**6)
d = [set() for _ in range(N+1)]
Cs = [0 for _ in range(N+1)]
for _ in range(N-1):
    u, v, p = map(int, input().split())
    d[u].add((v, p))
    d[v].add((u, p))

def it(v, p):
    for u, c in d[v]:
        if u == p:
            continue
        Cs[u] = int(not Cs[v]) if c%2 else Cs[v]
        it(u, v)
it(1, None)
for i in range(1, N+1):
    print(Cs[i])

Buggy submission (verdict: Runtime Error):
N, = map(int, input().split())
d = [set() for _ in range(N+1)]
l = [set() for _ in range(N+1)]
c = [0 for _ in range(N+1)]
for _ in range(N-1):
    u, v, p = map(int, input().split())
    d[u].add(v)
    d[v].add(u)
    l[min(u,v)] = p

def it(v, p):
    for u in d[v]:
        if u == p:
            continue
        c[u] = int(not c[v]) if l[min(u, v)]%2 else c[v]
        it(u, v)
it(1, None)
for i in range(1, N+1):
    print(c[i])

Buggy submission (verdict: Runtime Error):
N, K = map(int, input().split())
As = [0] + list(map(int, input().split()))
from itertools import accumulate
As = list(accumulate(As))
M = len(As)
d = []
j = 0
r = 0
for i in range(M):
    a = As[i]
    while True:
        if j == M:
            break
        if a + K <= As[j]:
            break
        j += 1
    r += M - j
print(r)
Problem p03046 (python)

Fixed submission:
M, K = map(int, input().split())
if K >= 2**M:
    print(-1)
elif M == 0:
    print(0, 0)
elif M == 1:
    if K == 0:
        print("0 0 1 1")
    else:
        print(-1)
elif K==0:
    r = list(range(2**M))
    r += r[::-1]
    print(*r)
else:
    d = set()
    for i in range(2**M):
        p = tuple(sorted([i, i^K]))
        if p not in d:
            d.add(p)
    r = []
    while d:
        x,y = d.pop()
        z,w = d.pop()
        r += [x,y,z,w,y,x,w,z]
    print(*r)

Buggy submission (verdict: Runtime Error):
M, K = map(int, input().split())
if K >= 2**(M+1):
    print(-1)
elif M == 1:
    if K == 0:
        print("1 0")
    else:
        print(-1)
else:
    d = set()
    for i in range(2**(M+1)):
        p = tuple(sorted([i, i^K]))
        if p not in d:
            d.add(p)
    r = []
    while d:
        x,y = d.pop()
        z,w = d.pop()
        r += [x,y,z,w,y,x,w,z]
    print(*r)
Problem p03088 (python)

Fixed submission:
N = int(input().strip())
M = pow(10, 9) + 7
a = 1
g = 1
ag = 0
agg = 0
agt = 0
atg = 0
ac = 0
at = 0
aa = 0
ga = 0

al = 4
nal = 0

for i in range(N-1):
    nal = (al * 4) % M
    nal = (nal + M - (ag + ac + ga + agg + agt + atg) ) % M

    agg = ag
    agt = ag
    atg = at
    ag = a
    aa = a
    at = a
    nac = (a + M- ga) % M
    ga = g
    a = al
    g = (al + M - ac) % M
    ac = nac
    al = nal
print(al)

Buggy submission (verdict: Runtime Error):
a,g,a_,a__,ac,ga,al=[0]*6+[1]
for i in range(int(input())):
    a__,a_,ac,ga,a,g,al=a_,a,a-ga,g,al,al-ac,(al*4-(ag+ac+ga+a__*3))%(pow(10,9)+7)
print(al)
Problem p03091 (python)

Fixed submission:
import sys

def ta(x, y, p):
    xc = 0
    yc = 0

    for i in p[x]:
        bc = x
        c = i
        while True:
            if c == x:
                xc += 1
                break
            elif c == y:
                yc += 1
                break
            cs = p[c]
            for j in cs:
                if j != bc:
                    bc = c
                    c = j
                    break
    if xc == yc:
        return True
    else:
        return False


d = {}
p = {}
n, m = input().strip().split(" ")
for i in range(int(n)):
    i += 1
    d[i] = 0
    p[i] = list()

for line in sys.stdin:
    x, y = line.strip().split(" ")
    x, y = int(x), int(y)
    d[x] += 1
    d[y] += 1
    p[x].append(y)
    p[y].append(x)

r = None
fc = 0
fcs = []
for x in d:
    y = d[x]
    if y % 2 != 0:
        r = False
        break
    if y >= 6:
        r = True
    if y >= 4:
        fc += 1
        fcs.append(x)

if r == None:
    if fc >= 3:
        r = True
    elif fc == 2:
        x, y = fcs
        r = ta(x, y, p)
    else:
        r = False
if r:
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
import sys

def ta(x, y, p):
    xc = 0
    yc = 0

    for i in p[x]:
        c = i
        while True:
            if c == x:
                xc += 1
                break
            elif c == y:
                yc += 1
                break
            cs = p[c]
            for j in cs:
                if j != bc:
                    bc = c
                    c = j
                    break
    if xc == yc:
        return True
    else:
        return False


d = {}
p = {}
n, m = input().strip().split(" ")
for i in range(int(n)):
    i += 1
    d[i] = 0
    p[i] = list()

for line in sys.stdin:
    x, y = line.strip().split(" ")
    x, y = int(x), int(y)
    d[x] += 1
    d[y] += 1
    p[x].append(y)
    p[y].append(x)

r = None
fc = 0
fcs = []
for x in d.values():
    if x % 2 != 0:
        r = False
        break
    if x >= 6:
        r = True
    if x >= 4:
        fc += 1
        fcs.append(x)

if r == None:
    if fc >= 3:
        r = True
    elif fc == 2:
        x, y = fcs
        r = ta(x, y, p)
    else:
        r = False
if r:
    print("Yes")
else:
    print("No")
Problem p03095 (python)

Fixed submission:
import collections
M = pow(10, 9) + 7
input()
s = input().strip()
r=1
for x in collections.Counter(s).values():
    r = (r*(x+1)) %M
print(r-1)

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

M = pow(10, 9) + 7
import sys

dc = {}
al = [0]

rr = [1]


def search(ss, start, end):
    z = al[(start + end)//2]
    nz = al[(start + end)//2+1]
    if z <= ss and ss < nz:
        return (start+end)//2
    elif ss < z:
        return search(ss, start, (start+end)//2)
    else:
        return search(ss, (start+end)//2+1, end)

c = 0
cn = 0
for line in sys.stdin:
    a = int(line)
    if a in dc:
        ss = dc[a]
        if ss != c-1:
            if ss >= al[cn]:
                rr.append((rr[cn]*2)%M)
            else:
                i = search(ss, 0, cn)
                rr.append((rr[cn] + rr[i])%M)
            al.append(c)
            cn += 1
    dc[a] = c
    c += 1
print(rr[cn]%M)
Problem p03160 (python)

Fixed submission:
N, = [int(x) for x in input().strip().split(" ")]
hs = [int(x) for x in input().strip().split(" ")]
d = [0] * N
d[1] = abs(hs[0] - hs[1])

for i in range(N-2):
    i = i+2
    d[i] = min(d[i-1] + abs(hs[i-1] - hs[i]), d[i-2] + abs(hs[i-2] - hs[i]))

print(d[-1])

Buggy submission (verdict: Runtime Error):
N, K = [int(x) for x in input().strip().split(" ")]
hs = [int(x) for x in input().strip().split(" ")]
d = [0] * N

for i in range(N-1):
    i = i+1
    tmp = pow(10, 18)
    for j in range(K):
        j = j + 1
        if i-j < 0:
            continue
        tmp = min(tmp, d[i-j] + abs(hs[i-j] - hs[i]))
    d[i] = tmp
print(d[-1])
Problem p03165 (python)

Fixed submission:
s = input().strip()
t = input().strip()
LS, LT = len(s), len(t)
dp = [[0]*(LT+1) for _ in range(LS+1)]
dp2 = [[(0, 0)]*(LT+1) for _ in range(LS+1)]
for i in range(LS):
    for j in range(LT):
        if s[i] == t[j]:
            dp[i+1][j+1] = dp[i][j] + 1
            dp2[i+1][j+1] = (i, j)
        else:
            dp[i+1][j+1] = max(dp[i][j+1], dp[i+1][j])
            if dp[i][j+1] > dp[i+1][j]:
                dp2[i+1][j+1] = (i, j+1)
            else:
                dp2[i+1][j+1] = (i+1, j)
bb = []
a, b = (LS, LT)
while a > 0 and b > 0:
    if s[a-1] == t[b-1]:
        bb.append(s[a-1])
    a, b = dp2[a][b]

print("".join(bb[::-1]))

Buggy submission (verdict: Runtime Error):
s = " " + input().strip()
t = " " + input().strip()
LS, LT = len(s), len(t)
dp = [[0]*LT for _ in range(LS)]
for i in range(1, LS):
    for j in range(1, LT):
        if s[i] == t[j]:
            dp[i][j] = dp[i-1][j-1] + 1
        else:
            dp[i][j] = max(dp[i-1][j], dp[i][j-1])
a, b = (LS-1, LT-1)
r = ""
while a > 0 and b > 0:
    if s[a] == t[b]:
        r+=s[a]
        a, b = a-1, b-1
    elif dp[a+1][b+1] == dp[a][b+1]:
        a -= 1
    else:
        b -= 1

print(r[::-1])