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:
from collections import defaultdict
import collections
import math

n = int(input())
a = list(map(int,input().split()))
#辞書で作る
e = defaultdict(int)
o = defaultdict(int)
for i in range(n):#e[a_i]=個数にする
    if i%2 == 1:#odd
        o[a[i]]+=1
    else:
        e[a[i]]+=1

#個数を数えたりする
maxe = collections.Counter(e)
maxo = collections.Counter(o)
maxe = list(maxe.items())
maxo = list(maxo.items())
#それぞれ[['値','個数']]が降順で入ってる
a=maxo[0][1]
b=maxe[0][1]
no = n//2 #奇数の要素の個数
ne = n//2 + n%2 #偶数の要素の個数

if maxo[0][0] == maxe[0][0]:#奇数と偶数で頻出の値が同じ時
    # print("mojionaji")
    if no-a < ne-b:#書き換える個数が奇数の方が多いとき奇数を変える
        # print("aookii")
        if len(maxe) >1:
            b = maxe[1][1]
        else:
            b = 0
        # print(a,b)
    elif no-a>ne-b:#偶数が書き換え多いなら偶数を変える
        # print("bookii")
        if len(maxo) > 1:
            a = maxo[1][1]
        else:
            a = 0
        # print(a,b)
    else:#どちらも同じ個数なら2番目に大きい方を比較
        # print("saigo")
        if len(maxo) == 1 :
            a = 0
        elif len(maxe) == 1:
            b = 0
        else:
            if no - maxo[1][1] < ne - maxe[1][1]:
                a = maxo[1][1]
            else:
                b = maxe[1][1]
        # print(a,b)


ans = n-a-b
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
import collections
import math

n = int(input())
a = list(map(int,input().split()))
#辞書で作る
e = defaultdict(int)
o = defaultdict(int)
for i in range(n):#e[a_i]=個数にする
    if i%2 == 1:#odd
        o[a[i]]+=1
    else:
        e[a[i]]+=1

#個数を数えたりする
maxe = collections.Counter(e)
maxo = collections.Counter(o)
maxe = list(maxe.items())
maxo = list(maxo.items())
#それぞれ[['値','個数']]が降順で入ってる
a=maxo[0][1]
b=maxe[0][1]
no = n//2 #奇数の要素の個数
ne = n//2 + n%2 #偶数の要素の個数

if maxo[0][0] == maxe[0][0]:#奇数と偶数で頻出の値が同じ時
    # print("mojionaji")
    if no-a < ne-b:#書き換える個数が偶数の方が多いとき偶数を変える
        # print("aookii")
        if len(maxe) >1:
            b = maxe[1][1]
        else:
            b = 0
        # print(a,b)
    elif no-a>no-b:#奇数が書き換え多いなら奇数を変える
        # print("bookii")
        if len(maxo) > 1:
            a = maxo[1][1]
        else:
            a = 0
        # print(a,b)
    else:#どちらも同じ個数なら2番目に大きい方を比較
        # print("saigo")
        if len(maxo) == 1 :
            a = 0
        elif len(maxe) == 1:
            b = 0
        else:
            if no - maxo[1][1] < ne - maxe[1][1]:
                a = maxo[1][1]
            else:
                b = maxe[1][1]
        # print(a,b)


ans = n-a-b
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
import collections
import math

n = int(input())
a = list(map(int,input().split()))
#辞書で作る
e = defaultdict(int)
o = defaultdict(int)
for i in range(n):#e[a_i]=個数にする
    if i%2 == 1:#odd
        o[a[i]]+=1
    else:
        e[a[i]]+=1

#個数を数えたりする
maxe = collections.Counter(e)
maxo = collections.Counter(o)
maxe = list(maxe.items())
maxo = list(maxo.items())
#それぞれ[['値','個数']]が降順で入ってる
a=maxo[0][1]
b=maxe[0][1]
no = n//2 #奇数の要素の個数
ne = n//2 + n%2 #偶数の要素の個数

if maxo[0][0] == maxe[0][0]:#奇数と偶数で頻出の値が同じ時
    # print("mojionaji")
    if no-a < ne-b:#書き換える個数が偶数の方が多いとき偶数を変える
        # print("aookii")
        if len(maxe) >1:
            b = maxe[1][1]
        else:
            b = 0
        print(a,b)
    elif no-a>no-b:#奇数が書き換え多いなら奇数を変える
        # print("bookii")
        if len(maxo) > 1:
            a = maxo[1][1]
        else:
            a = 0
        print(a,b)
    else:#どちらも同じ個数なら2番目に大きい方を比較
        # print("saigo")
        if len(maxo) == 1 :
            a = 0
        elif len(maxe) == 1:
            b = 0
        else:
            if no - maxo[1][1] < ne - maxe[1][1]:
                a = maxo[1][1]
            else:
                b = maxe[1][1]
        # print(a,b)


ans = n-a-b
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
import collections
import math

n = int(input())
a = list(map(int,input().split()))
#辞書で作る
e = defaultdict(int)
o = defaultdict(int)
for i in range(n):#e[a_i]=個数にする
    if i%2 == 1:#odd
        o[a[i]]+=1
    else:
        e[a[i]]+=1

#個数を数えたりする
maxe = collections.Counter(e)
maxo = collections.Counter(o)
maxe = list(maxe.items())
maxo = list(maxo.items())
#それぞれ[['値','個数']]が降順で入ってる
a=maxo[0][1]
b=maxe[0][1]
no = n//2 #奇数の要素の個数
ne = n//2 + n%2 #偶数の要素の個数

if maxo[0][0] == maxe[0][0]:#奇数と偶数で頻出の値が同じ時
    print("mojionaji")
    if no-a < ne-b:#書き換える個数が奇数の方が多いとき偶数を変える
        print("aookii")
        if len(maxe) >1:
            b = maxe[1][1]
        else:
            b = 0
        print(a,b)
    elif no-a>no-b:#偶数が多いなら奇数を変える
        print("bookii")
        if len(maxo) > 1:
            a = maxo[1][1]
        else:
            a = 0
        print(a,b)
    else:#どちらも同じ個数なら2番目に大きい方を比較
        print("saigo")
        if len(maxo) == 1 :
            a = 0
        elif len(maxe) == 1:
            b = 0
        else:
            if no - maxo[1][1] < ne - maxe[1][1]:
                a = maxo[1][1]
            else:
                b = maxe[1][1]
        print(a,b)


ans = n-a-b
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
import collections
import math

n = int(input())
a = list(map(int,input().split()))
#辞書で作る
e = defaultdict(int)
o = defaultdict(int)
for i in range(n):#e[a_i]=個数にする
    if i%2 == 1:#odd
        o[a[i]]+=1
    else:
        e[a[i]]+=1

#個数を数えたりする
maxe = collections.Counter(e)
maxo = collections.Counter(o)
maxe = list(maxe.items())
maxo = list(maxo.items())
#それぞれ[['値','個数']]が降順で入ってる
a=maxo[0][1]
b=maxe[0][1]
no = n//2 #奇数の要素の個数
ne = n//2 + n%2 #偶数の要素の個数

if maxo[0][0] == maxe[0][0]:#奇数と偶数で頻出の値が同じ時
    if no-a > ne-b:#書き換える個数が奇数の方が多いとき偶数を変える
        if len(maxe) >1:
            b = maxe[1][1]
        else:
            b = 0
    elif no-a<no-b:#偶数が多いなら奇数を変える
        if len(maxo) > 1:
            a = maxo[1][1]
        else:
            a = 0
    else:#どちらも同じ個数なら2番目に大きい方を比較
        if len(maxo) == 1 :
            a = 0
        elif len(maxe) == 1:
            b = 0
        else:
            if no - maxo[1][1] > ne - maxe[1][1]:
                a = maxo[1][1]
            else:
                b = maxe[1][1]


ans = n-a-b
print(ans)

Submission status: Wrong Answer

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

odd = {}
even = {}
for i, x in enumerate(v):
    if i % 2 == 0:
        if odd.get(x):
            odd[x] += 1
        else:
            odd[x] = 1
    else:
        if even.get(x):
            even[x] += 1
        else:
            even[x] = 1

odd_max = 0
odd_index = 0
for i, x in odd.items():
    if odd_max < x:
        odd_max = x
        odd_index = i
even_max = 0
even_index = 0
for i, x in even.items():
    if even_max < x:
        even_max = x
        even_index = i
if odd_max == n // 2 and even_max == n // 2 and even_index != odd_index:
    print(0)
elif odd_max == n // 2 and even_max == n // 2:
    print(even_max)
elif odd_max == n // 2:
    print(n//2 - even_max)
else:
    print(n//2 - odd_max)

Submission status: Wrong Answer

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

odd = {}
even = {}
for i, x in enumerate(v):
    if i % 2 == 0:
        if odd.get(x):
            odd[x] += 1
        else:
            odd[x] = 1
    else:
        if even.get(x):
            even[x] += 1
        else:
            even[x] = 1

odd_max = 0
odd_index = 0
for i, x in odd.items():
    if odd_max > x:
        odd_max = x
        odd_index = i
even_max = 0
even_index = 0
for i, x in even.items():
    if even_max > x:
        even_max = x
        even_index = i
if odd_max == n // 2 and even_max == n // 2 and even_index != odd_index:
    print(0)
elif odd_max == n // 2 and even_max == n // 2:
    print(even_max)
elif odd_max == n // 2:
    print(n//2 - even_max)
else:
    print(n//2 - odd_max)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
import collections
import math

n = int(input())
a = list(map(int,input().split()))
e = defaultdict(int)
o = defaultdict(int)
for i in range(n):
    if i%2 == 1:#odd
        o[a[i]]+=1
    else:
        e[a[i]]+=1
maxe = collections.Counter(e)
maxo = collections.Counter(o)
maxo = list(maxo.items())
maxe = list(maxe.items())
a=maxo[0][1]
b=maxe[0][1]
no = n//2
ne = n//2 + n%2
if maxo[0][0] == maxe[0][0]:
    if no-a > ne - b:
        if len(maxe) >1:
            b = maxe[1][1]
        else:
            b = 0
    else:
        if len(maxo) > 1:
            a = maxo[1][1]
        else:
            a = 0

ans = (no-a)+(ne-b)
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
import collections
import math

n = int(input())
a = list(map(int,input().split()))
e = defaultdict(int)
o = defaultdict(int)
for i in range(n):
    if i%2:#odd
        o[a[i]]+=1
    else:
        e[a[i]]+=1
maxe = collections.Counter(e)
maxo = collections.Counter(o)
maxo = list(maxo.items())
maxe = list(maxe.items())
a=maxo[0][1]
b=maxe[0][1]
if maxo[0][0] == maxe[0][0]:
    if a>b:
        if len(maxe) >1:
            b = maxe[1][1]
        else:
            b = 0
    else:
        if len(maxo) > 1:
            a = maxo[1][1]
        else:
            a = 0
no = n//2
ne = n//2 + n%2
ans = (no-a)+(ne-b)
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
import collections
import math

n = int(input())
a = list(map(int,input().split()))
e = defaultdict(int)
o = defaultdict(int)
for i in range(n):
    if i%2:#odd
        o[a[i]]+=1
    else:
        e[a[i]]+=1
x = set(a)
maxe = collections.Counter(e)
maxo = collections.Counter(o)
maxo = list(maxo.items())
maxe = list(maxe.items())
a=maxo[0][1]
b=maxe[0][1]
if maxo[0][0] == maxe[0][0]:
    if a>b:
        if len(maxe) >1:
            b = maxe[1][1]
        else:
            b = 0
    else:
        if len(maxo) > 1:
            a = maxo[1][1]
        else:
            a = 0
no = math.ceil(n/2)
ne = n//2
ans = (no-a)+(ne-b)
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
N = int(input())
l = list(map(int,input().split()))
l_odd,l_even = [],[]

for i in range(N):
  if i%2 == 0:
    l_odd.append(l[i])
  else:
    l_even.append(l[i])

if set(l_odd) == set(l_even):
  print(N//2)
  exit()

C_odd = Counter(l_odd)
C_even = Counter(l_even)

C_odd_values = list(C_odd.values())
C_even_values = list(C_even.values())
C_odd_values.sort()
C_even_values.sort()

ans = (N//2 - C_odd_values[-1]) + (N//2 - C_even_values[-1])

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import *
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
#sys.setrecursionlimit(int(pow(10, 2)))
#sys.stdin = open("input.txt", "r")
# sys.stdout = open("output.txt", "w")
mod = int(pow(10, 9) + 7)
mod2 = 998244353
def data(): return sys.stdin.readline().strip()
def out(*var, end="\n"): sys.stdout.write(' '.join(map(str, var))+end)
def l(): return list(sp())
def sl(): return list(ssp())
def sp(): return map(int, data().split())
def ssp(): return map(str, data().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]





# @lru_cache(None)

n=l()[0]
A=l()
e=[]
o=[]
for i in range(n):
    if(i%2):
        o.append(A[i])
    else:
        e.append(A[i])
d={}
for i in range(n//2):
    if(o[i] not in d):
        d[o[i]]=0
    d[o[i]]+=1
mx=[]
for ks in d:
    mx.append([d[ks],ks])
mx.sort(reverse=True)
d={}
for i in range(n//2):
    if(e[i] not in d):
        d[e[i]]=0
    d[e[i]]+=1
mx1=[]
for ks in d:
    mx1.append([d[ks],ks])
mx1.sort(reverse=True)
if(mx[0][1]!=mx1[0][1]):
    print(n-mx[0][0]-mx1[0][0])
elif(mx[0][0]>mx1[0][0]):
    if(len(mx1)==1):
        print(n-mx[0][0])
    else:
        print(n-mx[0][0]-mx1[1][0])
else:
    mx,mx1=mx1,mx
    if(len(mx1)==1):
        print(n-mx[0][0])
    else:
        print(n-mx[0][0]-mx1[1][0])

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

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

cntA = defaultdict(int)
cntB = defaultdict(int)
for i in range(n):
    if i % 2  == 0:
        cntA[v[i]] += 1
    else:
        cntB[v[i]] += 1

max_num = 0
max_value = 0
for k, v in cntA.items():
    if max_value < v:
        max_value = v
        max_num = k

max_value2 = 0
for k, v in cntB.items():
    if max_num != k and max_value2 < v:
        max_value2 = v

print(n - max_value - max_value2)

Submission status: Wrong Answer

Solution code:
import collections
import sys

def calc_change(sequence):
    counter_dict = collections.Counter(sequence)
    max_val = max(counter_dict.values())
    return len(sequence) - max_val

length = int(sys.stdin.readline().strip())
sequence = [int(i) for i in sys.stdin.readline().split(" ")]
odd_sequence = [val for i, val in enumerate(sequence) if i%2 == 0]
even_sequence = [val for i, val in enumerate(sequence) if i%2 != 0]

print(calc_change(odd_sequence) + calc_change(even_sequence))

Submission status: Wrong Answer

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

v1 = [v[i] for i in range(n) if i%2 ==1]
v2 = [v[i] for i in range(n) if i%2 ==0]

c1 = Counter(v1).most_common()
c2 = Counter(v2).most_common()
c１=c1[::-1]
c2=c2[::-1]
cnt = 0
if len(c1) ==1 and len(c2) ==1:
  if c1 != c2:
    print(0)
  else:
    print(c2[0][1])
else:
  for i in range(len(c1)-1):
    cnt += c1[i][1]
  for i in range(len(c2)-1):
    cnt += c2[i][1]
  print(cnt)

Submission status: Wrong Answer

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

v1 = [v[i] for i in range(n) if i%2 ==1]
v2 = [v[i] for i in range(n) if i%2 ==0]

c1 = Counter(v1).most_common()
c2 = Counter(v2).most_common()

print(c1,c2)
cnt = 0
if len(c1) ==1 and len(c2) ==1:
  if c1 != c2:
    print(0)
  else:
    print(c2[0][1])
else:
  for i in range(len(c1)-1):
    cnt += c1[i][1]
  for i in range(len(c2)-1):
    cnt += c2[i][1]
  print(cnt)

Submission status: Wrong Answer

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

even_dict = {}
odd_dict = {}
for i in range(n):
    if i % 2 == 0:
        if V[i] not in even_dict:
            even_dict[V[i]] = 1
        else:
            even_dict[V[i]] += 1

    else:
        if V[i] not in odd_dict:
            odd_dict[V[i]] = 1
        else:
            odd_dict[V[i]] += 1
            
even_max = max(even_dict)
odd_max = max(odd_dict)
if len(even_dict) == len(odd_dict) == 1:
    if even_max == odd_max:
        print(n // 2)
    else:
        print(0)

else:
    even_count = sorted(even_dict.values(), reverse=True)
    odd_count = sorted(odd_dict.values(), reverse=True)
    if even_max == odd_max:
        change1 = even_count[0] + odd_count[1]
        change2 = even_count[1] + odd_count[0]
        print(n - max(change1, change2))

    else:
        print(n - (even_count[0]+odd_count[0]))

Submission status: Wrong Answer

Solution code:
import collections

arr_length = int(input().rstrip())
arr = list(map(int,input().rstrip().split()))

arr_odd = arr[0::2]
arr_even = arr[1::2]

def count_strange(arr):
    c = collections.Counter(arr)
    keys = list(c.keys())
    vals = list(c.values())
    return keys, vals

def proc(arr1, arr2):
    keys1, vals1 = count_strange(arr1)
    keys2, vals2 = count_strange(arr2)
    
    if keys1[0] == keys2[0]:
        print(vals1[0]) # n = even number
    else:
        print(sum(vals1[1:])+sum(vals2[1:]))
    
proc(arr_odd, arr_even)

Submission status: Wrong Answer

Solution code:
import collections

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

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

c1 = collections.Counter(v1)
c2 = collections.Counter(v2)

if v1 == v2:
    print(len(v1))
elif c1.most_common()[0][0] != c2.most_common()[0][0]:
    print(len(v1) - c1.most_common()[0][1] + len(v2) - c2.most_common()[0][1])
else:
    if c1.most_common()[1][1] < c2.most_common()[1][1]:
        print(len(v1) - c1.most_common()[0][1] + len(v2) - c2.most_common()[1][1])
    else:
        print(len(v1) - c1.most_common()[1][1] + len(v2) - c2.most_common()[0][1])

Submission status: Wrong Answer

Solution code:
import collections

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

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

c1 = collections.Counter(v1)
c2 = collections.Counter(v2)

if v1 == v2:
    print(len(v1))
elif c1.most_common()[0][0] != c2.most_common()[0][0]:
    print(len(v1) - c1.most_common()[0][1] + len(v2) - c2.most_common()[0][1])
else:
    if c1.most_common()[1][1] > c2.most_common()[1][1]:
        print(len(v1) - c1.most_common()[0][1] + len(v2) - c2.most_common()[1][1])
    else:
        print(len(v1) - c1.most_common()[1][1] + len(v2) - c2.most_common()[0][1])

Submission status: Wrong Answer

Solution code:
import collections

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

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

c1 = collections.Counter(v1)
c2 = collections.Counter(v2)

if v1 == v2:
    print(len(v1))
elif c1.most_common()[0][0] != c2.most_common()[0][0]:
    print(len(v1) - c1.most_common()[0][1] + len(v2) - c2.most_common()[0][1])
else:
    print(len(v1) - c1.most_common()[0][1] + len(v2) - c2.most_common()[1][1])

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

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

result=0

dic_a=defaultdict(int)
dic_b=defaultdict(int)

for i in range(n//2):
    dic_a[v[i*2]]+=1
    dic_b[v[i*2+1]]+=1


#それぞれの最大値を取得
max_a=max(dic_a.items(),key=lambda x:[1])
max_b=max(dic_b.items(),key=lambda x:[1])

if max_a[0] != max_b[0]:
    result=n-max_a[1]-max_b[1]

elif len(dic_a)==1 and len(dic_b)==1:
    result=n//2

else:
    dic_a.pop(max_a[0])
    max_a2=max(dic_a.items(),key=lambda x:[1])

    dic_b.pop(max_b[0])
    max_b2=max(dic_b.items(),key=lambda x:[1])

    result=min(n-max_a2[1]-max_b[1],n-max_a[1]-max_b2[1])

print(int(result))

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

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

result=0

dic_a=defaultdict(int)
dic_b=defaultdict(int)

for i in range(n//2):
    dic_a[v[i*2]]+=1
    dic_b[v[i*2+1]]+=1


#それぞれの最大値を取得
max_a=max(dic_a.items(),key=lambda x:[1])
max_b=max(dic_b.items(),key=lambda x:[1])

if max_a[0] != max_b[0]:
    result=n-max_a[1]-max_b[1]

elif len(dic_a)==1 and len(dic_b)==1:
    result=n//2

elif len(dic_a)==1:
    dic_b.pop(max_b[0])
    max_b=max(dic_b.items(),key=lambda x:[1])
    result=n-max_a[1]-max_b[1]

elif len(dic_b)==1:
    dic_a.pop(max_a[0])
    max_a=max(dic_a.items(),key=lambda x:[1])
    result=n-max_a[1]-max_b[1]

else:
    dic_a.pop(max_a[0])
    max_a2=max(dic_a.items(),key=lambda x:[1])

    dic_b.pop(max_b[0])
    max_b2=max(dic_b.items(),key=lambda x:[1])

    result=min(n-max_a2[1]-max_b[1],n-max_a[1]-max_b2[1])

print(int(result))

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

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

result=0

dic_a=defaultdict(int)
dic_b=defaultdict(int)

for i in range(n//2):
    dic_a[v[i*2]]+=1
    dic_b[v[i*2+1]]+=1


#それぞれの最大値を取得
max_a=max(dic_a.items(),key=lambda x:[1])
max_b=max(dic_b.items(),key=lambda x:[1])

if max_a[0] != max_b[0]:
    result=n-max_a[1]-max_b[1]

elif len(dic_a)==1 and len(dic_b)==1:
    result=n//2

elif len(dic_a)==1:
    dic_b.pop(max_b[0])
    max_b=max(dic_b.items(),key=lambda x:[1])
    result=n-max_a[1]-max_b[1]

elif len(dic_b)==1:
    dic_a.pop(max_a[0])
    max_a=max(dic_a.items(),key=lambda x:[1])
    result=n-max_a[1]-max_b[1]

else:
    dic_a.pop(max_a[0])
    max_a2=max(dic_a.items(),key=lambda x:[1])

    dic_b.pop(max_b[0])
    max_b2=max(dic_b.items(),key=lambda x:[1])

    if max_a2[1]>max_b2[1]:
        result=n-max_a2[1]-max_b[1]
    else:
        result=n-max_a[1]-max_b2[1]

print(int(result))

Submission status: Wrong Answer

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

E = set( V[ i ] for i in range( 0, len( V ), 2 ) )
O = set( V[ i ] for i in range( 1, len( V ), 2 ) )
n = len( set( V ))

if n == 1:
  c = len( range( 0, len( V ), 2 ))
  print( c )
else:
  print( len( E ) + len( O ) - 2 )

Submission status: Wrong Answer

Solution code:
n = int(input())

v = [int(x) for x in input().split()]

ac = {}

bc = {}

for i in range(0, n, 2):
    if v[i] not in ac:
        ac[v[i]] = 1
    else:
        ac[v[i]] += 1
        
    if v[i + 1] not in bc:
        bc[v[i + 1]] = 1
    else:
        bc[v[i + 1]] += 1 

amxcount = 0
amx = []
for a in ac:
    if ac[a] > amxcount:
        amxcount = ac[a]
        amx = [a]
    elif ac[a] == amxcount:
        amx.append(a)

bmxcount = 0
bmx = []
for b in bc:
    if bc[b] > bmxcount:
        bmxcount = bc[b]
        bmx = [b]
    elif bc[b] == bmxcount:
        bmx.append(b)

if (amx == bmx):
    if amxcount == n // 2:
        print(n // 2)
    else:
        print(n // 2 - amxcount + n // 2 - bmxcount)
else:
    if amxcount == bmxcount and amxcount == n // 2:
        print(0)
    else:
        print(n // 2 - amxcount + n // 2 - bmxcount)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
v = list(map(int, input().split()))
o = [v[i] for i in range(n) if i % 2 == 0]
o2 = Counter(o)
e = [v[i] for i in range(n) if i % 2 == 1]
e2 = Counter(e)
if o2.most_common()[0][0] == e2.most_common()[0][0]:
    try:
        print(min((len(o) - o2.most_common()[0][2]) + (len(e) - e2.most_common()[0][1]), (len(o) - o2.most_common()[0][1]) + (len(e) - e2.most_common()[0][2])))
    except:
        print(min((len(o) - o2.most_common()[0][1]) + len(e), len(o) + (len(e) - e2.most_common()[0][1])))
else:
    print((len(o) - o2.most_common()[0][1]) + (len(e) - e2.most_common()[0][1]))

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
v = list(map(int, input().split()))
o = [v[i] for i in range(n) if i % 2 == 0]
o2 = Counter(o)
e = [v[i] for i in range(n) if i % 2 == 1]
e2 = Counter(e)
if o2.most_common()[0][1] == e2.most_common()[0][1]:
    try:
        print(min((len(o) - o2.most_common()[0][2]) + (len(e) - e2.most_common()[0][1]), (len(o) - o2.most_common()[0][1]) + (len(e) - e2.most_common()[0][2])))
    except:
        print(min((len(o) - o2.most_common()[0][1]) + len(e), len(o) + (len(e) - e2.most_common()[0][1])))
else:
    print((len(o) - o2.most_common()[0][1]) + (len(e) - e2.most_common()[0][1]))

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
v = list(map(int,input().split()))
#奇数番目
odd = collections.Counter(v[::2]).most_common()
#偶数番目
even = collections.Counter(v[1::2]).most_common()

if odd[0][0] != even[0][0]:
	print(n-odd[0][1]-even[0][1])
else:
	if len(odd) == 1:
		if len(even) == 1:
			print(n//2)
		else:
			print(even[1][1])
	else:
		if len(even) == 1:
			print(odd[1][1])
		else:
			print(min(odd[1][1], even[1][1]))

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
v = list(map(int,input().split()))
#奇数番目
odd = collections.Counter(v[::2]).most_common()
#偶数番目
even = collections.Counter(v[1::2]).most_common()
oddichiban = odd[0][1]
evenichiban = even[0][1]
if odd[0][0] != even[0][0]:
	print(n-oddichiban-evenichiban)
else:
	if len(odd) == 1:
		if len(even) == 1:
			print(n//2)
		else:
			print(n//2 - even[1][1])
	else:
		if len(even) == 1:
			print(n//2 - odd[1][1])
		else:
			print(n//2 - max(odd[1][1], even[1][1]))

Submission status: Wrong Answer

Solution code:
n=int(input())
v=list(map(int,input().split()))
from collections import defaultdict
a=defaultdict(int)
b=defaultdict(int)
for i in range(n):
    if i%2==0:
        a[v[i]]+=1
    else:
        b[v[i]]+=1
a=dict(sorted(a.items(), key=lambda x:x[1], reverse=True))
b=dict(sorted(b.items(), key=lambda x:x[1], reverse=True))
#print(a,b)
ans=float('inf')
akeys=list(a.keys())
bkeys=list(b.keys())
if akeys[0]==bkeys[0]:
    if len(akeys)==1 and len(bkeys)==1:
        ans=n//2
    else:
        if len(akeys)>1:
            x=sum(a.values())-a[akeys[1]]+sum(b.values())-b[bkeys[0]]
            ans=min(x,ans)
        if len(bkeys)>1:
            x=sum(a.values())-a[akeys[0]]+sum(b.values())-b[bkeys[1]]
            ans=min(x,ans)
else:
    ans=sum(a.values())-a[akeys[0]]+sum(b.values())-b[bkeys[0]]
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
v=list(map(int,input().split()))
from collections import defaultdict
a=defaultdict(int)
b=defaultdict(int)
for i in range(n):
    if i%2==0:
        a[v[i]]+=1
    else:
        b[v[i]]+=1
a=dict(sorted(a.items(), key=lambda x:x[1], reverse=True))
b=dict(sorted(b.items(), key=lambda x:x[1], reverse=True))
print(a,b)
ans=float('inf')
akeys=list(a.keys())
bkeys=list(b.keys())
if akeys[0]==bkeys[0]:
    if len(akeys)==1 and len(bkeys)==1:
        ans=n//2
    else:
        if len(akeys)>1:
            x=sum(a.values())-a[akeys[1]]+sum(b.values())-b[bkeys[0]]
            ans=min(x,ans)
        if len(bkeys)>1:
            x=sum(a.values())-a[akeys[0]]+sum(b.values())-b[bkeys[1]]
            ans=min(x,ans)
else:
    ans=sum(a.values())-a[akeys[0]]+sum(b.values())-b[bkeys[0]]
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
v=list(map(int,input().split()))
from collections import defaultdict
a=defaultdict(int)
b=defaultdict(int)
for i in range(n):
    if i%2==0:
        a[v[i]]+=1
    else:
        b[v[i]]+=1
a=dict(sorted(a.items(), key=lambda x:x[1], reverse=True))
b=dict(sorted(b.items(), key=lambda x:x[1], reverse=True))

ans=float('inf')
akeys=list(a.keys())
bkeys=list(b.keys())
if akeys[0]==bkeys[0]:
    if len(akeys)==1 and len(bkeys):
        ans=n//2
    else:
        if len(akeys)>1:
            x=sum(a.values())-a[akeys[1]]+sum(b.values())-b[bkeys[0]]
            ans=min(x,ans)
        if len(bkeys)>1:
            x=sum(a.values())-a[akeys[0]]+sum(b.values())-b[bkeys[1]]
            ans=min(x,ans)
else:
    ans=sum(a.values())-a[akeys[0]]+sum(b.values())-b[bkeys[0]]
print(ans)

Submission status: Wrong Answer

Solution code:
def str_to_int(lista):
    for num, i in enumerate(lista):
        lista[num]=int(i)
    
    
def main():
    N= int(input())
    lst_v = input().split()
    str_to_int(lst_v)
    lst_sum_o = []
    lst_srt_o = []
    lst_sum_e = []
    lst_srt_e = []
    for num, i in enumerate(lst_v):
        if num%2 == 0:
            if i in lst_srt_e:
                lst_sum_e[lst_srt_e.index(i)] = lst_sum_e[lst_srt_e.index(i)] + 1
            else:
                lst_srt_e.append(i)
                lst_sum_e.append(1)
        elif num%2 == 1:    
            if i in lst_srt_o:
                lst_sum_o[lst_srt_o.index(i)] = lst_sum_o[lst_srt_o.index(i)] + 1
            else:
                lst_srt_o.append(i)
                lst_sum_o.append(1)

    if lst_srt_o[lst_sum_o.index(max(lst_sum_o))] == lst_srt_e[lst_sum_e.index(max(lst_sum_e))]:
        if len(lst_sum_o) == 1 and len(lst_sum_e) == 1 :
            print(max(lst_sum_o))
        
        else:
            if len(lst_sum_o) == 1:
                lst_sum_o.append(max(lst_sum_o))
                
            if len(lst_sum_e) == 1:
                lst_sum_e.append(max(lst_sum_e))
        
            lst_sum_o.sort()
            lst_sum_e.sort()
            if lst_sum_o[-2]>=lst_sum_e[-2]:
                print(int(N/2)- max(lst_sum_o) + int(N/2)- lst_sum_e[-2])
                #print("OK1")
            else:
                print(int(N/2)- max(lst_sum_e) + int(N/2)- lst_sum_o[-2])
                #print("OK2")
        #print(lst_sum_e)
    #print(lst_srt_o, lst_sum_o,lst_srt_e, lst_sum_e)
    else:
        print(N - max(lst_sum_o) + - max(lst_sum_e) )
    
        
    
main()

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
a = []
b = []
v = list(map(int,input().split()))
for i in range(n):
    if i%2 == 0:
        a.append(v[i])
    else:
        b.append(v[i])
X = collections.Counter(a)
Y = collections.Counter(b)
A = int(X.most_common()[0][1])
B = int(Y.most_common()[0][1])
print(min(A,B))

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
a = []
b = []
v = list(map(int,input().split()))
for i in range(n):
    if i%2 == 0:
        a.append(v[i])
    else:
        b.append(v[i])
X = collections.Counter(a)
Y = collections.Counter(b)
A = int(X.most_common()[0][1])
B = int(Y.most_common()[0][1])
print(max(len(a)-A,len(b)-B))

Submission status: Wrong Answer

Solution code:
n = int(input())
list_all = list(map(int, input().split()))
ans = 0
list_even=[]
list_odd=[]
max_even=0
max_odd=0
for i in range(0,n,2):
    list_odd.append(list_all[i])
for i in range(1,n,2):
    list_even.append(list_all[i])
dic_odd={}
dic_even={}
li_odd=[0]
li_even=[0]
for i in list_odd:
    if i not in dic_odd:
        dic_odd[i]=1
    else:
        dic_odd[i]+=1
for i in list_even:
    if i not in dic_even:
        dic_even[i]=1
    else:
        dic_even[i]+=1
for i in dic_odd.keys():
    if dic_odd[i]>max_odd:
        max_odd=i
    li_odd.append(dic_odd[i])
for i in dic_even.keys():
    if i>max_even:
        max_even=i
    li_even.append(dic_even[i])
li_even.sort(reverse=True)
li_odd.sort(reverse=True)
if max_odd==max_even:
    print(n-li_even[0]-max(li_even[1], li_odd[1]))
else:
    print(n-li_even[0]-li_odd[0])

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3

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

V1 = []
V2 = []

for i in range(N):
    if i%2==0: V1.append(V[i])
    else: V2.append(V[i])

ans = 0
if len(set(V1)) == 1 and len(set(V2)) == 1 and V1[0]==V2[0]:
    ans = len(V1)
else:
    ans = len(set(V1)) + len(set(V2)) - 2

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
N = int(input())
v = list(map(int, input().split()))
cnt = Counter(v).most_common()
print(N - cnt[0][1] - cnt[1][1] if len(cnt) >= 2 else N // 2)