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

Fixed submission:
n,q = map(int, input().split())
tree = [set() for i in range(n+1)]
for _ in range(n-1):
  a,b = map(int, input().split())
  tree[a].add(b)
  tree[b].add(a)
lazy = [0]*(n+1)
cnt = 0

for _ in range(q):
  x,v = map(int, input().split())
  lazy[x] += v

que = [(1,0)]
while que:
  v,p = que.pop()
  for x in tree[v]:
    if x == p:
      continue
    lazy[x] += lazy[v]
    que.append((x,v))

print(" ".join(map(str,lazy[1:])))

Buggy submission (verdict: Runtime Error):
n,q = map(int, input().split())
tree = [set() for i in range(n+1)]
for _ in range(n-1):
  a,b = map(int, input().split())
  tree[a].add(b)
  tree[b].add(a)
lazy = [0]*(n+1)
ans = [0]*(n+1)
cnt = 0

for _ in range(q):
  x,v = map(int, input().split())
  lazy[x] += v

def dfs(v,p,tree):
  ans[v] += lazy[v]
  for x in tree[v]:
    if x == p:
      continue
    lazy[x] += lazy[v]
    dfs(x,v,tree)
  lazy[v] = 0
  return

dfs(1,0,tree)

print(" ".join(map(str,ans[1:])))

Buggy submission (verdict: Runtime Error):
n,q = map(int, input().split())
tree = [set() for i in range(n+1)]
for _ in range(n-1):
  a,b = map(int, input().split())
  tree[a].add(b)
  tree[b].add(a)
lazy = [0]*(n+1)
ans = [0]*(n+1)
cnt = 0

for _ in range(q):
  x,v = map(int, input().split())
  lazy[x] += v

def dfs(v,p,tree):
  ans[v] += lazy[v]
  for x in tree[x]:
    if x == p:
      continue
    lazy[x] += lazy[v]
    dfs(x,v,tree)
  lazy[v] = 0
  return

dfs(1,0,tree)

print(" ".join(map(str,ans[1:])))
Problem p02937 (python)

Fixed submission:
def main():
  s = list(map(lambda x:ord(x)-97, list(input())))
  ls = len(s)
  ss = set(s)
  t = list(map(lambda x:ord(x)-97, list(input())))
  lt = len(t)
  st = set(t)
  td = [list() for _ in range(26)]
  if not st.issubset(ss):
    print(-1)
    exit()
  for i in range(lt-1):
    td[t[i]].append(t[i+1])
  md = [None for _ in range(ls)]
  cd = [0]*26
  for i in range(ls-1,-1,-1):
    cd[s[i]] = i + ls
  for i in range(ls-1,-1,-1):
    md[i] = cd.copy()
    cd[s[i]] = i
  ans = 0
  cur = cd[t[0]]
  for i in range(lt-1):
    cur = md[cur][t[i+1]]
    ans += (cur//ls)
    cur %= ls
  print(1 + ans*ls+cur)

if __name__ == "__main__":
  main()

Buggy submission (verdict: Runtime Error):
def main():
  s = list(map(lambda x:ord(x)-97, list(input())))
  ls = len(s)
  ss = set(s)
  t = list(map(lambda x:ord(x)-97, list(input())))
  lt = len(t)
  st = set(t)
  td = [list() for _ in range(26)]
  if not st.issubset(ss):
    print(-1)
    exit()
  for i in range(lt-1):
    td[t[i]].append(t[i+1])
  md = [None for _ in range(ls)]
  cd = [0]*26
  for i in range(ls-1,-1,-1):
    cd[s[i]] = i + ls
  for i in range(ls-1,-1,-1):
    md[i] = cd.copy()
    cd[s[i]] = i
  ans = 0
  cur = cd[t[0]]
  for i in range(lt-1):
    cur = md[cur][t[i+1]]
    ans += (cur//ls)
    cur %= ls
  print(1 + ans*ls+cur)

if __name__ == "__main__":
  main()
Problem p02940 (python)

Fixed submission:
mod = 998244353
n = int(input())
a = list(map(lambda x: ord(x)%3, list(input())))
g = [list() for _ in range(3)]
for i in range(3*n):
  g[a[i]].append(i)
l = [0]*3*n
for i in range(n):
  a, b, c = sorted([g[0][i], g[1][i], g[2][i]])
  l[b] = 1
  l[c] = 2
ans = 1
for i in range(n):
  ans = ans * (i+1) % mod
c = 0
for x in l:
  if x == 0:
    c += 1
  elif x == 1:
    ans = ans * c % mod
    c -= 1
for x in reversed(l):
  if x == 2:
    c += 1
  elif x == 1:
    ans = ans * c % mod
    c -= 1
print(ans)

Buggy submission (verdict: Runtime Error):
import heapq as h
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
e6 = 10**6
q = [-b[i]*e6-i for i in range(n)]
q.sort()
cnt = 0
while q:
  w = -h.heappop(q)
  v, i = divmod(w, e6)
  u = b[i-1] + b[(i+1)%n]
  if v < u or a[i] == v: continue
  elif a[i] > v: print(-1); exit(0)
  t = (v-a[i])//u
  if not t: print(-1); exit(0)
  cnt += t
  b[i] -= t*u
  if b[i] > a[i]:
    h.heappush(q,-b[i]*e6-i)
print(cnt if a==b else -1)
Problem p02985 (python)

Fixed submission:
import sys
sys.setrecursionlimit(200000)
n,k = map(int,input().split())
mod = 10**9+7
gr = [set() for _ in range(n+1)]
for i in range(n-1):
    a,b = map(int,input().split())
    gr[a].add(b)
    gr[b].add(a)
ans = [0]*(n+1)
done = [0]*(n+1)
done[1] = -1
done[0] = -2
def dfs2(gr,p,v,done,ans):
    ans[v] = k-2-done[p]
    for x in gr[v]:
        if x == p:
            continue
        dfs2(gr,v,x,done,ans)
        done[v] += 1
    return
dfs2(gr,0,1,done,ans)
m = 1
for x in ans[1:]:
    m = m*x%mod
print(m)

Buggy submission (verdict: Runtime Error):
n,k = map(int,input().split())
mod = 10**9+7
gr = [set() for _ in range(n+1)]
for _ in range(n-1):
    a,b = map(int,input().split())
    gr[a].add(b)
    gr[b].add(a)
par = [0]*(n+1)
ans = [0]*(n+1)
done = [0]*(n+1)
done[1] = -1
done[0] = -2
def dfs2(gr,p,v,done,ans):
    ans[v] = k-2-done[p]
    for x in gr[v]:
        if x == p:
            continue
        dfs2(gr,v,x,done,ans)
        done[v] += 1
    return
dfs2(gr,0,1,done,ans)
m = 1
for x in ans[1:]:
    m = m*x%mod
print(m)
Problem p02997 (python)

Fixed submission:
n,k = map(int, input().split())
k -= n*(n-1)//2 - (n-1)
if k > 0:
  print(-1)
  exit()
else:
  i = 2
  j = 3
  tl = [(1,f) for f in range(2,n+1)]
  for _ in range(-k):
    tl.append((i,j))
    j += 1
    if j > n:
      i += 1
      j = i+1
print(len(tl))
for x,y in tl:
  print(x,y)

Buggy submission (verdict: Runtime Error):
n,k = map(int, input().split())
k -= n*(n-1)//2 - (n-1)
if k > 0:
  print(-1)
else:
  i = 2
  j = 3
  tl = [(1,f) for f in range(2,n+1)]
  for _ in range(-k):
    tl.append((i,j))
    j += 1
    if j > n:
      i += 1
      j = i+1
print(len(tl))
for x,y in tl:
  print(x,y)
Problem p03006 (python)

Fixed submission:
from collections import defaultdict as ddict
d = ddict(int)
d[0] = 0
n = int(input())
l = [tuple(map(int, input().split())) for _ in range(n)]
l.sort()
for i in range(n-1):
  for j in range(i+1,n):
    curx = l[j][0] - l[i][0]
    cury = l[j][1] - l[i][1]
    d[(curx,cury)] += 1
print(n-max(d.values()))

Buggy submission (verdict: Runtime Error):
from collections import defaultdict as ddict
d = ddict(int)
n = int(input())
l = [tuple(map(int, input().split())) for _ in range(n)]
l.sort()
for i in range(n-1):
  for j in range(i+1,n):
    curx = l[j][0] - l[i][0]
    cury = l[j][1] - l[i][1]
    d[(curx,cury)] += 1
print(n-max(d.values()))
Problem p03030 (python)

Fixed submission:
n = int(input())
l = []
for i in range(1,n+1):
  s,p = input().split()
  l.append((s,-int(p),i))
l.sort()
for x in l:
  print(x[2])

Buggy submission (verdict: Runtime Error):
n = int(input())
l = []
for i in range(1,n+1):
  s,p = input(),split()
  l.append(s,-int(p),i)
l.sort()
for x in l:
  print(x[2])
Problem p03039 (python)

Fixed submission:
n,m,k = map(int, input().split())
n_ = n*m
mod = 10**9+7
fun = [1]*(n_+1)
for i in range(1,n_+1):
    fun[i] = fun[i-1]*i%mod
rev = [1]*(n_+1)
rev[n_] = pow(fun[n_],mod-2,mod)
for i in range(n_-1,0,-1):
    rev[i] = rev[i+1]*(i+1)%mod

def nCr(n,r):
    if r > n:
        return 0
    return fun[n]*rev[r]%mod*rev[n-r]%mod
  
x = sum(i*(n-i) for i in range(n))%mod
y = sum(i*(m-i) for i in range(m))%mod
ans = (x*m**2 + y*n**2)%mod*nCr(n*m-2,k-2)%mod
print(ans)

Buggy submission (verdict: Runtime Error):
n,m,k = map(int, input().split())
mod = 10**9+7
def cc(a,b):
  b = min(b,a-b)
  tot = 1
  for i in range(1,b+1):
    tot = (tot*(a-i+1)//i)%mod
  return tot
xans = 0
yans = 0
for i in range(1,n):
  xans+=i*(n-i)*m**2
  xans%=mod
for j in range(1,m):
  yans+=i*(m-i)*n**2
  yans%=mod
print((xans+yans)*cc(n*m-2,k-2)%mod)

Buggy submission (verdict: Runtime Error):
n,m,k = map(int, input().split())
mod = 10**9+7
def cc(a,b):
  b = min(b,a-b)
  tot = 1
  for i in range(1,b+1):
    tot = (tot*(a-i+1)//i)%mod
    return tot
xans = 0
yans = 0
for i in range(1,n):
  xans+=i*(n-i)*m**2
  xans%=mod
for j in range(1,m):
  yans+=i*(m-i)*n**2
  yans%=mod
print((xans+yans)*cc(n*m-2,k-2)%mod)
Problem p03085 (python)

Fixed submission:
print(input().translate(str.maketrans("ATGC","TACG")))

Buggy submission (verdict: Runtime Error):
n = int(input())
mod = 10**9+7
a = [1]*16
no = [0,0]
for _ in range(n-2):
  b = [0]*16
  b[0] = a[0] + a[4] + a[8] + a[12]
  b[1] = a[0] + a[4] + a[12]
  b[2] = a[0] + a[4] + a[8] + a[12]
  b[3] = a[0] + a[4] + a[8] + a[12]
  b[4] = a[1] + a[5] + a[9] + a[13]
  b[5] = a[1] + a[5] + a[9] + a[13]
  b[6] = a[5] + a[9] + a[13]
  b[7] = a[1] + a[5] + a[9] + a[13]
  b[8] = a[2] + a[6] + a[9] + a[14]
  b[9] = a[6] + a[9] + a[14] - no[0] - no[1]
  b[10] = a[2] + a[6] + a[9] + a[14]
  b[11] = a[2] + a[6] + a[9] + a[14]
  b[12] = a[3] + a[7] + a[10] + a[15]
  b[13] = a[3] + a[7] + a[10] + a[15] - no[1]
  b[14] = a[3] + a[7] + a[10] + a[15]
  b[15] = a[3] + a[7] + a[10] + a[15]
  no[0] = a[2]
  no[1] = a[3]
  a = b
  for i in range(16):
    a[i] %= mod
print(sum(a))
Problem p03096 (python)

Fixed submission:
n = int(input())
oth = [int(input()) for _ in range(n)]
mod = 10**9 + 7
l = list()
for x in oth:
    if l and l[-1] == x:
        continue
    l.append(x)
lenl = len(l)
last = [-1] * 200001
l2 = [-1] * 200001
for i, a in enumerate(l):
    l2[i] = last[a]
    last[a] = i

dp = [0] * lenl
dp[0] = 1
for i in range(1, lenl):
    prev = 0 if l2[i] < 0 else dp[l2[i]]
    dp[i] = (dp[i - 1] + prev) % mod
print(dp[-1])

Buggy submission (verdict: Runtime Error):
n = int(input())
l = [int(input()) for _ in range(n)] + [0]
p = [0]
for i in range(n):
  if l[i] != l[i+1]:
    p.append(l[i])
lp = len(p)
l = [0]*lp
l[0] = 1
d = dict()
for i in range(1,lp):
  l[i] = l[i-1]
  if p[i] in d:
    l[i] += l[p[i]]
  d[p[i]] = i
print(l[-1])
Problem p03111 (python)

Fixed submission:
n,a,b,c = map(int, input().split())
l = [int(input()) for _ in range(n)]
def dfs(k,p,q,r):
  if k == n:
    if min(p,q,r) > 0:
      return abs(p-a)+abs(q-b)+abs(r-c)-30
    else:
      return 10**7
  t1 = dfs(k+1,p,q,r)
  t2 = dfs(k+1,p+l[k],q,r)+10
  t3 = dfs(k+1,p,q+l[k],r)+10
  t4 = dfs(k+1,p,q,r+l[k])+10
  return min(t1,t2,t3,t4)

print(dfs(0,0,0,0))

Buggy submission (verdict: Runtime Error):
n,a,b,c = map(int, input().split())
l = [int(input()) for _ in range(n)]
def dfs(k,p,q,r):
  if k == n:
    if min(a,b,c) > 0:
      return abs(p-a)+abs(q-b)+abs(r-c)-30
    else:
      return 10**5
  t1 = dfs(k+1,p,q,r)
  t2 = dfs(k+1,p+l[k],q,r)+10
  t3 = dfs(k+1,p,q+l[k],r)+10
  t2 = dfs(k+1,p,q,r+l[k])+10
  return min(t1,t2,t3,t4)

print(dfs(0,0,0,0))

Buggy submission (verdict: Runtime Error):
n, a, b, c = map(int, input().split())
l = [int(input()) for _ in range(n)]
cnt = 0
for k in [a,b,c]:
    ans = 0
    for i in range(1, 257):
        s = 0
        for j in range(n):
            if i & 2**j:
                if s > 0:
                    s += 10
                s += l[j]
        v = abs(k - s)
        if v < ans:
            ans = v
            x = i
    cnt += ans
    for j in range(n):
        if x & 2**j:
            l[j] = 0
print(cnt)

Buggy submission (verdict: Runtime Error):
n, a, b, c = map(int, input().split())
l = [int(input()) for _ in range(n)]
cnt = 0
for k in [a,b,c]:
    ans = 0
    for i in range(1, 257):
        s = 0
        for j in range(7):
            if i & 2**j:
                if s > 0:
                    s += 10
                s += l[j]
        v = abs(k - s)
        if v < ans:
            ans = v
            x = i
    cnt += ans
    for j in range(7):
        if x & 2**j:
            l[j] = 0
print(cnt)
Problem p03151 (python)

Fixed submission:
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
ov = []
un = 0
cnt = 0
for i in range(n):
  c = a[i]-b[i]
  if c >= 0:
    ov.append(c)
  else:
    un += c
    cnt += 1
if un == 0:
  print(0)
else:
  un *= -1
  ov.sort(reverse=True)
  ov2 = 0
  for i in range(len(ov)):
    ov2 += ov[i]
    if ov2 >= un:
      print(cnt+i+1)
      break
  else:
    print(-1)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
ov = []
un = 0
cnt = 0
for i in range(n):
  c = a[i]-b[i]
  if c >= 0:
    ov.append(c)
  else:
    un += c
    cnt += 1
if un == 0:
  print(0)
else:
  un *= -1
  ov.sort(reverse=True)
  ov2 = 0
  for i in range(n):
    ov2 += ov[i]
    if ov2 >= un:
      print(cnt+i+1)
      break
  else:
    print(-1)
Problem p03169 (python)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
uno = a.count(1)
dos = a.count(2)
tres = n - uno - dos
dp = [[[0]*(n+1) for _ in range(dos+tres+1)] for j in range(tres+1)]
for k in range(tres+1):
  for j in range(dos+tres-k+1):
    for i in range(n+1-j-k):
      if i+j+k == 0: continue
      v = i+j+k
      res = n
      if i: res += i * dp[k][j][i-1]
      if j: res += j * dp[k][j-1][i+1]
      if k: res += k * dp[k-1][j+1][i]
      dp[k][j][i] = res / v
print(dp[tres][dos][uno])

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**5)
n = int(input())
cnt = [0,0,0]
dp = [[[0.0]*(n+1) for _ in range(n+1)] for _ in range(n+1)]
for i in map(int,input().split()):
  cnt[i-1] += 1
def fj(i,j,k):
  global dp
  if i < 0 or j < 0 or k < 0 or i>n or j>n or k>cnt[2]:
    return 0.0
  if dp[i][j][k] != 0.0:
    return dp[i][j][k]
  s = i+j+k
  res = n/s + fj(i-1,j,k)*i/s + fj(i+1,j-1,k)*j/s + fj(i,j+1,k-1)*k/s
  dp[i][j][k] = res
  return dp[i][j][k]
print(fj(*cnt))
Problem p03171 (python)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
dp = [[None]*n for _ in range(n)]
for d in range(n):
  for l in range(n-d):
    r = l + d
    if d:
      dp[l][r] = max(a[l] - dp[l+1][r], a[r] - dp[l][r-1])
    else:
      dp[l][r] = a[l]
print(dp[0][n-1])

Buggy submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
d = [None]*(n+1)**2
def judge(l,r):
  if l >= r:
    return a[l]
  v = l + r*(n+1)
  if d[v] is not None: return d[v]
  d[v] = max(a[l] - judge(l+1,r), a[r] - judge(l,r-1))
  return d[v]

print(judge(0,n-1))

Buggy submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
d = [None]*(n+1)**2
def judge(l,r):
  if l >= r:
    return a[l]
  v = l + r*(n+1)
  if d[v] is not None: return d[v]
  d[v] = min(a[l] - judge(l+1,r), a[r] - judge(l,r-1))
  return d[v]

print(judge(0,n-1))

Buggy submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
d = [None]*3001**2
def judge(l,r):
  if l >= r:
    return a[l]
  v = l + r*3001
  if d[v] is not None: return d[v]
  res1 = a[l] - judge(l+1,r)
  res2 = a[r] - judge(l,r-1)
  if res1 < res2: res1, res2 = res2, res1
  d[v] = res1
  return res1

print(judge(0,n-1))
Problem p03196 (python)

Fixed submission:
from collections import defaultdict as dd
primes = dd(int)
n,p = map(int, input().split())
gcd = 1
for i in range(2,int(p**.5)+1):
  while p%i == 0:
    p //= i
    primes[i] += 1
if p > 1:
  primes[p] += 1
for fac in primes:
  gcd *= fac**(primes[fac]//n)
print(gcd)

Buggy submission (verdict: Runtime Error):
from collections import defaultdict as dd
primes = dd(int)
n,p = int(input().split())
gcd = 1
for i in range(2,int(p**0.5)+1):
  while p%i == 0:
    p //= i
    primes[i] += 1
for fac in primes:
  gcd *= fac**(primes[fac]//n)
print(gcd)
Problem p03200 (python)

Fixed submission:
s = input()
t = 0
c = 0
for i in range(len(s)):
  if s[i] == "W":
    t += i
    c += 1
print(t-c*(c-1)//2)

Buggy submission (verdict: Runtime Error):
s = input()
ans = 0
while b:
  b = 0
  c = s.count("BW")
  if c:
    ans += c
    b = 1
    s = s.replace("BW", "WB")
print(ans)
Problem p03211 (python)

Fixed submission:
s = list(map(int, list(input())))
m = 1000
for i in range(len(s)-2):
  if abs(753 - (s[i]*100+s[i+1]*10+s[i+2])) < m:
    m = abs(753 - (s[i]*100+s[i+1]*10+s[i+2]))
print(m)

Buggy submission (verdict: Runtime Error):
s = list(input())
m = 1000
for i in range(len(s)-3):
  if s[i]*100+s[i+1]*10+s[i+2] < m:
    m = s[i]*100+s[i+1]*10+s[i+2]
print(m)
Problem p03213 (python)

Fixed submission:
from collections import defaultdict as ddict
d = ddict(int)
n = int(input())
for i in range(1,n+1):
  for p in range(2,int(i**.5)+2):
    while i%p == 0:
      d[p] += 1
      i//=p
  if i>1:
    d[i] += 1
g = [2,4,14,24,74]
f = [0]*5
for x in d.values():
  for i in range(5):
    if x >= g[i]:
      f[i] += 1
ans = f[1]*(f[1]-1)//2*(f[0]-2) + f[3]*(f[0]-1) + f[2]*(f[1]-1) + f[4]
print(ans)

Buggy submission (verdict: Runtime Error):
from collections import defaultdict as ddict
d = ddict(int)
for i in range(1,n):
  for p in range(2,int(i**.5)+2):
    while i%p == 0:
      d[p] += 1
      i//=p
f = [2,4,14,24,74]
g = [0]*5
for x in d.values():
  for i in range(5):
    if x >= f[i]:
      g[i] += 1
#3 5 5
#3 25
#15 5
#75
ans = f[1]*(f[1]-1)*(f[0]-2) + f[3]*(f[0]-1) + f[2]*(f[1]-1) + f[4]
print(ans)
Problem p03219 (python)

Fixed submission:
x, y = map(int, input().split())
print(int(x+y/2))

Buggy submission (verdict: Runtime Error):
n = int(input())
t, a = map(int, input().split())
h = list(map(int, input().split()))
v = t-a
for i in range(n):
    h[i] = abs(v-h[i])
print(h.index(min(h))+1)
Problem p03239 (python)

Fixed submission:
n, t =map(int, input().split())
l = [tuple(map(int, input().split())) for i in range(n)]
m = [i for i in l if i[1] <= t]
if m == []:
  print("TLE")
else:
  m.sort()
  print(m[0][0])

Buggy submission (verdict: Runtime Error):
n, t =map(int, input().split())
l = [tuple(map(int, input().split())) for i in range(n)]
m = sorted([i for i in l if i[1] <= t])
print(m[0][0])
Problem p03260 (python)

Fixed submission:
a, b = map(int, input().split())
if a * b % 2 == 0:
  print("No")
else:
  print("Yes")

Buggy submission (verdict: Runtime Error):
a, b = map(int, input().split())
if a % 2 != 0 and b % 2 != 0:
  print(“Yes”)
else:
  print(“No”)
Problem p03282 (python)

Fixed submission:
s = input()
k = int(input())
i = 0
l = len(s)
while s[i] == '1':
  if i >= l-1:
    break
  i += 1
if i == 0 or k <= i:
  print(s[0])
else:
  print(s[i])

Buggy submission (verdict: Runtime Error):
s = input()
k = int(input())
i = 0
while s[i] == '1':
  i += 1
if i == 0 or k <= i:
  print(1)
else:
  print(int(s[i]))

Buggy submission (verdict: Runtime Error):
s = input()
k = int(input())
i = 0
while s[i] == '1':
  i += 1
if i == 0 or k <= i:
  print(s[0])
else:
  print(s[i])

Buggy submission (verdict: Runtime Error):
s = input()
k = int(input())
if k == 1 and s[0] == '1':
  print(s[0])
else:
  print(s[1])
Problem p03287 (python)

Fixed submission:
from collections import defaultdict as dd
d = dd(int)
d[0] = 1
n,m = map(int, input().split())
a = list(map(int, input().split()))
ans = 0
f = 0
for i in range(1,n+1):
  f = (f + a[i-1])%m
  d[f] += 1
for i in d:
  ans += d[i]*(d[i]-1)//2
print(ans)

Buggy submission (verdict: Runtime Error):
n,m = map(int, input().split())
ans = 0
a = list(map(int, input().split()))
b = [0]*(n+1)
for i in range(1,n+1):
  b[i] = (a[i-1] + b[i-1])%m
f = [0]*m
for i in b:
  f[i] += 1
for i in f:
  ans += i*(i-1)//2
print(ans)

Buggy submission (verdict: Runtime Error):
n,m = map(int, input().split())
ans = 0
def kx(t):
  return int(t)%m
a = list(map(kx, input().split()))
b = [0]*(n+1)
for i in range(1,n+1):
  a[i] = a[i-1] + b[i-1]
f = [0]*m
for i in b:
  f[i] += 1
for i in f:
  ans += i*(i-1)//2
print(ans)
Problem p03289 (python)

Fixed submission:
s = input()
b = 0
if s[0] == "A" and "C" in s[2:-1] and s[1:].replace("C","",1).islower():
    print("AC")
else:
    print("WA")

Buggy submission (verdict: Runtime Error):
s = list(input())
b = 0
if s[0] == "A" and "C" in s[2:-2] and s.replace("A","",1).replace("C","",1).islower():
    print("AC")
else:
    print("WA")
Problem p03313 (python)

Fixed submission:
def renew(lis,id1,id2):
  tar = lis[id1]; bow = lis[id2]
  if tar[0] < bow[0]:
    tar = [bow[0],max(bow[1],tar[0])]
  else:
    tar[1] = max(bow[0],tar[1])
  lis[id1] = tar
  return

n = int(input())
a = [[x,0] for x in list(map(int, input().split()))]
for j in range(n):
  for i in range(2**n):
    if not i & (1<<j):
      renew(a,i|(1<<j),i)
a = [x+y for x,y in a[1:]]
for i in range(1,2**n-1):
  if a[i] < a[i-1]:
    a[i] = a[i-1]
for x in a:
  print(x)

Buggy submission (verdict: Runtime Error):
def renew(lis,id1,id2):
  tar = lis[id1]; bow = lis[id2]
  if tar[0] < bow[0]:
    tar = [bow[0],max(bow[1],tar[0])]
  else:
    tar[1] = max(bow[0],tar[1])
  lis[id1] = tar
  return

n = int(input())
a = [[x,0] for x in list(map(int, input().split()))]
for j in range(n):
  t = 1<<j
  for i in range(1<<n):
    if not i&t:
      renew(a,i|t,i)
a = [x+y for x,y in a]
for i in range(1,1<<n):
  if a[i] < a[i-1]:
    a[i] = a[i-1]
for x in a[1:]:
  print(x)
Problem p03330 (python)

Fixed submission:
from collections import defaultdict as ddict
tot = 10**12
n,c = map(int, input().split())
d = [list(map(int, input().split())) for _ in range(c)]
clr = [list(map(int, input().split())) for _ in range(n)]
l = [ddict(int) for _ in range(3)]
for y in range(n):
  for x in range(n):
    l[(x+y)%3][clr[y][x]] += 1
for c1 in range(c):
  for c2 in range(c):
    if c1 == c2:
      continue
    for c3 in range(c):
      if c1==c3 or c2==c3:
        continue
      ctot = 0
      cl = [c1,c2,c3]
      for i in range(3):
        for x in l[i]:
          ctot += d[x-1][cl[i]]*l[i][x]
      if tot > ctot:
        tot = ctot
print(tot)

Buggy submission (verdict: Runtime Error):
from collections import defaultdict
tot = 10**12
n,c = map(int, input().split())
d = [list(map(int, input().split())) for _ in range(n)]
clr = [list(map(int, input().split())) for _ in range(n)]
l = [dict()]*3
for y in range(n):
  for x in range(n):
    l[(x+y)%3][clr[y][x]] += 1
for c1 in range(c):
  for c2 in range(c):
    if c1 == c2:
      continue
    for c3 in range(c):
      if c1==c3 or c2==c3:
        continue
      ctot = 0
      cl = [c1,c2,c3]
      for i in range(3):
        for x in l[i]:
          ctot += d[x-1][c[i]]*l[i][x]
      if tot > ctot:
        tot = ctot
print(tot)
Problem p03331 (python)

Fixed submission:
n = int(input())
s = n
for i in range(1, n//2+1):
  s = min(s, sum(map(int, list(str(i)))) + sum(map(int, list(str(n-i)))))
print(s)

Buggy submission (verdict: Runtime Error):
n = int(input())
s = n
for i in range(n//2+1):
  s = min(s, sum(list(str(i))) + sum(list(str(n-i))))
print(s)
Problem p03351 (python)

Fixed submission:
a, b, c, d = map(int, input().split())
ans = "No"
if abs(c-a) <= d:
  ans = "Yes"
elif abs(b-a) <= d and abs(c-b) <= d:
  ans = "Yes"
print(ans)

Buggy submission (verdict: Runtime Error):
a, b, c, d = map(int, input().spit())
ans = "No"
if abs(c-a) <= d:
  ans = "Yes"
elif abs(b-a) <= d and abs(c-b) <= d:
  ans = "Yes"
print(ans)
Problem p03355 (python)

Fixed submission:
s = input()
k = int(input())
sub = set()
for i in range(len(s)):
  for j in range(1,k+1):
    sub.add(s[i:i+j])
print(sorted(list(sub))[k-1])

Buggy submission (verdict: Runtime Error):
n,m = map(int, input().split())
p = list(map(int,input().split()))
d = [list() for _ in range(n+1)]
cnt = 0
for _ in range(m):
  x,y = map(int, input().split())
  d[x].append(y)
  d[y].append(x)
gr = [0]*(n+1)
gr[0] = -1
gn = 0
for x in range(1,n+1):
  if gr[x] == 0:
    gn += 1
    gr[x] = gn
    l = [x]
    while l:
      cur = l.pop()
      for i in d[cur]:
        if i not in l and gr[i] == 0:
          gr[i] = gn
          l.append(i)
for i in range(n):
  if gr[i+1] == gr[p[i]]:
    cnt += 1
print(cnt)

Buggy submission (verdict: Runtime Error):
s = input()
k = int(input())
sub = set()
for i in range(len(s)):
  for j in range(1,k):
    sub.add(s[i:i+j])
print(sorted(list(sub))[k-1])

Buggy submission (verdict: Runtime Error):
s = input()
k = int(input())
sub = set()
for i in range(n):
  for j in range(1,k):
    sub.add(s[i:i+j])
print(sorted(list(sub))[k-1])