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: Wrong Answer

Solution code:
n = int(input())
v = [int(i) for i in input().split(" ")]

even = {}
odd = {}
for i in range(0, n, 2):
    even[v[i + 1]] = even.get(v[i + 1], 0) + 1
    odd[v[i]] = odd.get(v[i], 0) + 1

max_even = 0
max_even_key = 0
second_max_even = -1
for key, value in even.items():
    if max_even < value:
        second_max_even = max_even
        max_even = value
        max_even_key = key

max_odd = 0
max_odd_key = 0
second_max_odd = -1
for key, value in odd.items():
    if max_odd < value:
        second_max_odd = max_odd
        max_odd = value
        max_odd_key = key

if max_even_key != max_odd_key:
    ans = n / 2 - max_even
    ans += n / 2 - max_odd
else:
    ans = min(n / 2 - second_max_even + n / 2 - max_odd, n /2 - max_even + n / 2 - second_max_odd)

print(int(ans))

Submission status: Wrong Answer

Solution code:
n = int(input())
v = [int(i) for i in input().split(" ")]

even = {}
odd = {}
for i in range(0, n, 2):
    even[v[i + 1]] = even.get(v[i + 1], 0) + 1
    odd[v[i]] = odd.get(v[i], 0) + 1

max_even = 0
max_even_key = 0
second_max_even = -1
for key, value in even.items():
    if max_even < value:
        second_max_even = max_even
        max_even = value
        max_even_key = key

max_odd = 0
max_odd_key = 0
second_max_odd = -1
for key, value in odd.items():
    if max_odd < value:
        second_max_odd = max_odd
        max_odd = value
        max_odd_key = key

if max_even_key != max_odd_key:
    ans = n / 2 - max_even
    ans += n / 2 - max_odd
else:
    ans1 = 10 ** 5
    ans2 = 10 ** 5
    if second_max_even != -1:
        ans1 = n / 2 - second_max_even + n / 2 - max_odd
    if second_max_odd != -1:
        ans2 = n /2 - max_even + n / 2 - second_max_odd
    ans = min(ans1, ans2)

print(int(ans))

Submission status: Wrong Answer

Solution code:
n = int(input())
v = [int(i) for i in input().split(" ")]

even = {}
odd = {}
for i in range(0, n, 2):
    even[v[i + 1]] = even.get(v[i + 1], 0) + 1
    odd[v[i]] = odd.get(v[i], 0) + 1

max_even = 0
max_even_key = 0
second_max_even = 0
for key, value in even.items():
    if max_even < value:
        second_max_even = max_even
        max_even = value
        max_even_key = key

max_odd = 0
max_odd_key = 0
second_max_odd = 0
for key, value in odd.items():
    if max_odd < value:
        second_max_odd = max_odd
        max_odd = value
        max_odd_key = key

if max_even_key != max_odd_key:
    ans = n / 2 - max_even
    ans += n / 2 - max_odd
else:
    if max_even < max_odd:
        ans = n / 2 + n / 2 - second_max_even
    else:
        ans = n / 2 + n / 2 - second_max_odd

print(int(ans))

Submission status: Wrong Answer

Solution code:
n = int(input())
v = [int(i) for i in input().split(" ")]

even = {}
odd = {}
for i in range(0, n, 2):
    even[v[i + 1]] = even.get(v[i + 1], 0) + 1
    odd[v[i]] = odd.get(v[i], 0) + 1

max_even = 0
max_even_key = 0
for key, value in even.items():
    if max_even < value:
        max_even = value
        max_even_key = key

max_odd = 0
max_odd_key = 0
for key, value in odd.items():
    if max_odd < value:
        max_odd = value
        max_odd_key = key

if max_even_key != max_odd_key:
    ans = n / 2 - max_even
    ans += n / 2 - max_odd
else:
    if max_even < max_odd:
        ans = n / 2 + n / 2 - max_even
    else:
        ans = n / 2 + n / 2 - max_odd

print(int(ans))

Submission status: Wrong Answer

Solution code:
# 2018-10-05 18:50
import collections

# arg = iter(["6", "105 119 105 119 105 119"])
# raw_input = lambda: arg.next()

n = int(raw_input())
A = map(int, raw_input().split(" "))

c1 = collections.Counter(A[::2])
c2 = collections.Counter(A[1::2])

res = n
for i in c1:
    for j in c2:
        if i != j:
            res = min(res, n - c1[i] - c2[j])
print res

Submission status: Wrong Answer

Solution code:
import collections

n = int(input())
v = [int(i) for i in input().split()]
c = 0
even = collections.Counter(v[0::2])
odd = collections.Counter(v[1::2])


if len(even) == 1 and len(odd) == 1:
    if v[0] == v[1]:
        c = int(n/2)
    else:
        c = 0
elif len(even) != 1:
    c += sum(list(even.values())) - max(list(even.values()))
elif len(odd) != 1:
    c += sum(list(odd.values())) - max(list(odd.values()))
    
print(c)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

odd = v[1::2]
even = v[0::2]

odd_most = Counter(odd).most_common(1)
even_most = Counter(even).most_common(1)

if odd_most[0][0] != even_most[0][0]:
    odd_new = [i for i in odd if i != odd_most[0][0]]
    even_new = [i for i in even if i != even_most[0][0]]
    print(len(odd_new + even_new))

else:
    odd_new = [i for i in odd if i != odd_most[0][0]]
    print(len(odd_new + even))

Submission status: Wrong Answer

Solution code:
n = int(input())
a = map(int, input().split())
x = len(set(a))

if x != 1:
	print(x-2)
else:
  print(n//2)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = map(int, input().split())
x = set(a)

if len(x) == 3:
  print(1)
elif len(x) == 2:
  print(0)
elif len(x) == 1:
  print(n // 2)

Submission status: Wrong Answer

Solution code:
# -*- coding : utf-8 -*-
from collections import Counter

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

even = []
odd = []

for i in range(n):
    if i % 2 == 0:
        even.append(v[i])
    else:
        odd.append(v[i])

even_most = Counter(even).most_common()
odd_most = Counter(odd).most_common()

ans = 0

if len(even) != even_most[0][1]:
    ans += len(even) - even_most[0][1]

if len(odd) != odd_most[0][1]:
    ans += len(odd) - odd_most[0][1]

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
v=list(input().split(" "))
count = 0


for i in range(0,n-2):
    if v[i]!=v[i+2]:
        count+=1
        
    if v[i]==v[i+1]:
        count+=1
        
print(count)

Submission status: Wrong Answer

Solution code:
n = int(input())
v=list(input().split(" "))
count = 0


for i in range(0,n-2):
    if v[i]!=v[i+2]:
        v[i+2]=v[i]
        count+=1
        
    if v[i]==v[i+1]:
        count+=1
        
print(count)

Submission status: Wrong Answer

Solution code:
n = int(input())
v=list(input().split(" "))
count = 0
print(v)

for i in range(0,n-2):
    if v[i]!=v[i+2]:
        v[i+2]=v[i]
        count+=1
        
    if v[i]==v[i+1]:
        count+=1
        
print(count)

Submission status: Wrong Answer

Solution code:
n = int(input())
v=list(input())
v_length=len(v)
count = 0

for i in range(0,n-2):
    if v[i]!=v[i+2]:
        v[i+2]=v[i]
        count+=1
    if v[i]==v[i+1]:
        count+=1
        
print(count)

Submission status: Wrong Answer

Solution code:
N = int(input())
d = [{}, {}]
W = input().split()
ans = 0

for i, v in enumerate(W):
    if v not in d[i%2]:
        d[i%2][v] = 0
    d[i%2][v] += 1

if(d[0]==d[1]):
    ans = N//2
else:
    ans = N - max(d[0].values()) - max(d[1].values())

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

n = int(input())
v = list(map(int, input().split()))
for_set_v = v # set用
set_v = set(v)
even = []
odd = []
count = 0 # 置き換えた回数
count_list = []
for num in range(n):
    if num % 2 == 0:
        even.append(v[num])
    else:
        odd.append(v[num])

even_most = Counter(even).most_common()
odd_most = Counter(odd).most_common()
#print(even_most)
#print(odd_most)
if len(set(v)) >= 2:
    if even_most[0][0] != odd_most[0][0]:
        if len(set(even)) != 1:
            count += (n/2) - int(even_most[0][1])
        if len(set(odd)) != 1:
            count += (n/2) - int(odd_most[0][1])
    else:
        try:
            count_list.append(n-int(even_most[0][1])-int(odd_most[1][1]))
            count_list.append(n-int(even_most[1][1])-int(odd_most[0][1]))
            print(count_list)
            count += int(min(count_list))
        except:
            if len(even_most) == 1:
                count += (n/2)-int(odd_most[1][1])
            elif len(odd_most) == 1:
                count += (n/2)-int(even_most[1][1])
else:
    count += (n/2)
print(int(count))

Submission status: Wrong Answer

Solution code:
from collections import Counter

n = int(input())
v = list(map(int, input().split()))
for_set_v = v # set用
set_v = set(v)
even = []
odd = []
count = 0 # 置き換えた回数
count_list = []
for num in range(n):
    if num % 2 == 0:
        even.append(v[num])
    else:
        odd.append(v[num])

even_most = Counter(even).most_common()
odd_most = Counter(odd).most_common()
#print(even_most)
#print(odd_most)
if len(set(v)) >= 2:
    if even_most[0][0] != odd_most[0][0]:
        if len(set(even)) != 1:
            count += (n/2) - int(even_most[0][1])
        if len(set(odd)) != 1:
            count += (n/2) - int(odd_most[0][1])
    else:
        try:
            count_list.append(n-int(even_most[0][1])-int(odd_most[1][1]))
            count_list.append(n-int(even_most[1][1])-int(odd_most[0][1]))
            count += int(max(count_list))
        except:
            if len(even_most) == 1:
                count += (n/2)-int(odd_most[1][1])
            elif len(odd_most) == 1:
                count += (n/2)-int(even_most[1][1])
else:
    count += (n/2)
print(int(count))

Submission status: Wrong Answer

Solution code:
from collections import Counter

n = int(input())
v = list(map(int, input().split()))
for_set_v = v # set用
set_v = set(v)
even = []
odd = []
count = 0 # 置き換えた回数
count_list = []
for num in range(n):
    if num % 2 == 0:
        even.append(v[num])
    else:
        odd.append(v[num])

even_most = Counter(even).most_common()
odd_most = Counter(odd).most_common()
print(even_most)
print(odd_most)
if len(set(v)) >= 2:
    if even_most[0][0] != odd_most[0][0]:
        if len(set(even)) != 1:
            count += (n/2) - int(even_most[0][1])
        if len(set(odd)) != 1:
            count += (n/2) - int(odd_most[0][1])
    else:
        try:
            count_list.append(n-int(even_most[0][1])-int(odd_most[1][1]))
            count_list.append(n-int(even_most[1][1])-int(odd_most[0][1]))
            count += int(max(count_list))
        except:
            if len(even_most) == 1:
                count += (n/2)-int(odd_most[1][1])
            elif len(odd_most) == 1:
                count += (n/2)-int(even_most[1][1])
else:
    count += (n/2)
print(int(count))

Submission status: Wrong Answer

Solution code:
from collections import Counter

n = int(input())
v = list(map(int, input().split()))
for_set_v = v # set用
set_v = set(v)
even = []
odd = []
count = 0 # 置き換えた回数
count_list = []
for num in range(n):
    if num % 2 == 0:
        even.append(v[num])
    else:
        odd.append(v[num])

even_most = Counter(even).most_common()
odd_most = Counter(odd).most_common()
#print(even_most)
#print(odd_most)
if len(set(v)) >= 2:
    if even_most[0][0] != odd_most[0][0]:
        if len(set(even)) != 1:
            count += (n/2) - int(even_most[0][1])
        if len(set(odd)) != 1:
            count += (n/2) - int(odd_most[0][1])
    else:
        try:
            count_list.append(n-int(even_most[0][1])-int(odd_most[1][1]))
            count_list.append(n-int(even_most[1][1])-int(odd_most[0][1]))
            count += int(max(count_list))
        except:
            if len(even_most) == 1:
                count += n-int(even_most[0][1])-int(odd_most[1][1])
            elif len(odd_most) == 1:
                count += n-int(even_most[1][1])-int(odd_most[0][1])
else:
    count += (n/2)
print(int(count))

Submission status: Wrong Answer

Solution code:
from collections import Counter

n = int(input())
v = list(map(int, input().split()))
for_set_v = v # set用
set_v = set(v)
even = []
odd = []
count = 0 # 置き換えた回数
count_list = []
for num in range(n):
    if num % 2 == 0:
        even.append(v[num])
    else:
        odd.append(v[num])

even_most = Counter(even).most_common()
odd_most = Counter(odd).most_common()
#print(even_most)
#print(odd_most)
"""if even_most[0][0] != odd_most[0][0]:
    if len(set(v)) >= 2:
        if len(set(even)) == 1:
            pass
        else:
            count += (n/2) - int(even_most[0][1])

        if len(set(odd)) == 1:
            pass
        else:
            count += (n/2) - int(odd_most[0][1])

    elif len(set(v)) < 2:
        if len(set(even)) == 1 and len(set(odd)) == 1:
            count += (n/2)"""
if len(set(v)) >= 2:
    if even_most[0][0] != odd_most[0][0]:
        if len(set(even)) != 1:
            count += (n/2) - int(even_most[0][1])
        if len(set(odd)) != 1:
            count += (n/2) - int(odd_most[0][1])
    else:
        try:
            count_list.append(n-int(even_most[0][1])-int(odd_most[1][1]))
            count_list.append(n-int(even_most[1][1])-int(odd_most[0][1]))
            count += int(max(count_list))
        except:
            if len(even_most) == 1:
                count += n-int(even_most[0][1])-int(odd_most[1][1])
            elif len(odd_most) == 1:
                count += n-int(even_most[1][1])-int(odd_most[0][1])
print(int(count))

Submission status: Wrong Answer

Solution code:
"""
C - /\/\/\/
"""
import collections
import numpy as np

n = int(input())

value = []
for part in input().split():
    value.append(int(part))

odd = value[0::2]
even = value[1::2]

#print(odd)
#print(even)

odd_set = collections.Counter(odd)
even_set = collections.Counter(even)

odd_cnt = np.array([[i, odd_set[i]] for i in odd_set])
even_cnt = np.array([[i, even_set[i]] for i in even_set])

#print(even_cnt)

# 数字
#print(even_cnt[:, 0])
# 個数
#print(even_cnt[:, 1])

# 個数優先でソート
odd_sort_index = np.argsort(odd_cnt[:, 1])
even_sort_index = np.argsort(even_cnt[:, 1])

odd_n = odd_cnt[odd_sort_index[0], 0]
even_n = even_cnt[even_sort_index[0], 0]

if even_n == odd_n:
    odd_0 = 0
    odd_1 = 0
    even_0 = 0
    even_1 = 0
    
    try:
        odd_0 = odd_cnt[odd_sort_index[0], 1]
    except:
        pass
    try:
        odd_1 = odd_cnt[odd_sort_index[1], 1]
    except:
        pass
    try:
        even_0 = even_cnt[even_sort_index[0], 1]
    except:
        pass
    try:
        even_1 = even_cnt[even_sort_index[1], 1]
    except:
        pass

    print(min(n - odd_0 - even_1, n - odd_1 - even_0))
else:
    print(n - odd_cnt[odd_sort_index[0], 1] - even_cnt[even_sort_index[0], 1])

Submission status: Wrong Answer

Solution code:
"""
C - /\/\/\/
"""
import collections
import numpy as np

n = int(input())

value = []
for part in input().split():
    value.append(int(part))

odd = value[0::2]
even = value[1::2]

#print(odd)
#print(even)

odd_set = collections.Counter(odd)
even_set = collections.Counter(even)

odd_cnt = np.array([[i, odd_set[i]] for i in odd_set])
even_cnt = np.array([[i, even_set[i]] for i in even_set])

#print(even_cnt)

# 数字
#print(even_cnt[:, 0])
# 個数
#print(even_cnt[:, 1])

# 個数優先でソート
odd_sort_index = np.argsort(odd_cnt[:, 1])
even_sort_index = np.argsort(even_cnt[:, 1])

odd_n = odd_cnt[0, 0]
even_n = even_cnt[0, 0]

if even_n == odd_n:
    odd_0 = 0
    odd_1 = 0
    even_0 = 0
    even_1 = 0
    
    try:
        odd_0 = odd_cnt[0, 1]
    except:
        pass
    try:
        odd_1 = odd_cnt[1, 1]
    except:
        pass
    try:
        even_0 = even_cnt[0, 1]
    except:
        pass
    try:
        even_1 = even_cnt[1, 1]
    except:
        pass

    print(min(n - odd_0 - even_1, n - odd_1 - even_0))
else:
    print(n - odd_cnt[0, 1] - even_cnt[0, 1])

Submission status: Wrong Answer

Solution code:
"""
C - /\/\/\/
"""
import collections
import numpy as np

n = int(input())

value = []
for part in input().split():
    value.append(int(part))

odd = value[0::2]
even = value[1::2]

#print(odd)
#print(even)

odd_set = collections.Counter(odd)
even_set = collections.Counter(even)

odd_cnt = np.array([[i, odd_set[i]] for i in odd_set])
even_cnt = np.array([[i, even_set[i]] for i in even_set])

#print(even_cnt)

# 数字
#print(even_cnt[:, 0])
# 個数
#print(even_cnt[:, 1])

# 個数優先でソート
odd_sort_index = np.argsort(odd_cnt[:, 1])
even_sort_index = np.argsort(even_cnt[:, 1])

#print(even_sort_index)

odd_max = 0
even_max = 0
# 数字が一緒でなく、個数が最大を求める

for odd_i in odd_sort_index:
    for even_i in even_sort_index:
        
        odd_n = odd_cnt[odd_i, 0]
        even_n = even_cnt[even_i, 0]

        if odd_n != even_n:
            odd_max = max(odd_max, odd_cnt[odd_i, 1])
            even_max = max(even_max, even_cnt[even_i, 1])
            break

if odd_max == 0 and even_max == 0:
    print(n // 2)
else:
    #print(odd_max)
    #print(even_max)
    print(n - odd_max - even_max)

Submission status: Wrong Answer

Solution code:
from collections import Counter

n = int(input())
v = list(map(int, input().split()))
for_set_v = v # set用
set_v = set(v)
even = []
odd = []
count = 0 # 置き換えた回数
for num in range(n):
    if num % 2 == 0:
        even.append(v[num])
    else:
        odd.append(v[num])

even_most = int(Counter(even).most_common()[0][1])
odd_most = int(Counter(odd).most_common()[0][1])

if len(set(v)) >= 2:
    if len(set(even)) == 1:
        pass
    else:
        count += (n/2) - even_most

    if len(set(odd)) == 1:
        pass
    else:
        count += (n/2) - odd_most
        
elif len(set(v)) < 2:
    if len(set(even)) == 1 and len(set(odd)) == 1:
        count += (n/2)
        
print(int(count))

Submission status: Wrong Answer

Solution code:
from collections import Counter

n = int(input())
v = list(map(int, input().split()))
for_set_v = v # set用
set_v = set(v)
even = ''
odd = ''
count = 0 # 置き換えた回数
for num in range(n):
    if num % 2 == 0:
        even += str(v[num])
    else:
        odd += str(v[num])

even_most = int(Counter(even).most_common()[0][1])
odd_most = int(Counter(odd).most_common()[0][1])

if len(set(v)) >= 2:
    if len(set(even)) == 1:
        pass
    else:
        count += (n/2) - even_most

    if len(set(odd)) == 1:
        pass
    else:
        count += (n/2) - odd_most
elif len(set(v)) < 2:
    if len(set(even)) == 1 and len(set(odd)) == 1:
        count += (n/2)
print(int(count))

Submission status: Wrong Answer

Solution code:
from collections import Counter
input()
a = [[], []]
[a[i%2].append(t) for i, t in enumerate(map(int, input().split()))]
print(sum([len(ai)-max(Counter(ai).values()) for ai in a]))

Submission status: Wrong Answer

Solution code:
input()
a = [[], []]
[a[i%2].append(t) for i, t in enumerate(map(int, input().split()))]
print(sum([(lambda x: len(x) -max([x.count(xi) for xi in x]))(ai) for ai in a]))

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
k = n//2
a = list(map(int, input().split()))
p = []
q = []
for i in range(k):
    p.append(a[2*i])
    q.append(a[2*i+1])
s = Counter(p).most_common()
t = Counter(q).most_common()
u, v = len(s), len(t)
ans = 0
if s[0][0] == t[0][0]:
    if u == 1 and v == 1:
        ans = k
    elif u == 1:
        ans = k - t[1][1]
    elif v == 1:
        ans = k - s[1][1]
    else:
        comp = max(s[1][1], t[1][1])
        ans = n - s[0][0] - comp
else:
    ans = n - s[0][1] - t[0][1]
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
k = n//2
a = list(map(int, input().split()))
p = []
q = []
for i in range(k):
    p.append(a[2*i])
    q.append(a[2*i+1])
s = Counter(p).most_common()
t = Counter(q).most_common()
u, v = len(s), len(t)
ans = 0
if s[0][0] == t[0][0]:
    if u == 1 and v == 1:
        ans = k
    elif u == 1:
        ans = k - t[1][1]
    elif v == 1:
        ans = k - u[1][1]
    else:
        comp = max(s[1][1], t[1][1])
        ans = n - s[0][0] - comp
else:
    ans = n - s[0][1] - t[0][1]
print(ans)

Submission status: Wrong Answer

Solution code:
n=input()
l=input().split()
ans = 0
w0,w1=dict(),dict()
flag = 0 #ループ用カウンター
for i in l:
    flag += 1
    if flag % 2 == 0:
        if i not in w0.keys():
            w0[i] = 1
        else:
            w0[i] +=1
    else:
        if i not in w1.keys():
            w1[i] = 1
        else:
            w1[i] +=1
    
#print(w0)
#print(w1)
sumv = sum(w0.values()) + sum(w1.values())
max_w0 = max(w0.values())
max_w1 = max(w1.values())
ans = sumv -max_w0 -max_w1
#もし偶奇で最大のkeyが同じだった場合valueが少ないほうを2番目にvalueが多いkeyにそろえる
max_k0= max(w0, key=w0.get)
max_k1= max(w1, key=w1.get)
def sortdict(w):
    wc = dict()
    for k, v in sorted(w0.items(), key=lambda x:x[1], reverse = True):
        #print(str(k) + ": " + str(v))
        wc[k] = v
    return wc
w0["a"] = 0
w1["a"] = 0
w0 = sortdict(w0)
w1 = sortdict(w1)

if max_k0 == max_k1:
    #2番目のvalueを取得
    max2w0 = list(w0.values())[1]
    max2w1 = list(w1.values())[1]
    
    if max2w1 >= max2w0:
        ans = sum(w0.values()) - max2w0 + sum(w1.values()) - max_w1
    else:
        ans = sum(w1.values()) - max2w1 + sum(w0.values()) - max_w0

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
v = [int(i) for i in input().split()]
m = n//2

a = [v[2*i] for i in range(0,m)]
b = [v[2*i+1] for i in range(0,m)]

def mode(arr):
        r = [0] * (max(arr) + 1)
        for a in arr:
            r[a] += 1
        return r.index(max(r))

A = mode(a)
B = mode(b)

v.remove(A)

if v == []:
    print(m)
    exit()
if A == B:
    if a.count(A) < b.count(B):
        a.remove(A)
        C = mode(a)
        print(n - a.count(C) - b.count(B))
    else:
        if b.count(B) == m:
            print(n - m)
        else:
            b.remove(B)
            C = mode(b)
            print(n - a.count(A) - b.count(C))
else:
    print(n - a.count(A) - b.count(B))

Submission status: Wrong Answer

Solution code:
import collections

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

v1 = v[0::2]
v2 = v[1::2]

c1 = collections.Counter(v1)
c2 = collections.Counter(v2)
if(c1.most_common()[0][0] != c2.most_common()[0][0]):
	print(n - c1.most_common()[0][1] - c2.most_common()[0][1])
else:
	if(c1.most_common()[0][1] < c2.most_common()[0][1]):
		if(c1.most_common()[0][1] == n/2):
			print(n - c2.most_common()[0][1])
		else:
			print(n - c1.most_common()[1][1] - c2.most_common()[0][1])
	else:
		if(c2.most_common()[0][1] == n/2):
			print(n - c1.most_common()[0][1])
		else:
			print(n - c1.most_common()[0][1] - c2.most_common()[1][1])

Submission status: Wrong Answer

Solution code:
import collections

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

v1 = v[0::2]
v2 = v[1::2]

c1 = collections.Counter(v1)
c2 = collections.Counter(v2)
if(c1.most_common()[0][0] != c2.most_common()[0][0]):
	print(n - c1.most_common()[0][1] - c2.most_common()[0][1])
else:
	if(c1.most_common()[0][1] < c2.most_common()[0][1]):
		if(c2.most_common()[0][1] == n/2):
			print(n - c2.most_common()[0][1])
		else:
			print(n - c1.most_common()[1][1] - c2.most_common()[0][1])

	if(c2.most_common()[0][1] == n/2):
		print(n - c1.most_common()[0][1])
	else:
		print(n - c1.most_common()[0][1] - c2.most_common()[1][1])

Submission status: Wrong Answer

Solution code:
import collections

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

v1 = v[0::2]
v2 = v[1::2]

c1 = collections.Counter(v1)
c2 = collections.Counter(v2)
if(c1.most_common()[0][0] != c2.most_common()[0][0]):
	print(n - c1.most_common()[0][1] - c2.most_common()[0][1])
else:
	if(c2.most_common()[0][1] == n/2):
		print(n - c1.most_common()[0][1])
	else:
		print(n - c1.most_common()[0][1] - c2.most_common()[1][1])

Submission status: Wrong Answer

Solution code:
n = input()
l = input().split()
w0,w1 = dict(),dict()
flag = 0
for i in l:
  if flag % 2 == 0:
    if i not in w0.keys():w0[i] = 1
    else:w0[i] += 1
  else:
    if i not in w1.keys():w1[i] = 1
    else:w1[i] += 1
  flag += 1
print(sum(w0.values()) + sum(w1.values()) - max(w0.values())  - max(w1.values()))

Submission status: Wrong Answer

Solution code:
import numpy as np

n = int(input())
Odd = np.zeros(int(n/2))
Even = np.zeros(int(n/2))
list = input().split(" ")

for i in range(n):
    x = int(list[i])
    if i%2==1:
        Odd[int(i/2)] = x
    else:
        Even[int(i/2)] = x

O1n = int(np.max(Odd))
O1c = np.sum(Odd == O1n)
Odd = np.where(Odd == O1n,0,Odd)

E1n = int(np.max(Even))
E1c = np.sum(Even == E1n)
Even = np.where(Even == E1n,0,Even)


if O1c > E1c:
    if O1n != E1n:
        print(n-O1c-E1c)
    else:
        print(n-O1c-int(np.max(Even)))
elif O1c < E1c:
    if O1n != E1n:
        print(n-O1c-E1c)
    else:
        print(n-int(np.max(Odd))-E1c)
else:
    if O1n == E1n:
        if int(np.max(Even)) > int(np.max(Odd)):
            print(n-O1c-int(np.max(Even)))
        else:
            print(n-int(np.max(Odd))-E1c)
    else:
        print(n-O1c-E1c)

Submission status: Wrong Answer

Solution code:
import collections

def j(v):
    v.sort(reverse=True)
    f,s = 0,0
    if len(v) != 1:
        f,s = v[0],v[1]
    else:
        f,s = v[0],v[0]
    return f,s

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

e,o = [],[]
for i in range(len(v)):
    if i%2 == 0:
        e.append(v[i])
    else:
        o.append(v[i])

eD = list(collections.Counter(e).keys())
oD = list(collections.Counter(o).keys())

E1,E2 = j(eD)
O1,O2 = j(oD)

a1 = (len(e)-e.count(E1))+(len(o)-o.count(O2))
a2 = (len(e)-e.count(E2))+(len(o)-o.count(O1))
if a1<=a2:
    print(a1)
else:
    print(a2)

Submission status: Wrong Answer

Solution code:
import collections

def j(v):
    f,s = 0,0
    if len(v) != 1:
        f,s = v[0],v[1]
    else:
        f,s = v[0],v[0]
    return f,s

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

e,o = [],[]
for i in range(len(v)):
    if i%2 == 0:
        e.append(v[i])
    else:
        o.append(v[i])

eD = list(collections.Counter(e).keys())
oD = list(collections.Counter(o).keys())

E1,E2 = j(eD)
O1,O2 = j(oD)

a1 = (len(e)-e.count(E1))+(len(o)-o.count(O2))
a2 = (len(e)-e.count(E2))+(len(o)-o.count(O1))
if a1<=a2:
    print(a1)
else:
    print(a2)

Submission status: Wrong Answer

Solution code:
from collections import Counter

def f(n,v):
	a=Counter(v[0::2]).most_common()
	b=Counter(v[1::2]).most_common()
	
	if a[0][0]!=b[0][0]:
		return n-(a[0][1]+b[0][1])
	elif len(a) == 1 and len(b) == 1:
		return int(n/2)
	else:
		return max(n-(a[1][1]+b[0][1]),n-(a[0][1]+b[1][1]))

if __name__=="__main__":
	x=int(input())
	data=[int(i) for i in input().split()]
	print(f(x,data))

Submission status: Wrong Answer

Solution code:
from collections import Counter

def f(n,v):
	a=Counter(v[0::2]).most_common()
	b=Counter(v[1::2]).most_common()
	a.append([0,0])
	b.append([0,0])
	
	if a[0][0]==b[0][0]:
		return max(n-(a[1][1]+b[0][1]),n-(a[0][1]+b[1][1]))
	else:
		return n-(a[0][1]+b[0][1])

if __name__=="__main__":
	x=int(input())
	data=[int(i) for i in input().split()]
	print(f(x,data))

Submission status: Wrong Answer

Solution code:
def CC(v):
    f,s = 0,0
    for i in list(set(v)):
      c = v.count(i)
      if f < c:
        f = i
      if s < c:
        s = i
    return f,s

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

e,o = [],[]
for i in range(len(v)):
    if i%2 == 0:
        e.append(v[i])
    else:
        o.append(v[i])

E1,E2 = CC(e)
O1,O2 = CC(o)

a1 = (len(e)-e.count(E1))+(len(o)-o.count(O2))
a2 = (len(e)-e.count(E2))+(len(o)-o.count(O1))
if a1<=a2:
    print(a1)
else:
    print(a2)

Submission status: Wrong Answer

Solution code:
a = int(input())

b = list(map(int,input().split()))
d = max(b)
c = [0 for i in range(pow(10,5)+1)]
cc = [0 for i in range(pow(10,5)+1)]
for i in range(len(b)):
    if i % 2 == 0:
        c[b[i]-1] += 1
    else:
        cc[b[i]-1] += 1

one = 0
onee = 0
two = 0
twoo = 0
k = 0
kk = 0
for i in range(d+1):
    if one <= c[i]:
        onee = one
        one = c[i]
        k = i
    if two <= cc[i]:
        twoo = two
        two = cc[i]
        kk = i

t = max(one+twoo,onee+two)

if k != kk:
    print(a-one-two)
else:
    print(a-t)

Submission status: Wrong Answer

Solution code:
a = int(input())

b = list(map(int,input().split()))
d = max(b)
c = [0 for i in range(pow(10,5)+1)]
cc = [0 for i in range(pow(10,5)+1)]
for i in range(len(b)):
    if i % 2 == 0:
        c[b[i]-1] += 1
    else:
        cc[b[i]-1] += 1

one = 0
onee = 0
two = 0
twoo = 0
k = 0
kk = 0
for i in range(d+1):
    if one <= c[i]:
        onee = one
        one = c[i]
        k = i
    if two <= cc[i]:
        twoo = two
        two = cc[i]
        kk = i

t = max(one+twoo,onee+two)

if k != kk:
    print(a-one-two)
else:
    print(a-t-1)

Submission status: Wrong Answer

Solution code:
N = int(input())
NA = input()
NW = []
for i in range (1,N+1):
    Ni = NA.count(str(i))
    NW.append(Ni)
NN = NW.sort()
print(NW)
S = 0
for x in range (0,N-2):
    S = S + NW[x]
print(S)

Submission status: Wrong Answer

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

f,s = 0,0

if v.count(v[0]) != n:
  for i in list(set(v)):
    c = v.count(i)
    if f < c:
      f = c
    elif s < c:
      s = c
  print(len(v)-(f+s))
 
else:
  print(n/2)

Submission status: Wrong Answer

Solution code:
import collections
n=int(input())
v=list(map(int,input().split()))
s=[]
t=[]
for i in range(n):
    if i%2==0:
        s.append(v[i])
    else:
        t.append(v[i])
p=collections.Counter(s)
q=collections.Counter(t)
a=p.most_common()[0][0]
a1=p.most_common()[0][1]
b=q.most_common()[0][0]
b1=q.most_common()[0][1]
if a==b:
    if a==len(v)/2 or b==len(v)/2:
        print(len(v))
    else:
        if len(set(s))!=1:
            c=p.most_common()[1][1]
        else:
            c=0
        if len(set(t))!=1:
            d=p.most_common()[1][1]
        else:
            d=0
        print(min(len(v)-c-b1,len(v)-d-a1))
else:
    print(len(v)-a1-b1)

Submission status: Wrong Answer

Solution code:
import collections
n=int(input())
v=list(map(int,input().split()))
s=[]
t=[]
for i in range(n):
    if i%2==0:
        s.append(v[i])
    else:
        t.append(v[i])
p=collections.Counter(s)
q=collections.Counter(t)
a=p.most_common()[0][0]
a1=p.most_common()[0][1]
b=q.most_common()[0][0]
b1=q.most_common()[0][1]
if a==b:
    if a==len(v)/2 or b==len(v)/2:
        print(len(v))
    else:
        if len(set(s))!=1:
            c=p.most_common()[1][1]
        else:
            c=0
        if len(set(s))!=1:
            d=p.most_common()[1][1]
        else:
            d=0
        print(min(len(v)-c-b1,len(v)-d-a1))
else:
    print(len(v)-a1-b1)