from collections import Counter

from itertools import product





def solve(LIST):

    stmp = [i for i, li in enumerate(LIST * 2) if li == 1]

    S = min(stmp[i] - stmp[i - 1] for i in range(1, len(stmp)))

    return S





n = int(eval(input()))

d = Counter(list(map(int, input().split())) + [0])



if any(d[num] > (2 - (num in {0, 12})) for num in d):

    print((0))

    exit()



ans, cnt = [0] * 24, []

for num in d:

    if (num in {0, 12}) and d[num] == 1:

        ans[num] = 1 

    elif d[num] == 2:

        ans[num], ans[24 - num] = 1, 1

    elif d[num] == 1:

        cnt.append(num)



s = 0

if len(cnt) == 0:

    s = max(s, solve(ans))

for bit in product([1, -1], repeat=len(cnt)):

    tmp = ans[:]

    for bi, ci in zip(bit, cnt):

        tmp[(ci - 12) * bi + 12] = 1

    s = max(s, solve(tmp))

print(s)

n = int(eval(input()))

d = sorted(list(map(int, input().split())) + [0])



bit, cnt = [0] * 24, 1

for num in d:

    bit[((num - 12) * cnt + 12) % 24] += 1

    cnt *= -1



if any(i > 1 for i in bit):

    print((0))

    exit()

ans = [i for i, li in enumerate(bit * 2) if li == 1]

s = min(ans[i] - ans[i - 1] for i in range(1, len(ans)))

print(s)

from collections import Counter
from itertools import product


def solve(LIST):
    stmp = [i for i, li in enumerate(LIST * 2) if li == 1]
    S = min(stmp[i] - stmp[i - 1] for i in range(1, len(stmp)))
    return S


n = int(eval(input()))
d = Counter(list(map(int, input().split())) + [0])
if any(d[num] > (2 - (num in {0, 12})) for num in d):
    print((0))
    exit()
ans, cnt = [0] * 24, []
for num in d:
    if (num in {0, 12}) and d[num] == 1:
        ans[num] = 1
    elif d[num] == 2:
        ans[num], ans[24 - num] = 1, 1
    elif d[num] == 1:
        cnt.append(num)
s = 0
if len(cnt) == 0:
    s = max(s, solve(ans))
for bit in product([1, -1], repeat=len(cnt)):
    tmp = ans[:]
    for bi, ci in zip(bit, cnt):
        tmp[(ci - 12) * bi + 12] = 1
    s = max(s, solve(tmp))
print(s)

n = int(eval(input()))
d = sorted(list(map(int, input().split())) + [0])
bit, cnt = [0] * 24, 1
for num in d:
    bit[((num - 12) * cnt + 12) % 24] += 1
    cnt *= -1
if any(i > 1 for i in bit):
    print((0))
    exit()
ans = [i for i, li in enumerate(bit * 2) if li == 1]
s = min(ans[i] - ans[i - 1] for i in range(1, len(ans)))
print(s)

-from collections import Counter -from itertools import product - - -def solve(LIST): -    stmp = [i for i, li in enumerate(LIST * 2) if li == 1] -    S = min(stmp[i] - stmp[i - 1] for i in range(1, len(stmp))) -    return S - - -d = Counter(list(map(int, input().split())) + [0]) -if any(d[num] > (2 - (num in {0, 12})) for num in d): +d = sorted(list(map(int, input().split())) + [0]) +bit, cnt = [0] * 24, 1 +for num in d: +    bit[((num - 12) * cnt + 12) % 24] += 1 +    cnt *= -1 +if any(i > 1 for i in bit): -ans, cnt = [0] * 24, [] -for num in d: -    if (num in {0, 12}) and d[num] == 1: -        ans[num] = 1 -    elif d[num] == 2: -        ans[num], ans[24 - num] = 1, 1 -    elif d[num] == 1: -        cnt.append(num) -s = 0 -if len(cnt) == 0: -    s = max(s, solve(ans)) -for bit in product([1, -1], repeat=len(cnt)): -    tmp = ans[:] -    for bi, ci in zip(bit, cnt): -        tmp[(ci - 12) * bi + 12] = 1 -    s = max(s, solve(tmp)) +ans = [i for i, li in enumerate(bit * 2) if li == 1] +s = min(ans[i] - ans[i - 1] for i in range(1, len(ans)))