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

Solution code:
import numpy as np

N = int(input())
D = list(map(int, input().split()))
if N > 24:
    print(0)
    exit()
elif N == 23:
    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: Wrong Answer

Solution code:
import numpy as np

N = int(input())
D = list(map(int, input().split()))
if N > 22:
    print(0)
    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: Wrong Answer

Solution code:
import numpy as np

N = int(input())
D = list(map(int, input().split()))
if N > 21:
    print(0)
    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: Wrong Answer

Solution code:
N = int(input())
D = [0]+[int(x) for x in input().split()]
D.sort()
li = []
for ind, d in enumerate(D):
    if(ind%2==0):
        li.append(d)
    else:
        li.append(24-d)
li.sort()
ans = 24
for ind, d in enumerate(li[:-1]):
    ans = min(li[ind+1]-d, ans)
print(ans if ans!=24 else 0)

Submission status: Wrong Answer

Solution code:
N = int(input())
D = [int(x) for x in input().split()]
D.append(0)
D.sort()
ans = 0

for _ in range(N):
    min_dis = 24
    chg_ind = 0
    for ind, d in enumerate(D[:-1]):
        if(D[ind+1]-d<min_dis):
            min_dis = D[ind+1]-d
            chg_ind = ind
    ans = max(min_dis, ans)
    x = D.pop(chg_ind)
    if(x>12):
        D.append(x)
    else:
        D.append(24-x)
    D.sort
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
D = [int(x) for x in input().split()]
D.append(0)
D.sort()
ans = 0

for _ in range(N):
    min_dis = 24
    chg_ind = 0
    for ind, d in enumerate(D[:-1]):
        if(D[ind+1]-d<min_dis):
            min_dis = D[ind+1]-d
            chg_ind = ind
    ans = max(min_dis, ans)
    x = D.pop(chg_ind)
    D.append(24-x)
    D.sort
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
D = [int(x) for x in input().split()]
D.append(0)
D.sort()
ans = 0

for _ in range(N**2):
    min_dis = 24
    chg_ind = 0
    for ind, d in enumerate(D[:-1]):
        if(D[ind+1]-d<min_dis):
            min_dis = D[ind+1]-d
            chg_ind = ind
    ans = max(min_dis, ans)
    x = D.pop(chg_ind)
    D.append(24-x)
    D.sort
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
D = [int(x) for x in input().split()]
D.append(0)
D.sort()
ans = 0

for _ in range(N):
    min_dis = 24
    chg_ind = 0
    for ind, d in enumerate(D[:-1]):
        if(D[ind+1]-d<min_dis):
            min_dis = D[ind+1]-d
            chg_ind = ind
    ans = max(min_dis, ans)
    x = D.pop(chg_ind)
    if(x>12):
        break
    D.append(24-x)
    D.sort
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
D = [int(x) for x in input().split()]
D.sort()
ans = 0

for _ in range(N):
    min_dis = 24
    chg_ind = 0
    for ind, d in enumerate(D[:-1]):
        if(D[ind+1]-d<min_dis):
            min_dis = D[ind+1]-d
            chg_ind = ind
    ans = max(min_dis, ans)
    x = D.pop(chg_ind)
    if(x>12):
        break
    D.append(24-x)
    D.sort
print(ans if ans!=24 else 0)

Submission status: Wrong Answer

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
print(li)
print(len(li))
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])
            continue
        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(hour)-1):
        tmp=min(tmp,hour[j+1]-hour[j])
    # print(tmp)
    ans=max(ans,tmp)
print(ans)

Submission status: Wrong Answer

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(hour)-1):
        tmp=min(tmp,hour[j+1]-hour[j])
    # print(tmp)
    ans=max(ans,tmp)
print(ans)

Submission status: Wrong Answer

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])%13
    for j in range(len(hour)-1):
        tmp=min(tmp,(hour[j+1]-hour[j])%13)
    # print(tmp)
    ans=max(ans,tmp)
print(ans)

Submission status: Wrong Answer

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])%12
    for j in range(len(hour)-1):
        tmp=min(tmp,(hour[j+1]-hour[j])%12)
    # print(tmp)
    ans=max(ans,tmp)
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from collections import Counter
import copy

N = int(input())
D = list(map(int, input().split()))
if N == 1:
    print(min(D[0], 24-D[0]))
    exit()

D.append(0)

c = Counter(D)

times = []
p = []
for num, cnt in c.items():
    if (num == 0 or num == 12) and cnt >= 2:
        # D==24-D になるかつ時差０の組がいるので時差の最小は０で確定
        print(0)
        exit()
    elif cnt >= 3:
        # 時差０の組み合わせがある
        print(0)
        exit()
    elif cnt == 2:
        # Dと24-Dに一人ずつ
        times.append(num)
        times.append(24-num)
    elif cnt == 1:
        # D or 24-D のどちらか一方に一人だけいる状態なので別枠で確保
        p.append((num, 24-num))

num_b = len(p)
ans = 0
# D or 24-Dの可能性があるものについて全パターン試すために、2進表記を利用
for b in range(2**num_b):
    b = bin(b)[2:].zfill(num_b)
    time = copy.deepcopy(times)
    for i in range(num_b):
        if b[i] == "0":
            time.append(p[i][0])
        else:
            time.append(p[i][1])
    tmp = 24
    for i in range(len(time)):
        for j in range(i+1, len(time)):
            tmp = min(tmp, abs(time[i] - time[j]))

    ans = max(ans, tmp)

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
D = list(map(int, input().split()))
D.append(0)
D.sort()
min_v = D[1]
for n in range(1,N+1,2):
  D[n] = 24 - D[n]
D.sort()
for i in range(1, N):
  min_v = min(min_v, D[i] - D[i - 1])
print(min_v)

Submission status: Wrong Answer

Solution code:
N = int(input())
D = list(map(int, input().split()))
D.append(0)
D.sort()
min_v = D[1]
for n in range(1,N,2):
  D[n] = 24 - D[n]
D.sort()
for i in range(1, N):
  min_v = min(min_v, D[i] - D[i - 1])
print(min_v)

Submission status: Wrong Answer

Solution code:
N = int(input())
D = list(map(int, input().split()))
D.append(0)
D.sort()
for n in range(1,N,2):
  D[n] = 24 - D[n]
min_v = 24
D.sort()
for i in range(1, N):
  min_v = min(min_v, D[i] - D[i - 1])
print(min_v)

Submission status: Wrong Answer

Solution code:
from itertools import combinations

N = int(input())

D = list(map(int, input().split()))
D.sort()
D24 = [24 - d for d in D]
for n in range(0,N,2):
  D[n] = 24 - D[n]
min_v = 24
for a, b in combinations(D, 2):
  min_v = min(min_v, abs(a - b))
print(min_v)

Submission status: Wrong Answer

Solution code:
from itertools import combinations

N = int(input())

D = list(map(int, input().split()))
D.append(0)
D.sort()
D24 = [24 - d for d in D]
for n in range(1,N,2):
  D[n] = 24 - D[n]
min_v = 24
for a, b in combinations(D, 2):
  min_v = min(min_v, abs(a - b))
print(min_v)

Submission status: Wrong Answer

Solution code:
from collections import Counter
N = int(input())
now_time = []
D = list(map(int, input().split()))
c = Counter(D)
candidate = []
if N == 1:
    print(min(D[0], 24-D[0]))
    exit()

for num, amount in c.items():
    if num == 0:
        print(0)
        exit()
    if amount > 2:
        print(0)
        exit()
    if amount == 2:
        # 確定した時間
        now_time.append(num)
        now_time.append(24-num)
    if amount == 1:
        candidate.append((num, 24-num))  # 選択の余地がある時間
ans = 0
# 確定した時間に選択の余地がある組を追加していく
for mask in range(1 << len(candidate)):
    list_0_1 = []
    time_list = now_time.copy()  # 確定している時間
    for i in range(len(candidate)):
        list_0_1.append(int((mask >> i) & 1))
    # print(list_0_1)
    for i, num in enumerate(list_0_1):
        time_list.append(candidate[i][num])
    # exit()
    tmp = 100
    for i in range(len(time_list)):
        for j in range(i+1, len(time_list)):
            tmp = min(tmp, abs(time_list[i] - time_list[j]))
    ans = max(tmp, ans)


print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
N = int(input())
now_time = []
D = list(map(int, input().split()))
c = Counter(D)
candidate = []
for num, amount in c.items():
    if num == 0:
        print(0)
        exit()
    if amount > 2:
        print(0)
        exit()
    if amount == 2:
        # 確定した時間
        now_time.append(num)
        now_time.append(24-num)
    if amount == 1:
        candidate.append((num, 24-num))  # 選択の余地がある時間
ans = 0
# 確定した時間に、選択の余地がある組を追加していく
for mask in range(1 << len(candidate)):
    list_0_1 = []
    time_list = now_time.copy()  # 確定している時間
    for i in range(len(candidate)):
        list_0_1.append(int((mask >> i) & 1))
    for i, num in enumerate(list_0_1):
        time_list.append(candidate[i][num])
    # exit()
    tmp = 100
    for i in range(len(time_list)):
        for j in range(i+1, len(time_list)):
            tmp = min(tmp, abs(time_list[i] - time_list[j]))
    ans = max(tmp, ans)


print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
N = int(input())
D = list(map(int, input().split()))  # 高橋くんの都市との時差
c = Counter(D)
hoge = []
for num, amout in c.items():
    amout = min(amout, 2)
    for _ in range(amout):
        hoge.append(num)
D = hoge

times_list = []
for i in range(len(D)):
    times_list.append((D[i], 24-D[i]))

# print(times_list)

ans = 0
for mask in range(1 << len(D)):  # len(D)の二乗
    # リストを作成する
    divide = []
    for i in range(len(D)):
        divide.append(int((mask >> i) & 1))
    time_status = []
    for i, num in enumerate(divide):
        time_status.append(times_list[i][num])

    tmp = 100
    # print(time_status)
    for i in range(len(time_status)):
        for j in range(i+1, len(time_status)):
            tmp = min(tmp, abs(time_status[i]-time_status[j]))
    ans = max(tmp, ans)

if N == 1:
    print(min(D[0], 24-D[0]))
else:
    print(ans)

Submission status: Wrong Answer

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

cnt_memo = {}
for num in s:
    if num in cnt_memo:
        cnt_memo[num] += 1
    else:
        cnt_memo[num] = 1

kakutei = [0]
mikakutei = []
for i in cnt_memo:
    if i == 0:
        print(0)
        exit()
    elif i == 12:
        if cnt_memo[i] == 1:
            kakutei.append(12)
        else:
            print(0)
            exit()
    else:
        if cnt_memo[i] == 1:
            mikakutei.append(i)
        elif cnt_memo[i] == 2:
            kakutei.append(i)
            kakutei.append(24 - i)
        else:
            print(0)
            exit()
tmp_ans1 = 25
for i in kakutei:
    for j in kakutei:
        if i != j:
            tmp_ans1 = min(tmp_ans1, abs(i - j))

len_mikakutei = len(mikakutei)
mikakutei_pattern = 2**len_mikakutei
ans = 0
for i in range(mikakutei_pattern):
    tmp = []
    num = i
    cnt = 0
    for _ in range(len_mikakutei):
        if num % 2 == 1:
            tmp.append(mikakutei[cnt])
        else:
            tmp.append(mikakutei[cnt] + 12)
        num //= 2
        cnt += 1
    tmp_ans = 25
    for num1 in tmp:
        for num2 in kakutei:
            tmp_ans = min(tmp_ans, min(abs(num1 - num2), 24 -abs(num1 - num2)))
    for num1 in tmp:
        for num2 in tmp:
            if num1 != num2:
                tmp_ans = min(tmp_ans, min(abs(num1 - num2), 24 -abs(num1 - num2)))
    tmp_ans = min(tmp_ans, tmp_ans1)
    ans = max(ans, tmp_ans)

print(ans)

Submission status: Wrong Answer

Solution code:
import collections
N = int(input())
D = list(map(int, input().split()))
D.append(0)
ans = 0  
    
x = collections.Counter(D)
y = x.most_common(1)
#print(x,y,y[0][1])

if y[0][1] >= 3:
  print(ans)
  quit()
         
if y[0][1] == 2:
  if (y[0][0] == 0) or (y[0][0] == 12):
    print(ans)
    quit()
 
day = [0] * 24 
ilist = [0] * 13
for i in range(13):
  if (i == 0) or (i == 12):
    if i in D:
      day[i] = 1
      ilist[i] = 1
  else:# i = 1 ~ 11
    if D.count(i) == 2:
      day[i] = 1
      day[24 - i] = 1
      ilist[i] = 2
    elif D.count(i) == 1:
      #print(i)
      p = 0
      l = 1
      while p == 0:
        p = ilist[i - l]
        if p == 0:
          l += 1
        if (p == 0) and (l == i):
          p = 3
      #print(i,p,ilist)
      if p == 3:
        day[i] = 1
      if p == 2:
        day[i] = 1
      if p == 1:
        #print(i, l, day)
        if day[i - l] == 1:
          day[24-i] = 1
        else:
          day[i] = 1
      ilist[i] = 1
      

day2 = day * 2
ans = 25
ans2 = 1
xp = 1
#print(day2)
for i in range(len(day2)):
  if day2[i] == 0:
    ans2 += 1
    xp = 0
  elif (day2[i] == 1) and (xp == 0):
    #print(ans, ans2)
    ans = min(ans, ans2)
    ans2 = 1
   
print(ans)

Submission status: Wrong Answer

Solution code:

import collections

n = int(input())

inp_list = list(map(int,input().split()))
inp_list.append(0)

c = collections.Counter(inp_list)
a = c.most_common()

def ura(time):
   if time == 12:
       time = 12
   elif time == 0:
       time = 0
   else:
       time = 24- time

   return time


member = []

for tup in a:
   if tup[1]>1:
       member.append(tup[0])
       member.append(tup[0])
   elif tup[1] == 1:
       member.append(tup[0])



ans = 0

for i in range(2**len(member)):
	trry = format(i, '0'+ str(len(member))+'b')
	time_diff = 24
	
	for ii in range(len(member)-1):
		for iii in range(ii+1,len(member)):
			A=member[ii]
			if trry[iii]=='0':
				B=member[iii]
			else:
				B=ura(member[iii])
			a_b = abs(A-B)
			b_a = min(A,B)+24-max(A,B)
			time_diff=min(time_diff,a_b,b_a)
			
	ans = max(ans,time_diff)
	
print(ans)

Submission status: Wrong Answer

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

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

hour = [0]
last = []
for d in D:
    back = minGap(hour + [d])
    front = minGap(hour + [24 - d])
    if back > front:
        hour += [d]
    elif back < front:
        hour += [24 - d]
    else:
        last.append(d)

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

ans = minGap(hour)

print(ans)

Submission status: Wrong Answer

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

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

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

print(ans)

Submission status: Wrong Answer

Solution code:

import collections

n = int(input())

inp_list = list(map(int,input().split()))
inp_list.append(0)

c = collections.Counter(inp_list)
a = c.most_common()

def ura(time):
   if time == 12:
       time = 12
   elif time == 0:
       time = 0
   else:
       time = 24- time

   return time


member = []

for tup in a:
   if tup[1]>1:
       member.append(tup[0])
       member.append(tup[0])
   elif tup[1] == 1:
       member.append(tup[0])



ans = 0

for i in range(2**len(member)):
	trry = format(i, '0'+ str(len(member))+'b')
	time_diff = 24
	
	for ii in range(len(member)-1):
		for iii in range(ii+1,len(member)):
			A=member[ii]
			if trry[iii]=='0':
				B=member[iii]
			else:
				B=ura(member[iii])
			a_b = abs(A-B)
			time_diff=min(time_diff,a_b)
			
	ans = max(ans,time_diff)
	
print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
D=list(map(int,input().split()))
r=12
t=[0,24]
from bisect import bisect_left,bisect_right
for d in D:
    x=bisect_right(t,d)
    y=bisect_left(t,24-d)
    if min(d-t[x-1],t[x]-d)<min(24-d-t[y-1],t[y]-24+d):
        r=min(r,24-d-t[y-1],t[y]-24+d)
        t.insert(y,24-d)
    else:
        r=min(r,d-t[x-1],t[x]-d)
        t.insert(x,d)
print(r)

Submission status: Wrong Answer

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

line=[1]+[0]*12
clock = [0]*24
D.sort()
tag=0
ans=25
ansL=[]

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

if(line[0]>=2 or line[12]>=2):
    ans=0
else:
    #lineを円周上の時計に置き換える
    clock[0]=1
    for i in range(1, len(line)):
        if (line[i] > 2):#線上に３人以上 ->どうやっても同時刻に２人以上存在することになるのでans=0
            ans = 0
            break
        elif (line[i] == 2): #線上に２人
            clock[i] = 1
            clock[24 - i] = 1
        elif (line[i] == 1):#線上に１人 ー＞交互に
            if (tag == 0):
                clock[i] = 1
            else:
                clock[24 - i] = 1
            tag += 1

    #one-hotベクトルに変換
    for i in range(len(clock)):
        if(clock[i]==1):
            ansL.append(i)

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

print(ans)

Submission status: Wrong Answer

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

D.append(0)
line=[0]*13
clock = [0]*24
D.sort()
tag=0
ans=25
ansL=[]

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

if(line[0]>=2 or line[12]>=2):
    ans=0
else:
    #円周上の時計に置き換える
    clock[0]=1
    for i in range(1, len(line)):
        if (line[i] > 2):#線上に３人以上 ->どうやっても同時刻に２人以上存在することになるのでans=0
            ans = 0
            break
        elif (line[i] == 2): #線上に２人
            clock[i] = 1
            clock[24 - i] = 1
        elif (line[i] == 1):#線上に１人 ー＞交互に
            if (tag == 0):
                clock[i] = 1
            else:
                clock[24 - i] = 1
            tag += 1

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

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

print(ans)

Submission status: Wrong Answer

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

D.append(0)
line=[0]*13
clock = [0]*24
D.sort()
tag=0
ans=25
ansL=[]

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

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

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

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

#int(ansL)
print(ans)

Submission status: Wrong Answer

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

D.append(0)
line=[0]*13
clock = [0]*24
D.sort()
tag=0
ans=25
ansL=[]

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

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

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

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

#int(ansL)
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys

#+++++

def dd_max(di, dj):
	if di==0:
		ss=[0]
	else:
		ss=[di, 24-di]
		
	if dj == 0:
		dd=[0]
	else:
		dd=[dj,24-dj]
		
	ret=0
	for i in ss:
		for j in dd:
			ma=max(i,j)-min(i, j)
			mm=min(ma, 24-ma)
			ret = max(mm, ret)
		
	return ret
	
		
def main():
	n = int(input())
	dl = list(map(int, input().split()))
	dl.append(0)
	
	
	mii=25
	for i,di in enumerate(dl):
		for j, dj in enumerate(dl):
			if i == j:
				continue
			ee=dd_max(di,dj)
			mii = min(mii, ee)
			
	print(mii)
	
	
#+++++
isTest=False

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

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

Submission status: Wrong Answer

Solution code:
import sys

#+++++

def dd_max(di, dj):
	if di==0:
		ss=[0]
	else:
		ss=[di, 24-di]
		
	if dj == 0:
		dd=[0]
	else:
		dd=[dj,24-dj]
		
	ret=0
	for i in ss:
		for j in dd:
			ma=max(i,j)-min(i, j)
			mb=(24-max(i, j))+min(i, j)
			mm=min(ma,mb)
			ret = max(mm, ret)
		
	return ret
	
		
def main():
	n = int(input())
	dl = list(map(int, input().split()))
	dl.append(0)
	
	
	mii=25
	for i,di in enumerate(dl):
		for j, dj in enumerate(dl):
			if i == j:
				continue
			ee=dd_max(di,dj)
			mii = min(mii, ee)
			
	print(mii)
	
	
#+++++
isTest=False

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

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

Submission status: Wrong Answer

Solution code:
def diff(s, t):
    return min(abs(s-t), 24 - abs(s-t))

for i in range(0, 25):
    for j in range(0, 25):
        assert diff(i, j) == diff(j, i)
        assert 0 <= diff(i, j) <= 12

def main():
    N = int(input())
    D = [int(x) for x in input().split()]
    print(solve(D))

def solve(D):
    def max(x, y):
        if x == y:
            return x
        if x is None:
            return y
        if y is None:
            return x
        return x if x > y else y

    def check(d, di, dj, i, j):
        for k in range(N):
            if k == i or k == j:
                continue
            if diff(D[k], di) < d:
                return False
            if diff(D[k], dj) < d:
                return False
        return True

    D = [0]+D
    D.sort()
    N = len(D)
    answer = None
    for i in range(N):
        Di = D[i]
        Di_ = 24 - D[i]
        for j in range(i+1, N):
            Dj = D[j]
            Dj_ = 24 - D[j]

            m = None
            for di, dj in [(Di, Dj), (Di_, Dj), (Di, Dj_), (Di_, Dj_)]:
                Dij = diff(di, dj)
                if not check(Dij, di, dj, i, j):
                    continue
                m = max(m, Dij)
            answer = max(answer, m)

            #print(answer, m)
    if answer is None:
        None[1]
    return answer

def test(D):
    import sys
    print("DEBUG", D, solve(D), file=sys.stderr)
test([7, 8, 12])
test([11, 11])
test([11, 11, 11])
test([0])
main()

Submission status: Wrong Answer

Solution code:
def diff(s, t):
    return min(abs(s-t), 24 - abs(s-t))
def main():
    N = int(input())
    D = [int(x) for x in input().split()]
    print(solve(D))

def solve(D):
    def check(d, di, dj, i, j):
        for k in range(N):
            if k == i or k == j:
                continue
            if diff(D[k], di) < d:
                return None
            if diff(D[k], dj) < d:
                return None
        return d

    D = [0]+D
    D.sort()
    N = len(D)
    answer = None
    for i in range(N):
        Di = D[i]
        Di_ = 24 - D[i]
        for j in range(i+1, N):
            Dj = D[j]
            Dj_ = 24 - D[j]

            m = None
            for di, dj in [(Di, Dj), (Di_, Dj), (Di, Dj_), (Di_, Dj_)]:
                Dij = diff(di, dj)
                dm = check(Dij, di, dj, i, j)
                #print(D, "\t", (i, j), "diff(%2d, %2d) = %2d "%(di, dj, Dij), dm, m)
                if dm is None:
                    continue
                if m is None:
                    m = dm
                m = max(m, dm)
            if answer is None and m is not None:
                answer = m
            answer = max(answer, m) if m else answer
            #print(answer, m)
    if answer is None:
        None[1]
    return answer

def test(D):
    print(D, solve(D))
#test([7, 8, 12])
#test([11, 11])
#test([11, 11, 11])
#test([0])
main()