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:
# -*- coding: utf-8 -*-

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
#from math import gcd
import bisect
import heapq
from collections import defaultdict
from collections import deque
from collections import Counter
from functools import lru_cache

#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')
AZ = "abcdefghijklmnopqrstuvwxyz"

#############
# Functions #
#############

######INPUT######
def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]

######OUTPUT######
def P(arg): print(arg); return
def Y(): print("Yes"); return
def N(): print("No"); return
def E(): exit()
def PE(arg): print(arg); exit()
def YE(): print("Yes"); exit()
def NE(): print("No"); exit()

#####Shorten#####
def DD(arg): return defaultdict(arg)

#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n): return kaijo_memo[n]
  if(len(kaijo_memo) == 0): kaijo_memo.append(1)
  while(len(kaijo_memo) <= n): kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n): return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0): gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n): gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if n == r: return 1
  if n < r or r < 0: return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0: 
        cnt+=1 
        temp //= i
      arr.append([i, cnt])
  if temp!=1: arr.append([temp, 1])
  if arr==[]: arr.append([n, 1])
  return arr

#####MakeDivisors######
def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  return divisors

#####MakePrimes######
def make_primes(N):
  max = int(math.sqrt(N))
  seachList = [i for i in range(2,N+1)]
  primeNum = []
  while seachList[0] <= max:
    primeNum.append(seachList[0])
    tmp = seachList[0]
    seachList = [i for i in seachList if i % tmp != 0]
  primeNum.extend(seachList)
  return primeNum

#####GCD#####
def gcd(a, b):
    while b: a, b = b, a % b
    return a

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#####BitCount#####
def count_bit(n):
  count = 0
  while n:
    n &= n-1
    count += 1
  return count

#####ChangeBase#####
def base_10_to_n(X, n):
  if X//n: return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i-1])*n**i for i in range(len(str(X))))

def base_10_to_n_without_0(X, n):
  X -= 1
  if X//n: return base_10_to_n_without_0(X//n, n)+[X%n]
  return [X%n]

#####IntLog#####
def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count

#############
# Main Code #
#############

N = I()
A = IL()
data = []
for k in range(1<<N):
  temp = [0,24]
  for i in range(N):
    if (k>>i)&1:
      temp.append(A[i])
    else:
      temp.append(24-A[i])
  temp.sort()
  data.append(min(temp[i+1]-temp[i] for i in range(N)))
print(max(data))

Submission status: Wrong Answer

Solution code:
#!/usr/bin python3
# -*- coding: utf-8 -*-

from collections import Counter

def main():
    N = int(input())
    D = list(map(int, input().split()))
    D.append(0)
    D = Counter(D)
    for i in range(13):
        if (i==0 or i==12) and D[i]==2:
            print(0)
            exit()
        elif D[i]==3:
            print(0)
            exit()
    ret = 0
    for i in range(2**11):
        l = [0,24]
        if D[12]==1:
            l.append(12)
        for j in range(1,12):
            if D[j]==1:
                if i>>j & 1:
                    l.append(24 - j)
                else:
                    l.append(j)
            elif D[j]==2:
                l.append(24 - j)
                l.append(j)
        l.sort()
        mi = 24
        for i in range(1,len(l)):
            mi = min(mi, l[i]-l[i-1])
#        print(l,mi)
        ret = max(ret, mi)
    print(ret)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#import sys
#import numpy as np
import math
#from fractions import Fraction
import itertools
from collections import deque
from collections import Counter
#import heapq
#from fractions  import gcd
#input=sys.stdin.readline
import bisect
n=int(input())
d=list(map(int,input().split()))
d.sort()
res=24
if n==1 or 0 in d:
  print(d[0])
  exit()
for i in range(0,n-2):
    res=min(res,d[i+2]-d[i])
for i in range(n-1):
    res=min(res,d[i]+d[i+1],24-d[i]-d[i+1])
ans=min(d[1],res)
print(ans)

Submission status: Wrong Answer

Solution code:
#import sys
#import numpy as np
import math
#from fractions import Fraction
import itertools
from collections import deque
from collections import Counter
#import heapq
#from fractions  import gcd
#input=sys.stdin.readline
import bisect
n=int(input())
d=list(map(int,input().split()))
d.sort()
res=24
if n==1 or 0 in d:
  print(d[0])
  exit()
for i in range(0,n-2):
    res=min(res,d[i+2]-d[i])
for i in range(n-1):
    res=min(res,24-d[i]-d[i+1])
ans=min(d[1],res)
print(ans)

Submission status: Wrong Answer

Solution code:
#import sys
#import numpy as np
import math
#from fractions import Fraction
import itertools
from collections import deque
from collections import Counter
#import heapq
#from fractions  import gcd
#input=sys.stdin.readline
import bisect
n=int(input())
d=list(map(int,input().split()))
d.sort()
res=24
if n==1:
  print(d[0])
  exit()
for i in range(0,n-2):
    res=min(res,d[i+2]-d[i])
for i in range(n-1):
    res=min(res,24-d[i]-d[i+1])
ans=min(d[1],res)
print(ans)

Submission status: Wrong Answer

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

if N == 1:
    print(D[0])
    exit()

time = [0]
for i in range(N):
    max_24 = 24
    max_0 = 24
    for j in range(len(time)):
        max_0 = min(abs(time[j] - D[i]), max_0)
        max_24 = min(abs(time[j] - (24-D[i])), max_24)
    if max_0 >= max_24:
        time.append(D[i])
    else:
        time.append(24 - D[i])

time.append(24)
ans = 12
for i in range(len(time)):
    for j in range(i+1, len(time)):
        ans = min(ans, abs(time[i] - time[j]))

print(ans)

Submission status: Wrong Answer

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

if N == 1:
    print(D[0])
    exit()

time = [0]
for i in range(N):
    max_24 = 24
    max_0 = 24
    for j in range(len(time)):
        max_0 = min(abs(time[j] - D[i]), max_0)
        max_24 = min(abs(time[j] - (24-D[i])), max_24)
    if max_0 >= max_24:
        time.append(D[i])
    else:
        time.append(24 - D[i])

ans = 12
for i in range(len(time)):
    for j in range(i+1, len(time)):
        ans = min(ans, abs(time[i] - time[j]))

print(ans)

Submission status: Wrong Answer

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

if N == 1:
    print(D[0])
    exit()

time = [0]
for i in range(N):
    max_24 = 12
    max_0 = 12
    for j in range(len(time)):
        max_0 = min(abs(time[j] - D[i]), max_0)
        max_24 = min(abs(time[j] - (24-D[i])), max_24)
    if max_0 >= max_24:
        time.append(D[i])
    else:
        time.append(24 - D[i])

ans = 12
for i in range(len(time)):
    for j in range(i+1, len(time)):
        ans = min(ans, abs(time[i] - time[j]))

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
def base10toN(num, base):
    converted_string, modstring = "", ""
    currentnum = num
    if not num:
        return '0'
    while currentnum:
        mod = currentnum % base
        currentnum = currentnum // base
        converted_string = chr(48 + mod + 7*(mod > 10)) + converted_string
    return converted_string

n=int(input())
d=list(map(int,input().split()))
dic={}
dic[0]=1
for i in range(n):
  if d[i] in dic:
    dic[d[i]]+=1
  else:
    dic[d[i]]=1
ones=[]
twos=[]
for i in dic:
  if dic[i]>=3:
    print(0)
    sys.exit()
  if dic[i]==1:
    ones.append(i)
  if dic[i]==2:
    twos.append(i)
maxans=0
for i in range(2**(len(ones))):
  ans=100000
  s=base10toN(i,2)
  a=[]
  for j in range(len(ones)-len(s)):
    a.append('0')
  for j in range(len(s)):
    a.append(s[j])
  tlist=[]
  for j in twos:
    tlist.append(j)
    if j!=0:
      tlist.append(24-j)
    if j==0:
      tlist.append(0)
  for j in range(len(ones)):
    if a[j]=='1':
      tlist.append(ones[j])
    else:
      tlist.append(24-ones[j])
  for j in range(len(tlist)-1):
    for k in range(j+1,len(tlist)):
      ans=min(ans,abs(tlist[j]-tlist[k]))
  maxans=max(maxans,ans)
print(maxans)

Submission status: Wrong Answer

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

ans = 12
while ans > 1:
  Fix = [0]
  for i in range(N):
    MIN = []
    for dotti in range(2):
      if dotti == 0:
        nxt = D[i]
      else:
        nxt = 24-D[i]
      now = 100
      for t in Fix:
        now = min(now,abs(nxt-t),24-abs(nxt-t))
      MIN.append(now)
    if MIN[0] <= MIN[1]:
      Fix.append(24-D[i])
    else:
      Fix.append(D[i])
  #print(Fix)
  break
ans = 100
for i in range(N+1):
  for j in range(i+1,N+1):
    #print(Fix[i],Fix[j])
    ans = min(ans,abs(Fix[i]-Fix[j]),24-abs(Fix[i]-Fix[j]))
    #print(ans)
print(ans)

Submission status: Wrong Answer

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

ans = 12
while ans > 1:
  Fix = [0]
  for i in range(N):
    MIN = []
    for dotti in range(2):
      if dotti == 0:
        nxt = D[i]
      else:
        nxt = 24-D[i]
      now = 100
      for t in Fix:
        now = min(now,abs(nxt-t),24-abs(nxt-t))
      MIN.append(now)
    if MIN[0] <= MIN[1]:
      Fix.append(24-D[i])
    else:
      Fix.append(D[i])
  print(Fix)
  break
ans = 100
for i in range(N+1):
  for j in range(i+1,N+1):
    #print(Fix[i],Fix[j])
    ans = min(ans,abs(Fix[i]-Fix[j]),24-abs(Fix[i]-Fix[j]))
    #print(ans)
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    N=I()
    D=LI()
    #同じ時差の都市に対して3人以上いる場合は0
    if 0 in D:
        print(0)
        exit()
    if D.count(12)>=2:
        print(0)
        exit()
    
    temp=[0]*24
    temp[0]=1
    if 12 in D:
        temp[13]=1
    
    d=[]
    cnt=0
    for i in range(1,12):
        if D.count(i)==1:
            d.append(i)
            cnt+=1
        elif D.count(i)==2:
            temp[i]=1
            temp[24-i]=1
        elif D.count(i)>=3:
            print(0)
            exit()
            
            
    ans=[]
    
    for i in range(1<<cnt):
        temp2=[0]*24
        
        #コピー
        for k in range(24):
            temp2[k]=temp[k]
        
        for j in range(cnt):
            if i>>j & 1:
                temp2[d[j]]=1
            else:
                temp2[24-d[j]]=1
                
        aaa=24
        for ii in range(24):
            for jj in range(ii+1,24):
                if temp2[ii]==1 and temp2[jj]==1:
                    diff=min(jj-ii,24-(jj-ii))
                    if diff<aaa:
                        aaa=diff
        ans.append(aaa)
    print(max(ans))
            
    
        

main()

Submission status: Wrong Answer

Solution code:
n = int(input())
d = list(map(int,input().split()))
time = [0 for i in range(13)]
for i in range(n):
    time[d[i]] += 1
    if d[i] == 0:
        print(0)
        exit()

kouho = [0]
doti = []
for i in range(13):
    if time[i] >= 3:
        print(0)
        exit()
    elif time[i] == 2:
        kouho.append(i)
        kouho.append(24-i)
    elif time[i] == 1:
        doti.append((i,24-i))


ans = 0
for i in range(2**len(doti)):
    kar = []
    for j in range(len(doti)):
        kar.append(doti[j][i>>j&1])
    c = kouho[:] + kar[:]
    c.sort()
    now = 12
    for k in range(len(c)-1):
        now = min(now,min(c[k+1]-c[k],24-c[k+1]+c[k]))
    ans = max(ans,now)
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
d = list(map(int,input().split()))
time = [0 for i in range(13)]
for i in range(n):
    time[d[i]] += 1
    if d[i] == 0:
        print(0)
        exit()

kouho = [0]
doti = []
for i in range(13):
    if time[i] >= 3:
        print(0)
        exit()
    elif time[i] == 2:
        kouho.append(i)
        kouho.append(24-i)
    elif time[i] == 1:
        doti.append((i,24-i))


ans = 0
for i in range(2**len(doti)):
    kar = []
    for j in range(len(doti)):
        kar.append(doti[j][i>>j&1])
    c = kouho[:] + kar[:]
    c.sort()
    now = 12
    for k in range(len(c)-1):
        now = min(now,c[k+1]-c[k])
    ans = max(ans,now)
print(ans)

Submission status: Wrong Answer

Solution code:
import itertools
n = int(input())
d = list(map(int,input().split()))
time = [0 for i in range(13)]
for i in range(n):
    time[d[i]] += 1
    if d[i] == 0:
        print(0)
        exit()

if n == 1:
    print(d[0])
    exit()

kouho = [0]
doti = []
for i in range(13):
    if time[i] >= 3:
        print(0)
        exit()
    elif time[i] == 2:
        kouho.append(i)
        kouho.append(24-i)
    elif time[i] == 1:
        doti.append((i,24-i))


ans = 0
for i in range(2**len(doti)):
    kar = []
    for j in range(len(doti)):
        kar.append(doti[j][i>>j&1])
    c = kouho[:] + kar[:]
    c.sort()
    now = 24
    for k in range(len(c)-1):
        now = min(now,c[k+1]-c[k])
    ans = max(ans,now)
if ans == 24:
    print(0)
else:
    print(ans)

Submission status: Wrong Answer

Solution code:
import itertools
n = int(input())
d = list(map(int,input().split()))
time = [0 for i in range(13)]
for i in range(n):
    time[d[i]] += 1

if n == 1:
    print(min(d[0],24-d[0]))
    exit()
kouho = [0]
doti = []
for i in range(13):
    if time[i] >= 3:
        print(0)
        exit()
    elif time[i] == 2:
        kouho.append(i)
        kouho.append(24-i)
    elif time[i] == 1:
        doti.append((i,24-i))


ans = 0
for i in range(2**len(doti)):
    kar = []
    for j in range(len(doti)):
        kar.append(doti[j][i>>j&1])
    c = kouho[:] + kar[:]
    c.sort()
    now = 24
    for k in range(len(c)-1):
        now = min(now,c[k+1]-c[k])
    ans = max(ans,now)
if ans == 24:
    print(0)
else:
    print(ans)

Submission status: Wrong Answer

Solution code:
import itertools
n = int(input())
d = list(map(int,input().split()))
time = [0 for i in range(13)]
for i in range(n):
    time[d[i]] += 1

kouho = [0]
doti = []
for i in range(13):
    if time[i] >= 3:
        print(0)
        exit()
    elif time[i] == 2:
        kouho.append(i)
        kouho.append(24-i)
    elif time[i] == 1:
        doti.append((i,24-i))


ans = 0
for i in range(2**len(doti)):
    kar = []
    for j in range(len(doti)):
        kar.append(doti[j][i>>j&1])
    c = kouho[:] + kar[:]
    c.sort()
    now = 24
    for k in range(len(c)-1):
        now = min(now,c[k+1]-c[k])
    ans = max(ans,now)
if ans == 24:
    print(0)
else:
    print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    D = list(map(int,input().split()))
    D.sort()

    b = 0
    ans = 24
    for i,d in enumerate(D):
        if i%2 == 0:
            t = d
        else:
            t = 24 - d

        ans = min(abs(b - t),ans)
        b = t

    print(ans)

main()

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    D = list(map(int,input().split()))
    D.sort()

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

        ans = min(abs(b - t),ans)
        b = t

    print(ans)

main()

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
a.append(0)
from collections import Counter
ca=Counter(a)
if max(ca.values())>2 or ca[0]>1 or ca[12]>1:
  print(0)
  exit()
elif ca[12]>0 and ca[11]>0:
  print(1)
  exit()
a.sort()
ans=0
for i in range(2**n):
  aa=[0]
  for j in range(n):
    if (i>>j)&1:
      aa.append((24-a[j+1])%24)
    else:
      aa.append(a[j+1]%24)
  tmp=float('inf')
  aa.sort()
  for j in range(n):
    tmp=min(tmp,aa[j+1]-aa[j])
  tmp=min(tmp,abs(24-a[-1]-aa[0]))
  #print(tmp,aa)
  ans=max(ans,tmp)
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
a.append(0)
from collections import Counter
ca=Counter(a)
if max(ca.values())>2 or ca[0]>1 or ca[12]>1:
  print(0)
  exit()
elif ca[12]>0 and ca[11]>0:
  print(1)
  exit()
a.sort()
ans=0
for i in range(2**n):
  aa=[0]
  for j in range(n):
    if (i>>j)&1:
      aa.append((24-a[j+1])%24)
    else:
      aa.append(a[j+1]%24)
  tmp=float('inf')
  aa.sort()
  for j in range(n+1):
    tmp=min(tmp,abs(aa[j-1]-aa[j]))
  #print(tmp,aa)
  ans=max(ans,tmp)
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
a.append(0)
from collections import Counter
ca=Counter(a)
if max(ca.values())>2 or ca[0]>1 or ca[12]>1:
  print(0)
  exit()
elif ca[12]>0 and ca[11]>0:
  print(1)
  exit()
a.sort()
ans=0
for i in range(2**n):
  aa=[0]
  for j in range(n):
    if (i>>j)&1:
      aa.append((24-a[j+1])%24)
    else:
      aa.append(a[j+1]%24)
  tmp=float('inf')
  aa.sort()
  for j in range(n):
    tmp=min(tmp,(aa[j+1]-aa[j])%24)
  #print(tmp,aa)
  ans=max(ans,tmp)
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
a.append(0)
from collections import Counter
ca=Counter(a)
if max(ca.values())>2 or ca[0]>1:
  print(0)
  exit()
a.sort()
ans=0
for i in range(2**n):
  aa=a.copy()
  for j in range(n):
    if (i>>j)&1:
      aa[j+1]=(24-aa[j+1])%24
  tmp=float('inf')
  aa.sort()
  for j in range(n):
    tmp=min(tmp,(aa[j+1]-aa[j])%24)
  #print(tmp,aa)
  ans=max(ans,tmp)
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
a.append(0)
from collections import Counter
ca=Counter(a)
if max(ca.values())>2 or ca[0]>1:
  print(0)
  exit()
a.sort()
n=len(a)
ans=0
for i in range(2**n):
  aa=a.copy()
  for j in range(n):
    if (i>>j)&1:
      aa[j]=24-aa[j]
  tmp=float('inf')
  aa.sort()
  for j in range(n-1):
    tmp=min(tmp,(aa[j+1]-aa[j])%24)
  #print(tmp,aa)
  ans=max(ans,tmp)
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
a.append(0)
from collections import Counter
ca=Counter(a)
if max(ca.values())>2:
  print(0)
  exit()
a.sort()
n=len(a)
ans=0
for i in range(2**n):
  aa=a.copy()
  for j in range(n):
    if (i>>j)&1:
      aa[j]=24-aa[j]
  tmp=float('inf')
  aa.sort()
  for j in range(n-1):
    tmp=min(tmp,(aa[j+1]-aa[j])%24)
  #print(tmp,aa)
  ans=max(ans,tmp)
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
D = list(map(int,input().split()))
Ta = [0]*13
Ta[0] = 1
for i in range(N):
    Ta[min(D[i],24-D[i])] += 1

if max(Ta)>=3:
    print(0)
elif Ta[0]>=2:
    print(0)
elif Ta[12]>=2:
    print(0)
else:
    L1 = []
    L2 = []
    for i in range(13):
        if Ta[i] ==1:
            if i==0 or i==12:
                L2.append(i)
            else:
                L1.append(i)
        elif Ta[i]==2:
            L2.append(i)
            L2.append(24-i)
    NL1 = len(L1)
    from itertools import product,combinations
    LS = list(product([0,1], repeat=NL1))
    NLS = len(LS)
    out = 0
    for i in range(NLS):
        L = LS[i]
        L3 = L2[:]
        score = 100
        for j in range(NL1):
            if L[j]==1:
                L3.append(L1[j])
            elif L[j]==0:
                L3.append(24-L1[j])
        CS = list(list(combinations(L3,2)))
        NCS = len(CS)
        for k in range(NCS):
            score = min(score,abs(CS[k][0]-CS[k][1]))
        out=max(out,score)

    print(out)

Submission status: Wrong Answer

Solution code:
import sys
readline = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
#mod = 998244353
INF = 10**18
eps = 10**-7

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

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

if c[0] >= 2 or c[12] >= 2:
    print(0)
    exit()
for i in range(1,12):
    if c[i] >= 3:
        print(0)
        exit()

bitsearchlist = []
notbitsearch = [False]*24
notbitsearch[0] = True
if c[12]:
    notbitsearch[12] = True


for i in range(1,12):
    if c[i] == 1:
        bitsearchlist.append(i)
    elif c[i] == 2:
        notbitsearch[i] = True
        notbitsearch[24-i] = True

print(bitsearchlist)
print(notbitsearch)


def count(List):
    anss = INF
    ret = INF
    for b in notbitsearch:
        if b:
            anss = min(anss,ret)
            ret = 0
        else:
            ret += 1
    anss = min(anss,ret)
    anss += 1
    return anss



L = len(bitsearchlist)

if L == 0:
    print(count(notbitsearch))
    exit()

ans = 0
for i in range(2**L):
    for j in range(L):
        if ((i >> j) & 1):
            notbitsearch[bitsearchlist[j]] = True
        else:
            notbitsearch[24-bitsearchlist[j]] = True
    ans = max(ans,count(notbitsearch))
    for j in range(L):
        if ((i >> j) & 1):
            notbitsearch[bitsearchlist[j]] = False
        else:
            notbitsearch[24-bitsearchlist[j]] = False

print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
D=[0]+list(map(int,input().split()))
D.sort()
for i in range(N):
  if i&1:
    D[i]=(24-D[i])%24
D.sort()
P=24-D[N]
for i in range(N):
  P=min(P,D[i+1]-D[i])
print(P)

Submission status: Wrong Answer

Solution code:
import sys
from itertools import product
from copy import deepcopy

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())
    D = list(map(int, input().split()))

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

    P = []
    init_T = []
    for i in range(13):
        if i == 0 or i == 12:
            if cnt[i]:
                if cnt[i] == 1:
                    init_T.append(i)
                else:
                    print(0)
                    exit()
        else:
            if cnt[i]:
                if cnt[i] == 1:
                    P.append(i)
                elif cnt[i] == 2:
                    init_T.append(i)
                    init_T.append(24 - i)
                else:
                    print(0)
                    exit()

    res = 0
    for pattern in product([0, 1], repeat=len(P)):
        T = deepcopy(init_T)
        for idx, p in enumerate(pattern):
            if p == 0:
                T.append(P[idx])
            else:
                T.append(24 - P[idx])

        min_gap = f_inf
        for i in range(len(T)):
            for j in range(i + 1, len(T)):
                gap = abs(T[i] - T[j])
                min_gap = min(min_gap, gap)

        res = max(res, min_gap)

    print(res)


if __name__ == '__main__':
    resolve()

Submission status: Wrong Answer

Solution code:
# CODE FESTIVAL 2017 Final
# C - Time Gap
# https://atcoder.jp/contests/cf17-final/tasks/cf17_final_c
from collections import Counter
N = int(input())
*A, = map(int, input().split())

INF = 1 << 30
C = Counter(A)
if N >= 24 or 0 in C:
    print(0)
    exit()

dt = []
nt = []
for k, v in C.items():
    if v > 2:
        print(0)
        exit()
    if v == 2:
        dt.append(k)
        dt.append(24-k)
    if v == 1:
        nt.append(k)

tmp = INF
for i, t in enumerate(dt):
    for s in dt[i+1:]:
        if abs(t-s) < tmp:
            tmp = abs(t-s)

ans = tmp if tmp < INF else 0
M = len(nt)
for bit in range(1 << M):
    D = [0]*M
    for i in range(M):
        if bit >> i & 1:
            D[i] = nt[i]
        else:
            D[i] = 24-nt[i]

    mn = tmp
    for j, d in enumerate(D):
        for e in D[j+1:]:
            if abs(d-e) < mn:
                mn = abs(d-e)
        for t in dt:
            if abs(d-t) < mn:
                mn = abs(d-t)

    if mn != INF and mn > ans:
        ans = mn

print(ans)

Submission status: Wrong Answer

Solution code:
# CODE FESTIVAL 2017 Final
# C - Time Gap
# https://atcoder.jp/contests/cf17-final/tasks/cf17_final_c
from collections import Counter
N = int(input())
*A, = map(int, input().split())

INF = 1 << 30
C = Counter(A)
if N >= 24 or 0 in C:
    print(0)
    exit()

dt = []
nt = []
for k, v in C.items():
    if v > 2:
        print(0)
        exit()
    if v == 2:
        dt.append(k)
        dt.append(24-k)
    if v == 1:
        nt.append(k)

tmp = INF
for i, t in enumerate(dt):
    for s in dt[i+1:]:
        if abs(t-s) < tmp:
            tmp = abs(t-s)

ans = tmp
M = len(nt)
for bit in range(1 << M):
    D = [0]*M
    for i in range(M):
        if bit >> i & 1:
            D[i] = nt[i]
        else:
            D[i] = 24-nt[i]

    mn = tmp
    for j, d in enumerate(D):
        for e in D[j+1:]:
            if abs(d-e) < mn:
                mn = abs(d-e)
        for t in dt:
            if abs(d-t) < mn:
                mn = abs(d-t)

    if mn != INF and mn > ans:
        ans = mn

print(ans)

Submission status: Wrong Answer

Solution code:
def dist(a,b):
    return min(abs(a-b),24-abs(a-b))
def solve():
    N = int(input())
    D = list(map(int, input().split()))
    lis = [0]
    for i in range(N):
        d = D[i]
        m = 24
        for l in lis:
            m = min(m,dist(d,l))
        d = (24-D[i])%24
        n = 24
        for l in lis:
            n = min(n,dist(d,l))
        if m>=n:
            lis.append(D[i])
        else:
            lis.append((24-D[i])%24)
    m = 24
    l = len(lis)
    for i in range(l):
        for j in range(l):
            if i!=j:
                m = min(m,dist(lis[i],lis[j]))
    return m
print(solve())

Submission status: Wrong Answer

Solution code:
def solve():
    N = int(input())
    D = list(map(int, input().split()))
    lis = [0]
    for i in range(N):
        d = D[i]
        m = 24
        for l in lis:
            m = min(m,min(abs(d-l),24-abs(d-l)))
        d = (24-D[i])%24
        n = 24
        for l in lis:
            n = min(n,min(abs(d-l),24-abs(d-l)))
        if m>=n:
            lis.append(D[i])
        else:
            lis.append((24-D[i])%24)
    m = 24
    l = len(lis)
    for i in range(l):
        for j in range(l):
            if i!=j:
                m = min(m,min(abs(lis[i]-lis[j]),24-abs(lis[i]-lis[j])))
    return m
print(solve())

Submission status: Wrong Answer

Solution code:
def solve():
    N = int(input())
    D = list(map(int, input().split()))
    lis = [0]
    for i in range(N):
        d = D[i]
        m = 24
        for l in lis:
            m = min(m,min(abs(d-l),24-abs(d-l)))
        d = (24-D[i])%24
        n = 24
        for l in lis:
            n = min(n,min(abs(d-l),24-abs(d-l)))
        if m>=n:
            lis.append(D[i])
            if i==N-1:
                return m
        else:
            lis.append((24-D[i])%24)
            if i==N-1:
                return n
print(solve())

Submission status: Wrong Answer

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

ans = [d[0]]
s = 100
def get_min(ans, d):
    dif = 100
    for i in range(len(ans)):
        m = min(abs(ans[i]-d), 24-abs(ans[i]-d))
        if m < dif:
            dif = m
    return dif

for i in range(1, n):
    d1 = d[i]
    d2 = 24-d[i]
    m1 = get_min(ans, d1)
    m2 = get_min(ans, d2)
    if d1 > d2:
        ans.append(d1)
    else:
        ans.append(d2)

ans.append(0)
for i in range(n+1):
    for j in range(i+1, n+1):
        tmp_s = min(abs(ans[i]-ans[j]), 24-abs(ans[i]-ans[j]))
        if tmp_s < s:
            s = tmp_s
# print(ans, s)
print(s)

Submission status: Wrong Answer

Solution code:
import collections
import itertools

def dfs(used:set, new:int, i:int):
    global D, N, iters
    new1 = new
    new2 = (24-new) * (new!=0)
    if new1 not in used:
        used.add(new1)
        if i+1 == N:
            iters.append(list(used))
        else:
            dfs(used, D[i+1], i+1)
        used.remove(new1)
    if new2 not in used:
        used.add(new2)
        if i+1 == N:
            iters.append(list(used))
        else:
            dfs(used, D[i+1], i+1)
        used.remove(new2)

def main():
    global D, N, iters
    N = int(input())
    D = list(map(int, input().split()))
    D.sort()
    iters = []
    used = set([0])
    dfs(used, D[0], 0)
    if len(iters) == 0:
        print(0)
        return
    maxd = 0
    for tmp in iters:
        pairs = itertools.combinations(tmp, 2)
        mind = 25
        for x, y in pairs:
            mind = min(mind, abs(x-y))
        maxd = max(maxd, mind)
    print(maxd)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import collections
n=int(input())
s=list(map(int,input().split()))
if 0 in s:
  print(0)
  quit()
s=collections.Counter(s)
l1=[0]
l2=[]
for x in s:
  if s[x]>2:
    print(0)
    quit()
  elif s[x]>1:
    l2.append(x)
    l2.append(24-x)
  else:
    l1.append(x)
x=len(l1)
an=0
for i in range(2**x):
  memo=[0]*x
  for j in range(x):
    if ((i >> j) & 1):
      memo[j]=l1[j]
    else:
      memo[j]=24-l1[j] 
  ans=12
  memo=memo+l2
  for k in range(len(memo)):
    for m in range(k+1,len(memo)):
      ans=min(ans,abs(memo[k]-memo[m]))
  an=max(ans,an)
print(an)