Problem:
 Score : 500 points    Problem Statement 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 .      Constraints  1 \leq N \leq 50  0 \leq D_i \leq 12  All input values are integers.         Input Input is given from Standard Input in the following format:  N  D_1  D_2  ...  D_N       Output Print the maximum possible value of s .        Sample Input 1 3
7 12 8      Sample Output 1 4  For example, consider the situation where it is 7 , 12 and 16 o'clock in each person's city at the moment when it is 0 o'clock in Takahashi's city. In this case, the time gap between the second and third persons' cities is 4 hours.       Sample Input 2 2
11 11      Sample Output 2 2       Sample Input 3 1
0      Sample Output 3 0  Note that Takahashi himself is also a participant.

Solution (Python):

import sys
from collections import deque, defaultdict
import copy
import bisect
sys.setrecursionlimit(10 ** 9)
import math
import heapq
from itertools import product, permutations,combinations
import fractions

import sys
def input():
	return sys.stdin.readline().strip()

N = int(input())
D = list(map(int, input().split()))

times = [0]*13
times[0] = 1
for i in range(N):
	times[D[i]] += 1
	if times[D[i]] == 3:
		print(0)
		exit()
if times[0] > 1 or times[12] > 1:
	print(0)
	exit()

base_time = [0]
add_time = []
for i in range(1, 12):
	if times[i] == 2:
		bisect.insort(base_time, -i)
		bisect.insort(base_time, i)
	elif times[i] == 1:
		add_time.append(i)
if times[12] == 1:
	bisect.insort(base_time, 12)

def min_diff(A):
	min_times = 50
	for i in range(len(A) - 1):
		min_times = min(min_times, A[i + 1] - A[i])
	min_times = min(min_times, A[0] + 24 - A[-1])
	return min_times

if len(add_time) == 0:
	print(min_diff(base_time))
	exit()

ans = 0
for i in range(2**len(add_time)):
	base_time2 = copy.deepcopy(base_time)
	for bit in range(len(add_time)):
		mask = ((2**bit)&i)//(2**bit)
		bisect.insort(base_time2, add_time[bit]*(1 - 2*mask))
	ans = max(ans, min_diff(base_time2))
	

print(ans)

Solution (Python):
def solve(n, d):
    if n >= 24:
        return 0

    cnt = {i: 0 for i in range(12 + 1)}
    cnt[0] = 1
    for dd in d:
        cnt[dd] += 1

    
    
    
    if cnt[0] > 1:
        return 0
    elif cnt[12] > 1:
        return 0
    else:
        for i in range(1, 12):
            if cnt[i] > 2:
                return 0

    bit_cnt = 0
    for i in range(1, 12):
        if cnt[i] == 1:
            bit_cnt += 1

    res = -1
    for mask in range(1 << bit_cnt):
        t = [False] * 24
        t[0] = True

        cur = 0
        for i in range(1, 12):
            if cnt[i] == 1:
                if (mask >> cur) & 1 == 1:
                    t[i] = True
                else:
                    t[24 - i] = True
                cur += 1
            elif cnt[i] == 2:
                t[i] = True
                t[24 - i] = True

        if cnt[12] == 1:
            t[12] = True

        

        dist = 24
        frm = 0
        for i in range(1, 48 + 1):
            if t[i % 24]:
                dist = min(dist, (i - frm) % 24)
                frm = i

        res = max(res, dist)

    return res


if __name__ == '__main__':
    n = int(input())
    d = tuple(map(int, input().split()))

    res = solve(n, d)
    print(res)

Solution (Python):
def solve(n, d):
    if n >= 24:
        return 0

    cnt = {i: 0 for i in range(12 + 1)}
    cnt[0] = 1
    for dd in d:
        cnt[dd] += 1

    
    
    
    if cnt[0] > 1:
        return 0
    elif cnt[12] > 1:
        return 0
    else:
        for i in range(1, 12):
            if cnt[i] > 2:
                return 0

    bit_cnt = 0
    for i in range(1, 12):
        if cnt[i] == 1:
            bit_cnt += 1

    res = -1
    for mask in range(1 << bit_cnt):
        t = [False] * 24
        t[0] = True

        cur = 0
        for i in range(1, 12):
            if cnt[i] == 1:
                if (mask >> cur) & 1 == 1:
                    t[i] = True
                else:
                    t[24 - i] = True
                cur += 1
            elif cnt[i] == 2:
                t[i] = True
                t[24 - i] = True

        if cnt[12] == 1:
            t[12] = True

        

        dist = 24
        frm = 0
        for i in range(1, 48 + 1):
            if t[i % 24]:
                dist = min(dist, (i - frm) % 24)
                frm = i

        res = max(res, dist)

    return res


if __name__ == '__main__':
    n = int(input())
    d = tuple(map(int, input().split()))

    res = solve(n, d)
    print(res)

Solution (Python):
N = int(input())
D = [int(v) for v in input().split(' ')]

D.append(0)
L = len(D)

D.sort()


min_diff = D[1] - D[0]

if L >= 3:
    d = (24 - D[L - 2]) - D[L - 1]
    if min_diff > d:
        min_diff = d

for i in range(2, L):
    d = D[i] - D[i - 2]
    if min_diff > d:
        min_diff = d

print(min_diff)

Solution (Python):
N = int(input())
D = list(map(int, input().split()))
D.sort()

def minGap(hour):
    ret = float('inf')
    for i in range(len(hour)):
        for j in range(len(hour)):
            if i == j:
                continue
            h1 = hour[i]
            h2 = hour[j]
            gap = max(h1, h2) - min(h1, h2)
            ret = min(ret, gap, 24 - gap)
    return ret

hour = [0]
for d in D:
    back = minGap(hour + [d])
    front = minGap(hour + [24 - d])
    if back > front:
        hour += [d]
    else:
        hour += [24 - d]
ans = minGap(hour)

print(ans)

Solution (Python):
N = int(input())
D = list(map(int, input().split()))

def minGap(hour):
    ret = float('inf')
    for i in range(len(hour)):
        for j in range(len(hour)):
            if i == j:
                continue
            h1 = hour[i]
            h2 = hour[j]
            gap = max(h1, h2) - min(h1, h2)
            ret = min(ret, gap, 24 - gap)
    return ret

D.sort()
hour = [0]
for i, d in enumerate(D):
    if i % 2 == 0:
        hour.append(d)
    else:
        hour.append(24 - d)

print(minGap(hour))

Solution (Python):
N=int(input())
D=list(map(int,input().split()))
from collections import defaultdict
dic=defaultdict(int)
for d in D:
    dic[d]+=1
a=[0,24]
f=0
T=[]
for k in dic.keys():
    for i in range(dic[k]):
        T.append(k)
T.sort()
for t in T:
    if f:
        t=24-t
    a.append(t)
    f^=1
a.sort()
r=12
for i in range(len(a)-1):
    r=min(r,a[i+1]-a[i])
print(r)

Solution (Python):
import sys;
input = sys.stdin.readline

def doit():
  n = int(input())
  if n >= 24:
    return 0

  d = [int(x) for x in input().split()]
  if n == 1:
    return d[0]
  
  res = [0] * 13
  for x in d:
    if x == 0:
      return 0
    res[x] += 1;
    if x == 12:
      if res[x] == 2:
        return 0
    if res[x] == 3:
      return 0
  
  
  mm = 12
  flip = False
  prev = [0, 24]
  for i, x in enumerate(res):
    diff = 12
    if x == 2:
      
      diff = i - prev[0]
      prev[0] = i
      prev[1] = 24 - i
      
      flip = not flip
    if x == 1:
      if flip:
        
        diff = i - prev[0]
        prev[0] = i
      else:
        
        diff = prev[1] - (24 - i)
        prev[1] = 24 - i
      flip = not flip
      
    if diff < mm:
      mm = diff
      
  
  last = prev[1] - prev[0]
  
  if last < mm:
    return last
  return mm


print(doit())

Solution (Python):
import sys;
input = sys.stdin.readline

n = int(input())
d = [int(x) for x in input().split()]

def doit():
  if n >= 24:
    return 0
  if n == 1:
    return d[0]
  
  res = [0] * 13
  for x in d:
    if x == 0:
      return 0
    res[x] += 1;
    if x == 12:
      if res[x] == 2:
        return 0
    if res[x] == 3:
      return 0
  
  ban = [False] * 24
  mm = 12
  flip = False
  prev = [0, 24]
  for i, x in enumerate(res):
    diff = 12
    if x == 2:
      ban[i] = ban[24 - i] = True
      diff = i - prev[0]
      prev[0] = i
      prev[1] = 24 - i
      print("x2", i, diff, file=sys.stderr)
      flip = not flip
    if x == 1:
      if flip:
        ban[i] = True
        diff = i - prev[0]
        prev[0] = i
      else:
        ban[24 - i] = True
        diff = prev[1] - (24 - i)
        prev[1] = 24 - i
      flip = not flip
      print("x1", i, diff, file=sys.stderr)
    if diff < mm:
      mm = diff
      print(mm, file=sys.stderr)
  
  last = prev[1] - prev[0]
  print("last", prev[0], prev[1], file=sys.stderr)
  if last < mm:
    return last
  return mm


print(doit())

Solution (Python):
N=int(input())
D=[0]+[int(i) for i in input().split()]

line=[0]*13
clock = [0]*24
tag=0
ans=25
ansL=[]

for i in D:
    line[i%13]+=1

if(line[0]>=2 or line[12]>=2):
    ans=0
else:
    
    for i in range(len(line)):
        if (line[i] > 2):
            ans = 0
            break
        elif (line[i] == 2): 
            clock[i] = 1
            clock[24 - i] = 1
        elif (line[i] == 1):
            if (tag % 2 == 0):
                clock[i] = 1
            else:
                clock[24 - i] = 1
            tag += 1

    
    for i in range(len(clock)):
        if(clock[i]==1):
            ansL.append(i)

    ansL.reverse()
    before = 24
    for i in range(len(ansL)):
        if (ans > before - ansL[i]):
            ans = before - ansL[i]
        before=ansL[i]

print(ans)

Solution (Python):
import sys



def dd_max(ring):
	mm=25
	s=1
	for r in ring[1:]:
		
		if r >= 1:
			mm=min(s,mm)
			s=1
		else:
			s+=1
	return mm
	
		
def main():
	n = int(input())
	dl = list(map(int, input().split()))
	dl.append(0)
	
	
	if dl.count(0) >=2:
		return 0
	
	if dl.count(12) >=2:
		return 0
	
	for i in range(1,11+1):
		if dl.count(i) >= 3:
			return 0
	
	ll=[0]*25
	ll[0]=1
	ll[24]=1
	cc=[]
	if dl.count(12) == 1:
		ll[12]=1
	for i in range(1,11+1):
		if dl.count(i)==2:
			ll[i]=1
			ll[24-i]=1
		if dl.count(i)==1:
			cc.append(i)
			
	if len(cc)==0:
		print(dd_max(ll))
		
		return 
	
	
	ret=0
	n_cc=len(cc)
	cc_max=(2**n_cc)-1
	for i in range(cc_max):
		tll=ll.copy()
		for j,v in enumerate(cc):
			if i & (2**j) > 0:
				tll[24-v]=1
			else:
				tll[v]=1
				
		tr=dd_max(tll)
		ret=max(ret, tr)
	
	print(ret)
	
	

isTest=False

def pa(v):
	if isTest:
		print(v)

if __name__ == "__main__":
	if sys.platform =='ios':
		sys.stdin=open('inputFile.txt')
		isTest=True
	else:
		pass
		
			
	ret = main()
	if ret is not None:
		print(ret)

Solution (Python):
_,d=open(0);s=sorted;l=s((x,24-x)[i%2]for i,x in enumerate(s(map(int,d.split()))));print(min(j-i for i,j in zip([0]+l,l)))

Solution (Python):
_,d=open(0);s=sorted;l=s((24-x,x)[i%2]for i,x in enumerate([0]+s(map(int,d.split()))));print(min(j-i for i,j in zip([0]+l,l)))

Solution (Python):
_,d=open(0);s=sorted;l=s((24-x,x)[i%2]for i,x in enumerate(s(map(int,d.split()))));print(min(j-i for i,j in zip([0]+l,l+[24])))

Solution (Python):
_,d=open(0);s=sorted;l=s([(24-x,x)[i%2]for i,x in enumerate(s(map(int,d.split())))]);print(min(j-i for i,j in zip([0]+l,l+[24])))

Solution (Python):
N=int(input())
D =[0]+[int(x) for x in input().split()]
m=D[1]
D.sort()
for i in range(1,N+1):
  D[i]=D[i] if i&1 else 24-D[i]
D.sort()
for i in range(1,N+1):
  m= min(m,D[i]-D[i-1])
print(m)

Solution (Python):
N,*D=map(int,open(0).read().split())
T=[0]+sorted(d if i%2 else (24-d)%24 for i,d in enumerate(sorted(D)))+[24]
print(min(a-b for a,b in zip(T[1:],T)))

Solution (Python):
N, *D = map(int, open(0).read().split())
D.sort()
T = [0] + sorted(d if i % 2 else (24 - d) % 24 for i, d in enumerate(D)) + [24]
print(min(T[i + 1] - T[i] for i in range(N + 1)))

Solution (Python):
N, *D = map(int, open(0).read().split())
D.append(0)
D.sort()
T = [0] * 24
for i, d in enumerate(D):
    if i % 2 == 0 and d % 12 != 0:
        d = 24 - d
    T[d] += 1
if any(t >= 2 for t in T):
    print(0)
    quit()
T = [i for i, t in enumerate(T) if t != 0] + [24]
print(min(T[i + 1] - T[i] for i in range(len(T) - 1)))

Solution (Python):
_,d=open(0);s=sorted;l=[0]+s([[24-x,x][i%2]for i,x in enumerate(s(map(int,d.split())))])+[24];print(min(j-i for i,j in zip(l,l[1:])))

Solution (Python):
_,d=open(0);s=sorted;l=[0]+s([x if i%2else 24-x for i,x in enumerate(s(map(int,d.split())))])+[24];print(min(j-i for i,j in zip(l,l[1:])))

Solution (Python):
n,*d=map(int,open(0).read().split());s=sorted
l=[0]+s([x if i%2 else 24-x for i,x in enumerate(s(d))])+[24]
print(min(j-i for i,j in zip(l,l[1:])))

Solution (Python):
n,*d=map(int,open(0).read().split())
if 0 in d or d.count(12)>1 or any(d.count(x)>2 for x in range(1,12)) or n>24:
	print(0)
elif n>11:
	print(1)
else:
	m=0
	for i in range(2**n):
		l=[0,24]
		for j in range(n):
			if i>>j&1:
				l.append(24-d[j])
			else:
				l.append(d[j])
		l.sort()
		m=max(m,min(j-i for i,j in zip(l,l[1:])))
	print(m)

Solution (Python):
import sys
import heapq
import bisect

mod = 10**9+7
dd = ((-1,0),(1,0),(0,-1),(0,1))

def I(): return(int(sys.stdin.readline()))
def LI(): return([int(x) for x in sys.stdin.readline().split()])
def S(): return(sys.stdin.readline()[:-1])
def IR(n): return([I() for _ in range(n)])

def GCD(a,b):
    while b!=0:
        a,b = b,a%b
    return a

def LCM(a,b):
    return a * b // GCD(a,b)

def main():
    N = I()
    D = LI()

    pigeon = [0] * 13

    for d in D:
        pigeon[d] += 1

    if pigeon[0] >= 1:
        return 0
    if pigeon[12] >=2:
        return 0
    for i in range(1,12):
        if pigeon[i] >= 3:
            return 0

    if N > 11:
        return 1

    Time = [[0,24] for _ in range(2**N)]

    ans = 0
    for x in range(2**N):
        for i in range(N):
            if (x>>i)%2:
                Time[x].append(D[i])
            else:
                Time[x].append(24-D[i])
        Time[x].sort()
        ans = max(ans,min([a-b for a,b in zip(Time[x][1:],Time[x][:-1])]))

    return(ans)

if __name__ == "__main__":
    print(main())

Solution (Python):
import copy

def minTG(TG):
    indexes1 = [i for i, x in enumerate(TG) if x == 1]
    indexes2 = [i for i, x in enumerate(TG) if x == 2]
    TG24 = [1] + [0] * 23    
    if 12 in indexes1:
        indexes1.pop(-1)
        TG24[12] = 1
    for i in indexes1 + indexes2:
        TG24[i], TG24[24-i] = 1, 1
    
    ans = 0
    for i in range(2**len(indexes1)):
        TG24c = copy.copy(TG24)
        bit = i
        for j in range(len(indexes1)):
            if bin(bit>>(j+1))[-1] == '1':
                TG24c[indexes1[j]] = 0
            else:
                TG24c[24 - indexes1[j]] = 0
        temp = minTG_search(TG24c)
        if ans < temp:  ans = temp
    return ans

def minTG_search(TG24):
    s, temp, i = 24, 0, 1
    while i < 24:
        if TG24[i] == 1:
            if i - temp < s:
                s = i - temp
            temp = i
        i += 1
    if 24 - temp < s:
        s = 24 - temp
    return s

N = int(input())
D = sorted(list(map(int, input().split())))
TG = [0] * 13
for i in range(N):
    TG[D[i]] += 1

if TG[0] > 0 or max(TG) > 2:
    print(0)
else:
    print(minTG(TG))

Solution (Python):
N = int(input())
D = list(map(int, input().split()))

T = [0 for _ in range(13)]

for d in D:
    if d > 12:
        T[24-d] += 1
    else:
        T[d] += 1

which = []
A = []
ans = -1
for i, t in enumerate(T):
    if t == 0:
        continue
    elif t == 1:
        which.append(i)
    elif t == 2:
        A.extend([i, 24-i])
    else:
        ans = 0
        break

def dfs(which, i, l, p):
    if i == len(which):
        p.append(l)
        return p
    t = which[i]
    p = dfs(which, i+1, l+[t], p)
    p = dfs(which, i+1, l+[24-t], p)
    return p

if ans == 0:
    print(0)
else:
    p = dfs(which, 0, [], [])
    
    ans = 0
    for l in p:
        B = sorted(l+A)
        pre = 0
        tmp = 100
        for b in B:
            tmp = min(tmp, b-pre)
            pre = b
        tmp = min(tmp, 24-pre)
        ans = max(ans, tmp)
    print(ans)

Solution (Python):



import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
D = LI()
D.sort()
a = D[:]
b = D[:]
if n == 1:
    print(D[0])
    quit()
for i in range(n):
    if i % 2:
        continue
    a[i] = 24 - a[i]
a.sort()
for i in range(n):
    if i % 2:
        b[i] = 24 - b[i]
b.sort()
d = [0] + a + [24]
ans1 = inf
for i in range(n+1):
    ans1 = min(ans1,d[i+1] - d[i])
d = [0] + b + [24]
ans2 = inf
for i in range(n+1):
    ans2 = min(ans2,d[i+1] - d[i])
print(max(ans1,ans2))

Solution (Python):
N = int(input())
D = [int(x) for x in input().split()]
D.sort()
d = D[0]
D = [(d * (-1) ** i) % 24 for i, d in enumerate(D)]
D.sort()
for i in range(N - 1):
  d = min(D[i + 1] - D[i], d)
print(d)

Solution (Python):
n = int(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)

Solution (Python):
n = int(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)

Solution (Python):
n = int(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)

Solution (Python):
n = int(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)

Solution (Python):
N = int(input())
D = list(map(int, input().split()))
D.sort()

hour = [0]

for i, d in enumerate(D):
    if i % 2 == 0:
        hour.append(d)
    else:
        hour.append(24 - d)

ans = float('inf')
for i in range(N + 1):
    for j in range(i + 1, N + 1):
        ti = hour[i]
        tj = hour[j]
        ti, tj = ti - min(ti, tj), tj - min(ti, tj)
        gap = max(ti, tj)
        ans = min(ans, gap, 24 - gap)

print(ans)

Solution (Python):
n,t=open(0)
n=int(n)+1
d=[t if i%2else(24-t)%24for i,t in enumerate([0]+sorted(map(int,t.split())))]
print(min(abs(d[i]-d[j])for i in range(n)for j in range(i+1,n)))

Solution (Python):
n,t=open(0)
n=int(n)+1
d=[t if i%2else(24-t)%24for i,t in enumerate([0]+sorted(map(int,t.split())))]
print(min(abs(d[i]-d[j])for i in range(n)for j in range(i+1,n)))

Solution (Python):

N = int(input())
D = list(map(int,input().split()))

D.sort()
left = 0
flag = 0
cir = [0 for i in range(24)]
for i in range(N):
    if D[i] == 0 or D[i] == 12:
        cir[D[i]] += 1
        if cir[D[i]] == 2:
            flag = 1
            break
    else:
        if left == 0:
            cir[D[i]]+=1
            left = 1
            if cir[D[i]] == 2:
                flag = 1
                break
        else:
            cir[24-D[i]]+=1
            left = 0
            if cir[24-D[i]] == 2:
                flag = 1
                break
                
if flag == 1:
    print(0)
else:
    MIN = 12
    point = [0]
    for i in range(24):
        if cir[i] == 1:
            point.append(i)
    point.append(0)
    
    for i in range(len(point)-1):
        MIN = min(MIN,abs(point[i+1]-point[i]))
    print(MIN)

Solution (Python):
import math, string, itertools, fractions, heapq, collections, re, array, bisect, copy, functools, random
import sys
from collections import deque, defaultdict, Counter; from heapq import heappush, heappop
from itertools import permutations, combinations, product, accumulate, groupby
from bisect import bisect_left, bisect_right, insort_left, insort_right
from operator import itemgetter as ig
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20; INF = float("INF"); ans = 0; tmp = 0; cnt = 0; ansli = []; tmpli = []; candili = []; stillset = set()
eps = 1.0 / 10 ** 10; mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]; ddn = dd + [(-1, 1), (1, 1), (1, -1), (-1, -1)]; ddn9 = ddn + [(0, 0)]
"""for dx, dy in dd:
        nx = j + dx; ny = i + dy
            if 0 <= nx < w and 0 <= ny < h:"""
def wi(): return list(map(int, sys.stdin.readline().split()))
def wip(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def ws(): return sys.stdin.readline().split()
def i(): return int(sys.stdin.readline())
def s(): return input()
def s_list(): return list(input())
def hi(n): return [i() for _ in range(n)]
def hs(n): return [s() for _ in range(n)]
def mi(n): return [wi() for _ in range(n)]
def num_grid(n): return [[int(i) for i in sys.stdin.readline().split()[0]] for _ in range(n)]
def mip(n): return [wip() for _ in range(n)]
def ms(n): return [ws() for _ in range(n)]
def grid(n): return [s_list() for _ in range(n)]

n = i()
d = wi()

time = [[] for _ in range(13)]

for t in d:
    time[t].append(t)

for idx, kosu in enumerate(time):
    if len(kosu) >= 3:
        print(0)
        exit()

if n > 11:
    if len(time[0]) >= 1 or len(time[12]) > 1:
        print(0)
        exit()
    else:
        print(1)
        exit()

time = functools.reduce(lambda a, b: a + b, time)
ans = INF; A = 0

for ti in itertools.product([0, 1], repeat=len(time)):  
    kyu = []
    for kk in range(len(ti)):
        if ti[kk] == 0:
            kyu.append(time[kk])
        else:
            kyu.append(24 - time[kk])
    kyu.append(0)

    for k in itertools.combinations(kyu, 2):  
        ans = min(ans, abs(k[0] - k[1]), 24 - abs(k[0] - k[1]))
    A = max(ans, A)
    ans = INF  
print(A)

Solution (Python):
import math, string, itertools, fractions, heapq, collections, re, array, bisect, copy, functools, random
import sys
from collections import deque, defaultdict, Counter; from heapq import heappush, heappop
from itertools import permutations, combinations, product, accumulate, groupby
from bisect import bisect_left, bisect_right, insort_left, insort_right
from operator import itemgetter as ig
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20; INF = float("INF"); ans = 0; tmp = 0; cnt = 0; ansli = []; tmpli = []; candili = []; stillset = set()
eps = 1.0 / 10 ** 10; mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]; ddn = dd + [(-1, 1), (1, 1), (1, -1), (-1, -1)]; ddn9 = ddn + [(0, 0)]
"""for dx, dy in dd:
        nx = j + dx; ny = i + dy
            if 0 <= nx < w and 0 <= ny < h:"""
def wi(): return list(map(int, sys.stdin.readline().split()))
def wip(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def ws(): return sys.stdin.readline().split()
def i(): return int(sys.stdin.readline())
def s(): return input()
def s_list(): return list(input())
def hi(n): return [i() for _ in range(n)]
def hs(n): return [s() for _ in range(n)]
def mi(n): return [wi() for _ in range(n)]
def num_grid(n): return [[int(i) for i in sys.stdin.readline().split()[0]] for _ in range(n)]
def mip(n): return [wip() for _ in range(n)]
def ms(n): return [ws() for _ in range(n)]
def grid(n): return [s_list() for _ in range(n)]

n = i()
d = wi()

time = [[] for _ in range(13)]

for t in d:
    time[t].append(t)

for idx, kosu in enumerate(time):
    if len(kosu) >= 3:
        print(0)
        exit()

if n > 11:
    if len(time[0]) >= 1 or len(time[12]) > 1:
        print(0)
        exit()
    else:
        print(1)
        exit()

time = functools.reduce(lambda a, b: a + b, time)
ans = INF; A = 0

for ti in itertools.product([0, 1], repeat=len(time)):  
    kyu = []
    for kk in range(len(ti)):
        if ti[kk] == 0:
            kyu.append(time[kk])
        else:
            kyu.append(24 - time[kk])
    kyu.append(0)

    for k in itertools.combinations(kyu, 2):  
        ans = min(ans, abs(k[0] - k[1]), 24 - abs(k[0] - k[1]))
    A = max(ans, A)
    ans = INF  
print(A)

Solution (Python):
s=[0]*24
s[12]=1
n=int(input())
a=list(map(int,input().split()))
d=[a.count(i)for i in range(13)]
d[0]+=1
if max(d[0],d[12])<2 and max(d[1:-1])<3:
    if d[12]==1:
        s[0]=1
    t=[]
    for i in range(1,12):
        if d[i]==2:
            s[12-i]=1
            s[12+i]=1
        elif d[i]==1:
            t.append(i)
    k=0
    for i in range(2**len(t)):
        p=bin(i)[2:]
        p="0"*(len(t)-len(p))+p
        r=s[:]
        for j in range(len(t)):
            if p[j]=="0":
                r[12-t[j]]=1
            else:
                r[12+t[j]]=1
        h=0
        q=0
        ans=30
        for j in 2*r:
            if j==1:
                if h==0:
                    q=1
                    h=1
                else:
                    ans=min(q,ans)
                    q=1
            else:
                q+=1
        k=max(ans,k)
    print(k)
else:
    print(0)

Solution (Python):
n=int(input())
arr=list(map(int,input().split()))
cnt=[0]*13
cnt[0]=1
ans=0
for val in arr:
  cnt[val]+=1
flag=True
for i in range(13):
  if i==0 or i==12:
    if cnt[0]>=2:
      flag=False
      break
  else:
    if cnt[i]>=3:
      flag=False
      break
if flag==False:
  print(0)
else:
  ans=0
  base=[0]*24
  base[0]=1
  if cnt[12]!=0:
    base[12]=1
  for i in range(2**11):
    pos=base[:]
    bit=format(i,'b')
    if len(bit)!=11:
      bit='0'*(11-len(bit))+bit
    for j in range(1,12):
      if cnt[j]==0:
        continue
      elif cnt[j]==2:
        pos[j]=1
        pos[24-j]=1
      else:
        if bit[j-1]=='0':
          pos[j]=1
        else:
          pos[24-j]=1
    tmp=10**10
    for j in range(24):
      if pos[j]==0:
        continue
      for k in range(1,24):
        if pos[(j+k)%24]==1:
          tmp=min(tmp,k)
          break
    ans=max(ans,tmp)
  print(ans)

Solution (Python):
n=int(input())
arr=list(map(int,input().split()))
arr=sorted(arr)
pos=[0]*24
pos[0]=1
flag=0
for val in arr:
  if flag==0:
    pos[val]+=1
    flag=1
  else:
    pos[(24-val)%24]+=1
    flag=0
ans=10**10
for i in range(24):
  if pos[i]>=2:
    ans=0
    break
  elif pos[i]==1:
    for j in range(1,24):
      if pos[(i+j)%24]>=1:
        ans=min(ans,j)
        break
  else:
    continue    
print(ans)

Solution (Python):
n=int(input())
d=[int(i) for i in input().split()]
d.sort()
a=1
ans=[]

def dif(lout,lin):
    lo=[i for i in lout]
    li=[i for i in lin]
    if li:
        x=li.pop()
        if x in li:
            li.remove(x)
            lo.append(x)
            lo.append(24-x)
            dif(lo,li)
        else:
            dif(lo+[x],li)
            dif(lo+[24-x],li)
    else:
        pre=0
        rt=24
        lo=sorted(lo)+[24]
        for i in lo:
            rt=min(i-pre,rt)
            pre=i
        ans.append(abs(rt))
        return

for i in range(12+1):
    if d.count(i)>2:
        a=0
if 0 in d:
    a=0
if d.count(12)>=2:
    a=0

if a==0:
    print(0)
else:
    dif([],d)
    print(max(ans))

Solution (Python):
from collections import Counter

N = int(input())
D = list(map(int, input().split()))

if N > 23:
    print(0)
elif N > 11:
    D.append(0)
    D_count = Counter(D)
    if D_count.most_common()[0][1] > 2:
        print(0)
    else:
        print(1)
else:
    ans = 0
    for i in range(2 ** (N - 1)):
        bit = '0' + bin(i)[2:].zfill(N - 1)
        D_mod24 = [0] * N
        for j in range(N):
            if bit[j] == '0':
                D_mod24[j] = D[j]
            else:
                D_mod24[j] = 24 - D[j]
        D_mod24.sort()
        ans_temp = min(min(D_mod24), 24 - max(D_mod24))
        for j in range(N-1):
            ans_temp = min(ans_temp, D_mod24[j+1] - D_mod24[j])
        ans = max(ans, ans_temp)
    print(ans)

Solution (Python):
from itertools import product, combinations


N = int(input())
D = list(map(int, input().split()))



ans = (
    0 if N >= 24 else
    int(
        (0 not in D) and
        (D.count(12) <= 1) and
        all(
            D.count(i) <= 2
            for i in range(1, 12)
        )
    ) if 12 <= N < 24 else
    max(
        min(
            min(abs(a - b), 24 - abs(a - b))
            for a, b in combinations(t, 2)
        )
        for t in (
            product(
                (0,),
                *(
                    (d, 24 - d)
                    for d in D
                )
            )
        )
    )
)


print(ans)

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
a.sort()
b = [0]
c = [0]
for i in range(n):
    if i%2:
        b.append(a[i])
        c.append((24-a[i])%24)
    else:
        c.append(a[i])
        b.append((24-a[i])%24)
b.sort()
c.sort()
mn1=24
mn2=24
for i in range(n):
    mn1 = min(mn1,b[i+1]-b[i])
    mn2 = min(mn2,c[i+1]-c[i])
mn1 = min(mn1,b[0]+24-b[-1])
mn2 = min(mn2,c[0]+24-c[-1])
print(max(mn1,mn2))