Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
INF = 10**9 + 7


def main():
    N, W = (int(i) for i in input().split())
    A = [[int(i) for i in input().split()] for j in range(N)]

    dp = [[INF]*(10**4+1) for _ in range(N+1)]
    dp[0][0] = 0
    for i in range(N):
        for j in range(10**4 + 1):
            dp[i+1][j] = min(dp[i+1][j], dp[i][j])
            if 0 <= j - A[i][1] and dp[i][j - A[i][1]] + A[i][0] <= W:
                dp[i+1][j] = min(dp[i+1][j], dp[i][j - A[i][1]] + A[i][0])
    ans = 0
    for j in range(10**4+1)[::-1]:
        if dp[N][j] <= W:
            ans = break
    print(ans)


if __name__ == '__main__':
    main()


Fixed submission:
def main():
    N, W_MAX = (int(i) for i in input().split())
    W = []
    V = []
    for _ in range(N):
        w, v = (int(i) for i in input().split())
        W.append(w)
        V.append(v)
    V_SUM = sum(V)
    INF = (1 << 60)
    dp = [INF] * (V_SUM + 1)
    dp[0] = 0
    for i in range(N):
        for j in range(V[i], V_SUM + 1)[::-1]:
            dp[j] = min(dp[j], dp[j - V[i]] + W[i])
    print(max(j for j in range(V_SUM+1) if dp[j] <= W_MAX))


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
# 期待値自体が苦手なので厳しい
# 解説AC
def main():
    import sys
    sys.setrecursionlimit(10**6)
    N = int(input())
    A = [int(i) for i in input().split()]
    dp = [[[0]*(N+1) for _ in range(N+1)] for _ in range(N+1)]
    c = [0]*4
    for a in A:
        c[a] += 1

    def rec(c1, c2, c3):
        if c1 == c2 == c3 == 0:
            return 0
        if dp[c1][c2][c3] != 0:
            return dp[c1][c2][c3]
        ret = N
        if c1 > 0:
            ret += rec(c1-1, c2, c3) * c1
        if c2 > 0:
            ret += rec(c1 + 1, c2-1, c3) * c2
        if c3 > 0:
            ret += rec(c1, c2 + 1, c3-1) * c3
        ret /= c1 + c2 + c3
        dp[c1][c2][c3] = ret
        return ret

    print(rec(*c[1:]))


if __name__ == '__main__':
    main()


Fixed submission:
# 期待値自体が苦手なので厳しい
# 解説AC
def main():
    import sys
    sys.setrecursionlimit(10**6)
    N = int(input())
    A = [int(i) for i in input().split()]
    dp = [0]*(N*((N+1)**2) + N*(N+1) + N + 1)
    c = [0]*4
    for a in A:
        c[a] += 1

    def rec(c1, c2, c3):
        if c1 == c2 == c3 == 0:
            return 0
        if dp[c1 * (N+1)**2 + c2 * (N+1) + c3] != 0:
            return dp[c1 * (N+1)**2 + c2 * (N+1) + c3]
        ret = N
        if c1 > 0:
            ret += rec(c1-1, c2, c3) * c1
        if c2 > 0:
            ret += rec(c1 + 1, c2-1, c3) * c2
        if c3 > 0:
            ret += rec(c1, c2 + 1, c3-1) * c3
        ret /= c1 + c2 + c3
        dp[c1 * (N+1)**2 + c2 * (N+1) + c3] = ret
        return ret

    print(rec(*c[1:]))


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
def main():
    N, K = (int(i) for i in input().split())
    H = [int(i) for i in input().split()]
    H.sort()
    ans = 10**12
    for i in range(N-K+1):
        ans = min(ans, H[i+K-1] - H[i])

    print(ans)


if __name__ == '__main__':
    main()


Fixed submission:
def main():
    N, K = (int(i) for i in input().split())
    h = [int(input()) for i in range(N)]
    h.sort()
    ans = 10**9 + 7
    for i in range(N-(K-1)):
        ans = min(ans,h[i+(K-1)] - h[i])
    print(ans)
if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
def main():
    import numpy as np
    N = int(input())
    A = [int(i) for i in input().split()]
    avg = sum(A)/N
    ans = 0
    mi = abs(A[0] - avg)
    for i, a in enumerate(A[1:], start=1):
        if abs(a - avg) < mi:
            ans = i
            mi = abs(a - avg)
    print(ans)


if __name__ == '__main__':
    main()


Fixed submission:
def main():
    N = int(input())
    A = [int(i) for i in input().split()]
    avg = sum(A)/N
    ans = 0
    mi = abs(A[0] - avg)
    for i, a in enumerate(A[1:], start=1):
        if abs(a - avg) < mi:
            ans = i
            mi = abs(a - avg)
    print(ans)


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
n, m = (int(i) for i in input().split())
py = [[int(i) for i in input().split()] for j in range(m)]
pre = {}
for i in range(m):
    cur_p = py[i][0]
    curlist = pre.get(cur_p,[])
    curlist.append([py[i][1],i])
    curlist.sort()
    pre[cur_p] = curlist

city_nums = []
for i in range(m):
    p = py[i][0]
    x = 0
    p_list = pre[p]
    for j in range(len(p_list)):
        if p_list[j][1] == i:
            x = j+1
    ans = "{:0>6d}".format(p)+"{:0>6d}".format(x)
    city_nums.append(ans)
    
for c_n in city_nums:
    print(c_n)

Fixed submission:
n, m = (int(i) for i in input().split())
py = [[int(i) for i in input().split()] for j in range(m)]
pre = {}
for i in range(m):
    cur_p = py[i][0]
    cur_p_cities = pre.get(cur_p,[])
    cur_p_cities.append(i)
    pre[cur_p] = cur_p_cities

for i in pre.keys():
    pre[i].sort(key=lambda x:py[x][1])
    city_order = tuple(range(1,len(pre[i])+1))
    pre[i] = dict(zip(pre[i],city_order))

city_nums = []
for i in range(m):
    p = py[i][0]
    x = pre[py[i][0]][i]
    ans = "{:0>6d}".format(p)+"{:0>6d}".format(x)
    city_nums.append(ans)
    
for c_n in city_nums:
    print(c_n)

Buggy python submission (verdict: Time Limit Exceeded):
n, m = (int(i) for i in input().split())
py = [[int(i) for i in input().split()] for j in range(m)]
pre = {}
for i in range(m):
    cur_p = py[i][0]
    curlist = pre.get(cur_p,[])
    curlist.append([py[i][1],i])
    curlist.sort()
    pre[cur_p] = curlist

city_nums = []
for i in range(m):
    p = py[i][0]
    x = 0
    p_list = pre[p]
    for j in range(len(p_list)):
        if p_list[j][1] == i:
            x = j+1
    ans = "{:0>6d}".format(p)+"{:0>6d}".format(x)
    city_nums.append(ans)
    
for c_n in city_nums:
    print(c_n)

Fixed submission:
n, m = (int(i) for i in input().split())
py = [[int(i) for i in input().split()] for j in range(m)]
pre = {}
for i in range(m):
    cur_p = py[i][0]
    cur_p_cities = pre.get(cur_p,[])
    cur_p_cities.append(i)
    pre[cur_p] = cur_p_cities

for i in pre.keys():
    pre[i].sort(key=lambda x:py[x][1])
    city_order = tuple(range(1,len(pre[i])+1))
    pre[i] = dict(zip(pre[i],city_order))

city_nums = []
for i in range(m):
    p = py[i][0]
    x = pre[py[i][0]][i]
    ans = "{:0>6d}".format(p)+"{:0>6d}".format(x)
    city_nums.append(ans)
    
for c_n in city_nums:
    print(c_n)
Buggy python submission (verdict: Runtime Error):
MOD = 10**9 + 7


def main():
    S = input()
    N = len(S)
    pre_hatena = S[:1].count("?")
    a = S[:1].count("A")
    post_hatena = S[2:].count("?")
    c = S[2:].count("C")

    ans = 0
    for i in range(1, N-1):
        if S[i] == "?" or S[i] == "B":
            pre_pow = pow(3, pre_hatena-1, MOD)
            pre = ((pre_pow * 3) % MOD) * a + pre_pow * pre_hatena
            post_pow = pow(3, post_hatena-1, MOD)
            post = ((post_pow * 3) % MOD) * c + post_pow * post_hatena
            ans += pre * post
            ans %= MOD
        if S[i] == "?":
            pre_hatena += 1
        if S[i] == "A":
            a += 1
        if S[i+1] == "?":
            post_hatena -= 1
        if S[i+1] == "C":
            c -= 1
    print(ans)


if __name__ == '__main__':
    main()


Fixed submission:
MOD = 10**9 + 7


def main():
    S = input()
    N = len(S)
    pre_hatena = S[:1].count("?")
    a = S[:1].count("A")
    post_hatena = S[2:].count("?")
    c = S[2:].count("C")

    ans = 0
    for i in range(1, N-1):
        if S[i] == "?" or S[i] == "B":
            pre_pow = pow(3, pre_hatena-1, MOD)
            pre = ((pre_pow * 3) % MOD) * a + pre_pow * pre_hatena
            post_pow = pow(3, post_hatena-1, MOD)
            post = ((post_pow * 3) % MOD) * c + post_pow * post_hatena
            ans += pre * post
            ans %= MOD
        if S[i] == "?":
            pre_hatena += 1
        if S[i] == "A":
            a += 1
        if S[i+1] == "?":
            post_hatena -= 1
        if S[i+1] == "C":
            c -= 1
    print(ans)


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
from collections import deque
sin = [i for i in input()]
tin = [i for i in input()]
s = deque(sin)
s_origin = s.copy()
t = deque(tin)
s.rotate(1)
while s!=s_origin:
    if s == t or s_origin == t:
        print("Yes")
        break
    s.rotate(1)
else:
    print("No")

Fixed submission:
from collections import deque
sin = [i for i in input()]
tin = [i for i in input()]
s = deque(sin)
s_origin = deque(sin)
t = deque(tin)
s.rotate(1)
while s!=s_origin:
    if s == t or s_origin == t:
        print("Yes")
        break
    s.rotate(1)
else:
    if s_origin == t:
        print("Yes")
    else:
        print("No")

Buggy python submission (verdict: Runtime Error):
from collections import deque
s = deque([i for i in input()])
s_origin = s.copy()
t = deque([i for i in input()])
s.rotate(1)
while s!=s_origin:
    if s == t or s_origin == t:
        print("Yes")
        break
    s.rotate(1)
else:
    print("No")

Fixed submission:
from collections import deque
sin = [i for i in input()]
tin = [i for i in input()]
s = deque(sin)
s_origin = deque(sin)
t = deque(tin)
s.rotate(1)
while s!=s_origin:
    if s == t or s_origin == t:
        print("Yes")
        break
    s.rotate(1)
else:
    if s_origin == t:
        print("Yes")
    else:
        print("No")

Buggy python submission (verdict: Runtime Error):
from collections import deque
s = deque([i for i in input()])
s_origin = s.copy()
t = deque([i for i in input()])
s.rotate(1)
while s!=s_origin:
    if s == t or s_origin == t:
        print("Yes")
        break
    s.rotate(1)
else:
    print("No")

Fixed submission:
from collections import deque
sin = [i for i in input()]
tin = [i for i in input()]
s = deque(sin)
s_origin = deque(sin)
t = deque(tin)
s.rotate(1)
while s!=s_origin:
    if s == t or s_origin == t:
        print("Yes")
        break
    s.rotate(1)
else:
    if s_origin == t:
        print("Yes")
    else:
        print("No")
Buggy python submission (verdict: Runtime Error):
a, b = (int(i) for i input().split())
c = b - a
d = c*(c+1)//2
print(d - b)

Fixed submission:
a, b = (int(i) for i in input().split())
print(sum(range(b-a))-a)
Buggy python submission (verdict: Runtime Error):
def main():
    N = int(input())
    S = input()
    from collections import Counter
    ri = dict(Counter(S))
    le = {'W': 0, 'E': 0}
    pre = ''
    ans = 1 << 60
    for s in S:
        if pre:
            le[pre] += 1
        ri[s] -= 1
        ans = min(ans, le['W'] + ri['E'])
        pre = s
    print(ans)


if __name__ == '__main__':
    main()


Fixed submission:
def main():
    N = int(input())
    S = input()
    from collections import Counter, defaultdict
    ri = defaultdict(int, dict(Counter(S)))
    le = defaultdict(int, {'W': 0, 'E': 0})
    pre = ''
    ans = 1 << 60
    for s in S:
        le[pre] += 1
        ri[s] -= 1
        ans = min(ans, le['W'] + ri['E'])
        pre = s
    print(ans)


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    N = int(input())

    def Eratosthenes(x: int):
        import math
        sup = int(x)
        primes = {i for i in range(2, sup+1)}
        for i in range(2, int(math.sqrt(sup+1))+1):
            if i in primes:
                mul = 2
                while i*mul <= sup:
                    primes.discard(i*mul)
                    mul += 1
        return primes

    primes = Eratosthenes(55555)
    # print(len(primes))
    from itertools import combinations
    for ps in combinations(primes, N):
        # print(ps)
        for p in combinations(ps, 5):
            if sum(p) in primes:
                break
        else:
            return print(*ps)


if __name__ == '__main__':
    main()


Fixed submission:
def main():
    N = int(input())

    def Eratosthenes(x: int) -> set:
        """x以下の素数の集合を返す"""
        import math
        sup = int(x)
        primes = {i for i in range(2, sup+1)}
        for i in range(2, int(math.sqrt(sup+1))+1):
            if i in primes:
                mul = 2
                while i*mul <= sup:
                    primes.discard(i*mul)
                    mul += 1
        return primes

    p = Eratosthenes(55555)
    for v in p.copy():
        if v % 5 != 1:
            p.discard(v)

    from itertools import combinations
    for i, v in enumerate(combinations(p, N)):
        if i == 0:
            print(*v)
            break


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int,input().split()))

s = [0]*(n+1)

cnt = 0

for i in range(n):
    s[i+1] = s[i] + a[i]
    if a[i] == 0:
        cnt += 1
        
import itertools
for l,r in itertools.combinations(range(1,n+1),2):
    if l >= r:
        continue
    if s[r] - s[l-1] == 0:
        cnt += 1

print(cnt)

Fixed submission:
import itertools
import collections
n = int(input())
a = list(map(int,input().split()))

b = [0] + a
s = list(itertools.accumulate(b))


c = collections.Counter(s)
cm = c.most_common()
cnt = 0
for v in cm:
    if v[1] > 1:
        cnt += (v[1]*(v[1]-1) // 2)
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int,input().split()))

s = [0]*(n+1)

cnt = 0

for i in range(n):
    s[i+1] = s[i] + a[i]
    if a[i] == 0:
        cnt += 1
        
import itertools
for l,r in itertools.combinations(range(1,n+1),2):
    if l >= r:
        continue
    if s[r] - s[l-1] == 0:
        cnt += 1

print(cnt)

Fixed submission:
import itertools
import collections
n = int(input())
a = list(map(int,input().split()))

b = [0] + a
s = list(itertools.accumulate(b))


c = collections.Counter(s)
cm = c.most_common()
cnt = 0
for v in cm:
    if v[1] > 1:
        cnt += (v[1]*(v[1]-1) // 2)
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int,input().split()))

s = [0]*(n+1)
for i in range(n):
    s[i+1] = s[i] + a[i]

cnt = 0
import itertools
for l,r in itertools.product(range(1,n+1),range(1,n+1)):
    if l >= r:
        if l == r:
            if a[l-1] == 0:
                cnt += 1
        continue
    if s[r] - s[l-1] == 0:
        cnt += 1

print(cnt)

Fixed submission:
import itertools
import collections
n = int(input())
a = list(map(int,input().split()))

b = [0] + a
s = list(itertools.accumulate(b))


c = collections.Counter(s)
cm = c.most_common()
cnt = 0
for v in cm:
    if v[1] > 1:
        cnt += (v[1]*(v[1]-1) // 2)
print(cnt)
Buggy python submission (verdict: Runtime Error):
a, b, k = (int(i) for i in input().split())
l = list(range(a,b+1))
for i in sorted(set(l[:k]) | set(l[-k:])):
    print(i)

Fixed submission:
a, b, k = (int(i) for i in input().split())
l = [i for i in range(a,b+1)] if b - a < 110 else [i for i in range(a,a+110)] + [i for i in range(b-110,b+1)]
for i in sorted(set(l[:k]) | set(l[-k:])):
    print(i)
Buggy python submission (verdict: Runtime Error):
def main():
    N = int(input())
    posi = [0, 0]
    time = 0
    flag = True
    for i in range(N):
        t, x, y = (int(i) for i in input().split())
        move = abs(posi[0] - x) + abs(posi[1] - y)
        if (t - time) >= move and (t - time) % move:
            flag = False
        time = t
        posi = [x, y]
    if flag:
        print("Yes")
    else:
        print("No")


if __name__ == '__main__':
    main()


Fixed submission:
def main():
    N = int(input())
    txy = [[0,0,0]] + [[int(i) for i in input().split()] for j in range(N)]
    for i in range(1,N+1):
        cur_distance = abs(txy[i][1] - txy[i-1][1]) + abs(txy[i][2] - txy[i-1][2])
        t_diff = txy[i][0] - txy[i-1][0]
        if t_diff < cur_distance or t_diff%2 != cur_distance%2:
            print("No")
            break
    else:
        print("Yes")
if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
def eratosthenes_2017like(x): #エラトステネスからちょっと変更
    prime = []
    if x < 3:
        return prime
    search = [i for i in range(2,x+1)]
    while search[0] <= math.sqrt(x):
        add = search.pop(0)
        prime.append(add)
        multiple = 1
        while add*multiple <= x:
            multiple += 1
            if add*multiple in search:
                search.remove(add*multiple)
    prime.extend(search)

    for p in prime[::-1]:
        if not((p+1)/2 in prime):
            prime.remove(p)
    return prime

for i in range(q):
    l, r = map(int,input().split())
    left_len = len(eratosthenes_2017like(l-1))
    right_len = len(eratosthenes_2017like(r))
    print(right_len - left_len)

Fixed submission:
sieve = [True] * 100001
#one-based-index
def mark(sieve,x):
    for i in range(x+x,len(sieve),x):
        sieve[i] = False

for x in range(2,int(len(sieve) ** 0.5) + 1):
    if sieve[x]: mark(sieve,x)

sieve[0] = False
sieve[1] = False

for i in range(len(sieve)-2,2,-2):
    if sieve[i]:
        if not(sieve[(i+1)//2]):
            sieve[i] = False #2017likeでない

sieve[2] = False

cnt = [0] * 100002
for i,s in enumerate(sieve):
    if s:
        cnt[i] = cnt[i-1] + 1
    else:
        cnt[i] = cnt[i-1]

q = int(input())

for i in range(q):
    l, r = map(int,input().split())
    print(cnt[r] - cnt[l-1])

Buggy python submission (verdict: Runtime Error):
def eratosthenes_2017like(x):
    prime = []
    if x < 3:
        return prime
    search = [i for i in range(2,x+1)]
    while search[0] <= math.sqrt(x):
        add = search.pop(0)
        prime.append(add)
        multiple = 1
        while add*multiple <= x:
            multiple += 1
            try:
                search.remove(add*multiple)
            except ValueError:
                pass
    prime.extend(search)

    for p in prime[::-1]:
        if not((p+1)/2 in prime):
            prime.remove(p)
    return prime

for i in range(q):
    l, r = map(int,input().split())
    left_len = len(eratosthenes_2017like(l-1))
    right_len = len(eratosthenes_2017like(r))
    print(right_len - left_len)

Fixed submission:
sieve = [True] * 100001
#one-based-index
def mark(sieve,x):
    for i in range(x+x,len(sieve),x):
        sieve[i] = False

for x in range(2,int(len(sieve) ** 0.5) + 1):
    if sieve[x]: mark(sieve,x)

sieve[0] = False
sieve[1] = False

for i in range(len(sieve)-2,2,-2):
    if sieve[i]:
        if not(sieve[(i+1)//2]):
            sieve[i] = False #2017likeでない

sieve[2] = False

cnt = [0] * 100002
for i,s in enumerate(sieve):
    if s:
        cnt[i] = cnt[i-1] + 1
    else:
        cnt[i] = cnt[i-1]

q = int(input())

for i in range(q):
    l, r = map(int,input().split())
    print(cnt[r] - cnt[l-1])
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    N, K = (int(i) for i in input().split())
    WD = [[int(i) for i in input().split()] for j in range(N)]
    W = [w[0] for w in WD]
    D = [d[1] for d in WD]

    def is_ok(X):
        need = 0
        for i in range(N):
            need += (X - W[i]) // D[i] + 1
        if need >= K:
            return True
        else:
            return False

    def binary_search_meguru():
        ng = -1
        ok = 10**36 + 1
        while abs(ok - ng) > 1:
            mid = ng + (ok - ng) // 2
            if is_ok(mid):
                ok = mid
            else:
                ng = mid
        return ok

    print(binary_search_meguru())


if __name__ == '__main__':
    main()


Fixed submission:
def main():
    import sys
    input = sys.stdin.buffer.readline
    N, K = (int(i) for i in input().split())
    WD = [[int(i) for i in input().split()] for j in range(N)]
    ma_w = 0
    ma_d = 0
    for w, d in WD:
        if ma_w < w:
            ma_w = w
        if ma_d < d:
            ma_d = d

    def is_ok(X):
        need = 0
        for i in range(N):
            if WD[i][0] <= X:
                need += ((X - WD[i][0]) // WD[i][1]) + 1
        if need >= K:
            return True
        else:
            return False

    def binary_search_meguru():
        ng = -1
        ok = ma_w + K * ma_d + 1
        while abs(ok - ng) > 1:
            mid = ng + (ok - ng) // 2
            if is_ok(mid):
                ok = mid
            else:
                ng = mid
        return ok

    print(binary_search_meguru())


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
def main():
    S = input()
    N = len(S)
    from collections import Counter
    c = Counter(S)
    # print(c.most_common())
    if N == 3 and c.most_common()[0][1] >= (N+1)//2:
        print("NO")
    elif c.most_common()[0][1] > (N+1)//2 or \
            (c.most_common()[0][1] >= (N+1)//2 and c.most_common()[1][1] >= (N+1)//2):
        print("NO")
    else:
        print("YES")


if __name__ == '__main__':
    main()


Fixed submission:
def main():
    S = input()
    N = len(S)
    a = S.count("a")
    b = S.count("b")
    c = S.count("c")
    ma = max(a, b, c)
    mi = min(a, b, c)
    if ma - mi > 1:
        print("NO")
    else:
        print("YES")


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
def main():
    _ = int(input())
    D = [int(i) for i in input().split()]
    ans = 0
    cnt = [0]*24
    from collections import Counter
    c = Counter(D)
    cnt[0] = 1
    s = [0]*13
    for k, v in c.items():
        if v >= 3:
            ans = 0
            return print(ans)
        elif v >= 2:
            cnt[k] += 1
            cnt[24 - k] += 1
        elif k == 0 or k == 12:
            cnt[k] += 1
        else:
            s[k] += 1
    if any(c >= 2 for c in cnt):
        return print(0)
    for bit in range(1 << 11):
        cur = cnt[:]
        for i in range(11):
            if s[i+1]:
                if bit & (1 << i):
                    cur[24 - (i+1)] += 1
                else:
                    cur[i+1] += 1
        pre = 0
        mi = 24
        for i, ne in enumerate(cur[1:] + [1], start=1):
            if ne:
                if i - pre < mi:
                    mi = i - pre
                pre = i
        ans = max(ans, mi)
    print(ans)


if __name__ == '__main__':
    main()


Fixed submission:
def main():
    N = int(input())
    D = [int(i) for i in input().split()]
    ans = 0
    cnt = [0]*24
    from collections import Counter
    c = Counter(D)
    cnt[0] = 1
    s = [0]*13
    for k, v in c.items():
        if v >= 3 or k == 0:
            ans = 0
            return print(ans)
        elif v >= 2:
            cnt[k] += 1
            cnt[24 - k] += 1
        elif k == 12:
            cnt[12] += v
        else:
            s[k] += 1
    if any(c >= 2 for c in cnt):
        return print(0)
    for bit in range(1 << 11):
        cur = cnt[:]
        for i in range(11):
            if s[i+1]:
                if bit & (1 << i):
                    cur[24 - (i+1)] += 1
                else:
                    cur[i+1] += 1
        if any(c >= 2 for c in cnt):
            continue
        pre = 0
        mi = 24
        for i, ne in enumerate(cur[1:] + [1], start=1):
            if ne:
                if i - pre < mi:
                    mi = i - pre
                pre = i
        if mi != 24:
            ans = max(ans, mi)
    print(ans)


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
def main():
    N = int(input())
    P = [int(i) for i in input().split()]
    ans = 0
    for i in range(N):
        if i+1 == P[i]:
            P[i], P[i+1] = P[i+1], P[i]
            ans += 1
    print(ans)


if __name__ == '__main__':
    main()


Fixed submission:
def main():
    N = int(input())
    A = [int(i) for i in input().split()]
    ans = 0
    pre = False
    for i, a in enumerate(A):
        if pre:
            pre = False
        elif i+1 == a:
            ans += 1
            pre = True
    print(ans)


if __name__ == '__main__':
    main()