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:
#!/usr/bin/env python3
from collections import Counter
# from numba import njit

# input = stdin.readline

# @njit
def solve(n,v):
  d = Counter(v)
  d_len = len(d)
  if d_len == 1:
    return n//2
  sortedList = list(sorted(d.items(),key=lambda x: x[1],reverse=True))
  cand0 = sortedList[0]
  cand1 = sortedList[1]
  return n - cand0[1] - cand1[1]



def main():
  N = int(input())
  # N,M = map(int,input().split())
  v = list(map(int,input().split()))
  print(solve(N,v))
  return

if __name__ == '__main__':
  main()

Submission status: Wrong Answer

Solution code:
import collections
N = int(input())

O = []
E = []
A = list(map(lambda a: int(a), input().split(" ")))
for i in range(N):
  if i % 2 == 0:
    E.append(A[i])
  else:
    O.append(A[i])

CE = collections.Counter(E)
CO = collections.Counter(O)
CE2 = CE.most_common(2)
CO2 = CO.most_common(2)
if CE2[0][0] != CO2[0][0]:
  print(len(E) + len(O) - CE2[0][1] - CO2[0][1])
elif CE2[0][0] == CO2[0][0]:
  if len(CE2) == 1 and len(CO2) == 1:
    print(min([CE2[0][1], CO2[0][1]]))
  elif len(CE2) > 1 and len(CO2) == 1:
    print(len(E) + len(O) - CE2[1][1] - CO2[0][1])
  elif len(CE2) == 1 and len(CO2) > 1:
    print(len(E) + len(O) - CE2[0][1] - CO2[1][1])
  elif CE2[0][1] > CO2[0][1]:
    print(len(E) + len(O) - CE2[0][1] - CO2[1][1])
  elif CE2[0][1] <= CO2[0][1]:
    print(len(E) + len(O) - CE2[1][1] - CO2[0][1])

Submission status: Wrong Answer

Solution code:
n=int(input())
v=list(map(int,input().split()))
a=[0]*(10**5)
b=[0]*(10**5)
s,t=0,0
o,e,oi,ei=0,0,0,0
for i in range(1,n+1):
    if i%2==1:
        a[v[i-1]-1]+=1
        s+=1
    else:
        b[v[i-1]-1]+=1
        t+=1
o=max(a)
oi=[]
e=max(b)
ei=[]
for i in range(10**5):
    if a[i]==o:
        oi.append(i)
    if b[i]==o:
        ei.append(i)
if len(oi)==1 and len(ei)==1 and oi[0]==ei[0]:
    a.sort(reverse=True)
    b.sort(reverse=True)
    print(min(t-e+s-a[1],t-a[1]+s-o))
else:
    print(s+t-e-o)

Submission status: Wrong Answer

Solution code:
n=int(input())
v=list(map(int,input().split()))
a=[0]*(10**5)
b=[0]*(10**5)
s,t=0,0
o,e,oi,ei=0,0,0,0
for i in range(1,n+1):
    if i%2==1:
        a[v[i-1]-1]+=1
        s+=1
    else:
        b[v[i-1]-1]+=1
        t+=1
o=max(a)
oi=[]
e=max(b)
ei=[]
for i in range(10**5):
    if a[i]==o:
        oi.append(i)
    if b[i]==o:
        ei.append(i)
if len(oi)==1 and s-o==t-e and len(ei)==1 and oi[0]==ei[0]:
    a.sort(reverse=True)
    b.sort(reverse=True)
    print(min(t-e+s-a[1],t-a[1]+s-o))
else:
    print(s+t-e-o)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import math
N=int(input())
V=list(map(int,input().split()))
counter = [dict() for _ in range(2)]
for i in range(N):
  if V[i] in counter[i%2]:
    counter[i%2][V[i]] += 1
  else:
    counter[i%2][V[i]] = 1

counter[0] = sorted(counter[0].items(), reverse=True, key=lambda x:x[1])
counter[1] = sorted(counter[1].items(), reverse=True, key=lambda x:x[1])
if counter[0][0][0]!=counter[1][0][0]:
  print(N-counter[0][0][1] - counter[1][0][1])
elif len(counter[0])==1 and len(counter[1])==1:
  print(N//2)
elif len(counter[0])==1:
  print(N//2 - counter[1][1][1])
elif len(counter[1])==1:
  print(math.ceil(N/2)-counter[0][1][1])
elif N%2 or counter[0][0][1] < counter[1][0][1]:
  print(N-counter[0][0][1] - counter[1][1][1])
else:
  print(N-counter[0][1][1] - counter[1][0][1])

Submission status: Wrong Answer

Solution code:
import math
N=int(input())
V=list(map(int,input().split()))
counter = [dict() for _ in range(2)]
for i in range(N):
  if V[i] in counter[i%2]:
    counter[i%2][V[i]] += 1
  else:
    counter[i%2][V[i]] = 1
max_v = [[0,0],[0,0]]
max_k = [[-1,-1],[-1,-1]]
for i in range(2):
  for k,v in counter[i].items():
    if max_v[i][0] < v:
      max_v[i] = [v, max_v[i][0]]
      max_k[i] = k
    elif max_v[i][1] < v:
      max_v[i][1] = v
if max_k[0] != max_k[1]:
  print(N-max_v[0][0]-max_v[1][0])
elif N%2 or max_v[0][0] > max_v[1][0]:  # おなじでも奇数なら奇数回めの方をかえる
  print(N-max_v[0][0]-max_v[1][1])
else:
  print(N-max_v[0][1]-max_v[1][0])

Submission status: Wrong Answer

Solution code:
import math
N=int(input())
V=list(map(int,input().split()))
counter = [dict() for _ in range(2)]
for i in range(N):
  if V[i] in counter[i%2]:
    counter[i%2][V[i]] += 1
  else:
    counter[i%2][V[i]] = 1
max_v = [[0,0],[0,0]]
max_k = [-1,-1]
for i in range(2):
  for k,v in counter[i].items():
    if max_v[i][0] < v:
      max_v[i] = [v, max_v[i][0]]
      max_k[i] = k
    elif max_v[i][1] < v:
      max_v[i][1] = v
if max_k[0] != max_k[1]:
  print(N-max_v[0][0]-max_v[1][0])
else:
  print(N-max_v[0][0]-max_v[1][1])
#print(counter)

Submission status: Wrong Answer

Solution code:
n=int(input())
l=list(map(int, input().split()))
l1=l[0::2]
l2=l[1::2]
import collections
c1 = collections.Counter(l1)
#print(c1)
# Counter({'a': 4, 'c': 2, 'b': 1})
c2 =collections.Counter(l2)  
ans=n
for i in range(min(len(c1), 2)):
  for j in range(min(len(c2), 2)):
    if c1.most_common()[i][0]==c2.most_common()[j][0]:
      break
    else:
      ans=min(ans, n-c1.most_common()[i][1]-c2.most_common()[j][1])
if ans==n:
  print(int(n/2))
else:
  print(int(ans))

Submission status: Wrong Answer

Solution code:
n=int(input())
l=list(map(int, input().split()))
l1=l[0::2]
l2=l[1::2]
import collections
c1 = collections.Counter(l1)
#print(c1)
# Counter({'a': 4, 'c': 2, 'b': 1})
c2 =collections.Counter(l2)  
ans=n
for i in range(min(len(c1), 2)):
  for j in range(min(len(c2), 2)):
    if c1.most_common()[i][0]==c2.most_common()[j][0]:
      break
    else:
      ans=min(ans, n-c1.most_common()[i][1]-c2.most_common()[j][1])
if ans==n:
  print(n/2)
else:
  print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
l=list(map(int, input().split()))
l1=l[0::2]
l2=l[1::2]
import collections
c1 = collections.Counter(l1)
#print(c1)
# Counter({'a': 4, 'c': 2, 'b': 1})
c2 =collections.Counter(l2)  
ans=n
for i in range(min(len(c1), 2)):
  for j in range(min(len(c2), 2)):
    if c1.most_common()[i][0]==c2.most_common()[j][0]:
      break
    else:
      ans=min(ans, n-c1.most_common()[i][1]-c2.most_common()[j][1])
if ans==n:
  print(int(n/2))
else:
  print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

n=int(input())
v=list(map(int,input().split()))
for i in range(1,n):
  if v[0]==v[i] :
    print(n//2)
    exit()
vOdd=[]
vEven=[]
for i in range(n):
  if i%2==1 :
    vEven.append(v[i])
  elif i%2==0 :
    vOdd.append(v[i])
c1=Counter(vOdd)
c2=Counter(vEven)
print(len(vOdd)-(c1.most_common(1))[0][1] + len(vEven)-(c2.most_common(1))[0][1])

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
v = list(map(int, input().split()))
a = v[1::2]
b = v[0::2]
a2 = Counter(a)
b2 = Counter(b)

if a2.most_common()[0][0] != b2.most_common()[0][0]:
    print(n-a2.most_common()[0][1]-b2.most_common()[0][1])
else:
    if len(a2.most_common()) == len(b2.most_common()) == 1:
        print(len(a)-a2.most_common()[0][1]+len(b))
    elif len(a2.most_common()) == 1:
        if len(b)-b2.most_common()[1][1] >= len(a)+len(b)-b2.most_common()[0][1]:
            print(len(b)-b2.most_common()[1][1])
        else:
            print(len(a)+len(b)-b2.most_common()[0][1])
    elif len(b2.most_common()) == 1:
        if len(a)-a2.most_common()[1][1] >= len(a)+len(b)-a2.most_common()[0][1]:
            print(len(a)-a2.most_common()[1][1])
        else:
            print(len(a)+len(b)-a2.most_common()[0][1])
    else:
        if len(a)-a2.most_common()[0][1]+len(b)-b2.most_common()[1][1] >= len(a)-a2.most_common()[1][1]+len(b)-b2.most_common()[0][1]:
            print(len(a)-a2.most_common()[0][1]+len(b)-b2.most_common()[1][1])
        else:
            print(len(a)-a2.most_common()[1][1]+len(b)-b2.most_common()[0][1])

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

kisu = A[0::2]
gusu = A[1::2]

CK = Counter(kisu)
CG = Counter(gusu)
CKM = CK.most_common(2)
CGM = CG.most_common(2)

if len(CKM) == 1 and len(CGM) == 1:
    if CKM[0][0] == CGM[0][0]:
        ans = n // 2
    else:
        ans = 0
elif len(CKM) == 1:
    if CKM[0][0] == CGM[0][0]:
        ans = n // 2 - CGM[1][1]
    else:
        ans = n // 2 - CGM[0][1]
elif len(CGM) == 1:
    if CKM[0][0] == CGM[0][0]:
        ans = n // 2 - CKM[1][1]
    else:
        ans = n // 2 - CKM[0][1]
else:
    if CKM[0][0] == CGM[0][0]:
        ans1 = n // 2 - CKM[1][1] + n // 2 + CGM[0][1]
        ans2 = n // 2 - CGM[1][1] + n // 2 + CKM[0][1]
        ans = min(ans1, ans2)
    else:
        ans = n - (CKM[0][1] + CGM[0][1])

print(ans)

Submission status: Wrong Answer

Solution code:
import copy
import numpy as np

n = int(input())
v = list(map(int,input().split()))
a = v[0::2] 
b = v[1::2]

cnta = np.zeros(10**5+1, dtype=int)
cntb = np.zeros(10**5+1, dtype=int)
for i in range(n//2):
    ca, cb = a[i], b[i]
    cnta[ca] += 1
    cntb[cb] += 1

la = np.zeros((2,2), dtype=int)
lb = np.zeros((2,2), dtype=int)
for i in range(2):
    ia = cnta.argmax()
    ib = cntb.argmax()
    la[i][0], la[i][1] = ia, cnta[ia]
    lb[i][0], lb[i][1] = ib, cntb[ib]
    cnta[ia] = -1
    cntb[ib] = -1

if la[0][0] != lb[0][0]:
    ans = n//2 - la[0][1] + n//2 - lb[0][1]
else:
    ans = min(n//2 - la[0][1] + n//2 - lb[1][1], n//2 - la[1][1] + n//2 - lb[1][1])
print(ans)

Submission status: Wrong Answer

Solution code:
import copy
import numpy as np

n = int(input())
v = list(map(int,input().split()))
a = v[0::2] 
b = v[1::2]

cnta = np.zeros(10**5+1, dtype=int)
cntb = np.zeros(10**5+1, dtype=int)
for i in range(n//2):
    ca, cb = a[i], b[i]
    cnta[ca] += 1
    cntb[cb] += 1

la = np.zeros((2,2), dtype=int)
lb = np.zeros((2,2), dtype=int)
for i in range(2):
    ia = cnta.argmax()
    ib = cntb.argmax()
    la[i][0], la[i][1] = ia, cnta[ia]
    lb[i][0], lb[i][1] = ib, cntb[ib]
    cnta[ia] = 0
    cntb[ib] = 0

if la[0][0] != lb[0][0]:
    ans = n//2 - la[0][1] + n//2 - lb[0][1]
else:
    ans = min(n//2 - la[0][1] + n//2 - lb[1][1], n//2 - la[1][1] + n//2 - lb[1][1])
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n=int(input())
L=list(map(int,input().split()))
ans=0
L_1=Counter(L)
L1=Counter(L[::2])
L2=Counter(L[1::2])
if len(L_1)==1:
    print(int(n/2))
    exit(0)

ans1=0
if len(L1) != 1:
    L1_1=sorted([cnt for cnt in L1.values()],reverse=True)
    L1_1.pop(0)
    ans1=sum(L1_1)

ans2=0
if len(L2) != 1:
    L2_1=sorted([cnt for cnt in L2.values()],reverse=True)
    L2_1.pop(0)
    ans2=sum(L2_1)
print(ans1+ans2)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n=int(input())
L=list(map(int,input().split()))
ans=0
L1=Counter(L[::2])
L2=Counter(L[1::2])
if len(L)==1:
    print(n/2)
    exit(0)

ans1=0
if len(L1) != 1:
    L1_1=sorted([cnt for cnt in L1.values()],reverse=True)
    L1_1.pop(0)
    ans1=sum(L1_1)

ans2=0
if len(L2) != 1:
    L2_1=sorted([cnt for cnt in L2.values()],reverse=True)
    L2_1.pop(0)
    ans2=sum(L2_1)
print(ans1+ans2)

Submission status: Wrong Answer

Solution code:
n = int(input())
v = [int(i) for i in input().split()]
con_odd = [0]*(10**5+1)
con_even = [0]*(10**5+1)
for i in range(0,n,2):
    con_odd[v[i]] +=1
    con_even[v[i+1]] +=1

max_1 = []
max_2 = []
max_sc_1 = 0
max_sc_2 = 0
max_sc_1_2 = 0
max_sc_2_2 = 0
for i in range(len(con_odd)):
    if con_odd[i] > max_sc_1:
        max_1 = []
        max_1.append(i)
        max_sc_1_2 = max_sc_1
        max_sc_1 = con_odd[i]
    elif con_odd[i] ==  max_sc_1:
        max_1.append(i)
    if con_even[i] > max_sc_2:
        max_2 = []
        max_2.append(i)
        max_sc_2_2 = max_sc_2
        max_sc_2 = con_even[i]
    elif con_even[i] ==  max_sc_2:
        max_2.append(i)

if len(max_2) > 1 or len(max_1) > 1:
    ans_1 = sum(con_odd) - max_sc_1
    ans_2 = sum(con_even) - max_sc_2
    ans = ans_1 + ans_2
    
elif len(max_2) == 1 and len(max_1) == 1  and max_2[0] == max_1[0]:
    if max_sc_1 + max_sc_2_2 > max_sc_2 + max_sc_1_2:
        ans_1 = sum(con_odd) - max_sc_1
        ans_2 = sum(con_even) - max_sc_2_2
        ans = ans_1 + ans_2
    else:
        ans_1 = sum(con_odd) - max_sc_1_2
        ans_2 = sum(con_even) - max_sc_2
        ans = ans_1 + ans_2
else:
    ans_1 = sum(con_odd) - max_sc_1
    ans_2 = sum(con_even) - max_sc_2
    ans = ans_1 + ans_2

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
v = [int(i) for i in input().split()]
con_odd = [0]*(10**5+1)
con_even = [0]*(10**5+1)
for i in range(0,n,2):
    con_odd[v[i]] +=1
    con_even[v[i+1]] +=1

max_1 = []
max_2 = []
max_sc_1 = 0
max_sc_2 = 0
max_sc_1_2 = 0
max_sc_2_2 = 0
for i in range(len(con_odd)):
    if con_odd[i] > max_sc_1:
        max_1 = []
        max_1.append(i)
        max_sc_1_2 = max_sc_1
        max_sc_1 = con_odd[i]
    elif con_odd[i] ==  max_sc_1:
        max_sc_1_2 = max_sc_1
        max_1.append(i)
    if con_even[i] > max_sc_2:
        max_2 = []
        max_2.append(i)
        max_sc_2_2 = max_sc_2
        max_sc_2 = con_even[i]
    elif con_even[i] ==  max_sc_2:
        max_sc_2_2 = max_sc_2
        max_2.append(i)

if len(max_2) > 1 or len(max_1) > 1:
    ans_1 = sum(con_odd) - max_sc_1
    ans_2 = sum(con_even) - max_sc_2
    ans = ans_1 + ans_2
    
elif len(max_2) == 1 and len(max_1) == 1  and max_2[0] == max_1[0]:
    if max_sc_1 > max_sc_2:
        ans_1 = sum(con_odd) - max_sc_1
        ans_2 = sum(con_even) - max_sc_2_2
        ans = ans_1 + ans_2
    else:
        ans_1 = sum(con_odd) - max_sc_1_2
        ans_2 = sum(con_even) - max_sc_2
        ans = ans_1 + ans_2
else:
    ans_1 = sum(con_odd) - max_sc_1
    ans_2 = sum(con_even) - max_sc_2
    ans = ans_1 + ans_2

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
v = [int(i) for i in input().split()]
con_odd = [0]*(10**5+1)
con_even = [0]*(10**5+1)
for i in range(0,n,2):
    con_odd[v[i]] +=1
    con_even[v[i+1]] +=1

max_1 = []
max_2 = []
max_sc_1 = 0
max_sc_2 = 0
max_sc_1_2 = 0
max_sc_2_2 = 0
for i in range(len(con_odd)):
    if con_odd[i] > max_sc_1:
        max_1 = []
        max_1.append(i)
        max_sc_1_2 = max_sc_1
        max_sc_1 = con_odd[i]
    elif con_odd[i] ==  max_sc_1:
        max_1.append(i)
    if con_even[i] > max_sc_2:
        max_2 = []
        max_2.append(i)
        max_sc_2_2 = max_sc_2
        max_sc_2 = con_even[i]
    elif con_even[i] ==  max_sc_2:
        max_2.append(i)

if len(max_2) > 1 or len(max_1) > 1:
    ans_1 = sum(con_odd) - max_sc_1
    ans_2 = sum(con_even) - max_sc_2
    ans = ans_1 + ans_2
    
elif len(max_2) == 1 and len(max_1) == 1  and max_2[0] == max_1[0]:
    if max_sc_1 > max_sc_2:
        ans_1 = sum(con_odd) - max_sc_1
        ans_2 = sum(con_even) - max_sc_2_2
        ans = ans_1 + ans_2
    else:
        ans_1 = sum(con_odd) - max_sc_1_2
        ans_2 = sum(con_even) - max_sc_2
        ans = ans_1 + ans_2
else:
    ans_1 = sum(con_odd) - max_sc_1
    ans_2 = sum(con_even) - max_sc_2
    ans = ans_1 + ans_2

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
v = [int(i) for i in input().split()]
con_odd = [0]*(10**5+1)
con_even = [0]*(10**5+1)
for i in range(0,n,2):
    con_odd[v[i]] +=1
    con_even[v[i+1]] +=1

max_1 = []
max_2 = []
max_sc_1 = 0
max_sc_2 = 0
max_sc_1_2 = 0
max_sc_2_2 = 0
for i in range(len(con_odd)):
    if con_odd[i] > max_sc_1:
        max_1 = []
        max_1.append(i)
        max_sc_1_2 = max_sc_1
        max_sc_1 = con_odd[i]
    elif con_odd[i] ==  max_sc_1:
        max_1.append(i)
    if con_even[i] > max_sc_2:
        max_2 = []
        max_2.append(i)
        max_sc_2_2 = max_sc_2
        max_sc_2 = con_even[i]
    elif con_even[i] ==  max_sc_2:
        max_2.append(i)

if len(max_2) > 1 or len(max_1) > 1:
    ans_1 = sum(con_odd) - max_sc_1
    ans_2 = sum(con_even) - max_sc_2
    ans = ans_1 + ans_2
    
elif max_2[0] == max_1[0]:
    if max_sc_1 > max_sc_2:
        ans_1 = sum(con_odd) - max_sc_1
        ans_2 = sum(con_even) - max_sc_2_2
        ans = ans_1 + ans_2
    else:
        ans_1 = sum(con_odd) - max_sc_1_2
        ans_2 = sum(con_even) - max_sc_2
        ans = ans_1 + ans_2
else:
    ans_1 = sum(con_odd) - max_sc_1
    ans_2 = sum(con_even) - max_sc_2
    ans = ans_1 + ans_2

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
odd = []
even = []
for i in range(n):
    if i%2:
        odd.append(a[i])
    else:
        even.append(a[i])

odd.sort()
even.sort()

odd_counter = [[odd[0], 1]]
even_counter = [[even[0], 1]]

for i in range(len(odd)-1):
    if odd[i] != odd[i+1]:
        odd_counter.append([odd[i+1], 1])
    else:
        odd_counter[-1][1] += 1

for i in range(len(even)-1):
    if even[i] != even[i+1]:
        even_counter.append([even[i+1], 1])
    else:
        even_counter[-1][1] += 1

odd_counter.sort(reverse=True, key= lambda x:x[1])
even_counter.sort(reverse=True, key= lambda x:x[1])
if odd_counter[0][1] != even_counter[0][1]:
    if odd_counter[0][1] < even_counter[0][1]:
        if even_counter[0][0] == odd_counter[0][0]:
            if 1 < len(odd_counter):
                print((len(even)-even_counter[0][1])+(len(odd)-odd_counter[1][1]))
            else:
                print((len(even)-even_counter[0][1])+len(odd))
        else:
            print((len(even)-even_counter[0][1])+(len(odd)-odd_counter[0][1]))
    else:
        if even_counter[0][0] == odd_counter[0][0]:
            if 1 < len(even_counter):
                print((len(even)-even_counter[1][1])+(len(odd)-odd_counter[0][1]))
            else:
                print(len(even) + (len(odd) - odd_counter[0][1]))
        else:
            print((len(even)-even_counter[0][1])+(len(odd)-odd_counter[0][1]))
else:
    if even_counter[0][0] == odd_counter[0][0]:
        if 1 < len(odd_counter) and 1 == len(even_counter):
            print(len(odd)-odd_counter[1][1])
        elif 1 == len(odd_counter) and 1 < len(even_counter):
            print(len(even)-even_counter[1][1])
        elif 1 == len(odd_counter) and 1 == len(even_counter):
            print(len(odd))
        else:
            if odd_counter[1][1] < even_counter[1][1]:
                print(len(even) + (len(odd)-odd_counter[1][1]))
            else:
                print((len(even)-even_counter[1][1]) + len(odd))
    else:
        if even_counter[0][1] < odd_counter[0][1]:
            print(len(even)-even_counter[0][1])
        else:
            print(len(odd)-odd_counter[0][1])

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
odd = []
even = []
for i in range(n):
    if i%2:
        odd.append(a[i])
    else:
        even.append(a[i])

odd.sort()
even.sort()

odd_counter = [[odd[0], 1]]
even_counter = [[even[0], 1]]

for i in range(len(odd)-1):
    if odd[i] != odd[i+1]:
        odd_counter.append([odd[i+1], 1])
    else:
        odd_counter[-1][1] += 1

for i in range(len(even)-1):
    if even[i] != even[i+1]:
        even_counter.append([even[i+1], 1])
    else:
        even_counter[-1][1] += 1

odd_counter.sort(reverse=True, key= lambda x:x[1])
even_counter.sort(reverse=True, key= lambda x:x[1])

if odd_counter[0][1] < even_counter[0][1]:
    if even_counter[0][0] == odd_counter[0][0]:
        if 1 < len(odd_counter):
            print((len(even)-even_counter[0][1])+(len(odd)-odd_counter[1][1]))
        else:
            print((len(even)-even_counter[0][1])+len(odd))
    else:
        print((len(even)-even_counter[0][1])+(len(odd)-odd_counter[0][1]))
else:
    if even_counter[0][0] == odd_counter[0][0]:
        if 1 < len(even_counter):
            print((len(even)-even_counter[1][1])+(len(odd)-odd_counter[0][1]))
        else:
            print(len(even) + (len(odd) - odd_counter[0][1]))
    else:
        print((len(even)-even_counter[0][1])+(len(odd)-odd_counter[0][1]))

Submission status: Wrong Answer

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

ans = 0

eve = V[0::2]
odd = V[1::2]

cntEve = collections.Counter(eve)
cntOdd = collections.Counter(odd)

if cntEve.most_common()[0][1] < cntOdd.most_common()[0][1]:
    if len(eve) == cntEve.most_common()[0][1] and len(odd) == cntOdd.most_common()[0][1] and cntEve.most_common()[0][0] == cntOdd.most_common()[0][0]: 
        ans += len(eve)
    else:
        if len(eve) != cntEve.most_common()[0][1]:
            karians1 = 0
            karians2 = 0
            if cntEve.most_common()[0][0] == cntOdd.most_common()[0][0]:
                karians1 += len(eve) - cntEve.most_common()[1][1]
                if len(odd) != cntOdd.most_common()[0][1]:
                    karians1 += len(odd) - cntOdd.most_common()[0][1]
                karians2 += len(eve) - cntEve.most_common()[0][1]
                if len(odd) != cntOdd.most_common()[0][1]:
                    karians2 += len(odd) - cntOdd.most_common()[1][1]
                ans += min(karians1,karians2)
            else:
                karians1 += len(eve) - cntEve.most_common()[1][1]
                if len(odd) != cntOdd.most_common()[0][1]:
                    karians1 += len(odd) - cntOdd.most_common()[0][1]
                karians2 += len(eve) - cntEve.most_common()[0][1]
                if len(odd) != cntOdd.most_common()[0][1]:
                    karians2 += len(odd) - cntOdd.most_common()[1][1]

                ans += min(karians1,karians2)
else:
    if len(eve) == cntEve.most_common()[0][1] and len(odd) == cntOdd.most_common()[0][1] and cntEve.most_common()[0][0] == cntOdd.most_common()[0][0]: 
        ans += len(eve)
    else:
        if len(odd) != cntOdd.most_common()[0][1]:
            karians1 = 0
            karians2 = 0
            if cntOdd.most_common()[0][0] == cntEve.most_common()[0][0]:
                karians1 += len(odd) - cntOdd.most_common()[1][1]
                if len(eve) != cntEve.most_common()[0][1]:
                    karians1 += len(eve) - cntEve.most_common()[0][1]
                karians2 += len(odd) - cntOdd.most_common()[0][1]
                if len(eve) != cntEve.most_common()[0][1]:
                    karians2 += len(eve) - cntEve.most_common()[1][1]
                ans += min(karians1,karians2)
            else:
                karians1 += len(odd) - cntOdd.most_common()[0][1]
                if len(eve) != cntEve.most_common()[0][1]:
                    karians1 += len(eve) - cntEve.most_common()[1][1]
                karians2 += len(odd) - cntOdd.most_common()[1][1]
                if len(eve) != cntEve.most_common()[0][1]:
                    karians2 += len(eve) - cntEve.most_common()[0][1]
                ans += min(karians1,karians2)
print(ans)

Submission status: Wrong Answer

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

ans = 0

eve = V[0::2]
odd = V[1::2]

cntEve = collections.Counter(eve)
cntOdd = collections.Counter(odd)

if cntEve.most_common()[0][1] < cntOdd.most_common()[0][1]:
    if len(eve) == cntEve.most_common()[0][1] and len(odd) == cntOdd.most_common()[0][1] and cntEve.most_common()[0][0] == cntOdd.most_common()[0][0]: 
        ans += len(eve)
    else:
        if len(eve) != cntEve.most_common()[0][1]:
            if cntEve.most_common()[0][0] == cntOdd.most_common()[0][0]:
                ans += len(eve) - cntEve.most_common()[1][1]
                if len(odd) != cntOdd.most_common()[0][1]:
                    ans += len(odd) - cntOdd.most_common()[0][1]
            else:
                ans += len(eve) - cntEve.most_common()[0][1]
                if len(odd) != cntOdd.most_common()[0][1]:
                    ans += len(odd) - cntOdd.most_common()[0][1]
else:
    if len(eve) == cntEve.most_common()[0][1] and len(odd) == cntOdd.most_common()[0][1] and cntEve.most_common()[0][0] == cntOdd.most_common()[0][0]: 
        ans += len(eve)
    else:
        if len(odd) != cntOdd.most_common()[0][1]:
            if cntOdd.most_common()[0][0] == cntEve.most_common()[0][0]:
                ans += len(odd) - cntOdd.most_common()[1][1]
                if len(eve) != cntEve.most_common()[0][1]:
                    ans += len(eve) - cntEve.most_common()[0][1]
            else:
                ans += len(odd) - cntOdd.most_common()[0][1]
                if len(eve) != cntEve.most_common()[0][1]:
                    ans += len(eve) - cntEve.most_common()[0][1]
print(ans)

Submission status: Wrong Answer

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

ans = 0

eve = V[0::2]
odd = V[1::2]

cntEve = collections.Counter(eve)
cntOdd = collections.Counter(odd)

if cntEve.most_common()[0][1] < cntOdd.most_common()[0][1]:
    if len(eve) == cntEve.most_common()[0][1] and len(odd) == cntOdd.most_common()[0][1] and cntEve.most_common()[0][0] == cntOdd.most_common()[0][0]: 
        ans += len(eve)
    else:
        if len(eve) != cntEve.most_common()[0][1]:
            if cntEve.most_common()[0][0] == cntOdd.most_common()[0][0]:
                ans += len(eve) - cntEve.most_common()[1][1]
                if len(odd) != cntOdd.most_common()[0][1]:
                    ans += len(odd) - cntOdd.most_common()[0][1]
            else:
                ans += len(eve) - cntEve.most_common()[0][1]
                if len(odd) != cntOdd.most_common()[0][1]:
                    ans += len(odd) - cntOdd.most_common()[1][1]
else:
    if len(eve) == cntEve.most_common()[0][1] and len(odd) == cntOdd.most_common()[0][1] and cntEve.most_common()[0][0] == cntOdd.most_common()[0][0]: 
        ans += len(eve)
    else:
        if len(odd) != cntOdd.most_common()[0][1]:
            if cntOdd.most_common()[0][0] == cntEve.most_common()[0][0]:
                ans += len(odd) - cntOdd.most_common()[1][1]
                if len(eve) != cntEve.most_common()[0][1]:
                    ans += len(eve) - cntEve.most_common()[0][1]
            else:
                ans += len(odd) - cntOdd.most_common()[0][1]
                if len(eve) != cntEve.most_common()[0][1]:
                    ans += len(eve) - cntEve.most_common()[1][1]
print(ans)

Submission status: Wrong Answer

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

ans = 0

eve = V[0::2]
odd = V[1::2]

cntEve = collections.Counter(eve)
cntOdd = collections.Counter(odd)

if cntEve.most_common()[0][1] < cntOdd.most_common()[0][1]:
    if len(eve) == cntEve.most_common()[0][1] and len(odd) == cntOdd.most_common()[0][1] and cntEve.most_common()[0][0] == cntOdd.most_common()[0][0]: 
        ans += len(eve)
    else:
        if len(eve) != cntEve.most_common()[0][1]:
            if cntEve.most_common()[0][0] == cntOdd.most_common()[0][0]:
                ans += len(eve) - cntEve.most_common()[1][1]
            else:
                ans += len(eve) - cntEve.most_common()[0][1]
        if len(odd) != cntOdd.most_common()[0][1]:
            ans += len(odd) - cntOdd.most_common()[1][1]
else:
    if len(eve) == cntEve.most_common()[0][1] and len(odd) == cntOdd.most_common()[0][1] and cntEve.most_common()[0][0] == cntOdd.most_common()[0][0]: 
        ans += len(eve)
    else:
        if len(odd) != cntOdd.most_common()[0][1]:
            if cntOdd.most_common()[0][0] == cntEve.most_common()[0][0]:
                ans += len(odd) - cntOdd.most_common()[1][1]
            else:
                ans += len(odd) - cntOdd.most_common()[0][1]
        if len(eve) != cntEve.most_common()[0][1]:
            ans += len(eve) - cntEve.most_common()[1][1]

print(ans)

Submission status: Wrong Answer

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

ans = 0

eve = V[0::2]
odd = V[1::2]

cntEve = collections.Counter(eve)
cntOdd = collections.Counter(odd)

if cntEve.most_common()[0][1] < cntOdd.most_common()[0][1]:
    if len(eve) != cntEve.most_common()[0][1]:
        if cntEve.most_common()[0][0] == cntOdd.most_common()[0][0]:
            ans += len(eve) - cntEve.most_common()[1][1]
        else:
            ans += len(eve) - cntEve.most_common()[0][1]
    if len(odd) != cntOdd.most_common()[0][1]:
        ans += len(odd) - cntOdd.most_common()[1][1]
else:
    if len(odd) != cntOdd.most_common()[0][1]:
        if cntOdd.most_common()[0][0] == cntEve.most_common()[0][0]:
            ans += len(odd) - cntOdd.most_common()[1][1]
        else:
            ans += len(odd) - cntOdd.most_common()[0][1]
    if len(eve) != cntEve.most_common()[0][1]:
        ans += len(eve) - cntEve.most_common()[1][1]
    if len(eve) == cntEve.most_common()[0][1] and len(odd) == cntOdd.most_common()[0][1]: 
        ans += len(eve)

print(ans)

Submission status: Wrong Answer

Solution code:
import sys, bisect, math, itertools, string, queue, copy
#import numpy as np
#import scipy
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations
from heapq import heappop, heappush
from fractions import gcd
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

n = inp()
a = inpl()

cnt_even = defaultdict(int)
cnt_odd = defaultdict(int)
for i in range(0,n,2):
  cnt_even[a[i]] += 1
for i in range(1,n,2):
  cnt_odd[a[i]] += 1

cnt_even = list(reversed(sorted(cnt_even.items(),key=lambda x:x[1])))
cnt_odd  = list(reversed(sorted(cnt_odd.items(),key=lambda x:x[1])))

ans = n
flg = False
for i in range(min(len(cnt_even),len(cnt_odd))):
  a,b = (cnt_even[i],cnt_odd[i])
  if a[0] != b[0]:
    if flg == False:
      n -= a[1]+b[1]
    else:
      n -= max(a[1],b[1])
    break
  else:
    n -= a[1]
    flg = True

print(n)