Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

n, u = na()
d = []
for i in range(u):
    d.append(na())

c = []
for i in range(n):
    c.append(na())

for i in range(n):
    for j in range(n):
        c[i][j] -= 1

fs = []
for i in range(u):
    f = [0]*3
    for j in range(n):
        t = j%3
        for k in range(n):
            f[t] += d[c[j][k]][i]
            t += 1
            if t == 3:
                t = 0
    fs.append(f)

ans = 99999999999999999
for i in range(u):
    for j in range(u):
        for k in range(u):
            if i == j or j == k or k == i: continue

            ans = min(ans, fs[i][0] + fs[j][1] + fs[k][2])
print(ans)


Fixed submission:
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

n, u = na()
d = []
for i in range(u):
    d.append(na())

c = []
for i in range(n):
    c.append(na())

for i in range(n):
    for j in range(n):
        c[i][j] -= 1

fs = []
for i in range(u):
    f = [0]*3
    for j in range(n):
        t = j%3
        for k in range(n):
            f[t] += d[c[j][k]][i]
            t += 1
            if t == 3:
                t = 0
    fs.append(f)

ans = 99999999999999999
for i in range(u):
    for j in range(u):
        for k in range(u):
            if i == j or j == k or k == i: continue

            ans = min(ans, fs[i][0] + fs[j][1] + fs[k][2])
print(ans)

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

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

n, u = na()
d = []
for i in range(u):
    d.append(na())

c = []
for i in range(n):
    c.append(na())

for i in range(n):
    for j in range(n):
        c[i][j] -= 1

fs = []
for i in range(u):
    f = [0]*3
    for j in range(n):
        for k in range(n):
            f[(j+k)%3] += d[c[j][k]][i]
    fs.append(f)

ans = 99999999999999999
for i in range(u):
    for j in range(u):
        for k in range(u):
            if i == j or j == k or k == i: continue

            ans = min(ans, fs[i][0] + fs[j][1] + fs[k][2])
print(ans)


Fixed submission:
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

n, u = na()
d = []
for i in range(u):
    d.append(na())

c = []
for i in range(n):
    c.append(na())

for i in range(n):
    for j in range(n):
        c[i][j] -= 1

fs = []
for i in range(u):
    f = [0]*3
    for j in range(n):
        t = j%3
        for k in range(n):
            f[t] += d[c[j][k]][i]
            t += 1
            if t == 3:
                t = 0
    fs.append(f)

ans = 99999999999999999
for i in range(u):
    for j in range(u):
        for k in range(u):
            if i == j or j == k or k == i: continue

            ans = min(ans, fs[i][0] + fs[j][1] + fs[k][2])
print(ans)
Buggy python submission (verdict: Runtime Error):
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

print("Yes" if "9" in ns else "No")


Fixed submission:
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

print("Yes" if "9" in ns() else "No")
Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(100001)
stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

n = ni()
g = []
for i in range(n+1): g.append([])

for i in range(n-1):
    a, b, c = na()
    g[a].append((b,c))
    g[b].append((a,c))

q,k = na()

def dfs(cur, pre, g, par, dw, w):
    dw[cur] = w
    par[cur] = pre
    for e in g[cur]:
        if e[0] != pre:
            dfs(e[0], cur, g, par, dw, w + e[1])

par = [-1] * (n+2)
dw = [-1] * (n+2)
dfs(k, -1, g, par, dw, 0)

for z in range(q):
    x, y = na()
    print(dw[x] + dw[y])

Fixed submission:
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

n = ni()
g = []
for i in range(n+1): g.append([])

for i in range(n-1):
    a, b, c = na()
    g[a].append((b,c))
    g[b].append((a,c))

q,k = na()

def dfs(cur, pre, g, par, dw, w):
    dw[cur] = w
    par[cur] = pre
    for e in g[cur]:
        if e[0] != pre:
            dfs(e[0], cur, g, par, dw, w + e[1])

par = [-1] * (n+2)
dw = [-1] * (n+2)
from queue import Queue
qs = Queue()
qs.put(k)
dw[k] = 0

while not qs.empty():
    cur = qs.get()
    for e in g[cur]:
        if e[0] != par[cur]:
            par[e[0]] = cur
            dw[e[0]] = dw[cur] + e[1]
            qs.put(e[0])


# dfs(k, -1, g, par, dw, 0)

for z in range(q):
    x, y = na()
    print(dw[x] + dw[y])

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

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

n = ni()
g = []
for i in range(n+1): g.append([])

for i in range(n-1):
    a, b, c = na()
    g[a].append((b,c))
    g[b].append((a,c))

q,k = na()

def dfs(cur, pre, g, par, dw, w):
    dw[cur] = w
    par[cur] = pre
    for e in g[cur]:
        if e[0] != pre:
            dfs(e[0], cur, g, par, dw, w + e[1])

par = [-1] * (n+2)
dw = [-1] * (n+2)
dfs(k, -1, g, par, dw, 0)

for z in range(q):
    x, y = na()
    print(dw[x] + dw[y])



Fixed submission:
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

n = ni()
g = []
for i in range(n+1): g.append([])

for i in range(n-1):
    a, b, c = na()
    g[a].append((b,c))
    g[b].append((a,c))

q,k = na()

def dfs(cur, pre, g, par, dw, w):
    dw[cur] = w
    par[cur] = pre
    for e in g[cur]:
        if e[0] != pre:
            dfs(e[0], cur, g, par, dw, w + e[1])

par = [-1] * (n+2)
dw = [-1] * (n+2)
from queue import Queue
qs = Queue()
qs.put(k)
dw[k] = 0

while not qs.empty():
    cur = qs.get()
    for e in g[cur]:
        if e[0] != par[cur]:
            par[e[0]] = cur
            dw[e[0]] = dw[cur] + e[1]
            qs.put(e[0])


# dfs(k, -1, g, par, dw, 0)

for z in range(q):
    x, y = na()
    print(dw[x] + dw[y])
Buggy python submission (verdict: Runtime Error):
import sys

stdin = sys.stdin


def na(): return map(int, stdin.readline().split())


def ns(): return stdin.readline().strip()


a,b,c = map(int, stdin.readlien().split())
if a <= c <= b:
    print("Yes")
else:
    print("No")
    

Fixed submission:
import sys

stdin = sys.stdin


def na(): return map(int, stdin.readline().split())


def ns(): return stdin.readline().strip()


a,b,c = na()
if a <= c <= b:
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Time Limit Exceeded):
from typing import List, Any
import math
import sys
input = sys.stdin.readline

class SegmentTree:
    
    def __init__(self, array):
        self.n = len(array)
        self.array = [0 for _ in array]+array
        for i in range(self.n-1, 0, -1):
            self.array[i] = max(self.array[i<<1], self.array[i<<1|1])

    def set(self, i, v):
        p = self.n+i
        self.array[p] = v
        while p > 1:
            p >>= 1
            self.array[p] = max(self.array[p<<1], self.array[p<<1|1])

    def max(self, l, r):
        l += self.n
        r += self.n
        answer = 0
        while l < r:
            if l&1:
                answer = max(answer, self.array[l])
                l += 1
            if r&1:
                r -= 1
                answer = max(answer, self.array[r])
            l >>= 1
            r >>= 1
        return answer


def read_int() -> int:
    return int(input().strip())


def read_ints() -> List[int]:
    return list(map(int, input().strip().split(' ')))


def solve() -> Any:
    N, K = read_ints()
    A = [read_int() for _ in range(N)]
    maxA = max(A)
    segment_tree = SegmentTree([0]*(maxA+1))
    for a in A:
        count = segment_tree.max(max(0, a-K), min(maxA, a+K)+1)
        segment_tree.set(a, count+1)
    return segment_tree.max(0, maxA+1)


if __name__ == '__main__':
    print(solve())


Fixed submission:
from typing import List, Any
import math
import sys
input = sys.stdin.readline

class SegmentTree:
    
    def __init__(self, array):
        self.n = len(array)
        self.array = [0 for _ in array]+array
        for i in range(self.n-1, 0, -1):
            self.array[i] = max(self.array[i<<1], self.array[i<<1|1])

    def set(self, i, v):
        p = self.n+i
        self.array[p] = v
        while p > 1:
            p >>= 1
            self.array[p] = max(self.array[p<<1], self.array[p<<1|1])

    def max(self, l, r):
        l += self.n
        r += self.n
        answer = 0
        while l < r:
            if l&1:
                answer = max(answer, self.array[l])
                l += 1
            if r&1:
                r -= 1
                answer = max(answer, self.array[r])
            l >>= 1
            r >>= 1
        return answer


def read_int() -> int:
    return int(input().strip())


def read_ints() -> List[int]:
    return list(map(int, input().strip().split(' ')))


def solve() -> Any:
    N, K = read_ints()
    A = [read_int() for _ in range(N)]
    maxA = max(A)
    segment_tree = SegmentTree([0]*(maxA+1))
    for a in A:
        count = segment_tree.max(max(0, a-K), min(maxA, a+K)+1)
        segment_tree.set(a, count+1)
    return segment_tree.max(0, maxA+1)


if __name__ == '__main__':
    print(solve())
Buggy python submission (verdict: Time Limit Exceeded):


MOD = 10**9+7
factorial = [1]
inverse_factorial = [0]


def modpow(a, p):
    ans = 1
    while p:
        if p&1 == 1:
            ans = (ans*a)%MOD
        a = (a*a)%MOD
        p >>= 1
    return ans


def nCr(n, r):
    if r == 0 or r == n:
        return 1
    return (((factorial[n]*inverse_factorial[n-r])%MOD)*inverse_factorial[r])%MOD


def init_nCr(max_n):
    for i in range(1, 2*max_n+1):
        f = (factorial[-1]*i)%MOD
        factorial.append(f)
        inv_f = modpow(f, MOD-2)
        inverse_factorial.append(inv_f)


def pow(b, p):
    ans = 1
    for _ in range(p):
        ans = (ans*b)%MOD
    return ans


def pow_list(b, p):
    ans = [1]
    for _ in range(p):
        ans.append(ans[-1]*b)
    return ans


def read_int():
    return int(input().strip())


def read_ints():
    return list(map(int, input().strip().split(' ')))


def solve():
    K = read_int()
    S = len(input().strip())
    init_nCr(K+S)
    T = pow(26, K+S)
    pow_25 = pow_list(25, K+S)
    for i in range(S):
        T = (T-nCr(K+S, i)*pow_25[K+S-i])%MOD
    return T


if __name__ == '__main__':
    print(solve())


Fixed submission:


MOD = 10**9+7
factorial = [1]
inverse_factorial = [0]


def modpow(a, p):
    ans = 1
    while p:
        if p&1 == 1:
            ans = (ans*a)%MOD
        a = (a*a)%MOD
        p >>= 1
    return ans


def nCr(n, r):
    if r == 0 or r == n:
        return 1
    return (((factorial[n]*inverse_factorial[n-r])%MOD)*inverse_factorial[r])%MOD


def init_nCr(max_n):
    for i in range(1, max_n+1):
        f = (factorial[-1]*i)%MOD
        factorial.append(f)
        inv_f = modpow(f, MOD-2)
        inverse_factorial.append(inv_f)


def pow(b, p):
    ans = 1
    for _ in range(p):
        ans = (ans*b)%MOD
    return ans


def pow_list(b, p):
    ans = [1]
    for _ in range(p):
        ans.append((ans[-1]*b)%MOD)
    return ans


def read_int():
    return int(input().strip())


def read_ints():
    return list(map(int, input().strip().split(' ')))


def solve():
    K = read_int()
    S = len(input().strip())
    init_nCr(K+S)
    T = pow(26, K+S)
    pow_25 = pow_list(25, K+S)
    for i in range(S):
        T = (T-(nCr(K+S, i)*pow_25[K+S-i])%MOD)%MOD
    return T


if __name__ == '__main__':
    print(solve())
Buggy python submission (verdict: Time Limit Exceeded):
import math
from itertools import product
from collections import Counter


def read_int():
    return int(input().strip())


def read_ints():
    return list(map(int, input().strip().split(' ')))


def sums(a, N):
    ans = ((N//a)*((N//a)+1)//2)*a
    return ans


colors = set(['R', 'G', 'B'])

    

def solve():
    N = read_int()
    S = input().strip()
    right = Counter(S)
    left = Counter()
    total = 0
    for i in range(N):
        take = S[i]
        right[take] -= 1
        #
        for j in range(i):
            if S[j] != S[i]:
                color = (colors-set([S[j], S[i]])).pop()
                k = 2*i-j
                total += right[color]
                if k < N and S[k] == color:
                    total -= 1
        #
        left[take] += 1
    return total


if __name__ == '__main__':
    print(solve())


Fixed submission:
import math
from itertools import product
from collections import Counter


def read_int():
    return int(input().strip())


def read_ints():
    return list(map(int, input().strip().split(' ')))


def sums(a, N):
    ans = ((N//a)*((N//a)+1)//2)*a
    return ans


colors = ['R', 'G', 'B']

def complement(A, B):
    for color in colors:
        if A != color and B != color:
            return color
    

def solve():
    N = read_int()
    S = input().strip()
    right = Counter(S)
    left = Counter()
    total = 0
    for i in range(N):
        take = S[i]
        right[take] -= 1
        #
        for j in range(i):
            if S[j] != S[i]:
                color = complement(S[j], S[i])
                k = 2*i-j
                total += right[color]
                if k < N and S[k] == color:
                    total -= 1
        #
        left[take] += 1
    return total


if __name__ == '__main__':
    print(solve())
Buggy python submission (verdict: Runtime Error):


def read_int():
    return int(input().strip())


def read_ints():
    return list(map(int, input().strip().split(' ')))


def solve():
    """
    """
    N = read_int()
    A = read_ints()
    T = [0, 0, 0]
    answer = 1
    modulo = 1000000007
    for a in A:
        answer = (answer*T.count(a))%modulo
        T[T.index(a)] += 1
    return answer


if __name__ == '__main__':
    print(solve())


Fixed submission:


def read_int():
    return int(input().strip())


def read_ints():
    return list(map(int, input().strip().split(' ')))


def solve():
    """
    """
    N = read_int()
    A = read_ints()
    T = [0, 0, 0]
    answer = 1
    modulo = 1000000007
    for a in A:
        if a not in T:
            return 0
        answer = (answer*T.count(a))%modulo
        T[T.index(a)] += 1
    return answer


if __name__ == '__main__':
    print(solve())
Buggy python submission (verdict: Runtime Error):
from typing import List, Any


def read_int() -> int:
    return int(input().strip())


def read_ints() -> List[int]:
    return list(map(int, input().strip().split(' ')))


def solve() -> Any:
    N, M = read_ints()
    # key to cover
    cover = [0]*(1<<N)
    # key to cost
    costs = [0]*M
    INF = 10**9+1
    for i in range(M):
        a, b = read_ints()
        costs[i] = a
        for c in read_ints():
            cover[i] |= 1<<(c-1)
    # mask to cost
    mask_to_cost = [INF]*(1<<N)
    mask_to_cost[0] = 0
    for mask in range(1<<N):
        for i in range(M):
            mask_to_cost[cover[i]|mask] = min(mask_to_cost[cover[i]|mask], mask_to_cost[mask]+costs[i])
    return mask_to_cost[(1<<N)-1] if mask_to_cost[(1<<N)-1] != INF else -1


if __name__ == '__main__':
    print(solve())


Fixed submission:
from typing import List, Any


def read_int() -> int:
    return int(input().strip())


def read_ints() -> List[int]:
    return list(map(int, input().strip().split(' ')))


def solve() -> Any:
    N, M = read_ints()
    # key to cover
    cover = [0]*M
    # key to cost
    costs = [0]*M
    INF = 10**9+1
    for i in range(M):
        a, b = read_ints()
        costs[i] = a
        for c in read_ints():
            cover[i] |= 1<<(c-1)
    # mask to cost
    mask_to_cost = [INF]*(1<<N)
    mask_to_cost[0] = 0
    for mask in range(1<<N):
        for i in range(M):
            mask_to_cost[cover[i]|mask] = min(mask_to_cost[cover[i]|mask], mask_to_cost[mask]+costs[i])
    return mask_to_cost[(1<<N)-1] if mask_to_cost[(1<<N)-1] != INF else -1


if __name__ == '__main__':
    print(solve())
Buggy python submission (verdict: Runtime Error):


def read_int():
    return int(input().strip())


def read_ints():
    return list(map(int, input().strip().split(' ')))


def ilen(it):
    return sum(1 for _ in it)


def solve():
    """
    C[N-K+1][i]*C[K-1][i-1]
    1 1 1
    1 2 3
    1 3 6
    """
    N, K = read_ints()
    C = [
        [0 for _ in range(2001)] for _ in range(2001)
    ]
    modulo = 10**9+7
    C[1][1] = 1
    for i in range(2, 2001):
        for j in range(1, i+1):
            C[i][j] = (C[i-1][j]+C[i-1][j-1])%modulo

    for i in range(1, K+1):
        print((C[N-K+1+1][i+1]*C[K-1+1][i-1+1])%modulo)


if __name__ == '__main__':
    solve()


Fixed submission:


def read_int():
    return int(input().strip())


def read_ints():
    return list(map(int, input().strip().split(' ')))


def ilen(it):
    return sum(1 for _ in it)


def solve():
    """
    C[N-K+1][i]*C[K-1][i-1]
    1 1 1
    1 2 3
    1 3 6
    """
    N, K = read_ints()
    C = [
        [0 for _ in range(2002)] for _ in range(2002)
    ]
    modulo = 10**9+7
    C[1][1] = 1
    for i in range(2, 2002):
        for j in range(1, i+1):
            C[i][j] = (C[i-1][j]+C[i-1][j-1])%modulo

    for i in range(1, K+1):
        print((C[N-K+1+1][i+1]*C[K-1+1][i-1+1])%modulo)


if __name__ == '__main__':
    solve()
Buggy python submission (verdict: Time Limit Exceeded):


def read_int():
    return int(input().strip())


def read_ints():
    return list(map(int, input().strip().split(' ')))


def solve():
    # dp[i] = min(abs(h[i]-h[i-1])+dp[i-1], abs(h[i]-h[i-2])+dp[i-2])
    N, K = read_ints()
    h = read_ints()
    dp = [0, abs(h[1]-h[0])]
    for i in range(2, N):
        dp.append(min(abs(h[i]-h[i-k])+dp[i-k] for k in range(1, K+1) if i >= k))
    return dp[-1]


if __name__ == '__main__':
    print(solve())


Fixed submission:

def read_int():
    return int(input().strip())


def read_ints():
    return list(map(int, input().strip().split(' ')))


def solve():
    # dp[i] = min(abs(h[i]-h[i-1])+dp[i-1], abs(h[i]-h[i-2])+dp[i-2])
    N, K = read_ints()
    h = read_ints()
    dp = [0, abs(h[1]-h[0])]
    for i in range(2, N):
        dp.append(min(abs(h[i]-h[i-k])+dp[i-k] for k in range(1, K+1) if i >= k))
    return dp[-1]


if __name__ == '__main__':
    print(solve())
Buggy python submission (verdict: Time Limit Exceeded):
import math
from functools import lru_cache, reduce


def read_int():
    return int(input().strip())


def read_ints():
    return list(map(int, input().strip().split(' ')))


def prefix_sum(arr, a):
    arr.append(arr[-1]+a)
    return arr


def solve():
    """
    OPT[i][j] = min(OPT[i][k]+OPT[k+1][j])+sum(A[i:j+1])    i <= k < j
    OPT[i][j] = 0 if i == j
    """
    N = read_int()
    A = read_ints()
    prefix = reduce(prefix_sum, A, [0])

    @lru_cache(None)
    def dp(i, j):
        if i == j:
            return 0
        return min(dp(i, k)+dp(k+1, j)+(prefix[j+1]-prefix[i]) for k in range(i, j))

    return dp(0, N-1)


if __name__ == '__main__':
    print(solve())


Fixed submission:
import math
from functools import lru_cache, reduce


def read_int():
    return int(input().strip())


def read_ints():
    return list(map(int, input().strip().split(' ')))


def prefix_sum(arr, a):
    arr.append(arr[-1]+a)
    return arr


def solve():
    """
    OPT[i][j] = min(OPT[i][k]+OPT[k+1][j])+sum(A[i:j+1])    i <= k < j
    OPT[i][j] = 0 if i == j
    """
    N = read_int()
    A = read_ints()
    prefix = reduce(prefix_sum, A, [0])

    @lru_cache(None)
    def dp(i, j):
        if i == j:
            return 0
        return min(dp(i, k)+dp(k+1, j)+(prefix[j+1]-prefix[i]) for k in range(i, j))

    OPT = [[0]*N for _ in range(N)]
    for j in range(N):
        for i in range(j-1, -1, -1):
            OPT[i][j] = min(OPT[i][k]+OPT[k+1][j] for k in range(i, j))+(prefix[j+1]-prefix[i])

    return OPT[0][N-1]


if __name__ == '__main__':
    print(solve())

Buggy python submission (verdict: Time Limit Exceeded):
import math
from functools import lru_cache


def read_int():
    return int(input().strip())


def read_ints():
    return list(map(int, input().strip().split(' ')))


def solve():
    """
    OPT[i][j] = min(OPT[i][k]+OPT[k+1][j])+sum(A[i:j+1])    i <= k < j
    OPT[i][j] = 0 if i == j
    """
    N = read_int()
    A = read_ints()

    @lru_cache(None)
    def dp(i, j):
        if i == j:
            return 0
        return min(dp(i, k)+dp(k+1, j)+sum(A[i:j+1]) for k in range(i, j))

    return dp(0, N-1)


if __name__ == '__main__':
    print(solve())


Fixed submission:
import math
from functools import lru_cache, reduce


def read_int():
    return int(input().strip())


def read_ints():
    return list(map(int, input().strip().split(' ')))


def prefix_sum(arr, a):
    arr.append(arr[-1]+a)
    return arr


def solve():
    """
    OPT[i][j] = min(OPT[i][k]+OPT[k+1][j])+sum(A[i:j+1])    i <= k < j
    OPT[i][j] = 0 if i == j
    """
    N = read_int()
    A = read_ints()
    prefix = reduce(prefix_sum, A, [0])

    @lru_cache(None)
    def dp(i, j):
        if i == j:
            return 0
        return min(dp(i, k)+dp(k+1, j)+(prefix[j+1]-prefix[i]) for k in range(i, j))

    OPT = [[0]*N for _ in range(N)]
    for j in range(N):
        for i in range(j-1, -1, -1):
            OPT[i][j] = min(OPT[i][k]+OPT[k+1][j] for k in range(i, j))+(prefix[j+1]-prefix[i])

    return OPT[0][N-1]


if __name__ == '__main__':
    print(solve())
Buggy python submission (verdict: Time Limit Exceeded):
import math
from typing import List, Counter, Tuple
from collections import Counter
from itertools import permutations


def read_int() -> int:
    return int(input().strip())


def read_ints() -> List[int]:
    return list(map(int, input().strip().split(' ')))


INF = 10**9

def solve() -> int:
    N = read_int()
    D = read_ints()
    if N>23:
        return 0
    max_distance = -INF
    for mask in range(1<<N):
        distances = [0]
        min_distance = INF
        temp = mask
        for i in range(N):
            if temp&1 == 0:
                d = D[i]
            else:
                d = 24-D[i]
            current = min(min(abs(d0-d), 24-abs(d0-d)) for d0 in distances)
            distances.append(d)
            if current < min_distance:
                min_distance = current
            temp >>= 1
        if min_distance > max_distance:
            max_distance = min_distance
    return max_distance
        


if __name__ == '__main__':
    print(solve())


Fixed submission:
import math
from typing import List, Counter, Tuple
from collections import Counter
from itertools import permutations


def read_int() -> int:
    return int(input().strip())


def read_ints() -> List[int]:
    return list(map(int, input().strip().split(' ')))


INF = 10**9

def solve() -> int:
    N = read_int()
    D = read_ints()
    if N>23:
        return 0
    D.sort(key=lambda d:min(d, 24-d))
    right = True
    assignment = [False]*24
    assignment[0] = True
    for d in D:
        if right:
            if assignment[d]:
                return 0
            assignment[d] = True
        else:
            if assignment[(24-d)%24]:
                return 0
            assignment[(24-d)%24] = True
        right = not right

    count = 0
    counts = []
    for i in range(1, len(assignment)+1):
        i %= 24
        if not assignment[i]:
            count += 1
        else:
            counts.append(count)
            count = 0
    return min(counts)+1
        


if __name__ == '__main__':
    print(solve())