Problem:
In CODE FESTIVAL XXXX, there are N+1 participants from all over the world, including Takahashi.  Takahashi checked and found that the _time gap_ (defined below) between the local times in his city and the i-th person's city was D_i hours. The time gap between two cities is defined as follows. For two cities A and B, if the local time in city B is d o'clock at the moment when the local time in city A is 0 o'clock, then the time gap between these two cities is defined to be min(d,24-d) hours. Here, we are using 24-hour notation. That is, the local time in the i-th person's city is either d o'clock or 24-d o'clock at the moment when the local time in Takahashi's city is 0 o'clock, for example.  Then, for each pair of two people chosen from the N+1 people, he wrote out the time gap between their cities. Let the smallest time gap among them be s hours.  Find the maximum possible value of s.

Incorrect submission (verdict: Wrong Answer):
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline
INF = 2**62-1


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


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, D):
    D.append(0)
    C = Counter(D)
    if C[0] + C[12] > 1:
        return 0
    

    K = []
    for k in C:
        for _ in range(2 if C[k] >= 2 else 1):
            K.append(k)
    M = len(K)
    ans = 0
    for S in product([1, -1], repeat=M):
        tmp = []
        for s, v in zip(S, K):
            tmp.append(s*v)
        tmp.sort()
        cand = INF
        for i in range(M):
            d = abs(tmp[i] - tmp[i-1])
            cand = min(cand, min(24-d, d))
        ans = max(ans, cand)

    return ans

def main():
    N = read_int()
    D = read_int_n()
    print(slv(N, D))


if __name__ == '__main__':
    main()


Fixed, accepted submission:
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline
INF = 2**62-1


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


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, D):
    D.append(0)
    C = Counter(D)
    if C[0] > 1 or C[12] > 1:
        return 0
    

    K = []
    F = []
    for k in C:
        if C[k] > 2:
            return 0
        elif C[k] == 2:
            F.append(24-k)
            F.append(k)
        else:
            K.append(k)
    M = len(K)
    ans = 0
    for S in product([1, -1], repeat=M):
        tmp = []
        for s, v in zip(S, K):
            tmp.append(s*v)
        tmp.extend(F)
        tmp.sort()
        cand = INF
        for i in range(len(tmp)):
            d = abs(tmp[i] - tmp[i-1])
            cand = min(cand, min(24-d, d))

        ans = max(ans, cand)

    return ans

def main():
    N = read_int()
    D = read_int_n()
    print(slv(N, D))


if __name__ == '__main__':
    main()