Problem p03525 (python)

Fixed submission:
s=[0]*24
s[12]=1
n=int(input())
a=list(map(int,input().split()))
d=[a.count(i)for i in range(13)]
d[0]+=1
if max(d[0],d[12])<2 and max(d[1:-1])<3:
    if d[12]==1:
        s[0]=1
    t=[]
    for i in range(1,12):
        if d[i]==2:
            s[12-i]=1
            s[12+i]=1
        elif d[i]==1:
            t.append(i)
    k=0
    for i in range(2**len(t)):
        p=bin(i)[2:]
        p="0"*(len(t)-len(p))+p
        r=s[:]
        for j in range(len(t)):
            if p[j]=="0":
                r[12-t[j]]=1
            else:
                r[12+t[j]]=1
        h=0
        q=0
        ans=30
        for j in 2*r:
            if j==1:
                if h==0:
                    q=1
                    h=1
                else:
                    ans=min(q,ans)
                    q=1
            else:
                q+=1
        k=max(ans,k)
    print(k)
else:
    print(0)

Buggy submission (verdict: Runtime Error):
s=[0]*25
s[11]=1
d=[0]*13
d[0]+=1
n=int(input())
a=list(map(int,input().split()))
d=[a.count(i)for i in range(12)]
if max(d[0],d[12])<2 and max(d[1:12])<3:
    if d[12]==1:
        s[0]=1
        s[-1]=1
    t=[]
    for i in range(1,12):
        if d[i]==2:
            s[12-i]=1
            s[12+i]=1
        elif d[i]==1:
            t.append(i)
    k=0
    for i in range(s**len(t)):
        p=bin(i)[2:]
        p="0"*(len(t)-len(p))+p
        r=s[:]
        for j in range(len(t)):
            if p[j]=="0":
                r[12-t[j]]=1
            else:
                r[12+t[j]]=1
        r=2*r
        h=0
        q=0
        ans=0
        for j in r:
            if j==1:
                if h==0:
                    q=1
                    h=1
                else:
                    ans=min(q,ans)
                    q=1
            else:
                q+=1
        k=max(ans,k)
    print(k)
else:
    print(0)

Buggy submission (verdict: Runtime Error):
s=[0]*25
s[11]=1
d=[0]*13
n=int(input())
a=list(map(int,input().split()))
d=[a.count(i)for i in range(12)]
if max(d[0],d[12])<2 and max(d[1:12])<3:
    if d[12]==1:
        s[0]=1
        s[-1]=1
    t=[]
    for i in range(1,12):
        if d[i]==2:
            s[12-i]=1
            s[12+i]=1
        elif d[i]==1:
            t.append(i)
    k=0
    for i in range(s**len(t)):
        p=bin(i)[2:]
        p="0"*(len(t)-len(p))+p
        r=s[:]
        for j in range(len(t)):
            if p[j]=="0":
                r[12-t[j]]=1
            else:
                r[12+t[j]]=1
        r=2*r
        h=0
        q=0
        ans=0
        for j in r:
            if j==1:
                if h==0:
                    q=1
                    h=1
                else:
                    ans=min(q,ans)
                    q=1
            else:
                q+=1
        k=max(ans,k)
    print(k)
else:
    print(0)

Buggy submission (verdict: Runtime Error):
s=[0]*25
s[11]=1
d=[0]*13
n=int(input())
a=list(map(int,input().split()))
d=[a.count(i)for i in range(12)]
if max(d[0],d[12])<2 and max(d[1:12])<3:
    if d[12]==1:
        s[0]=1
        s[-1]=1
    t=[]
    for i in range(1,12):
        if d[i]==2:
            s[12-i]=1
            s[12+i]=1
        elif d[i]==1:
            t.append(i)
    k=0
    for i in range(s**len(t)):
        p=bin(i)[2:]
        p="0"*(len(t)-len(p))+p
        r=s[:]
        for j in range(len(t)):
            if p[j]=="0":
                r[12-t[j]]=1
            else:
                r[12+t[j]]=1
        r=2*r
        h=0
        q=0
        ans=0
        for j in r:
            if j==1:
                if h==0:
                    q=0
                    h=1
                else:
                    ans=min(q,ans)
                    q=0
            else:
                q+=1
        k=max(ans,k)
    print(k)
else:
    print(0)