Problem:


Score : 300 points

Problem Statement

A sequence a_1,a_2,... ,a_n is said to be /\/\/\/ when the following conditions are satisfied:

For each i = 1,2,..., n-2, a_i = a_{i+2}.

Exactly two different numbers appear in the sequence.

You are given a sequence v_1,v_2,...,v_n whose length is even.
We would like to make this sequence /\/\/\/ by replacing some of its elements.
Find the minimum number of elements that needs to be replaced.

Constraints

2 \leq n \leq 10^5

n is even.

1 \leq v_i \leq 10^5

v_i is an integer.

Input

Input is given from Standard Input in the following format:

n
v_1 v_2 ... v_n

Output

Print the minimum number of elements that needs to be replaced.

Sample Input 1

4
3 1 3 2

Sample Output 1

1

The sequence 3,1,3,2 is not /\/\/\/, but we can make it /\/\/\/ by replacing one of its elements: for example, replace the fourth element to make it 3,1,3,1.

Sample Input 2

6
105 119 105 119 105 119

Sample Output 2

0

The sequence 105,119,105,119,105,119 is /\/\/\/.

Sample Input 3

4
1 1 1 1

Sample Output 3

2

The elements of the sequence 1,1,1,1 are all the same, so it is not /\/\/\/.



Sample input:
4
3 1 3 2


Sample output:
1

Submission status: Runtime Error

Solution code:
from collections import Counter
n = int(input())
arr = list(map(int, input().split()))

odd_list =[]
num_list =[]

for i in range(n):
    if i%2 == 0:
        odd_list.append(arr[i])
    if i%2 != 0:
        num_list.append(arr[i])

odd_count = Counter(odd_list)
num_count = Counter(num_list)
odd1 = odd_count[odd_count.most_common()[0][0]]
num1 = num_count[num_count.most_common()[0][0]]

if odd1 != num1:
    print(n-odd_count.most_common()[0][1]-num_count.most_common()[0][1])
    exit()

if odd1 == odd2:
    odd2 = odd_count[odd_count.most_common()[1][0]]
    num2 = num_count[num_count.most_common()[1][0]]

Submission status: Runtime Error

Solution code:
from collections import Counter
n = int(input())
arr = list(map(int, input().split()))

odd_list =[]
num_list =[]

for i in range(n):
    if i%2 == 0:
        odd_list.append(arr[i])
    if i%2 != 0:
        num_list.append(arr[i])

odd_count = Counter(odd_list)
num_count = Counter(num_list)
odd1 = odd_count[odd_count.most_common()[0][0]]
num1 = num_count[num_count.most_common()[0][0]]



if len(set(arr)) == 1:
    print(int(n/2))
    exit()

if len(set(num_list))==1 and len(set(odd_list))==1:
    print(0)
    exit()

if len(set(odd_count)) == 1 and len(set(num_count)) != 1:
    num2 = num_count[num_count.most_common()[1][0]]
    if odd_list[0] == num_count.most_common()[0][0]:
        print(int(n/2)-num2)
        exit()
    if odd_list[0] != num_count.most_common()[0][0]:
        print(int(n/2)-num1)
        exit()

if len(set(odd_count)) != 1 and len(set(num_count)) == 1:
    odd2 = odd_list[odd_count.most_common()[1][0]]
    if num_list[0] == odd_count.most_common()[0][0]:
        print(int(n/2)-odd2)
        exit()
    if num_list[0] != odd_count.most_common()[0][0]:
        print(int(n/2)-odd1)
        exit()

odd2 = odd_count[odd_count.most_common()[1][0]]
num2 = num_count[num_count.most_common()[1][0]]

if odd_count.most_common()[0][0] != num_count.most_common()[0][0]:
    print(n-odd1-num1)

if odd_count.most_common()[0][0] == num_count.most_common()[0][0]:
    print(min(n-odd1-num2, n-odd2-num1))

Submission status: Runtime Error

Solution code:
# 初期入力
from collections import Counter
import sys
input = sys.stdin.readline  #文字列では使わない
n = int(input())
v = list(map(int, input().split()))
vo1 =v[1::2]
ve2 =v[0::2]
co1_k,co1_v = zip(*Counter(vo1).most_common())
ce2_k,ce2_v = zip(*Counter(ve2).most_common())
"""
co1_l =list(co1.values())
ce2_l =list(ce2.values())
co1_l.sort(reverse=True)
ce2_l.sort(reverse=True)
"""
ans =0

if vo1 ==ve2:
    ans =len(vo1)
elif len(co1_v) ==len(ce2_v) ==1:
    ans =0
elif co1_k[0] ==ce2_k[0]:
    if len(co1_v) ==1:
        ans =sum(ce2_v[1:])
    elif len(ce2_v) ==1:
        ans =sum(co1_v[1:])
    elif len(co1_v) ==len(ce2_v) ==2:
        ans1 =co1_v[1] +ce2_v[0]
        ans2 =co1_v[0] +ce2_v[1]
        ans =min(ans1,ans2)
    elif len(co1_v) ==2:
        ans1 =co1_v[1] +ce2_v[0] +sum(ce2_v[2:])
        ans2 =co1_v[0] +sum(ce2_v[1:])
        ans =min(ans1,ans2)
    elif len(ce2_v) ==2:
        ans1 =ce2_v[1] +co1_v[0] +sum(co1_v[2:])
        ans2 =ce2_v[0] +sum(co1_v[1:])
        ans =min(ans1,ans2)
    else:
        ans1 =sum(co1_v[1:]) +ce2_v[0] +sum(ce2_v[2:] )
        ans1 =sum(ce2_v[1:]) +co1_v[0] +sum(co1_v[2:] )
        ans =min(ans1,ans2)
else: 
    if len(co1_v) ==1:
        ans =sum(ce2_v[1:])
    elif len(ce2_v) ==1:
        ans =sum(co1_v[1:])
    else:
        ans =sum(co1_v[1:]) +sum(ce2_v[1:])  
   
print(ans)

Submission status: Runtime Error

Solution code:
from collections import Counter

n, *v = map(int, open(0).read().split())
vo = Counter(v[::2])
ve = Counter(v[1::2])
vo_mc = vo.most_common()[0]
ve_mc = ve.most_common()[0]
if vo_mc[0] == ve_mc[0]: 
    if vo_mc[1] > ve_mc[1]:
        ans = n//2 - vo_mc[1]
        if ve_mc[1] != n//2:
            ans += n//2 - ve.most_common()[1][1]
        else:
            ans += n//2
    elif vo_mc[1] < ve_mc[1]:
        ans =  n//2 - ve_mc[1]
        if vo_mc[1] != n//2:
            ans += n//2 - vo.most_common()[1][1]
        else:
            ans += n//2
else:
    ans = n//2 - vo_mc[1] + n//2 - ve_mc[1]
print(ans)

Submission status: Runtime Error

Solution code:
from collections import Counter
n = int(input())
arr = list(map(int, input().split()))

if n == 2 and arr[0] != arr[1]:
    print(0)
    exit()

if n == 2 and arr[0] == arr[1]:
    print(1)
    exit()

odd_list =[]
num_list =[]

for i in range(n):
    if i%2 == 0:
        odd_list.append(arr[i])
    if i%2 != 0:
        num_list.append(arr[i])

odd_count = Counter(odd_list)
num_count = Counter(num_list)
odd1 = odd_count[odd_count.most_common()[0][0]]
num1 = num_count[num_count.most_common()[0][0]]



if len(set(arr)) == 1:
    print(int(n/2))
    exit()

if len(set(num_list))==1 and len(set(odd_list))==1:
    print(0)
    exit()

if len(set(odd_count)) == 1 and len(set(num_count)) != 1:
    num2 = num_count[num_count.most_common()[1][0]]
    if odd_list[0] == num_count.most_common()[0][0]:
        print(int(n/2)-num2)
        exit()
    if odd_list[0] != num_count.most_common()[0][0]:
        print(int(n/2)-num1)
        exit()

if len(set(odd_count)) != 1 and len(set(num_count)) == 1:
    odd2 = odd_list[odd_count.most_common()[1][0]]
    if num_list[0] == odd_count.most_common()[0][0]:
        print(int(n/2)-odd2)
        exit()
    if num_list[0] != odd_count.most_common()[0][0]:
        print(int(n/2)-odd1)
        exit()

odd2 = odd_count[odd_count.most_common()[1][0]]
num2 = num_count[num_count.most_common()[1][0]]

if odd_count.most_common()[0][0] != num_count.most_common()[0][0]:
    print(n-odd1-num1)

if odd_count.most_common()[0][0] == num_count.most_common()[0][0]:
    print(min(n-odd1-num2, n-odd2-num1))

Submission status: Runtime Error

Solution code:
from collections import Counter
n = int(input())
arr = list(map(int, input().split()))

if n == 2 and arr[0] != arr[1]:
    print(0)
    exit()

if n == 2 and arr[0] == arr[1]:
    print(1)
    exit()

odd_list =[]
num_list =[]

for i in range(n):
    if i%2 == 0:
        odd_list.append(arr[i])
    if i%2 != 0:
        num_list.append(arr[i])

odd_count = Counter(odd_list)
num_count = Counter(num_list)
odd1 = odd_count[odd_count.most_common()[0][0]]
num1 = num_count[num_count.most_common()[0][0]]



if len(set(arr)) == 1:
    print(int(n/2))
    exit()

if len(set(num_arr))==1 and len(set(odd_arr))==1:
    print(0)
    exit()

if len(set(odd_count)) == 1 and len(set(num_count)) != 1:
    num2 = num_count[num_count.most_common()[1][0]]
    if odd_list[0] == num_count.most_common()[0][0]:
        print(int(n/2)-num2)
        exit()
    if odd_list[0] != num_count.most_common()[0][0]:
        print(int(n/2)-num1)
        exit()

if len(set(odd_count)) != 1 and len(set(num_count)) == 1:
    odd2 = odd_list[odd_count.most_common()[1][0]]
    if num_list[0] == odd_count.most_common()[0][0]:
        print(int(n/2)-odd2)
        exit()
    if num_list[0] != odd_count.most_common()[0][0]:
        print(int(n/2)-odd1)
        exit()

odd2 = odd_count[odd_count.most_common()[1][0]]
num2 = num_count[num_count.most_common()[1][0]]

if odd_count.most_common()[0][0] != num_count.most_common()[0][0]:
    print(n-odd1-num1)

if odd_count.most_common()[0][0] == num_count.most_common()[0][0]:
    print(min(n-odd1-num2, n-odd2-num1))

Submission status: Runtime Error

Solution code:
from collections import Counter
n = int(input())
arr = list(map(int, input().split()))

if n == 2 and arr[0] != arr[1]:
    print(0)
    exit()

if n == 2 and arr[0] == arr[1]:
    print(1)
    exit()

odd_list =[]
num_list =[]

for i in range(n):
    if i%2 == 0:
        odd_list.append(arr[i])
    if i%2 != 0:
        num_list.append(arr[i])

odd_count = Counter(odd_list)
num_count = Counter(num_list)
odd1 = odd_count[odd_count.most_common()[0][0]]
num1 = num_count[num_count.most_common()[0][0]]



if len(set(arr)) == 1:
    print(int(n/2))
    exit()

if len(set(odd_count)) == 1 and len(set(num_count)) != 1:
    num2 = num_count[num_count.most_common()[1][0]]
    if odd_list[0] == num_count.most_common()[0][0]:
        print(int(n/2)-num2)
        exit()
    if odd_list[0] != num_count.most_common()[0][0]:
        print(int(n/2)-num1)
        exit()

if len(set(odd_count)) != 1 and len(set(num_count)) == 1:
    odd2 = odd_list[odd_count.most_common()[1][0]]
    if num_list[0] == odd_count.most_common()[0][0]:
        print(int(n/2)-odd2)
        exit()
    if num_list[0] != odd_count.most_common()[0][0]:
        print(int(n/2)-odd1)
        exit()

odd2 = odd_count[odd_count.most_common()[1][0]]
num2 = num_count[num_count.most_common()[1][0]]

if odd_count.most_common()[0][0] != num_count.most_common()[0][0]:
    print(n-odd1-num1)

if odd_count.most_common()[0][0] == num_count.most_common()[0][0]:
    print(min(n-odd1-num2, n-odd2-num1))

Submission status: Runtime Error

Solution code:
from collections import Counter
n = int(input())
arr = list(map(int, input().split()))

odd_list =[]
num_list =[]

for i in range(n):
    if i%2 == 0:
        odd_list.append(arr[i])
    if i%2 != 0:
        num_list.append(arr[i])

odd_count = Counter(odd_list)
num_count = Counter(num_list)
odd1 = odd_count[odd_count.most_common()[0][0]]
num1 = num_count[num_count.most_common()[0][0]]

if n == 2 and arr[0] != arr[1]:
    print(0)
    exit()

if n == 2 and arr[0] == arr[1]:
    print(1)
    exit()

if len(set(arr)) == 1:
    print(int(n/2))
    exit()

if len(set(odd_count)) == 1 and len(set(num_count)) != 1:
    num2 = num_count[num_count.most_common()[1][0]]
    if odd_list[0] == num_count.most_common()[0][0]:
        print(int(n/2)-num2)
        exit()
    if odd_list[0] != num_count.most_common()[0][0]:
        print(int(n/2)-num1)
        exit()

if len(set(odd_count)) != 1 and len(set(num_count)) == 1:
    odd2 = odd_list[odd_count.most_common()[1][0]]
    if num_list[0] == odd_count.most_common()[0][0]:
        print(int(n/2)-odd2)
        exit()
    if num_list[0] != odd_count.most_common()[0][0]:
        print(int(n/2)-odd1)
        exit()

odd2 = odd_count[odd_count.most_common()[1][0]]
num2 = num_count[num_count.most_common()[1][0]]

if odd_count.most_common()[0][0] != num_count.most_common()[0][0]:
    print(n-odd1-num1)

if odd_count.most_common()[0][0] == num_count.most_common()[0][0]:
    print(min(n-odd1-num2, n-odd2-num1))

Submission status: Runtime Error

Solution code:
from collections import Counter
n = int(input())
arr = list(map(int, input().split()))

odd_list =[]
num_list =[]

for i in range(n):
    if i%2 == 0:
        odd_list.append(arr[i])
    if i%2 != 0:
        num_list.append(arr[i])

odd_count = Counter(odd_list)
num_count = Counter(num_list)
odd1 = odd_count[odd_count.most_common()[0][0]]
num1 = num_count[num_count.most_common()[0][0]]


if len(set(arr)) == 1:
    print(int(n/2))
    exit()

if len(set(odd_count)) == 1 and len(set(num_count)) != 1:
    num2 = num_count[num_count.most_common()[1][0]]
    if odd_list[0] == num_count.most_common()[0][0]:
        print(int(n/2)-num2)
        exit()
    if odd_list[0] != num_count.most_common()[0][0]:
        print(int(n/2)-num1)
        exit()

if len(set(odd_count)) != 1 and len(set(num_count)) == 1:
    odd2 = odd_list[odd_count.most_common()[1][0]]
    if num_list[0] == odd_count.most_common()[0][0]:
        print(int(n/2)-odd2)
        exit()
    if num_list[0] != odd_count.most_common()[0][0]:
        print(int(n/2)-odd1)
        exit()

odd2 = odd_count[odd_count.most_common()[1][0]]
num2 = num_count[num_count.most_common()[1][0]]

if odd_count.most_common()[0][0] != num_count.most_common()[0][0]:
    print(n-odd1-num1)

if odd_count.most_common()[0][0] == num_count.most_common()[0][0]:
    print(min(n-odd1-num2, n-odd2-num1))

Submission status: Runtime Error

Solution code:
from collections import Counter
n = int(input())
arr = list(map(int, input().split()))

odd_list =[]
num_list =[]

for i in range(n):
    if i%2 == 0:
        odd_list.append(arr[i])
    if i%2 != 0:
        num_list.append(arr[i])

odd_count = Counter(odd_list)
num_count = Counter(num_list)
odd1 = odd_count[odd_count.most_common()[0][0]]
num1 = num_count[num_count.most_common()[0][0]]


if len(set(arr)) == 1:
    print(int(n/2))
    exit()

if len(set(odd_count)) == 1 and len(set(num_count)) != 1:
    num2 = num_count[num_count.most_common()[1][0]]
    if odd_list[0] == num_count.most_common()[0][0]:
        print(int(n/2)-num2)
        exit()
    if odd_list[0] != num_count.most_common()[0][0]:
        print(int(n/2)-num1)
        exit()

if len(set(odd_count)) != 1 and len(set(num_count)) == 1:
    odd2 = odd_list[odd_count.most_common()[1][0]]
    if num_count[0] == odd_count.most_common()[0][0]:
        print(int(n/2)-odd2)
        exit()
    if num_list[0] != odd_count.most_common()[0][0]:
        print(int(n/2)-odd1)
        exit()

odd2 = odd_count[odd_count.most_common()[1][0]]
num2 = num_count[num_count.most_common()[1][0]]

if odd_count.most_common()[0][0] != num_count.most_common()[0][0]:
    print(n-odd1-num1)

if odd_count.most_common()[0][0] == num_count.most_common()[0][0]:
    print(min(n-odd1-num2, n-odd2-num1))

Submission status: Runtime Error

Solution code:
from collections import Counter
n = int(input())
v = list(map(int,input().split()))

if len(set(v)) == 1:
    print(n//2)
else:

    c1 = Counter(v[::2])
    c2 = Counter(v[1::2])
    o = c1.most_common(2)
    e = c2.most_common(2)
    o.append((0,0))
    e.append((0,0))
    if o[0][0] == e[0][0]:
        print(min(n-o[1][1]-e[0][1],n-o[0][1]-e[1][1]))
    else:
        print(n-o(2)[0][1]-e(2)[0][1])

Submission status: Runtime Error

Solution code:
n = int(input())
v = list(map(int, input().split()))
a = sorted(([i,v[::2].count(i)] for i in set(v[::2])), key=lambda x:x[1])
b = sorted(([j,v[1::2].count(j)] for j in set(v[1::2])),key=lambda x:x[1])
if a[-1]!=b[-1]:
    print(n-a[-1][1]-b[-1][1])
elif len(a) == 1 and len(b) == 1:
    print(min(a[-1][1],b[-1][1]))
elif len(a) ==1:
    print(n-a[-1][1]-b[-2][1])
elif len(b) ==1:
    print(n-a[-2][1]-b[-1][1])
else:
    print(min(n-a[-2][1]-b[-1][1],n-a[-1][1]-b[-2][1])

Submission status: Runtime Error

Solution code:
n=int(input())
v=list(map(int,input().split()))
d1=[0]*(10**5+1)
d2=[0]*(10**5+1)

for i in range(n):
    if i%2==0:
        d1[v[i]]+=1
    else:
        d2[v[i]]+=1
assert n-max(d1)-max(d2)<0
print(n-max(d1)-max(d2))

Submission status: Runtime Error

Solution code:
from collections import deque
n=int(input())
v=list(map(int,input().split()))
d1={}
d2={}
l1=[]
l2=[]
for i in range(n):
    num=v[i]
    if i%2==0:
        try:
            d1[num]+=1
        except:
            d1[num]=1
    else:
        try:
            d2[num]+=1
        except:
            d2[num]=1
for i in d1:
    l1.append([d1[i],i])
for i in d2:
    l2.append([d2[i],i])
l1.sort(reverse=True)
l2.sort(reverse=True)
ans=n
if l1[0][1]!=l2[0][1]:
    ans-=(l1[0][0]+l2[0][0])
elif len(l1)==1 and len(l2)==1:
    ans//=2
elif len(l1)==1:
    ans-=l2[1][0]
elif len(l2)==1
    ans-=l1[1][0]
else:
    a=ans-l1[0][0]-l2[1][0]
    b=ans-l1[1][0]-l2[0][0]
    ans=min(a,b)
print(ans)

Submission status: Runtime Error

Solution code:
from collections import Counter
n = int(input())
v = tuple(map(int, input().split()))
c1 = Counter(v[::2])
c2 = Counter(v[1::2])
if len(set(v)) == 1:
    print(n // 2)
else:
    c1m = c1.most_common(1)
    c2m = c2.most_common(1)
    if c1m[0][0] == c2m[0][0]:
        print(min(n - c1m[0][1] - c2m[1][1], n - c1m[1][1] - c2m[0][1]))
    else:
        print(n - c1m[0][1] - c2m[0][1])

Submission status: Runtime Error

Solution code:
import collections
n = int(input())
v = list(map(int,input().split()))
v_odd = []
v_even = []
for i,v in enumerate(v):
    if i % 2:
        v_even.append(v)
    else:
        v_odd.append(v)
odd_n = len(v_odd)
even_n = len(v_even)
v_odd = collections.Counter(v_odd)
v_odd = sorted(v_odd.items(), key=lambda x:x[1],reverse=True)
v_even = collections.Counter(v_even)
v_even = sorted(v_even.items(), key=lambda x:x[1],reverse=True)

if v_odd[0] == v_even[0]:
    if v_odd[1][1] < v_even[1][1]:
        v_even.pop(0)
    elif v_odd[1][1] > v_even[1][1]:
        v_odd.pop(0)

num = v_odd[0][0]

ans = odd_n-v_odd[0][1]
st = 0
for i,v in v_even:
    if num == i:
        continue
    else:
        st = v
        break
print(ans+(even_n-st))

Submission status: Runtime Error

Solution code:
from collections import Counter

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

v_0 = v[0:n-1:2]
v_1 = v[1:n:2]

v_0_max = Counter(v_0).most_common()[0][0]
v_1_max = Counter(v_1).most_common()[0][0]

if len(set(v_0)) == len(set(v_1)):
    if v_0_max == v_1_max:
        res = len(v_0)
    else:
        res = 0

else:
    v_0_sec = Counter(v_0).most_common()[1][0]
    v_1_sec = Counter(v_1).most_common()[1][0]

    if v_0_max == v_1_max:
        if v_0_sec > v_1_sec:
            v_0_max = v_0_sec
        else:
            v_1_max = v_1_sec

    res = 0
    for v0, v1 in zip(v_0,v_1):
        if v0 != v_0_max:
            res += 1
        if v1 != v_1_max:
            res += 1

print(res)

Submission status: Runtime Error

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

if len(set(v)) == 1:
    print(n // 2)
else:
    cnt_even = [0] * 10 ** 5
    cnt_odd = [0] * 10 ** 5
    max_even = 0
    max_odd = 0
    for i in range(n):
        if i % 2 == 0:
            cnt_even[v[i]] += 1
            if cnt_even[v[i]] > cnt_even[max_even]:
                max_even = v[i]
        else:
            cnt_odd[v[i]] += 1
            if cnt_odd[v[i]] > cnt_even[max_odd]:
                max_odd = v[i]
    print(n - cnt_even[max_even] - cnt_odd[max_odd])

Submission status: Runtime Error

Solution code:
n = int(input())
V = list(map(int, input().split()))

from collections import Counter

C0 = Counter(V[0::2])
C1 = Counter(V[1::2])

n0 = C0.most_common()[0][0]
n1 = C1.most_common()[0][0]



if n0 == n1:
    if C0.most_common()[1][1] >= C1.most_common()[1][1]:
        n0 = C0.most_common()[1][0]
    else:
        n1 = C1.most_common()[1][0]
    
count = 0
for v in V[0::2]:
    if v != n0:
        count += 1

for v in V[1::2]:
    if v != n1:
        count += 1
print(count)

Submission status: Runtime Error

Solution code:
n=int(input())
a=list(map(int,input().split()))
if len(set(a))=1:
  print(n//2)
else:
  x=[]
  y=[]
  cnt=0
  for i in a:
    if cnt%2==0:
      x.append(i)
      cnt+=1
    else:
      y.append(i)
      cnt+=1
  s=list(set(x))
  t=list(set(y))
  o=0
  p=0
  for i in s:
    o=max(o,x.count(i))
  for i in t:
    p=max(p,y.count(i))
  print(n-o-p)

Submission status: Runtime Error

Solution code:
from collections import Counter
n = int(input())
lis = list(map(int,input().split()))
even = lis[0::2]
odd = lis[1::2]
A = Counter(even).most_common()
B = Counter(odd).most_common()
if A[0][0] != B[0][0]:
    print(n - A[0][1]-B[0][1])
else:
    print(min(n-A[1][1]-B[0][1],n-A[0][1]-B[1][1]))

Submission status: Runtime Error

Solution code:
from collections import Counter
n = int(input())
lis = list(map(int,input().split()))
even = lis[0::2]
odd = lis[1::2]
A = Counter(even).most_common()
B = Counter(odd).most_common()
if A[0][0] != B[0][0]:
    print(n - A[0][1]-B[0][1])
else:
    print(min(n-A[1][1]-B[0][1],n-A[0][1]-B[1][1]))

Submission status: Runtime Error

Solution code:
from collections import Counter

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

even_counter=Counter(v[::2])
odd_counter=Counter(v[1::2])

even_counter_list = sorted(even_counter.items(), key=lambda x:x[1], reverse=True)
odd_counter_list = sorted(odd_counter.items(), key=lambda x:x[1], reverse=True)


if max(even_counter)!=max(odd_counter):
    print(n-even_counter[max(even_counter)]-odd_counter[max(odd_counter)])
else:
    if len(even_counter)!=1 and len(odd_counter)!=1:
        print(min(n-even_counter[even_counter_list[0,1]]-odd_counter[odd_counter_list[1,1]],n-even_counter[even_counter_list[1,1]]-odd_counter[odd_counter_list[0,1]]))
    elif len(even_counter)==1 and len(odd_counter)!=1:
        print(n-even_counter[max(even_counter)]-odd_counter[odd_counter_list[1,1]])
    elif len(even_counter)!=1 and len(odd_counter)==1:
        print(n-even_counter[even_counter_list[1,1]]-odd_counter[max(odd_counter)])
    else:
        print(n//2)

Submission status: Runtime Error

Solution code:
from collections import Counter
n = int(input())
V = list(map(int,input().split()))
A = Counter(V[0::2]).most_common(2)
A = Counter(V[1::2]).most_common(2)
A.append((0,0))
A.append((0,0))
if A[0][0]!=B[0][0]:
    print(n-(A[0][1]+B[0][1]))
else:
    print(min(n-(A[1][1]+B[0][1]),n-(A[0][1]+B[1][1])))

Submission status: Runtime Error

Solution code:
from collections import Counter
n = int(input())
v = list(map(int, input().split()))
v1, v2 = v[::2], [1::2]
vv1 = Counter(v1).most_common()
vv2 = Counter(v2).most_common()

if len(set(v)) == 1:
    print(n//2)
if vv1[0] != vv2[0]:
    print(n - vv1[0][1] - vv2[0][1])
else:
    print(n - max(vv1[1][1] + vv2[0][1], vv1[0][1] + vv2[1][1]))

Submission status: Runtime Error

Solution code:
from collections import Counter
n = int(input())
v = list(map(int, input().split()))
v1, v2 = [], []
for i in range(n):
    if i%2:
        v1.append(v[i])
    else:
        v2.append(v[i])
vv1 = Counter(v1).most_common()
vv2 = Counter(v2).most_common()
if vv1[0] != vv2[0]:
    print(n - vv1[0][1] - vv2[0][1])
else:
    if -(-n)//2 - vv1[0][1] < n//2 - vv2[0][1]:
        print(n - vv1[0][1] - vv2[1][1])
    else:
        print(n - vv1[1][1] - vv2[0][1])

Submission status: Runtime Error

Solution code:
import sys, re
from math import ceil, floor, sqrt, pi, factorial#, gcd
from copy import deepcopy
from collections import Counter, deque
from heapq import heapify, heappop, heappush
from itertools import accumulate, product, combinations, combinations_with_replacement
from bisect import bisect, bisect_left
from functools import reduce
from decimal import Decimal, getcontext
# input = sys.stdin.readline 
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_list(N): return [s_list() for _ in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 6)
INF = float('inf')
MOD = 10 ** 9 + 7

def main():
    n = i_input()
    num_list = i_list()

    zero_list = []
    one_list = []
    for i in range(n):
        if i % 2 == 0:
            zero_list.append(num_list[i])
        else:
            one_list.append(num_list[i])

    zero_c = Counter(zero_list)
    one_c = Counter(one_list)

    zero_saihin_key = zero_c.most_common()[0][0]
    zero_saihin_val = zero_c.most_common()[0][1]
    one_saihin_key = zero_c.most_common()[0][0]
    one_saihin_val = one_c.most_common()[0][1]

    if zero_saihin_key != one_saihin_key:
        print(n - zero_saihin_val - one_saihin_val)
        exit()

    if num_list.count(zero_saihin_key) == n:
        print(n//2)
        exit()

    if len(zero_c) == 1:
        print(n//2 - one_c.most_common()[1][1])
    elif len(one_c) == 1:
        print(n//2 - zero_c.most_common()[1][1])
    else:
        count1 = n - zero_saihin_val - one_c.most_common()[1][1]
        count2 = n - zero_c.most_common()[1][1] - one_saihin_val
        print(min(count1, count2))

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import math
import collections

n=int(input())

l=list(map(int, input().split())) 


one=[]
two=[]

for i in range(0,int(math.floor(n/2))):
    one.append(l[int(2*i)])
    two.append(l[int(2*i+1)])

c_one = collections.Counter(one)
c_two = collections.Counter(two)


if c_one.most_common()[0][0]==c_two.most_common()[0][0]:
    if c_one.most_common()[0][1]==int(math.floor(n//2)):
        print(int(math.floor(n/2)))

    else:
        if c_one.most_common()[0][1]>c_two.most_common()[0][1]:
            print(int(n-c_one.most_common()[0][1]-c_two.most_common()[0][2]))

        elif c_one.most_common()[0][1]<c_two.most_common()[0][1]:
            print(int(n-c_one.most_common()[0][2]-c_two.most_common()[0][2]))

        else:
            print(int(n-c_one.most_common()[0][2]-c_two.most_common()[0][2]))
else:
    print(int(n-c_one.most_common()[0][1]-c_two.most_common()[0][1]))

Submission status: Runtime Error

Solution code:
import math
import collections

n=int(input())

l=list(map(int, input().split())) 


one=[]
two=[]

for i in range(0,int(math.floor(n/2))):
    one.append(l[2*i])
    two.append(l[2*i+1])

c_one = collections.Counter(one)
c_two = collections.Counter(two)


if c_one.most_common()[0][0]==c_two.most_common()[0][0]:
    if c_one.most_common()[0][1]==int(math.floor(n//2)):
        print(int(math.floor(n/2)))

    else:
        if c_one.most_common()[0][1]>c_two.most_common()[0][1]:
            print(n-c_one.most_common()[0][1]-c_two.most_common()[0][2])

        elif c_one.most_common()[0][1]<c_two.most_common()[0][1]:
            print(n-c_one.most_common()[0][2]-c_two.most_common()[0][2])

        else:
            print(n-c_one.most_common()[0][2]-c_two.most_common()[0][2])
else:

    print(n-c_one.most_common()[0][1]-c_two.most_common()[0][1])

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sun May 31 18:36:13 2020

@author: NEC-PCuser
"""
n = int(input())
l = list(map(int, input().split()))
dic_gusu = {}
dic_kisu = {}

for i in range(0, n):
    if (i % 2 == 0):
        if (l[i] in dic_gusu):
            dic_gusu[l[i]] += 1
        else:
            dic_gusu[l[i]] = 1
    if (i % 2 == 1):
        if (l[i] in dic_kisu):
            dic_kisu[l[i]] += 1
        else:
            dic_kisu[l[i]] = 1
dic_kisu = sorted(dic_kisu.items(), key = lambda x : x[1])
dic_gusu = sorted(dic_gusu.items(), key = lambda x : x[1])

count = 0
if (len(dic_kisu) == 1 and len(dic_gusu) == 1 and dic_kisu[len(dic_kisu) - 1][0] == dic_gusu[len(dic_gusu) - 1][0]):
    count = n // 2
elif (dic_kisu[len(dic_kisu) - 1][0] != dic_gusu[len(dic_gusu) - 1][0]):
    for i in range(0, len(dic_kisu) - 1):
        count += dic_kisu[i][1]
    for i in range(0, len(dic_gusu) - 1):
        count += dic_gusu[i][1]
else:
    for i in range(0, len(dic_kisu)):
        count += dic_kisu[i][1]
    for i in range(0, len(dic_gusu)):
        count += dic_gusu[i][1]
    count_tmp = count
    count_ans = count_tmp - dic_kisu[len(dic_kisu) - 1][1] - dic_kisu[len(dic_gusu) - 2][1] 
    count_ans2 = count_tmp  - dic_kisu[len(dic_kisu) - 2][1] - dic_kisu[len(dic_gusu) - 1][1]
    count = min([count_ans, count_ans2])    
        
print(count)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sun May 31 18:36:13 2020

@author: NEC-PCuser
"""
n = int(input())
l = list(map(int, input().split()))
dic_gusu = {}
dic_kisu = {}

for i in range(0, n):
    if (i % 2 == 0):
        if (l[i] in dic_gusu):
            dic_gusu[l[i]] += 1
        else:
            dic_gusu[l[i]] = 1
    if (i % 2 == 1):
        if (l[i] in dic_kisu):
            dic_kisu[l[i]] += 1
        else:
            dic_kisu[l[i]] = 1
dic_kisu = sorted(dic_kisu.items(), key = lambda x : x[1])
dic_gusu = sorted(dic_gusu.items(), key = lambda x : x[1])

count = 0
if (len(dic_kisu) == 1 and len(dic_gusu) == 1 and dic_kisu[len(dic_kisu) - 1][0] == dic_gusu[len(dic_gusu) - 1][0]):
    count = n // 2
elif (dic_kisu[len(dic_kisu) - 1][0] != dic_gusu[len(dic_gusu) - 1][0]):
    for i in range(0, len(dic_kisu) - 1):
        count += dic_kisu[i][1]
    for i in range(0, len(dic_gusu) - 1):
        count += dic_kisu[i][1]
else:
    for i in range(0, len(dic_kisu)):
        count += dic_kisu[i][1]
    for i in range(0, len(dic_kisu)):
        count += dic_kisu[i][1]
    count_tmp = count
    count_ans = count_tmp - dic_kisu[len(dic_kisu) - 1][1] - dic_kisu[len(dic_gusu) - 2][1] 
    count_ans2 = count_tmp  - dic_kisu[len(dic_kisu) - 2][1] - dic_kisu[len(dic_gusu) - 1][1]
    count = min([count_ans, count_ans2])     
        
print(count)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sun May 31 18:36:13 2020

@author: NEC-PCuser
"""
n = int(input())
l = list(map(int, input().split()))
dic_gusu = {}
dic_kisu = {}

for i in range(0, n):
    if (i % 2 == 0):
        if (l[i] in dic_gusu):
            dic_gusu[l[i]] += 1
        else:
            dic_gusu[l[i]] = 1
    if (i % 2 == 1):
        if (l[i] in dic_kisu):
            dic_kisu[l[i]] += 1
        else:
            dic_kisu[l[i]] = 1
dic_kisu = sorted(dic_kisu.items(), key = lambda x : x[1])
dic_gusu = sorted(dic_gusu.items(), key = lambda x : x[1])


if (len(dic_kisu) == 1 and len(dic_gusu) == 1 and dic_kisu[len(dic_kisu) - 1][0] == dic_gusu[len(dic_gusu) - 1][0]):
    count = n // 2
elif (dic_kisu[len(dic_kisu) - 1][0] != dic_gusu[len(dic_gusu) - 1][0]):
    for i in range(0, len(dic_kisu) - 1):
        count += dic_kisu[i][1]
    for i in range(0, len(dic_gusu) - 1):
        count += dic_kisu[i][1]
else:
    for i in range(0, len(dic_kisu)):
        count += dic_kisu[i][1]
    for i in range(0, len(dic_kisu)):
        count += dic_kisu[i][1]
    count_tmp = count
    count_ans = count_tmp - dic_kisu[len(dic_kisu) - 1][1] - dic_kisu[len(dic_gusu) - 2][1] 
    count_ans2 = count_tmp  - dic_kisu[len(dic_kisu) - 2][1] - dic_kisu[len(dic_gusu) - 1][1]
    count = min([count_ans, count_ans2])     
        
print(count)

Submission status: Runtime Error

Solution code:
N = int(input())
V =  list(map(int,input().split()))
l = V[0::2]
r = V[1::2]
#print(l,r)
from collections import Counter

l = list(Counter(l).most_common(2))
r = list(Counter(r).most_common(2))

if l[0][0] != r[0][0]:
    ans = N -( l[0][1] + r[0][1])
elif l[0][0] == r[0][0]:
    if len(l) == 1 and len(r) == 1:
        ans = N//2
    elif l[1][1] > r[1][1]:
        ans = N-(l[0][1] +  r[1][1])
    elif l[1][1] < r[1][1]:
        ans = N-(l[1][1] +  r[0][1])

print(ans)