n = int(eval(input()))

a = [0]*13

for i in map(int, input().split()):

    a[i] += 1



ans = 0

if not (any(i>2 for i in a) or a[0] or a[12]>1):

    s = [[0]]

    for i in range(1, 13):

        nxt = []

        if a[i] == 0:

            nxt = s

        elif a[i] == 1:

            for si in s:

                nxt.append(si+[i])

                nxt.append(si+[24-i])

        else:

            for si in s:

                nxt.append(si+[i, 24-i])

        s = nxt

    for si in s:

        si.sort()

        tmp = float("Inf")

        for i in range(len(si)):

            k = abs(si[i]-si[i-1])

            k = min(k, 24-k)

            tmp = min(tmp, k)

        ans = max(ans, tmp)

print(ans)
n = int(eval(input()))

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

d.sort()

d = [j if i%2 else (24-j)%24 for i, j in enumerate(d)]

d.sort()

ans = float("Inf")

for i in range(n+1):

    k = abs(d[i-1]-d[i])

    ans = min(ans, min(k, 24-k))

print(ans)
n = int(eval(input()))
a = [0] * 13
for i in map(int, input().split()):
    a[i] += 1
ans = 0
if not (any(i > 2 for i in a) or a[0] or a[12] > 1):
    s = [[0]]
    for i in range(1, 13):
        nxt = []
        if a[i] == 0:
            nxt = s
        elif a[i] == 1:
            for si in s:
                nxt.append(si + [i])
                nxt.append(si + [24 - i])
        else:
            for si in s:
                nxt.append(si + [i, 24 - i])
        s = nxt
    for si in s:
        si.sort()
        tmp = float("Inf")
        for i in range(len(si)):
            k = abs(si[i] - si[i - 1])
            k = min(k, 24 - k)
            tmp = min(tmp, k)
        ans = max(ans, tmp)
print(ans)

n = int(eval(input()))
d = list(map(int, input().split())) + [0]
d.sort()
d = [j if i % 2 else (24 - j) % 24 for i, j in enumerate(d)]
d.sort()
ans = float("Inf")
for i in range(n + 1):
    k = abs(d[i - 1] - d[i])
    ans = min(ans, min(k, 24 - k))
print(ans)

-a = [0] * 13 -for i in map(int, input().split()): -    a[i] += 1 -ans = 0 -if not (any(i > 2 for i in a) or a[0] or a[12] > 1): -    s = [[0]] -    for i in range(1, 13): -        nxt = [] -        if a[i] == 0: -            nxt = s -        elif a[i] == 1: -            for si in s: -                nxt.append(si + [i]) -                nxt.append(si + [24 - i]) -        else: -            for si in s: -                nxt.append(si + [i, 24 - i]) -        s = nxt -    for si in s: -        si.sort() -        tmp = float("Inf") -        for i in range(len(si)): -            k = abs(si[i] - si[i - 1]) -            k = min(k, 24 - k) -            tmp = min(tmp, k) -        ans = max(ans, tmp) +d = list(map(int, input().split())) + [0] +d.sort() +d = [j if i % 2 else (24 - j) % 24 for i, j in enumerate(d)] +d.sort() +ans = float("Inf") +for i in range(n + 1): +    k = abs(d[i - 1] - d[i]) +    ans = min(ans, min(k, 24 - k))