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.



Sample input:
3
7 12 8


Sample output:
4

Submission status: Runtime Error

Solution code:
#n>=25なら鳩ノ巣で0
#2人以上居るdは一意
#あとはしらみつぶし

n = int(input())
if n>=25:
    print(0)
    exit()

d = list(map(int, input().split( )))
if 0 in d:##
    print(0)
    exit()
d.append(0)
dic = {}

for di in d:
    if di in dic:
        dic[di] += 1
    else:
        dic[di]= 1
solo = []
times = []
for di in dic:
    if dic[di]==1:#di=0はここに入る
        solo.append(di)
    elif dic[di]==2:
        times.append(di)
        times.append(24-di)
    else:
        print(0)
        exit()
        
ans = 0
m = len(solo)
bit = 1<<m

for i in range(bit):
    times2 = []
    for t in times:
        times2.append(t)
    for j in range(m):
        if i>>j&1:
            times2.append(solo[j])
        elif solo[j]:
            times2.append(24-solo[j])
    times2.sort()
    dif = 24
    if len(times2)==1:###
        print(0)
        exit()
    #print(times2)

    for k in range(len(times2)-1):
        dif = min(dif,times2[k+1]-times2[k])
    dif = min(dif,times[0] + 24 - times[-1])
    ans = max(ans,dif)
print(ans)

Submission status: Runtime Error

Solution code:
#n>=25なら鳩ノ巣で0
#2人以上居るdは一意
#あとはしらみつぶし
#周期性考慮せよ
n = int(input())
if n>=25:
    print(0)
    exit()

d = list(map(int, input().split( )))
if 0 in d:##
    print(0)
    exit()
d.append(0)
dic = {}

for di in d:
    if di in dic:
        dic[di] += 1
    else:
        dic[di]= 1
solo = []
times = []
for di in dic:
    if dic[di]==1:#di=0はここに入る
        solo.append(di)
    elif dic[di]==2:
        times.append(di)
        times.append(24-di)
    else:
        print(0)
        exit()
        
ans = 0
m = len(solo)
bit = 1<<m

for i in range(bit):
    times2 = []
    for t in times:
        times2.append(t)
    for j in range(m):
        if i>>j&1:
            times2.append(solo[j])
        elif solo[j]:
            times2.append(24-solo[j])
    times2.sort()
    dif = 24
    if len(times2)==1:###
        print(0)
        exit()
    #print(times2)

    for k in range(len(times2)-1):
        dif = min(dif,times2[k+1]-times2[k])
    dif = min(dif, 24 + times [0] -times2[-1])
    ans = max(ans,dif)
print(ans)

Submission status: Runtime Error

Solution code:
#n>=25なら鳩ノ巣で0
#2人以上居るdは一意
#あとはしらみつぶし

n = int(input())
if n>=25:
    print(0)
    exit()

d = list(map(int, input().split( )))
if 0 in d:##
    print(0)
    exit()
d.append(0)
dic = {}

for di in d:
    if di in dic:
        dic[di] += 1
    else:
        dic[di]= 1
solo = []
times = []
for di in dic:
    if dic[di]==1:#di=0はここに入る
        solo.append(di)
    elif dic[di]==2:
        times.append(di)
        times.append(24-di)
    else:
        print(0)
        exit()
        
ans = 0
m = len(solo)
bit = 1<<m

for i in range(bit):
    times2 = []
    for t in times:
        times2.append(t)
    for j in range(m):
        if i>>j&1:
            times2.append(solo[j])
        elif solo[j]:
            times2.append(24-solo[j])
    times2.sort()
    dif = 24
    if len(time2)==1:###
        print(0)
        exit()
    #print(times2)

    for k in range(len(times2)-1):
        dif = min(dif,times2[k+1]-times2[k])
    ans = max(ans,dif)
print(ans)

Submission status: Runtime Error

Solution code:
#n>=25なら鳩ノ巣で0
#2人以上居るdは一意
#あとはしらみつぶし

n = int(input())
if n>=25:
    print(0)
    exit()

d = list(map(int, input().split( )))
if 0 in d:##
    print(0)
    exit()
d.append(0)
dic = {}

for di in d:
    if di in dic:
        dic[di] += 1
    else:
        dic[di]= 1
solo = []
times = []
for di in dic:
    if dic[di]==1:#di=0はここに入る
        solo.append(di)
    elif dic[di]==2:
        times.append(di)
        times.append(24-di)
    else:
        print(0)
        exit()
        
ans = 0
m = len(solo)
bit = 1<<m

for i in range(bit):
    times2 = []
    for t in times:
        times2.append(t)
    for j in range(m):
        if i>>j&1:
            times2.append(solo[j])
        elif solo[j]:
            times2.append(24-solo[j])
    times2.sort()
    dif = 24
    if not len(time2):###
        print(0)
        exit()
    #print(times2)

    for k in range(len(times2)-1):
        dif = min(dif,times2[k+1]-times2[k])
    ans = max(ans,dif)
print(ans)

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda:sys.stdin.readline().rstrip()
def resolve():
    n=int(input())
    D=[int(input()) for _ in range(n)]

    V=100000
    dp=[0]*(V+1)
    for d in D:
        dp[d]+=1

    for j in range(3):
        for i in range(V):
            dp[i+1]+=dp[i]
        ndp=[0]*(V+1)
        for d in D:
            ndp[d]+=dp[d//2]
        dp=ndp

    print(sum(dp)%MOD)
resolve()

Submission status: Runtime Error

Solution code:
def examC():
    N = I(); D = LI()
    ans = -1
    d = defaultdict(int); d[0] +=1
    choice = [0]*13; choice[0] +=1
    for i in D:
        choice[i] +=1
        if choice[i]>2:
            ans = 0
            break
    if choice[0]>=2 or choice[12]>=2:
        ans = 0
#    print(choice)
    curT = [0]; cur = []
    for i in range(1,12):
        if choice[i]==1:
            cur.append(i)
        elif choice[i]==2:
            curT.append(i)
            curT.append(24-i)
        elif choice>=3:
            ans = 0
    ne = Counter(choice)
    if choice[12]==1:
        ne[1] -=1
        curT.append(12)
    loop = 2**(ne[1]-1)
#    print(loop)
    if ans==0:
        print(ans)
        exit()
    ans = 0
    for i in range(loop):
        now = copy.deepcopy(curT); ansC = 12
        for j in range(ne[1]-1):
            if i&(1<<j)==1:
                now.append(cur[j])
            else:
                now.append(12+cur[j])
        now.sort()
        for k in range(len(now)):
            if k != len(now) - 1:
                ansC = min(ansC, now[k + 1] - now[k], 24 - (now[k + 1] - now[k]))
            else:
                ansC = min(ansC, now[k], 24 - now[k])
        ans = max(ans, ansC)
    print(ans)
    return

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

if __name__ == '__main__':
    examC()

Submission status: Runtime Error

Solution code:
import sys
import heapq
input = sys.stdin.readline
N = int(input())
d = list(map(int, input().split()))
rres = 0
if N == 1:
  print(d[1])
  exit(0)
for t in range(13):
  res = True
  q = sorted(d)
  heapq.heapify(q)
  l = [0, 24]
  i = 0
  c = 0
  while len(q) and c < 2 * N ** 2:
    p = heapq.heappop(q)
    if abs(p - l[i]) < t:
      heapq.heappush(q, 24 - p)
    else:
      i += 1
      l.append(p)
      l.sort()
    c += 1
  if c >= 2 * N ** 2:
    res = False
  l.sort()
  for i in range(1, len(l)):
    if abs(l[i - 1] - l[i]) < t:
      res = False
      break
  #print(l)
  if res:
    rres = t
  else:
    break
 #print(res, t)
print(rres)

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline
N = int(input())
d = [0] + list(map(int, input().split()))
rres = 0
if N == 1:
  print(d[1])
  exit(0)
for t in range(13):
  res = True
  l = sorted(d)
  nl = sorted(d)
  for _ in range(N + 1):
    l.sort()
    for i in range(N):
      if abs(l[i] - l[i + 1]) < t:
        nl.append(24 - l[i + 1])
        nl.remove(l[i + 1])
    if abs(l[0] - l[-1]) < t:
      nl.append(24 - l[-1])
      nl.remove(l[-1])
    nl.sort()
    l = nl
  for i in range(N):
    if abs(nl[i] - nl[i + 1]) < t:
      res = False
  if abs(nl[-1] - nl[0]) < t:
    res = False
  if res:
    rres = t
    #print(nl)
  else:
    break
 #print(res, t)
print(rres)

Submission status: Runtime Error

Solution code:
n=int(input())
d=list(map(int,input().split()))
if n>=24:
    print(0)
    exit()
op=[[0],[1]]
for i in range(n-1):
    tmp=[]
    for j in op:
        tmp.append(j+[0])
        tmp.append(j+[1])
    op=tmp
ans=0
for i in op:
    t=[0]
    for j in range(n):
        if i[j]==0:
            t.append(d[i])
        else:
            t.append(24-d[i])
    a=10000
    for p in range(1+n):
        for q in range(1+n):
            if p>q:
                b=abs(t[p]-t[q])
                a=min(a,min(b,24-b))
    ans=max(ans,a)
print(ans)

Submission status: Runtime Error

Solution code:
from collections import Counter
n = int(input())
d = list(map(int,input().split())) + [0]

data = Counter(d).most_common()
if data[0][1] >= 3:
    print(0)
    exit()
ans = 0
#print(data)
for bit in range(2**11):
    this_time = []
    for x,c in data:
        if c == 2:
            if x == 0 or x == 12:
                print(0)
                exit()
            this_time.append(x)
            this_time.append(24-x)
        else:
            if bit>>(x-1) & 1 or x == 0 or x == 12:
                this_time.append(x)
            else:
                this_time.append(24-x)
    #print(this_time)
    ans_now = 20
    m = len(this_time)
    for  i in range(m):
        for j in range(i+1,m):
            ans_now = min(ans_now,abs(this_time[i]-this_time[j]))
    ans = max(ans,ans_now)

print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np

N = int(input())
D = list(map(int, input().split()))
if N > 23:
    print(0)
    exit()
for i in range(13):
    if D.count(i) >= 3:
        print(0)
        exit()
for i in range(13)
    elif D.count(i) == 2 and D.count(i+1) >= 1:
        print(1)
        exit()

# 深さ優先探索で全通りを探索できるのでは curは０からスタート
def dfs(cur, times):
    global answer
    if cur == N:
        times.sort()
        arr = np.array(times)
        result = (arr[1:] - arr[:-1]).min()
        if result > answer:
            answer = result
    else:
        x = D[cur]
        dfs(cur+1, times + [x])
        dfs(cur+1, times + [24-x])

answer = 0
dfs(0, [0, 24])
print(answer)

Submission status: Runtime Error

Solution code:
import sys
import collections
def input():
    return sys.stdin.readline()[:-1]
inf=float("inf")

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

c=collections.Counter(d)
if c.most_common()[0][1]>2:
    print(0)
    quit()
if 0 in c:
    if c[0]==1:
        print(0)
        quit()

li=list(map(int,c.keys()))
li.append(0)
ans=0
for i in range(2**len(li)):
    hour=[]
    for j in range(len(li)):
        if c[li[j]]==2:
            hour.append(li[j])
            hour.append(24-li[j])
            break
        if i&(1<<j):
            hour.append(li[j])
        else:
            hour.append(24-li[j])

    hour.sort()
    # print(hour)
    tmp=24+hour[0]-hour[-1]
    for j in range(len(li)-1):
        tmp=min(tmp,hour[j+1]-hour[j])
    # print(tmp)
    ans=max(ans,tmp)
print(ans)

Submission status: Runtime Error

Solution code:
import sys
import collections
def input():
    return sys.stdin.readline()[:-1]
inf=float("inf")

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

c=collections.Counter(d)
if c.most_common()[0][1]>2:
    print(0)
    quit()
if 0 in c:
    if c[0]==1:
        print(0)
        quit()

li=list(map(int,c.keys()))

ans=0
for i in range(2**len(li)):
    hour=[]
    for j in range(len(li)):
        if c[li[j]]==2:
            hour.append(li[j])
            hour.append(24-li[j])
            break
        if i&(1<<j):
            hour.append(li[j])
        else:
            hour.append(24-li[j])
    hour.sort()
    # print(hour)
    tmp=24+hour[0]-hour[-1]
    for j in range(len(li)-1):
        tmp=min(tmp,hour[j+1]-hour[j])
    ans=max(ans,tmp)
print(ans)

Submission status: Runtime Error

Solution code:
import sys
import collections
def input():
    return sys.stdin.readline()[:-1]
inf=float("inf")

n=int(input())
d=list(map(int,input().split()))
d.append(0)
d.append(12)
c=collections.Counter(d)
if c.most_common()[0][1]>2:
    print(0)
    quit()
if 0 in c:
    if c[0]==2:
        print(0)
        quit()
if 12 in c:
    if c[12]==2:
        print(0)
        quit()
li=list(map(int,c.keys()))

ans=0
for i in range(2**len(li)):
    hour=[]
    for j in range(len(li)):
        if c[li[j]]==2:
            hour.append(li[j])
            hour.append(24-li[j])
            break
        if i&(1<<j):
            hour.append(li[j])
        else:
            hour.append(24-li[j])
    hour.sort()
    # print(hour)
    tmp=24+hour[0]-hour[-1]
    for j in range(len(li)-1):
        tmp=min(tmp,hour[j+1]-hour[j])
    ans=max(ans,tmp)
print(ans)

Submission status: Runtime Error

Solution code:
import sys
import collections
def input():
    return sys.stdin.readline()[:-1]
inf=float("inf")

n=int(input())
d=list(map(int,input().split()))
d.append(0)
c=collections.Counter(d)
if c.most_common()[0][1]>2:
    print(0)
    quit()
if 0 in c:
    if c[0]==2:
        print(0)
        quit()
if 12 in c:
    if c[12]==2:
        print(0)
        quit()
li=list(map(int,c.keys()))

ans=0
for i in range(2**len(li)):
    hour=[]
    for j in range(len(li)):
        if c[li[j]]==2:
            hour.append(li[j])
            hour.append(24-li[j])
            break
        if i&(1<<j):
            hour.append(li[j])
        else:
            hour.append(24-li[j])
    hour.sort()
    # print(hour)
    tmp=24+hour[0]-hour[-1]
    for j in range(len(li)-1):
        tmp=min(tmp,hour[j+1]-hour[j])
    ans=max(ans,tmp)
print(ans)

Submission status: Runtime Error

Solution code:
import sys
import collections
def input():
    return sys.stdin.readline()[:-1]
inf=float("inf")

n=int(input())
d=list(map(int,input().split()))
d.append(0)
c=collections.Counter(d)
if c.most_common()[0][1]>2:
    print(0)
    quit()
if 0 in c:
    if c[0]==2:
        print(0)
        quit()
if 12 in c:
    if c[12]==2:
        print(0)
        quit()
li=list(map(int,c.keys()))

ans=0
for i in range(2**len(li)):
    hour=[]
    for j in range(len(li)):
        if c[li[j]]==2:
            hour.append(li[j])
            hour.append(24-li[j])
            break
        if i^(1<<j):
            hour.append(li[j])
        else:
            hour.append(24-li[j])
    hour.sort()

    tmp=24+hour[0]-hour[-1]
    for j in range(len(li)-1):
        tmp=min(tmp,hour[j+1]-hour[j])
    ans=max(ans,tmp)
print(ans)

Submission status: Runtime Error

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

diff = [0]*13
D.sort()
for i in range(N):
    diff[D[i]] += 1

if diff[0] > 0:
    print(0)
    exit(0)
else:
    diff2 = [diff[12 - i] for i in range(1, N-1)]

for i in range(13):
    if diff[i] > 2:
        print(0)
        exit(0)

ans = [0]
ans = [D[i]
       for i in range(N) if i % 2 == 0] + [24 - D[i] for i in reversed(range(N)) if i % 2 == 1]

ans = [abs(ans[i+1] - ans[i]) for i in range(N-1)]

print(min(ans))

Submission status: Runtime Error

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

diff = [0]*13
D.sort()
for i in range(N):
    diff[D[i]] += 1

if diff[0] > 0:
    print(0)
    exit(0)
else:
    diff2 = [diff[12 - i] for i in range(1, N-1)]

for i in range(13):
    if diff[i] > 2:
      print(0)
      exit(0)

ans = [0]
for i in range(N):
    if i % 2 == 0:
        ans.append(D[i])
    else:
        ans.append(24 - D[i])

ans = [abs(ans[i+1] - ans[i]) for i in range(N-1)]

print(min(ans))

Submission status: Runtime Error

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

diff = [0]*13
D.sort()
for i in range(N):
    diff[D[i]] += 1

if diff[0] > 0:
    print(0)
    exit(0)
else:
    diff2 = [diff[12 - i] for i in range(1, N-1)]

for i in range(13):
    if diff[i] > 2:
    print(0)
    exit(0)

ans = [0]
for i in range(N):
    if i % 2 == 0:
        ans.append(D[i])
    else:
        ans.append(24 - D[i])

ans = [abs(ans[i+1] - ans[i]) for i in range(N-1)]

print(min(ans))

Submission status: Runtime Error

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

diff = [0]*13
D.sort()
for i in range(N):
    diff[D[i]] += 1
    if diff[i] > 2:
        print(0)
        exit(0)
if diff[0] > 0:
    print(0)
    exit(0)
else:
    diff2 = [diff[12 - i] for i in range(1, N-1)]

ans = [0]
for i in range(N):
    if i % 2 == 0:
        ans.append(D[i])
    else:
        ans.append(24 - D[i])

ans = [abs(ans[i+1] - ans[i]) for i in range(N-1)]

print(min(ans))

Submission status: Runtime Error

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

diff = [0]*13
# D.sort()
for i in range(N):
    diff[D[i]] += 1
    if diff[i] > 2:
        print(0)
        exit(0)
if diff[0] > 0:
    print(0)
    exit(0)
else:
    diff2 = [diff[12 - i] for i in range(1, N-1)]

ans = [0]
for i in range(N):
    if i % 2 == 0:
        ans.append(D[i])
    else:
        ans.append(24 - D[i])

ans = [abs(ans[i+1] - ans[i]) for i in range(N-1)]

print(min(ans))

Submission status: Runtime Error

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

diff = [0]*13
# D.sort()
for i in range(N):
    diff[D[i]] += 1
    if diff[i] > 2:
        print(0)
        exit(0)
if diff[0] > 0:
    print(0)
    exit(0)
else:
    diff2 = [diff[12 - i] for i in range(1, N-1)]

ans = []
for i in range(N):
    if i % 2 == 0:
        ans.append(D[i])
    else:
        ans.append(24 - D[i])

ans = [abs(ans[i+1] - ans[i]) for i in range(N-1)]

print(min(ans))

Submission status: Runtime Error

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

ans = []
for i in range(N):
    if i % 2 == 0:
        ans.append(D[i])
    else:
        ans.append(24 - D[i])

ans = [abs(ans[i+1] - ans[i]) for i in range(N-1)]

print(min(ans))

Submission status: Runtime Error

Solution code:
s=[0]*25
s[11]=1
d=[0]*13
d[0]+=1
n=int(input())
a=list(map(int,input().split()))
d=[a.count(i)for i in range(12)]
if max(d[0],d[12])<2 and max(d[1:12])<3:
    if d[12]==1:
        s[0]=1
        s[-1]=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(s**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
        r=2*r
        h=0
        q=0
        ans=0
        for j in 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)

Submission status: Runtime Error

Solution code:
s=[0]*25
s[11]=1
d=[0]*13
n=int(input())
a=list(map(int,input().split()))
d=[a.count(i)for i in range(12)]
if max(d[0],d[12])<2 and max(d[1:12])<3:
    if d[12]==1:
        s[0]=1
        s[-1]=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(s**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
        r=2*r
        h=0
        q=0
        ans=0
        for j in 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)

Submission status: Runtime Error

Solution code:
s=[0]*25
s[11]=1
d=[0]*13
n=int(input())
a=list(map(int,input().split()))
d=[a.count(i)for i in range(12)]
if max(d[0],d[12])<2 and max(d[1:12])<3:
    if d[12]==1:
        s[0]=1
        s[-1]=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(s**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
        r=2*r
        h=0
        q=0
        ans=0
        for j in r:
            if j==1:
                if h==0:
                    q=0
                    h=1
                else:
                    ans=min(q,ans)
                    q=0
            else:
                q+=1
        k=max(ans,k)
    print(k)
else:
    print(0)

Submission status: Runtime Error

Solution code:
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <numeric>
#include <bitset>

using namespace std;
using ll = long long;
using ld = long double;
const ll mod =  1000000007;

#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define REP_FROM(i, j, n) for (ll i = (j); i < (n); ++i)
#define all(x) (x).begin(),(x).end()

ll power(ll base, ll exponent, ll module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ ll root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
ll inverse(ll x){ return power(x, mod - 2, mod);}
ll gcd(ll a, ll b) {if(a < b) gcd(b, a);ll r;while(r=a%b) {a=b;b=r;}return b;}
struct combination{ vector<ll> fact, inv; combination(int sz) : fact(sz + 1), inv(sz + 1){ fact[0] = 1; for(int i = 1; i <= sz; i++){ fact[i] = fact[i - 1] * i % mod; } inv[sz] = power(fact[sz], mod - 2, mod); for(int i = sz - 1; i >= 0; i--){ inv[i] = inv[i + 1] * (i + 1) % mod; } } ll C(int p, int q) const{ if(q < 0 || p < q) return 0; return (fact[p] * inv[q] % mod * inv[p - q] % mod); } };




signed main() {
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  map<int, int> d;
  d[24] = 1;
  REP(i, n) {
    int x;
    cin >> x;
    if(d.count(x) > 0) {
      d[x]++;
    }
    else {
      d[x] = 1;
    }
  }
  if(d.count(0) > 0  || (d.count(12) ? d[12] :0) > 1) {
    cout << 0 << endl;
    return 0;
  }
  REP(i, 24) {
    // cout << (d.count(i) ? d[i] :0) << " ";
    if((d.count(i) ? d[i] :0) > 2) {
      cout << 0 << endl;
      return 0;
    }
  }
  // cout << endl;
  ll ans = 0;
  REP(i, 1<<24) {
    bool valid = true;
    if(d.count(0) == 0 && i % 2 == 1) {
      continue;
    }
    REP_FROM(j, 1, 12) {
      int cnt = (d.count(j) ? d[j] :0);
      bool lft = i & (1 << j);
      bool rgt = i & (1 << (24-j));
      if(cnt == 0 ) {
        if(lft || rgt) {
          valid = false;
          break;
        }
      }
      if(cnt == 1) {
        if(lft ^ rgt) {
        }
        else {
          valid = false;
          break;
        }
      }
      if(cnt > 1) {
        if(lft && rgt) {
        }
        else {
          valid = false;
          break;
        }
      }
    }
    {
      bool cnt = d.count(12);
      if((i & (1 << 12)) > 0 != cnt) {
        valid = false;
      }
    }
    if(valid) {
      ll tmp = 100;
      ll lft = 0;
      REP(j, 24) {
        if(i & 1 << j) {
          tmp = min(tmp, j - lft);
          lft = j;
        }
      }
      tmp = min(tmp, 24 - lft);
      // cout << bitset<64>(i) << endl;
      // cout << tmp << endl;
      ans = max(ans, tmp);
    }
  }
  cout << ans << endl;
  return 0;
}

Submission status: Runtime Error

Solution code:
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
    
#print(t)
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]
    #print(T)
    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(10):
        if A[i]==[]:
            A[i]=[0,0]
    #print(A)
    
    MAX=0
    for i in range(2**10+1):
        S=copy.deepcopy(T)
        for j in range(11):
            if (i//(2**(9-j)))==1:
                S[A[j][1]]=1
            else:
                S[A[j][0]]=1
        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(L)
            #print(S)
    print(MAX)

Submission status: Runtime Error

Solution code:
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
    
#print(t)
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]
    #print(T)
    A=[[]for i in range(10)]
    for i in range(1,12):
        if t[i]==1:
            A[i-1]=[i,24-i]
    for i in range(10):
        if A[i]==[]:
            A[i]=[0,0]
    #print(A)
    
    MAX=0
    for i in range(2**10+1):
        S=copy.deepcopy(T)
        for j in range(10):
            if (i//(2**(9-j)))==1:
                S[A[j][1]]=1
            else:
                S[A[j][0]]=1
        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(L)
            #print(S)
    print(MAX)

Submission status: Runtime Error

Solution code:

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

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

def check(i):
    return False

def get_close(l,d=0):
    return