Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
s = input()
s = [ord(i) - 97 for i in s]
t = input()
t = [ord(i) -97 for i in t]

ls = len(s)
lt = len(t)

dp = [[0]*(lt+1) for i in range(ls+1)]

for i in range(1,ls+1):
    for j in range(1,lt+1):
        if s[i-1] == t[j-1]:
            dp[i][j] = dp[i-1][j-1] + 1
        else:
            dp[i][j] = max(dp[i][j-1], dp[i-1][j])

max_len = dp[-1][-1]

ans = []

i = ls
j = lt

for l in range(max_len):
    while dp[i-1][j] == max_len - l:
        i -= 1
    while dp[i][j-1] == max_len - l:
        j -= 1
    ans.append(s[i-1])
    #ans += s[i-1]

alphabet = [chr(97+i) for i in range(27)]
a = ""
for i in ans:
    a += alphabet[i]
print(a[::-1])
#print(ans[::-1])

Fixed submission:
s = input()
t = input()

ls = len(s)
lt = len(t)

dp = [[0]*(lt+1) for i in range(ls+1)]

for i in range(1,ls+1):
    for j in range(1,lt+1):
        if s[i-1] == t[j-1]:
            dp[i][j] = dp[i-1][j-1] + 1
        else:
            dp[i][j] = max(dp[i][j-1], dp[i-1][j])

max_len = dp[-1][-1]
ans = ""

i = ls
j = lt

while i > 0 and j > 0:
    if dp[i][j] == dp[i - 1][j]:
        i -= 1
    elif dp[i][j] == dp[i][j - 1]:
        j -= 1
    else:
        ans += s[i - 1]
        i -= 1
        j -= 1

print(ans[::-1])

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
t = input()

ls = len(s)
lt = len(t)

dp = [[0]*(lt+1) for i in range(ls+1)]

for i in range(1,ls+1):
    for j in range(1,lt+1):
        if s[i-1] == t[j-1]:
            dp[i][j] = dp[i-1][j-1] + 1
        else:
            dp[i][j] = max(dp[i][j-1], dp[i-1][j])

max_len = dp[-1][-1]
#print(max_len)

ans = ""

i = ls
j = lt

for l in range(max_len):
    while dp[i-1][j] == max_len - l:
        i -= 1
    while dp[i][j-1] == max_len - l:
        j -= 1
    ans += s[i-1]


print(ans[::-1])

Fixed submission:
s = input()
t = input()

ls = len(s)
lt = len(t)

dp = [[0]*(lt+1) for i in range(ls+1)]

for i in range(1,ls+1):
    for j in range(1,lt+1):
        if s[i-1] == t[j-1]:
            dp[i][j] = dp[i-1][j-1] + 1
        else:
            dp[i][j] = max(dp[i][j-1], dp[i-1][j])

max_len = dp[-1][-1]
ans = ""

i = ls
j = lt

while i > 0 and j > 0:
    if dp[i][j] == dp[i - 1][j]:
        i -= 1
    elif dp[i][j] == dp[i][j - 1]:
        j -= 1
    else:
        ans += s[i - 1]
        i -= 1
        j -= 1

print(ans[::-1])
Buggy python submission (verdict: Time Limit Exceeded):
import sys
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__

n,m = map(int, input().split())
G = [[] for i in range(n)]

in_ = set()
for i in range(m):
    a,b = map(int, input().split())
    a,b = a-1,b-1
    G[a].append(b)
    in_.add(b)

dist = [-1]*n

from collections import deque
def dfs(cur):
    que = deque()
    que.append((cur, 0))
    while que:
        cur, d = que.pop()
        if dist[cur] > d:
            continue
        dist[cur] = d
        for to in G[cur]:
            if dist[to] < d+1:
                que.append((to, d+1))

for i in range(n):
    if i in in_:
        continue
    dfs(i)

ans = max(dist)

print(ans)

Fixed submission:
import sys
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__

sys.setrecursionlimit(10**9)

n,m = map(int, input().split())
G = [[] for i in range(n)]

in_ = set()
for i in range(m):
    a,b = map(int, input().split())
    a,b = a-1,b-1
    G[a].append(b)
    in_.add(b)

dist = [-1]*n

from collections import deque
def dfs(cur):
    if dist[cur] != -1:
        return dist[cur]
    r = 0
    for to in G[cur]:
        r = max(r, dfs(to)+1)
    dist[cur] = r
    return r

for i in range(n):
    if i in in_:
        continue
    dfs(i)

ans = max(dist)

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10**9)
from functools import lru_cache

n = int(input())
a = list(map(int, input().split()))

one = a.count(1)
two = a.count(2)
three = a.count(3)

@lru_cache(n**3)
def dfs(one,two,three):
    if one<0 or two<0 or three<0:
        return 0
    s = one+two+three
    if s == 0:
        return 0
    zero = n-s
    tmp = (one*dfs(one-1,two,three) + two*dfs(one+1, two-1, three) + three*dfs(one,two+1,three-1) + n)/(n - zero)
    return tmp

ans = dfs(one,two,three)
print(ans)

Fixed submission:
from collections import Counter
n = int(input())
a = list(map(int, input().split()))
c = Counter(a)
a,b,c = c[1],c[2],c[3]
DP = [[[0]*(n+2) for i in range(n+2)] for j in range(n+2)]

for i in range(c+1):
    for j in range(n-a-i+1):
        for k in range(n-i-j+1):
            if i+j+k:
                DP[i][j][k] = (i*DP[i-1][j+1][k] + j*DP[i][j-1][k+1] + k*DP[i][j][k-1] + n)/(i+j+k)
print(DP[c][b][a])

Buggy python submission (verdict: Runtime Error):
from functools import lru_cache

n = int(input())
a = list(map(int, input().split()))

one = a.count(1)
two = a.count(2)
three = a.count(3)

@lru_cache(n**3)
def dfs(one,two,three):
    if one<0 or two<0 or three<0:
        return 0
    s = one+two+three
    if s == 0:
        return 0
    zero = n-s
    tmp = (one*dfs(one-1,two,three) + two*dfs(one+1, two-1, three) + three*dfs(one,two+1,three-1) + n)/(n - zero)
    return tmp

ans = dfs(one,two,three)
print(ans)

Fixed submission:
from collections import Counter
n = int(input())
a = list(map(int, input().split()))
c = Counter(a)
a,b,c = c[1],c[2],c[3]
DP = [[[0]*(n+2) for i in range(n+2)] for j in range(n+2)]

for i in range(c+1):
    for j in range(n-a-i+1):
        for k in range(n-i-j+1):
            if i+j+k:
                DP[i][j][k] = (i*DP[i-1][j+1][k] + j*DP[i][j-1][k+1] + k*DP[i][j][k-1] + n)/(i+j+k)
print(DP[c][b][a])

Buggy python submission (verdict: Runtime Error):
from functools import lru_cache

n = int(input())
a = list(map(int, input().split()))

one = a.count(1)
two = a.count(2)
three = a.count(3)

@lru_cache(n**3)
def dfs(one,two,three):
    if one<0 or two<0 or three<0:
        return 0
    s = one+two+three
    if s == 0:
        return 0
    zero = n-s
    tmp = (one*dfs(one-1,two,three) + two*dfs(one+1, two-1, three) + three*dfs(one,two+1,three-1) + n)/(n - zero)
    return tmp

ans = dfs(one,two,three)
print(ans)

Fixed submission:
from collections import Counter
n = int(input())
a = list(map(int, input().split()))
c = Counter(a)
a,b,c = c[1],c[2],c[3]
DP = [[[0]*(n+2) for i in range(n+2)] for j in range(n+2)]

for i in range(c+1):
    for j in range(n-a-i+1):
        for k in range(n-i-j+1):
            if i+j+k:
                DP[i][j][k] = (i*DP[i-1][j+1][k] + j*DP[i][j-1][k+1] + k*DP[i][j][k-1] + n)/(i+j+k)
print(DP[c][b][a])
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))

dp = [[-1]*n for i in range(n)]
for i in range(n):
    dp[i][i] = 0
cumsum = [0]
for i in range(n):
    cumsum.append(cumsum[-1] + a[i])

def calc_cost(left, right):
    if dp[left][right] >= 0:
        return dp[left][right]
    min_ = min(calc_cost(left, i) + calc_cost(i+1, right) for i in range(left, right))
    dp[left][right] = cumsum[right+1]-cumsum[left] + min_
    return dp[left][right]

print(calc_cost(0,n-1))

Fixed submission:
n = int(input())
a = list(map(int, input().split()))

dp = [[-1]*n for i in range(n)]
for i in range(n):
    dp[i][i] = 0
cumsum = [0]
for i in range(n):
    cumsum.append(cumsum[-1] + a[i])

def calc_cost(left, right):
    if dp[left][right] >= 0:
        return dp[left][right]
    min_ = min(calc_cost(left, i) + calc_cost(i+1, right) for i in range(left, right))
    dp[left][right] = cumsum[right+1]-cumsum[left] + min_
    return dp[left][right]

print(calc_cost(0,n-1))
Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict

mod = 10**9+7

n = int(input())
a = [list(map(int, input().split())) for i in range(n)]
DP = defaultdict(int)
DP[0] = 1
for i in range(n):
    nxt = defaultdict(int)
    for key, value in DP.items():
        for j in range(n):
            mask = 1<<j
            if key & mask == 0 and a[i][j]:
                nxt[key|mask] += value
                nxt[key|mask] %= mod
    DP = nxt
state = (1<<n) - 1
ans = DP[state]
print(ans)

Fixed submission:
mod = 10**9+7

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

DP = [0]*(1<<n)
DP[0] = 1

pow2 = [1<<i for i in range(n)]
cnt = [0]*(1<<n)
for i in range(1<<(n-1)):
    cnt[2*i] = cnt[i]
    cnt[2*i+1] = cnt[i]+1

for state in range(1, 1<<n):
    k = cnt[state]
    for j in range(n):
        if a[k-1][j] and (state>>j)&1:
            DP[state] += DP[state^pow2[j]]
    DP[state] %= mod
print(DP[-1])
Buggy python submission (verdict: Runtime Error):
mod = 10**9 + 7
N_str = input()
D = int(input())

max_k = len(N_str)
dp = [[[-1]*D for i in range(2)] for j in range(max_k) ]

def rec(k=0, tight=True, mod_sum=0):
    if k == max_k:
        return int(mod_sum==0)
    if dp[k][tight][mod_sum] >= 0:
        return dp[k][tight][mod_sum]
    top = 9 if not tight else int(N_str[k])
    res = 0
    for i in range(top+1):
        res += rec(k+1, tight and i==top, (mod_sum+i) % D)
        res %= mod
    dp[k][tight][mod_sum] = res
    return res

print(rec()-1)

Fixed submission:
mod = 10**9 + 7

K = list(map(int, list(input())))
D = int(input())
keta = len(K)

dp = [[[0]*D for i in range(2)] for j in range(keta+1)]
dp[0][1][0] = 1

from itertools import product
for i, j, k in product(range(keta), range(2), range(D)):
    max_n = K[i] if j else 9
    for l in range(max_n+1):
        dp[i+1][j and l == max_n][(k+l)%D] += dp[i][j][k]
        dp[i+1][j and l == max_n][(k+l)%D] %= mod

ans = 0
for i in range(2):
    ans += dp[-1][i][0]
    ans %= mod
print(max(0, (ans - 1)%mod))

Buggy python submission (verdict: Runtime Error):
mod = 10**9 + 7
N_str = input()
D = int(input())

max_k = len(N_str)
dp = [[[-1]*D for i in range(2)] for j in range(max_k) ]

def rec(k=0, tight=True, mod_sum=0):
    if k == max_k:
        return int(mod_sum==0)
    if dp[k][tight][mod_sum] >= 0:
        return dp[k][tight][mod_sum]
	top = 9 if not tight else int(N_str[k])
    res = 0
    for i in range(top+1):
        res += rec(k+1, tight and i==top, (mod_sum+i) % D)
        res %= mod
    dp[k][tight][mod_sum] = res
    return res

print(rec()-1)

Fixed submission:
mod = 10**9 + 7

K = list(map(int, list(input())))
D = int(input())
keta = len(K)

dp = [[[0]*D for i in range(2)] for j in range(keta+1)]
dp[0][1][0] = 1

from itertools import product
for i, j, k in product(range(keta), range(2), range(D)):
    max_n = K[i] if j else 9
    for l in range(max_n+1):
        dp[i+1][j and l == max_n][(k+l)%D] += dp[i][j][k]
        dp[i+1][j and l == max_n][(k+l)%D] %= mod

ans = 0
for i in range(2):
    ans += dp[-1][i][0]
    ans %= mod
print(max(0, (ans - 1)%mod))
Buggy python submission (verdict: Runtime Error):
from math import sqrt
n = int(input())
a = 1+8*n
b = int(sqrt(a))
if b**2 != a or b%2==0:
    print("No")
    exit()
else:
    print(c)
k = (1 + b)//2


Fixed submission:
from math import sqrt
n = int(input())
a = 1+8*n
b = int(sqrt(a))
if b**2 != a or b%2==0:
    print("No")
    exit()
else:
    k = (1 + b)//2
    s = [[] for i in range(k)]
    cur = 1
    for i in range(k):
        for j in range(k-i-1):
            s[i].append(cur)
            s[i+j+1].append(cur)
            cur += 1
    print("Yes")
    print(k)
    for i in range(k):
        res = "{} ".format(len(s[i])) + " ".join(map(str, s[i]))
        print(res)
Buggy python submission (verdict: Runtime Error):
import math

n, x = list(map(int, input().split()))
xi = list(map(int, input().split()))

ans = None
for i in xi:
    distance = abs(i-x)
    if ans is None:
        ans = distance
    else:
        ans = math.gcd(ans, distance)
print(ans)

Fixed submission:
import math
import numpy as np
def yakusu(num):
    top = []
    bot = []
    for i in range(int(math.sqrt(num))):
        k = i+1
        if num%k == 0:
            top.append(num//k)
            bot.append(k)
    return top + bot[::-1]

n, X = map(int, input().split())
x = list(map(int, input().split()))
x.append(X)
x.sort()
start = x[0]
x = np.array(x[1:])
x -= start
# print(x)

for ans_pred in yakusu(x[0]):
    if ans_pred == 1:
        break
    flag = True
    for i in x:
        if i % ans_pred != 0:
            flag= False
            break
    if flag:
        break

print(ans_pred)

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

n, X = list(map(int, input().split()))
x = list(map(int, input().split()))

ans = None
for ind, i in enumerate(x):
    x[ind] = abs(i - X)
    if ans is None:
        ans = x[ind]
    else:
        ans = math.gcd(ans, x[ind])
print(ans)

Fixed submission:
import math
import numpy as np
def yakusu(num):
    top = []
    bot = []
    for i in range(int(math.sqrt(num))):
        k = i+1
        if num%k == 0:
            top.append(num//k)
            bot.append(k)
    return top + bot[::-1]

n, X = map(int, input().split())
x = list(map(int, input().split()))
x.append(X)
x.sort()
start = x[0]
x = np.array(x[1:])
x -= start
# print(x)

for ans_pred in yakusu(x[0]):
    if ans_pred == 1:
        break
    flag = True
    for i in x:
        if i % ans_pred != 0:
            flag= False
            break
    if flag:
        break

print(ans_pred)
Buggy python submission (verdict: Runtime Error):
class BIT_RSQ():
    def __init__(self, n):
        self.n = n
        self.data = [0]*(n+1)

    def add(self, i, v):
        while i <= self.n:
            self.data[i-1] += v
            i += i & -i

    def sum(self, i):
        ret = 0
        while(i > 0):
            ret += self.data[i-1]
            i -= i & -i
        return ret

n = int(input())
a = list(map(int, input().split()))

def check(m):
    b = [[-1,1][i>=m] for i in a]
    bit = BIT_RSQ(2*n+1)
    s = [0] + list(accumulate(b))
    res = 0
    for i in range(n):
        bit.add(s[i]+n+1, 1)
        res += bit.sum(s[i+1]+n+1)
    return res >= (n*(n+1)//2+1)//2

left = 0
right = 10**9+1
while right-left > 1:
    mid = (right+left)//2
    if check(mid):
        left = mid
    else:
        right = mid
print(left)

Fixed submission:
from itertools import accumulate

class BIT_RSQ():
    def __init__(self, n):
        self.n = n
        self.data = [0]*(n+1)

    def add(self, i, v):
        while i <= self.n:
            self.data[i-1] += v
            i += i & -i

    def sum(self, i):
        ret = 0
        while(i > 0):
            ret += self.data[i-1]
            i -= i & -i
        return ret

n = int(input())
a = list(map(int, input().split()))

def check(m):
    b = [[-1,1][i>=m] for i in a]
    bit = BIT_RSQ(2*n+1)
    s = [0] + list(accumulate(b))
    res = 0
    for i in range(n):
        bit.add(s[i]+n+1, 1)
        res += bit.sum(s[i+1]+n+1)
    return res >= (n*(n+1)//2+1)//2

left = 0
right = 10**9+1
while right-left > 1:
    mid = (right+left)//2
    if check(mid):
        left = mid
    else:
        right = mid
print(left)
Buggy python submission (verdict: Runtime Error):
n,k = map(int, input().split())
ans = [0,1][n%k]
print(ans)

Fixed submission:
n,k = map(int, input().split())
ans = 1 if n%k else 0
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
def LI(): return list(map(int, input().split()))
n, m, d = LI()
if d == 0:
    one = n
    two = 0
else:
    hidari = d - max(0, 2*d-n)
    migi = n-hidari

    one = hidari*2
    two = max(0, migi - hidari)
    #print(hidari, migi,one,two)
a = one + 2*two
ans = n**(m-2)*(a*(m-1))
print(ans/n**m)



Fixed submission:
def LI(): return list(map(int, input().split()))
n, m, d = LI()
if d == 0:
    one = n
    two = 0
else:
    hidari = d - max(0, 2*d-n)
    migi = n-hidari

    one = hidari*2
    two = max(0, migi - hidari)
    #print(hidari, migi,one,two)
a = one + 2*two
ans = (a*(m-1))/n**2
print(ans)
Buggy python submission (verdict: Runtime Error):
from itertools import accumulate
from bisect import bisect_left

n = int(input())
a = list(map(int, input().split()))
s = list(accumulate(a))

ans = float("inf")

for j in range(2,n-1):
    i_list = []
    i_left = bisect_left(s, s[j-1]//2)-1
    if i_left != -1:
        i_list.append([s[i_left], s[j-1]-s[i_left]])
    if i_left != j-2:
        i_list.append([s[i_left+1], s[j-1]-s[i_left+1]])

    k_list = []
    k_left = bisect_left(s, s[j-1]+(s[-1]-s[j-1])//2)-1
    if k_left != j-1:
        k_list.append([s[k_left] - s[j-1], s[-1]-s[k_left]])
    if k_left != n-2:
        k_list.append([s[k_left+1] - s[j-1], s[-1]-s[k_left+1]])
    for i in i_list:
        for k in k_list:
            tmp = max(*i,*k)-min(*i, *k)
            ans = min(ans, tmp)

print(ans)

Fixed submission:
from itertools import accumulate
from bisect import bisect_left

n = int(input())
a = list(map(int, input().split()))
s = list(accumulate(a))

ans = float("inf")

for j in range(2,n-1):
    i_list = []
    i_left = bisect_left(s, s[j-1]//2)-1
    if i_left != -1:
        i_list.append([s[i_left], s[j-1]-s[i_left]])
    if i_left != j-2:
        i_list.append([s[i_left+1], s[j-1]-s[i_left+1]])

    k_list = []
    k_left = bisect_left(s, s[j-1]+(s[-1]-s[j-1])//2)-1
    if k_left != j-1:
        k_list.append([s[k_left] - s[j-1], s[-1]-s[k_left]])
    if k_left != n-2:
        k_list.append([s[k_left+1] - s[j-1], s[-1]-s[k_left+1]])
    for i in i_list:
        for k in k_list:
            tmp = max(i+k)-min(i+k)
            ans = min(ans, tmp)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
b = [[i, 1<<n] for i in range(len(a))]
a.append(-float("inf"))

def update(a1, a2):
    a1.extend(a2)
    return sorted(set(a1), key=lambda x: -a[x])[:2]

for j in range(n):
    for i in range(1<<n):
        if i & (1<<j):
            b[i] = update(b[i], b[i & ~(1<<j)])
ans = []
tmp = 0
for i in range(1, 1<<n):
    tmp = max(tmp, a[b[i][0]]+a[b[i][1]])
    ans.append(tmp)
print(*ans, sep="\n")


Fixed submission:
n = int(input())
a = list(map(int, input().split()))
b = [[i] for i in a]

for j in range(n):
    for i in range(1<<n):
        if i & (1<<j):
            b[i] = sorted(b[i]+b[i^1<<j], reverse=True)[:2]
ans = []
tmp = 0
for i in range(1, 1<<n):
    tmp = max(tmp, sum(b[i]))
    ans.append(tmp)
print(*ans, sep="\n")

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

n = int(input())
a = list(map(int, input().split()))

m = 1<<n
ans = [0]*m

for i in range(1, m):
    max1 = max2 = 0
    j = i
    while j >= 0:
        j &= i
        if a[j] >= max1:
            max1, max2 = a[j], max1
        elif a[j] > max2:
            max2 = a[j]
        j -= 1
    ans[i] = max(ans[i-1], max1+max2)

print(*ans[1:], sep="\n")

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
b = [[i] for i in a]

for j in range(n):
    for i in range(1<<n):
        if i & (1<<j):
            b[i] = sorted(b[i]+b[i^1<<j], reverse=True)[:2]
ans = []
tmp = 0
for i in range(1, 1<<n):
    tmp = max(tmp, sum(b[i]))
    ans.append(tmp)
print(*ans, sep="\n")
Buggy python submission (verdict: Time Limit Exceeded):
from itertools import product
n,m = map(int, input().split())

# dp[i][j] i個取った時の{+,-}*3 タイプの最大値
dp = [[0]*8 for i in range(m+1)]
op = [i for i in product([-1,1], repeat=3)]
#print(op)

for i in range(n):
    x,y,z = map(int, input().split())
    nxt = [[0]*8 for i in range(m+1)]
    for j in range(m):
        for k in range(8):
            nxt[j+1][k] = max(dp[j+1][k], dp[j][k] + op[k][0]*x+op[k][1]*y+op[k][2]*z)
    dp = nxt
print(max(dp[-1]))

Fixed submission:
n, m = map(int, input().split())
v = [list(map(int, input().split())) for i in range(n)]
ans = 0
op = [-1,1]
for i in range(2):
    for j in range(2):
        for k in range(2):
            sx, sy, sz = op[i], op[j], op[k]
            ans_tmp = sum(sorted([x*sx+y*sy+z*sz for x,y,z in v], reverse=True)[:m])
            ans = max(ans, ans_tmp)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
v = [list(map(int, input().split())) for i in range(n)]
ans = 0
op = [-1,1]
for i in range(2):
    for j in range(2):
        for k in range(2):
            sx, sy, sz = op[i], op[j], op[k]
            dp = [0]*(m+1)
            for l, (x, y, z) in enumerate(v):
                x *= sx
                y *= sy
                z *= sz
                score = x+y+z
                for h in range(min(m,l+1),0,-1):
                    if l < m and h == min(m,l+1):
                        dp[h] = dp[h-1]+score
                    else:
                        dp[h] = max(dp[h], dp[h-1]+score)
            ans = max(ans, dp[-1])
print(ans)

Fixed submission:
n, m = map(int, input().split())
v = [list(map(int, input().split())) for i in range(n)]
ans = 0
op = [-1,1]
for i in range(2):
    for j in range(2):
        for k in range(2):
            sx, sy, sz = op[i], op[j], op[k]
            ans_tmp = sum(sorted([x*sx+y*sy+z*sz for x,y,z in v], reverse=True)[:m])
            ans = max(ans, ans_tmp)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
board = [input() for i in range(n)]

def check(a, b):
    for i in range(n):
        for j in range(n):
            if board[(i-a)%n][(j-b)%n] != board[(j-a)%n][(i-b)%n]:
                return False
    return True

ans = 0
for i in range(n):
    if check(i,0):
        ans += n-i
    if check(0,i) and i >0:
        ans += n-i
print(ans)

Fixed submission:
# 解説AC
n = int(input())
board = [input() for i in range(n)]

def check(a, b):
    for i in range(n):
        for j in range(n):
            if board[(i-a)%n][(j-b)%n] != board[(j-a)%n][(i-b)%n]:
                return False
    return True

ans = 0
for i in range(n):
    if check(i,0):
        ans += n-i
    if check(0,i) and i >0:
        ans += n-i
print(ans)
Buggy python submission (verdict: Runtime Error):
n = int(input())
if n == 3:
    ans = [2, 5, 63]
elif n == 4:
    ans = [2, 5, 20, 63]
else:
    even = odd = None
    for i in range(1, 5001):
        a = n-3*i
        if a % 2 == 0 and 0 < a//2 <= 2500:
            even = 3*i
            odd = a
            break
    assert(even+odd == n)
    assert(0 < even <= 15000)
    assert(0 < odd <= 5000)
    evens = [i for i in range(1, 30001) if i%2 == 0]
    odds = [i for i in range(1, 30001) if i%3 == 0 and i%2 == 1]
    ans = evens[:even] + odds[:odd]
print(*ans)

Fixed submission:
n = int(input())
if n == 3:
    ans = [2, 5, 63]
elif n == 4:
    ans = [2, 5, 20, 63]
elif n == 6:
    ans = [2, 4, 8, 10, 3, 9]
else:
    even = odd = None
    for i in range(1, 5001):
        a = n-3*i
        if a % 2 == 0 and 0 < a <= 5000:
            even = 3*i
            odd = a
            break
    if n == 19999:
        even = 14999
        odd = 5000
    assert(even+odd == n)
    assert(0 < even <= 15000)
    assert(0 < odd <= 5000)
    evens = [i for i in range(1, 30001) if i%2 == 0]
    odds = [i for i in range(1, 30001) if i%3 == 0 and i%2 == 1]
    ans = evens[:even] + odds[:odd]
print(*ans)
Buggy python submission (verdict: Runtime Error):
h, w = map(int, input().split())
grid = [[c == "." for c in input()] for i in range(h)]
if not (grid[0][0] and grid[-1][-1]):
    print(-1)
else:
    print(grid[1000000])

Fixed submission:
from collections import deque
h, w = map(int, input().split())
grid = [[c == "." for c in input()] for i in range(h)]
q = deque()
q.append((0,0,1))
visited = set()
min_dist = 0
while q:
    y, x, d = q.popleft()
    # 訪問済み、黒マスならスキップ
    if (y,x) in visited or not grid[y][x]:
        continue
    visited.add((y,x))
    # 終了条件
    if y == h-1 and x == w-1:
        min_dist = d
        break

    for dy, dx in [[-1,0],[1,0],[0,1],[0,-1]]:
        yn = y + dy
        xn = x + dx
        if 0<=yn<h and 0<=xn<w:
            q.append((yn, xn, d+1))
if min_dist:
    white = sum(sum(i) for i in grid)
    #print(white, min_dist)
    print(white - min_dist)
else:
    print(-1)