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

Fixed submission:
import numpy as np
from collections import defaultdict
import sys
sys.setrecursionlimit(10**9)
def rec(start, p):
    if ans[start] != -1:
        return p
    ans[start] = C[p]
    p += 1
    for node in tree[start+1]:
        p = rec(node-1, p)
    return p

N = int(input())
tree = defaultdict(list)
degree = [0 for i in range(N)]
edges = [0 for i in range(N-1)]
for i in range(N-1):
    a, b = map(int, input().split())
    edges[i] = (a, b)
    tree[a].append(b)
    tree[b].append(a)
for k, v in tree.items():
    degree[k-1] = len(v)
# print(degree)
sort_i = np.argsort(degree)[::-1]
# max_di = sort_i[-1]
# print(sort_i)
C = list(map(int, input().split()))
C = sorted(C, reverse=True)
# C = list(sorted(zip(sorted(C), list(sort_i)),key=lambda x: x[1]))
# print(C[sort_i])
ans = 0
visited_e = []
# start = max_di + 1
visited = [False for i in range(N)]
p = 0
ans = [-1 for i in range(N)]
M = 0

rec(sort_i[0], p)

for e in edges:
    M += min(ans[e[0]-1], ans[e[1]-1])
    # print(ans)
print(M)
print(' '.join(list(map(lambda x: str(x), ans))))

Buggy submission (verdict: Runtime Error):
import numpy as np
from collections import defaultdict

def rec(start, p):
    if ans[start] != -1:
        return p
    ans[start] = C[p]
    p += 1
    for node in tree[start+1]:
        p = rec(node-1, p)
    return p

N = int(input())
tree = defaultdict(list)
degree = [0 for i in range(N)]
edges = [0 for i in range(N-1)]
for i in range(N-1):
    a, b = map(int, input().split())
    edges[i] = (a, b)
    tree[a].append(b)
    tree[b].append(a)
for k, v in tree.items():
    degree[k-1] = len(v)
# print(degree)
sort_i = np.argsort(degree)[::-1]
# max_di = sort_i[-1]
# print(sort_i)
C = list(map(int, input().split()))
C = sorted(C, reverse=True)
# C = list(sorted(zip(sorted(C), list(sort_i)),key=lambda x: x[1]))
# print(C[sort_i])
ans = 0
visited_e = []
# start = max_di + 1
visited = [False for i in range(N)]
p = 0
ans = [-1 for i in range(N)]
M = 0

rec(sort_i[0], p)

for e in edges:
    M += min(ans[e[0]-1], ans[e[1]-1])
    # print(ans)
print(M)
print(' '.join(list(map(lambda x: str(x), ans))))
Problem p03044 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10**7)
from collections import defaultdict
def dfs(node_i, oe):
    if ans[node_i] != -1:
        return
    next_nodes = graph[node_i]
    ans[node_i] = oe
    for next_i, cost in next_nodes:
        dfs(next_i, (oe+cost)%2)
        

N = int(input())
ans = [-1 for i in range(N+1)]
graph = defaultdict(list)
for i in range(N-1):
    u, v, w = map(int, input().split())
    graph[u] += [(v, w)]
    graph[v] += [(u, w)]

dfs(1, 0)
for i in range(1, N+1):
    print(ans[i])

Buggy submission (verdict: Runtime Error):
from collections import defaultdict
def dfs(node_i, oe):
    if ans[node_i] != -1:
        return
    next_nodes = graph[node_i]
    ans[node_i] = oe
    for next_i, cost in next_nodes:
        dfs(next_i, (oe+cost)%2)
        

N = int(input())
ans = [-1 for i in range(N+1)]
graph = defaultdict(list)
for i in range(N-1):
    u, v, w = map(int, input().split())
    graph[u] += [(v, w)]
    graph[v] += [(u, w)]

dfs(1, 0)
for i in range(1, N+1):
    print(ans[i])
Problem p03096 (python)

Fixed submission:
MOD = 10**9 + 7
N = int(input())
C = [int(input()) for i in range(N)]
dp = [0] * (N+1)
dp_c = [0] * (2*10**5+1)
pred_ci = 0
dp[0] = 1
for i, ci in enumerate(C, 1):
    if pred_ci == ci:
        dp[i] += dp[i-1]
        continue
    dp[i] = (dp[i-1] + dp_c[ci]) % MOD
    dp_c[ci] = dp[i]
    pred_ci = ci

print(dp[N])

Buggy submission (verdict: Runtime Error):
N = int(input())
C = [int(input()) for i in range(N)]
dp = [0] * (N+1)
dp_c = [0] * (N+1)
pred_ci = 0
dp[0] = 1
for i, ci in enumerate(C, 1):
    if pred_ci == ci:
        dp[i] += dp[i-1]
        continue
    dp[i] += dp[i-1] + dp_c[ci]
    dp_c[ci] = dp[i]
    pred_ci = ci

print(dp[N])
Problem p03160 (python)

Fixed submission:
N = int(input())
H = list(map(int, input().split()))
C = [10**13 for i in range(N)]
C[0] = 0
for i in range(N):
    if i+1 < N:
        C[i+1] = min(C[i] + abs(H[i+1]-H[i]), C[i+1])
    if i+2 < N:
        C[i+2] = min(C[i] + abs(H[i+2]-H[i]), C[i+2])
print(C[-1])

Buggy submission (verdict: Runtime Error):
def rec(i):
    if i == 0:
        C[i] = 0
        return C[i]
    elif i == 1:
        C[i] = rec(i-1)+abs(H[i]-H[i-1])
        return C[i]
    # print(i, rec(i-1), rec(i-2))
    C[i] = min(rec(i-1)+abs(H[i]-H[i-1]), rec(i-2)+abs(H[i]-H[i-2]))
    return C[i]
INFTY = 10**13
N = int(input())
H = list(map(int, input().split()))
C = [INFTY for i in range(N)]
# C[0] = 0
# for i in range(N):
#     if i+1 < N:
#         C[i+1] = min(C[i] + abs(H[i+1]-H[i]), C[i+1])
#     if i+2 < N:
#         C[i+2] = min(C[i] + abs(H[i+2]-H[i]), C[i+2])
# print(C[-1])
print(rec(N-1))
Problem p03229 (python)

Fixed submission:
N = int(input())
A = [int(input()) for i in range(N)]
A = sorted(A)
h = N // 2
if N % 2 == 0:
    ans = sum(A[h:])*2 - sum(A[:h])*2 - A[h] + A[h-1]
else:
    ans1 = sum(A[h-1:])*2 - sum(A[:h-1])*2 - (A[h-1] + A[h]) * 3
    ans2 = sum(A[h:])*2 - sum(A[:h])*2 - (A[h] + A[h+1])
    ans = max(ans1, ans2)
print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = [int(input()) for i in range(N)]
A.sort()
leftA = A[:N//2+N%2]
rightA = A[N//2+N%2:]
rightA.sort(reverse=True)
tmp = leftA[0]
leftA[0] = leftA[1]
leftA[1] = tmp
ans = 0
if len(leftA) == len(rightA):
    for i in range(N//2):
        if i == 0:
            ans += abs(leftA[i] - rightA[i])
            lastA = rightA[i]
            continue
        ans += abs(lastA - leftA[i])
        if i == N//2-1:
            ans += max(abs(leftA[i] - rightA[i]), abs(leftA[0] - rightA[i]))
            continue
        ans += abs(leftA[i] - rightA[i])
        lastA = rightA[i]
else:
    for i in range(N//2+1):
        if i == 0:
            ans += abs(leftA[i] - rightA[i])
            lastA = rightA[i]
            continue
        ans += abs(lastA - leftA[i])
        if i == N//2:
            continue
        ans += abs(leftA[i] - rightA[i])
        lastA = rightA[i]
    ans2 = 0
    tmp = leftA.pop(-1)
    rightA.insert(0, tmp)
    for i in range(N//2):
        if i == 0:
            ans2 += abs(leftA[i] - rightA[i])
            lastA = rightA[i]
            continue
        ans2 += abs(lastA - leftA[i])
        lastA = rightA[i]
    ans2 += abs(rightA[-2] - rightA[-1])
    ans = max(ans, ans2)

print(ans)
Problem p03241 (python)

Fixed submission:
import math
N, M = map(int, input().split())
tmp = [1]
if N == 1:
    print(M)
else:
    for i in range(2, int(math.ceil(M**0.5))):
        if M % i == 0:
            tmp.append(i)
            tmp.append(int(M/i))
    ans = 1
    for x in tmp:
        if M / x >= N:
            ans = max(ans, x)
    print(ans)

Buggy submission (verdict: Runtime Error):
import math
N, M = map(int, input().split())
tmp = [1]
if N == 1:
    print(M)
else:
    for i in range(2, int(math.ceil(M**0.5))):
        if M % i == 0:
            tmp.append(i)
            tmp.append(M/i)
    ans = 1
    for x in tmp:
        if m / x >= N:
            ans = max(ans, x)
    print(ans)

Buggy submission (verdict: Runtime Error):
import math
N, M = map(int, input().split())
tmp = [1]
if N == 1:
    print(M)
else:
    for i in range(2, int(math.ceil(M**0.5))):
        if M % i == 0:
            tmp.append(i)
            tmp.apend(M/i)
    ans = 1
    for x in tmp:
        if m / x >= N:
            ans = max(ans, x)
    print(ans)

Buggy submission (verdict: Runtime Error):
import math
N, M = map(int, input().split())
tmp = [1]
if N == 1:
    print(M)
else:
    for i in range(2, math.ceil(M**0.5)):
        if M % i == 0:
            tmp.append(i)
            tmp.apend(M/i)
    ans = 1
    for x in tmp:
        if m / x >= N:
            ans = max(ans, x)
    print(ans)
Problem p03263 (python)

Fixed submission:
H, W = map(int, input().split())
A = [[0 for w in range(W)] for h in range(H)]
for h in range(H):
    A[h] = list(map(int, input().split()))
    
ans = []
for h in range(H-1):
    for w in range(W):
        if A[h][w] % 2 == 1:
            A[h][w] -= 1
            A[h+1][w] += 1
            ans.append([h+1, w+1, h+2, w+1])
            
for w in range(W-1):
    if A[H-1][w] % 2 == 1:
        A[H-1][w] -= 1
        A[H-1][w+1] += 1
        ans.append([H, w+1, H, w+2])
    
print(len(ans))
for a in ans:
    print(a[0], a[1], a[2], a[3])

Buggy submission (verdict: Runtime Error):
h, w = map(int, input().split())
a = [list(map(int, input().split())) for i in range(h)]
ans = []
for i in range(h):
    for j in range(w):
        if a[i][j] % 2 == 0:
            continue
        elif j+1 < w:
            a[i][j+1] += 1
            ans.append(i, j, i, j+1)
        elif i+1 < h:
            a[i+1][j] += 1
            ans.append(i, j, i+1, j)
        # elif j + 1 < w and a[i][j+1] % 2 == 1:
        #     a[i][j] -= 1
        #     a[i][j+1] += 1
        #     continue
        #     ans.append([i, j, i, j+1])
        # elif i + 1 < h and a[i+1][j] % 2 == 1:
        #     a[i][j] -= 1
        #     a[i+1][j] += 1
        #     ans.append([i, j, i+1, j])
        #     continue
        # elif j - 1 >= 0 and a[i][j-1] % 2 == 1:
        #     a[i][j] -= 1
        #     a[i][j-1] += 1
        #     ans.append([i, j, i, j-1])
        #     continue
        # elif i - 1 >= 0 and a[i-1][j] % 2 == 1:
        #     a[i][j] -= 1
        #     a[i-1][j] += 1
        #     ans.append([i, j, i-1, j])
        #     continue
print(len(ans))
for x in ans:
    print(x[0], x[1], x[2], x[3])

Buggy submission (verdict: Runtime Error):
h, w = map(int, input().split())
a = [list(map(int, input().split())) for i in range(h)]
ans = []
for i in range(h):
    for j in range(w):
        if a[i][j] % 2 == 0:
            continue
        elif j+1 < w and :
            a[i][j+1] += 1
            ans.append(i, j, i, j+1)
        elif i+1 < h:
            a[i+1][j] += 1
            ans.append(i, j, i+1, j)
print(len(ans))
for x in ans:
    print(x[0], x[1], x[2], x[3])

Buggy submission (verdict: Runtime Error):
h, w = map(int, input().split())
a = [list(map(int, input().split())) for i in range(h)]
ans = []
for i in range(h):
    for j in range(w):
        if a[i,j] % 2 == 0:
            continue
        elif j + 1 < w and a[i, j+1] % 2 == 1:
            a[i, j] -= 1
            a[i, j+1] += 1
            continue
            ans.append([i, j, i, j+1])
        elif i + 1 < h and a[i+1, j] % 2 == 1:
            a[i, j] -= 1
            a[i+1, j] += 1
            ans.append([i, j, i+1, j])
            continue
        elif j - 1 >= 0 and a[i, j-1] % 2 == 1:
            a[i, j] -= 1
            a[i, j-1] += 1
            ans.append([i, j, i, j-1])
            continue
        elif i - 1 >= 0 and a[i-1, j] % 2 == 1:
            a[i, j] -= 1
            a[i-1, j] += 1
            ans.append([i, j, i-1, j])
            continue
print(len(ans))
for x in ans:
    print(x[0], x[1], x[2], x[3])
Problem p03294 (python)

Fixed submission:
import fractions
N = int(input())
ai = list(map(int, input().split()))
m = 1
ans = 0
for a in ai:
    m = (m * a) // fractions.gcd(m, a)
m -= 1
for a in ai:
    ans += m % a

print(ans)

Buggy submission (verdict: Runtime Error):
import math
N = int(input())
ai = list(map(int, input().split()))
m = 1
ans = 0
for a in ai:
    m = (m * a) // math.gcd(m, a)
m -= 1
for a in ai:
    ans += m % a
    
print(ans)
Problem p03337 (python)

Fixed submission:
a, b = map(int, input().split())
ans = max(a+b, a-b)
ans = max(ans, a*b)
print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))
A2 = []
Z = []
ans = 0
zerocnt = 0
for ai in A:
    if ai == 0:
        zerocnt += 1
    elif zerocnt >= 1:
        A2 += [0]
        Z += [zerocnt]
        ans += (zerocnt * (zerocnt+1)) // 2
        zerocnt = 0
    if ai != 0:
        A2 += [ai]
        Z += [1]
        ans += 1

if zerocnt >= 1:
    A2 += [0]
    Z += [zerocnt]
    ans += (zerocnt * (zerocnt+1)) // 2
    zerocnt = 0

for i, ai in enumerate(A2):
    aixor = ai
    sumA = ai
    for j in range(i+1, min(i+41, len(A2))):
        aj = A2[j]
        aixor = aixor ^ aj
        sumA += aj
        if aixor != sumA:
            break
        else:
            ans += (Z[i] * Z[j])
        
print(ans)
Problem p03362 (python)

Fixed submission:
n = int(input())

isprime = [True for i in range(55556)]
isprime[0] = False
isprime[1] = False
for i in range(4, 55556, 2):
    isprime[i] = False
for i in range(3, 237):
    if isprime[i]:
        for j in range(i*3, 55556, i*2):
            isprime[j] = False
ans = []
for i in range(55556):
    flag = False
    if isprime[i] and i % 5 == 1:
        ans.append(i)
    if len(ans) == n:
        break
for i in ans:
    print(i, end=' ')

Buggy submission (verdict: Runtime Error):
from itertools import combinations
n = int(input())

isprime = [True for i in range(55556)]
isprime[0] = False
isprime[1] = False
for i in range(4, 55556, 2):
    isprime[i] = False
for i in range(3, 237):
    if isprime[i]:
        for j in range(i*3, 55556, i*2):
            isprime[j] = False
ans = []
for i in range(55556):
    flag = False
    if isprime[i]:
        if len(ans) >= 4:
            for c in combinations(ans, 4):
                if isprime[sum(c) + i]:
                    flag = True
                    break
            if flag:
                continue
        ans.append(i)
    if len(ans) == n:
        break
for i in ans:
    print(i, end=' ')
Problem p03427 (python)

Fixed submission:
n = input()
head = n[0]
tail = '0' * (len(n) - 1)
m = str(int(head + tail) - 1)
sumn = 0
summ = 0
for i in n:
    sumn += int(i)
for i in m:
    summ += int(i)
print(max(sumn, summ))

Buggy submission (verdict: Runtime Error):
n = input()
tail = int(n[1:])
m = str(int(n) - tail - 1)
ans = 0
for i in m:
    ans += int(i)
print(ans)
Problem p03607 (python)

Fixed submission:
N = int(input())
ans = {}
for i in range(N):
  ai = int(input())
  if ans.get(ai):
    ans.pop(ai)
  else:
    ans[ai] = 1
print(len(ans))

Buggy submission (verdict: Runtime Error):
N = int(input())
Ex = [False for i in range(100001)]
for i in range(N):
	A = int(input())
	Ex[A] = not Ex[A]
count = 0
for tf in range(100001):
	if Ex[tf]:
		count += 1
print(count)
Problem p03673 (python)

Fixed submission:
from collections import deque
d = deque()
n = int(input())
a = input().split()

for i in range(n):
	if i % 2 == n % 2:
		d.append(a[i])
	else:
		d.appendleft(a[i])

print(' '.join(d))

Buggy submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
for i in range(n):
	if i % 2 == n % 2:
		b.insert(0, a[i])
	else:
		b.append(a[i])

for x in b:
	print(x, end=' ')
print()

Buggy submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
for i in range(n):
	if i % 2 == n & 2:
		b.insert(0, a[i])
	else:
		b.append(a[i])

for x in b:
	print(x, end=' ')
print()
Problem p03970 (python)

Fixed submission:
s = input()
count = 0;
anser = "CODEFESTIVAL2016"
for i in range(0,16):
	if not s[i] == anser[i]:
		count+=1
print(count)

Buggy submission (verdict: Runtime Error):
nums = input().split()
N = int(nums[0])
A = int(nums[1])
B = int(nums[2])
S = input()
count = 0
bcount = 0
for x in S:
	if x == 'a' and A+B > count:
		count += 1
		print("Yes")
	elif x == 'b' and A+B > count and bcount < B :
		count += 1
		bcount += 1
		print("Yes")
	else :
		print("No")
Problem p03694 (python)

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
A.sort()
print(A[-1] - A[0])

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))
A.sort()
print(A[-1] - A[1])
Problem p03695 (python)

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
col = [0] * 9
for i in A:
  r = i//400
  if r > 8:
    r = 8
  col[r] += 1

ans = 0
for i in col[:8]:
  if i > 0:
    ans += 1

if ans == 0:
  print(1, col[-1])
else:
  print(ans, ans + col[-1])

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))
col = [0] * 9
for i in A:
  r = i//400
  if r > 9:
    r = 8
  col[r] += 1

ans = 0
for i in col[:8]:
  if i > 0:
    ans += 1

print(ans, ans + col[-1])

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))
col = [0] * 9
for i in A:
  col[i // 400] += 1

ans = 0
for i in col[:8]:
  if i > 0:
    ans += 1

print(ans, ans + col[-1])
Problem p02678 (python)

Fixed submission:
import sys
from collections import deque

sys.setrecursionlimit(10**6)
readline = sys.stdin.readline

def main():
    N, M = map(int, readline().split())
    graph = [[] for _ in range(N)]
    for _ in range(M):
        A, B = map(int, readline().split())
        A -= 1; B -= 1
        graph[A].append(B)
        graph[B].append(A)
    trace = [-1]*N
    trace[0] = 0

    que = deque([0])
    while True:
        fr = que.popleft()
        for to in graph[fr]:
            if trace[to] != -1:
                continue
            trace[to] = fr
            que.append(to)
        if len(que) == 0:
            break

    if -1 in trace:
        print('No')
        return

    print('Yes')
    for t in trace[1:]:
        print(t+1)

if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
import sys
from collections import deque

sys.setrecursionlimit(10**6)
readline = sys.stdin.readline

def main():
    N, M = map(int, readline().split())
    graph = [[] for _ in range(M)]
    for _ in range(M):
        A, B = map(int, readline().split())
        A -= 1; B -= 1
        graph[A].append(B)
        graph[B].append(A)
    trace = [-1]*N
    trace[0] = 0

    que = deque([0])
    while True:
        fr = que.popleft()
        for to in graph[fr]:
            if trace[to] != -1:
                continue
            trace[to] = fr
            que.append(to)
        if len(que) == 0:
            break

    if -1 in trace:
        print('No')
        return

    for t in trace[1:]:
        print(t+1)

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

Fixed submission:
import sys
#import copy
#import numpy as np
#import itertools
import collections
#from collections import deque
#from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson
#from scipy.sparse import csr_matrix

sys.setrecursionlimit(10**6)
readline = sys.stdin.readline
read = sys.stdin.read
count = collections.Counter

def main():
    N = int(readline())
    S = input()

    values = list(count(S).values())
    if len(values) < 3:
        print(0)
        return
    
    ans = values[0] * values[1] * values[2]

    for i in range(N-2):
        for j in range(i+1, N-1):
            k = 2 * j - i
            if k >= N:
                break
            if S[i] != S[j] and S[i] != S[k] and S[j] != S[k]:
                ans -= 1

    print(ans)
    #print('end')


if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
import sys
#import copy
#import numpy as np
#import itertools
import collections
#from collections import deque
#from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson
#from scipy.sparse import csr_matrix

sys.setrecursionlimit(10**6)
readline = sys.stdin.readline
read = sys.stdin.read
count = collections.Counter

def main():
    N = int(readline())
    S = input()

    values = list(count(S).values())
    ans = values[0] * values[1] * values[2]

    for i in range(N-2):
        for j in range(i+1, N-1):
            k = 2 * j - i
            if k >= N:
                break
            if S[i] != S[j] and S[i] != S[k] and S[j] != S[k]:
                ans -= 1

    print(ans)
    #print('end')


if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
import sys
#import copy
import numpy as np
#import itertools
#import collections
#from collections import deque
#from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson
#from scipy.sparse import csr_matrix

sys.setrecursionlimit(10**6)
readline = sys.stdin.readline
read = sys.stdin.buffer.read

def main():
    # input
    N = int(readline())
    #S = np.array(list(readline()))
    S = np.array(list(read().rstrip()), np.int8)
    #print(S)

    R = np.sum(S == ord('R'))
    G = np.sum(S == ord('G'))
    B = np.sum(S == ord('B'))

    ans = R*G*B

    for i in range(N-2):
        for j in range(i+1, N-1):
            k = 2 * j - i
            if k >= N:
                break
            if S[i] != S[j] and S[i] != S[k] and S[j] != S[k]:
                ans -= 1

    print(ans)
    #print('end')


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

Fixed submission:
import sys

readline = sys.stdin.readline

def main():
    N, M = map(int, readline().split())
    aclist = [0] * N
    wrongcount = [0] * N
    for _ in range(M):
        p, S = readline().split()
        q = int(p)-1
        if aclist[q] == 0 and S == 'WA':
            wrongcount[q] += 1
        if S == 'AC':
            aclist[q] = 1

    pena = 0
    for i in range(N):
        if aclist[i] == 1:
            pena += wrongcount[i]
    ac = sum(aclist)

    print(ac, pena)


if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
# coding UTF-8
# 
# problem C
# 

import pandas as pd

t = []
N, M = map(int, input().split())
for i in range(M):
    t.append(tuple(input().split(' ')))

df = pd.DataFrame(t, columns=['p', 'S'])
alist = df.groupby('p')['S'].apply(list)

#print(df)
#print(alist)

#print(alist[0])

#print(alist.apply(lambda d: d[:d.index('AC')))


c = 0
NG = 0
for i in range(len(alist)):
    #print(alist[i])
    try:
        k = alist[i].index('AC')
    except ValueError:
        NGtmp = alist[i].count('WA')
        NG = NG + NGtmp
    else:
        #print(k)
        #print(alist[:k])
        NGtmp = alist[i][:k].count('WA')
        c = c + 1
        NG = NG + NGtmp

#print(c)
#print(NG)

print('{} {}'.format(c, NG))

Buggy submission (verdict: Runtime Error):
# coding UTF-8
# 
# problem C
# 

import pandas as pd

t = []
N, M = map(int, input().split())
for i in range(M):
    t.append(tuple(input().split(' ')))

df = pd.DataFrame(t, columns=['p', 'S'])
alist = df.groupby('p')['S'].apply(list)

#print(df)
#print(alist)

#print(alist[0])

#print(alist.apply(lambda d: d[:d.index('AC')))

c = 0
NG = 0
for i in range(M):
    try:
        k = alist[i].index('AC')
    except:
        NGtmp = alist[i].count('WA')
        NG = NG + NGtmp
    else:
        NGtmp = alist[:k].count('WA')
        c = c + 1
        NG = NG + NGtmp

print('%s %s'%(c, NG))

Buggy submission (verdict: Runtime Error):
# coding UTF-8
# 
# problem C
# 

import pandas as pd

t = []
N, M = map(int, input().split())
for i in range(M):
    t.append(tuple(input().split(' ')))

df = pd.DataFrame(t, columns=['p', 'S'])
alist = df.groupby('p')['S'].apply(list)

print(df)
print(alist)

print(alist[0])

print(alist.apply(lambda d: d[:d.index('AC')))

c = 0
NG = 0
for i in range(M):
    try:
        k = alist[i].index('AC')
    except:
        NGtmp = alist[i].count('WA')
        NG = NG + NGtmp
    else:
        NGtmp = alist[:k].count('WA')
        c = c + 1
        NG = NG + NGtmp

print('%s %s'%(c, NG))
Problem p02882 (python)

Fixed submission:
import math

def main():
    a, b, x = map(int, input().split())
    if a*a*b == x:
        print(0)
        return
    mid = a**2*b/2
    c = x/(a**2)
    if mid == x:
        ans = 90 - math.degrees(math.atan(a/b))
    elif mid < x:
        d = 2*x/(a**2) - b
        ans = 90 - math.degrees(math.atan(a/(b-d)))
    else:
        d = 2*a*c/b
        ans = 90 - math.degrees(math.atan(d/b))

    print(ans)

if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
import math

def main():
    a, b, x = map(int, input().split())
    mid = a**2*b/2
    c = x/(a**2)
    if mid == x:
        ans = 90 - math.degrees(math.atan(a/b))
    elif mid < x:
        d = 2*x/(a**2) - b
        ans = 90 - math.degrees(math.atan(a/(b-d)))
    else:
        d = 2*a*c/b
        ans = 90 - math.degrees(math.atan(d/b))

    print(ans)

if __name__ == "__main__":
    main()