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: Wrong Answer

Solution code:
def ans_is_zero():
    print(0)
    exit(0)

def solve():
    n=int(input())
    if n > 23: ans_is_zero()

    d=list(map(int,input().split()))
    for num in d:
        if num == 0: ans_is_zero()

    ans=0

    N = 1 << n
    for i in range(N):#left or right
        t=1
        ret = 100
        for j in range(n):
            if (i>>j)&1: num = d[j]
            else: num = 24 - d[j]

            if (t >> num)&1:
                ret = -1
                break
        if ret == -1:
            continue

        if bin(t).count("1") < n + 1:#重複あり
            continue

        prev = 0
        for j in range(1, 24):
            if ((t>>j)&1) == 0: continue
            ret = min(ret, j - prev)
            prev = j

        ret = min(ret, 24-prev)
        ans = max(ans, ret)
    print(ans)
solve()

Submission status: Wrong Answer

Solution code:
n=int(input())
d=list(map(int,input().split()))
ans=0
for i in range(2**n):
    time=[]
    for j in range(n):
        if (i>>j)&1:
            time.append(d[j])
        else:
            time.append((24-d[j])%24)
    time=[0]+time
    time.sort()
    mini=10**18
    for j in range(n):
        mini=min(mini,time[j+1]-time[j])
    ans=max(ans,mini)
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
d=list(map(int,input().split()))
ans=0
for i in range(2**n):
    time=[]
    for j in range(n):
        if (i>>j)&1:
            time.append(d[j])
        else:
            time.append(24-d[j])
    time=[0]+time
    time.sort()
    mini=10**18
    for j in range(n):
        mini=min(mini,time[j+1]-time[j])
    ans=max(ans,mini)
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
d=list(map(int,input().split()))
if n>=24 or 0 in d:
    print(0)
else:
    ans=0
    for i in range(2**n):
        time=[]
        for j in range(n):
            if (i>>j)&1:
                time.append(d[j])
            else:
                time.append(24-d[j])
        time=[0]+time
        time.sort()
        mini=10**18
        for j in range(n):
            mini=min(mini,time[j+1]-time[j])
        ans=max(ans,mini)
    print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
d=list(map(int,input().split()))
if n>=24 or 0 in d:
    print(0)
else:
    d=[0]+d
    ans=0
    for i in range(2**(n+1)):
        time=[]
        for j in range(n+1):
            if (i>>j)&1:
                time.append(d[j])
            else:
                time.append((24-d[j])%24)
        time.sort()
        mini=10**18
        for j in range(n):
            mini=min(mini,time[j+1]-time[j])
        ans=max(ans,mini)
    print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
d=[0]+list(map(int,input().split()))
if n>=25:
    print(0)
else:
    ans=0
    for i in range(2**(n+1)):
        time=[]
        for j in range(n+1):
            if (i>>j)&1:
                time.append(d[j])
            else:
                time.append((24-d[j])%24)
        time.sort()
        mini=10**18
        for j in range(n):
            mini=min(mini,time[j+1]-time[j])
        ans=max(ans,mini)
    print(ans)

Submission status: Wrong Answer

Solution code:
import sys
input=sys.stdin.buffer.readline
inputs=sys.stdin.buffer.readlines
sys.setrecursionlimit(10**9)
n=int(input())
from collections import Counter as co
ds=co(list(map(int,input().split() ))+[0]).most_common()
if ds[0][1]>3:print(0)
else:
    nows=[]
    nexts=[]
    for k,v in ds:
        if v==1:nexts.append(k)
        else:
            nows.append(-k)
            nows.append(k)
    def f(k):
        res=24
        for i in range(len(k)-1):
            for j in range(i+1,len(k)):
                #x y  0 y-x 
                res=min(res,-abs(k[i]-k[j])%24 ,abs(k[i]-k[j])%24)
        return res
    from itertools import product as pr
    print(max(f(nows+[v*j  for v,j in zip(nexts,i)])for i in pr((1,-1),repeat=len(ds))))

Submission status: Wrong Answer

Solution code:
import sys
input=sys.stdin.buffer.readline
inputs=sys.stdin.buffer.readlines
sys.setrecursionlimit(10**9)
n=int(input())
from collections import Counter as co
ds=co(list(map(int,input().split() ))+[0]).most_common()
if ds[0][1]>3:print(0)
else:
    nows=[]
    nexts=[]
    for k,v in ds:
        if v==1:nexts.append(k)
        else:
            nows.append(-k)
            nows.append(k)
    def f(k):
        res=24
        for i in range(len(k)-1):
            for j in range(i+1,len(k)):
                #x y  0 y-x 
                res=min(res,24-abs(k[i]-k[j])%24 ,abs(k[i]-k[j])%24)
        return res
    from itertools import product as pr
    print(max(f(nows+[v*j  for v,j in zip(nexts,i)])for i in pr((1,-1),repeat=len(ds))))

Submission status: Wrong Answer

Solution code:
import sys
input=sys.stdin.buffer.readline
inputs=sys.stdin.buffer.readlines
sys.setrecursionlimit(10**9)
n=int(input())
from collections import Counter as co
ds=co(list(map(int,input().split() ))+[0]).most_common()
if ds[0][1]>3:print(0)
else:
    nows=[]
    for k,v in ds:
        if v==1:break
        nows.append(-k)
        nows.append(k)
    ds=list(f for f,z in ds)
    ds.reverse()
    if nows:
        ds=ds[:-len(nows)//2]
    def f(k):
        res=24
        for i in range(len(k)-1):
            for j in range(i+1,len(k)):
                #x y  0 y-x 
                res=min(res,24-abs(k[i]-k[j])%24 ,abs(k[i]-k[j])%24)
        return res
    from itertools import product as pr
    print(max(f(nows+[v*j  for v,j in zip(ds,i)])for i in pr((1,-1),repeat=len(ds))))

Submission status: Wrong Answer

Solution code:
def main():
    import itertools
    n = int(input())
    d = list(map(int,input().split()))
    d.sort()
    ans = [0] * 25
    ans[0] = 1
    for i in range(n):
        if d[i]==0:
            ans[0] += 1
        elif i%2==0:
            ans[24-d[i]] += 1
        else:
            ans[d[i]] += 1
    p = []
    for i in range(25):
        if ans[i]>1:
            print(0)
            return
        if ans[i]==1:
            p.append(i)
    ans = float('inf')
    for cb in itertools.combinations(p,2):
        if ans>abs(cb[0]-cb[1]):
            ans = abs(cb[0]-cb[1])
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
def main():
    import itertools
    n = int(input())
    d = list(map(int,input().split()))
    time = [0] * 13
    for i in range(n):
        time[d[i]] += 1
    ans = [0] * 25
    ans[0] += 1
    for i in range(13):
        if time[i]>2:
            print(0)
            return
        if time[i]==1:
            ans[i] += 1
        elif time[i]==2:
            ans[i] += 1
            ans[24-i]+=1
    if max(ans)>1:
        print(0)
        return
    p = []
    for i in range(25):
        if ans[i]==1:
            p.append(i)
    ans = float('inf')
    for cb in itertools.combinations(p,2):
        if abs(cb[0]-cb[1])<ans:
            ans = abs(cb[0]-cb[1])
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
def main():
    import itertools
    n = int(input())
    d = list(map(int,input().split()))
    time = [0] * 13
    time[0] = 1
    for i in range(n):
        time[d[i]] += 1
    ans = 0
    A = [0 for i in range(13)]
    for i in range(13):
        A[i] = min(24-2*i,2*i)
    for i in range(13):
        if time[i]>1:
            ans = A[i]
    for p in itertools.product([-1,1],repeat=13):
        m = float('inf')
        for c in itertools.combinations(range(13),2):
            if time[c[0]]==0 or time[c[1]]==0:
                continue
            if p[c[0]]==-1:
                a = 24-c[0]
            else:
                a = c[0]
            if p[c[1]]==-1:
                b = 24-c[1]
            else:
                b = c[1]
            if min(abs(a-b),24-abs(a-b))<=m:
                m = min(abs(a-b),24-abs(a-b))
        if m>ans:
            ans = m
    for i in range(13):
        if time[i]==2:
            if ans>A[i]:
                ans = A[i]
        if time[i]>2:
            ans = 0
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
def main():
    import itertools
    n = int(input())
    d = list(map(int,input().split()))
    time = [0] * 13
    time[0] = 1
    for i in range(n):
        time[d[i]] += 1
    ans = 0
    A = [0 for i in range(13)]
    for i in range(13):
        A[i] = min(24-2*i,2*i)
    for p in itertools.product([-1,1],repeat=13):
        m = float('inf')
        for c in itertools.combinations(range(13),2):
            if time[c[0]]==0 or time[c[1]]==0:
                continue
            if p[c[0]]==-1:
                a = 24-c[0]
            else:
                a = c[0]
            if p[c[1]]==-1:
                b = 24-c[1]
            else:
                b = c[1]
            if min(abs(a-b),24-abs(a-b))<=m:
                m = min(abs(a-b),24-abs(a-b))
        if m>ans:
            ans = m
    for i in range(13):
        if time[i]>1:
            if ans>A[i]:
                ans = A[i]
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
n=int(input())
d=list(map(int,input().split()))
d.sort()
t=[0]
for i,x in enumerate(d):
    if x==0:t.append(0)
    elif i%2:t.append(x)
    else:t.append(24-x)
t.sort()
ans=12
for i in range(1,n+1):
    ans=min(ans,t[i]-t[i-1])
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
d=list(map(int,input().split()))
d.sort()
t=[0]
for i,x in enumerate(d):
    if i%2:t.append(x)
    else:t.append(24-x)
t.sort()
ans=12
for i in range(1,n):
    ans=min(ans,t[i]-t[i-1])
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
d = list(map(int, input().split()))
ans = 0
def dfs(time_set,index):
    # print("{} {}".format(time_set, index))
    if len(time_set) >= n:
        time_list = list(time_set)
        time_list.sort()
        cand = min(time_list[-1] - time_list[0], 24 + time_list[0] - time_list[-1])
        global ans
        for i in range(1,n):
            cand = min(cand, time_list[i] - time_list[i-1])
        ans = max(ans, cand)
    elif index < n:
        time1, time2 = d[index], 24 - d[index]
        if time1 not in time_set:
            dfs(time_set | {time1}, index+1)
        if time2 not in time_set:
            dfs(time_set | {time2}, index+1)
dfs(set(),0)
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
d = list(map(int, input().split()))
ans = 0
def dfs(time_set,index):
    # print("{} {}".format(time_set, index))
    if len(time_set) >= n:
        time_list = list(time_set)
        time_list.sort()
        cand = 30
        global ans
        for i in range(1,n):
            cand = min(cand, time_list[i] - time_list[i-1])
        ans = max(ans, cand)
    elif index < n:
        time1, time2 = d[index], 24 - d[index]
        if time1 not in time_set:
            dfs(time_set | {time1}, index+1)
        if time2 not in time_set:
            dfs(time_set | {time2}, index+1)
dfs(set(),0)
if ans == 30:
    print(0)
else:
    print(ans)

Submission status: Wrong Answer

Solution code:
import collections
from collections import deque
N=int(input())
D=list(map(int,input().split()))
c=collections.Counter(D)
count0=0
count12=0
l=[]
if c[12]>0:
    count12=1
if c[0]>0:
    count0=1
#print(l,count0,count12)
#print(n)
allmax=0
q=deque()
l=[]
q.append([0])
q.append([24])
if (count0==1):
    q=deque()
    q.append([0,0])
    q.append([0,24])
    q.append([24,24])
for i in range(1,12):
    length=len(q)
    j=0
    if c[i]==0: continue
    if c[i]==1:
        while j<length:
            buf1=[]
            buf2=[]
            l=q.popleft()
            buf1.extend(l)
            buf1.append(i)
            buf2.extend(l)
            buf2.append(24-i)
            q.append(buf1)
            q.append(buf2)
            j=j+1
    if c[i]>1:
        while j<length:
            buf1=[]
            buf2=[]
            buf3=[]
            l=q.popleft()
            buf1.extend(l)
            buf1.extend([i,i])
            buf2.extend(l)
            buf2.extend([24-i,24-i])
            buf3.extend(l)
            buf3.extend([i,24-i])
            q.append(buf1)
            q.append(buf2)
            q.append(buf3)
            j=j+1
    #print(q)
    #input()
if count12==1:
    length=len(q)
    j=0
    while j<length:
        buf1=[]
        l=q.popleft()
        buf1.extend(l)
        l.append(12)
        q.append(l)
        j=j+1
#print(q)
for l in q:
    l.sort()
    mi=100
    n=len(l)
    for j in range(n-1):
        mi=min(mi,l[j+1]-l[j],24-l[j+1]+l[j])
    mi=min(mi,l[n-1]-l[0],24-l[n-1]+l[0])
    #print(mi)
    allmax=max(allmax,mi)
print(allmax)

"""
for i in range(pow(2,n)):
    buf=[0]
    bit=[0]*n
    mi=100
    if count12==1:
        buf.append(12)
    buf.append(0)
    for j in range(n):
        if (i>>j)&1:
            bit[j]=1
    #print(bit)
    for j in range(n):
        buf.append(l[j][bit[j]])
    buf.sort()
    buf.append(24)
    #print(buf)
    for j in range(len(buf)-1):
        mi=min(mi,buf[j+1]-buf[j])
    allmax=max(allmax,mi)
print(allmax)
"""

Submission status: Wrong Answer

Solution code:
from itertools import product
from collections import Counter
N=int(input())
D=list(map(int, input().split()))
res=0
if max(Counter(D).values())>2:print(0);exit()
if N>13:print(1);exit()
for b in product(*((d,24-d) for d in D)):
    d0, m= 0,1<<30
    for d in sorted(b):
        m=min((d-d0),24-(d-d0),m)
        d0=d
    m=min(24-d0,m)
    res = max(res,m)
print(res)

Submission status: Wrong Answer

Solution code:
from itertools import product
from collections import Counter
N=int(input())
D=list(map(int, input().split()))
res=0
if max(Counter(D).values())>2:print(0);exit()
if N>13:print(1);exit()
for b in product(*((d,24-d) for d in D)):
    d0, m= 0,1<<30
    for d in sorted(b):
        m=min((d-d0),24-(d-d0),m)
        d0=d
    res = max(res,m)
print(res)

Submission status: Wrong Answer

Solution code:
from itertools import product
from collections import Counter
N=int(input())
D=list(map(int, input().split()))
res=0
if max(Counter(D).values())>2:print(0);exit()
if N>13:print(1);exit()
for b in product(*((d,24-d) for d in D)):
    d0, m= 0,1<<30
    for d in sorted(b):
        m=min((d-d0)%24,m)
        d0=d
    res = max(res,m)
print(res)

Submission status: Wrong Answer

Solution code:
from itertools import product
from collections import Counter
N=int(input())
D=list(map(int, input().split()))
res=0
if max(Counter(D).values())>2:print(0);exit()
for b in product(*((d,24-d) for d in D)):
    d0, m= 0,1<<30
    for d in sorted(b):
        m=min((d-d0)%24,m)
        d0=d
    res = max(res,m)
print(res)

Submission status: Wrong Answer

Solution code:
from collections import Counter
import marshal
N = int(input())
D = Counter(list(map(int, input().split())))
P = [[0]]
for i in range(13):
    if D.get(i,0) == 0:
        continue
    if D.get(i,0) == 1:
        Q = marshal.loads(marshal.dumps(P))
        for p in P:
            p.append(i)
        for q in Q:
            q.append(24-i)
        P += Q
    if D.get(i,0) == 2:
        for p in P:
            p.append(i)
            p.append(24-i)
    if D.get(i,0) >= 3:
        print(0)
        exit()
res = 0
for p in P:
    m = float("inf")
    for i in range(len(p)):
        for j in range(i+1,len(p)):
            if abs(p[i]-p[j])==24:
                m=0
            else:
                m = min(abs(p[i]-p[j]),m)
    res = max(m,res)
print(res)

Submission status: Wrong Answer

Solution code:
from collections import Counter
import marshal
N = int(input())
D = Counter(list(map(int, input().split())))
P = [[0]]
for i in range(13):
    if D.get(i,0) == 0:
        continue
    if D.get(i,0) == 1:
        Q = marshal.loads(marshal.dumps(P))
        for p in P:
            p.append(i)
        for q in Q:
            q.append(24-i)
        P += Q
    if D.get(i,0) == 2:
        for p in P:
            p.append(i)
            p.append(24-i)
    if D.get(i,0) == 3:
        print(0)
        exit()
res = 0
for p in P:
    m = float("inf")
    for i in range(len(p)):
        for j in range(i+1,len(p)):
            if abs(p[i]-p[j])==24:
                m=0
            else:
                m = min(abs(p[i]-p[j]),m)
    res = max(m,res)
print(res)

Submission status: Wrong Answer

Solution code:
from itertools import product
N = int(input())
D = list(map(int,input().split()))
max2 = lambda x,y: x if x > y else y
min2 = lambda x,y: x if x < y else y

def solve():
    if N >= 24:
        return 0

    cnt = [0]*13
    for d in D:
        cnt[d] += 1

    if cnt[0] > 0 or any(c > 2 for c in cnt):
        return 0

    if N > 10:
        return 1

    res = 0
    for p in product(*((d, 24-d) for d in D)):
        p = [0]+sorted(p)
        r = min(b-a for a,b in zip(p,p[1:]))
        res = max2(res,r)
    return res

print(solve())

Submission status: Wrong Answer

Solution code:
N = int(input())
D = list(map(int, input().split()))
P = []
for i in range(N):
    for j in range(i+1,N):
        P.append(max(abs(D[i]-D[j]), abs(D[i]-(24-D[j]))))
for i in range(N):
    P.append(D[i])
print(min(P))

Submission status: Wrong Answer

Solution code:
N = int(input())
N += 1
D = list(map(int, input().split()))
D += [0]
P = []
for i in range(N):
    for j in range(i+1,N):
        P.append(max(abs(D[i]-D[j]), abs(D[i]-(24-D[j]))))
res = min(P)
print(res if res!=24 else 0)

Submission status: Wrong Answer

Solution code:
from collections import Counter
from copy import deepcopy


def solve(c_d):
    one = []
    all_d = []
    for i in range(13):
        if c_d[i] >= 3:
            return 0
        elif c_d[i] == 2:
            all_d.append(i)
            all_d.append(24 - i)
        elif c_d[i] == 1:
            one.append(i)
    ans = 0
    for i in range(1 << len(one)):
        now = deepcopy(all_d)
        for j in range(len(one)):
            if (i >> j) & 1:
                now.append(one[j])
            else:
                now.append(24 - one[j])
        now_ans = float("inf")
        for j in range(len(now)):
            for k in range(j + 1, len(now)):
                now_ans = min(now_ans, abs(now[j] - now[k]))
        ans = max(ans, now_ans)
    return min(ans, 24 - ans)


def main():
    n = int(input())
    d = list(map(int, input().split()))
    d.append(0)
    print(solve(Counter(d)))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
I,a,i=input,24,int;n=i(I());d=[0]+[24]+list(map(i,I().split()));d.sort()
for j in range(1,n+1,2):d[j]=24-d[j]
for j in range(n+1):a=min(a,abs(d[j+1]-d[j]))
print(a)

Submission status: Wrong Answer

Solution code:
import bisect
import collections
import copy
import functools
import heapq
import math
import sys
from collections import deque
from collections import defaultdict
from fractions import Fraction
input = sys.stdin.readline
sys.setrecursionlimit(10**9)
INF = float("inf")
MOD = 10**9+7

N = int(input())
A = list(map(int,input().split()))
d = defaultdict(int)

if 0 in A:
    print(0)
    exit()

for i in range(N):
    d[A[i]] += 1

T = [0]
W = []
for k in d.keys():
    if d[k] >= 2:
        T.append(k)
        T.append(24-k)
    else:
        W.append(k)
#print(T,W)

ans = []

w = len(W)
K = 2 # 選択肢の数
for i in range(K**w):
    TF=[0]*w

    for j in range(w):
        TF[w-j-1] = i % K
        i //= K
    
    l = copy.deepcopy(T)
    for j in range(w):
        if TF[j] == 1:
            l.append(24-W[j])
        else:
            l.append(W[j])
            
    l.sort()
    l.append(24)
    m = 24
    for j in range(1,len(l)):
        m = min(m,l[j] - l[j-1])
    ans.append(m)

print(max(ans))

Submission status: Wrong Answer

Solution code:
import bisect
import collections
import copy
import functools
import heapq
import math
import sys
from collections import deque
from collections import defaultdict
from fractions import Fraction
input = sys.stdin.readline
sys.setrecursionlimit(10**9)
INF = float("inf")
MOD = 10**9+7

N = int(input())
A = list(map(int,input().split()))
d = defaultdict(int)

if 0 in A:
    print(0)
    exit()

for i in range(N):
    d[A[i]] += 1

T = [0]
W = []
for k in d.keys():
    if d[k] >= 2:
        T.append(k)
        T.append(24-k)
    else:
        W.append(k)
#print(T,W)

ans = []

w = len(W)
K = 2 # 選択肢の数
for i in range(K**w):
    TF=[0]*w

    for j in range(w):
        TF[w-j-1] = i % K
        i //= K
    
    l = copy.deepcopy(T)
    for j in range(w):
        if TF[j] == 1:
            l.append(24-W[j])
        else:
            l.append(W[j])
            
    l.sort()
    m = 24
    for j in range(1,len(l)):
        m = min(m,l[j] - l[j-1])
    ans.append(m)

print(max(ans))

Submission status: Wrong Answer

Solution code:
n= int(input())
d= list(map(int,input().split()))
if n==1:print(0)
else:
    ddict={}
    for sd in d:ddict[sd]=ddict.get(sd,0)+1
    if 3<=max(ddict.values()):
        print(0);exit()
    elif 0 in ddict.keys():
        print(0);exit()
    elif 12 in ddict.keys() and ddict[12]==2:
        print(0);exit()
    else:
        fixtime=[0,24]
        ktime=[]
        for akey in ddict:
            if ddict[akey]==2:
                fixtime.append(akey)
                fixtime.append(24-akey)
            elif ddict[akey]==1:
                if akey==12:fixtime.append(12)
                else:ktime.append((akey,24-akey))
        gmin= min(d)
        skouho=sorted(fixtime)
        for i in range(len(skouho)-1):gmin=min(gmin,skouho[i+1]-skouho[i])
        if len(ktime)==0:print(gmin)
        else:
            longtime=0
            for i in range(2**len(ktime)):
                newtime=[]
                tempmin=24
                for j in range(len(ktime)):newtime.append(ktime[j][i>>j&1])
                temptime=sorted(fixtime+newtime)
                for k in range(len(temptime)-1):
                    tempmin=min(tempmin,temptime[k+1]-temptime[k])
                longtime=max(longtime,tempmin)
            print(longtime)

Submission status: Wrong Answer

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce, lru_cache
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def TUPLE(): return tuple(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7 
#mod = 998244353
from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10

def main():

	N = INT()
	D = LIST()

	time = [0]*13
	for i, d in enumerate(D):
		time[d] += 1

	if 1 <= time[0] or 2 <= time[12]:
		print(0)
		exit()
	elif any(3 <= x for x in time):
		print(0)
		exit()

	D.sort()
	ans = 0
	for x in product([0, 1], repeat=N):
		time = [0, 24]
		for i, y in enumerate(x):
			if y:
				time.append(D[i])
			else:
				time.append(24-D[i])

		time.sort()
		tmp_diff = INF
		tmp = 0
		for d in D[1:]:
			tmp_diff = min(d-tmp, tmp_diff)
			tmp = d

		ans = max(tmp_diff, ans)

	print(ans)

if __name__ == '__main__':
	main()

Submission status: Wrong Answer

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce, lru_cache
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def TUPLE(): return tuple(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7 
#mod = 998244353
from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10

N = INT()
D = LIST()

time = [0]*13
time[0] = 1
for i, d in enumerate(D):
	time[d] += 1

if 2 <= time[0] or 2 <= time[12]:
	print(0)
	exit()
elif any(3 <= x for x in time):
	print(0)
	exit()

time_ = [0]*24
time_koho = []
for i, cnt in enumerate(time[1:], 1):
	if cnt:
		if cnt == 2:
			time_[i] = 1
			time_[24-i] = 1
		else:
			time_koho.append(i)

ans = 0
for x in product([0, 1], repeat=len(time_koho)):
	time_tmp = time_.copy()
	for idx, y in enumerate(x):
		if y:
			time_tmp[24-time_koho[idx]] = 1
		else:
			time_tmp[time_koho[idx]] = 1

	time_diff = INF
	tmp = 0
	for j, c in enumerate(time_tmp[1:], 1):
		if c:
			time_diff = min(time_diff, j-tmp)
			tmp = j

	ans = max(ans, time_diff)

print(ans)

Submission status: Wrong Answer

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce, lru_cache
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def TUPLE(): return tuple(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7 
#mod = 998244353
from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10

N = INT()
D = LIST()

time = [0]*13
for i, d in enumerate(D):
	time[d] += 1

if 1 <= time[0] or 2 <= time[12]:
	print(0)
	exit()
elif any(3 <= x for x in time):
	print(0)
	exit()

D.sort()
ans = 0
for x in product([0, 1], repeat=N):
	time = [0]
	for i, y in enumerate(x):
		if y:
			time.append(D[i])
		else:
			time.append(24-D[i])

	time.sort()
	tmp_diff = INF
	tmp = 0
	for d in D[1:]:
		tmp_diff = min(d-tmp, tmp_diff)
		tmp = d

	ans = max(tmp_diff, ans)

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
d = list(map(int,input().split()))
if n >= 12:
    count = [0]*24
    count[0] += 2
    for i in d:
        count[i] += 1
        count[(24-i)%24] += 1
    if max(count) > 2:
        print(0)
    else:
        print(1)

Submission status: Wrong Answer

Solution code:
print("NO")

Submission status: Wrong Answer

Solution code:
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n = int(input())
d = list(map(int, input().split()))
from itertools import product
if n>=24:
    from collections import Counter
    d.append(0)
    c = Counter(d)
    for i in range(13):
        c.setdefault(0)
    if c[0]<=1 and (c[12]<=1) and all(c[v]<=2 for v in range(1,12)):
        ans = 1
    else:
        ans = 0
else:
    ans = 0
    for ind in product(*[range(2) for _ in range(n)]):
        vals = []
        for i in range(n):
            if ind[i]:
                vals.append(d[i])
            else:
                vals.append((24-d[i])%24)
        vals.append(0)
        res = 50
        for i in range(len(vals)):
            for j in range(i+1,len(vals)):
                res = min(res, abs(vals[i]-vals[j]))
        ans = max(ans, res)
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n = int(input())
d = list(map(int, input().split()))
from itertools import product
if n>=15:
    from collections import Counter
    d.append(0)
    c = Counter(d)
    for i in range(13):
        c.setdefault(0)
    if c[0]<=1 and (c[12]<=1) and all(c[v]<=2 for v in range(1,12)):
        ans = 1
    else:
        ans = 0
else:
    ans = 0
    for ind in product(*[range(2) for _ in range(n)]):
        vals = []
        for i in range(n):
            if ind[i]:
                vals.append(d[i])
            else:
                vals.append((24-d[i])%24)
        vals.append(0)
        res = 50
        for i in range(len(vals)):
            for j in range(i+1,len(vals)):
                res = min(res, abs(vals[i]-vals[j]))
        ans = max(ans, res)
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n = int(input())
d = list(map(int, input().split()))
from itertools import product
if n>=13:
    from collections import Counter
    d.append(0)
    c = Counter(d)
    for i in range(13):
        c.setdefault(0)
    if c[0]<=1 and (c[12]<=1) and all(c[v]<=2 for v in range(1,12)):
        ans = 1
    else:
        ans = 0
else:
    ans = 0
    for ind in product(*[range(2) for _ in range(n)]):
        vals = []
        for i in range(n):
            if ind[i]:
                vals.append(d[i])
            else:
                vals.append((24-d[i])%24)
        vals.append(0)
        res = 50
        for i in range(len(vals)):
            for j in range(i+1,len(vals)):
                res = min(res, abs(vals[i]-vals[j]))
        ans = max(ans, res)
print(ans)