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

Fixed submission:
import math
import sys

UNDEF=-1
sys.setrecursionlimit(1000010)
N = int(input())
# print(N)
V=[[UNDEF,UNDEF,[],[] ] for _ in range(N) ]      # Vertex
E=[[] for _ in range(N-1) ]    # Edge 

for i in range(N-1):
    (xa,xb) = map(int,input().split())
    # print(xa,xb)
    E[i]=[xa,xb]
    V[xb-1][0]=xa
    V[xb-1][1]=i+1
    V[xa-1][2].append(xb)
    V[xa-1][3].append(i+1)


# print("Edge:", E)
# print("Vertex:",V)

def root_v():
    global UNDEF
    global V
    for i in range(len(V)):
        if V[i][0] == UNDEF:
            return i+1
    return UNDEF

# print("Root Node:",root_v())

def max_degree(s):
    if V[s-1][0] != UNDEF: 
        degree=len(V[s-1][2]) + 1 # Node S 's degree for non root
    else:
        degree=len(V[s-1][2])     # Node S 's degree for root 

    for c in V[s-1][2]:
        degree = max ( degree, max_degree(c) ) 
    return degree

# print("Max Degree:", max_degree(root_v()))
print(max_degree(root_v()))

# Initialize 'color list' for edges
color=[UNDEF for _ in range(N-1)]

def put_colors(s):
    # print("put_color",s)
    global color 
    pcolor=UNDEF
    if V[s-1][1] != UNDEF:
        pcolor = color[V[s-1][1]-1]
    ic = 1
    for i in range(len(V[s-1][3])):
        if ic == pcolor:
            ic = ic + 1
        # print("put_color",s,i,V[s-1][3][i], ic )
        color[V[s-1][3][i]-1] = ic 
        put_colors(V[s-1][2][i])
        ic = ic + 1
    
put_colors(root_v())
for i in range(N-1):
    print(color[i])

Buggy submission (verdict: Runtime Error):
import math
import sys

UNDEF=-1
sys.setrecursionlimit(1000010)
N = int(input())
# print(N)
V=[[UNDEF,UNDEF,[],[] ] for _ in range(N) ]      # Vertex
E=[[] for _ in range(N-1) ]    # Edge 

for i in range(N-1):
    (xa,xb) = map(int,input().split())
    # print(xa,xb)
    E[i]=[xa,xb]
    V[xb-1][0]=xa
    V[xb-1][1]=i+1
    V[xa-1][2].append(xb)
    V[xa-1][3].append(i+1)


# print("Edge:", E)
# print("Vertex:",V)

def root_v():
    global UNDEF
    global V
    for i in range(len(V)):
        if V[i][0] == UNDEF:
            return i+1
    return UNDEF

# print("Root Node:",root_v())

def max_degree(s):
    if V[s-1][0] != UNDEF: 
        degree=len(V[s-1][2]) + 1 # Node S 's degree for non root
    else:
        degree=len(V[s-1][2])     # Node S 's degree for root 

    for c in V[s-1][2]:
        degree = max ( degree, max_degree(c) ) 
    return degree

# print("Max Degree:", max_degree(root_v()))
print(max_degree(root_v()))

# Initialize 'color list' for edges
color=[UNDEF for _ in range(N-1)]

def put_colors(s):
    # print("put_color",s)
    global color 
    pcolor = color[V[s-1][1]-1]
    ic = 1
    for i in range(len(V[s-1][3])):
        if ic == pcolor:
            ic = ic + 1
        # print("put_color",s,i,V[s-1][3][i], ic )
        color[V[s-1][3][i]-1] = ic 
        put_colors(V[s-1][2][i])
        ic = ic + 1
    
put_colors(root_v())
for i in range(N-1):
    print(color[i])
Problem p02853 (python)

Fixed submission:
(x,y) = map(int,input().split())
point=0
if x == 1: 
    point = point + 300000
elif x == 2:
    point = point + 200000
elif x == 3:
    point = point + 100000
if y == 1: 
    point = point + 300000
    if x == 1:
        point = point + 400000
elif y == 2:
    point = point + 200000
elif y == 3:
    point = point + 100000
print(point)

Buggy submission (verdict: Runtime Error):
print(x,y)
point=0
if x == 1: 
    point = point + 300000
elif x == 2:
    point = point + 200000
elif x == 3:
    point = point + 100000
if y == 1: 
    point = point + 300000
    if x == 1:
        point = point + 400000
elif y == 2:
    point = point + 200000
elif y == 3:
    point = point + 100000
print(point)
Problem p02898 (python)

Fixed submission:
# -*- coding: utf-8 -*-
import numpy as np 
n,k = list(map(int,input().split()))
h = list(map(int,input().split()))

s = 0 
for hi in h:
    if hi >= k:
        s += 1
print(s)

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
import numpy as np
n,k = list(map(int,input().split()))
s = 0 

for i in range(n):
    h = int(input())
    if h >= k:
        s += 1
print(s)
exit(0)

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
import numpy as np
n,k = list(map(int,input().split()))
s = 0 

for i in range(n):
    h = int(input())
    if h >= k:
        s += 1
print(s)
exit(0)
Problem p02900 (python)

Fixed submission:
# -*- coding: utf-8 -*-
import numpy as np 
import math

#a,bの最大公約数
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])


    return arr

a,b = list(map(int,input().split()))
x = gcd(a,b)
# print(gcd)
# print(factorization(gcd))
print(len(factorization(x))+1)

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
import numpy as np 
import math

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])


    return arr

a,b = list(map(int,input().split()))
gcd = math.gcd(a,b)
# print(gcd)
# print(factorization(gcd))
print(len(factorization(gcd))+1)
Problem p03353 (python)

Fixed submission:
def calc( s , k , n):

	bruh = {}
	for i  in range(1, k + 1): # length
		for j in range( n - ( i - 1)): # start 
			bruh[s[j: j + i:]] = 0
	another = bruh.keys()
	another = sorted(another)
	print( another[k - 1])

s = input()

k = int(input())

n = len(s)
 
calc( s , k , n)

Buggy submission (verdict: Runtime Error):
def calc( s , k , n):

	bruh = {}
	for i  in range(1, n + 1): # length
		for j in range( n - ( i - 1)): # start 
			bruh[s[j: j + i:]] = 0
	another = bruh.keys()
	another = sorted(another)
	print( another[k - 1])

s = raw_input()

k = int(raw_input())

n = len(s)
 
calc( s , k , n)

Buggy submission (verdict: Runtime Error):
def calc( s , k , n):

	bruh = {}
	for i  in range(1, n + 1): # length
		for j in range( n - ( i - 1)): # start 
			bruh[s[j: j + i:]] = 0
	another = bruh.keys()
	another = sorted(another)
	return another[k - 1]

s = raw_input()

k = int(raw_input())

n = len(s)
 
print( calc( s , k , n))

Buggy submission (verdict: Runtime Error):
s = raw_input()

k = int(raw_input())

n = len(s)
bruh = {}
for i  in range(1, n + 1): # length
	for j in range( n - ( i - 1)): # start 
		bruh[s[j: j + i:]] = 0
another = bruh.keys()
another = sorted(another)
print(another[k - 1])
Problem p03470 (python)

Fixed submission:

def func():
	n = int(input(""))
	bruh = []
	for i in range(n):
		var = input("")
		bruh.append(var)
	bruh = list(dict.fromkeys(bruh))
	return len(bruh)
print(func())

Buggy submission (verdict: Runtime Error):
def func():
	n = input("")
	bruh = []
	for i in range(n):
		var = input("")
		bruh.append(var)
	bruh = list(dict.fromkeys(bruh))
	return len(bruh)
print(func())

Buggy submission (verdict: Runtime Error):
n = input("")
bruh = []
for i in range(n):
	var = input("")
	bruh.append(var)
bruh = list(dict.fromkeys(bruh))
print(len(bruh))
Problem p03160 (python)

Fixed submission:
import sys
sys.setrecursionlimit(1000000)

n = int(input())
h = list(map(int,input().split()))
memo = [-1 for i in range(n)]

def dp(i):
    if i == 0:
        return 0
    elif i >= 2:
        if memo[i] != -1:
            return memo[i]
        else:
            memo[i] = min(dp(i-2) + abs(h[i]-h[i-2]), dp(i-1) + abs(h[i]-h[i-1]))
            return memo[i]
    else:
        return abs(h[1]-h[0])

print(dp(n-1))

Buggy submission (verdict: Runtime Error):
n = int(input())
h = list(map(int,input().split()))
memo = [-1 for i in range(n)]

def dp(i):
    if i == 0:
        return 0
    elif i >= 2:
        if memo[i] != -1:
            return memo[i]
        else:
            memo[i] = min(dp(i-2) + abs(h[i]-h[i-2]), dp(i-1) + abs(h[i]-h[i-1]))
            return memo[i]
    else:
        return abs(h[1]-h[0])

print(dp(n-1))
Problem p03162 (python)

Fixed submission:
import sys
sys.setrecursionlimit(1000000)

n = int(input())
action = []
for i in range(n):
    action.append(list(map(int,input().split())))

memo = []
for i in range(n):
    memo.append([-1]*3)

def dp(i, a):
    if i == 0:
        return action[0][a]
    elif memo[i][a] != -1:
        return memo[i][a]
    else:
        memo[i][a] = max(dp(i-1, (a+1)%3), dp(i-1, (a+2)%3)) + action[i][a]
        return memo[i][a]

print(max([dp(n-1,a) for a in range(3)]))

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(100000)

n = int(input())
action = []
for i in range(n):
    action.append(list(map(int,input().split())))

def dp(i, a):
    if i == 0:
        return action[0][a]
    else:
        return max(dp(i-1, (a+1)%3), dp(i-1, (a+2)%3)) + action[i][a]

print(max([dp(n-1,a) for a in range(3)]))

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(100000)

n = int(input())
action = []
for i in range(n):
    action.append(list(map(int,input().split())))

memo = []
for i in range(n):
    memo.append([-1]*3)

def dp(i, a):
    if i == 0:
        return action[0][a]
    elif memo[i][a] != -1:
        return memo[i][a]
    else:
        memo[i][a] = max(dp(i-1, (a+1)%3), dp(i-1, (a+2)%3)) + action[i][a]
        return memo[i][a]

print(max([dp(n-1,a) for a in range(3)]))

Buggy submission (verdict: Runtime Error):
n = int(input())
action = []
for i in range(n):
    action.append(list(map(int,input().split())))

memo = []
for i in range(n):
    memo.append([-1]*3)

def dp(i, a):
    if i == 0:
        return action[0][a]
    elif memo[i][a] != -1:
        return memo[i][a]
    else:
        memo[i][a] = max(dp(i-1, (a+1)%3), dp(i-1, (a+2)%3)) + action[i][a]
        return memo[i][a]

print(max([dp(n-1,a) for a in range(3)]))

Buggy submission (verdict: Runtime Error):
n = int(input())
action = []
for i in range(n):
    action.append(list(map(int,input().split())))

memo = []
for i in range(n):
    memo.append([-1]*3)

def dp(i, a):
    if i == 0:
        return action[0][a]
    else:
        memo[i][a] = max(dp(i-1, (a+1)%3), dp(i-1, (a+2)%3)) + action[i][a]
        return memo[i][a]

print(max([dp(n-1,a) for a in range(3)]))

Buggy submission (verdict: Runtime Error):
n = int(input())
action = []
for i in range(n):
    action.append(list(map(int,input().split())))

def dp(i, a):
    if i == 0:
        return action[0][a]
    else:
        return max(dp(i-1, (a+1)%3), dp(i-1, (a+2)%3)) + action[i][a]

print(max([dp(n-1,a) for a in range(3)]))
Problem p03142 (python)

Fixed submission:
import sys
sys.setrecursionlimit(100000000)

N, M = map(int, input().split())
BtoA = [[] for i in range(N + 1)]


for i in range(N - 1 + M):
    A, B = map(int, input().split())
    BtoA[B].append(A)

memo = {}
def depth(b):
    if b in memo:
        return memo[b]
    
    res = 0
    for a in BtoA[b]:
        res = max(res, depth(a) + 1)

    memo[b] = res
    return res

for i in range(1, N + 1):
    ans = 0
    for a in BtoA[i]:
        if depth(a) + 1 == depth(i):
            ans = a
            break
    print(ans)

Buggy submission (verdict: Runtime Error):
sys.setrecursionlimit(100000000)

N, M = map(int, input().split())
BtoA = [[] for i in range(N + 1)]


for i in range(N - 1 + M):
    A, B = map(int, input().split())
    BtoA[B].append(A)

memo = {}
def depth(b):
    if b in memo:
        return memo[b]
    
    res = 0
    for a in BtoA[b]:
        res = max(res, depth(a) + 1)

    memo[b] = res
    return res

for i in range(1, N + 1):
    ans = 0
    for a in BtoA[i]:
        if depth(a) + 1 == depth(i):
            ans = a
            break
    print(ans)

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
BtoA = [[] for i in range(N + 1)]


for i in range(N - 1 + M):
    A, B = map(int, input().split())
    BtoA[B].append(A)

memo = {}
def depth(b):
    if b in memo:
        return memo[b]
    
    res = 0
    for a in BtoA[b]:
        res = max(res, depth(a) + 1)

    memo[b] = res
    return res

for i in range(1, N + 1):
    ans = 0
    for a in BtoA[i]:
        if depth(a) + 1 == depth(i):
            ans = a
            break
    print(ans)
Problem p03157 (python)

Fixed submission:
import sys
sys.setrecursionlimit(300000)

H, W = map(int, input().split())
S = [input() for y in range(H)]
visited = [[False] * W for y in range(H)]

def color(y, x):
    if y < 0 or H <= y or x < 0 or W <= x or visited[y][x]:
        return "@"
    else:
        return S[y][x]


def dfs(y, x):
    b = 0
    w = 0
    nxt = "n"
    if color(y, x) == ".":
        w = 1
        nxt = "#"
    elif color(y, x) == "#":
        b = 1
        nxt = "."
    
    visited[y][x] = True
    if color(y - 1, x) == nxt:
        _b, _w = dfs(y - 1, x)
        b += _b
        w += _w
    if color(y + 1, x) == nxt:
        _b, _w = dfs(y + 1, x)
        b += _b
        w += _w
    if color(y, x - 1) == nxt:
        _b, _w = dfs(y, x - 1)
        b += _b
        w += _w
    if color(y, x + 1) == nxt:
        _b, _w = dfs(y, x + 1)
        b += _b
        w += _w

    return (b, w)

    
ans = 0
for y in range(H):
    for x in range(W):
        b, w = dfs(y, x)
        ans += b * w

print(ans)

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(114514)

H, W = map(int, input().split())
S = [input() for y in range(H)]
visited = [[False] * W for y in range(H)]

def color(y, x):
    if y < 0 or H <= y or x < 0 or W <= x or visited[y][x]:
        return "@"
    else:
        return S[y][x]


def dfs(y, x):
    b = 0
    w = 0
    nxt = "n"
    if color(y, x) == ".":
        w = 1
        nxt = "#"
    elif color(y, x) == "#":
        b = 1
        nxt = "."
    
    visited[y][x] = True
    if color(y - 1, x) == nxt:
        _b, _w = dfs(y - 1, x)
        b += _b
        w += _w
    if color(y + 1, x) == nxt:
        _b, _w = dfs(y + 1, x)
        b += _b
        w += _w
    if color(y, x - 1) == nxt:
        _b, _w = dfs(y, x - 1)
        b += _b
        w += _w
    if color(y, x + 1) == nxt:
        _b, _w = dfs(y, x + 1)
        b += _b
        w += _w

    return (b, w)

    
ans = 0
for y in range(H):
    for x in range(W):
        b, w = dfs(y, x)
        ans += b * w

print(ans)

Buggy submission (verdict: Runtime Error):
H, W = map(int, input().split())
S = [input() for y in range(H)]
visited = [[False] * W for y in range(H)]

def color(y, x):
    if y < 0 or H <= y or x < 0 or W <= x or visited[y][x]:
        return "@"
    else:
        return S[y][x]


def dfs(y, x):
    b = 0
    w = 0
    nxt = "n"
    if color(y, x) == ".":
        w = 1
        nxt = "#"
    elif color(y, x) == "#":
        b = 1
        nxt = "."
    
    visited[y][x] = True
    if color(y - 1, x) == nxt:
        _b, _w = dfs(y - 1, x)
        b += _b
        w += _w
    if color(y + 1, x) == nxt:
        _b, _w = dfs(y + 1, x)
        b += _b
        w += _w
    if color(y, x - 1) == nxt:
        _b, _w = dfs(y, x - 1)
        b += _b
        w += _w
    if color(y, x + 1) == nxt:
        _b, _w = dfs(y, x + 1)
        b += _b
        w += _w

    return (b, w)

    
ans = 0
for y in range(H):
    for x in range(W):
        b, w = dfs(y, x)
        ans += b * w

print(ans)
Problem p03231 (python)

Fixed submission:
import math
import fractions

n, m = [int(i) for i in input().split()]
s = input()
t = input()

ans = n * m // fractions.gcd(n, m)

for scnt in range(n):
    if scnt * m % n == 0:
        tcnt = scnt * m // n
        if s[scnt] != t[tcnt]:
            ans = -1
            break

print(ans)

Buggy submission (verdict: Runtime Error):
import math

n, m = [int(i) for i in input().split()]
s = input()
t = input()

ans = n * m // math.gcd(n, m)

for scnt in range(n):
    if scnt * m % n == 0:
        tcnt = scnt * m // n
        if s[scnt] != t[tcnt]:
            ans = -1
            break

print(ans)
Problem p03550 (python)

Fixed submission:
import sys
sys.setrecursionlimit(114514)

n, z, w = map(int, input().split())
aa = list(map(int, input().split()))

memo = {}
def act(last, turn):
    if (last, turn) in memo:
        return memo[(last, turn)]

    if turn == 0:
        # x turn
        y = w if last == -1 else aa[last]
        ans = abs(y - aa[n - 1])
        for i in range(last + 1, n - 1):
            ans = max(ans, act(i, 1))
    else:
        # y turn
        x = z if last == -1 else aa[last]
        ans = abs(x - aa[n - 1])
        for i in range(last + 1, n - 1):
            ans = min(ans, act(i, 0))
    
    memo[(last, turn)] = ans
    return ans


print(act(-1, 0))

Buggy submission (verdict: Runtime Error):
n, z, w = map(int, input().split())
aa = list(map(int, input().split()))

memo = {}
def act(xlast, ylast, turn):
    x = z if xlast == -1 else aa[xlast]
    y = w if ylast == -1 else aa[ylast]

    if xlast == n - 1 or ylast == n - 1:
        return abs(x - y)
    
    if (xlast, ylast, turn) in memo:
        return memo[(xlast, ylast, turn)]
    
    if turn == 0:
        # x turn
        ans = 0
        for i in range(ylast + 1, n):
            ans = max(ans, act(i, ylast, 1))
    else:
        # y turn
        ans = 1 << 30
        for i in range(xlast + 1, n):
            ans = min(ans, act(xlast, i, 0))
    
    memo[(xlast, ylast, turn)] = ans
    return ans

print(act(-1, -1, 0))

Buggy submission (verdict: Runtime Error):
n, z, w = map(int, input().split())
aa = list(map(int, input().split()))

memo = {}
def act(xlast, ylast, turn):
    x = z if xlast == -1 else aa[xlast]
    y = w if ylast == -1 else aa[ylast]

    if xlast == n - 1 or ylast == n - 1:
        return abs(x - y)
    
    if (xlast, ylast, turn) in memo:
        return memo[(xlast, ylast, turn)]
    
    if turn == 0:
        # x turn
        ans = 0
        for i in range(ylast + 1, n):
            ans = max(ans, act(i, ylast, 1))
    else:
        # y turn
        ans = 1 << 30
        for i in range(xlast + 1, n):
            ans = min(ans, act(xlast, i, 0))
    
    memo[(xlast, ylast, turn)] = ans
    return ans

print(act(-1, -1, 0))
Problem p02683 (python)

Fixed submission:
import numpy as np
N, M, X = map(int, input().split())
prices = []
effects = []
for i in range(N):
    c, *a = map(int, input().split())
    prices.append(c)
    effects.append(list(a))
 
prices = np.array(prices)
effects = np.array(effects)
 
 
ans = float("inf")
 
pats = []
for i in range(2 ** N):
    pat = bin(i).replace("0b", "")
    pat = "0" * (N - len(pat)) + pat
    pat = list(map(int, list(pat)))
    pats.append(pat)
    
pats = np.array(pats)
total_price = np.dot(pats, prices)
total_effects = np.dot(pats, effects)
cond = ((total_effects >= X).sum(axis=1) == M)
 
final = total_price[cond == 1]
if len(final) > 0:
    ans = int(final.min())
    print(ans)
else:
    print(-1)

Buggy submission (verdict: Runtime Error):
import numpy as np
N, M, X = map(int, input().split())
prices = []
effects = []
for i in range(N):
    c, *a = map(int, input().split())
    prices.append(c)
    effects.append(list(a))

prices = np.array(prices)
effects = np.array(effects)


ans = float("inf")

pats = []
for i in range(2 ** N):
    pat = bin(i).replace("0b", "")
    pat += "0" * (N - len(pat))
    pat = list(map(int, list(pat)))
    pats.append(pat)
    
pats = np.array(pats)
total_price = np.dot(pats, prices)
total_effects = np.dot(pats, effects)
cond = ((total_effects >= X).sum(axis=1) == M)


ans = int(total_price[cond == 1].min())
print(ans)
Problem p02687 (python)

Fixed submission:
s = input()

print("ABC" if s == "ARC" else "ARC")

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

root = int(X**(1/5))

if root**5 < X:
    rest = X - root**5
    another = -int(rest**(1/5))
else:
    rest = root**5 - X
    another = int(rest**(1/5))

while root**5 - another**5 != X:
    another_plus = another + 1
    another_minus = another - 1
    if root**5 - another_plus**5 == X:
        another = another_plus
        break
    if root**5 - another_minus**5 == X:
        another = another_minus
        break


print(root, another)
Problem p02691 (python)

Fixed submission:
from collections import Counter

N = int(input())
A = list(map(int, input().split()))

d = dict(Counter([i + A[i-1] for i in range(1, N+1)]))
ans = sum([d.get(i - A[i-1], 0) for i in range(1, N+1)])

print(ans)

Buggy submission (verdict: Runtime Error):
from collections import Counter

N = int(input())
A = list(map(int, input().split()))

d = dict(collections.Counter([i + A[i-1] for i in range(1, N+1)]))
ans = sum([d.get(i - A[i-1], 0) for i in range(1, N+1)])

print(ans)
Problem p02706 (python)

Fixed submission:
N, M = map(int, input().split())
A = list(map(int, input().split()))
 
days = sum(A)
 
if days <= N:
    print(N-days)
else:
    print(-1)

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

days = sum(A)

if days <= N:
    print(N-days)
else:
    print(-1)
Problem p02714 (python)

Fixed submission:
N = int(input())
S = input()

r = S.count("R")
g = S.count("G")
b = S.count("B")

cnt = 0
for i in range(N):
    for j in range(i+1, N):
        k = j + j - i
        if 0 <= k < N:
            if S[i] != S[j] and S[j] != S[k] and S[k] != S[i]:
                cnt += 1

print(r*g*b - cnt)

Buggy submission (verdict: Runtime Error):
N = int(input())
S = list(input())

import numpy as np

r = (np.array(S) == "R").sum()
g = (np.array(S) == "G").sum()
b = (np.array(S) == "B").sum()

cnt = 0
for i in range(N):
    for j in range(i+1, N):
        k = j + j - i
        if 0 <= k < N:
            if S[i] != S[j] and S[j] != S[k] and S[k] != S[i]:
                cnt += 1

print(r*g*b - cnt)
Problem p02730 (python)

Fixed submission:
import sys
S = input()
N = len(S)

if S == S[::-1]:
    if S[0:(N-1)//2] == S[0:(N-1)//2][::-1]:
        if S[((N+3)//2)-1:N] == S[((N+3)//2)-1:N][::-1]:
            print("Yes")
            sys.exit()


print("No")

Buggy submission (verdict: Runtime Error):
S = input()

words = []
words.append(S)
words.append(S[:(N-1)//2])
words.append(S[(N+3)//2 - 1:])

ans = all([word == word[::-1] for word in words])

print("Yes" if ans else "No")

Buggy submission (verdict: Runtime Error):
import sys
S = input()
N = len(S)

if S == S[::-1]:
    if S[0:(N-1)/2] == S[0:(N-1)/2][::-1]:
        if S[((N+3)/2)-1:N] == S[((N+3)/2)-1:N][::-1]:
            print("Yes")
            sys.exit()


print("No")
Problem p02756 (python)

Fixed submission:
from collections import deque

S = deque(input())
Q = int(input())

reverse = False
cnt = 0
for i in range(Q):
    inp = input().split()
    if inp[0] == "1":
        cnt += 1
        reverse = (cnt % 2 != 0)
        #S = S[::-1]
    else:
        f, c = inp[1:]
        if int(f) == 1:
            if reverse:
                S.append(c)
            else:
                S.appendleft(c)
        else:
            if reverse:
                S.appendleft(c)
            else:
                S.append(c)
S = "".join(S)
print(S[::-1] if reverse else S)

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

S = deque(input())
Q = int(input())
Queries = [input().split() for _ in range(Q)]

need_reverse = False

for q in Queries:
    if q[0] == "1":
        need_reverse = not need_reverse
    else:
        if q[1] == "1":
            if not need_reverse:
                S.appendleft(q[2])
            else:
                S.append(q[2])
        else:
            if not need_reverse:
                S.append(q[2])
            else:
                S.appendleft(q[2])

print(S if not need_reverse else S[::-1])

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

S = deque(input())
Q = int(input())

reverse = False
cnt = 0
for i in range(Q):
    inp = input().split()
    if inp[0] == "1":
        cnt += 1
        reverse = (cnt % 2 != 0)
        #S = S[::-1]
    else:
        f, c = inp[1:]
        if int(f) == 1:
            if reverse:
                S.append(c)
            else:
                S.leftappend(c)
        else:
            if reverse:
                S.leftappend(c)
            else:
                S.append(c)
S = "".join(S)
print(S[::-1] if reverse else S)