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 = input()

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


odd_v = v[::2]
even_v = v[1::2]

counter_odd = {}

for i in odd_v:
    if not i in counter_odd:
        counter_odd[i] = 1
    else:
        counter_odd[i] += 1

counter_even = {}
for i in even_v:
    if not i in counter_even:
        counter_even[i] = 1
    else:
        counter_even[i] += 1


max_odd = -1e+100
max_odd_idx = 0
for k, v in counter_odd.items():
    if max(v, max_odd) == v:
        max_odd = v
        max_odd_idx = k


max_even = -1e+100
max_even_idx = 0
for k, v in counter_even.items():
    if max(v, max_even) == v:
        max_even = v
        max_even_idx = k

should_change_odd = None

if max_odd_idx == max_even_idx:
    if max_odd <= max_even:
        should_change_odd = True
    else:
        should_change_odd = False

nb_change = 0
m = int(n) / 2

if should_change_odd is None:
    nb_change += m - max_odd
    nb_change += m - max_even
elif should_change_odd is True:
    # 2nd largest item
    if len(counter_odd.items()) == 1:
        nb_change += m
    else:
        s = sorted(counter_odd.items(), key= lambda x:x[1])[0][1]
        nb_change += m - s
        nb_change += m - max_even
elif should_change_odd is False:
    # 2nd largest item
    if len(counter_even.items()) == 1:
        nb_change += m
    else:
        s = sorted(counter_even.items(), key=lambda x: x[1])[0][1]
        nb_change += m - s
        nb_change += m - max_odd

print(int(nb_change))

Submission status: Wrong Answer

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

de = {}
do = {}

for i in range(0, len(v), 2):
  if v[i] in de:
    de[v[i]] += 1
  else:
    de[v[i]] = 1
  if v[i+1] in do:
    do[v[i+1]] += 1
  else:
    do[v[i+1]] = 1

de_k, do_k = \
 [sorted(d.keys(), reverse=True, key=lambda k: d[k]) for d in [de, do]]

if de[de_k[0]] < do[do_k[0]]:
  dl   = do
  dl_k = do_k
  ds   = de
  ds_k = de_k
else:
  dl   = de
  dl_k = de_k
  ds   = do
  ds_k = do_k

n_dl = n//2 - dl[dl_k[0]]

if dl_k[0] != ds_k[0]:
  n_ds = n//2 - ds[ds_k[0]]
elif len(ds_k) <= 1:
  n_ds = ds[ds_k[0]]
else:
  n_ds = n//2 - ds[ds_k[1]]

print(n_dl + n_ds)

Submission status: Wrong Answer

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

de = {}
do = {}

for i in range(0, len(v), 2):
  if v[i] in de:
    de[v[i]] += 1
  else:
    de[v[i]] = 1
  if v[i+1] in do:
    do[v[i+1]] += 1
  else:
    do[v[i+1]] = 1

de_k, do_k = \
 [sorted(d.keys(), reverse=True, key=lambda k: d[k]) for d in [de, do]]

#print(de_k)
#print(do_k)

if de[de_k[0]] < do[do_k[0]]:
  dl   = do
  dl_k = do_k
  ds   = de
  ds_k = de_k
else:
  dl   = de
  dl_k = de_k
  ds   = do
  ds_k = do_k

#print(n//2 - dl[dl_k[0]] - ds[ds_k[1 if dl_k[0] == ds_k[0] else 0]])
n_dl = n//2 - dl[dl_k[0]]

if dl_k[0] != ds_k[0]:
  n_ds = ds_k[0]
elif len(ds_k) <= 1:
  n_ds = ds_k[0]
else:
  n_ds = n//2 - ds_k[1]

print(n_dl + n_ds)

Submission status: Wrong Answer

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

de = {}
do = {}

for i in range(0, len(v), 2):
  if v[i] in de:
    de[v[i]] += 1
  else:
    de[v[i]] = 1
  if v[i+1] in do:
    do[v[i+1]] += 1
  else:
    do[v[i+1]] = 1

de_k, do_k = \
 [sorted(d.keys(), reverse=True, key=lambda k: d[k]) for d in [de, do]]

print(de_k)
print(do_k)

if de[de_k[0]] < do[do_k[0]]:
  dl   = do
  dl_k = do_k
  ds   = de
  ds_k = de_k
else:
  dl   = de
  dl_k = de_k
  ds   = do
  ds_k = do_k

#print(n//2 - dl[dl_k[0]] - ds[ds_k[1 if dl_k[0] == ds_k[0] else 0]])
n_dl = n//2 - dl[dl_k[0]]

if dl_k[0] != ds_k[0]:
  n_ds = ds_k[0]
elif len(ds_k) <= 1:
  n_ds = ds_k[0]
else:
  n_ds = n//2 - ds_k[1]

print(n_dl + n_ds)

Submission status: Wrong Answer

Solution code:

n=int(raw_input())
lt=raw_input().split(' ')

ar=[]
for i in range(0,n):
	ar.append(int(lt[i]))

l=(n//2)
dic={}
m1=0; m2=0;
a=-1; b=-1
for i in range(0,n,2):
	if ar[i] in dic:
		dic[ar[i]]+=1
	else:
		dic[ar[i]]=1
	if dic[ar[i]]>m1:
		m2=m1;
		m1=dic[ar[i]]
		b=a;
		a=ar[i]
	elif dic[ar[i]]>m2:
		m2=dic[ar[i]]
		b=ar[i]

d2={}
m3=0; m4=0;
c=-1; d=-1;
for i in range(1,n,2):
	if ar[i] in d2:
		d2[ar[i]]+=1
	else:
		d2[ar[i]]=1
	if d2[ar[i]]>m3:
		m4=m3
		m3=d2[ar[i]]
		d=c
		c=ar[i]
	elif d2[ar[i]]>m4:
		m4=d2[ar[i]]
		d=ar[i]

if a!=c:
	print((l-m1)+(l-m3))
elif a!=d and c!=b:
	g=(l-m1)+(l-m4)
	h=(l-m2)+(l-m3)
	print(min(g,h))
elif a!=d:
	print((l-m1)+(l-m4))
elif c!=d:
	print((l-m2)+(l-m3))
else:
	if m1>m3:
		print((l-m1)+l)
	else:
		print(l+(l-m3))

Submission status: Wrong Answer

Solution code:
n=int(input())
vn=list(map(int,input().split()))
c_vo={-1:0}
c_ve={-1:0}
for i in range(0,n,2):
  v_o = vn[i]
  v_e = vn[i+1]
  if v_o in c_vo:
    c_vo[v_o]+=1
  else:
    c_vo[v_o]=1
  if v_e in c_ve:
    c_ve[v_e]+=1
  else:
    c_ve[v_e]=1

cl_vo = list(c_vo.items())
cl_vo.sort(key=lambda x:x[1],reverse=True)
cl_ve = list(c_ve.items())
cl_ve.sort(key=lambda x:x[1],reverse=True)
if cl_vo[0][0] != cl_ve[0][0]:
  print (n-cl_vo[0][1]-cl_ve[0][1])
elif cl_vo[1][0] > cl_ve[1][0]:
  print (n-cl_vo[1][1]-cl_ve[0][1])
else:
  print (n-cl_vo[0][1]-cl_ve[1][1])

Submission status: Wrong Answer

Solution code:
import collections

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

ans = 0

even_dict = collections.Counter(vn[::2])
odd_dict = collections.Counter(vn[1::2])

if even_dict.most_common()[0][0] != odd_dict.most_common()[0][0]:
    ans = sum(list(even_dict.values())[1:] + list(odd_dict.values())[1:])
else:
    if sum(list(even_dict.values())[1:]) > sum(list(odd_dict.values())[1:]):
        ans = sum(list(odd_dict.values())[1:]) + sum(list(even_dict.values())[:1]+list(even_dict.values())[2:])
    else:
        ans = sum(list(even_dict.values())[1:]) + sum(list(odd_dict.values())[:1] + list(odd_dict.values())[2:])
                  
print(ans)

Submission status: Wrong Answer

Solution code:
import collections
N = int(input())
a = input().split( )

ret = [0]

odds = []
evens = []
for i in range(N):
    if i % 2 == 0:
        odds.append(int(a[i]))
    else:
        evens.append(int(a[i]))

codds = collections.Counter(odds)
cevens = collections.Counter(evens)

if codds.most_common()[0][0] ==cevens.most_common()[0][0]:
    codds = sorted(list(codds.values()))
    cevens = sorted(list(cevens.values()))
    codds1 = codds
    codds2 = codds
    cevens1=cevens
    cevens2=cevens
    if len(codds) > 1:
        codds1.pop(-1)
        codds2.pop(-2)
    else:
        codds1 = [0]
    if len(cevens) > 1:
        cevens1.pop(-2)
        cevens2.pop(-1)
    else:
        cevens2 = [0]
    c1 = sum(codds1) + sum(cevens1)
    c2 = sum(codds2) + sum(cevens2)
    print(min(c1, c2))

else:
    codds = sorted(list(codds.values()))
    cevens = sorted(list(cevens.values()))
    if len(codds) > 1:
        codds.pop(-1)
    else:
        codds= [0]
    if len(cevens) > 1:
        cevens.pop(-1)
    else:
        cevens = [0]

    print(sum(codds) + sum(cevens))

Submission status: Wrong Answer

Solution code:
import collections
N = int(input())
a = input().split( )

ret = [0]

odds = []
evens = []
for i in range(N):
    if i % 2 == 0:
        odds.append(int(a[i]))
    else:
        evens.append(int(a[i]))

codds = collections.Counter(odds)
cevens = collections.Counter(evens)

if codds.most_common()[0][0] ==cevens.most_common()[0][0]:
    if codds.most_common()[0][1] > cevens.most_common()[0][1]:
        codds = sorted(list(codds.values()))
        cevens = sorted(list(cevens.values()))
        if len(codds) > 1:
            codds.pop(-1)
        else:
            codds = [0]
        if len(cevens) > 1:
            cevens.pop(-2)
    else:
        codds = sorted(list(codds.values()))
        cevens = sorted(list(cevens.values()))
        if len(codds) > 1:
            codds.pop(-2)
        if len(cevens) > 1:
            cevens.pop(-1)
        else:
            cevens = [0]
else:
    codds = sorted(list(codds.values()))
    cevens = sorted(list(cevens.values()))
    if len(codds) > 1:
        codds.pop(-1)
    else:
        codds= [0]
    if len(cevens) > 1:
        cevens.pop(-1)
    else:
        cevens = [0]

print(sum(codds) + sum(cevens))

Submission status: Wrong Answer

Solution code:
import collections
N = int(input())
a = input().split( )

ret = [0]

odds = []
evens = []
for i in range(N):
    if i % 2 == 0:
        odds.append(int(a[i]))
    else:
        evens.append(int(a[i]))

codds = collections.Counter(odds)
cevens = collections.Counter(evens)

if codds.most_common()[0][0] ==cevens.most_common()[0][0]:
    if codds.most_common()[0][1] > cevens.most_common()[0][1]:
        codds = sorted(list(codds.values()))
        cevens = sorted(list(cevens.values()))
        if len(codds) > 1:
            codds.pop(-1)
        else:
            codds = [0]
        if len(cevens) > 1:
            cevens.pop(-2)
    else:
        codds = list(codds.values())
        cevens = list(cevens.values())
        if len(codds) > 1:
            codds.pop(-2)
        if len(cevens) > 1:
            cevens.pop(-1)
        else:
            cevens = [0]
else:
    codds = sorted(list(codds.values()))
    cevens = sorted(list(cevens.values()))
    if len(codds) > 1:
        codds.pop(-1)
    else:
        codds= [0]
    if len(cevens) > 1:
        cevens.pop(-1)
    else:
        cevens = [0]

print(sum(codds) + sum(cevens))

Submission status: Wrong Answer

Solution code:
import collections
N = int(input())
a = input().split( )

ret = [0]

odds = []
evens = []
for i in range(N):
    if i % 2 == 0:
        odds.append(int(a[i]))
    else:
        evens.append(int(a[i]))

codds = collections.Counter(odds)
cevens = collections.Counter(evens)

if codds.most_common()[0][0] ==cevens.most_common()[0][0]:
    if codds.most_common()[0][1] > cevens.most_common()[0][1]:
        codds = list(codds.values())
        cevens = list(cevens.values())
        if len(codds) > 1:
            codds=sorted(codds)
            codds.pop(-1)
        else:
            codds = [0]
        if len(cevens) > 1:
            cevens = sorted(cevens)
            cevens.pop(-2)
    else:
        codds = list(codds.values())
        cevens = list(cevens.values())
        if len(codds) > 1:
            codds=sorted(codds)
            codds.pop(-2)
        if len(cevens) > 1:
            cevens = sorted(cevens)
            cevens.pop(-1)
        else:
            cevens = [0]
else:
    codds = list(codds.values())
    cevens = list(cevens.values())
    if len(codds) > 1:
        codds=sorted(codds)
        codds.pop(-1)
    else:
        codds= [0]
    if len(cevens) > 1:
        cevens = sorted(cevens)
        cevens.pop(-1)
    else:
        cevens = [0]

print(sum(codds) + sum(cevens))

Submission status: Wrong Answer

Solution code:
import collections
N = int(input())
a = input().split( )

ret = [0]

odds = []
evens = []
for i in range(N):
    if i % 2 == 0:
        odds.append(int(a[i]))
    else:
        evens.append(int(a[i]))

codds = collections.Counter(odds)
cevens = collections.Counter(evens)

if codds.most_common()[0][0] ==cevens.most_common()[0][0]:
    if codds.most_common()[0][1] > cevens.most_common()[0][1]:
        codds = list(codds.values())
        cevens = list(cevens.values())
        if len(codds) > 1:
            codds=sorted(codds)
            codds.pop(-1)
        else:
            codds = [0]
        if len(cevens) > 1:
            cevens = sorted(cevens)
            cevens.pop(-2)
    else:
        codds = list(codds.values())
        cevens = list(cevens.values())
        if len(codds) > 1:
            codds=sorted(codds)
            codds.pop(-2)
        if len(cevens) > 1:
            cevens = sorted(cevens)
            cevens.pop(-1)
        else:
            cevens = [0]
else:
    codds = list(codds.values())
    cevens = list(cevens.values())
    if len(codds) > 1:
        codds=sorted(codds)
        codds.pop(-1)
    if len(cevens) > 1:
        cevens = sorted(cevens)
        cevens.pop(-1)

print(sum(codds) + sum(cevens))

Submission status: Wrong Answer

Solution code:
import collections
N = int(input())
a = input().split( )

ret = [0]

odds = []
evens = []
for i in range(N):
    if i % 2 == 0:
        odds.append(int(a[i]))
    else:
        evens.append(int(a[i]))

codds = collections.Counter(odds)
cevens = collections.Counter(evens)
print(codds)
print(cevens)

if codds.most_common()[0][0] ==cevens.most_common()[0][0]:
    if codds.most_common()[0][1] > cevens.most_common()[0][1]:
        codds = list(codds.values())
        cevens = list(cevens.values())
        if len(codds) > 1:
            codds=sorted(codds)
            codds.pop(-1)
        else:
            codds = [0]
        print(1)
        if len(cevens) > 1:
            print(3)
            cevens = sorted(cevens)
            cevens.pop(-2)
    else:
        codds = list(codds.values())
        cevens = list(cevens.values())
        if len(codds) > 1:
            codds=sorted(codds)
            codds.pop(-2)
        if len(cevens) > 1:
            cevens = sorted(cevens)
            cevens.pop(-1)
        else:
            cevens = [0]
else:
    codds = list(codds.values())
    cevens = list(cevens.values())
    if len(codds) > 1:
        codds=sorted(codds)
        codds.pop(-1)
    if len(cevens) > 1:
        cevens = sorted(cevens)
        cevens.pop(-1)

print(sum(codds) + sum(cevens))

Submission status: Wrong Answer

Solution code:
import collections
N = int(input())
a = input().split( )

ret = [0]

odds = []
evens = []
for i in range(N):
    if i % 2 == 0:
        evens.append(int(a[i]))
    else:
        odds.append(int(a[i]))

codds = collections.Counter(odds)
cevens = collections.Counter(evens)

if codds.most_common()[0][0] ==cevens.most_common()[0][0]:
    if codds.most_common()[0][1] > cevens.most_common()[0][1]:
        codds = list(codds.values())
        cevens = list(cevens.values())
        if len(codds) > 1:
            codds=sorted(codds)
            codds=codds[1:]
        else:
            codds = [0]
        if len(cevens) > 1:
            cevens = sorted(cevens)
            evens = evens.pop(1)
    else:
        codds = list(codds.values())
        cevens = list(cevens.values())
        if len(codds) > 1:
            codds=sorted(codds)
            codds.pop(1)
        if len(cevens) > 1:
            cevens = sorted(cevens)
            cevens = cevens[1:]
        else:
            cevens = [0]
else:
    codds = list(codds.values())
    cevens = list(cevens.values())
    if len(codds) > 1:
        codds=sorted(codds)
        codds=codds[1:]
    if len(cevens) > 1:
        cevens = sorted(cevens)
        cevens = cevens[1:]

print(sum(codds) + sum(cevens))

Submission status: Wrong Answer

Solution code:
from collections import Counter

class Solver(object):
    def __init__(self):
        self._input()
        self.solve()

    def _input(self):
        self.n = int(input())
        self.v_s = list(map(int, input().split(" ")))
        self.evens = []
        self.odds = []
        for i, v in enumerate(self.v_s):
            if i % 2 == 0:
                self.evens.append(v)
            else:
                self.odds.append(v)
        self.evens = Counter(self.evens)
        self.odds = Counter(self.odds)
            
    def solve(self):
        if max(self.evens.values()) > max(self.odds.values()):
            self.count_adjust(self.evens, self.odds)
        else:
            self.count_adjust(self.odds, self.evens)
    
    def count_adjust(self, major, minor):
        major_prime = (-1, -1)
        for x, count in major.items():
            if count > major_prime[1]:
                major_prime = (x, count)
        minor_prime = (-1, -1)
        for x, count in minor.items():
            if (count > minor_prime[1]) and (x != major_prime[0]):
                minor_prime = (x, count)
        ans = 0
        for x, count in major.items():
            if x != major_prime[0]:
                ans += count
        if minor_prime == (-1, -1):
            ans += list(minor.values())[0]
        else:
            for x, count in minor.items():
                if x != minor_prime[0]:
                    ans += count
        print(ans)


if __name__ == "__main__":
    Solver()

Submission status: Wrong Answer

Solution code:
from sys import stdin
import collections

n, v_list = stdin.readlines()
n = int(n.rstrip())
v_list = [int(v) for v in v_list.rstrip().split()]
#print(n, v_list)

v_list_odd  = [v_list[i] for i in range(1, n, 2)]
v_list_even = [v_list[i] for i in range(0, n, 2)]

c_odd  = collections.Counter(v_list_odd)
c_even = collections.Counter(v_list_even)

most_common_odd  = c_odd.most_common()
most_common_even = c_even.most_common()
#print(most_common_even)
#print(most_common_odd)

if most_common_odd[0][0] == most_common_even[0][0]:
  if len(most_common_even) == len(most_common_odd) == 1:
    print(n/2)
  elif len(most_common_even) == 1:
    print(n/2-most_common_odd[1][1])
  elif len(most_common_odd) == 1:
    print(n/2-most_common_even[1][1])
  else:
    case1 = (n/2-most_common_odd[0][1]) + (n/2-most_common_even[1][1])
    case2 = (n/2-most_common_odd[1][1]) + (n/2-most_common_even[0][1])
    if case1 > case2:
      print(case2)
    else:
      print(case1)
else:
  odd_cnt  = most_common_odd[0][1]
  even_cnt = most_common_even[0][1]
  print(n-odd_cnt-even_cnt)

Submission status: Wrong Answer

Solution code:
from sys import stdin
import collections

n, v_list = stdin.readlines()
n = int(n.rstrip())
v_list = [int(v) for v in v_list.rstrip().split()]
#print(n, v_list)

v_list_odd  = [v_list[i] for i in range(1, n, 2)]
v_list_even = [v_list[i] for i in range(0, n, 2)]

c_odd  = collections.Counter(v_list_odd)
c_even = collections.Counter(v_list_even)

most_common_odd  = c_odd.most_common()
most_common_even = c_even.most_common()
#print(most_common_even)
#print(most_common_odd)

if most_common_odd[0][0] == most_common_even[0][0]:
  print(n/2)
else:
  odd_cnt  = most_common_odd[0][1]
  even_cnt = most_common_even[0][1]
  print(n-odd_cnt-even_cnt)

Submission status: Wrong Answer

Solution code:
import collections as cl

n = int(input())
a = [int(i) for i in input().split(' ')]
cnt=0
if len(set(a)) == 1:
  cnt = len(a)/2

else:
  a1 = [a[i] for i in range(len(a)) if i%2==0]
  a2 = [a[i] for i in range(len(a)) if i%2==1]
 
  cnt1 = len(a1)-max(cl.Counter(a1).values())
  cnt2 = len(a2)-max(cl.Counter(a2).values())
  cnt = cnt1+cnt2
print(cnt)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
n = int(input())
nums = [int(each) for each in input().split()]
oddD = defaultdict(int)
evenD = defaultdict(int)
for i in range(len(nums)):
  if((i+1) % 2==0):
    evenD[nums[i]] += 1
  else:
    oddD[nums[i]] += 1
evenD_list = []
oddD_list = []
for key in evenD.keys():
  evenD_list.append([key, evenD[key]])
for key in oddD.keys():
  oddD_list.append([key,oddD[key]])
evenD_list.sort(key=lambda x :x[1])
oddD_list.sort(key=lambda x : x[1])
i = len(evenD_list)-1
j = len(oddD_list)-1
while(i >= 0 and j >= 0):
  e_value, e_num = evenD_list[i]
  o_value, o_num = oddD_list[j]
  if(e_value == o_value):
    if(e_num < o_num):
      i -= 1
    else:
      j -= 1
  else:
    break
    
if(i < 0):
    i = 0
if(j < 0):
    j = 0
e_value, e_num = evenD_list[i]
o_value, o_num =oddD_list[j]
if(e_value == o_value):
  print(int((n/2-max(e_num,o_num) + n/2)))
else:
  print(int(n/2 - e_num + n/2 -o_num))

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
n = int(input())
nums = [int(each) for each in input().split()]
oddD = defaultdict(int)
evenD = defaultdict(int)
for i in range(len(nums)):
  if((i+1) % 2==0):
    evenD[nums[i]] += 1
  else:
    oddD[nums[i]] += 1
evenD_list = []
oddD_list = []
for key in evenD.keys():
  evenD_list.append([key, evenD[key]])
for key in oddD.keys():
  oddD_list.append([key,oddD[key]])
evenD_list.sort(key=lambda x :x[1])
oddD_list.sort(key=lambda x : x[1])
i = len(evenD_list)-1
j = len(oddD_list)-1
while(i > 0 and j > 0):
  e_value, e_num = evenD_list[i]
  o_value, o_num = oddD_list[j]
  if(e_value == o_value):
    if(e_num < o_num):
      i -= 1
    else:
      j -= 1
  else:
    break
if(i >= len(evenD_list)):
    i = len(evenD_list)-1
if(j >= len(oddD_list)):
    j = len(oddD_list)- 1
e_value, e_num = evenD_list[i]
o_value, o_num =oddD_list[j]
if(e_value == o_value):
  print(int((n/2-max(e_num,o_num) + n/2)))
else:
  print(int(n/2 - e_num + n/2 -o_num))

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
n = int(input())
nums = [int(each) for each in input().split()]
oddD = defaultdict(int)
evenD = defaultdict(int)
for i in range(len(nums)):
  if((i+1) % 2==0):
    evenD[nums[i]] += 1
  else:
    oddD[nums[i]] += 1
evenD_list = []
oddD_list = []
for key in evenD.keys():
  evenD_list.append([key, evenD[key]])
for key in oddD.keys():
  oddD_list.append([key,oddD[key]])
evenD_list.sort(key=lambda x :x[1])
oddD_list.sort(key=lambda x : x[1])
i = 0
j = 0
while(i <= len(evenD_list)-1 and j <= len(oddD_list)-1):
  e_value, e_num = evenD_list[i]
  o_value, o_num = oddD_list[j]
  if(e_value == o_value):
    if(e_num < o_num):
      i += 1
    else:
      j += 1
  else:
    break
if(i >= len(evenD_list)):
    i = len(evenD_list)-1
if(j >= len(oddD_list)):
    j = len(oddD_list)- 1
e_value, e_num = evenD_list[i]
o_value, o_num =oddD_list[j]
if(e_value == o_value):
  print(int((n/2-max(e_num,o_num) + n/2)))
else:
  print(int(n/2 - e_num + n/2 -o_num))

Submission status: Wrong Answer

Solution code:
import collections
n=int(input())
list=list(map(int,input().split()))
list_1=list[::2]
list_2=list[1::2]
a=collections.Counter(list_1)
b=collections.Counter(list_2)
print(a.most_common()[0]==b.most_common()[0])
print(len(list_1),a.most_common()[0][1])
if((a.most_common()[0]==b.most_common()[0]) & (a.most_common()[0][1]!=len(list_1))):#2つの数列の最大をとる数が等しい場合どちらかは最大個数の数に、もう１つはその次に多い数に置き換える。
  if(n-a.most_common()[0][1]-b.most_common()[1][1]>n-a.most_common()[1][1]-b.most_common()[0][1]):
  	print(n-a.most_common()[1][1]-b.most_common()[0][1])
  else:
    print(n-a.most_common()[0][1]-b.most_common()[1][1])
elif ((a.most_common()==b.most_common()) & (a.most_common()[0][1]==len(list_1))):#２つの数列の全要素が一致する場合どちらかの数字を変更
  print(n//2)
else:

  print(n-a.most_common()[0][1]-b.most_common()[0][1])

Submission status: Wrong Answer

Solution code:
import collections
n=int(input())
list=list(map(int,input().split()))
#print(list)
list_1=list[::2]
list_2=list[1::2]
#print(list_1)
#print(list_2)
a=collections.Counter(list_1)
b=collections.Counter(list_2)
if (a.most_common()==b.most_common()):
  print(n//2)
elif(a.most_common()[0]==b.most_common()[0]):
  print(n-a.most_common()[0][1]-b.most_common()[1][1])
else:
  #print(a)
  #print(b)
  #print(a.most_common())
  #print(b.most_common())
  #print(a.most_common()[0][1])
  #print(b.most_common()[0][1])

  print(n-a.most_common()[0][1]-b.most_common()[0][1])

Submission status: Wrong Answer

Solution code:
import collections
n=int(input())
list=list(map(int,input().split()))
#print(list)
list_1=list[::2]
list_2=list[1::2]
#print(list_1)
#print(list_2)
a=collections.Counter(list_1)
b=collections.Counter(list_2)
if (a.most_common()==b.most_common()):
  print(n//2)
else:
  #print(a)
  #print(b)
  #print(a.most_common())
  #print(b.most_common())
  #print(a.most_common()[0][1])
  #print(b.most_common()[0][1])

  print(n-a.most_common()[0][1]-b.most_common()[0][1])

Submission status: Wrong Answer

Solution code:
import collections
n=int(input())
list=list(map(int,input().split()))
#print(list)
list_1=list[::2]
list_2=list[1::2]
#print(list_1)
#print(list_2)
a=collections.Counter(list_1)
b=collections.Counter(list_2)
if (list_1[0]==list_2[0] & all(list_1) & all(list_2)):
  print(n//2)
elif (a==b):
  print(n//2)
else:
  #print(a)
  #print(b)
  #print(a.most_common())
  #print(b.most_common())
  #print(a.most_common()[0][1])
  #print(b.most_common()[0][1])

  print(n-a.most_common()[0][1]-b.most_common()[0][1])

Submission status: Wrong Answer

Solution code:
import collections
n=int(input())
list=list(map(int,input().split()))
#print(list)
list_1=list[::2]
list_2=list[1::2]
if (list_1[0]==list_2[0] & all(list_1) & all(list_2)):
  print(n//2)
else:
  #print(list_1)
  #print(list_2)
  a=collections.Counter(list_1)
  b=collections.Counter(list_2)
  #print(a)
  #print(b)
  #print(a.most_common())
  #print(b.most_common())
  #print(a.most_common()[0][1])
  #print(b.most_common()[0][1])

  print(n-a.most_common()[0][1]-b.most_common()[0][1])

Submission status: Wrong Answer

Solution code:
import collections
n=int(input())
list=list(map(int,input().split()))
#print(list)
list_1=list[::2]
list_2=list[1::2]
#print(list_1)
#print(list_2)
a=collections.Counter(list_1)
b=collections.Counter(list_2)
#print(a)
#print(b)
#print(a.most_common())
#print(b.most_common())
#print(a.most_common()[0][1])
#print(b.most_common()[0][1])
print(n-a.most_common()[0][1]-b.most_common()[0][1])

Submission status: Wrong Answer

Solution code:
import collections
n=int(input())
list=list(map(int,input().split()))
#print(list)
list_1=list[::2]
list_2=list[1::2]
print(list_1)
#print(list_2)
a=collections.Counter(list_1)
b=collections.Counter(list_2)
#print(a)
#print(b)
#print(a.most_common())
#print(b.most_common())
#print(a.most_common()[0][1])
#print(b.most_common()[0][1])
print(n-a.most_common()[0][1]-b.most_common()[0][1])

Submission status: Wrong Answer

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

os=dict()
es=dict()
for i in range(N//2):
    os[v[2*i]] = os.get(v[2*i], 0) + 1
    es[v[2*i+1]] = es.get(v[2*i+1], 0) + 1

osr=sorted(os.items(), key=lambda x: (x[1], x[0]))
esr=sorted(es.items(), key=lambda x: (x[1], x[0]))

osv = osr.pop()
esv = esr.pop()

o1n = N//2 - osv[1]
e1n = N//2 - esv[1]

count = o1n + e1n
if osv[0] == esv[0]:
    if len(osr) == 0:
        o2n = N//2
    else:
        o2n = osr.pop()[1]
    if len(esr) == 0:
        e2n = N//2
    else:
        e2n = esr.pop()[1]

    count = min(o1n + e2n, o2n + e1n)

print(count)

Submission status: Wrong Answer

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

os=dict()
es=dict()
for i in range(N//2):
    os[v[2*i]] = os.get(v[2*i], 0) + 1
    es[v[2*i+1]] = es.get(v[2*i+1], 0) + 1

osr=sorted(os.items(), key=lambda x: (x[1], x[0]))
esr=sorted(es.items(), key=lambda x: (x[1], x[0]))

osv = osr.pop()
esv = esr.pop()

osc = N//2 - osv[1]
esc = N//2 - esv[1]
if osv[0] == esv[0]:
    if len(osr) == 0:
        if len(esr) == 0:
            osc = N//2
            esc = 0
        else:
            osc = 0
            esc = N//2 - esr.pop()[1]
    else:
        if len(esr) == 0:
            osc = N//2 - osr.pop()[1]
            esc = 0
        else:
            if osv[1] < esv[1]:
                osc = N//2 - osr.pop()[1]
                esc = N//2 - esv[1]
            else:
                osc = N//2 - osv[1]
                esc = N//2 - esr.pop()[1]

print(osc + esc)

Submission status: Wrong Answer

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

os=dict()
es=dict()
for i in range(N//2):
    os[v[2*i]] = os.get(v[2*i], 0) + 1
    es[v[2*i+1]] = es.get(v[2*i+1], 0) + 1

osr=sorted(os.items(), key=lambda x: x[1])
esr=sorted(es.items(), key=lambda x: x[1])

osv = osr.pop()
esv = esr.pop()

osc = N//2 - osv[1]
esc = N//2 - esv[1]
if osv[0] == esv[0]:
    if len(osr) == 0:
        if len(esr) == 0:
            osc = N//2
            esc = 0
        else:
            osc = 0
            esc = N//2 - esr.pop()[1]
    else:
        if len(esr) == 0:
            osc = N//2 - osr.pop()[1]
            esc = 0
        else:
            if osv[1] < esv[1]:
                osc = N//2 - osr.pop()[1]
                esc = N//2 - esv[1]
            else:
                osc = N//2 - osv[1]
                esc = N//2 - esr.pop()[1]

print(osc + esc)

Submission status: Wrong Answer

Solution code:
from collections import Counter
N=int(input())
NN=N//2
l=list(map(int,input().split()))
l1=[l[2*i] for i in range(NN)]
l2=[l[2*i+1] for i in range(NN)]
l1c=Counter(l1)
l2c=Counter(l2)
r1=l1c.most_common()
r2=l2c.most_common()
if r1[0][0]==r2[0][0]:
  if r1[0][1]==NN and r2[0][1]==NN:
    ans=NN
  elif r1[0][1]>r2[0][1]:
    ans=N-r1[0][1]-r2[1][1]
  else:
    ans=N-r1[1][1]-r2[0][1]
else:
  ans=N-r1[0][1]-r2[0][1]
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
N=int(input())
NN=N//2
l=list(map(int,input().split()))
l1=[l[2*i] for i in range(NN)]
l2=[l[2*i+1] for i in range(NN)]
l1c=Counter(l1)
l2c=Counter(l2)
r1=l1c.most_common()
r2=l2c.most_common()
if r1[0][0]==r2[0][1]:
  ans=N-r1[0][1]
else:
  ans=N-r1[0][1]-r2[0][1]
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
N=int(input())
NN=N//2
l=list(map(int,input().split()))
l1=[l[2*i] for i in range(NN)]
l2=[l[2*i+1] for i in range(NN)]
l1c=Counter(l1)
l2c=Counter(l2)
r1=l1c.most_common()
r2=l2c.most_common()
ans=N-r1[0][1]-r2[0][1]
print(ans)

Submission status: Wrong Answer

Solution code:
longs=int(input())
half=int(longs/2)
read=input().split(" ")
A=[[0,0] for i in range(half)]
B=[[0,0] for i in range(half)]

for i in range(longs):
    s=int(read[i])
    #print(i)
    a=int(i/2)
    b=int(i/2-1/2)


    if i==0:
        A[0][1]=s
    elif i%2==0:
        A[a][1]=s
    else:
        B[b][1]=s
        
for i in range(half):
    for j in range(half):
        if A[i][1]==A[j][1]:
            A[i][0]+=1
        if B[i][1]==B[j][1]:
            B[i][0]+=1
            
C=sorted(A)
D=sorted(B)

c=half-int(C[0][0])
d=half-int(D[0][0])

print(c+d)

"""
print(A[0][0])
print(A)
print(B)
"""

Submission status: Wrong Answer

Solution code:
# 数列を2つに分割。arr1, arr2とする。
# arr1, arr2

from collections import *
N = int(input())
As = list(map(int, input().split()))

def solve(arr1, arr2):
    cnt1 = Counter(arr1)
    cnt2 = Counter(arr2)

    # 最大出現文字の集合を得る
    # 最初、引数に1と入れていなかったことによりWA
    most1 = cnt1.most_common(1)
    most2 = cnt2.most_common(1)

    if len(most1) > 1 or len(most2) > 1:
        return len(arr1) - most1[0][1] + len(arr2) - most2[0][1]
    elif most1[0][0] != most2[0][0]:
        return 0
    else:
        try:
            ans1 = len(arr1) - most1[0][1] \
                + len(arr2) - cnt2.most_common(2)[1][1]
        except:
            ans1 = len(arr1) - most1[0][1] \
                + len(arr2)
        try:
            ans2 = len(arr2) - most2[0][1] \
                + len(arr1) - cnt1.most_common(2)[1][1]
        except:
            ans2 = len(arr2) - most2[0][1] \
                + len(arr1)
        return min(ans1, ans2)


arr1 = As[0::2]
arr2 = As[1::2]
print(solve(arr1, arr2))