n = int(eval(input()))

d = list(map(int, input().split()))

h = [0]*13

for i in d:

    h[i] += 1



ans = 0

def rec(now, state):

    global ans

    if now == 13:

        state.sort()

        m = float("Inf")

        for i in range(len(state)):

            m = min(m, min(abs(state[i-1]-state[i]), 24-abs(state[i-1]-state[i])))

        ans = max(ans, m)

    elif now == 0:

        if h[now]:

            return

        rec(now+1, state)

    elif now == 12:

        if h[now]==0:

            rec(now+1, state)

        elif h[now]==1:

            state.append(now)

            rec(now+1, state)

    else:

        if h[now]==0:

            rec(now+1, state)

        elif h[now]==1:

            s = state[:]

            s.append(now)

            rec(now+1,s)

            s = state[:]

            s.append(24-now)

            rec(now+1, s)

        elif h[now]==2:

            state.append(now)

            state.append(24-now)

            rec(now+1, state)

rec(0, [0])

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

a = [0]*13

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

    a[i] += 1



ans = 0

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

    pass

else:

    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()))
h = [0] * 13
for i in d:
    h[i] += 1
ans = 0


def rec(now, state):
    global ans
    if now == 13:
        state.sort()
        m = float("Inf")
        for i in range(len(state)):
            m = min(
                m, min(abs(state[i - 1] - state[i]), 24 - abs(state[i - 1] - state[i]))
            )
        ans = max(ans, m)
    elif now == 0:
        if h[now]:
            return
        rec(now + 1, state)
    elif now == 12:
        if h[now] == 0:
            rec(now + 1, state)
        elif h[now] == 1:
            state.append(now)
            rec(now + 1, state)
    else:
        if h[now] == 0:
            rec(now + 1, state)
        elif h[now] == 1:
            s = state[:]
            s.append(now)
            rec(now + 1, s)
            s = state[:]
            s.append(24 - now)
            rec(now + 1, s)
        elif h[now] == 2:
            state.append(now)
            state.append(24 - now)
            rec(now + 1, state)


rec(0, [0])
print(ans)

n = int(eval(input()))
a = [0] * 13
for i in map(int, input().split()):
    a[i] += 1
ans = 0
if any(i > 2 for i in a) or a[0] or a[12] > 1:
    pass
else:
    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)

-d = list(map(int, input().split())) -h = [0] * 13 -for i in d: -    h[i] += 1 +a = [0] * 13 +for i in map(int, input().split()): +    a[i] += 1 - - -def rec(now, state): -    global ans -    if now == 13: -        state.sort() -        m = float("Inf") -        for i in range(len(state)): -            m = min( -                m, min(abs(state[i - 1] - state[i]), 24 - abs(state[i - 1] - state[i])) -            ) -        ans = max(ans, m) -    elif now == 0: -        if h[now]: -            return -        rec(now + 1, state) -    elif now == 12: -        if h[now] == 0: -            rec(now + 1, state) -        elif h[now] == 1: -            state.append(now) -            rec(now + 1, state) -    else: -        if h[now] == 0: -            rec(now + 1, state) -        elif h[now] == 1: -            s = state[:] -            s.append(now) -            rec(now + 1, s) -            s = state[:] -            s.append(24 - now) -            rec(now + 1, s) -        elif h[now] == 2: -            state.append(now) -            state.append(24 - now) -            rec(now + 1, state) - - -rec(0, [0]) +if any(i > 2 for i in a) or a[0] or a[12] > 1: +    pass +else: +    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)