Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

# まずは桁数を増やす→数字の大きい順に並べる
N, M = lr()
A = lr()
matches = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]
A = [(matches[a], a) for a in A]
A.sort(key = lambda x: x[1], reverse=True)
A.sort(key = lambda x: x[0])
top_match = A[0][0]
dp = [None] * (N+1)
dp[0] = []
used = set()
for match, num in A:
    if match in used:
        continue
    used.add(match)
    for x in range(N+1):
        if x - match < 0:
            continue
        if dp[x] == None and dp[x-match] != None:
            dp[x] = dp[x-match] + [num]
        elif dp[x] != None and dp[x-match] != None:
            if len(dp[x-match]) >= len(dp[x]):
                dp[x] = dp[x-match] + [num]
            elif len(dp[x-match]) >= 1 and len(dp[x-match]) == len(dp[x]) - 1:
                y = list(map(str, dp[x][::-1])); y.sort(reverse=True)
                z = [str(num)] + list(map(str, dp[x-match][::-1])); z.sort(reverse=True)
                y = int(''.join(y))
                z = int(''.join(z))
                if z > y:
                    dp[x] = dp[x-match] + [num]

X = dp[N]
X.sort(reverse=True)
answer = ''.join(list(map(str, X)))
print(answer)
# 37


Fixed submission:
N, M = map(int, input().split())
A = list(map(int, input().split()))

dp = [0] * N + [-1] * 9
for i in range(1, N+1):
    dp[i] = max(dp[i-int('0255456376'[a])] * 10 + a for a in A)

print(dp[N])
Buggy python submission (verdict: Runtime Error):
print(eval(int(input()).replace(' ','/')))

Fixed submission:
t,x=map(int,input().split())
print(t/x)
Buggy python submission (verdict: Runtime Error):
# coding: utf-8
import sys
from functools import lru_cache
import numpy as np

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N, K = lr()
A = np.array(lr())
limit = max(A.max(), K).bit_length()
bit_cnt = [((A>>k)&1).sum() for k in range(limit)]

@lru_cache(None)
def solve(K, index):
    if index < 0:
        return 0
    bit = 1 << index
    # bitを使わない（整数Xのこの桁のbitは0）
    ret = (bit_cnt[index]<<index) + solve(min(K, bit-1), index-1)
    if bit <= K:
        ret = max(ret, ((N-bit_cnt[index])<<index) +  solve(K-bit, index-1))
    return ret

answer = solve(K, limit-1)
print(answer)



Fixed submission:
import numpy as np

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

max_len = max(len(bin(K)[2:]), len(bin(max(A))[2:]))
bit_cnt = [((A>>k)&1).sum() for k in range(max_len)]

x = 0
for i in range(max_len-1, -1, -1):
    if x+2**i <= K and bit_cnt[i] < (N+1)//2:
        x += 2**i

answer = 0
for a in A:
    answer += a^x
print(answer)

Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
import sys
import numpy as np

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

# bit毎で１と０の多い方の値、K以下でdfs
N, K = lr()
A = lr()
limit = max(max(A), K).bit_length()
X = [0] * (limit)
for a in A:
    for i in range(limit):
        if (a >> i) & 1:
            X[i] += 1

def dfs(index, sum, y):
    if index == limit:
        return sum
    i = limit - 1 - index
    ret = dfs(index+1, sum + X[i] * 2 ** i, y)
    if y + 2 ** i <= K:
        ret = max(ret, dfs(index+1, sum + (N-X[i]) * 2 ** i, y + 2 ** i))
    return ret

answer = dfs(0, 0, 0)
print(answer)


Fixed submission:
import numpy as np

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

max_len = max(len(bin(K)[2:]), len(bin(max(A))[2:]))
bit_cnt = [((A>>k)&1).sum() for k in range(max_len)]

x = 0
for i in range(max_len-1, -1, -1):
    if x+2**i <= K and bit_cnt[i] < (N+1)//2:
        x += 2**i

answer = 0
for a in A:
    answer += a^x
print(answer)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
from collections import deque

stdin = sys.stdin

ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split()))
rs = lambda: stdin.readline().rstrip()  # ignore trailing spaces

def bfs(x, y, c):
    grid = [[None] * W for _ in range(H)]

    dx = [1, 0, -1, 0]
    dy = [0, 1, 0, -1]

    que = deque()
    que.append(((x, y), c))
    grid[y][x] = 'visited'
    ret = 0

    while que:
        p, color = que.popleft()
        for i in range(4):
            nx = p[0] + dx[i]
            ny = p[1] + dy[i]
            next_color = '#' if color == '.' else '.'            
            if 0 <= ny and ny <= H-1 and 0 <= nx and nx <= W-1 and \
                    grid[ny][nx] == None and data[ny][nx] == next_color:
                grid[ny][nx] = 'visited'
                if next_color == '.':
                    ret += 1
                que.append(((nx, ny), next_color))
    return ret

H, W = rl()
data = [list(rs()) for _ in range(H)]
answer = 0

for y in range(H):
    for x in range(W):
        if data[y][x] == '#':
          answer += bfs(x, y, data[y][x])

print(answer)
#46

Fixed submission:
import sys
from collections import deque

stdin = sys.stdin

ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split()))
rs = lambda: stdin.readline().rstrip()  # ignore trailing spaces

def bfs(x, y, c):
    global data
    
    dx = [1, 0, -1, 0]
    dy = [0, 1, 0, -1]

    que = deque()
    que.append(((x, y), c))
    data[y][x] = 'visited'
    black = 1
    white = 0

    while que:
        p, color = que.popleft()
        for i in range(4):
            nx = p[0] + dx[i]
            ny = p[1] + dy[i]
            next_color = '#' if color == '.' else '.'            
            if 0 <= ny and ny <= H-1 and 0 <= nx and nx <= W-1 and \
                    data[ny][nx] == next_color:
                data[ny][nx] = 'visited'
                if next_color == '.':
                    white += 1
                elif next_color == '#':
                    black += 1
                que.append(((nx, ny), next_color))
    return white * black

H, W = rl()
data = [list(rs()) for _ in range(H)]
answer = 0

for y in range(H):
    for x in range(W):
        if data[y][x] == '#':
            answer += bfs(x, y, data[y][x])

print(answer)
# rest
Buggy python submission (verdict: Runtime Error):
N, X = map(int, input().split())

S = 'P'
while N > 0:
    S = 'B' + S + 'P' + S + 'B'
    N -= 1
print(S[:X].count('P'))

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

count_p = [1] * (N+1) # パティの数
for i in range(1, N+1):
    count_p[i] += count_p[i-1] * 2

length = [1] * (N+1) # バーガーの長さ
for i in range(1, N+1) :
    length[i] += (length[i-1] + 1) * 2

def F(n, x): # レベルnバーガーの下x層のあるパティの数
    if n == 0:
        return 0 if x <= 0 else 1
    if x == length[n] // 2 + 1:
        return count_p[n-1] + 1
    elif x > length[n] // 2 + 1:
        return count_p[n-1] + 1 + F(n-1, x-(length[n]//2+1))
    else:
        return F(n-1, max(0, x-1))
print(F(N, X))
Buggy python submission (verdict: Runtime Error):
N = int(input())
e = [0] * (N+1)

for i in range(2, N+1):
    cur = i
    for j in range(2, i+1):
        while cur % j == 0:
            e[j] += 1
            cur //= j

def num(m): # eの要素のうち m-1 以上のものの個数
    return len(list(filter(lambda x: x >= m-1, e)))

answer = num(75) + num(25) * (num(3)-1) + num(15) * (num(5) - 1)
    + num(5) * (num(5) - 1) * (num(3) - 2) // 2)

Fixed submission:
N = int(input())
e = [0] * (N+1)

for i in range(2, N+1):
    cur = i
    for j in range(2, i+1):
        while cur % j == 0:
            e[j] += 1
            cur //= j

def num(m): # eの要素のうち m-1 以上のものの個数
    return len(list(filter(lambda x: x >= m-1, e)))

answer = num(75) + num(25) * (num(3)-1) + num(15) * (num(5) - 1)\
    + num(5) * (num(5) - 1) * (num(3) - 2) // 2
print(answer)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
import numpy as np

stdin = sys.stdin
 
ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split()))
rs = lambda: stdin.readline().rstrip()  # ignore trailing spaces

N = ri()
x = int((2 * N) ** (0.5))
if x * (x+1) == 2 * N:
    print('Yes')
else:
    print('No')
    exit()

k = x + 1 #部分集合の個数 
num = 2 * N // k #部分集合の要素数
answer = []
used = set()
unused = list(range(1, N+1))

for i in range(k):
    l = []
    append = l.append
    for j in range(i):
        for x in answer[j]:
            if x not in used:
                append(x)
                used.add(x)
                break
    if len(l) < num:
        y = len(l)
        while y < num:
            z = unused.pop(0)
            append(z)
            y += 1
    answer.append(l)
print(k)
for a in answer:
    print(num, *a)


Fixed submission:
import sys
from itertools import combinations

stdin = sys.stdin
 
ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split()))
rs = lambda: stdin.readline().rstrip()  # ignore trailing spaces

N = ri()
x = int((2 * N) ** (0.5))
if x * (x+1) == 2 * N:
    print('Yes')
else:
    print('No')
    exit()

k = x + 1 #部分集合の個数 
num = 2 * N // k #部分集合の要素数
answer = [[] for _ in range(k)]
for i, (a, b) in enumerate(combinations(range(k), 2), 1):
    answer[a].append(i)
    answer[b].append(i)

print(k)
for a in answer:
    print(num, *a)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
import numpy as np

stdin = sys.stdin
 
ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split()))
rs = lambda: stdin.readline().rstrip()  # ignore trailing spaces

N = ri()
x = int((2 * N) ** (0.5))
if x * (x+1) == 2 * N:
    print('Yes')
else:
    print('No')
    exit()

k = x + 1 #部分集合の個数 
num = 2 * N // k #部分集合の要素数
answer = []
used = set()
unused = list(range(1, N+1))

for i in range(k):
    l = []
    for j in range(i):
        for x in answer[j]:
            if x not in used:
                l.append(x)
                used.add(x)
                break
    if len(l) < num:
        y = num - len(l)
        l.extend(unused[:y])
        unused = unused[y:]
    answer.append(l)
print(k)
for a in answer:
    print(num, *a)


Fixed submission:
import sys
from itertools import combinations

stdin = sys.stdin
 
ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split()))
rs = lambda: stdin.readline().rstrip()  # ignore trailing spaces

N = ri()
x = int((2 * N) ** (0.5))
if x * (x+1) == 2 * N:
    print('Yes')
else:
    print('No')
    exit()

k = x + 1 #部分集合の個数 
num = 2 * N // k #部分集合の要素数
answer = [[] for _ in range(k)]
for i, (a, b) in enumerate(combinations(range(k), 2), 1):
    answer[a].append(i)
    answer[b].append(i)

print(k)
for a in answer:
    print(num, *a)
Buggy python submission (verdict: Runtime Error):
# coding: utf-8
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N = ir()
if N == 1:
    pritn('Hello World'); exit()
A = ir(); B = ir()
answer = A + B
print(answer)


Fixed submission:
N = int(input())
if N == 1:
  print("Hello World")
else:
  print(int(input()) + int(input()))
Buggy python submission (verdict: Runtime Error):
# coding: utf-8
import sys
import numpy as np

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N, T = lr()
CT = np.array([lr() for _ in range(N)])
CT = CT[CT[:, 1] <= T]
time = CT[:, 0]
if not time:
    print('TLE')
else:
    answer = time.min()
    print(answer)


Fixed submission:
n,t=map(int,input().split())
a=[list(map(int, input().split())) for i in range(n)]
a.sort(key=lambda x: x[0])
for i in a:
  if i[1]<=t:
    print(i[0])
    exit()
print('TLE')
Buggy python submission (verdict: Runtime Error):
import numpy as np
import sys

N = int(input())
X = np.zeros(N, dtype = np.int64)
Y = np.zeros(N, dtype = np.int64)
H = np.zeros(N, dtype = np.int64)
for i in range(N):
    x, y, h = map(int, input().split())
    X[i] = x
    Y[i] = y
    H[i] = h
node = 10 ** 9
for x in range(101):
    for y in range(101):
        result = (abs(X - x) + abs(Y - y) + H) * (H != 0)
        s = set(result)
        if 0 in s:
            s -= {0}
        if len(s) <= 1:
            height = (abs(X - x) + abs(Y - y) + H).min()
            print(x, y, height)
            sys.exit(0)

Fixed submission:
N = int(input())
hxy = []
for _ in range(N):
    x, y, h = map(int, input().split())
    hxy.append((h, x, y))
hxy.sort(reverse=True)
for x in range(101):
    for y in range(101):
        H = abs(hxy[0][1] - x) + abs(hxy[0][2] - y) + hxy[0][0]
        for j in range(1, N):
            if max(0, H - abs(x - hxy[j][1]) - abs(y - hxy[j][2])) == hxy[j][0]:
                continue
            else:
                break
        else:
            print(x, y, H)
Buggy python submission (verdict: Runtime Error):
from collections import Counter

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

s1 = Counter(V).most_common(2)[0]
s2 = Counter(V).most_common(2)[0]
V1 = V[0::2]
V2 = V[1::2]
x1, c1 = Counter(V1).most_common(1)[0]
x2, c2 = Counter(V2).most_common(1)[0]
x3, c3 = Counter(V1).most_common(2)[1]
x4, c4 = Counter(V2).most_common(2)[1]
if x1 == x2:
    a = max(c1+c4, c2+c3)
    print(N-a)
else:
    print(N - c1 - c2)

Fixed submission:
from collections import Counter

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

s1 = Counter(V).most_common(2)[0]
s2 = Counter(V).most_common(2)[0]
V1 = V[0::2]
V2 = V[1::2]
x1, c1 = Counter(V1).most_common(1)[0]
x2, c2 = Counter(V2).most_common(1)[0]
if x1 == x2:
    if c1 > c2:
        x2, c2 = Counter(V2).most_common(2)[1]
    elif c1 < c2:
        x1, c1 = Counter(V1).most_common(2)[1]
    elif c1 == c2 == N // 2:
        c1, c2 = N//2, 0
    else:

        x2, c2 = Counter(V2).most_common(2)[1]
        x3, c3 = Counter(V1).most_common(2)[1]
        c2 = max(c2, c3)

print(N - c1 - c2)
Buggy python submission (verdict: Runtime Error):
# coding: utf-8
import sys
import numpy as np
from fractions import gcd

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N, X = lr()
X = np.array(lr())
Xdiff = np.abs(np.diff(X)).tolist()
g = Xdiff[0]
for i in range(1, N):
    g = gcd(g, Xdiff[1])

answer = g
print(answer)


Fixed submission:
import numpy as np
from functools import reduce
from fractions import gcd


N, X = map(int, input().split())

places = np.array(list(map(int, input().split())))

distances = abs(places - X)

answer = reduce(gcd, distances)
print(answer)
Buggy python submission (verdict: Runtime Error):
# coding: utf-8
import sys
import numpy as np

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

x1, y1, x2, y2 = lr()
P2 = np.array([x2, y2])  # 2つ目の点
A = np.array([[0, -1], [1, 0]])
vec = np.array([x2-x1, y2-y1])
vec2 = np.dot(A, vec)
vec3 = np.dot(A, vec2)
P3 = np.array(P2) + vec2
P4 = np.array(P3) + vec3
print(*P3, *P4)


Fixed submission:
X1, Y1, X2, Y2 = map(int, input().split())
X3, Y3 = X2-(Y2-Y1), Y2+(X2-X1)
X4, Y4 = X3-(Y3-Y2), Y3+(X3-X2)
print(X3, Y3, X4, Y4)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
import numpy as np

stdin = sys.stdin
 
ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split()))
rs = lambda: stdin.readline().rstrip()  # ignore trailing spaces

N, M = rl()
A = np.array(rl())
A_cum = A.cumsum()
A_cum %= M
answer = 0

for i in range(N):
    answer += (A_cum[i:] == 0).sum()
    A_cum -= A_cum[i]

print(answer)
#13

Fixed submission:
import sys
import numpy as np
from collections import Counter
from math import factorial

stdin = sys.stdin
 
ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split()))
rs = lambda: stdin.readline().rstrip()  # ignore trailing spaces

N, M = rl()
A = np.array(rl())
A_cum = A.cumsum()
A_cum %= M
A_cum = A_cum.tolist()
c = Counter(A_cum)
answer = 0

for k, v in c.items():
    if k == 0:
        answer += v
    if v >= 2:
        answer += factorial(v) // factorial(2) // factorial(v-2)

print(answer)
#13
Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

# DP[0, 0], Aの数、ABの数、ABCの数
MOD = 10 ** 9 + 7
S = sr()
dp = [0, 0, 0]
total = 1
for s in S:
    if s == 'A':
        dp[0] += total
    elif s == 'B':
        dp[1] += dp[0]
    elif s == 'C':
        dp[2] += dp[1]
    elif s == '?':
        dp[2] = dp[2]*3 + dp[1]
        dp[1] = dp[1]*3 + dp[0]
        dp[0] = dp[0]*3 + total
        total *= 3
    #print(dp, total)

print(dp[2]%MOD)


Fixed submission:
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

S = sr()[::-1]
MOD = 10 ** 9 + 7
answer = 0
dp = [0, 0, 1] #Cの数, BC数, 総数
for i in range(len(S)):
    s = S[i]
    if s == 'A':
        answer += dp[1]
    elif s == 'B':
        dp[1] += dp[0]
    elif s == 'C':
        dp[0] += dp[2]
    elif s == '?':
        answer *= 3
        answer += dp[1]
        dp[1] *= 3
        dp[1] += dp[0]
        dp[0] *= 3
        dp[0] += dp[2]
        dp[2] *= 3
    answer %= MOD
    dp[0] %= MOD; dp[1] %= MOD; dp[2] %= MOD
print(answer)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
import numpy as np

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

T = ir()

def check(a, b, c, d, i):
    if a < b or d < b:
        print('No')
    else:
        a %= b
        if d > b:
            d %= b
            d += b        
        X = np.array([a] + [d] * 10 ** 5)
        Xcum = (X.cumsum() % b)
        Xcum[Xcum<=c] += d
        bool = np.any(Xcum < b)
        print('No' if bool else 'Yes')

for i in range(T):
    check(*(lr() + [i]))    

# 10

Fixed submission:
import sys
from fractions import gcd

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

T = ir()

def check(a, b, c, d):
    if a < b or d < b:
        answer = 'No'
    # 以降 d >= b とする
    elif c >= b:
        answer = 'Yes'
    else:
        a %= b; d %= b
        # c < x < b の間に個数が入ると'No'
        g = gcd(b, d)
        if b - g + (a % g) > c:
            answer = 'No'
        else:
            answer = 'Yes'
    print(answer)

for _ in range(T):
    check(*lr())

# 16
Buggy python submission (verdict: Runtime Error):
# coding: utf-8
import sys
import numpy as np

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N = ir()
A = np.array(lr())
A -= np.arange(1, N+1)
A.sort()

def check(i):
    ret = np.abs(A - A[i]).sum()
    return ret

answer = min(check(0), check(-1))
left = 0; right = N-1
while abs(right-left) > 2:
    l_mid = (left*2 + right) // 3
    r_mid = (left + right*2) // 3
    if check(l_mid) < check(r_mid):
        right = r_mid
    else:
        left = l_mid

cand = min(check(l_mid), check(r_mid))
answer = min(answer, cand)
print(answer)


Fixed submission:
import numpy as np
import statistics

N = int(input())
A = np.array(list(map(int, input().split())))
R = np.array([x+1 for x in range(N)])

med = int(np.median((A-R)))
print(abs(A-R-med).sum())

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

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N = ir()
A = np.array(lr())
A -= np.arange(1, N+1)
answer = 10 ** 15
B = np.abs(np.subtract.outer(A, A))
answer = np.min(B.sum(axis=1))
print(answer)


Fixed submission:
import numpy as np
import statistics

N = int(input())
A = np.array(list(map(int, input().split())))
R = np.array([x+1 for x in range(N)])

med = int(np.median((A-R)))
print(abs(A-R-med).sum())

Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
import sys
import numpy as np

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N = ir()
A = np.array(lr())
A -= np.arange(1, N+1)
answer = 10 ** 15
for i in range(N):
    temp = np.abs(A - A[i]).sum()
    if temp < answer:
        answer = temp

print(answer)


Fixed submission:
import numpy as np
import statistics

N = int(input())
A = np.array(list(map(int, input().split())))
R = np.array([x+1 for x in range(N)])

med = int(np.median((A-R)))
print(abs(A-R-med).sum())
Buggy python submission (verdict: Time Limit Exceeded):
import itertools

def main():
    # 8通りの方法を調べて最大値　-,-,- から +,+,+
    N, M = map(int, input().split())

    data = [[0] * 8 for _ in range(M+1)]
    p = list(itertools.product([-1, 1], repeat=3))

    for i in range(N):
        #print(data)
        x, y, z = map(int, input().split())
        for k in range(M-1, -1, -1):
            for j in range(8):
                tmp = x * p[j][0] + y * p[j][1] + z * p[j][2]
                if data[k+1][j] < data[k][j] + tmp:
                    data[k+1][j] = data[k][j] + tmp
    answer = 0
    for d in data[M]:
        if abs(d) > answer:
            answer = abs(d)
    print(answer)

if __name__ == '__main__':
    main()

Fixed submission:
import itertools

def main():
    # 8通りの方法を調べて最大値　-,-,- から +,+,+
    N, M = map(int, input().split())

    data = [[] for i in range(8)]
    p = list(itertools.product([-1, 1], repeat=3))

    for i in range(N):
        #print(data)
        x, y, z = map(int, input().split())
        for j in range(8):
            tmp = x * p[j][0] + y * p[j][1] + z * p[j][2]
            data[j].append(tmp)
               
    answer = 0
    for d in data:
        d.sort(reverse=True)
        s = sum(d[:M])
        if abs(s) > answer:
            answer = abs(s)
    print(answer)

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import itertools

# 8通りの方法を調べて最大値　-,-,- から +,+,+
N, M = map(int, input().split())

data = [[0] * 8 for _ in range(M+1)]
p = list(itertools.product([-1, 1], repeat=3))

for i in range(N):
    #print(data)
    x, y, z = map(int, input().split())
    for k in range(M-1, -1, -1):
        for j in range(8):
            tmp = x * p[j][0] + y * p[j][1] + z * p[j][2]
            if data[k+1][j] < data[k][j] + tmp:
                data[k+1][j] = data[k][j] + tmp
answer = 0
for d in data[M]:
    if abs(d) > answer:
        answer = abs(d)
print(answer)

Fixed submission:
import itertools

def main():
    # 8通りの方法を調べて最大値　-,-,- から +,+,+
    N, M = map(int, input().split())

    data = [[] for i in range(8)]
    p = list(itertools.product([-1, 1], repeat=3))

    for i in range(N):
        #print(data)
        x, y, z = map(int, input().split())
        for j in range(8):
            tmp = x * p[j][0] + y * p[j][1] + z * p[j][2]
            data[j].append(tmp)
               
    answer = 0
    for d in data:
        d.sort(reverse=True)
        s = sum(d[:M])
        if abs(s) > answer:
            answer = abs(s)
    print(answer)

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
# coding: utf-8
import sys
import numpy as np

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

# dp
N = ir()
INF = 10 ** 8
dp = np.array([INF] * 100001)
dp[0] = 0
for i in range(5, 0, -1):
    num = 9 ** i
    for j in range(100000):
        if j+num <= N:
            dp[j+num] = min(dp[j+num], dp[j]+1)

for i in range(6, 0, -1):
    num = 6 ** i
    for j in range(100000):
        if j+num <= N:
            dp[j+num] = min(dp[j+num], dp[j]+1)

num = 1
for j in range(100000):
    dp[j+num] = min(dp[j+num], dp[j]+1)

answer = dp[N]
print(answer)


Fixed submission:
N=int(input())
ans=N
for i in range(N+1):
    cnt=0
    t = i
    while t>0:
        cnt+=t%6
        t//=6
    t=N-i
    while t>0:
        cnt+=t%9
        t//=9
    ans=min(ans,cnt)
print(ans)