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

Fixed submission:
N=int(input())
S=[input() for _ in range(N)]

a=0
w=0
t=0
r=0

for i in range(N):
  if S[i] =="AC":
    a+=1
  elif S[i] =="WA":
    w+=1
  elif S[i] =="TLE":
    t+=1
  elif S[i] =="RE":
    r+=1

print("AC x "+ str(a))
print("WA x "+ str(w))
print("TLE x "+ str(t))
print("RE x "+ str(r))

Buggy submission (verdict: Runtime Error):
N=int(input())
S=[input() for _ in range(N)]

a=0
w=0
t=0
r=0

for i range(N):
  if S[i] =="AC":
    a+=1
  elif S[i] =="WA":
    w+=1
  elif S[i] =="TLE":
    t+=1
  elif S[i] =="RE":
    r+=1

print("AC x "+ str(a))
print("WA x "+ str(w))
print("TLE x "+ str(t))
print("RE x "+ str(r))

Buggy submission (verdict: Runtime Error):
N= int(input())
S=[input() for _ in range(N)]

a=0
w=0
t=0
r=0

for i range(N):
  if S[i] =="AC":
    a+=1
  elif S[i] =="WA":
    w+=1
  elif S[i] =="TLE":
    t+=1
  elif S[i] =="RE":
    r+=1

print("AC x "+ str(a))
print("WA x "+ str(w))
print("TLE x "+ str(t))
print("RE x "+ str(r))

Buggy submission (verdict: Runtime Error):
N= int(input())
S=[ input() for _ in range(N) ]

a=0
w=0
t=0
r=0

for i range(N):
  if S[i] =="AC":
    a+=1
  elif S[i] =="WA":
    w+=1
  elif S[i] =="TLE":
    t+=1
  elif S[i] =="RE":
    r+=1

print("AC × "+ str(a))
print("WA × "+ str(w))
print("TLE × "+ str(t))
print("RE × "+ str(r))

Buggy submission (verdict: Runtime Error):
N= int(input())
S=[ input() for _ in range(N) ]

a=0
w=0
t=0
r=0

for i range(N):
  if S[i] =="AC":
    a+=1
  elif S[i] =="WA":
    w+=1
  elif S[i] =="TLE":
    t+=1
  elif S[i] =="RE":
    r+=1

print("AC x "+ str(a))
print("WA x "+ str(w))
print("TLE x "+ str(t))
print("RE x "+ str(r))

Buggy submission (verdict: Runtime Error):
N= int(input())
S=[ input() for _ in range(N) ]

a=0
w=0
t=0
r=0

for i range(N):
  if S[i] =="AC":
    a+=1
  elif S[i] =="WA":
    w+=1
  elif S[i] =="TLE":
    t+=1
  elif S[i] =="RE":
    r+=1

print("AC × "+ str(a))
print("WA × "+ str(w))
print("TLE × "+ str(t))
print("RE × "+ str(r))

Buggy submission (verdict: Runtime Error):
N= int(input())
S=[ input() for _ in range(N) ]

a=0
w=0
t=0
r=0

for i range(N):
  if S[i]=="AC":
    a+=1
  elif S[i]=="WA":
    w+=1
  elif S[i]=="TLE":
    t+=1
  elif S[i]=="RE":
    r+=1

print("AC x "　+ "str(a)")
print("WA x "　+ "str(w)")
print("TLE x "　+ "str(t)")
print("RE x "　+ "str(r)")

Buggy submission (verdict: Runtime Error):
N= int(input())
S=[ input() for _ in range(N) ]

a=0
w=0
t=0
r=0

for i range(N):
  if S[i]=="AC":
    a+=1
  elif S[i]=="WA":
    w+=1
  elif S[i]=="TLE":
    t+=1
  elif S[i]=="RE":
    r+=1

print("AC × "　+ "str(a)")
print("WA × "　+ "str(w)")
print("TLE × "　+ "str(t)")
print("RE × "　+ "str(r)")
Problem p02614 (python)

Fixed submission:
H,W,K=map(int, input().split())
C=list(input()for _ in range(H))
ans=0
import itertools
tf=("Yes", "No")
l=list(itertools.product(tf, repeat=(H+W)))
black=0
for i in range(2**(H+W)):
  for j in range(H):
    for k in range(W):
      if l[i][j]=="No"and l[i][H+k]=="No"and C[j][k]=="#":
        black+=1
  if black==K:
    ans+=1
  black=0
print(ans)

Buggy submission (verdict: Runtime Error):
H,W,K=map(int, input().split())
C=[list(input().split())for _ in range(H)]

#H,Wが小さいことが肝
#つまり全通り試してみる

#itertoolのうちpermutationが順列、combinationが組み合わせ
#productが直積

ans=0
import itertools
tf=("Yes", "No")
for l in itertools.product(tf, repeat=(H+W)):
  L=list(l)
black=0
for i in range(2**(H+W)):
  for j in range(H):
    for k in range(W):
      if l[i][j]=="No"and l[i][H+k]=="No"and C[j][k]=="#":
        black+=1
  if black==K:
    ans+=1
    black=0
print(ans)

Buggy submission (verdict: Runtime Error):
H,W,K=map(int, input().split())
C=[list(input().split())for _ in range(H)]

#H,Wが小さいことが肝
#つまり全通り試してみる

#itertoolのうちpermutationが順列、combinationが組み合わせ
#productが直積

ans=0
import itertools
tf=("Yes", "No")
for l in itertools.product(tf, repeat=(H+W)):
  L=list(l)
black=0
for i in range(2**(H+W)):
  for j in range(H):
    for k in range(W):
      if l[i][j]=="No", l[i][H+k]="No", C[j][k]="#":
        black+=1
  if black=K:
    ans+=1
    black=0
print(ans)
Problem p02658 (python)

Fixed submission:
def main ():
    N = int(input())
    A = list(map(int,input(). split ()))
    if 0 in A:
        print(0)
        return
    prod = 1
    for a in A:
        prod *= a
        if prod > 1000000000000000000:
            print(-1)
            return
    print(prod)
main ()

Buggy submission (verdict: Runtime Error):
def main ():
    N = int(input())
    A = list(map(int,input(). split ()))
    if 0 in A:
        print(0)
        return
    prod = 1
    for a in A:
        prod *= a
        if prod > 1000000000000000000:
        print(-1):
            return
    print(prod)
main ()
Problem p02732 (python)

Fixed submission:
from collections import deque, Counter as cnt
from collections import defaultdict as dd
from operator import itemgetter as ig
from bisect import bisect_right as bsr
from math import factorial, ceil, floor
import sys
sys.setrecursionlimit(1000000)

# お約束
args = None
INF = float("inf")
MOD = int(1e9 + 7)


def input(*ps):
    if type(ps[0]) is list:
        return [input(*ps[0][:-1]) for _ in range(ps[0][-1])]
    elif len(ps) == 1:
        return ps[0](next(args))
    else:
        return [p(next(args)) for p in ps]


def nlist(n, v):
    if not n:
        return [] if type(v) is list else v
    return [nlist(n[1:], v) for _ in range(n[0])]


def yesno(v):
    print(["Yes", "No"][not v])


# エントリーポイント
def main():
    N = input(int)
    A = input([int, N])

    count = dd(int)
    for a in A:
        count[a] += 1
    sum_ = 0
    for k, v in count.items():
        sum_ += (v * (v - 1)) // 2
    for a in A:
        print(sum_ - count[a] + 1)


if __name__ == '__main__':
    args = iter(sys.stdin.read().split())
    main()

Buggy submission (verdict: Runtime Error):
from collections import deque, Counter as cnt
from collections import defaultdict as dd
from operator import itemgetter as ig
from bisect import bisect_right as bsr
from math import factorial, ceil, floor
import sys
sys.setrecursionlimit(1000000)

# お約束
args = None
INF = float("inf")
MOD = int(1e9 + 7)


def input(*ps):
    if type(ps[0]) is list:
        return [input(*ps[0][:-1]) for _ in range(ps[0][-1])]
    elif len(ps) == 1:
        return ps[0](next(args))
    else:
        return [p(next(args)) for p in ps]


def nlist(n, v):
    if not n:
        return [] if type(v) is list else v
    return [nlist(n[1:], v) for _ in range(n[0])]


def yesno(v):
    print(["Yes", "No"][not v])


if not __name__ == '__main__':
    def debug(*v):
        print(*v)


# エントリーポイント
def main():
    N = input(int)
    A = input([int, N])

    count = dd(int)
    for a in A:
        count[a] += 1
    debug(count)
    for a in A:
        ans = 0
        for k, v in count.items():
            temp = v if not k == a else v - 1
            ans += (temp * (temp - 1)) // 2
        print(ans)


if __name__ == '__main__':
    args = iter(sys.stdin.read().split())
    main()
Problem p02756 (python)

Fixed submission:
from collections import deque, Counter as cnt
from collections import defaultdict as dd
from operator import itemgetter as ig
from bisect import bisect_right as bsr
from math import factorial, ceil, floor
import sys
sys.setrecursionlimit(1000000)

# お約束
args = None
INF = float("inf")
MOD = int(1e9 + 7)


def input(*ps):
    if type(ps[0]) is list:
        return [input(*ps[0][:-1]) for _ in range(ps[0][-1])]
    elif len(ps) == 1:
        return ps[0](next(args))
    else:
        return [p(next(args)) for p in ps]


def nlist(n, v):
    if not n:
        return [] if type(v) is list else v
    return [nlist(n[1:], v) for _ in range(n[0])]


def yesno(v):
    print(["Yes", "No"][not v])


# エントリーポイント
def main():
    S, Q = input(str, int)
    front, end, state = "", "", 0
    for _ in range(Q):
        t = int(next(args))
        if t == 1:
            state = (state + 1) % 2
            continue
        F, C = int(next(args)), str(next(args))
        if state == 0:
            if F == 1:
                front = C + front
            else:
                end = end + C
        else:
            if F == 1:
                end = end + C
            else:
                front = C + front
    ans = front + S + end
    if state == 1:
        ans = end[::-1] + S[::-1] + front[::-1]
    print(ans)


if __name__ == '__main__':
    args = iter(sys.stdin.read().split())
    main()

Buggy submission (verdict: Runtime Error):
from collections import deque, Counter as cnt
from collections import defaultdict as dd
from operator import itemgetter as ig
from bisect import bisect_right as bsr
from math import factorial, ceil, floor
import sys
sys.setrecursionlimit(1000000)

# お約束
args = None
INF = float("inf")
MOD = int(1e9 + 7)


def input(*ps):
    if type(ps[0]) is list:
        return [input(*ps[0][:-1]) for _ in range(ps[0][-1])]
    elif len(ps) == 1:
        return ps[0](next(args))
    else:
        return [p(next(args)) for p in ps]


def nlist(n, v):
    if not n:
        return [] if type(v) is list else v
    return [nlist(n[1:], v) for _ in range(n[0])]


def yesno(v):
    print(["Yes", "No"][not v])


# エントリーポイント
def main():
    S, Q = input(str, int)
    front, end, state = "", "", 0
    for _ in range(Q):
        t = int(next(args))
        if t == 1:
            state = (state + 1) % 2
            continue
        F, C = int(next(args)), str(next(args))
        if state == 0:
            if F == 1:
                front = C + front
            else:
                end = end + C
        else:
            if F == 1:
                end = end + C
            else:
                front = C + front
        print(front, end, state)
    ans = front + S + end
    if state == 1:
        ans = end[::-1] + S[::-1] + front[::-1]
    print(ans)


if __name__ == '__main__':
    args = iter(sys.stdin.read().split())
    main()
Problem p02936 (python)

Fixed submission:
import sys
from math import factorial, ceil, floor
from bisect import bisect_right as bsr
from operator import itemgetter as ig
from collections import defaultdict as dd
from collections import deque

# お約束
args = None
INF = float("inf")
MOD = int(1e9 + 7)
def int1(n):
    return int(n) - 1
def input():
    return next(args)
def parse(*params):
    if len(params) == 1:
        return params[0](next(args))
    return tuple(p(v) for p, v in zip(params, next(args).split()))
def debug(*v):
    if __debug__:
        print(*v, file=sys.stderr)

# エントリーポイント
def main():
    N, Q = parse(int, int)
    edges = [[] for _ in range(N)]
    for _ in range(N - 1):
        a, b = parse(int1, int1)
        edges[a] += [b]
        edges[b] += [a]
    vals = [0] * N
    for _ in range(Q):
        p, x = parse(int1, int)
        vals[p] += x

    counter = [0] * N
    que = [(0, 0)]
    alr = [False] * N
    while que:
        v, x = que.pop()
        alr[v] = True
        counter[v] += x + vals[v]
        for n in edges[v]:
            if not alr[n]:
                que.append((n, counter[v]))

    for v in counter:
        print(v)

if __name__ == '__main__':
    args = iter(sys.stdin.read().split("\n"))
    main()

Buggy submission (verdict: Runtime Error):
# お約束
INF = float("inf")
MOD = int(1e9 + 7)

N, Q = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(N - 1)]
PX = [list(map(int, input().split())) for _ in range(Q)]

sum_val = [0] * N
for p, x in PX:
	p, x = p - 1, x
	sum_val[p] += x

edges = [[] for _ in range(N)]
for a, b in AB:
	a, b = a - 1, b - 1
	edges[a] += [b]
	edges[b] += [a]

visited = [False] * N
vals = [0] * N

def dfs(v, p, add_val):
	global visited, vals
	visited[v] = True
	vals[v] = add_val + sum_val[v]
	for n in edges[v]:
		if visited[n]: continue
		dfs(n, v, add_val + sum_val[v])

dfs(0, -1, 0)
for v in vals:
	print(v)
Problem p02960 (python)

Fixed submission:
MOD = 10 ** 9 + 7

S = input()
dp = [[0] * 13 for _ in range(len(S) + 1)]
dp[0][0] = 1

for i, s in enumerate(S):
	if s == "?":
		for n in range(13):
			for m in range(10):
				mod = (n * 10 + m) % 13
				dp[i + 1][mod] += dp[i][n]
				dp[i + 1][mod] %= MOD
	else:
		m = int(s)
		for n in range(13):
			mod = (n * 10 + m) % 13
			dp[i + 1][mod] += dp[i][n]
			dp[i + 1][mod] %= MOD

#for l in dp:
#	print(l)

print(dp[-1][5])

Buggy submission (verdict: Runtime Error):
def main():
    S = input()
    dp = [[0 for _ in range(13)] for _ in range(len(S) + 1)]
    dp[0][0] = 1
    for i, s in enumerate(S):
        i += 1
        loop = range(10) if s == "?" else [int(s)]
        for n in range(13):
            for m in loop:
                dp[i][(n * 10 + m) % 13] += dp[i - 1][n]
                dp[i][(n * 10 + m) % 13] %= MOD
    print(dp[-1][5])

main()
Problem p02985 (python)

Fixed submission:
import sys
sys.setrecursionlimit(100000)

N, K = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(N - 1)]

MOD = 10 ** 9 + 7

g = [[] for _ in range(N)]
for a, b in AB:
	a, b = a - 1, b - 1
	g[a] += [b]
	g[b] += [a]

cn = [0] * N
def dfs(v, p):
	cn[v] = len(set(g[v]) - {p})
	for n in g[v]:
		if n == p:
			continue
		dfs(n, v)
dfs(0, -1)

r = K
for i in range(cn[0]):
	r *= K - 1 - i
	r %= MOD

for n in cn[1:]:
	for i in range(n):
		r *= K - 2 - i
		r %= MOD

print(r)

Buggy submission (verdict: Runtime Error):
N, K = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(N - 1)]

MOD = 10 ** 9 + 7

g = [[] for _ in range(N)]
for a, b in AB:
	a, b = a - 1, b - 1
	g[a] += [b]
	g[b] += [a]

cn = [0] * N
def dfs(v, p):
	cn[v] = len(set(g[v]) - {p})
	for n in g[v]:
		if n == p:
			continue
		dfs(n, v)
dfs(0, -1)

r = K
for i in range(cn[0]):
	r *= K - 1 - i
	r %= MOD

for n in cn[1:]:
	for i in range(n):
		r *= K - 2 - i
		r %= MOD

print(r)
Problem p02991 (python)

Fixed submission:
N, M = map(int, input().split())
UV = [list(map(int, input().split())) for _ in range(M)]
S, T = map(int, input().split())

if 0 == M:
	print(-1)
	exit()

graph = [set() for _ in range(N)]
for u, v in UV:
	graph[u - 1] |= {v - 1}

INF = 10 ** 12
depths = [[INF, INF, INF] for _ in range(N)]

def bfs(start, end):
	depth = 0
	nodes = {start}
	while nodes:
		if (0 == depth % 3) and (end in nodes):
			return depth // 3
		next_nodes = set()
		for node in nodes:
			if depths[node][depth % 3] <= depth:
				continue
			depths[node][depth % 3] = depth
			next_nodes |= graph[node]
		nodes = next_nodes
		depth += 1
	return -1

print(bfs(S - 1, T - 1))

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
UV = [list(map(int, input().split())) for _ in range(M)]
S, T = map(int, input().split())

if 0 == M:
	print(-1)
	exit()

s, t = S - 1, T - 1

graph = [[] for _ in range(N)]
for u, v in UV:
	graph[u - 1] += [v - 1]

INF = 10 ** 12
cost = [[INF, INF, INF] for _ in range(N)]
def print_cost(cost):
	for line in cost:
		for cell in line:
			print("  INF" if cell == INF else " {:4d}".format(cell), end="")
		print()
	print()

def dfs(graph, cost, c, d):
	if cost[c][d % 3] <= d:
		return
	cost[c][d % 3] = d
	#print_cost(cost)
	for n in graph[c]:
		dfs(graph, cost, n, d + 1)

dfs(graph, cost, s, 0)

print(cost[t][0] // 3 if 0 == cost[t][0] % 3 else -1)

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
UV = [list(map(int, input().split())) for _ in range(M)]
S, T = map(int, input().split())

if 0 == M:
	print(-1)
	exit()

s, t = S - 1, T - 1

graph = [[] for _ in range(M)]
for u, v in UV:
	graph[u - 1] += [v - 1]

INF = 10 ** 12
cost = [[INF, INF, INF] for _ in range(M)]
def print_cost(cost):
	for line in cost:
		for cell in line:
			print("  INF" if cell == INF else " {:4d}".format(cell), end="")
		print()
	print()

def dfs(graph, cost, c, d):
	if cost[c][d % 3] <= d:
		return
	cost[c][d % 3] = d
	#print_cost(cost)
	for n in graph[c]:
		dfs(graph, cost, n, d + 1)

dfs(graph, cost, 0, 0)

print(cost[T - 1][0] // 3 if 0 == cost[T - 1][0] % 3 else -1)
Problem p03032 (python)

Fixed submission:
N, K = map(int, input().split())
V = list(map(int, input().split()))

vmax = 0
for l in range(0, K + 1):
	for r in range(0, K - l + 1):
		if N < l + r:
			break
		tv = V[:l] + V[N - r:]
		#print(tv)
		tv.sort()
		for n in range(min(len(tv), K - (l + r))):
			if tv[n] < 0:
				tv[n] = 0
		vmax = max(vmax, sum(tv))

print(vmax)

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

rs = [0]
def check(k, v, current):
	global rs
	rs += [sum(current)]
	if 0 == k:
		return
	else:
		if current:
			i = current.index(min(current))
			check(k - 1, v + [min(current)], current[:i] + current[i + 1:])
			check(k - 1, [min(current)] + v, current[:i] + current[i + 1:])
		check(k - 1, v[1:], current + [v[0]])
		check(k - 1, v[:-1], current + [v[-1]])
		return

check(K, V, [])

print(max(rs))
Problem p03043 (python)

Fixed submission:
N, K = map(int, input().split())

r = 0
for n in range(1, N + 1):
	c, t = 0, n
	while t < K:
		t *= 2
		c += 1
	r += (1 / N) * (1 / 2) ** c
print(r)

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

r = 0
def func(n):
	c, t = 0, n
	while t <= K:
		t <<= 1
		c += 1
	#return (1 / 2) ** c
	return c
"""
for n in range(N):
	#r += [func(n)]
	r += 2 ** n
	#print(r)
"""

base = func(1)

r = int("1" * (base - 1), 2)
#print(r)

print(r * ((1 / 2) ** base) / N)
Problem p03081 (python)

Fixed submission:
N, Q = map(int, input().split())
S = list(input())
TD = [tuple(input().split()) for _ in range(Q)]

def bs_l(f, s, e):
	if s==e:
		return s if f(s) else s+1

	c = (s+e)//2
	if f(c):
		#左
		return bs_l(f, s, c if c == s else c-1)
	else:
		#右
		return bs_l(f, c if c == e else c+1, e)

def bs_r(f, s, e):
	if s==e:
		return s if f(s) else s-1

	c = (s+e)//2
	if not f(c):
		#左
		return bs_r(f, s, c if c == s else c-1)
	else:
		#右
		return bs_r(f, c if c == e else c+1, e)

def isAlive(c):
	for t, d in TD:
		if S[c] == t:
			c += 1 if "R" == d else -1
			if c < 0 or N <= c:
				return False
	return True

S, E = bs_l(isAlive, 0, N-1), bs_r(isAlive, 0, N-1)
print(max(E-S+1, 0))

Buggy submission (verdict: Runtime Error):
N, Q = map(int, input().split())
S = input()
TD = reversed([tuple((input().split())) for _ in range(Q)])

left, right = 0, N-1

for t, d in TD:
	if S[left] == t and "L" == d:
		left += 1
	if S[right] == t and "R" == d:
		right -= 1
print(right-left+1)

Buggy submission (verdict: Runtime Error):
N, Q = map(int, input().split())
S = list(input())
TD = [tuple(input().split()) for _ in range(Q)]

def bs_l(f, s, e):
	if s==e:
		return s if(1==f(s)) else s+1

	c = (s+e)//2
	if f(c):
		#左
		return bs_l(f, s, c if c == s else c-1)
	else:
		#右
		return bs_l(f, c if c == e else c+1, e)

def bs_r(f, s, e):
	if s==e:
		return s if(1==f(s)) else s-1

	c = (s+e)//2
	if not f(c):
		#左
		return bs_r(f, s, c if c == s else c-1)
	else:
		#右
		return bs_r(f, c if c == e else c+1, e)

def isAlive_l(c):
	if c < 0 or N <= c:
		return False

	for t, d in TD:
		if S[c] == t:
			c += 1 if "R" == d else -1
			if c < 0:
				return False
	return True

def isAlive_r(c):
	if c < 0 or N <= c:
		return False

	for t, d in TD:
		if S[c] == t:
			c += 1 if "R" == d else -1
			if N <= c:
				return False
	return True

S, E = bs_l(isAlive_l, 0, N-1), bs_r(isAlive_r, 0, N-1)
print(E-S+1)

Buggy submission (verdict: Runtime Error):
N, Q = map(int, input().split())
S = list(input())
TD = [tuple(input().split()) for _ in range(Q)]

TEST = [0, 0, 0, 1, 1, 1, 0, 0]

def bs_l(f, s, e):
	if s==e:
		return s if(1==f(s)) else s+1

	c = (s+e)//2
	if f(c):
		#左
		return bs_l(f, s, c if c == s else c-1)
	else:
		#右
		return bs_l(f, c if c == e else c+1, e)

def bs_r(f, s, e):
	if s==e:
		return s if(1==f(s)) else s-1

	c = (s+e)//2
	if not f(c):
		#左
		return bs_r(f, s, c if c == s else c-1)
	else:
		#右
		return bs_r(f, c if c == e else c+1, e)

def isAlive_l(c):
	for t, d in TD:
		if S[c] == t:
			c += 1 if "R" == d else -1
			if c < 0:
				return False
	return True

def isAlive_r(c):
	for t, d in TD:
		if S[c] == t:
			c += 1 if "R" == d else -1
			if N <= c:
				return False
	return True

S, E = bs_l(isAlive_l, 0, N-1), bs_r(isAlive_r, 0, N-1)
print(E-S+1)
Problem p03086 (python)

Fixed submission:
import re
S = input()
H = re.findall("[ACGT]+", S)
max_length = 0
for h in H:
	if max_length < len(h):
		max_length = len(h)
print(max_length)

Buggy submission (verdict: Runtime Error):
S = input()
H = re.findall("[ACGT]+", S)
max_length = 0
for h in H:
	if max_length < len(h):
		max_length = len(h)
print(max_length)
Problem p03087 (python)

Fixed submission:
N, Q = map(int, input().split())
S = input()

# S         * A C * A C C
# sumlist   0 0 1 1 1 2 2
sumlist = [0]
for i in range(1, len(S)):
	sumlist.append(sumlist[-1])
	if S[i - 1] == "A" and S[i] == "C":
		sumlist[-1] += 1

query = []
for i in range(Q):
	l, r = map(int, input().split())
	query.append(dict(l=l-1, r=r-1))

for q in query:
	print(sumlist[q["r"]] - sumlist[q["l"]])

Buggy submission (verdict: Runtime Error):
import re

N, Q = map(int, input().split())
S = list(input())
P = []

for _ in range(Q):
	l, r = map(int, input().split())
	P.append((l, r))

for p in P:
	s = S[p[0] - 1:p[1]]
	I = [i for i, x in enumerate(s) if x == "A"]
	if I[-1] == (len(s) - 1):
		I.pop()
	count = 0
	for i in I:
		if s[i + 1] == "C":
			count += 1
	print(count)
Problem p03103 (python)

Fixed submission:
def main():
	N, M = map(int, input().split())
	S = []
	for i in range(N):
		a, b = map(int, input().split())
		S.append([a, b])
	sorted_shop_list = sorted(S, key=lambda x: x[0])
	cost = 0
	for i in sorted_shop_list:
		a = i[0]
		b = i[1]
		if b < M:
			M -= b
			cost += a * b
		else:
			cost += a * M
			break
	print(cost)
	return

if __name__ == '__main__':
	main()

Buggy submission (verdict: Runtime Error):
def main():
	N, M = map(int, input().split())
	S = {}
	for i in range(N):
		a, b = map(int, input().split())
		S[a] = b
	sorted_price_list = sorted(S)
	cost = 0
	for i in range(N):
		a = sorted_price_list[i]
		mc = S[a]
		if mc < M:
			M -= mc
			cost += a * mc
		else:
			cost += a * M
			print(cost)
			return
	return

if __name__ == '__main__':
	main()

Buggy submission (verdict: Runtime Error):
def main():
	N, M = map(int, input().split())
	S = {}
	for i in range(N):
		a, b = map(int, input().split())
		S[a] = b
	sorted_price_list = sorted(S)
	cost = 0
	for i in range(N):
		a = sorted_price_list[i]
		mc = S[a]
		if M <= mc:
			for i in range(mc):
				M -= 1
				cost += a
				if M <= 0:
					print(cost)
					return
		else:
			M -= mc
			cost += a * mc
	return

if __name__ == '__main__':
	main()