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 Counter
n = int(input())
v = list(map(int, input().split()))
kisu = []
gusu = []
flag = True
for el in v:
    if flag:
        kisu.append(el)
    else:
        gusu.append(el)
    flag = not flag
a = Counter(kisu)
b = Counter(gusu)
a_max = list(a.values())[0]
b_max = list(b.values())[0]
if list(a.keys())[0] == list(b.keys())[0]:
    if a_max <= b_max:
        if len(a) < 2:
            a_max = 0
        else:
            a_max = list(a.values())[1]
    else:
        if len(b) < 2:
            b_max = 0
        else:
            b_max = list(b.values())[1]
print(len(v)-a_max-b_max)

Submission status: Wrong Answer

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

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
v = LI()
a = []
b = []
for i in range(n):
    if i % 2 == 0:
        a.append(v[i])
    else:
        b.append(v[i])
a = list(Counter(a).items())
b = list(Counter(b).items())
a.sort(key = lambda x:x[1], reverse=1)
b.sort(key = lambda x:x[1], reverse=1)
if len(a) == 1 and len(b) == 1:
    if a[0][0] == b[0][0]:
        print(n//2)
    else:
        print(0)
elif len(a) > 1 and len(b) == 1:
    if a[0][0] == b[0][0]:
        print((n-1)//2 + 1 - a[1][1])
    else:
        print((n-1)//2 + 1 - a[0][1])
elif len(a) == 1 and len(b) > 1:
    if a[0][0] == b[0][0]:
        print(n//2 - b[1][1])
    else:
        print(n//2 - b[0][1])
else:
    if a[0][0] == b[0][0]:
        print(min((n-1)//2 + 1 - a[1][1] + (n // 2) - b[0][0], (n-1)//2 + 1 - a[0][1] + (n // 2) - b[1][1]))
    else:
        print(min((n-1)//2 + 1 - a[0][1] + (n // 2) - b[0][0], (n-1)//2 + 1 - a[0][1] + (n // 2) - b[0][1]))

Submission status: Wrong Answer

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

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
v = LI()
a = []
b = []
for i in range(n):
    if i % 2 == 0:
        a.append(v[i])
    else:
        b.append(v[i])
a = list(Counter(a).items())
b = list(Counter(b).items())
a.sort(key = lambda x:x[1], reverse=1)
b.sort(key = lambda x:x[1], reverse=1)
if len(a) == 1 and len(b) == 1:
    if a[0][0] == b[0][0]:
        print(n//2)
    else:
        print(0)
elif len(a) > 1 and len(b) == 1:
    if a[0][0] == b[0][0]:
        print((n-1)//2 + 1 - a[1][1])
    else:
        print((n-1)//2 + 1 - a[0][1])
elif len(a) == 1 and len(b) > 1:
    if a[0][0] == b[0][0]:
        print(n//2 - b[1][1])
    else:
        print(n//2 - b[0][1])
else:
    if a[0][0] == b[0][0]:
        print(min((n-1)//2 + 1 - a[1][1] + n // 2 - b[0][0], (n-1)//2 + 1 - a[0][0] + n // 2 - b[1][1]))
    else:
        print(min((n-1)//2 + 1 - a[0][1] + n // 2 - b[0][0], (n-1)//2 + 1 - a[0][0] + n // 2 - b[0][1]))

Submission status: Wrong Answer

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

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
v = LI()
a = []
b = []
for i in range(n):
    if i % 2 == 0:
        a.append(v[i])
    else:
        b.append(v[i])
a = list(Counter(a).items())
b = list(Counter(b).items())
a.sort(key = lambda x:x[1], reverse=1)
b.sort(key = lambda x:x[1], reverse=1)
if len(a) == 1 and len(b) == 1:
    if a[0][0] == b[0][0]:
        print(n//2)
    else:
        print(0)
elif len(a) > 1 and len(b) == 1:
    if a[0][0] == b[0][0]:
        print((n-1)//2 + 1 - a[1][1])
    else:
        print((n-1)//2 + 1 - a[0][1])
elif len(a) == 1 and len(b) > 1:
    if a[0][0] == b[0][0]:
        print(n//2 - b[1][1])
    else:
        print(n//2 - b[0][1])
else:
    if a[0][0] == b[0][0]:
        print(min((n-1)//2 + 1 - a[1][1], n // 2 - b[1][1]))
    else:
        print(min((n-1)//2 + 1 - a[0][1], n // 2 - b[0][1]))

Submission status: Wrong Answer

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

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
v = LI()
a = []
b = []
for i in range(n):
    if i % 2 == 0:
        a.append(v[i])
    else:
        b.append(v[i])
a = list(Counter(a).items())
b = list(Counter(b).items())
a.sort(key = lambda x:x[1], reverse=1)
b.sort(key = lambda x:x[1], reverse=1)
if len(a) == 1 and len(b) == 1:
    if a[0][0] == b[0][0]:
        print(n//2)
    else:
        print(0)
elif len(a) > 1 and len(b) == 1:
    if a[0][0] == b[0][0]:
        print((n-1)//2 + 1 - a[1][1])
    else:
        print((n-1)//2 + 1 - a[0][1])
elif len(a) == 1 and len(b) > 1:
    if a[0][0] == b[0][0]:
        print((n-1)//2 + 1 - b[1][1])
    else:
        print((n-1)//2 + 1 - b[0][1])
else:
    if a[0][0] == b[0][0]:
        print(min((n-1)//2 + 1 - a[1][1], n // 2 + 1 - b[1][1]))
    else:
        print(min((n-1)//2 + 1 - a[0][1], n // 2 + 1 - b[0][1]))

Submission status: Wrong Answer

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

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
v = LI()
a = []
b = []
for i in range(n):
    if i % 2 == 0:
        a.append(v[i])
    else:
        b.append(v[i])
a = list(Counter(a).items())
b = list(Counter(b).items())
a.sort(key = lambda x:x[1], reverse=1)
b.sort(key = lambda x:x[1], reverse=1)
if len(a) == 1 and len(b) == 1:
    if a[0][0] == b[0][0]:
        print(n//2)
    else:
        print(0)
elif len(a) > 1 and len(b) == 1:
    if a[0][0] == b[0][0]:
        print((n-1)//2 + 1 - a[0][1])
    else:
        print((n-1)//2 + 1 - a[0][0])
elif len(a) == 1 and len(b) > 1:
    if a[0][0] == b[0][0]:
        print((n-1)//2 + 1 - b[0][1])
    else:
        print((n-1)//2 + 1 - b[0][0])
else:
    if a[0][0] == b[0][0]:
        print(min((n-1)//2 + 1 - a[0][1], n // 2 + 1 - b[0][1]))
    else:
        print(min((n-1)//2 + 1 - a[0][0], n // 2 + 1 - b[0][0]))

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

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

v1 = v[::2]
even = sorted(Counter(v1).items(), key=lambda x: x[1])[0:2]

v2 = v[1::2]
odd = sorted(Counter(v2).items(), key=lambda x: x[1])[0:2]

if even[0][0] == odd[0][0]:
    mode = max(even[0][1] + odd[1][1], even[1][1] + odd[0][1])


else:
    mode = even[0][1]
    mode += odd[0][1]
ans = n - mode
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

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

v1 = v[::2]
even = sorted(Counter(v1).items(), key=lambda x: x[1])[0][1]

v2 = v[1::2]
odd = sorted(Counter(v2).items(), key=lambda x: x[1])[0][1]

ans = n - even - odd
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
from collections import Counter

input = sys.stdin.readline

n = int(input())
v = list(map(int, input().split()))
arr1 = list(Counter([v[i] for i in range(n) if i % 2 == 0]).items())
arr2 = list(Counter([v[i] for i in range(n) if i % 2 == 1]).items())

arr1.append((0, 0))
arr2.append((0, 0))

arr1.sort(key=lambda x:x[1])
arr2.sort(key=lambda x:x[1])

if arr1[-1][0] == arr2[-1][0]:
    if arr1[-1][1] >= arr2[-1][1]:
        ans = n - arr1[-1][1] - arr2[-2][1]
    else:
        ans = n - arr1[-2][1] - arr2[-1][1]
else:
    ans = n - arr1[-1][1] - arr2[-1][1]

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
from collections import Counter

input = sys.stdin.readline

n = int(input())
v = list(map(int, input().split()))
arr1 = list(Counter([v[i] for i in range(n) if i % 2 == 0]).items())
arr2 = list(Counter([v[i] for i in range(n) if i % 2 == 1]).items())

arr1.append((0, 0))
arr2.append((0, 0))

arr1.sort(key=lambda x:x[1])
arr2.sort(key=lambda x:x[1])

if arr1[-1][0] == arr2[-1][0]:
    if arr1[-1][1] >= arr2[-1][1]:
        ans = n - arr1[-1][1] - arr2[-2][1]
else:
    ans = n - arr1[-1][1] - arr2[-1][1]

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
v = list(map(int, input().split()))
a = [[0, i] for i in range(10 ** 5 + 1)]
b = [[0, i] for i in range(10 ** 5 + 1)]
for i in range(n):
    if i % 2 == 0:
        a[v[i]][0] += 1
    else:
        b[v[i]][0] += 1
a.sort(reverse = True)
b.sort(reverse = True)
if a[0][1] == b[0][1]:
    ans = n - min(a[0][0] + b[1][0], a[1][0] + b[0][0])
else:
    ans = n - (a[0][0] + b[0][0])
print(ans)

Submission status: Wrong Answer

Solution code:
# C - /\/\/\/
from collections import defaultdict

if __name__ == "__main__":
    n = int(input())
    v = list(map(int, input().split()))

    even = defaultdict(int)
    odd = defaultdict(int)
    even_num = 0
    odd_num = 0
    for i in range(n):
        if i % 2 == 0:
            even[v[i]] += 1
            even_num += 1
        else:
            odd[v[i]] += 1
            odd_num += 1

    # 偶数位置と奇数位置の最汎値を比較
    even_arr = list(sorted(even.items(), key=lambda x: x[1]))
    odd_arr = list(sorted(odd.items(), key=lambda x: x[1]))
    ans = 0
    if even_arr[0][0] == odd_arr[0][0]:
        if len(even_arr) == 1 and len(odd_arr) == 1:
            ans = min([even_arr[0][1], odd_arr[0][1]])
        elif len(even_arr) == 1:
            ans = min([len(even_arr), odd_num - odd_arr[1][1]])
        elif len(odd_arr) == 1:
            ans = min([len(odd_arr)], even_num-even_arr[1][1])
        else:
            ans = n - max([even_arr[0][1]+odd_arr[1][1],
                           even_arr[1][1]+odd_arr[0][1]])

    else:
        ans += even_num - even_arr[0][1]
        ans += odd_num - odd_arr[0][1]

    print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
li = list(map(int,input().split()))
a = [l for i,l in enumerate(li) if i % 2 == 0]
b = [l for i,l in enumerate(li) if i % 2 == 1]
se_a = list(set(a))
se_b = list(set(b))
if Counter(a).most_common()[0][0] != Counter(b).most_common()[0][0]:
    a_change = len(a) - Counter(a).most_common()[0][1]
    b_change = len(b) - Counter(b).most_common()[0][1]
    print(a_change+b_change)
else:
    if len(se_a) == 1 and len(se_b) == 1:
        print(len(a))
    else:
        x = len(a) - Counter(a).most_common()[0][1] + len(a) - Counter(a).most_common()[1][1]
        y = len(a) - Counter(a).most_common()[1][1] + len(a) - Counter(a).most_common()[0][1]
        print(min(x,y))

Submission status: Wrong Answer

Solution code:
N = int(input())
Vnodd = {}
Vneven = {}
Vnlist = input().split()
for n, v in enumerate(Vnlist):
  if (n+1)%2 == 1:
    if Vnodd.get(v) is None:
      Vnodd[v] = 1
    else:
      Vnodd[v] += 1
  else:
    if Vneven.get(v) is None:
      Vneven[v] = 1
    else:
      Vneven[v] += 1 
maxoddindx  = max(Vnodd.items(), key=lambda x: x[1])[0]
maxevenindx = max(Vneven.items(), key=lambda x: x[1])[0]

count = 0
for v in Vnodd:
  if v != maxoddindx: count += Vnodd[v]

for v in Vneven:
  if v != maxevenindx: count += Vneven[v]

if count == 0 and Vnlist[0]==Vnlist[1]: count += N//2
print(count)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

v1=v[::2]
n1=len(set(v1))
v2=v[1::2]
n2=len(set(v2))

cnt1=Counter(v1)
cnt2=Counter(v2)

cnt1=cnt1.most_common()
cnt2=cnt2.most_common()

if cnt1[0][0]!=cnt2[0][0]:
  print(N-cnt1[0][1]-cnt2[0][1])
else:
  if cnt1[0][1]>=cnt2[0][1]:
    if n2==1:
      print(N-cnt1[0][1])
    else:
      print(N-cnt1[0][1]-cnt2[1][1])
  else:
    if n1==1:
      print(N-cnt2[0][1])
    else:
      print(N-cnt1[1][1]-cnt2[0][1])

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

veven = v[::2]
vodd = v[1::2]

neven = Counter(veven).most_common()
nodd = Counter(vodd).most_common()

print(n - neven[0][1] - nodd[0][1] if neven[0][0] != nodd[0][0] else min(nodd[0][1], neven[0][1]))

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

counter_a = Counter(v[0::2])
counter_b = Counter(v[1::2])

keys_a = list(counter_a.keys())
keys_b = list(counter_b.keys())
values_a = list(counter_a.values())
values_b = list(counter_b.values())

if keys_a[0] != keys_b[0]:
  cnt_a = n//2 - values_a[0]
  cnt_b = n//2 - values_b[0]
  ans = cnt_a + cnt_b
else:
  if values_a[0] > values_b[0]:
    cnt_a = n//2 - values_a[0]
    cnt_b = n//2 - values_b[1]
    ans = cnt_a + cnt_b
  elif values_a[0] < values_b[0]:
    cnt_a = n//2 - values_a[1]
    cnt_b = n//2 - values_b[0]
    ans = cnt_a + cnt_b
  else:
    if n//2 == values_a[0]:
      ans = values_a[0]
    else:
      cnt_1 = n//2 - values_a[0]
      cnt_2 = n//2 - max(values_a[1], values_b[1])
      ans = cnt_1 + cnt_2

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

n = int(input())
v = list(map(int, input().split()))
ev, od = [], []
for i in range(n):
    if i % 2 == 0:
        ev.append(v[i])
    else:
        od.append(v[i])

cnt_ev = sorted(Counter(ev).items(), key=lambda x: x[1], reverse=True)
cnt_od = sorted(Counter(od).items(), key=lambda x: x[1], reverse=True)
if len(cnt_ev) == 1 and len(cnt_od) == 1:

    if cnt_ev[0][0] == cnt_od[0][0]:
        res = n // 2
        print(res)
    else:
        res = 0
        print(res)
elif len(cnt_ev) == 1:
    if cnt_ev[0][0] == cnt_od[0][0]:
        res = n // 2 - cnt_od[1][1]
        print(res)
    else:
        res = n // 2 - cnt_od[0][1]
        print(res)
elif len(cnt_od) == 1:
    if cnt_ev[0][0] == cnt_od[0][0]:
        res = n // 2 - cnt_ev[1][1]
        print(res)
    else:
        res = n // 2 - cnt_ev[0][1]
        print(res)
else:
    res1 = n - cnt_ev[0][1] - cnt_od[1][1]
    res2 = n - cnt_ev[1][1] - cnt_od[0][1]
    res = min(res1, res2)
    print(res)

Submission status: Wrong Answer

Solution code:
n = int(input())
v = list(map(int, input().split()))
v_odd = []
v_even = []
for i in range(n):
    if i % 2 == 0:
        v_odd.append(v[i])
    else:
        v_even.append(v[i])

        
import collections
cl_odd = collections.Counter(v_odd)
cl_even = collections.Counter(v_even)


if cl_odd.most_common()[0][0] != cl_even.most_common()[0][0]:
    # even, odd列で最頻値が異なる場合
    print(len(v_odd) - cl_odd.most_common()[0][1] +
          len(v_even) - cl_even.most_common()[0][1])
else:
    # even, odd列で最頻値が同じ場合
    if max(len(cl_odd.most_common()),len(cl_even.most_common())) != 1:
        # 少なくとも片方が２種類ある場合
        if len(cl_odd.most_common()) == 1 and len(cl_even.most_common()) != 1:
            print(len(v_even) - cl_even.most_common()[1][1])
        elif len(cl_odd.most_common()) != 1 and len(cl_even.most_common()) == 1:
            print(len(v_odd) - cl_odd.most_common()[1][1])
        else:
            # even, oddの効率の良い方を書き換える
            ans = min(len(v_even) - cl_even.most_common()[1][1], len(v_odd) - cl_odd.most_common()[1][1])
            print(ans)
    else:
        # 両方とも１種類ずつの値で構成されていて，かつ同じ値
        print(len(v_odd))

Submission status: Wrong Answer

Solution code:
n = int(input())
v = list(map(int, input().split()))
v_odd = []
v_even = []
for i in range(n):
    if i % 2 == 0:
        v_odd.append(v[i])
    else:
        v_even.append(v[i])

        
import collections
cl_odd = collections.Counter(v_odd)
cl_even = collections.Counter(v_even)


if cl_odd.most_common()[0][0] != cl_even.most_common()[0][0]:
    # even, odd列で最頻値が異なる場合
    print(len(v_odd) - cl_odd.most_common()[0][1] +
          len(v_even) - cl_even.most_common()[0][1])
else:
    # even, odd列で最頻値が同じ場合
    if max(len(cl_odd.most_common()),len(cl_odd.most_common())) != 1:
        # 少なくとも片方が２種類ある場合
        if len(cl_odd.most_common()) == 1 and len(cl_odd.most_common()) != 1:
            print(len(v_even) - cl_even.most_common()[1][1])
        elif len(cl_odd.most_common()) != 1 and len(cl_odd.most_common()) == 1:
            print(len(v_odd) - cl_odd.most_common()[1][1])
        else:
            # even, oddの効率の良い方を書き換える
            ans = min(len(v_even) - cl_even.most_common()[1][1], len(v_odd) - cl_odd.most_common()[1][1])
            print(ans)
    else:
        # 両方とも１種類ずつの値で構成されていて，かつ同じ値
        print(len(v_odd))

Submission status: Wrong Answer

Solution code:
from collections import Counter
N = int(input())
A = list(map(int,input().split()))
e = A[0::2]
o = A[1::2]
me = Counter(e).most_common()[0][0]
mo = Counter(o).most_common()[0][0]
ans = 0
for i in range(N):
  if i % 2 == 0:
    if A[i] != me:
      ans += 1
  elif i % 2 == 1:
    if A[i] != mo:
      ans += 1
if me == mo:
  ans = N // 2
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
v = list(map(int, input().split()))
ev, od = [], []
for i in range(n):
    if i % 2 == 0:
        ev.append(v[i])
    else:
        od.append(v[i])
res = 0
res += len(set(ev)) - 1
res += len(set(od)) - 1
if res == 0 and v[0] == v[1]:
    res += n // 2

print(res)

Submission status: Wrong Answer

Solution code:
n = int(input())
v = list(map(int,input().split()))
d1 = {}
d2 = {}
for i in range(n):
  if i%2 == 0:
    if v[i] in d1:
      d1[v[i]] += 1
    else:
      d1[v[i]] = 1
  else:
    if v[i] in d2:
      d2[v[i]] += 1
    else:
      d2[v[i]] = 1

if max(d1) != max(d2):
  if n%2 == 0:
    print((n//2 - max(d1.values()))+((n//2 - max(d2.values()))))
  else:
    print((n//2 - max(d1.values()))+((n//2 - max(d2.values()) + 1)))
else:
  if max(d1) > max(d2):
    try:
      d2_max2 = sorted(d2.values())[-2]
    except:
      d2_max2 = 0
    if n%2 == 0:
      print((n//2 - max(d1.values()))+((n//2 - d2_max)))
    else:
      print((n//2 - max(d1.values()))+((n//2 - d2_max + 1)))
  else:
    try:
      d1_max2 = sorted(d1.values())[-2]
    except:
      d1_max2 = 0
    if n%2 == 0:
      print((n//2 - d1_max2)+((n//2 - max(d2.values()))))
    else:
      print((n//2 - d1_max2)+((n//2 - max(d2.values()) + 1)))

Submission status: Wrong Answer

Solution code:
n=int(input())
v=list(map(int,input().split()))
odd=v[0::2]
even=v[1::2]
from collections import Counter
o=Counter(odd).most_common(1)[0][1]
e=Counter(even).most_common(1)[0][1]
if len(set(v))!=1:
    print(n-o-e)
else:
    print(n-o)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
n=int(input())
a=list(map(int,input().split()))
even=defaultdict(int)
odd=defaultdict(int)
for i in range(n):
  if i%2==0:
    even[a[i]]+=1
  else:
    odd[a[i]]+=1
tmp=0
v1=-1
for key in even.keys():
  if even[key]>tmp:
    tmp=even[key]
    v1=key
tmp2=0
v2=-1   
for key in odd.keys():
  if odd[key]>tmp2 and key!=v1 :
    tmp2=odd[key]
    v2=key
V1=(n//2 if n%2==0 else n//2+1)-tmp
V2=n//2-tmp2
print(V1+V2)

Submission status: Wrong Answer

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

count1 = {}
count2 = {}

for i in range(n):
    if i%2==0:
        if lst[i] in count1:
            count1[lst[i]] += 1
        else:
            count1[lst[i]] = 1
    else:
        if lst[i] in count2:
            count2[lst[i]] += 1
        else:
            count2[lst[i]] = 1

sorted1 = sorted(count1.items(), key=lambda x:x[1])
sorted2 = sorted(count2.items(), key=lambda x:x[1])

sorted1.append((-1,0))
sorted2.append((-1,0))

if sorted1[0][0]!=sorted2[0][0]:
    print(n-sorted1[0][1]-sorted2[0][1])
else:
    a = n-sorted1[0][1]-sorted2[1][1]
    b = n-sorted1[1][1]-sorted2[0][1]
    print(min(a,b))

Submission status: Wrong Answer

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

count1 = {}
count2 = {}

for i in range(n):
    if i%2==0:
        if lst[i] in count1:
            count1[lst[i]] += 1
        else:
            count1[lst[i]] = 1
    else:
        if lst[i] in count2:
            count2[lst[i]] += 1
        else:
            count2[lst[i]] = 1

sorted1 = sorted(count1.items(), key=lambda x:x[0])
sorted2 = sorted(count2.items(), key=lambda x:x[0])

sorted1.append((-1,0))
sorted2.append((-1,0))

if sorted1[0][0]!=sorted2[0][0]:
    print(n-sorted1[0][1]-sorted2[0][1])
else:
    a = n-sorted1[0][1]-sorted2[1][1]
    b = n-sorted1[1][1]-sorted2[0][1]
    print(min(a,b))

Submission status: Wrong Answer

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

count1 = {}
count2 = {}

for i in range(n):
    if i%2==0:
        if lst[i] in count1:
            count1[lst[i]] += 1
        else:
            count1[lst[i]] = 1
    else:
        if lst[i] in count2:
            count2[lst[i]] += 1
        else:
            count2[lst[i]] = 1

sorted1 = sorted(count1.items(), key=lambda x:x[0])
sorted2 = sorted(count2.items(), key=lambda x:x[0])

sorted1.append((-1,0))
sorted2.append((-1,0))

if sorted1[0][0]!=sorted2[0][0]:
    print(n-sorted1[0][1]-sorted2[0][1])
else:
    a = n-sorted1[0][1]-sorted2[1][1]
    b = n-sorted1[1][1]-sorted2[0][1]
    print(max(a,b))

Submission status: Wrong Answer

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

cnt1 = {}
cnt2 = {}

for i in range(n):
    if i % 2 == 0:
        if v[i] in cnt1:
            cnt1[v[i]] += 1
        else:
            cnt1[v[i]] = 1
    else:
        if v[i] in cnt2:
            cnt2[v[i]] += 1
        else:
            cnt2[v[i]] = 1

sorted_cnt1 = sorted(cnt1.items(), key = lambda x: x[1], reverse = True)
sorted_cnt2 = sorted(cnt2.items(), key = lambda x: x[1], reverse = True)

sorted_cnt1.append((-1,0))
sorted_cnt2.append((-1,0))

if sorted_cnt1[0][0] != sorted_cnt2[0][0]:
    print(n - sorted_cnt1[0][1] - sorted_cnt2[0][1])
else:
    print(n - max(sorted_cnt1[0][1] + sorted_cnt2[1][1], sorted_cnt1[1][1], sorted_cnt2[0][1]))

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
l = list(map(int, input().split(' ')))
print(n-max(collections.Counter(l[::2]).values())-max(collections.Counter(l[1::2]).values()))

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
from collections import Counter

n = int(input())
v = list(map(int, input().split()))
a = Counter(v[::2]).most_common()
b = Counter(v[1::2]).most_common()
if a[0][0] != b[0][0]:
    print(n-a[0][1]-b[0][1])
else:
    print(min(a[0][1], b[0][1]))

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
from collections import Counter

n = int(input())
v = list(map(int, input().split()))
c1 = Counter(sorted(v[::2],reverse=True))
c2 = Counter(sorted(v[1::2],reverse=True))
ans = 0
mi1 = list(c1.elements())[0]
mc1 = list(c1.values())[0]
mi2 = list(c2.elements())[0]
mc2 = list(c2.values())[0]
ans = 0
if mc1 != n//2:
    for i,c in c1.items():
       if i != mi1:ans+=c
if mc2 != n//2:
    for i,c in c2.items():
       if i != mi2:ans+=c
if ans == 0 and mi1 == mi2:
    ans = n//2
print(ans)

Submission status: Wrong Answer

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

judge_2n_1 = {}
judge_2n = {}

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

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

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

print(answer)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

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

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

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

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

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

half = (n - 2) / 2
cnt = 0

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

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

# print(f'{last_odd}, {last_even}, {num1}, {num2}')
print(int(cnt))

Submission status: Wrong Answer

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

judge_2n_1={}
judge_2n={}

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

#print(max(judge_2n))
#print(max(judge_2n_1))

if max(judge_2n_1)!=max(judge_2n):
    print(n//2-max(judge_2n.values())+n//2-max(judge_2n_1.values()))
else:
    save_2n=max(judge_2n.values())
    save_2n_1=max(judge_2n_1.values())
    judge_2n[max(judge_2n)]=0
    judge_2n_1[max(judge_2n_1)]=0
    print(min(n-(max(judge_2n.values())+save_2n_1),n-(save_2n+max(judge_2n_1.values()))))

Submission status: Wrong Answer

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

judge_2n_1={}
judge_2n={}

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

#print(max(judge_2n))
#print(max(judge_2n_1))

if max(judge_2n_1)!=max(judge_2n):
    print(n//2-max(judge_2n.values())+n//2-max(judge_2n_1.values()))
else:
    if max(judge_2n_1.values())>=max(judge_2n.values()):
        judge_2n[max(judge_2n)]=0
    else:
        judge_2n_1[max(judge_2n_1)]=0
    print(n//2-max(judge_2n.values())+n//2-max(judge_2n_1.values()))

Submission status: Wrong Answer

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

judge_2n_1={}
judge_2n={}

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

#print(max(judge_2n))
#print(max(judge_2n_1))
if max(judge_2n_1)!=max(judge_2n):
    print(n-(max(judge_2n.values())+max(judge_2n_1.values())))
else:
    if max(judge_2n_1.values())>=max(judge_2n.values()):
        judge_2n[max(judge_2n)]=0
    else:
        judge_2n_1[max(judge_2n_1)]=0
    print(n-(max(judge_2n.values())+max(judge_2n_1.values())))

Submission status: Wrong Answer

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

judge_2n_1={}
judge_2n={}

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

#print(max(judge_2n))
#print(max(judge_2n_1))
if max(judge_2n_1)!=max(judge_2n):
    print(n-(max(judge_2n.values())+max(judge_2n_1.values())))
else:
    if max(judge_2n_1.values())>=max(judge_2n.values()):
        judge_2n[max(judge_2n)]=0
    else:
        judge_2n_1[max(judge_2n_1)]=0
    print(n-(max(judge_2n.values())+max(judge_2n_1.values())))

Submission status: Wrong Answer

Solution code:
import collections

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

vlist1=[vlist[2*i] for i in range(n//2)]
vlist2=[vlist[2*i+1] for i in range(n//2)]
#print(vlist1)
#print(vlist2)

vc1=collections.Counter(vlist1).most_common()
vc2=collections.Counter(vlist2).most_common()
print(vc1)
print(vc2)

if vc1[0][0]!=vc2[0][0]:
  print(n-vc1[0][1]-vc2[0][1])
elif len(vc1)==1 and len(vc2)==1:
  print(n//2)
elif len(vc1)==1:
  print(n//2-vc2[1][1])
elif len(vc2)==1:
  print(n//2-vc1[1][1])
else:
  if vc1[0][1]>vc2[0][1]:
    print(n-vc1[0][1]-vc2[1][1])
  elif vc1[0][1]<vc2[0][1]:
    print(n-vc1[1][1]-vc2[0][1])
  else:
    max_2nd=max(vc1[1][1],vc2[1][1])
    print(n-vc1[0][1]-max_2nd)