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 copy
N=int(input())

t=[0 for i in range(13)]
T=[0 for i in range(25)]
T[0]=1
T[24]=1

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

for i in range(N):
    t[D[i]]+=1
    

if t[0]>=1 or t[12]>=2 or max(t)>=3:
    print(0)
else:
    for i in range(len(t)):
        if t[i]==2:
            T[i]=1
            T[24-i]=1
    T[12]=t[12]
    
    A=[[]for i in range(11)]
    for i in range(1,12):
        if t[i]==1:
            A[i-1]=[i,24-i]
    for i in range(11):
        if A[i]==[]:
            A[i]=[0,0]
    
    
    MAX=0
    for i in range(2**11+1):
        S=copy.deepcopy(T)
        I=i
        for j in range(11):
            if (I//(2**(10-j)))==1:
                S[A[j][1]]=1
            else:
                S[A[j][0]]=1
            I%=(2**(10-j))
        L=100
        P=0
        for k in range(1,25):
            if S[k]==1:
                if L>(k-P):
                    L=(k-P)
                P=k
        if L>MAX:
            MAX=L
            
            
    print(MAX)

Solution (Python):
N=int(input())
D=[0]+sorted(map(int,input().split()))

B=[0]*13
for d in D:B[d]+=1
ans=1
if max(B)>2 or max(B[0],B[12])>1:ans=0
if ans>0:
    v1=[]
    v2=[0]
    if B[12]==1:v2.append(12)
    for i,b in enumerate(B[1:-1],1):
        if b==1:v1.append(i)
        elif b==2:v2.append(i);v2.append(24-i)

    l=len(v1)
    for i in range(1<<l):
        v3=v2[:]
        for j,v in enumerate(v1):
            if i&(1<<j):
                v3.append(24-v)
            else:
                v3.append(v)
        tmp=24
        for v in v3:
            for vv in v3:
                if v==vv:continue
                tmp = min(tmp,abs(v-vv),24-abs(v-vv))
        ans = max(ans,tmp)
print(ans)

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

ans = 0
for s in range(0,13):
    Q = [-s,-s]
    ok = 1
    for d in D:
        if Q[0]+s <= d <= 24 - Q[1]-s:
            Q[0] = d
        elif Q[1]+s <= d <= 24 - Q[0] - s:
            Q[1] = d
        else:
            ok = 0
    if ok:
        ans = s

print(min(ans,min(D)))

Solution (Python):
from itertools import product
n = int(input())
d = [int(i) for i in input().split()]
if 0 in d or 23<n: ans = 0
elif n<12:
    ans = 0
    for i in product((0,1),repeat=n):
        x = [0,24]
        for j in range(n):
            if i[j]: x.append(d[j])
            else: x.append(24-d[j])
        x,num = sorted(x),24
        for j in range(n+1): num = min(num,x[j+1]-x[j])
        ans = max(ans,num)
else:
    d+=[0]
    f = 1
    for i in range(1,13):
        if d.count(i)>2: f = 0
    if f: ans = 1
    else: ans = 0
print(ans)

Solution (Python):


import sys
from collections import Counter
from copy import copy

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N=INT()
D=LIST()

L=[0]

C=Counter(D)
S=[]
for k, v in C.items():
    if v>=3:
        print(0)
        exit()
    elif v>=2:
        L.append(k)
        L.append(24-k)
    else:
        S.append(k)

mx=0
for i in range(1<<len(S)):
    L2=copy(L)
    for j in range(len(S)):
        if i>>j&1:
            L2.append(S[j])
        else:
            L2.append(24-S[j])
    L2.sort()
    L2=L2+[l+24 for l in L2]
    mn=INF
    for i in range(1, len(L2)):
        mn=min(mn, abs(L2[i-1]-L2[i])%24)
    mx=max(mx, mn)
print(mx)

Solution (Python):
import sys
from collections import deque
import copy
import math
def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline

def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [N] = [long(input_raw[0])]
    input_raw = read_func().strip().split()
    D = []
    for i in range(N):
        D.append(long(input_raw[i]))

    D.sort()

    D_ = []
    flag = False
    for i in range(N):
        if flag == False:
            D_.append(D[i])
            flag = True
        else:
            D_.append(24 - D[i])
            flag = False

    min_score = sys.maxint
    for i in range(N):
        for j in range(i + 1, N):
            min_score = min(min_score, abs(D_[i] - D_[j]))

    for i in range(N):
        min_score = min(min_score, D[i])

    print min_score


if __name__ == '__main__':
    main()

Solution (Python):
N = int( input())
D = list( map( int, input().split()))
D.sort()
ans = 24
c = 1
A = []
B = []
now = 0
for i in range(N):
    if D[i] == now:
        c += 1
    if c == 2:
        ans = 0
    if i%2 == 0:
        A.append(D[i])
    else:
        B.append(D[i])
s = 0
if A:
    for a in A:
        ans = min(ans, a-s)
        s = a
s = 0
if B:
    for b in B:
        ans = min(ans, b-s)
        s=b
if A and B:
    ans = min( ans, 24-A[-1]-B[-1], A[-1]+B[-1])
print(ans)

Solution (Python):
def solve(n, ds):
    if n >= 24: return 0
    if max([ds.count(v) for v in range(13)]) >= 3:
        return 0
    if ds.count(0) > 0: return 0
    if ds.count(12) > 1: return 0
    if n >= 12: return 1
    
    res = 0
    for mask in range(1<<n):
        pos = ds[::]
        s = 24
        for i in range(n):
            if mask & 1<<i:
                pos[i] = 24 - pos[i]
        pos.append(0)
        for i in range(len(pos)):
            for j in range(i):
                s = min(s, abs(pos[i] - pos[j]), 24 - abs(pos[i] - pos[j]))
        res = max(res, s)
    return res

n = int(input())
ds = list(map(int, input().split()))
print(solve(n, ds))

Solution (Python):
n = int(input()) + 1
ds = [0] + sorted(map(int, input().split()))
for i in range(0, n, 2):
    ds[i] = (24 - ds[i]) % 24
print(min(abs(ds[i]-ds[j]) for i in range(n) for j in range(i+1, n)))

Solution (Python):
import sys
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt, ceil, floor
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
INF = float("inf")
sys.setrecursionlimit(10**7)


dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]


def inside(y: int, x: int, H: int, W: int) -> bool: return 0 <= y < H and 0 <= x < W


def main():
    N = int(input())
    D = list(map(int, input().split()))
    c = [0] * 13
    c[0] = 1
    for d in D:
        c[d] += 1
    if max(c) >= 3 or c[0] >= 2 or c[12] >= 2:
        print(0)
        return

    ans = 0
    
    n = 11  
    for b in range(2 ** n):
        a = [0]
        if c[12]:
            a.append(12)

        for i in range(n):
            d = i + 1
            if c[d] == 0:
                continue
            elif c[d] == 2:
                a += [d, 24 - d]
            elif b & 1 << i:
                a.append(d)
            else:
                a.append(24 - d)
        a.sort()
        mini = INF
        for i in range(len(a) - 1):
            mini = min(mini, abs(a[i] - a[i + 1]))
        mini = min(mini, abs(24 - a[-1]))

        ans = max(ans, mini)
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
import itertools

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

if any((D+[0,0,12]).count(i) >2 for i in range(0,13)):
    print(0)
    exit(0)


l= [0]
if D.count(12):
    l.append(12)

can_select=[]
for i in range(1,12):
    if (D).count(i) ==2:
        l.append((i))
        l.append((24 - i))

    if D.count(i)==1:
        can_select.append(i)

def change12(v):
    return min(24-v,v)

def get_closest(l):
    min_val =24
    for i in range(len(l)-1):
        min_val= min(change12(l[i+1]-l[i]),min_val)

    return min(change12(l[-1] - l[0]),min_val )

tmp_ans=0
for seed in list(itertools.product(range(2), repeat=len(can_select))):
    tmp_list = list(l)
    for i,val in enumerate(can_select):
        if seed[i]==1:
            tmp_list.append(val)
        else:
            tmp_list.append(24-val)
    tmp_list.sort()
    tmp_ans =max(tmp_ans, get_closest(tmp_list))



print(tmp_ans)

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

ans = 0
for k in range(0, 13):
    Q = [-k, -k]
    ok = 1
    for d in D:
        if Q[0]+k <= d <= 24-Q[1]-k:
            Q[0] = d
        elif Q[1]+k <= d <= 24-Q[0]-k:
            Q[1] = d
        else:
            ok = 0
    if ok:
        ans = k
print(min(ans, min(D)))