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: Accepted

Solution code:
#C
from collections import Counter
n = int(input())
v = list(map(int,input().split()))
e = []
o = []
for i in range(len(v)):
    if i%2 == 0:
        e.append(v[i])
    else:
        o.append(v[i])
    
c_e = Counter(e)
c_o = Counter(o)

e_m = c_e.most_common()
o_m = c_o.most_common()

result1 = 10**5+1
result2 = 10**5+1
result3 = 10**5+1
r1 = len(e) - e_m[0][1]
r2 = len(o) - o_m[0][1]
result1 = r1 + r2
if o_m[0][0] == e_m[0][0]:
    if len(o_m) > 1:
        result2 = r1 + len(o) - o_m[1][1]
    if len(e_m) > 1:
        result3 = len(e)-e_m[1][1] + r2
    else:
        result2 = len(e)
    print(min(result2,result3))
else:
    print(result1)

Submission status: Accepted

Solution code:
from collections import Counter


def main():
  n, *lst = map(int, open(0).read().split())
  c1, c2 = [(0, 0)] + sorted(Counter(lst[::2]).items(), key=lambda x: x[1]), [(0, 0)] + sorted(Counter(lst[1::2]).items(), key=lambda x: x[1])
  if c1[-1][0] != c2[-1][0]:
    print(n - c1[-1][1] - c2[-1][1])
  else:
    print(n - max(c1[-2][1] + c2[-1][1], c1[-1][1] + c2[-2][1]))


if __name__ == '__main__':
  main()

Submission status: Accepted

Solution code:
from collections import Counter


def main():
  n, *lst = map(int, open(0).read().split())
  c1, c2 = sorted(Counter(lst[::2]).items(), key=lambda x: x[1], reverse=1), sorted(Counter(lst[1::2]).items(), key=lambda x: x[1], reverse=1)
  c1.append((0, 0)), c2.append((0, 0))
  if c1[0][0] != c2[0][0]:
    print(n - c1[0][1] - c2[0][1])
  else:
    print(n - max(c1[1][1] + c2[0][1], c1[0][1] + c2[1][1]))


if __name__ == '__main__':
  main()

Submission status: Accepted

Solution code:
from collections import Counter


def main():
  n = int(input())
  m = map(int, input().split())
  lst1, lst2 = zip(*zip(m, m))
  c1, c2 = sorted(Counter(lst1).items(), key=lambda x: x[1], reverse=1), sorted(Counter(lst2).items(), key=lambda x: x[1], reverse=1)
  c1.append((0, 0)), c2.append((0, 0))
  if c1[0][0] != c2[0][0]:
    print(n - c1[0][1] - c2[0][1])
  else:
    print(n - max(c1[1][1] + c2[0][1], c1[0][1] + c2[1][1]))


if __name__ == '__main__':
  main()

Submission status: Accepted

Solution code:
from collections import Counter
n, *lst = map(int, open(0).read().split())
c1, c2 = [(0, 0)] + sorted(Counter(lst[::2]).items(), key=lambda x: x[1]), [(0, 0)] + sorted(Counter(lst[1::2]).items(), key=lambda x: x[1])
if c1[-1][0] != c2[-1][0]:
  print(n - c1[-1][1] - c2[-1][1])
else:
  print(n - max(c1[-2][1] + c2[-1][1], c1[-1][1] + c2[-2][1]))

Submission status: Accepted

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

odd=[[0,0] for _ in range(10**5+1)]
even=[[0,0] for _ in range(10**5+1)]
ev=0
od=0


for i,v in enumerate(vv):
    if i%2==0:
        ev+=1
        even[v-1][1]=v-1
        even[v-1][0]+=1
    else:
        od+=1
        odd[v-1][1]=v-1
        odd[v-1][0]+=1


even.sort()
odd.sort()

#print(odd)
#print(even)


if even[-1][1]!=odd[-1][1]:
    print(ev-even[-1][0]+od-odd[-1][0])
else:
    print(min(ev-even[-2][0]+od-odd[-1][0],ev-even[-1][0]+od-odd[-2][0]))

Submission status: Accepted

Solution code:

from collections import Counter

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

def f(x, y):
  return n - ( x + y )

v0 = Counter(v[::2])
v1 = Counter(v[1::2])
L = v0.most_common(2)
R = v1.most_common(2)

#print(L, R)

if L[0][0] != R[0][0]:
  print(f(L[0][1], R[0][1]))
elif len(L) > len(R):
  print(f(L[1][1], R[0][1]))
elif len(L) < len(R):
  print(f(L[0][1], R[1][1]))
elif len(L) == 2:
  print(min(f(L[1][1], R[0][1]), f(L[0][1], R[1][1])))
else:
  print(n//2)

Submission status: Accepted

Solution code:
N = int(input())
V =  [int(i) for i in input().split()]
V1 = [V[2*j-2] for j in range(1, N//2+1)]
V2 = [V[2*j-1] for j in range(1, N//2+1)]
#print(V1, V2)

def dict(x):
  D = {}
  for i in x:
    if i in D:
      D[i] += 1
    else:
      D.setdefault(i, 1)
  return D

dictV1 = dict(V1)
dictV2 = dict(V2)
#print(dictV1, dictV2)

sortdictV1 = sorted(dictV1.items(), key=lambda x:x[1], reverse=True)
sortdictV2 = sorted(dictV2.items(), key=lambda x:x[1], reverse=True)
a = 0
if sortdictV1[0][0] != sortdictV2[0][0]:
    a = N - sortdictV1[0][1] - sortdictV2[0][1]
else:
  if len(dictV1) == len(dictV2) == 1:
    a = N // 2
  else:
    if len(dictV1) == 1:
      a = N - sortdictV1[0][1] - sortdictV2[1][1]
    elif len(dictV2) == 1:
      a = N - sortdictV1[1][1] - sortdictV2[0][1]
    else:
      a = min(N - sortdictV1[0][1] - sortdictV2[1][1], N - sortdictV1[1][1] - sortdictV2[0][1])
print(a)

Submission status: Accepted

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

odd_dict = {}
even_dict = {}

for i in range(n):
    k = series[i]
    if i % 2 == 0:
        try:
            even_dict[k] += 1
        except KeyError:
            even_dict[k] = 1 
    else:
        try:
            odd_dict[k] += 1
        except KeyError:
            odd_dict[k] = 1

odd_vals = []
even_vals = []

for key in odd_dict.keys():
    odd_vals.append([odd_dict[key], key])
for key in even_dict.keys():
    even_vals.append([even_dict[key], key])

odd_vals.sort(reverse=True)
even_vals.sort(reverse=True)

# print(odd_vals)
# print(even_vals)

if len(odd_vals) == 1 and len(even_vals) == 1:
    a = odd_vals[0][0]
    b = even_vals[0][0]

    if odd_vals[0][1] != even_vals[0][1]:
        print(n - a - b)
    else:
        print(n // 2)
elif len(odd_vals) > 1 and len(even_vals) > 1:
    if odd_vals[0][1] != even_vals[0][1]:
        print(n - odd_vals[0][0] - even_vals[0][0])
    else:
        a = odd_vals[0][0]
        b = odd_vals[1][0]
        c = even_vals[0][0]
        d = even_vals[1][0]
        print(min(n - a - d, n - b - c))
else:
    a = odd_vals[0][0]
    b = even_vals[0][0]
    c = 0
    if len(odd_vals) == 1:
        c = even_vals[1][0]
    else:
        c = odd_vals[1][0]
    
    if odd_vals[0][1] != even_vals[0][1]:
        print(n - a - b)
    else:
        print(n - a - c)

# print(even_dict)
# print(odd_dict)

Submission status: Accepted

Solution code:
n = int(input())
arr = list(map(int, input().split()))
e = {-1:0}
o = {-1:0}
for i in range(0, n, 2):
    e[arr[i]] = e.get(arr[i], 0) + 1

for i in range(1, n, 2):
    o[arr[i]] = o.get(arr[i], 0) + 1

#print(n - (max(e.values()) + max(o.values())))

ek = 0
ev = 0
for k in e:
    if ek == 0 or e[k] > ev:
        ek = k
        ev = e[k]

ok = 0
ov = 0
for k in o:
    if ok == 0 or o[k] > ov:
        ok = k
        ov = o[k]

if ok != ek:
    print(n-ev-ov)
else:
    del e[ek]
    del o[ok]
    print(n-max(max(e.values()) + ov, max(o.values()) + ev))

Submission status: Accepted

Solution code:
n = int(input())
V = list(map(int,input().split()))
A = []
B = []
for i in range(n):
    if i%2==0:
        A.append(V[i])
    else:
        B.append(V[i])
from collections import Counter
NA = len(A)
NB = len(B)
Ac = dict(Counter(A))
Bc = dict(Counter(B))
Am = max(Ac.values())
Ak = max(Ac, key=Ac.get)
Bm = max(Bc.values())
Bk = max(Bc, key=Bc.get)
if len(Ac.keys())==1 and len(Bc.keys())==1 and A[0]==B[0]:
    print(NB)
else:
    if Ak!=Bk:
        print(NA-Am+NB-Bm)
    else:
        Ac[Ak] = 0
        Bc[Bk] = 0
        Am2 = max(Ac.values())
        Ak2 = max(Ac, key=Ac.get)
        Bm2 = max(Bc.values())
        Bk2 = max(Bc, key=Bc.get)
        print(min(NA-Am2+NB-Bm,NA-Am+NB-Bm2))

Submission status: Accepted

Solution code:
from collections import Counter
from itertools import product

n = int(input())
V = list(map(int, input().split()))
odd = Counter(V[1::2]).most_common()[:2]
even = Counter(V[::2]).most_common()[:2]

if len(odd) == 1:
    odd.append((0, 0))
if len(even) == 1:
    even.append((0, 0))
INF = 10**18
total = -INF
for p in product((1, 0), repeat=2):
    if odd[p[0]][0] == even[p[1]][0]:
        continue
    total = max(total, odd[p[0]][1]+even[p[1]][1])
ans = n - total
print(ans)

Submission status: Accepted

Solution code:

def s0():return input()
def s1():return input().split()
def s2(n):return [input() for x in range(n)]
def s3(n):return [input().split() for _ in range(n)]
def s4(n):return [[x for x in s] for s in s2(n)]
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]
def t3(n):return [tuple(int(x) for x in input().split()) for _ in range(n)]
def p0(b,yes="Yes",no="No"): print(yes if b else no)
# from sys import setrecursionlimit
# setrecursionlimit(1000000)
from collections import Counter,deque,defaultdict
# import itertools
# import math
# import networkx as nx
# from bisect import bisect_left,bisect_right
# from heapq import heapify,heappush,heappop
n=n0()
V=n1()
V0=[V[i] for i in range(n) if i%2==0]
V1=[V[i] for i in range(n) if i%2==1]

c0=list(Counter(V0).items())
c1=list(Counter(V1).items())
c0.sort(key=lambda x:-x[1])
c1.sort(key=lambda x:-x[1])

if c0[0][0]!=c1[0][0]:
    ans=n-c0[0][1]-c1[0][1]
else:
    if len(c0)==1 or len(c1)==1:
        if len(c0)==len(c1)==1:
            ans=n-c0[0][1]
        elif len(c0)==1:
            ans=n-c1[1][1]
        else:
            ans=n-c0[1][1]        
    elif c0[0][1] > c1[0][1]:
        ans=n-c0[0][1]-c1[1][1]
    elif c0[0][1] < c1[0][1]:
        ans=n-c0[1][1]-c1[0][1]
    else:
        if c0[1][1] > c1[1][1]:
            ans=n-c0[1][1]-c1[0][1]
        else:
            ans=n-c0[0][1]-c1[1][1]
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter

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

if len(set(l)) == 1:
  print(N//2)
else:
  l_odd,l_even = [],[]

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

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

  if C_odd[0][0] != C_even[0][0]:
    ans = N - C_odd[0][1] - C_even[0][1]
  else:
    ans = min(N - C_odd[0][1] - C_even[1][1],N - C_odd[1][1] - C_even[0][1])

  print(ans)

Submission status: Accepted

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





# @lru_cache(None)

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

Submission status: Accepted

Solution code:
from collections import Counter

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

if len(set(v)) == 1:
    print(n // 2)
else:
    a = []
    b = []
    for i in range(n):
        if i % 2 == 0:
            a.append(v[i])
        else:
            b.append(v[i])
    c_a = Counter(a).most_common()
    c_b = Counter(b).most_common()

    if c_a[0][0] != c_b[0][0]:
        ans = n - c_a[0][1] - c_b[0][1]
    else:
        ans = min(n - c_a[0][1] - c_b[1][1], n - c_a[1][1] - c_b[0][1])
    
    print(ans)

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import numpy as np

n = int(readline())
kx = np.array(read().split(),np.int32)
k = kx[::2]
x = kx[1::2]

from collections import Counter
c = Counter(k)
c.update({0:0})
d = Counter(x)
d.update({0:0})
if c.most_common()[0] != d.most_common()[0]:
  print(n-c.most_common()[0][1]-d.most_common()[0][1])
else:
  a = max(c.most_common()[0][1]+d.most_common()[1][1],c.most_common()[1][1]+d.most_common()[0][1])
  print(n-a)

Submission status: Accepted

Solution code:
N= int(input())
l=list(map(int,input().split()))
if N == 2:
   if l[0] == l[1]:
      print(1)
      exit()
   else:
      print(0)
      exit()
l1=[l[i] for i in range(N) if i%2==0]
l2=[l[i] for i in range(N) if i%2==1]
import collections
flag=0
l1=collections.Counter(l1).most_common()
l2=collections.Counter(l2).most_common()
if l1[0][0] == l2[0][0]:
   if l1[0][1] == l2[0][1]:
      try:
         ans=N-l1[0][1]-max(l1[1][1],l2[1][1])
      except IndexError:
         ans=N//2
      print(ans)
   elif l1[0][1] > l2[0][1]:
      print(N-l1[0][1]-l2[1][1])
   elif l1[0][1] < l2[0][1]:
      print(N-l1[1][1]-l2[0][1])
else:
   print(N-l1[0][1]-l2[0][1])

Submission status: Accepted

Solution code:
import collections
n = int(input())
a = list(map(int, input().split()))
if len(set(a)) == 1:
    print(n // 2)
else:
    l_a = [a[i] for i in range(0, n, 2)]
    r_a = [a[i] for i in range(1, n, 2)]
    c_l = collections.Counter(l_a).most_common()
    c_r = collections.Counter(r_a).most_common()
    if c_l[0][0] != c_r[0][0]:
        ans = n - c_l[0][1] - c_r[0][1]
    else:
        ans = min(n - c_l[0][1] - c_r[1][1], n - c_l[1][1] - c_r[0][1])
    print(int(ans))

Submission status: Accepted

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

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

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

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

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

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
list_N = list(map(int, input().split()))
list_L = []
list_R = []
for i in range(n):
    if i % 2 == 0:
        list_L.append(list_N[i])
    else:
        list_R.append(list_N[i])

list_L_V = Counter(list_L)
list_R_V = Counter(list_R)

list_L_V = list_L_V.items()
list_R_V = list_R_V.items()

list_L_V = sorted(list_L_V, key=lambda x:x[1], reverse=True)
list_R_V = sorted(list_R_V, key=lambda x:x[1], reverse=True)

list_L_V.append((0, 0))
list_R_V.append((0, 0))

ans = 0
if list_L_V[0][0] != list_R_V[0][0]:
    ans += n - list_L_V[0][1] - list_R_V[0][1]
else:
    ans += min(n - list_L_V[1][1] - list_R_V[0][1], n - list_L_V[0][1] - list_R_V[1][1])

print(ans)

Submission status: Accepted

Solution code:
from collections import Counter

def main():
    N = int(input())
    V = list(map(int, input().split()))
    V1 = []
    V2 = []
    for i in range(0,len(V),2):
        V1.append(V[i])
    for i in range(1,len(V),2):
        V2.append(V[i])  
    VC1 = Counter(V1)
    VC2 = Counter(V2)
    count = 0

    VC1mosc = VC1.most_common()[0][0]
    VC1mosv = VC1.most_common()[0][1]
    VC2mosc = VC2.most_common()[0][0]
    VC2mosv = VC2.most_common()[0][1]

    count += len(V1) - VC1mosv
    count += len(V2) - VC2mosv

    if VC1mosc  == VC2mosc and len(VC1)==1:
        count += VC1mosv
    elif  VC1mosc  == VC2mosc:
        vc1sa = VC1mosv - VC1.most_common()[1][1]
        vc2sa = VC2mosv - VC2.most_common()[1][1]
        count += min([vc1sa,vc2sa])


    print(count)




if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n, v = int(input()), list(map(int, input().split()))
from collections import Counter
import math
a = Counter(v[::2])
b = Counter(v[1::2])
a[-1] = 0
b[-1] = 0
a = list(a.items())
b = list(b.items())
a.sort(reverse=True, key=lambda x:x[1])
b.sort(reverse=True, key=lambda x:x[1])
if a[0][0] == b[0][0]:
    result = n - max(a[0][1] + b[1][1],
                     a[1][1] + b[0][1])
else:
    result = n - a[0][1] - b[0][1]
print(result)

Submission status: Accepted

Solution code:
import collections

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

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

def count_strange(arr):
    c = collections.Counter(arr)
    keys, vals = zip(*c.most_common())
    return keys, vals

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

Submission status: Accepted

Solution code:
import collections

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

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

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

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

Submission status: Accepted

Solution code:
from collections import Counter

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

even = [v[i] for i in range(n) if i % 2 == 0]
odd = [v[i] for i in range(n) if i % 2 == 1]
ecnt = Counter(even).most_common() + [(0, 0)]
ocnt = Counter(odd).most_common() + [(0, 0)]

if ecnt[0][0] == ocnt[0][0]:
    print(n - max(ecnt[0][1] + ocnt[1][1], ecnt[1][1] + ocnt[0][1]))
else:
    print(n - ecnt[0][1] - ocnt[0][1])

Submission status: Accepted

Solution code:
from collections import Counter

n = int(input())
v = list(map(int, input().split()))
even = [v[i] for i in range(n) if i % 2 == 0]
odd = [v[i] for i in range(n) if i % 2 == 1]

ecnt = Counter(even).most_common() + [(0, 0)]
ocnt = Counter(odd).most_common() + [(0, 0)]
if ecnt[0][0] == ocnt[0][0]:
    print(n - max(ecnt[0][1] + ocnt[1][1], ecnt[1][1] + ocnt[0][1]))
else:
    print(n - ecnt[0][1] - ocnt[0][1])

Submission status: Accepted

Solution code:
from collections import Counter

n = int(input())
v = list(map(int, input().split()))
even = [v[i] for i in range(n) if i % 2 == 0]
odd = [v[i] for i in range(n) if i % 2 == 1]

ecnt = Counter(even).most_common() + [(0, 0)]
ocnt = Counter(odd).most_common() + [(0, 0)]
if ecnt[0][0] == ocnt[0][0]:
    print(min(len(even) - ecnt[0][1] + len(odd) - ocnt[1][1],
              len(even) - ecnt[1][1] + len(odd) - ocnt[0][1]))
else:
    print(len(even) - ecnt[0][1] + len(odd) - ocnt[0][1])

Submission status: Accepted

Solution code:
from collections import defaultdict

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

result=0

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

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


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

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

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

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

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

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

print(int(result))

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
vn = list(map(int, input().split()))
odd = []
even = []
for i in range(n):
    if i % 2 == 0:
        even.append(vn[i])
    else:
        odd.append(vn[i])
ans = len(even) + len(odd)
count_odd = Counter(odd).most_common()
count_even = Counter(even).most_common()
if count_odd[0][0] == count_even[0][0]:
    if len(set(even)) != 1 and len(set(odd)) != 1:
        even2 = count_even[1][1]
        odd2 = count_odd[1][1]
        ans -= max(even2 + count_odd[0][1], odd2 + count_even[0][1])
    elif len(set(even)) != 1 and len(set(odd)) == 1:
        ans -= count_odd[0][1] + count_even[1][1]
    elif len(set(even)) == 1 and len(set(odd)) != 1:
        ans -= count_even[0][1] + count_odd[1][1]
    else:
        ans -= max(count_even[0][1], count_odd[0][1])
else:
    ans -= count_odd[0][1] + count_even[0][1]
print(ans)

Submission status: Accepted

Solution code:

from collections import Counter

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

X = Counter(V[::2]).most_common(2)
Y = Counter(V[1::2]).most_common(2)

if X[0][0] != Y[0][0]:
    print(n - X[0][1] - Y[0][1])
else:
    x = 0 if len(X) < 2 else X[1][1]
    y = 0 if len(Y) < 2 else Y[1][1]
    if X[0][1] + y > x + Y[0][1]:
        print(n - X[0][1] - y)
    else:
        print(n - x - Y[0][1])

Submission status: Accepted

Solution code:
from collections import Counter
N = int(input())
v = list(map(int, input().split()))
v_odd = v[0::2]
v_even = v[1::2]
cnt_o = Counter(v_odd).most_common()
cnt_e = Counter(v_even).most_common()
if cnt_o[0][0] != cnt_e[0][0]:
    print(N - cnt_o[0][1] - cnt_e[0][1])
else:
    if len(cnt_o) == 1 and len(cnt_e) == 1:
        print(N // 2)
    elif len(cnt_o) == 1:
        print(len(v_even) - cnt_e[1][1])
    elif len(cnt_e) == 1:
        print(len(v_odd) - cnt_o[1][1])
    else:
        print(min(N - cnt_o[1][1] - cnt_e[0][1], N - cnt_o[0][1] - cnt_e[1][1]))

Submission status: Accepted

Solution code:
from collections import Counter

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

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

C = Counter(A)
D = Counter(B)

E = C.most_common()
F = D.most_common()

E += [(-1,0)]
F += [(-1,0)]

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

Submission status: Accepted

Solution code:
import collections

sequence_num=int(input())
count=0
even_sequence_list=[]
odd_sequence_list=[]
sequence_list=list(map(int,input().split()))
for i in range(sequence_num):
	if i%2 == 0:
		even_sequence_list.append(sequence_list[i])
	else:
		odd_sequence_list.append(sequence_list[i])
even_mode=collections.Counter(even_sequence_list).most_common()[0][0]
odd_mode=collections.Counter(odd_sequence_list).most_common()[0][0]
if even_mode != odd_mode:
	for i in even_sequence_list:
		if i != even_mode:
			count+=1
	for j in odd_sequence_list:
		if j != odd_mode:
			count+=1
	print(count)
else:
	even_counter=collections.Counter(even_sequence_list)
	odd_counter=collections.Counter(odd_sequence_list)
	if len(even_counter.keys()) == 1 and len(odd_counter.keys()) == 1:
		even_mode=0
		for i in even_sequence_list:
			if i != even_mode:
				count+=1
		for j in odd_sequence_list:
			if j != odd_mode:
				count+=1
		print(count)
	elif len(even_counter.keys()) != 1 and len(odd_counter.keys()) == 1:
		even_mode=collections.Counter(even_sequence_list).most_common()[1][0]
		for i in even_sequence_list:
			if i != even_mode:
				count+=1
		for j in odd_sequence_list:
			if j != odd_mode:
				count+=1
		print(count)
	elif len(even_counter.keys()) == 1 and len(odd_counter.keys()) != 1:
		odd_mode=collections.Counter(odd_sequence_list).most_common()[1][0]
		for i in even_sequence_list:
			if i != even_mode:
				count+=1
		for j in odd_sequence_list:
			if j != odd_mode:
				count+=1
		print(count)
	else:
		even_2_mode=collections.Counter(even_sequence_list).most_common()[1][0]
		odd_2_mode=collections.Counter(odd_sequence_list).most_common()[1][0]
		even_change_count=0
		odd_change_count=0
		for i in even_sequence_list:
			if i != even_2_mode:
				even_change_count+=1
		for j in odd_sequence_list:
			if j != odd_mode:
				even_change_count+=1
		for i in even_sequence_list:
			if i != even_mode:
				odd_change_count+=1
		for j in odd_sequence_list:
			if j != odd_2_mode:
				odd_change_count+=1
		if even_change_count < odd_change_count:
			print(even_change_count)
		else:
			print(odd_change_count)

Submission status: Accepted

Solution code:
def main():
    n=int(input())
    v=list(map(int,input().split()))
    l1=[0]*(10**5+1)
    l2=[0]*(10**5+1)
    for i,vn in enumerate(v):
        if i%2==0:
            l1[vn]+=1
        else:
            l2[vn]+=1
    f1,f2,s1,s2,m1,m2=0,0,0,0,0,0
    for i,ln in enumerate(l1):
        s1=max(s1,min(ln,f1))
        if f1<ln:
            m1=i
        f1=max(f1,ln)
    for i,ln in enumerate(l2):
        s2=max(s2,min(ln,f2))
        if f2<ln:
            m2=i
        f2=max(f2,ln)
    if m1==m2:
        print(min(n-f1-s2,n-f2-s1))
    else:
        print(n-f1-f2)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def ma():
  return map(int,input().split())

def main():
  from collections import Counter
  N=int(input())
  A=list(ma())
  evens = Counter(A[::2])
  odds = Counter(A[1::2])
  evens[0]=0 #この部分は文字列が小さい時に必要
  odds[0]=0 #
  
  e1, e2=evens.most_common(2) #上位２つを実際の数字をⅠ番目に、出てきた回数を２こめ
  o1, o2=odds.most_common(2) #
  
  if e1[0]!=o1[0]:
    print(N - (e1[1] + o1[1]))
  else: 
    print(N - max(e1[1]+o2[1], e2[1]+o1[1]))
  
if __name__ == '__main__':
  main()

Submission status: Accepted

Solution code:
from collections import Counter

def count(a):
    c = Counter(a)
    return len(a) - c.most_common(1)[0][1]

n = int(input())
s = list(map(int, input().split()))
s1 = s[::2]
s2 = s[1::2]
if(count(s) == 0):
    print(len(s) // 2)
else:
    a = Counter(s1).most_common(2)
    b = Counter(s2).most_common(2)
    if(len(a) == 1):
        a.append((-1, 0))
    if(len(b) == 1):
        b.append((-2, 0))
    way1 = a[0][1] + b[0][1] if a[0][0] != b[0][0] else -100
    way2 = a[0][1] + b[1][1] if a[0][0] != b[1][0] else -100
    way3 = a[1][1] + b[0][1] if a[1][0] != b[0][0] else -100
    ans = n - max(way1, way2, way3)
    print(ans)

Submission status: Accepted

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

v_even =v[0::2] 
v_odd = v[1::2]

c_v = collections.Counter(v)
c_even = collections.Counter(v_even)
c_odd = collections.Counter(v_odd)

c_even_s = sorted(c_even.items(), key=lambda x:x[1], reverse=True)
c_odd_s = sorted(c_odd.items(), key=lambda x:x[1], reverse=True)

if(len(c_v) != 1):
    if(c_even_s[0][0] != c_odd_s[0][0]):
        print(n//2-c_even_s[0][1]+n//2-c_odd_s[0][1])
    else:
        if(c_even_s[0][1] > c_odd_s[0][1]):
            ans = n//2-c_even_s[0][1]+n//2-c_odd_s[1][1]
        elif(c_even_s[0][1] == c_odd_s[0][1]):
            ans = min(n//2-c_even_s[0][1]+n//2-c_odd_s[1][1], n//2-c_even_s[1][1]+n//2-c_odd_s[0][1])
        else:
            ans = n//2-c_odd_s[0][1] + n//2-c_even_s[1][1]
        print(ans)
else:
    print(n//2)

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    A = [int(i) for i in input().split()]
    A_odd = A[1::2]
    A_even = A[0::2]
    dict_odd = {-1:0}
    dict_even = {-1:0}
    for i in A_odd :
        if i not in dict_odd :
            dict_odd[i] = 1
        else:
            dict_odd[i] += 1
    for i in A_even :
        if i not in dict_even :
            dict_even[i] = 1
        else:
            dict_even[i] += 1
    dict_odd  = sorted(dict_odd.items(), key = lambda x : x[1],reverse=True)
    dict_even = sorted(dict_even.items(), key=lambda x: x[1], reverse=True)

    if dict_even[0][0] != dict_odd[0][0] :
        max_odd = dict_odd[0][1]
        max_even = dict_even[0][1]
        print(N - max_even - max_odd)
    else:
        if dict_odd[0][1] > dict_even[0][1]:
            max_odd = dict_odd[0][1]
            max_even = dict_even[1][1]
            print(N - max_even - max_odd)
        elif dict_even[0][1] > dict_odd[0][1] :
            max_odd = dict_odd[1][1]
            max_even = dict_even[0][1]
            print(N - max_even - max_odd)
        else:
            max_odd = max(dict_even[1][1],dict_odd[1][1])
            print(N - dict_even[0][1] - max_odd)
            
            


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from collections import Counter

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

cnt1 = Counter(v[::2]).most_common()
cnt2 = Counter(v[1::2]).most_common()
cnt1 += [(-1,0)]
cnt2 += [(-1,0)]
if cnt1[0][0] != cnt2[0][0]:
    print(n - (cnt1[0][1] + cnt2[0][1]))
else:
    print(n - max(cnt1[1][1] + cnt2[0][1], cnt1[0][1] + cnt2[1][1]))

Submission status: Accepted

Solution code:
from collections import Counter

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

X = Counter(V[::2]).most_common(2)
Y = Counter(V[1::2]).most_common(2)

if X[0][0] != Y[0][0]:
    print(n - X[0][1] - Y[0][1])
else:
    x = 0 if len(X) < 2 else X[1][1]
    y = 0 if len(Y) < 2 else Y[1][1]
    if X[0][1] + y > x + Y[0][1]:
        print(n - X[0][1] - y)
    else:
        print(n - x - Y[0][1])