Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
K = int(input())
a = 0
count = 0
mm = [0,1]
while True:
    a += 1
    if a == 1:
        for i in range(1,10):
            count += 1
            if count == K:
                print(i)
                exit()

    elif a == 2:
        for i in range(1,10):
            for j in range(0,10):
                if abs(i-j)<=1:
                    count+= 1
                    mm.append(i*10+j)
                    if count == K:
                        print(i*10+j)
                        exit()

    elif a >= 3:
        tmp = [] 
        for i in range(1,10):
            # print(mm)
            for j in mm:
                b = j//(10**(a-2))
                # print(b)
                if abs(i-b) <=1:
                    count+= 1
                    e = i*(10**(a-1))+j
                    # print(count,e)
                    tmp.append(e)
                    if count == K:
                        print(e)
                        exit()
        # print(tmp)
        mm = mm + tmp

Fixed submission:
N,K = [int(i.strip()) for i in input().split(' ')]

M = N % K
result = M if K -M > M else K-M
print(result)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict
import math

def combinations_count(n, r):
    if n == 1 or n == 0:
        return 0
    else:
        return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


N = int(input())
A= [int(i.strip()) for i in input().split(' ')]

D =defaultdict(int)

for i in A:
    D[i] += 1

for i in A:
    D[i] -= 1
    result = 0
    for k,v in D.items():
        result += combinations_count(v,2)
    print(result)
    D[i] += 1

Fixed submission:
from collections import defaultdict
import math

def combinations_count(n, r):
    if n == 1 or n == 0:
        return 0
    else:
        return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


N = int(input())
A= [int(i.strip()) for i in input().split(' ')]

D =defaultdict(int)

for i in A:
    D[i] += 1

S = 0
for i in D.values():
    S += combinations_count(i,2)

result_dic ={}
for i in A:
    a = D[i] - 1
    print(S - a)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
if __name__ == '__main__':
    lines = sys.stdin.readlines()
    line = [a.strip('\n').split(' ') for a in lines]
    for i,v in enumerate(line):
        if i == 0:
            n = int(v[0])
            p = v[1]
        else:
            numbers = list(v[0])
            # print(numbers)

    count = 0
    leng = len(list(p))
    p = int(p)

    numbers_int = [int(i) for i in numbers]

    map_ = dict()
    a = 10 % p
    for i in set(numbers_int):
        c = i% p
        for j in range(n):
            map_[i,j] = c
            c = c *a


    count = 0
    for i in range(n):
        for j in range(i,n):
            tar = numbers_int[i:j+1]
            # print(tar)
            leng = len(tar)
            su = 0 
            for k,v in enumerate(tar):
                su += map_[v,leng - k -1]
                # print(v, leng - k)
                # print(map_[1,1])
            if su % p == 0:
                count += 1
                # print(tar)

    print(count)

Fixed submission:
from collections import Counter

N, P = map(int, input().split())
S = input()

c = 0

if P == 2 or P == 5:
    for i,v in enumerate(S):
        if int(v) % P == 0:
            c += (i+1)

else:
    T = [0]*(N+1)
    d = 1
    for i,v in enumerate(S[::-1]):
        a = (int(v) * d + T[i])% P
        T[i+1] = a
        d *= 10
        d %= P
    count = Counter(T)

    c = sum(x * (x -1) / 2 for x in count.values())

print(int(c))

Buggy python submission (verdict: Time Limit Exceeded):
import sys
if __name__ == '__main__':
    lines = sys.stdin.readlines()
    line = [a.strip('\n').split(' ') for a in lines]
    for i,v in enumerate(line):
        if i == 0:
            n = int(v[0])
            p = int(v[1])
        else:
            numbers = list(v[0])
            # print(numbers)

    count = 0
    for i in range(n):
        for j in range(i+1,n+1):
            strs = ''.join(numbers[i:j])
            num = int(strs)
            if num%p==0:
                count += 1

    print(count)

Fixed submission:
from collections import Counter

N, P = map(int, input().split())
S = input()

c = 0

if P == 2 or P == 5:
    for i,v in enumerate(S):
        if int(v) % P == 0:
            c += (i+1)

else:
    T = [0]*(N+1)
    d = 1
    for i,v in enumerate(S[::-1]):
        a = (int(v) * d + T[i])% P
        T[i+1] = a
        d *= 10
        d %= P
    count = Counter(T)

    c = sum(x * (x -1) / 2 for x in count.values())

print(int(c))
Buggy python submission (verdict: Runtime Error):
N, M = [int(i) for i in input().split(' ')]
SC = []
for _ in range(M):
    SC.append([int(i) for i in input().split(' ')])

for n in range(10**(N-1),10**N):
    n = list(str(n))
    flg = 0
    for s,c in SC:
        if not n[s-1] == str(c):
            flg = 1

    if flg == 0:
        print(''.formatjoin(n))
        exit()

Fixed submission:
N, M = [int(i) for i in input().split(' ')]
SC = []
for _ in range(M):
    SC.append([int(i) for i in input().split(' ')])

ch = [-1] * N
for s,c in SC:
    if N >1:
        if s == 1 and c == 0:
            print(-1)
            exit()

    if ch[s-1] == -1 or ch[s-1] == c:
        ch[s-1] = c
    else:
        print(-1)
        exit()
s = 10**(N-1) if N >1 else 0
f = 10 ** N if N >1 else 10
for n in range(s,f):
    n = list(str(n))
    flg = 0
    for s,c in SC:
        if not n[s-1] == str(c):
            flg = 1

    if flg == 0:
        print(''.join(n))
        exit()
Buggy python submission (verdict: Runtime Error):
import numpy as np

N, K = [int(i) for i in input().split(' ')]
A = np.array([int(i) for i in input().split(' ')])
A.sort()

minus = A[A<0]
zero = A[A==0]
plus = A[A>0]

def f(x):
    cnt = 0
    if x>0:
        cnt += len(zero) * N
    cnt += np.searchsorted(A,x//plus,side='right').sum()
    cnt += (N - np.searchsorted(A,-(x//-minus),side='left')).sum()
    cnt -= np.count_nonzero(A*A<=x)

    assert cnt%2 == 0
    return cnt//2

left = -10**18
right = 10**18
while left + 1 < right:
    mid = (left+right) // 2
    if f(mid) >= K:
        right = mid
    else:
        left = mid

print(right)

Fixed submission:
import numpy as np
N,K = [int(i) for i in input().split(' ')]

A = np.array([int(i) for i in input().split(' ')])

A.sort()
zero = A[A==0]
minus = A[A<0]
plus = A[A>0]

def index_count(x):
    cnt = 0
    if x >= 0:
        cnt += len(zero) * N
    cnt += np.searchsorted(A,x//plus,side='right').sum()
    cnt += (N - np.searchsorted(A,-(-x//minus),side='left')).sum()
    cnt -= np.count_nonzero(A*A <= x)

    assert cnt % 2 == 0
    return cnt //2


left = -10**18
right = 10**18

while left + 1 < right:
    mid = (left +right) //2
    a = index_count(mid)
    if a >= K:
        right = mid
    else:
        left = mid

print(right)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
N = list(str(N))
N = [int(i) for i in N]

# print(N)
ans = 0
DP = [0] *2
DP[0] = 0
DP[1] = 1
for i in N:
    a, b = DP[0] ,DP[1]
    DP[0] = a + i if a+i < b +(10-i) else b +(10-i)
    DP[1] = a + i+1 if a + i+1 < b + (9-i) else b + (9-i)

    # print(DP)

print(DP[0] if DP[0] <= DP[1]+1 else DP[1] +1)

Fixed submission:
N = list(map(int, input()))

# print(N)
ans = 0
DP = [0] *2
DP[0] = 0
DP[1] = 1
for i in N:
    a, b = DP[0] ,DP[1]
    DP[0] = a + i if a+i < b +(10-i) else b +(10-i)
    DP[1] = a + i+1 if a + i+1 < b + (9-i) else b + (9-i)

    # print(DP)

print(DP[0] if DP[0] <= DP[1]+1 else DP[1] +1)
Buggy python submission (verdict: Time Limit Exceeded):
N, K =map(int,input().split())
A = list(map(int,input().split()))
ans = 0

for i in range(len(A)-K+1):
    t = sum(A[i:i+K])
    ans = max(ans,t)

print((ans+K)/2)


Fixed submission:
N, K = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]

MAX = 0
for i in range(N-K+1):
    if i == 0:
        SUM = 0
        for j in range(K):
            SUM += (A[i+j]+1)/2

    else:
        SUM += (A[i+K-1]+1)/2
        SUM -= (A[i-1]+1)/2
    
    if MAX < SUM:
        MAX = SUM

print(MAX)
Buggy python submission (verdict: Runtime Error):
H,N= [int(i) for i in input().split(' ')]
A = [int(i) for i in input().split(' ')]

A.sort()
if A[-1] + A[-2]>= H:
    print('Yes')
else:
    print('No')

Fixed submission:
H,N= [int(i) for i in input().split(' ')]
A = [int(i) for i in input().split(' ')]

if sum(A)>= H:
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Runtime Error):
H ,N = [int(i) for i in input().split()]
AB = []
for _ in range(N):
    AB.append([int(i) for i in input().split(' ')])
 
MAX = 0
for a, b in AB:
    MAX = a if MAX < a else MAX
 
DP = [10**10] * (H+MAX)
DP[0] = 0
for i in range(H):
    for a,b in AB:
        if DP[i] != 10**10:
            DP[i+a] = min(DP[i+a],DP[i] + b)
 
print(min(DP[H:]))
H ,N = [int(i) for i in input().split()]
AB = []
for _ in range(N):
    AB.append([int(i) for i in input().split(' ')])

MAX = 0
for a, b in AB:
    MAX = a if MAX < a else MAX

DP = [10**10] * (H+MAX)
DP[0] = 0
for i in range(H):
    for a,b in AB:
        if DP[i] != 10**10:
            DP[i+a] = min(DP[i+a],DP[i] + b)

print(min(DP[H:]))
提出情報

Fixed submission:
H ,N = [int(i) for i in input().split()]
AB = []
for _ in range(N):
    AB.append([int(i) for i in input().split(' ')])
 
MAX = 0
for a, b in AB:
    MAX = a if MAX < a else MAX
 
DP = [10**10] * (H+MAX)
DP[0] = 0
for i in range(H):
    for a,b in AB:
        if DP[i] != 10**10:
            DP[i+a] = min(DP[i+a],DP[i] + b)
 
print(min(DP[H:]))

Buggy python submission (verdict: Time Limit Exceeded):
H ,N = [int(i) for i in input().split()]
AB = []
for _ in range(N):
    AB.append([int(i) for i in input().split(' ')])

MAX = 0
for a, b in AB:
    MAX = a if MAX < a else MAX

DP = [10**10] * (H+MAX)
DP[0] = 0
for i in range(H):
    for a,b in AB:
        if DP[i] != 10**10:
            DP[i+a] = min(DP[i+a],DP[i] + b)

print(min(DP[H:]))

Fixed submission:
H ,N = [int(i) for i in input().split()]
AB = []
for _ in range(N):
    AB.append([int(i) for i in input().split(' ')])
 
MAX = 0
for a, b in AB:
    MAX = a if MAX < a else MAX
 
DP = [10**10] * (H+MAX)
DP[0] = 0
for i in range(H):
    for a,b in AB:
        if DP[i] != 10**10:
            DP[i+a] = min(DP[i+a],DP[i] + b)
 
print(min(DP[H:]))
Buggy python submission (verdict: Time Limit Exceeded):
import fractions

N = int(input())
A = list(map(int,input().split()))
MOD = 10** 9 + 7
lcm = 1
for a in A:
    lcm = a // fractions.gcd(a,lcm) * lcm

ans = 0
for a in A:
    ans += lcm // a
    ans %= MOD
print(ans)

Fixed submission:
import fractions

N = int(input())
A = list(map(int,input().split()))
MOD = 10** 9 + 7
lcm = 1
for a in A:
    lcm = a // fractions.gcd(a,lcm) * lcm

print(sum(lcm//a for a in A)%MOD)

Buggy python submission (verdict: Time Limit Exceeded):
import fractions

N = int(input())
A = list(map(int,input().split()))
MOD = 10** 9 + 7
lcm = 1
for a in A:
    lcm = a // fractions.gcd(a,lcm) * lcm

ans = 0
for a in A:
    ans += lcm // a

print(sum(lcm//a for a in A)%MOD)

Fixed submission:
import fractions

N = int(input())
A = list(map(int,input().split()))
MOD = 10** 9 + 7
lcm = 1
for a in A:
    lcm = a // fractions.gcd(a,lcm) * lcm

print(sum(lcm//a for a in A)%MOD)

Buggy python submission (verdict: Time Limit Exceeded):
import fractions
import collections 
from functools import reduce
MOD = 10**9 + 7

N = int(input())
A = [int(i) for i in input().split()]

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

dic = collections.defaultdict(int)
for a in A:
    c2 = collections.Counter(prime_factorize(a))
    for k, v in list(c2.items()):
        dic[k] = max(dic[k],v)
        
ans = 0
for a in A:
    c2 = collections.Counter(prime_factorize(a))
    B =1
    for k,v in list(dic.items()):
        B *= k ** (v-c2[k]) 
        B %= MOD
    ans += B
    ans %= MOD

print(ans)


Fixed submission:
import fractions

N = int(input())
A = list(map(int,input().split()))
MOD = 10** 9 + 7
lcm = 1
for a in A:
    lcm = a // fractions.gcd(a,lcm) * lcm

print(sum(lcm//a for a in A)%MOD)

Buggy python submission (verdict: Runtime Error):
import fractions
from functools import reduce
MOD = 10**9 + 7

N = int(input())
A = [int(i) for i in input().split()]

def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)

LCM = lcm(*A)
ans = 0
for a in A:
    ans += LCM/a
    ans %= MOD

print(int(ans))

Fixed submission:
import fractions

N = int(input())
A = list(map(int,input().split()))
MOD = 10** 9 + 7
lcm = 1
for a in A:
    lcm = a // fractions.gcd(a,lcm) * lcm

print(sum(lcm//a for a in A)%MOD)

Buggy python submission (verdict: Runtime Error):
import math
from functools import reduce
MOD = 10**9 + 7

N = int(input())
A = [int(i) for i in input().split()]

def lcm_base(x, y):
    return (x * y) // math.gcd(x, y)

def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)

LCM = lcm(*A)
ans = 0
for a in A:
    ans += LCM/a
    ans %= MOD

print(int(ans))

Fixed submission:
import fractions

N = int(input())
A = list(map(int,input().split()))
MOD = 10** 9 + 7
lcm = 1
for a in A:
    lcm = a // fractions.gcd(a,lcm) * lcm

print(sum(lcm//a for a in A)%MOD)
Buggy python submission (verdict: Runtime Error):
N = int(input())
S = list(input())
cnt = 0
for i in range(i,N-2):
    if S[i] ='A' and S[i+1] == 'B' and S[i+2] == 'C':
        cnt += 1

print(cnt)

Fixed submission:
N = int(input())
S = list(input())
cnt = 0
for i in range(0,N-2):
    if S[i] =='A' and S[i+1] == 'B' and S[i+2] == 'C':
        cnt += 1

print(cnt)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int,input().split()))
MOD = 10**9+7

table = [0] * 60

for a in A:
    for i in range(60):
        if (a>>i) & 1:
            table[i] += 1

ans = 0
for i ,t in enumerate(table):
    ans += t * (N-t) * 2**i
    ans %= MOD
print(ans)

Fixed submission:
import numpy as np
MOD = 10**9+7
N = int(input())
A = list(map(int,input().split(' ')))
A = np.array(A)

ans = 0
for i in range(60):
    c_1 = int((A&1).sum())
    ans += c_1*(N-c_1)*(2**i)
    A >>= 1

print(ans%MOD)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int,input().split(' ')))
MOD = 10**9+7

SUM = 0
for i, a in enumerate(A):
    for b in A[i+1:]:
        SUM += a ^ b
        SUM %= MOD

print(SUM)

Fixed submission:
import numpy as np
MOD = 10**9+7
N = int(input())
A = list(map(int,input().split(' ')))
A = np.array(A)

ans = 0
for i in range(60):
    c_1 = int((A&1).sum())
    ans += c_1*(N-c_1)*(2**i)
    A >>= 1

print(ans%MOD)
Buggy python submission (verdict: Runtime Error):
from collections import deque
 
N = int(input())
G = [deque([]) for _ in range(N)]
arrive = [0] *N
key = []
for _ in range(N-1):
    a,b = map(int,input().split())
    key.append((a,b))
    G[a-1].append(b-1)
    G[b-1].append(a-1)
 
MAX = 0
for i,g in enumerate(G):
    if MAX < len(g):
        MAX = len(g)
        t = i
 
c_l = list(range(MAX))
C = dict()
 
def bfs(v,c):
    arrive[v] = 1
    cnt = 0
    for w in G[v]:
        if arrive[w] == 0:
            if c == cnt:
                cnt += 1
            bfs(w,cnt)
            if v > w:
                v,w = w,v
            C[(v+1,w+1)] = cnt+1
            cnt += 1
 
bfs(1,-1)
 
print(MAX)
# print(C)
for k in sorted(key):
    print(C[k])

Fixed submission:
from collections import defaultdict,deque

graph = defaultdict(list)
N, *AB = map(int, open(0).read().split())
for a, b in zip(*[iter(AB)] * 2):
    graph[a].append(b)


stack = deque([1])
C = [0] * (N + 1)
while stack:
    v = stack.popleft()
    c = 0
    for w in graph[v]:
        c += 1 + (c + 1 == C[v])
        C[w] = c
        stack.append(w)
        
print(max(C))
print("\n".join(str(C[b]) for b in AB[1::2]))

Buggy python submission (verdict: Runtime Error):
from collections import deque

N = int(input())
G = [deque([]) for _ in range(N)]
arrive = [0] *N

for _ in range(N-1):
    a,b = map(int,input().split())
    G[a-1].append(b-1)
    G[b-1].append(a-1)

MAX = 0
for i,g in enumerate(G):
    if MAX < len(g):
        MAX = len(g)
        t = i

c_l = list(range(MAX))
C = dict()

def bfs(v,c):
    arrive[v] = 1
    # print(v)
    cnt = 0
    for w in G[v]:
        if arrive[w] == 0:
            if c == cnt:
                cnt += 1
            bfs(w,cnt)
            if v > w:
                v,w = w,v
            C[(v+1,w+1)] = cnt+1
            cnt += 1

bfs(t,-1)

print(MAX)
for k in sorted(C.keys()):
    print(C[k])

Fixed submission:
from collections import defaultdict,deque

graph = defaultdict(list)
N, *AB = map(int, open(0).read().split())
for a, b in zip(*[iter(AB)] * 2):
    graph[a].append(b)


stack = deque([1])
C = [0] * (N + 1)
while stack:
    v = stack.popleft()
    c = 0
    for w in graph[v]:
        c += 1 + (c + 1 == C[v])
        C[w] = c
        stack.append(w)
        
print(max(C))
print("\n".join(str(C[b]) for b in AB[1::2]))
Buggy python submission (verdict: Time Limit Exceeded):
N , T = map(int,input().split())
AB = []
for _ in range(N):
    AB.append(list(map(int,input().split())))
dp = [-1] * (T+3000)
dp[0] = 0
for a,b in sorted(AB):
    for i in range(T-1,-1,-1):
        if dp[i] == -1:
            continue
        if dp[i+a] < dp[i] + b:
            dp[i+a] = dp[i] +b 
print(max(dp))

Fixed submission:
import numpy as np
 
N, T = map(int, input().split())
data = []
for i in range(N):
  a, b = map(int, input().split())
  data.append((a,b))
data.sort()
data = np.array(data)

dp = np.zeros(T)
ans = 0
for a, b in data:
    ans = max(ans,dp[-1]+b)
    if a< T:
        newtable = dp[:T-a] + b
        dp[a:] = np.maximum(dp[a:], newtable)

print(int(ans))

Buggy python submission (verdict: Time Limit Exceeded):
N , T = map(int,input().split(' '))
AB = []
for _ in range(N):
    AB.append(list(map(int,input().split())))
dp = [-1] * (T+3000)
dp[0] = 0
for a,b in sorted(AB):
    for i in range(T-1,-1,-1):
        if dp[i] == -1:
            continue
        if dp[i+a] < dp[i] + b:
            dp[i+a] = dp[i] +b 
print(max(dp))

Fixed submission:
import numpy as np
 
N, T = map(int, input().split())
data = []
for i in range(N):
  a, b = map(int, input().split())
  data.append((a,b))
data.sort()
data = np.array(data)

dp = np.zeros(T)
ans = 0
for a, b in data:
    ans = max(ans,dp[-1]+b)
    if a< T:
        newtable = dp[:T-a] + b
        dp[a:] = np.maximum(dp[a:], newtable)

print(int(ans))
Buggy python submission (verdict: Time Limit Exceeded):
import bisect

N = int(input())
A = list(map(int,input().split()))
A.sort()

SUM = 0
for i,a in enumerate(A):
    for j,b in enumerate(A[i+1:]):
        SUM += bisect.bisect_left(A[i+j+2:], a+b)

print(SUM)


Fixed submission:
N = int(input())
A = list(map(int,input().split()))
A.sort()
count = 0

for i in range(N-1,0,-1):
    l = 0
    r = i -1
    while(l< r):
        if (A[l] + A[r] >A[i]):
            count += (r-l)
            r -= 1
        else:
            l += 1
print(count)
Buggy python submission (verdict: Runtime Error):
print(sum(list(range(1,int(input())))))

Fixed submission:
N = int(input())
print(N*(N-1)//2)
Buggy python submission (verdict: Runtime Error):
from collections import Counter,defaultdict
import math

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

N = int(input())
A = defaultdict(int)
for _ in range(N):
    c = Counter(list(input()))
    d = sorted(c.items(),key= lambda x:x[0])
    A[tuple(d)] += 1

SUM = 0
for v in A.values():
    SUM += combinations_count(v,2)

print(SUM)

Fixed submission:
from collections import Counter,defaultdict
import math

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

N = int(input())
A = defaultdict(int)
for _ in range(N):
    c = Counter(list(input()))
    d = sorted(c.items(),key= lambda x:x[0])
    A[tuple(d)] += 1

SUM = 0
for v in A.values():
    if v > 1:
        SUM += combinations_count(v,2)

print(SUM)
Buggy python submission (verdict: Runtime Error):
n,a,b,c,d = map(int,input().split())
S = list(input())
S = ['#'].expand(S)
print(S)

flg = 1
for i in range(a-1,c-2):
    if S[i:i+2] == ['#','#']:
        flg *= 0

for i in range(b-1,d-2):
    if S[i:i+2] == ['#','#']:
        flg *= 0

if c>d:
    flg2 = 0
    for i in range(b-1,d):
        if S[i-1:i+2] == ['.','.','.']:
            flg2 = 1
    flg *= flg2

if flg == 0:
    print('No')
else:
    print('Yes')

Fixed submission:
n,a,b,c,d = map(int,input().split())
S = list(input())

flg = 1
for i in range(a-1,c-2):
    if S[i:i+2] == ['#','#']:
        flg *= 0

for i in range(b-1,d-2):
    if S[i:i+2] == ['#','#']:
        flg *= 0

if c>d:
    flg2 = 0
    for i in range(b-1,d):
        if S[i-1:i+2] == ['.','.','.']:
            flg2 = 1
    flg *= flg2

if flg == 0:
    print('No')
else:
    print('Yes')
Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter

N = int(input())
V = list(map(int,input().split()))

c1 = Counter(V[::2])
c2 = Counter(V[1::2])

c1 = dict(c1)
c2 = dict(c2)
c1[-1] = 0
c2[-2] = 0

MAX = 0
for k,v in c1.items():
    for k2,v2 in c2.items():
        if k != k2:
            MAX = max(v+v2,MAX)

print(N - MAX)

Fixed submission:
from collections import Counter

N = int(input())
V = list(map(int,input().split()))

c1 = Counter(V[::2]).most_common(2)
c2 = Counter(V[1::2]).most_common(2)

c1 = dict(list(c1))
c2 = dict(list(c2))
c1[-1] = 0
c2[-2] = 0

MAX = 0
for k,v in c1.items():
    for k2,v2 in c2.items():
        if k != k2:
            MAX = max(v+v2,MAX)

print(N - MAX)
Buggy python submission (verdict: Runtime Error):
import math
from functools import reduce

N, K = [int(i) for i in input().split(' ')]
X = [int(i) for i in input().split(' ')]

def gcd_list(numbers):
    return reduce(math.gcd, numbers)

X.append(K)
diff = []
for i,x in enumerate(X):
    if i != 0:
        diff.append(abs(X[i-1] - x))

print(gcd_list(diff))


Fixed submission:
import fractions
from functools import reduce

N, K = [int(i) for i in input().split(' ')]
X = [int(i) for i in input().split(' ')]

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)

X.append(K)
diff = []
for i,x in enumerate(X):
    if i != 0:
        diff.append(abs(X[i-1] - x))

print(gcd_list(diff))
Buggy python submission (verdict: Time Limit Exceeded):
from functools import reduce

N = int(input())
A = list(map(int,input().split()))

cnt = 0
l = 0
r = 1
for l in range(N):
    r = l+1
    b = A[l]
    t = 0
    while sum(A[l:r]) == reduce(lambda a, b: a^b, A[l:r]) and r < N+1:
        r += 1
        cnt += 1
print(cnt)

Fixed submission:
N = int(input())
A = list(map(int,input().split()))
cnt = 0
t = 0
r = 0
for l in range(N):
    while r < N and (t & A[r]) == 0:
        t += A[r]
        r += 1
    t -= A[l]
    cnt += (r-l)

print(cnt)

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

L = []
b = 0
cnt = 0
for i,a in enumerate(A):
    cnt += 1
    while i < N-1:
        i += 1
        if a & A[i]==0:
            cnt += 1
            a ^= A[i]
        else:
            break

print(cnt)

Fixed submission:
N = int(input())
A = list(map(int,input().split()))
cnt = 0
t = 0
r = 0
for l in range(N):
    while r < N and (t & A[r]) == 0:
        t += A[r]
        r += 1
    t -= A[l]
    cnt += (r-l)

print(cnt)