alexjercan/bugnet huggingface dataset:
Problem p03241 (Python) — buggy submission, verdict: Time Limit Exceeded

from collections import Counter

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


def factorize(n):
    if n == 1:
        return [1]

    i, factors = 2, []
    while i * i <= n:
        while n % i == 0:
            n //= i
            factors.append(i)
        i += 1
    if n > 1:
        factors.append(n)
    return factors


c = Counter(factorize(M))
a = [1]
for k, v in c.items():
    tmp = []
    for x in a:
        for i in range(v + 1):
            tmp.append(x * (k**i))
    a = list(set(a) | set(tmp))

ans = 0
for x in a:
    y = M // x
    if N <= y:
        ans = max(ans, x)
print(ans)


Error: TLE

Fixed submission:

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


def factorize(n):
    if n == 1:
        return [1]

    i, factors = 2, []
    while i * i <= n:
        while n % i == 0:
            n //= i
            factors.append(i)
        i += 1
    if n > 1:
        factors.append(n)
    return factors


factors = factorize(M)
n_factors = len(factors)

ans = 0
for i in range(1 << n_factors):
    x = 1
    for j in range(n_factors):
        if i & (1 << j):
            x *= factors[j]
    y = M // x
    if N <= y:
        ans = max(ans, x)
print(ans)
Problem p03241 (Python) — buggy submission, verdict: Time Limit Exceeded

# -*- coding: utf-8 -*-

import bisect

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

y = [1, M]
for i in range(2, int(M**0.5) + 1):
    if M % i == 0:
        y.append(i)
        y.append(M // i)

y.sort()
print(M // y[bisect.bisect_left(y, N)])


Error: TLE

Fixed submission:

# -*- coding: utf-8 -*-

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

for i in range(1, M // 2 + 1):
    if M % i == 0 and i >= N:
        print(M // i)
        exit()

print(1)
Problem p03241 (Python) — buggy submission, verdict: Time Limit Exceeded

N, M = map(int, input().split())
ceil = M // N
for i in range(1, ceil + 1)[::-1]:
    tmp = M - i * (N - 1)
    if tmp > 0 and tmp % i == 0:
        print(i)
        break


Error: TLE

Fixed submission:

N, M = map(int, input().split())
ceil = M / N
tmp = 1
mx = 0
while ceil >= tmp:
    if (M - tmp * (N - 1)) % tmp == 0:
        mx = tmp
    tmp += 1

print(mx)
Problem p03241 (Python) — buggy submission, verdict: Time Limit Exceeded

# a1 + a2 + a3 ... + an = M
# ai の 最大公約数をDとする
# ai = xi * D　のはず。 D * x0 + D * x1 ... + D * xn = M
# まとめて D(x1 + x2 + .... + xn) = M
# 変形し、D = M / (x1 + x2 + .... + xn)
# (x1 + ... xn) = K とすると、Kを最小化するとDが最大化する
# M / K が割り切れる必要があるので、KはMの約数のいずれか
# K >= N。なぜなら xi >= 1 なので、Kは最低でも数字の個数 N になる
# つまり、約数のうちで N 以上の最初の値が K になる
# ex: 3 14
# 14 の約数 {1, 2, 7}
# K >= N なので、　K >= 3
# K = 7 で確定。つまり D = M/K = 2 でAnswer

N, M = map(int, input().split())
M_ROOT = int(M**0.5)
k = M
for i in range(1, M_ROOT + 1):
    if M % i == 0:
        if i >= N:
            print(M // i)
            exit()
        d = M // i
        if d < k and d >= N:
            k = d
print(M // k)


Error: TLE

Fixed submission:

# a1 + a2 + a3 ... + an = M
# ai の 最大公約数をDとする
# ai = xi * D　のはず。 D * x0 + D * x1 ... + D * xn = M
# まとめて D(x1 + x2 + .... + xn) = M
# 変形し、D = M / (x1 + x2 + .... + xn)
# (x1 + ... xn) = K とすると、Kを最小化するとDが最大化する
# M / K が割り切れる必要があるので、KはMの約数のいずれか
# K >= N。なぜなら xi >= 1 なので、Kは最低でも数字の個数 N になる
# つまり、約数のうちで N 以上の最初の値が K になる
# ex: 3 14
# 14 の約数 {1, 2, 7}
# K >= N なので、　K >= 3
# K = 7 で確定。つまり D = M/K = 2 でAnswer

N, M = map(int, input().split())
for i in range(1, M + 1):
    if M % i == 0 and i >= N:
        print(M // i)
        break
Problem p03241 (Python) — buggy submission, verdict: Time Limit Exceeded

import math

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

div = M
for i in range(1, int(math.sqrt(M)) + 1):
    if M % i:
        continue
    i2 = M // i
    if i >= N:
        div = min(div, i)
    if i2 >= N:
        div = min(div, i2)

print(M // div)


Error: TLE

Fixed submission:

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

i = M // N
while M % i:
    i -= 1

print(i)
Problem p03242 (Python) — buggy submission, verdict: Runtime Error

n = int(input())
print(1110 - n)


Error: TypeError: 'int' object is not iterable
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03242/Python/s049531454.py", line 2, in <module>
    for i in n:
TypeError: 'int' object is not iterable


Fixed submission:

n = int(input())
for i in n:
    if i == 1:
        i = 9
    elif i == 9:
        i = 1
print(n)
Problem p03242 (Python) — buggy submission, verdict: Runtime Error

s = list(str(input()))
ans = ""
for i in range(3):
    if s[i] == "1":
        ans = ans + "9"
    else:
        ans = ans + "1"
print(ans)


Error: TypeError: can only concatenate str (not "int") to str
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03242/Python/s740292612.py", line 7, in <module>
    ans += 1
TypeError: can only concatenate str (not "int") to str


Fixed submission:

s = str(input())
ans = ""
for i in range(len(s)):
    if s[i] == 1:
        ans += 9
    else:
        ans += 1
print(ans)
Problem p03242 (Python) — buggy submission, verdict: Runtime Error

n = str(input())
ans = ""
for i in n:
    if i == "9":
        ans += "1"
    else:
        ans += "9"
print(ans)


Error: TypeError: 'str' object does not support item assignment
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03242/Python/s999144591.py", line 6, in <module>
    n[i] = 9
TypeError: 'str' object does not support item assignment


Fixed submission:

n = str(input())
for i in n:
    if i == 9:
        n[i] = 1
    else:
        n[i] = 9
print(int(n))
Problem p03242 (Python) — buggy submission, verdict: Runtime Error

n = input()
ans = []
for i in range(len(n)):
    if n[i] == "1":
        ans.append("9")
    elif n[i] == "9":
        ans.append("1")

print("".join(ans))


Error: TypeError: string indices must be integers
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03242/Python/s208424458.py", line 6, in <module>
    if n_letters[i] == "1":
TypeError: string indices must be integers


Fixed submission:

n = int(input())

n_letters = str(n)

for i in n_letters:
    if n_letters[i] == "1":
        n_letters[i] = "9"
    elif n_letters[i] == "9":
        n_letters[i] = "1"
Problem p03243 (Python) — buggy submission, verdict: Runtime Error

n = int(input())
x = (n - 1) // 111 + 1
print(x * 111)


Error: TypeError: unsupported operand type(s) for -: 'str' and 'int'
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03243/Python/s109763902.py", line 2, in <module>
    x = (n - 1) // 111 + 1
TypeError: unsupported operand type(s) for -: 'str' and 'int'


Fixed submission:

n = input()
x = (n - 1) // 111 + 1
print(x * 111)
Problem p03243 (Python) — buggy submission, verdict: Runtime Error

N = int(input())
print(min([x for x in [int(str(i) * 3) - N for i in range(1, 10)] if x >= 0]) + N)


Error: WA

Fixed submission:

N = int(input())
print(min([x for x in [int(str(i) * 3) - N for i in range(1, 10)] if x > 0]) + N)
Problem p03243 (Python) — buggy submission, verdict: Runtime Error

n = input()
for ans in range(111, 1000, 111):
    if int(n) <= ans:
        break
print(ans)


Error: TypeError: '<=' not supported between instances of 'str' and 'int'
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03243/Python/s479378402.py", line 3, in <module>
    if n <= ans:
TypeError: '<=' not supported between instances of 'str' and 'int'


Fixed submission:

n = input()
for ans in range(111, 1000, 111):
    if n <= ans:
        break
print(ans)
Problem p03244 (Python) — buggy submission, verdict: Runtime Error

import collections

n = int(input())
v = list(map(int, input().split()))
a = v[::2]
b = v[1::2]
ac = collections.Counter(a)
bc = collections.Counter(b)
ac = sorted(ac.items(), key=lambda x: x[1], reverse=True)
bc = sorted(bc.items(), key=lambda x: x[1], reverse=True)
if ac[0][0] == bc[0][0]:
    if len(ac) == len(bc) and len(ac) == 1:
        print(ac[0][1])
        exit()
    i = 0
    while ac[i][1] == bc[i][1]:
        i += 1
        if i == len(ac) - 1 or i == len(bc) - 1:
            break
    if ac[i][1] > bc[i][1]:
        ac.remove(ac[i])
        bc.remove(bc[0])
    elif ac[i][1] < bc[i][1]:
        ac.remove(ac[0])
        bc.remove(bc[i])
    else:
        ac.remove(ac[0])
        bc.remove(bc[1])
else:
    ac.remove(ac[0])
    bc.remove(bc[0])
ans = 0
for i in range(len(ac)):
    ans += ac[i][1]
for i in range(len(bc)):
    ans += bc[i][1]
print(ans)


Error: 0

Fixed submission:

import collections

n = int(input())
v = list(map(int, input().split()))
a = v[::2]
b = v[1::2]
ac = collections.Counter(a)
bc = collections.Counter(b)
ac = sorted(ac.items(), key=lambda x: x[1], reverse=True)
bc = sorted(bc.items(), key=lambda x: x[1], reverse=True)
if ac[0][0] == bc[0][0]:
    if len(ac) == len(bc) and len(ac) == 1:
        print(ac[0][1])
        exit()
    i = 0
    while ac[i][1] == bc[i][1]:
        i += 1
    if ac[i][1] > bc[i][1]:
        ac.remove(ac[i])
        bc.remove(bc[0])
    elif ac[i][1] < bc[i][1]:
        ac.remove(ac[0])
        bc.remove(bc[i])
else:
    ac.remove(ac[0])
    bc.remove(bc[0])
ans = 0
for i in range(len(ac)):
    ans += ac[i][1]
for i in range(len(bc)):
    ans += bc[i][1]
print(ans)
Problem p03244 (Python) — buggy submission, verdict: Runtime Error

from collections import Counter

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

if len(set(v)) == 1:
    print(n // 2)
else:
    v1 = [v[i] for i in range(0, n, 2)]
    v2 = [v[i + 1] for i in range(0, n, 2)]

    kw1 = Counter(v1)
    kw2 = Counter(v2)

    x1 = kw1.most_common()[0][0]
    x2 = kw2.most_common()[0][0]

    if x1 != x2:
        ans = 0
        for i in v1:
            if i != x1:
                ans += 1
        for i in v2:
            if i != x2:
                ans += 1
    else:
        y1 = kw1.most_common()[1][0]
        y2 = kw2.most_common()[1][0]

        ans1 = 0
        ans2 = 0

        for i in v1:
            if i != y1:
                ans1 += 1
        for i in v2:
            if i != x2:
                ans1 += 1

        for i in v1:
            if i != x1:
                ans2 += 1
        for i in v2:
            if i != y2:
                ans2 += 1

        ans = min(ans1, ans2)

    print(ans)


Error: 0

Fixed submission:

from collections import Counter

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

if len(set(v)) == 1:
    print(n // 2)
else:
    v1 = [v[i] for i in range(0, n, 2)]
    v2 = [v[i + 1] for i in range(0, n, 2)]

    kw1 = Counter(v1)
    kw2 = Counter(v2)

    x1 = kw1.most_common()[0][0]
    x2 = kw2.most_common()[0][0]

    if x1 != x2:
        ans = 0
        for i in v1:
            if i != x1:
                ans += 1
        for i in v2:
            if i != x2:
                ans += 1
    else:
        y1 = kw1.most_common()[1][0]
        y2 = kw2.most_common()[1][0]

        ans1 = 0
        ans2 = 0

        for i in v1:
            if i != y1:
                ans1 += 1
        for i in v2:
            if i != x2:
                ans1 += 1

        for i in v1:
            if i != x1:
                ans2 += 1
        for i in v2:
            if i != y2:
                ans2 += 1

        ans = min(ans1, ans2)

print(ans)
Problem p03244 (Python) — buggy submission, verdict: Runtime Error

from collections import defaultdict

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

# コーナーケースは先に終わらせる
# 全部同じ数の場合は、N/2が答え
if len(set(V)) == 1:
    print(N // 2)
    exit()
# 2つしかない場合は1が答え
if N == 2:
    print(1)
    exit()

# 方針: 偶数番目と奇数番目は分けて考える
# 偶数番目、奇数番目はそれぞれの最頻値に合わせるのが低コスト
# 最頻値が同じ場合は「数列に現れる数はちょうど2種類」の制約を外れるので、2番目に多い数にあわせる
d_even = defaultdict(int)
d_odd = defaultdict(int)

for i in range(N):
    v = V[i]
    if i % 2 == 0:
        d_even[v] += 1
    else:
        d_odd[v] += 1

l_even = sorted(d_even.items(), key=lambda x: -x[1])
l_odd = sorted(d_odd.items(), key=lambda x: -x[1])

if l_even[0][0] != l_odd[0][0]:
    print(N - l_even[0][1] - l_odd[0][1])
else:
    # どちらも試してコストの小さい方を採用する
    ans1 = N - l_even[0][1] - l_odd[1][1]
    ans2 = N - l_even[1][1] - l_odd[0][1]
    print(min(ans1, ans2))


Error: 0

Fixed submission:

from collections import defaultdict

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

if N == 2:
    if V[0] == V[1]:
        print(0)
    else:
        print(1)
    exit()

d_even = defaultdict(int)
d_odd = defaultdict(int)

for i in range(N):
    v = V[i]
    if i % 2 == 0:
        d_even[v] += 1
    else:
        d_odd[v] += 1

l_even = sorted(d_even.items(), key=lambda x: -x[1])
l_odd = sorted(d_odd.items(), key=lambda x: -x[1])

if l_even[0][0] != l_odd[0][0]:
    print(N - l_even[0][1] - l_odd[0][1])
else:
    ans1 = N - l_even[0][1] - l_odd[1][1]
    ans2 = N - l_even[1][1] - l_odd[0][1]
    print(min(ans1, ans2))
Problem p03244 (Python) — buggy submission, verdict: Time Limit Exceeded

n = int(input())
odd = [[i, 0] for i in range(100000)]
even = [[i, 0] for i in range(100000)]
arr = list(map(int, input().split()))
odd_e = True
even_e = True
for i, e in enumerate(arr):
    if i % 2 == 0:
        odd[e - 1][1] += 1
        if odd_e and arr[0] != e:
            odd_e = False
    else:
        even[e - 1][1] += 1
        if even_e and arr[1] != e:
            even_e = False
odd.sort(key=lambda z: z[1])
even.sort(key=lambda z: z[1])
if odd[-1][0] == even[-1][0]:
    if odd_e or even_e:
        ans = n - even[-1][1]
    elif odd[-2][1] > even[-2][1]:
        ans = n - even[-1][1] - odd[-2][1]
    else:
        ans = n - even[-2][1] - odd[-1][1]
else:
    ans = n - odd[-1][1] - even[-1][1]
print(ans)


Error: TLE

Fixed submission:

n = int(input())
odd = []
even = []
arr = list(map(int, input().split()))
for i, e in enumerate(arr):
    if i % 2 == 0:
        # odd
        res = False
        for x in odd:
            if x[0] == e:
                x[1] += 1
                res = True
                break
        if not res:
            odd.append([e, 1])
    else:
        # even
        res = False
        for x in even:
            if x[0] == e:
                x[1] += 1
                res = True
                break
        if not res:
            even.append([e, 1])
odd.sort(key=lambda x: x[1])
even.sort(key=lambda x: x[1])
if odd[-1][0] == even[-1][0]:
    if len(odd) == 1:
        ans = n - even[-1][1]
    elif len(even) == 1:
        ans = n - odd[-1][1]
    elif odd[-2][1] > even[-2][1]:
        ans = n - even[-1][1] - odd[-2][1]
    else:
        ans = n - even[-2][1] - odd[-1][1]
else:
    ans = n - odd[-1][1] - even[-1][1]
print(ans)
Problem p03244 (Python) — buggy submission, verdict: Runtime Error

from collections import Counter

N = int(input())

index = 0
even_numbers = []
odd_numbers = []

for i in input().split():
    if index % 2 == 0:
        even_numbers.append(int(i))
    else:
        odd_numbers.append(int(i))
    index += 1

even = Counter(even_numbers).most_common(2)
odd = Counter(odd_numbers).most_common(2)

if even[0][0] == odd[0][0]:
    if len(even) == 1:
        print(N // 2)
    else:
        print(N - even[0][1] - max(even[1][1], odd[1][1]))
else:
    print(N - even[0][1] - odd[0][1])


Error: 0

Fixed submission:

from collections import Counter

N = int(input())

index = 0
even_numbers = []
odd_numbers = []

for i in input().split():
    if index % 2 == 0:
        even_numbers.append(int(i))
    else:
        odd_numbers.append(int(i))
    index += 1

even = Counter(even_numbers).most_common(2)
odd = Counter(odd_numbers).most_common(2)

if even[0][1] == odd[0][1]:
    print(min(N - even[0][1] - odd[1][1], N - even[1][1] - odd[0][1]))
else:
    print(N - even[0][1] - odd[0][1])
Problem p03244 (Python) — buggy submission, verdict: Runtime Error

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

judge_2n_1 = {}
judge_2n = {}

for i in range(n):
    if i % 2 == 0:
        if v[i] not in judge_2n_1.keys():
            judge_2n_1[v[i]] = 1
        else:
            judge_2n_1[v[i]] += 1
    else:
        if v[i] not in judge_2n.keys():
            judge_2n[v[i]] = 1
        else:
            judge_2n[v[i]] += 1

judge_2n = sorted(judge_2n.items(), key=lambda x: x[1], reverse=True)
judge_2n_1 = sorted(judge_2n_1.items(), key=lambda x: x[1], reverse=True)
answer = n - 1

for i in judge_2n[:2]:
    for j in judge_2n_1[:2]:
        if i[0] != j[0]:
            answer = min(answer, n - i[1] - j[1])
        else:
            answer = min(answer, n - max(i[1], j[1]))

print(answer)


Error: TypeError: 'map' object is not subscriptable
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03244/Python/s492098689.py", line 63, in <module>
    last_odd = V[-2]
TypeError: 'map' object is not subscriptable


Fixed submission:

from collections import defaultdict

n = int(input())
V = map(int, input().split())

odd = defaultdict(int)
even = defaultdict(int)

max_odd = 0
max_even = 0
f_odd = 0
f_even = 0
s_odd = 0
s_even = 0

for i, v in enumerate(V):
    i += 1
    if i % 2 == 0:
        even[v] += 1
        if even[v] > max_even:
            max_even = even[v]
            if f_even != 0 and v != f_even:
                s_even = f_even
                f_even = v
            elif f_even == 0:
                f_even = v

    elif i % 2 == 1:
        odd[v] += 1
        if odd[v] > max_odd:
            max_odd = odd[v]
            if f_odd != 0 and v != f_odd:
                s_odd = f_odd
                f_odd = v
            elif f_odd == 0:
                f_odd = v

half = n / 2
cnt = 0


if f_odd != f_even:
    c1 = (half - max_odd) + (half - max_even)
    c2 = (half - max_even) + (half - max_odd)
    if c1 > c2:
        cnt = c2
    else:
        cnt = c1
    num1 = f_odd
    num2 = f_even
elif f_odd == f_even:
    c1 = (half - max_odd) + (half - even[s_even])
    c2 = (half - max_even) + (half - odd[s_odd])
    if c1 > c2:
        cnt = c2
        num1 = s_odd
        num2 = f_even
    else:
        cnt = c1
        num1 = f_odd
        num2 = s_even

last_odd = V[-2]
last_even = V[-1]
if last_odd != num1 and last_odd == num2:
    cnt -= 1
if last_even != num2 and last_even == num1:
    cnt -= 1

print(int(cnt))
Problem p03244 (Python) — buggy submission, verdict: Runtime Error

from collections import Counter


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

v_odd = []
v_even = []
for index in range(len(v)):
    i = index + 1
    if i % 2 == 0:
        v_even.append(v[index])
    else:
        v_odd.append(v[index])
# print(v_odd)
# print(v_even)
# print(Counter(v_odd).most_common())
# print(Counter(v_even).most_common())

if Counter(v_odd).most_common()[0][0] != Counter(v_even).most_common()[0][0]:
    number_of_rewrites = len(v_odd) - Counter(v_odd).most_common()[0][1]
    number_of_rewrites += len(v_even) - Counter(v_even).most_common()[0][1]
else:
    odd_1st = Counter(v_odd).most_common()[0][1]
    even_1st = Counter(v_even).most_common()[0][1]
    odd_2nd = (
        Counter(v_odd).most_common()[1][1]
        if len(Counter(v_odd).most_common()) >= 2
        else 0
    )
    even_2nd = (
        Counter(v_even).most_common()[1][1]
        if len(Counter(v_even).most_common()) >= 2
        else 0
    )

    number_of_rewrites = min(
        len(v_odd) - odd_1st + len(v_even) - even_2nd,
        len(v_odd) - odd_2nd + len(v_even) - even_1st,
    )

print(number_of_rewrites)


Error: 0

Fixed submission:

from collections import Counter


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

v_odd = []
v_even = []
for index in range(len(v)):
    i = index + 1
    if i % 2 == 0:
        v_even.append(v[index])
    else:
        v_odd.append(v[index])
# print(v_odd)
# print(v_even)
# print(Counter(v_odd).most_common())
# print(Counter(v_even).most_common())

if Counter(v_odd).most_common()[0][1] != Counter(v_even).most_common()[0][1]:
    number_of_rewrites = len(v_odd) - Counter(v_odd).most_common()[0][1]
    number_of_rewrites += len(v_even) - Counter(v_even).most_common()[0][1]
else:
    if Counter(v_odd).most_common()[0][1] >= Counter(v_even).most_common()[0][1]:
        number_of_rewrites = len(v_odd) - Counter(v_odd).most_common()[0][1]
        number_of_rewrites += len(v_even) - Counter(v_even).most_common()[1][1]
    else:
        number_of_rewrites = len(v_odd) - Counter(v_odd).most_common()[1][1]
        number_of_rewrites += len(v_even) - Counter(v_even).most_common()[0][1]


print(number_of_rewrites)
Problem p03244 (Python) — buggy submission, verdict: Time Limit Exceeded

from collections import Counter

n = int(input())
vs = input().split()

xs = [v for v in vs[::2]]
x = Counter(xs).most_common()

ys = [v for v in vs[1::2]]
y = Counter(ys).most_common()

if x[0][0] != y[0][0]:
    d = n - x[0][1] - y[0][1]
    print(d)
else:
    if len(x) == 1:
        print(n // 2)
    else:
        d1 = n - x[0][1] - y[1][1]
        d2 = n - x[1][1] - y[0][1]
        if d1 > d2:
            print(d2)
        else:
            print(d1)


Error: TLE

Fixed submission:

n = int(input())
vs = input().split()

vs1 = [vs[i] for i in range(0, len(vs), 2)]
vs2 = [vs[i] for i in range(1, len(vs), 2)]

m1 = 0
i1 = -1
m2 = 0
i2 = -1
ccc = 0
for value in vs1:
    ccc += 1
    count = vs1.count(value)
    if count > m1:
        i2 = i1
        m2 = m1
        i1 = value
        m1 = count

m3 = 0
i3 = -1
m4 = 0
i4 = -1
ccc2 = 0
for value in vs2:
    ccc2 += 1
    count = vs2.count(value)
    if count > m3:
        i4 = i3
        m4 = m3
        i3 = value
        m3 = count

if i1 != i3:
    print((ccc - m1) + (ccc2 - m3))
else:
    if m2 > m4:
        print((ccc - m2) + (ccc2 - m3))
    else:
        print((ccc - m1) + (ccc2 - m4))
Problem p03244 (Python) — buggy submission, verdict: Time Limit Exceeded

import collections

n = int(input())
v = input().split(" ")
"""
n = 10000
# v = [_i % 10 for _i in range(n)]
v = [_i for _i in range(n)]
n = 10
v = [1, 1, 1, 1, 1, 1, 1, 1, 1, 2]
"""
if len(set(v)) == 1:
    print(n // 2)
else:
    odds = v[1::2]
    _o = collections.Counter(odds)
    r_o = {str(v): k for k, v in _o.items()}
    evens = v[::2]
    _e = collections.Counter(evens)
    r_e = {str(v): k for k, v in _e.items()}
    ans1 = 0
    tmp = max(_o.values())
    ans1 += len(odds) - tmp
    key = r_o[str(tmp)]
    if key in _e.keys():
        _e[key] = 0
    ans1 += len(evens) - max(_e.values())

    ans2 = 0
    _o = collections.Counter(odds)
    r_o = {str(v): k for k, v in _o.items()}
    _e = collections.Counter(evens)
    r_e = {str(v): k for k, v in _e.items()}
    tmp = max(_e.values())
    ans2 += len(evens) - tmp
    key = r_e[str(tmp)]
    if key in _o.keys():
        _o[key] = 0
    ans2 += len(evens) - max(_o.values())

    print(min(ans1, ans2))


Error: TLE

Fixed submission:

n = int(input())
v = input().split(" ")
if len(set(v)) == 1:
    print(n // 2)
else:
    ans = 0
    odds = v[1::2]
    evens = v[::2]
    ans += len(odds) - max([odds.count(_o) for _o in set(odds)])
    ans += len(evens) - max([evens.count(_o) for _o in set(evens)])
    print(ans)