Problem:
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.

Incorrect submission (verdict: Wrong Answer):

N=int(input())

D=list(map(int,input().split()))
flg =False
A = [0 for i in range(13)]
A[0]=1
for i in range(N):
    j = min(i,24-i)
    if j==0:
        flg=True
        break
    elif j==12:
        if A[j]==1:
            flg=True
            break
        else:
            A[j]+=1
    else:
        if A[j]==2:
            flg=True
            break
        else:
            A[j]+=1

import copy

if flg:
    print(0)
else:
    count=0
    one_times=[]
    times=[0]
    for i in range(1,12): 
        if A[i]==1:
            count+=1
            one_times.append(i)
        if A[i]==2:
            times.append(i)
            times.append(24-i)
    if A[12]==1:
        times.append(12)
    score_max=0
    for i in range(2**count):
        t=copy.copy(times)
        for j in range(count):
            if (i//(2**j))%2==0:
                t.append(one_times[j])
            else:
                t.append(24-one_times[j])
        t.sort()
        score_min=24
        for j in range(len(t)):
            if j==len(t)-1:
                score_min=min(t[0]+24-t[len(t)-1],score_min)
            else:
                score_min=min(t[j+1]-t[j],score_min)
        score_max=(score_min,score_max)
    print(score_max)

Fixed, accepted submission:
N=int(input())

D=list(map(int,input().split()))
flg =False
A = [0 for i in range(13)]
A[0]=1
for i in range(N):
    j = min(D[i],24-D[i])
    if j==0:
        flg=True
        break
    elif j==12:
        if A[j]==1:
            flg=True
            break
        else:
            A[j]+=1
    else:
        if A[j]==2:
            flg=True
            break
        else:
            A[j]+=1

import copy

if flg:
    print(0)
else:
    count=0
    one_times=[]
    times=[0]
    for i in range(1,12): 
        if A[i]==1:
            count+=1
            one_times.append(i)
        if A[i]==2:
            times.append(i)
            times.append(24-i)
    if A[12]==1:
        times.append(12)
    score_max=0
    for i in range(2**count):
        t=copy.copy(times)
        for j in range(count):
            if (i//(2**j))%2==0:
                t.append(one_times[j])
            else:
                t.append(24-one_times[j])
        t.sort()
        
        score_min=24
        for j in range(len(t)):
            if j==len(t)-1:
                score_min=min(t[0]+24-t[len(t)-1],score_min)
            else:
                score_min=min(t[j+1]-t[j],score_min)
        score_max=max(score_min,score_max)
    print(score_max)