Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
# coding: utf-8
# Your code here!

import numpy as np
import bisect

h, n = map(int, list(input().split()))

ab = []
for _ in range(n):
    ab.append(list(map(int, list(input().split()))))
ab = np.array(ab)
max_a = max(ab[:,0])

dp = [int(1e9)] * int(1e6)
checked = [False] * int(1e6)
dp[0] = 0

sorted_list = [0]
while len(sorted_list) > 0:
    v = sorted_list.pop(0)
    
    if v > h:
        break
    
    for i in range(n):
        if checked[v + ab[i, 0]] == False:
            bisect.insort_right(sorted_list, v + ab[i, 0])
            checked[v + ab[i, 0]] = True
        dp[v + ab[i,0]] = min(dp[v + ab[i,0]], dp[v] + ab[i,1])
    
print(min(dp[v-1:]))


Fixed submission:
# coding: utf-8
# Your code here!

import bisect

h, n = map(int, list(input().split()))

ab = []
max_a = 0
for _ in range(n):
    ab.append(list(map(int, list(input().split()))))
    max_a = max(max_a, ab[-1][0])

dp = [int(1e9)] * int(1e6)
checked = [False] * int(1e6)
dp[0] = 0

sorted_list = [0]
while len(sorted_list) > 0:
    v = sorted_list.pop(0)
    
    if v > h:
        break
    
    for i in range(n):
        if checked[v + ab[i][0]] == False:
            bisect.insort_right(sorted_list, v + ab[i][0])
            checked[v + ab[i][0]] = True
        dp[v + ab[i][0]] = min(dp[v + ab[i][0]], dp[v] + ab[i][1])
    
print(min(dp[v-1:]))
Buggy python submission (verdict: Time Limit Exceeded):

N = int(input())

dp = dict()
total = 0
for i in range(1, N+1):
    mae = str(i)[0]
    usiro = str(i)[-1]
    key = mae + usiro
    if key in dp.keys():
        total += dp[key]
    else:
        count = 0
        for j in range(1, N+1):
            mae = str(j)[0]
            usiro = str(j)[-1]
            if key == usiro + mae:
                count += 1
        dp[key] = count
        total += count
    
print(total)

Fixed submission:
import math

N = int(input())

dp = [[-1] * 10 for _ in range(10)]
temp = 0
total = 0

mae_usiro = [[-1] * 2 for _ in range(N+1)]
for i in range(1, N+1):
    mae = int(i / 10 ** int(math.log10(i)))
    usiro = i % 10
    mae_usiro[i] = [mae, usiro]

for i in range(1, N+1):
    mae, usiro = mae_usiro[i]
    if i > 100:
        total += dp[mae][usiro]
    elif dp[mae][usiro] != -1:
        total += dp[mae][usiro]
    else:
        count = 0
        for j in range(1, N+1):
            mae2, usiro2 = mae_usiro[j]
            if mae == usiro2 and usiro == mae2:
                count += 1
        dp[mae][usiro] = count
        total += count
    
print(total)
Buggy python submission (verdict: Time Limit Exceeded):
from fractions import gcd

# mod. m での a の逆元 a^{-1} を計算する
# b * a^{-1} (mod m)を計算したい場合はb * modinv(a, m) % m
def modinv(a, m):
    b = m
    u = 1
    v = 0
    while b:
        t = int(a / b)
        a -= t * b
        a, b = b, a
        u -= t * v
        u, v = v, u
    u %= m
    if u < 0:
        u += m
    return u

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

lcm = A[0]
for i in range(1, N):
    lcm = lcm * A[i] // gcd(lcm, A[i])

print(sum([(lcm * modinv(x, int(1e9+7)) % int(1e9+7)) for x in A]) % int(1e9+7))

Fixed submission:
from fractions import gcd
import collections
from collections import defaultdict

# mod. m での a の逆元 a^{-1} を計算する
# b * a^{-1} (mod m)を計算したい場合はb * modinv(a, m) % m
def modinv(a, m):
    b = m
    u = 1
    v = 0
    while b:
        t = int(a / b)
        a -= t * b
        a, b = b, a
        u -= t * v
        u, v = v, u
    u %= m
    if u < 0:
        u += m
    return u
    
# 途中計算でmodを計算する高速な累乗計算
def pow_k_mod(x, n, m):
    """
    O(log n)
    """
    if n == 0:
        return 1

    K = 1
    while n > 1:
        if n % 2 != 0:
            K *= x
            K %= m
        x *= x
        x %= m
        n //= 2

    return (K * x) % m
    
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

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

factor = defaultdict(lambda: -1)
for i in range(N):
    c = collections.Counter(prime_factorize(A[i]))
    for k, v in c.items():
        factor[k] = max(factor[k], v)

lcm = 1
for k, v in factor.items():
    lcm *= pow_k_mod(k, v, int(1e9+7))
    lcm %= int(1e9+7)

print(sum([(lcm * modinv(x, int(1e9+7)) % int(1e9+7)) for x in A]) % int(1e9+7))
Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
# Your code here!
import queue

H, W = map(int, input().rstrip().split())
m = [input() for _ in range(H)]

def bfs(h, w):
    q = queue.Queue()
    q.put((h, w, 0))
    f = [[False] * W for _ in range(H)]
    max_d = 0
    while q.qsize() > 0:
        h, w, d = q.get()
        f[h][w] = True
        max_d = max(max_d, d)
        for dh, dw in [[-1, 0], [1, 0], [0, 1], [0, -1]]:
            if h + dh >= 0 and h + dh < H and w + dw >= 0 and w + dw < W:
                if f[h+dh][w+dw] == False and m[h+dh][w+dw] == '.':
                    q.put((h+dh, w+dw, d+1))
    return max_d    

max_d = 0
for h in range(H):
    for w in range(W):
        if m[h][w] == '.':
            max_d = max(max_d, bfs(h, w))
        
print(max_d)
        

Fixed submission:
# coding: utf-8
# Your code here!
import queue

H, W = map(int, input().rstrip().split())
m = [input() for _ in range(H)]

def bfs(h, w):
    q = queue.Queue()
    q.put((h, w, 0))
    f = [[False] * W for _ in range(H)]
    f[h][w] = True
    max_d = 0
    while q.qsize() > 0:
        h, w, d = q.get()
        max_d = max(max_d, d)
        for dh, dw in [[-1, 0], [1, 0], [0, 1], [0, -1]]:
            if h + dh >= 0 and h + dh < H and w + dw >= 0 and w + dw < W:
                if f[h+dh][w+dw] == False and m[h+dh][w+dw] == '.':
                    q.put((h+dh, w+dw, d+1))
                    f[h+dh][w+dw] = True
    return max_d    

max_d = 0
for h in range(H):
    for w in range(W):
        if m[h][w] == '.':
            max_d = max(max_d, bfs(h, w))
        
print(max_d)
Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
# Your code here!

import bisect

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

for _ in range(M):
    a = A.pop()
    a = a / 2
    bisect.insort_right(A, a)
    
print(sum([int(x) for x in A]))
    

Fixed submission:
# coding: utf-8
# Your code here!

import heapq

N, M = map(int, input().rstrip().split())
A = list(map(lambda x: -int(x), input().rstrip().split()))
heapq.heapify(A)

for _ in range(M):
    a = heapq.heappop(A)
    a = a / 2
    heapq.heappush(A, a)
    
print(sum([-int(x) for x in A]))

Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
# Your code here!

import bisect
import copy

N, M = map(int, input().rstrip().split())
A = list(map(int, input().rstrip().split()))
A = sorted(A)
ori_A = copy.copy(A)
maisu = [0] * N

for i in range(M):
    _, b, c = A.pop(), ori_A.pop(), maisu.pop()
    a = b // 2 ** (c + 1)
    idx = bisect.bisect_right(A, a)
    A.insert(idx, a)
    ori_A.insert(idx, b)
    maisu.insert(idx, c + 1)
    
print(sum(A))
    

Fixed submission:
# coding: utf-8
# Your code here!

import heapq

N, M = map(int, input().rstrip().split())
A = list(map(lambda x: -int(x), input().rstrip().split()))
heapq.heapify(A)

for _ in range(M):
    a = heapq.heappop(A)
    a = a / 2
    heapq.heappush(A, a)
    
print(sum([-int(x) for x in A]))
Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
# Your code here!

N, M = list(map(int, input().rstrip().split(' ')))
S = list(map(int, input().rstrip().split(' ')))
T = list(map(int, input().rstrip().split(' ')))
dp = [[0] * (N + 1) for _ in range(M + 1)]

for i in range(1, M+1):
    for j in range(1, N+1):
        if S[j-1] == T[i-1]:
            dp[i][j] = dp[i-1][j] + dp[i][j-1] + 1
        else:
            dp[i][j] = dp[i-1][j] + dp[i][j-1] - dp[i-1][j-1]
            
print((dp[-1][-1]+1) % 1000000007)


Fixed submission:
# coding: utf-8
# Your code here!

N, M = list(map(int, input().rstrip().split(' ')))
S = list(map(int, input().rstrip().split(' ')))
T = list(map(int, input().rstrip().split(' ')))
dp = [[0] * (N + 1) for _ in range(M + 1)]

for i in range(1, M+1):
    for j in range(1, N+1):
        if S[j-1] == T[i-1]:
            dp[i][j] = dp[i-1][j] + dp[i][j-1] + 1
        else:
            dp[i][j] = dp[i-1][j] + dp[i][j-1] - dp[i-1][j-1]
        dp[i][j] = dp[i][j] % 1000000007
            
print((dp[-1][-1]+1) % 1000000007)
Buggy python submission (verdict: Time Limit Exceeded):

from collections import defaultdict
import sys
sys.setrecursionlimit(100000)

N, M = map(int, input().rstrip().split(' '))

A = [0] * (N + 1)
for _ in range(M):
    A[int(input())] = 1

dp = defaultdict(lambda: -1)
def dfs(n):
    if n > N:
        return 0
    if A[n] == 1:
        return 0
    if n == N:
        return 1
    if dp[n] != -1:
        return dp[n]
        
    count = 0
    count += dfs(n + 1)
    count += dfs(n + 2)
    
    dp[n] = count
    
    return count
    
print(dfs(0) % (1000000007))

Fixed submission:
# coding: utf-8
# Your code here!

from collections import defaultdict

N, M = map(int, input().rstrip().split(' '))
if M == 0:
    A = [0]
else:
    A = sorted([int(input()) for _ in range(M)]) + [N + 1]
    
dp = [0] * (N+1)
dp[0] = 1
if A[0] != 1:
    dp[1] = 1
    index_A = 0
else:
    dp[1] = -1
    index_A = 1
    
for i in range(2,N+1):
    if A[index_A] == i:
        dp[i] = -1
        index_A += 1
    else:
        if dp[i-1] != -1:
            dp[i] += dp[i-1]
        if dp[i-2] != -1:
            dp[i] += dp[i-2]
            
print(dp[N] %  (1000000007))

Buggy python submission (verdict: Runtime Error):

from collections import defaultdict

N, M = map(int, input().rstrip().split(' '))

A = [0] * (N + 1)
for _ in range(M):
    A[int(input())] = 1

dp = defaultdict(lambda: -1)
def dfs(n):
    if n > N:
        return 0
    if A[n] == 1:
        return 0
    if n == N:
        return 1
    if dp[n] != -1:
        return dp[n]
        
    count = 0
    count += dfs(n + 1)
    count += dfs(n + 2)
    
    dp[n] = count
    
    return count
    
print(dfs(0) % (1000000007))

Fixed submission:
# coding: utf-8
# Your code here!

from collections import defaultdict

N, M = map(int, input().rstrip().split(' '))
if M == 0:
    A = [0]
else:
    A = sorted([int(input()) for _ in range(M)]) + [N + 1]
    
dp = [0] * (N+1)
dp[0] = 1
if A[0] != 1:
    dp[1] = 1
    index_A = 0
else:
    dp[1] = -1
    index_A = 1
    
for i in range(2,N+1):
    if A[index_A] == i:
        dp[i] = -1
        index_A += 1
    else:
        if dp[i-1] != -1:
            dp[i] += dp[i-1]
        if dp[i-2] != -1:
            dp[i] += dp[i-2]
            
print(dp[N] %  (1000000007))
Buggy python submission (verdict: Runtime Error):
# coding: utf-8
# Your code here!

N, K = map(int, input().rstrip().split(' '))
X = [0] + list(map(int, input().rstrip().split(' ')))

sorted_left_X = []
sorted_right_X = []
sorted_remove_X = []
for i in range(N+1):
    sorted_left_X.append(sorted([x for x in X[:i] if x < 0]))
    sorted_right_X.append(sorted([x for x in X[::-1][:i] if x < 0]))
    
    sorted_remove_X.append(sorted([x for x in X[:i] if x < 0] + [x for x in X[::-1][:i] if x < 0]))

cum_X = []
cum = 0
for x in X:
    cum += x
    cum_X.append(cum)

max_count = 0
for k in range(1,K+1):
    for i in range(k+1):
        num_left_removed = i
        num_right_removed = k - i
        temp = sorted(sorted_left_X[i] + sorted_right_X[k-i])
        temp2 = sum(temp[:min(len(temp), K-k)])
        max_count = max(cum_X[i] - cum_X[0] + cum_X[-1] - cum_X[i+N-k] - temp2, max_count)

print(max_count)
    

Fixed submission:
# coding: utf-8
# Your code here!

N, K = map(int, input().rstrip().split(' '))
X = [0] + list(map(int, input().rstrip().split(' ')))

sorted_left_X = []
sorted_right_X = []
sorted_remove_X = []
for i in range(N+1):
    sorted_left_X.append(sorted([x for x in X[:i] if x < 0]))
    sorted_right_X.append(sorted([x for x in X[::-1][:i] if x < 0]))
    
    sorted_remove_X.append(sorted([x for x in X[:i] if x < 0] + [x for x in X[::-1][:i] if x < 0]))

cum_X = []
cum = 0
for x in X:
    cum += x
    cum_X.append(cum)

if K > N:
    temp = sorted([x for x in X if x < 0])
    print(cum_X[-1] - sum(temp[:min(len(temp), K)]))
else:
    max_count = 0
    for k in range(1,K+1):
        for i in range(k+1):
            temp = sorted(sorted_left_X[i] + sorted_right_X[k-i])
            temp2 = sum(temp[:min(len(temp), K-k)])
            max_count = max(cum_X[i] - cum_X[0] + cum_X[-1] - cum_X[i+N-k] - temp2, max_count)

    print(max_count)
Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
# Your code here!

import numpy as np

N, M = map(int, input().rstrip().split(' '))

x = np.zeros(N, dtype=int)
for _ in range(M):
    l, r = map(int, input().rstrip().split(' '))
    x[:l-1] = 1
    x[r:] = 1
    
print(N - x.sum())

Fixed submission:
# coding: utf-8
# Your code here!

import numpy as np

N, M = map(int, input().rstrip().split(' '))

max_l = 0
min_r = int(1e9)
for _ in range(M):
    l, r = map(int, input().rstrip().split(' '))
    max_l = max(max_l, l)
    min_r = min(min_r, r)
    
output = min_r - max_l + 1
if output < 0:
    print(0)
else:
    print(output)
Buggy python submission (verdict: Runtime Error):
# coding: utf-8
# Your code here!

import numpy as np

N, K = map(int, input().rstrip().split(' '))

x = np.arange(N) + 1
c = np.ceil(np.log2(K / x)).astype(int)
c = c[np.where(c > 0)]
cumprod = np.cumprod([0.5] * int(c[0]+1))
print(2 * np.sum(cumprod[c]) / N + (N - len(c)) / N)

Fixed submission:
# coding: utf-8
# Your code here!

import numpy as np

N, K = map(int, input().rstrip().split(' '))

x = np.arange(N) + 1
c = np.ceil(np.log2(K / x)).astype(int)
c = c[np.where(c > 0)]
if len(c) == 0:
    print(1)
else:
    cumprod = np.cumprod([0.5] * int(c[0]+1))
    print(2 * np.sum(cumprod[c]) / N + (N - len(c)) / N)
Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
# Your code here!

from collections import defaultdict

R, G, B, N = map(int, input().rstrip().split(' '))
A = [R, G, B]

dp = defaultdict(lambda: defaultdict(lambda: -1))
def rec(i, n):
    if dp[i][n] != -1:
        return dp[i][n]
    if n == 0:
        return 1
    if i > 2:
        return 0
        
    #print(i, n)
        
    temp = 0
    for j in range(n // A[i] + 1):
        temp += rec(i + 1, n - j * A[i])
        
    dp[i][n] = temp
    
    return temp
    
print(rec(0, N))

Fixed submission:
# coding: utf-8
# Your code here!

from collections import defaultdict

R, G, B, N = map(int, input().rstrip().split(' '))
A = [R, G, B]

dp = defaultdict(lambda: defaultdict(lambda: -1))
def rec(i, n):
    if dp[i][n] != -1:
        return dp[i][n]
    if n == 0:
        return 1
    if i == 2:
        return n % A[2] == 0
       
    temp = 0
    for j in range(n // A[i] + 1):
        temp += rec(i + 1, n - j * A[i])
        
    dp[i][n] = temp
    
    return temp
    
print(rec(0, N))
Buggy python submission (verdict: Runtime Error):

A, B = map(int, input().rstrip().split(' '))
values = list(range(A, B + 1))
#xor_bit = [0] * (B - A)

xor = 0
digit = 0
while True:
    if values[-1] == 0:
        break
    
    num_zeros = 0
    for v in values:
        if v == 0:
            num_zeros = 0
        else:
            break
    
    values = values[num_zeros:]
    
    num_one = 0
    for i, v in enumerate(values):
        num_one += v % 2
        values[i] = v // 2
      
    xor += 2 ** digit * (num_one % 2)
    
    digit += 1
    
print(xor)
    

Fixed submission:
# coding: utf-8
# Your code here!

A, B = map(int, input().rstrip().split(' '))

if A == B:
    print(A)
    
else:
    max_bit = 0
    copied_B = B
    while copied_B > 0:
        copied_B = copied_B // 2
        max_bit += 1
    
    count = 0
    for digit in range(max_bit):
        period = 2 ** (digit + 1)
        pos_A = A % period
        pos_B = B % period
        
        num_one = 0
        if pos_A >= period // 2:
            num_one += period - pos_A
        else:
            num_one += period // 2
         
        if pos_B >= period // 2:
            num_one += pos_B - period // 2 + 1
            
        if digit == 0:
            num_one = 0
            num_one += B % 2
            num_one += A % 2
            if B % 2 == 1 and A % 2 == 1:
                num_one += (B - A - 1) // 2
            else:
                num_one += (B - A) // 2
            
        if num_one % 2 != 0:
            count += 2 ** digit
         
    print(count)
Buggy python submission (verdict: Runtime Error):
# coding: utf-8
# Your code here!

N, M = map(int, input().rstrip().split(' '))

g = [[] for _ in range(N)]
for _ in range(M):
    x, y = map(int, input().rstrip().split(' '))
    g[y-1].append(x-1)
    
dp = [-1] * N
def rec(v):
    if dp[v] != -1:
        return dp[v]
        
    count = 0
    for x in g[v]:
        count = max(count, rec(x)+1)
        
    dp[v] = count
    
    return count
   
for i in range(N):
    rec(i)

print(max(dp))

Fixed submission:
# coding: utf-8
# Your code here!

import sys
sys.setrecursionlimit(int(1e5))

N, M = map(int, input().rstrip().split(' '))

g = [[] for _ in range(N)]
for _ in range(M):
    x, y = map(int, input().rstrip().split(' '))
    g[y-1].append(x-1)
    
dp = [-1] * N
def rec(v):
    if dp[v] != -1:
        return dp[v]
        
    count = 0
    for x in g[v]:
        count = max(count, rec(x)+1)
        
    dp[v] = count
    
    return count
   
for i in range(N):
    rec(i)

print(max(dp))
Buggy python submission (verdict: Runtime Error):
# coding: utf-8
# Your code here!

H, W = map(int, input().rstrip().split(' '))

field = []
for _ in range(H):
    temp_field = []
    for s in input():
        temp_field.append(0 if s == '.' else 1)
    field.append(temp_field)
    
dp = [[0] * (W + 1) for _ in range(H+1)]
dp[0][1] = 1

for h in range(1, H+1):
    for w in range(1, W+1):
        if field[h-1][w-1] == 0:
            dp[h][w] = dp[h-1][w] + dp[h][w-1]
            
#print(int(dp[-1][-1] % (1e9 + 7)))
print((dp[-1][-1] % (1_000_000_007)))


Fixed submission:
# coding: utf-8
# Your code here!

H, W = map(int, input().rstrip().split(' '))

field = []
for _ in range(H):
    temp_field = []
    for s in input():
        temp_field.append(0 if s == '.' else 1)
    field.append(temp_field)
    
dp = [[0] * (W + 1) for _ in range(H+1)]
dp[0][1] = 1

for h in range(1, H+1):
    for w in range(1, W+1):
        if field[h-1][w-1] == 0:
            dp[h][w] = dp[h-1][w] + dp[h][w-1]
            
print(dp[-1][-1] % (1000000007))

Buggy python submission (verdict: Runtime Error):
# coding: utf-8
# Your code here!

H, W = map(int, input().rstrip().split(' '))

field = []
for _ in range(H):
    temp_field = []
    for s in input():
        temp_field.append(0 if s == '.' else 1)
    field.append(temp_field)
    
dp = [[0] * (W + 1) for _ in range(H+1)]
dp[0][1] = 1

for h in range(1, H+1):
    for w in range(1, W+1):
        if field[h-1][w-1] == 0:
            dp[h][w] = dp[h-1][w] + dp[h][w-1]
            
print(int(dp[-1][-1] % (1e9 + 7)))

Fixed submission:
# coding: utf-8
# Your code here!

H, W = map(int, input().rstrip().split(' '))

field = []
for _ in range(H):
    temp_field = []
    for s in input():
        temp_field.append(0 if s == '.' else 1)
    field.append(temp_field)
    
dp = [[0] * (W + 1) for _ in range(H+1)]
dp[0][1] = 1

for h in range(1, H+1):
    for w in range(1, W+1):
        if field[h-1][w-1] == 0:
            dp[h][w] = dp[h-1][w] + dp[h][w-1]
            
print(dp[-1][-1] % (1000000007))
Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
# Your code here!

N = int(input())
P = list(map(float, input().rstrip().split(' ')))

dp = [[0] * (N + 1) for _ in range(N + 1)]

dp[0][0] = 1
for i in range(1, N + 1):
    dp[0][i] = (1.0 - P[i-1]) * dp[0][i-1]
    
for i in range(1, N + 1):
    for j in range(i, N + 1):
        dp[i][j] = dp[i-1][j-1] * P[j-1] + dp[i][j-1] * (1.0 - P[j-1])
        
print(sum([x[-1] for x in dp[-(N+1)//2:]]))


Fixed submission:
# coding: utf-8
# Your code here!

import numpy as np

N = int(input())
P = list(map(float, input().rstrip().split(' ')))

dp = np.zeros((N+2, N+1))

dp[1,0] = 1
for i in range(0, N):
    dp[1:(i+3), i+1] += dp[0:(i+2), i] * P[i]
    dp[1:(i+3), i+1] += dp[1:(i+3), i] * (1.0 - P[i])
        
print(sum(dp[-(N+1)//2:, -1]))
Buggy python submission (verdict: Runtime Error):
import sys
 
N = int(input())
seq = list(map(int, input().rstrip().split(' ')))

odd = [0] * int(1e5)
even = [0] * int(1e5)

for i in range(0, N, 2):
    even[seq[i]] += 1
    
for i in range(1, N, 2):
    odd[seq[i]] += 1

type_number = 0
for i in range(0, int(1e5)):
    if odd[i] + even[i] > 0:
        type_number += 1

max_even = max(even)
max_odd = max(odd)

count = 0
count += N // 2 - max_even
count += N // 2 - max_odd

if type_number == 1:
    print(N // 2)
else:
    print(count)

Fixed submission:

N = int(input())
seq = list(map(int, input().rstrip().split(' ')))

odd = [[0, i] for i in range(int(1e5 + 1))]
even = [[0, i] for i in range(int(1e5 + 1))]

for i in range(0, N, 2):
    even[seq[i]][0] += 1
    
for i in range(1, N, 2):
    odd[seq[i]][0] += 1

sorted_even = sorted(even, key=lambda x: x[0])[::-1]
sorted_odd = sorted(odd, key=lambda x: x[0])[::-1]

if sorted_even[0][1] == sorted_odd[0][1]:
    if sorted_even[0][0] + sorted_odd[1][0] > sorted_even[1][0] + sorted_odd[0][0]:
        max_even = sorted_even[0][0]
        max_odd = sorted_odd[1][0]
    else:
        max_even = sorted_even[1][0]
        max_odd = sorted_odd[0][0]
else:
    max_even = sorted_even[0][0]
    max_odd = sorted_odd[0][0]
 
count = 0
count += N // 2 - max_even
count += N // 2 - max_odd

print(count)