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 itertools

N,*D = map(int,open(0).read().split())
lst = []
if D.count(0) >= 1 or D.count(24) >= 1 or D.count(12) >= 2:
    print(0)
    exit()
if D.count(12) == 1:
    lst.append([12])
lst.append([0,24])

for i in range(1,12):
    i_24 = 24 - i
    if i_24 in D:
        D.append(i)
    cnt = D.count(i)    
    if cnt == 1:
        lst.append([i,i_24])
    elif cnt == 2:
        lst.append([i])
        lst.append([i_24])
    elif cnt >= 3:
        print(0)
        exit()

min_list = []
for i in itertools.product(*lst):
    s = 24
    comb = itertools.combinations(i,2)
    for a,b in comb:
        s = min(abs(b - a), s)
    min_list.append(s)    
print(max(min_list))

Submission status: Wrong Answer

Solution code:
import itertools
from collections import Counter

N,*D = map(int,open(0).read().split())
D.append(0)
if N == 1:
    print(min(D[0],24 - D[0]))
    exit()
  
c = Counter(D)
for i in c:
    if c[i] > 2 or ((i == 12 or i == 0) and c[i] == 2) or (i == 24 and c[i] >= 1):
        print(0)
        exit()
        
arr = []
for i in c:
    if i == 12 or i == 0:
        arr.append([i])
    elif c[i] == 2:
        arr.append([i])
        arr.append([24 - i])
    else:
        arr.append([i, 24 - i])

min_list = []
for i in itertools.product(*arr):
    s = 25
    for a,b in itertools.combinations(i,2):
        
        s = min(abs(a-b),s)
    min_list.append(s)
    
print(max(min_list))

Submission status: Wrong Answer

Solution code:
import itertools
from collections import Counter

N,*D = map(int,open(0).read().split())
D.append(0)
if N == 1:
    print(min(D[0],24 - D[0]))
    exit()
  
c = Counter(D)
for i in c:
    if c[i] > 2 or ((i == 12 or i == 0) and c[i] == 2) or (i == 24 and c[i] >= 1):
        print(0)
        exit()
        
arr = []
for i in c:
    if i == 12 or i == 0:
        arr.append([i])
    elif c[i] == 2:
        arr.append([i, 24 - i])
        arr.append([i, 24 - i])
    else:
        arr.append([i, 24 - i])

min_list = []
for i in itertools.product(*arr):
    s = 25
    for a,b in itertools.combinations(i,2):
        
        s = min(abs(a-b),s)
    min_list.append(s)
    
print(max(min_list))

Submission status: Wrong Answer

Solution code:
import itertools
from collections import Counter

N,*D = map(int,open(0).read().split())
D.append(0)
if N == 1:
    print(min(D[0],24 - D[0]))
    exit()
  
c = Counter(D)
for i in c:
    if (i == 12 and c[i] >= 2) or c[i] > 2:
        print(0)
        exit()
        
arr = []
for i in c:
    if i == 12:
        arr.append([i])
    else:
        arr.append([i, 24 - i])

min_list = []
for i in itertools.product(*arr):
    s = 24
    for a,b in itertools.combinations(i,2):
        s = min(abs(a-b),s)
    min_list.append(s)
    
print(max(min_list))

Submission status: Wrong Answer

Solution code:
import itertools
from collections import Counter

N,*D = map(int,open(0).read().split())
D.append(0)
if N == 1:
    print(min(D[0],24 - D[0]))
    exit()
  
c = Counter(D)
for i in c:
    if (i == 12 and c[i] >= 2) or c[i] > 2 or i == 0 or i == 24:
        print(0)
        exit()
        
arr = []
for i in c:
    if i == 12:
        arr.append([i])
    else:
        arr.append([i, 24 - i])

min_list = []
for i in itertools.product(*arr):
    s = 24
    for a,b in itertools.combinations(i,2):
        s = min(abs(a-b),s)
    min_list.append(s)
    
print(max(min_list))

Submission status: Wrong Answer

Solution code:
import itertools
from collections import Counter

N,*D = map(int,open(0).read().split())
D.append(0)
if N == 1:
    print(min(D[0],24 - D[0]))
    exit()
  
c = Counter(D)
for i in c:
    if (i == 12 and c[i] >= 2) or c[i] > 2 or i == 0:
        print(0)
        exit()
        
arr = []
for i in c:
    if i == 12:
        arr.append([i])
    else:
        arr.append([i, 24 - i])

min_list = []
for i in itertools.product(*arr):
    s = 24
    for a,b in itertools.combinations(i,2):
        s = min(abs(a-b),s)
    min_list.append(s)
    
print(max(min_list))

Submission status: Wrong Answer

Solution code:
import itertools
from collections import Counter

N,*D = map(int,open(0).read().split())
D.append(0)
if N == 1:
    print(min(D[0],24 - D[0]))
    exit()
#D.sort    
c = Counter(D)
for i in c:
    if (i == 12 and c[i] >= 2) or c[i] > 2 or c[i] == 0:
        print(0)
        exit()
        
arr = []
for i in c:
    if i == 12:
        arr.append([i])
    else:
        arr.append([i, 24 - i])

min_list = []
for i in itertools.product(*arr):
    s = 24
    for a,b in itertools.combinations(i,2):
        s = min(abs(a-b),s)
    min_list.append(s)
    
print(max(min_list))

Submission status: Wrong Answer

Solution code:
import itertools
from collections import Counter

N,*D = map(int,open(0).read().split())
D.append(0)
if N == 1:
    print(min(D[0],24 - D[0]))
    exit()
D.sort    
c = Counter(D)
for i in c:
    if i == 12 and c[i] >= 2:
        print(0)
        exit()
    if c[i] > 2:
        print(0)
        exit()
        
arr = []
for i in c:
    for j in range(c[i]):
        arr.append([i, 24 - i])

p = itertools.product(*arr)
min_list = []
for i in p:
    s = 24
    for a,b in itertools.combinations(i,2):
        s = min(abs(a-b),s)
    min_list.append(s)
print(max(min_list))

Submission status: Wrong Answer

Solution code:
import itertools
from collections import Counter

N,*D = map(int,open(0).read().split())
D.append(0)
if N == 1:
    print(min(D[0],24 - D[0]))
    exit()
D.sort    
c = Counter(D)
for i in c:
    if c[i] > 2:
        print(0)
        exit()
        
arr = []
for i in c:
    for j in range(c[i]):
        arr.append([i, 24 - i])

p = itertools.product(*arr)
min_list = []
for i in p:
    s = 24
    for a,b in itertools.combinations(i,2):
        s = min(abs(a-b),s)
    min_list.append(s)
print(max(min_list))

Submission status: Wrong Answer

Solution code:
import itertools
from collections import Counter

N,*D = map(int,open(0).read().split())

if N == 1:
    print(min(D[0],24 - D[0]))
    exit()
    
c = Counter(D)
for i in c:
    if c[i] > 2:
        c[i] = 2
        
arr = []
for i in c:
    for j in range(c[i]):
        arr.append([i, 24 - i])

p = itertools.product(*arr)
min_list = []
for i in p:
    s = 24
    for a,b in itertools.combinations(i,2):
        s = min(abs(a-b),s)
    min_list.append(s)
print(max(min_list))

Submission status: Wrong Answer

Solution code:
import itertools
from collections import Counter

N,*D = map(int,open(0).read().split())

if N == 1:
    print(min(D[0],24 - D[0]))
    exit()
    
c = Counter(D)
for i in c:
    if c[i] > 2:
        c[i] = 2
        
arr = []
for i in c:
    for j in range(c[i]):
        arr.append([i, 24 - i])

p = itertools.product(*arr)
min_list = []
for i in p:
    s = 24
    for a,b in itertools.combinations(i,2):
        s = min(abs(a-b),s)
    min_list.append(s)
print(max(min_list))

Submission status: Wrong Answer

Solution code:
import collections
N=int(input())
D=list(map(int,input().split()))
c=collections.Counter(D)
count0=0
count12=0
l=[]
if c[0]>0:
    count0=1
if c[12]>0:
    count12=1
for i in range(1,12):
    if c[i]>=1:
        l.append([i,24-i])
    if c[i]>=2:
        l.append([i,24-i])
#print(l,count0,count12)
n=len(l)
#print(n)
allmax=0
for i in range(pow(2,n)):
    buf=[0]
    bit=[0]*n
    mi=100
    if count12==1:
        buf.append(12)
    if count0==1:
        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:
# 7,12,18
# ありうるのは、(7,17),(12,12),(8,16)
# ......AC...B...CA.......
# 7,12,16を選んだとき
# ......A_...B...C_.......
# BとCの差が4時間になる
# 17,12,8でもよい
# ......_C...B..._A.......
# 50人存在するが、時刻は0-23の24通り (ただし高橋くんは0固定なので、それ以外の人は23通り)
# N = 24人になったら鳩ノ巣理論により必ず誰かが同じ時刻になるため、答えは0
# 23人以下の場合は、全組み合わせ（2^23 = (10 ** 6) * 8）を試せば良い

N = int(input())
D = list(map(int,input().split()))
if N >= 24:
  print(0)
  exit(0)
# 23桁のbit文字列で0の場合はそのまま、1の場合はひっくり返す（24-D[i]）
# []24桁のリスト(0は高橋くんがいるため初めから1人)に、人数を加算していく
# あるindexですでに人がいたらその時点で答えは0になる
# 最小値を更新していく
ans = 0

for i in range(2 ** N):
  data = [0] * 24
  data[0] = 1 # 高橋くん
  for j in range(N):
    if (i >> j)&1:
      if data[(24-D[j]) % 24] == 1: # 0時の場合にindexが24にならないように%24している
        break # 同時刻に既に誰かいた時点で最小値は0確定
      data[(24-D[j]) % 24] += 1
    else:
      if data[D[j] % 24] == 1: # この時点で最小値は0確定
        break
      data[D[j] % 24] += 1
  else:
    # 最小値が0でない場合
    minval = 24
    lastexist = 0
    for j in range(1,len(data)):
      if data[j]:
        if j - lastexist < minval:
          minval = j - lastexist
        lastexist = j
    if minval > ans:
      ans = minval
print(ans)

Submission status: Wrong Answer

Solution code:
import copy
N = int(input())
Dn = list(map(int,input().split(' ')))
d_map = {}
for d in Dn:
    if d not in d_map:
        d_map[d] = 1
    else:
        d_map[d] += 1
if 0 in d_map:
    print(0)
    exit(0)
if len(Dn) == 1:
    print(Dn[0])
    exit(0)
for v in d_map.values():
    if 3 <= v:
        print(0)
        exit(0)
all_combination = [ [0] ]
for k,v in d_map.items():
    if v == 1:
        len_all_combination = len(all_combination)
        for i in range(len_all_combination):
            tmp = copy.deepcopy(all_combination[i])
            all_combination[i].append(k)
            tmp.append(24-k)
            all_combination.append(tmp)
    else:
        for comb in all_combination:
            comb.append(k)
            comb.append(24-k)
ans = -1
for comb in all_combination:
    comb.sort()
    #print(comb)
    tmp = 100
    for i in range(1,len(comb)):
        tmp = min(tmp,comb[i]-comb[i-1])
    ans = max(ans,tmp)
print(ans)

Submission status: Wrong Answer

Solution code:
import copy
N = int(input())
Dn = list(map(int,input().split(' ')))
d_map = {0:1}
for d in Dn:
    if d not in d_map:
        d_map[d] = 1
    else:
        d_map[d] += 1
for v in d_map.values():
    if 3 <= v:
        print(0)
        exit(0)
cal_cnt = 0
for k,v in d_map.items():
    if v == 1:
        cal_cnt += 1
all_combination = [ [] ]
for k,v in d_map.items():
    if v == 1:
        len_all_combination = len(all_combination)
        for i in range(len_all_combination):
            tmp = copy.deepcopy(all_combination[i])
            all_combination[i].append(k)
            tmp.append(24-k)
            all_combination.append(tmp)
    else:
        for comb in all_combination:
            comb.append(k)
            comb.append(24-k)
ans = -1
for comb in all_combination:
    comb.sort()
    tmp = 100
    for i in range(1,len(comb)):
        tmp = min(tmp,comb[i]-comb[i-1])
    ans = max(ans,tmp)
print(ans)

Submission status: Wrong Answer

Solution code:
import copy
N = int(input())
Dn = list(map(int,input().split(' ')))
d_map = {}
for d in Dn:
    if d not in d_map:
        d_map[d] = 1
    else:
        d_map[d] += 1
if 0 in d_map:
    print(0)
    exit(0)
for v in d_map.values():
    if 3 <= v:
        print(0)
        exit(0)
cal_cnt = 0
for k,v in d_map.items():
    if v == 1:
        cal_cnt += 1
all_combination = [ [0] ]
for k,v in d_map.items():
    if v == 1:
        len_all_combination = len(all_combination)
        for i in range(len_all_combination):
            tmp = copy.deepcopy(all_combination[i])
            all_combination[i].append(k)
            tmp.append(24-k)
            all_combination.append(tmp)
    else:
        for comb in all_combination:
            comb.append(k)
            comb.append(24-k)
ans = -1
for comb in all_combination:
    comb.sort()
    tmp = 100
    for i in range(1,len(comb)):
        tmp = min(tmp,comb[i]-comb[i-1])
    ans = max(ans,tmp)
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
Dn = list(map(int,input().split(' ')))
if 24 <= N:
    print(0)
else:
    print(0)

Submission status: Wrong Answer

Solution code:
N = int(input())
Dn = list(map(int,input().split(' ')))
if 24 <= N:
    print(0)
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
from collections import Counter
N = int(input())
D = list(map(int, input().split()))
D.sort()
d = [0]*25
d[0] = d[-1] = 1
for i in range(N):
    if i & 1:
        d[D[i]] += 1
    else:
        d[24-D[i]] += 1
for i in range(25):
    if d[i] > 1:
        print(0)
        exit()
print(d)
last, ans = 0, 24
for i in range(1, 25):
    if d[i]:
        ans = min(i-last, ans)
        last = i
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
D = [0] + list(map(int, input().split()))
Diffs = [[[0, 0] for i in range(N+1)] for j in range(N+1)]

candidates = []
for i in range(N+1):
  for j in range(i+1, N+1):
    di, dj = D[i], D[j]
    diff1, diff2 = abs(di-dj), min(24-di-dj, di+dj)
    candidates.extend([[i, j, diff1, 0], [i, j, diff2, 1]])
    Diffs[i][j] = [diff1, diff2]

ans = 0
for idx1, idx2, diff, c in candidates:
  conditions = [-1] * (N+1)
  if c == 0:
    conditions[idx1] = conditions[idx2] = 0
  else:
    conditions[idx1] = 0; conditions[idx2] = 1
  res = True
  for i in range(N+1):
    for j in range(i+1, N+1):
      if idx1 == i and idx2 == j:
        continue
      diff1, diff2 = Diffs[i][j]
      if diff1 < diff and diff2 < diff:
        res = False
        break
      elif diff1 < diff:
        c1, c2 = conditions[i], conditions[j]
        if c1 < 0 and c2 < 0:
          conditions[i] = conditions[j] = 0
        elif c1 < 0:
          conditions[i] = c2
        elif c2 < 0:
          conditions[j] = c1
        else:
          if c1 != c2:
            res = False
            break
      elif diff2 < diff:
        c1, c2 = conditions[i], conditions[j]
        if c1 < 0 and c2 < 0:
          conditions[i] = 0; conditions[j] = 1
        elif c1 < 0:
          conditions[i] = 1 - c2
        elif c2 < 0:
          conditions[j] = 1 - c1
        else:
          if c1 == c2:
            res = False
            break
    else:
      continue
    break
  if res:
    ans = max(ans, diff)

print(ans)

Submission status: Wrong Answer

Solution code:
from itertools import combinations

N = int(input())
D = [0] + list(map(int, input().split()))
Diffs = [[[0, 0] for i in range(N+1)] for j in range(N+1)]

candidates = []
for i in range(N+1):
  for j in range(i+1, N+1):
    di, dj = D[i], D[j]
    diff1, diff2 = abs(di-dj), min(24-di-dj, di+dj)
    candidates.extend([[i, j, diff1], [i, j, diff2]])
    Diffs[i][j] = [diff1, diff2]

ans = 0
for idx1, idx2, diff in candidates:
  conditions = [-1] * (N+1)
  res = True
  for i in range(N+1):
    for j in range(i+1, N+1):
      if idx1 == i and idx2 == j:
        continue
      diff1, diff2 = Diffs[i][j]
      if diff1 < diff and diff2 < diff:
        res = False
        break
      elif diff1 < diff:
        c1, c2 = conditions[i], conditions[j]
        if c1 < 0 and c2 < 0:
          conditions[i] = conditions[j] = 0
        elif c1 < 0:
          conditions[i] = c2
        elif c2 < 0:
          conditions[j] = c1
        else:
          if c1 != c2:
            res = False
            break
      elif diff2 < diff:
        c1, c2 = conditions[i], conditions[j]
        if c1 < 0 and c2 < 0:
          conditions[i] = 0; conditions[j] = 1
        elif c1 < 0:
          conditions[i] = 1 - c2
        elif c2 < 0:
          conditions[j] = 1 - c1
        else:
          if c1 == c2:
            res = False
            break
    else:
      continue
    break
  if res:
    ans = max(ans, diff)

print(ans)

Submission status: Wrong Answer

Solution code:
from itertools import product
from collections import Counter


def solve():
    N = int(input())
    *D, = map(int, input().split())

    l, m = [], []
    for i, j in Counter(D).items():
        if j>=3 or (i==12 and j>=2) or i==0:
            print(0)
            return
        elif j==2:
            l.append(i)
        elif j==1:
            m.append(i)

    size = len(m)
    ans = 0

    for i in product(range(2), repeat=size):
        c = []
        for j, k in enumerate(i):
            if k or (m[j]==0 or m[j]==12):
                c.append(m[j])
            else:
                c.append(24-m[j])
        for j in l:
            c.append(j)
            c.append(24-j)

        v = min(c)
        for j in range(N):
            for k in range(j+1, N):
                d = abs(c[j]-c[k])
                v = min(v, min(d, 24-d))
        ans = max(ans, v)

    print(ans)


if __name__ == "__main__":
    solve()

Submission status: Wrong Answer

Solution code:
from itertools import product
from collections import Counter


def solve():
    N = int(input())
    *D, = map(int, input().split())

    if N==1:
        print(D[0])
        return
    else:
        l, m = [], []
        for i, j in Counter(D).items():
            if j>=3 or ((i==0 or i==12) and j>=2):
                print(0)
                return
            elif j==2:
                l.append(i)
            elif j==1:
                m.append(i)

    size = len(m)
    ans = 0

    for i in product(range(2), repeat=size):
        c = []
        for j, k in enumerate(i):
            if k or (m[j]==0 or m[j]==12):
                c.append(m[j])
            else:
                c.append(24-m[j])
        for j in l:
            c.append(j)
            c.append(24-j)

        v = min(c)
        for j in range(N):
            for k in range(j+1, N):
                d = abs(c[j]-c[k])
                v = min(v, min(d, 24-d))
        ans = max(ans, v)

    print(ans)


if __name__ == "__main__":
    solve()

Submission status: Wrong Answer

Solution code:
from itertools import product
from collections import Counter


def solve():
    N = int(input())
    *D, = map(int, input().split())

    if N==1:
        print(D[0])
        return
    else:
        l, m = [], []
        for i, j in Counter(D).items():
            if j>=3 or ((i==0 or i==12) and j>=2):
                print(0)
                return
            elif j==2:
                l.append(i)
            elif j==1:
                m.append(i)

    size = len(m)
    ans = 0

    for i in product(range(2), repeat=size):
        c = []
        for j, k in enumerate(i):
            if k or (m[j]==0 or m[j]==12):
                c.append(m[j])
            else:
                c.append(24-m[j])
        for j in l:
            c.append(j)
            c.append(24-j)

        v = 24
        for j in range(N):
            for k in range(j+1, N):
                d = abs(c[j]-c[k])
                v = min(v, min(d, 24-d))
        ans = max(ans, v)

    print(ans)


if __name__ == "__main__":
    solve()

Submission status: Wrong Answer

Solution code:
from itertools import product
from collections import Counter


def solve():
    N = int(input())
    *D, = map(int, input().split())

    if N==1:
        print(D[0])
        return
    else:
        l, m = [], []
        for i, j in Counter(D).items():
            if j>=3 or ((i==0 or i==12) and j>=2):
                print(0)
                return
            elif j==2:
                l.append(i)
            elif j==1:
                m.append(i)

    size = len(m)
    ans = 0

    for i in product(range(2), repeat=size):
        c = []
        for j, k in enumerate(i):
            if k:
                c.append(m[j])
            else:
                c.append(24-m[j])
        for j in l:
            c.append(j)
            c.append(24-j)

        v = 24
        for j in range(N):
            for k in range(j+1, N):
                d = abs(c[j]-c[k])
                v = min(v, min(d, 24-d))
        ans = max(ans, v)

    print(ans)


if __name__ == "__main__":
    solve()

Submission status: Wrong Answer

Solution code:
from itertools import product
from collections import Counter


def solve():
    N = int(input())
    *D, = map(int, input().split())

    if N==1:
        print(D[0])
        return
    else:
        l, m = [], []
        for i, j in Counter(D).items():
            if j>=3 or ((i==0 or i==12) and j>=2):
                print(0)
                return
            elif j==2:
                l.append(i)
            elif j==1:
                m.append(i)

    size = len(m)
    ans = 0

    for i in product(range(2), repeat=size):
        c = []
        for j, k in enumerate(i):
            if k:
                c.append(m[j])
            else:
                c.append(24-m[j])
        for j in l:
            c.append(j)
            c.append(24-j)

        v = 24
        for j in range(N):
            for k in range(j+1, N):
                v = min(v, abs(c[j]-c[k]))
        ans = max(ans, v)

    print(ans)


if __name__ == "__main__":
    solve()

Submission status: Wrong Answer

Solution code:
from itertools import product
from collections import Counter


def solve():
    N = int(input())
    *D, = map(int, input().split())

    if N==1:
        print(D[0])
        return
    else:
        l, m = [], []
        for i, j in Counter(D).items():
            if j>=3 or ((i==0 or i==12) and j>=2):
                print(0)
            elif j==2:
                l.append(i)
            elif j==1:
                m.append(i)

    size = len(m)
    ans = 0

    for i in product(range(2), repeat=size):
        c = []
        for j, k in enumerate(i):
            if k:
                c.append(m[j])
            else:
                c.append(24-m[j])
        for j in l:
            c.append(j)
            c.append(24-j)

        v = 24
        for j in range(N):
            for k in range(j+1, N):
                v = min(v, abs(c[j]-c[k]))
        ans = max(ans, v)

    print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter


def solve():
    N = int(input())
    *D, = map(int, input().split())

    if N==1:
        print(D[0])
    else:
        for i, j in Counter(D).items():
            if j>=3 or (j>=2 and i==12) or i==0:
                print(0)
                return

        ans = 24
        for i in range(N):
            v = 24 - D[i]
            s = v
            for j in range(N):
                if j==i:continue
                s = min(s, v-D[j])
                s = min(s, D[j])
            ans = min(ans, s)
        print(ans)


if __name__ == "__main__":
    solve()

Submission status: Wrong Answer

Solution code:
from collections import Counter


def solve():
    N = int(input())
    *D, = map(int, input().split())

    if N==1:
        print(D[0])
    else:
        for i, j in Counter(D).items():
            if j>=3 or (j>=2 and i==12):
                print(0)
                return

        ans = 24
        for i in range(N):
            v = 24 - D[i]
            s = v
            for j in range(N):
                if j==i:continue
                s = min(s, v-D[j])
                s = min(s, D[j])
            ans = min(ans, s)
        print(ans)


if __name__ == "__main__":
    solve()

Submission status: Wrong Answer

Solution code:
from collections import Counter


def solve():
    N = int(input())
    *D, = map(int, input().split())

    if N==1:
        print(D[0])
    else:
        for i in Counter(D).values():
            if i>=3:
                print(0)
                return

        ans = 24
        for i in range(N):
            v = 24 - D[i]
            s = v
            for j in range(N):
                if j==i:continue
                s = min(s, v-D[j])
                s = min(s, D[j])
            ans = min(ans, s)
        print(ans)


if __name__ == "__main__":
    solve()

Submission status: Wrong Answer

Solution code:
from itertools import combinations

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

if N==1:
    print(min(D[0], 24-D[0]))
else:
    ans = 24
    for i in range(N):
        v = 24 - D[i]

        s = v
        for j in range(N):
            if j==i:continue
            s = min(s, v-D[j])
            s = min(s, D[j])
        ans = min(ans, s)
    print(ans)

Submission status: Wrong Answer

Solution code:
from itertools import combinations

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

if N==1:
    print(min(D[0], 24-D[0]))
else:
    ans = 24
    for i in range(N):
        v = 24 - D[i]
        s = 24

        for j in range(N):
            if j==i:continue
            s = min(s, v-D[j])
            s = min(s, D[j])
        ans = min(ans, s)
    print(ans)

Submission status: Wrong Answer

Solution code:
from itertools import combinations

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

if N==1:
    print(min(D[0], 24-D[0]))
else:
    ans = 24
    *e, = map(lambda x:abs(x-12), D)
    for i in combinations(e, 2):
        ans = min(ans, sum(i))
    print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
D = list(map(int,input().split()))
kouho_1 = [0]*(n+1)
kouho_2 = [0]*(n+1)
flag = False
for i in range(n):
    if D[i] == 0:
        kouho_1[i+1] = 0
    elif D[i] == 12:
        kouho_1[i+1] = 12
    else:
        if not flag:
            flag = True
            kouho_1[i+1] = D[i]
        else:
            cur1 = 24
            temp1 = D[i]
            cur2 = 24
            temp2 = 24-D[i]
            for j in range(i+1):
                cur1 = min(cur1, abs(kouho_1[j]-temp1), 24-abs(kouho_1[j]-temp1))
            for j in range(i+1):
                cur2 = min(cur2, abs(kouho_1[j]-temp2), 24-abs(kouho_1[j]-temp2))
            if cur1 > cur2:
                kouho_1[i+1] = temp1
            else:
                kouho_1[i+1] = temp2
flag = False
for i in range(n):
    if D[i] == 0:
        kouho_2[i+1] = 0
    elif D[i] == 12:
        kouho_2[i+1] = 12
    else:
        if not flag:
            flag = True
            kouho_2[i+1] = 24-D[i]
        else:
            cur1 = 24
            temp1 = D[i]
            cur2 = 24
            temp2 = 24-D[i]
            for j in range(i+1):
                cur1 = min(cur1, abs(kouho_2[j]-temp1), 24-abs(kouho_2[j]-temp1))
            for j in range(i+1):
                cur2 = min(cur2, abs(kouho_2[j]-temp2), 24-abs(kouho_2[j]-temp2))
            if cur1 > cur2:
                kouho_2[i+1] = temp1
            else:
                kouho_2[i+1] = temp2
ans1 = min(24-abs(kouho_1[0]-kouho_1[1]),abs(kouho_1[0]-kouho_1[1]))
ans2 = min(24-abs(kouho_2[0]-kouho_2[1]),abs(kouho_2[0]-kouho_2[1]))
for i in range(n+1):
    for j in range(i+1, n+1):
        ans1 = min(ans1, abs(kouho_1[i]-kouho_1[j]), 24-abs(kouho_1[i]-kouho_1[j]))
        ans2 = min(ans2, abs(kouho_2[i]-kouho_2[j]), 24-abs(kouho_2[i]-kouho_2[j]))
print(max(ans1,ans2))

Submission status: Wrong Answer

Solution code:
n = int(input())
D = list(map(int,input().split()))
kouho_1 = [0]*(n+1)
kouho_2 = [0]*(n+1)
flag = False
for i in range(n):
    if D[i] == 0:
        kouho_1[i+1] = 0
    elif D[i] == 12:
        kouho_1[i+1] = 12
    else:
        if not flag:
            flag = True
            kouho_1[i+1] = D[i]
        else:
            cur1 = 24
            temp1 = D[i]
            cur2 = 24
            temp2 = 24-D[i]
            for j in range(i+1):
                cur1 = min(cur1, abs(kouho_1[j]-temp1))
            for j in range(i+1):
                cur2 = min(cur2, abs(kouho_1[j]-temp2))
            if cur1 > cur2:
                kouho_1[i+1] = temp1
            else:
                kouho_1[i+1] = temp2
flag = False
for i in range(n):
    if D[i] == 0:
        kouho_2[i+1] = 0
    elif D[i] == 12:
        kouho_2[i+1] = 12
    else:
        if not flag:
            flag = True
            kouho_2[i+1] = 24-D[i]
        else:
            cur1 = 24
            temp1 = D[i]
            cur2 = 24
            temp2 = 24-D[i]
            for j in range(i+1):
                cur1 = min(cur1, abs(kouho_2[j]-temp1))
            for j in range(i+1):
                cur2 = min(cur2, abs(kouho_2[j]-temp2))
            if cur1 > cur2:
                kouho_2[i+1] = temp1
            else:
                kouho_2[i+1] = temp2
ans1 = min(24-abs(kouho_1[0]-kouho_1[1]),abs(kouho_1[0]-kouho_1[1]))
ans2 = min(24-abs(kouho_2[0]-kouho_2[1]),abs(kouho_2[0]-kouho_2[1]))
for i in range(n+1):
    for j in range(i+1, n+1):
        ans1 = min(ans1, abs(kouho_1[i]-kouho_1[j]), 24-abs(kouho_1[i]-kouho_1[j]))
        ans2 = min(ans2, abs(kouho_2[i]-kouho_2[j]), 24-abs(kouho_2[i]-kouho_2[j]))
print(max(ans1,ans2))

Submission status: Wrong Answer

Solution code:
n = int(input())
D = list(map(int,input().split()))
kouho_1 = [0]*(n+1)
kouho_2 = [0]*(n+1)
flag = False
change = 0
if n >= 24:
    print(0)
    exit()
for i in range(n):
    if D[i] == 0:
        kouho_1[i+1] = 0
    elif D[i] == 12:
        kouho_1[i+1] = 12
    else:
        if not flag:
            flag = True
            kouho_1[i+1] = D[i]
        else:
            cur1 = 24
            temp1 = D[i]
            cur2 = 24
            temp2 = 24-D[i]
            for j in range(i+1):
                cur1 = min(cur1, abs(kouho_1[j]-temp1))
            for j in range(i+1):
                cur2 = min(cur2, abs(kouho_1[j]-temp2))
            if cur1 > cur2:
                kouho_1[i+1] = temp1
            else:
                kouho_1[i+1] = temp2
flag = False
for i in range(n):
    if D[i] == 0:
        kouho_2[i+1] = 0
    elif D[i] == 12:
        kouho_2[i+1] = 12
    else:
        if not flag:
            flag = True
            kouho_2[i+1] = 24-D[i]
        else:
            cur1 = 24
            temp1 = D[i]
            cur2 = 24
            temp2 = 24-D[i]
            for j in range(i+1):
                cur1 = min(cur1, abs(kouho_2[j]-temp1))
            for j in range(i+1):
                cur2 = min(cur2, abs(kouho_2[j]-temp2))
            if cur1 > cur2:
                kouho_2[i+1] = temp1
            else:
                kouho_2[i+1] = temp2
ans1 = abs(kouho_1[0]-kouho_1[1])
ans2 = abs(kouho_2[0]-kouho_2[1])
for i in range(n+1):
    for j in range(i+1, n+1):
        ans1 = min(ans1, abs(kouho_1[i]-kouho_1[j]), 24-abs(kouho_1[i]-kouho_1[j]))
        ans2 = min(ans2, abs(kouho_2[i]-kouho_2[j]), 24-abs(kouho_2[i]-kouho_2[j]))
print(max(ans1,ans2))