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:
import collections
n=int(input())
v=list(map(int,input().split()))
c1=collections.Counter(v[::2])
c2=collections.Counter(v[1::2])
c1_v1=c1.most_common()[0][0]
c2_v1=c2.most_common()[0][0]
c1_n1=c1.most_common()[0][1]
c2_n1=c2.most_common()[0][1]

if c1_v1!=c2_v1:
    print(n-c1_n1-c2_n1)
else:
    if c1_n1==n//2:
        if c2_n1==n//2:
            print(n//2)
        else:
            c2_n2=c2.most_common(2)[1][1]
            print(n-c1_n1-c2_n2)
    else:
        c1_n2=c1.most_common(2)[1][1]
        if c2_n1==n//2:
            print(n-c1_n2-c2_n1)
        else:
            c2_n2=c2.most_common(2)[1][1]
            print(max(n-c1_n2-c2_n1,n-c1_n1-c2_n2))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
#from math import gcd
import bisect
from collections import defaultdict
from collections import deque
from functools import lru_cache


#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')

#############
# Functions #
#############

######INPUT######
def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]

######OUTPUT######
def P(arg): print(arg); return
def Y(): print("Yes"); return
def N(): print("No"); return
def E(): exit()
def PE(arg): print(arg); exit()
def YE(): print("Yes"); exit()
def NE(): print("No"); exit()

#####Shorten#####
def DD(arg): return defaultdict(arg)


#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0: 
        cnt+=1 
        temp //= i
      arr.append([i, cnt])
  if temp!=1:
    arr.append([temp, 1])
  if arr==[]:
    arr.append([n, 1])
  return arr

#####MakeDivisors######
def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  return divisors

#####GCD#####
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#####BitCount#####
def count_bit(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count

#####ChangeBase#####
def base_10_to_n(X, n):
  if X//n:
    return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i])*n**i for i in range(len(str(X))))

#####IntLog#####
def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count

#############
# Main Code #
#############

N = I()
n = N//2
l = IL()

l1 = l[::2]
l2 = l[1::2]

dic1 = DD(int)
dic2 = DD(int)

for x in l1:
  dic1[x] += 1
for x in l2:
  dic2[x] += 1
  
l1 = list(dic1.items())
l2 = list(dic2.items())

l1.sort()
l2.sort()

l1_1st = l1.pop()
l2_1st = l2.pop()
l1_2nd = l2_2nd = (INF,0)
if l1:
  l1_2nd = l1.pop()
if l2:
  l2_2nd = l2.pop()
  
if l1_1st[0] != l2_1st[0]:
  print(N-l1_1st[1]-l2_1st[1])
else:
  if l1_2nd[1]>l2_2nd[1]:
    print(N-l1_2nd[1]-l2_1st[1])
  else:
    print(N-l1_1st[1]-l2_2nd[1])

Submission status: Wrong Answer

Solution code:
import collections
n=int(input())
v=list(map(str,input().split()))
for i in range(n-1):
    if v[i]==v[i+1]:
        print(n//2)
        break
#print(v)
else:
    v_zero=[]
    v_one=[]
    for i in range(n):
        if i % 2 == 0 :
            v_zero.append(v[i])
        else:
            v_one.append(v[i])

    c_zero=collections.Counter(v_zero)
    c_one=collections.Counter(v_one)
    ans_zero=0
    ans_one=0
#print('c_zero',c_zero)
#print('c_one',c_one)
#print('c_zero.items()',c_zero.items())
#print('c_one.items()',c_one.items())
#print('a',c_zero.most_common()[0][1])
#print('b',c_zero.most_common()[1][1])
#print('c',c_one.most_common()[0][1])
#print('d',c_one.most_common()[1][1])
    ans_zero=n//2-c_zero.most_common()[0][1]
    ans_one=n//2-c_one.most_common()[0][1]
    print(ans_zero+ans_one)

Submission status: Wrong Answer

Solution code:
import collections
n=int(input())
v=list(map(str,input().split()))
#v=list(input())
c=collections.Counter(v)
for i in range(n-1):
    if v[i]==v[i+1]:
        print(n//2)
        break

else:

#print(c)
#print(c.items())
#print(c.most_common()[0])
#print(c.most_common()[1])
#print(v.index(c.most_common()[0][0]))
#print(v.index(c.most_common()[1][0]))  
    if v.index(c.most_common()[0][0]) %2==0 and v.index(c.most_common()[1][0]) %2 !=0:
        print(len(v)-(c.most_common()[0][1] + c.most_common()[1][1]))
        #print("3",len(v),(c.most_common()[0][1]),(c.most_common()[1][1]))
    elif v.index(c.most_common()[0][0]) %2!=0 and v.index(c.most_common()[1][0]) %2 ==0:
        print(len(v)-(c.most_common()[0][1] + c.most_common()[1][1]))

Submission status: Wrong Answer

Solution code:
n=int(input())
v=list(map(int,input().split()))
cnt=0
for i in range(n-2):
    if v[i]!= v[i+2] or v[i] == v[i+1]:
        cnt +=1
print(cnt)

Submission status: Wrong Answer

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


def solve(n: int, v: "List[int]"):
    from collections import Counter
    a = sorted(Counter(v[::2]).items(), key=lambda x: (x[1], x[0]))
    b = sorted(Counter(v[1::2]).items(), key=lambda x: (x[1], x[0]))
    if a[-1][0] != b[-1][0]:
        return n - a[-1][1] - b[-1][1]
    if a[-1][1] < b[-1][1]:
        a, b = b, a
    return n - a[-1][1] - ([(0,0)]+b)[-2][1]



# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    n = int(next(tokens))  # type: int
    v = [int(next(tokens)) for _ in range(n)]  # type: "List[int]"
    print(solve(n, v))

def test():
    import doctest
    doctest.testmod()

if __name__ == '__main__':
    #test()
    main()

Submission status: Wrong Answer

Solution code:
from collections import Counter

n = int(input())
v = [int(x) for x in input().split()]
v1 = Counter( v[::2])
v2 = Counter(v[1::2])
ev = max(v1.values())
od = max(v2.values())
max_v1 = max(v1, key=v1.get)
max_v2 = max(v2, key=v2.get)


if max_v1 != max_v2:
    ans = n - od - ev 
elif len(v1.values()) > 1 and len(v2.values()) > 1:
    if max(ev, od) == od:
        ans = n - (od+sorted(v1.keys(), reverse=True)[1])
    elif max(ev, od) == ev:
        ans = n - (ev+sorted(v2.keys(), reverse=True)[1])
elif len(v1.values()) == 1 and len(v2.values()) > 1:
    ans = n - max(od, ev + sorted(v1.keys(), reverse=True)[1])
elif len(v2.values()) == 1 and len(v1.values()) > 1:
    ans = n - max(ev, od + sorted(v2.keys(), reverse=True)[1])
else:
    ans = max(od, ev)
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
v=list(map(int,input().split()))
temp1=[]
temp2=[]
for i in range(0,n):
  if i%2==0:
    temp1.append(v[i])
  else:
    temp2.append(v[i])
count=0
from collections import Counter
c1=Counter(temp1)
values1,counts1=zip(*c1.most_common())
counts1=list(counts1)
mode1=counts1[0]
if len(counts1)>1:
  mode1s=counts1[1]
c2=Counter(temp2)
values2,counts2=zip(*c2.most_common())
counts2=list(counts2)
mode2=counts2[0]
if len(counts2)>1:
  mode2s=counts2[1]
if len(counts1)==1 and len(counts2)==1 and c1.most_common()[0][0]==c2.most_common()[0][0]:
  count=min(mode1,mode2)
elif c1.most_common()[0][0]==c2.most_common()[0][0]:
  if mode1s>=mode2s:
    count=len(temp1)-mode1s
  else:
    count=len(temp2)-mode2s
else:
  count=len(temp1)-mode1+len(temp2)-mode2
print(count)

Submission status: Wrong Answer

Solution code:
n=int(input())
v=list(map(int,input().split()))
temp1=[]
temp2=[]
for i in range(0,n):
  if i%2==0:
    temp1.append(v[i])
  else:
    temp2.append(v[i])
count=0
from collections import Counter
c1=Counter(temp1)
mode1=c1.most_common()[0][1]
c2=Counter(temp2)
mode2=c2.most_common()[0][1]
if len(temp1)==mode1 and len(temp2)==mode2 and c1.most_common()[0][0]==c2.most_common()[0][0]:
  count=mode1
else:
  count=len(temp1)-mode1+len(temp2)-mode2
print(count)

Submission status: Wrong Answer

Solution code:
n=int(input())
v=list(map(int,input().split()))
temp1=[]
temp2=[]
for i in range(0,n):
  if i%2==0:
    temp1.append(v[i])
  else:
    temp2.append(v[i])
count=0
from collections import Counter
c1=Counter(temp1)
mode1=c1.most_common()[0][1]
c2=Counter(temp2)
mode2=c2.most_common()[0][1]
if len(temp1)==mode1 and len(temp2)==mode2:
  count=mode1
else:
  count=len(temp1)-mode1+len(temp2)-mode2
print(count)

Submission status: Wrong Answer

Solution code:
n=int(input())
v=list(map(int,input().split()))
temp1=[]
temp2=[]
for i in range(0,n):
  if i%2==0:
    temp1.append(v[i])
  else:
    temp2.append(v[i])
count=0
from collections import Counter
c1=Counter(temp1)
mode1=c1.most_common()[0][1]
c2=Counter(temp2)
mode2=c2.most_common()[0][1]
count=len(temp1)-mode1+len(temp2)-mode2
print(count)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
v = list(map(int, input().split()))
C1 = []
C2 = []
for i in range(n)[::2]:
    C1.append(v[i])
    C2.append(v[i+1])

C1 = Counter(C1).most_common()
C2 = Counter(C2).most_common()

if C1[0][0] != C2[0][0]:
    print(n-C1[0][1]-C2[0][1])
else:
    try:
        ans1 = n-C1[0][1]-C2[1][1]
    except:
        ans1 = 10**6
    try:
        ans2 = n-C1[1][1]-C2[0][1]
    except:
        ans2 = 10**6
    print(min(ans1, ans2))

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
v = list(map(int, input().split()))
C1 = []
C2 = []
for i in range(n)[::2]:
    C1.append(v[i])
    C2.append(v[i+1])

C1 = Counter(C1).most_common()
C2 = Counter(C2).most_common()

if C1[0][0] != C2[0][0]:
    print(n-C1[0][1]-C2[0][1])
elif len(C1) == 1 and len(C2) == 1:
    ans = min(C1[0][0], C2[0][0])
    print(ans)
else:
    ans1 = n-C1[0][1]-C2[1][1]
    ans2 = n-C1[1][1]-C2[0][1]
    print(min(ans1, ans2))

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
v = list(map(int, input().split()))
C1 = []
C2 = []
for i in range(n)[::2]:
    C1.append(v[i])
    C2.append(v[i+1])

C1 = Counter(C1).most_common()
C2 = Counter(C2).most_common()

if C1[0][0] != C2[0][0]:
    print(n-C1[0][1]-C2[0][1])
elif len(C1) == 1 and len(C2) != 1:
    c = min(C2[0][1], C2[1][1])
    ans = min(C1[0][1], c)
    print(ans)
elif len(C1) != 1 and len(C2) == 1:
    c = min(C1[0][1], C1[1][1])
    ans = min(C2[0][1], c)
    print(ans)
elif len(C1) == 1 and len(C2) == 1:
    ans = min(C1[0][0], C2[0][0])
    print(ans)
else:
    ans1 = n-C1[0][1]-C2[1][1]
    ans2 = n-C1[1][1]-C2[0][1]
    print(min(ans1, ans2))

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

if len(set(V)) == 1:
    print(len(V)//2)
    exit()

V_odd = [i for i in V[::2]]
V_even = [i for i in V[1::2]]
V_odd_counter = Counter(V_odd)
V_even_counter = Counter(V_even)
while True:
    if V_odd_counter.most_common()[0][0] != V_even_counter.most_common()[0][0]:
        print(len(V) - V_odd_counter.most_common()[0][1] - V_even_counter.most_common()[0][1])
        exit()
    else:
        if V_odd_counter.most_common()[0][1] >= V_even_counter.most_common()[0][1]:
            s = V_even_counter.most_common()[0][0]
            V_even = [i for i in V_even if i != s ]
            V_even_counter = Counter(V_even)
        else:
            s = V_odd_counter.most_common()[0][0]
            V_odd = [i for i in V_odd if i != s ]
            V_odd_counter = Counter(V_odd)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

if len(set(V)) == 1:
    print(len(V)//2)
    exit()

V_odd = [i for i in V[::2]]
V_even = [i for i in V[1::2]]
V_odd_counter = Counter(V_odd)
V_even_counter = Counter(V_even)
while True:
    if V_odd_counter.most_common()[0][0] != V_even_counter.most_common()[0][0]:
        print(len(V) - V_odd_counter.most_common()[0][1] - V_even_counter.most_common()[0][1])
        exit()
    else:
        if V_odd_counter.most_common()[0][1] >= V_even_counter.most_common()[0][1]:
            V_even.remove(V_even_counter.most_common()[0][0])
            V_even_counter = Counter(V_even)
        else:
            V_odd.remove(V_odd_counter.most_common()[0][0])
            V_odd_counter = Counter(V_odd)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

if len(set(V)) == 1:
    print(len(V)//2)
    exit()

V_odd = [i for i in V[::2]]
V_even = [i for i in V[1::2]]
V_odd_counter = Counter(V_odd)
V_even_counter = Counter(V_even)
while True:
    if V_odd_counter.most_common()[0][0] != V_even_counter.most_common()[0][0]:
        print(len(V) - V_odd_counter.most_common()[0][1] - V_even_counter.most_common()[0][1])
        exit()
    else:
        if V_odd_counter.most_common()[0][1] >= V_even_counter.most_common()[0][1]:
            V_even.remove(V_even_counter.most_common()[0][0])
            V_even_counter = Counter(V_even)

Submission status: Wrong Answer

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

if len(set(v)) == 1:
    print(len(v)//2)
else:
    from collections import Counter
    ve = v[0::2]
    vec = Counter(ve).most_common()
    most_even = vec[0]

    vo = v[1::2]
    voc = Counter(vo).most_common()
    most_odd = voc[0]

    if most_even[0] == most_odd[0]:
        most_odd1 = voc[1]
        most_even1 = vec[1]
        if most_even[1] + most_odd1[1] > most_even1[1] + most_odd[1]:
            most_even = most_even1
        else:
            most_odd = most_odd1

    ans = len(ve) - most_even[1] + len(vo) - most_odd[1]
    print(ans)

Submission status: Wrong Answer

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

if len(set(v)) == 1:
    print(len(v)//2)
else:
    from collections import Counter
    ve = v[0::2]
    vec = Counter(ve).most_common()
    most_even = vec[0]

    vo = v[1::2]
    voc = Counter(vo).most_common()
    most_odd = voc[0]

    if most_even[0] == most_odd[0]:
        if most_even[1] > most_odd[1]:
            # 多い方を固定
            most_odd = voc[1]
        else:
            most_even = vec[1]

    ans = len(ve) - most_even[1] + len(vo) - most_odd[1]
    print(ans)

Submission status: Wrong Answer

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

ki = li[::2]
gu = li[1::2]

ki.sort()
gu.sort()

from itertools import groupby

ki_li = []
gu_li = []

for key, value in groupby(ki):
    ki_li.append((key,len(list(value))))

for key, value in groupby(gu):
    gu_li.append((key,len(list(value))))

ki_li.sort(key=lambda x:(x[1]*(-1)))
gu_li.sort(key=lambda x:(x[1]*(-1)))

if ki_li[0][0] == gu_li[0][0]:
    if ki_li[0][1] >= gu_li[0][1]:
        if len(gu_li) >= 2:
            ans = n-ki_li[0][1]-gu_li[1][1]
        else:
            ans = n-ki_li[0][1]
    else:
        if len(ki_li) >= 2:
            ans = n-gu_li[0][1]-ki_li[1][1]
        else:
            ans = n-gu_li[0][1]
else:
    ans = n-gu_li[0][1]-ki_li[0][1]
        
print(ans)

Submission status: Wrong Answer

Solution code:
from sys import stdin
def main():
    #入力
    readline=stdin.readline
    n=int(readline())
    v=list(map(int,readline().split()))

    cnt1=[0]*(10**5+1)
    cnt2=[0]*(10**5+1)

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

    max1=0
    m=0
    for i in range(1,10**5+1):
        if max1<cnt1[i]:
            max1=cnt1[i]
            m=i
    
    max2=0
    l=0
    for i in range(1,10**5+1):
        if max2<cnt2[i]:
            if i!=m:
                max2=cnt2[i]
                l=i

    print(n-max1-max2)

if __name__=="__main__":
    main()

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
v = list(map(int, input().split()))
l,r = Counter(v[0::2]).most_common(), Counter(v[1::2]).most_common()
l.append((0,0))
r.append((0,0))
if l[0][0] != r[0][0]:
  print(n//2-l[0][1] + n//2-r[0][1])
else:
  if l[0][1] >= r[0][0]:
    print(n//2-l[0][1] + n//2-r[1][1])
  else:
    print(n//2-l[1][1] + n//2-r[0][1])

Submission status: Wrong Answer

Solution code:
# AtCoder Beginner Contest 111
# C - /\/\/\/
# https://atcoder.jp/contests/abc111/tasks/arc103_a
from collections import Counter

N, *A = map(int, open(0).read().split())

ev = Counter(A[0::2])
od = Counter(A[1::2])

ev_m = ev.most_common()[0][1]
od_m = od.most_common()[0][1]
if ev_m == od_m == N//2 and ev[0]==od[0]:
    print(N//2)
else:
    print(N-ev_m-od_m)

Submission status: Wrong Answer

Solution code:
# AtCoder Beginner Contest 111
# C - /\/\/\/
# https://atcoder.jp/contests/abc111/tasks/arc103_a
from collections import Counter

N, *A = map(int, open(0).read().split())

ev = Counter(A[0::2])
od = Counter(A[1::2])

ev_m = ev.most_common()[0][1]
od_m = od.most_common()[0][1]
if ev_m == od_m == N//2:
    print(N//2)
else:
    print(N-ev_m-od_m)

Submission status: Wrong Answer

Solution code:
# AtCoder Beginner Contest 111
# C - /\/\/\/
# https://atcoder.jp/contests/abc111/tasks/arc103_a
from collections import Counter

N, *A = map(int, open(0).read().split())

ev = Counter(A[0::2])
od = Counter(A[1::2])

if ev == od:
    print(N//2)
else:
    print(N-ev.most_common()[0][1]-od.most_common()[0][1])

Submission status: Wrong Answer

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

a = Counter(lis[::2])
b = Counter(lis[1::2])

aa = sorted(a.items(), key=lambda x:x[1], reverse=True)
bb = sorted(b.items(), key=lambda x:x[1], reverse=True)
print(aa)
print(bb)

if aa[0][0] == bb[0][0]:
    if len(aa) > 1 and len(bb) > 1:
        res = n - max(aa[0][1]+bb[1][1], aa[1][1]+bb[0][1])
    elif len(aa) == 1 and len(bb) > 1:
        res = n - aa[0][1] - bb[1][1]
    elif len(aa) > 1 and len(bb) == 1:
        res = n - aa[1][1] - bb[0][1]
    else:
        res = n - aa[0][1]
else:
    res = n - aa[0][1] - bb[0][1]

print(res)

Submission status: Wrong Answer

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

a = Counter(lis[::2])
b = Counter(lis[1::2])

aa = sorted(a.items(), key=lambda x:x[1])
bb = sorted(b.items(), key=lambda x:x[1])


if aa[0][0] == bb[0][0]:
    if len(aa) > 1 and len(bb) > 1:
        res = n - max(aa[0][1]+bb[1][1], aa[1][1]+bb[0][1])
    elif len(aa) == 1 and len(bb) > 1:
        res = n - aa[0][1] - bb[1][1]
    elif len(aa) > 1 and len(bb) == 1:
        res = n - aa[1][1] - bb[0][1]
    else:
        res = n - aa[0][1]
else:
    res = n - aa[0][1] - bb[0][1]

print(res)

Submission status: Wrong Answer

Solution code:
import collections
n=int(input())
a=list(map(int,input().split()))
x=collections.Counter(a)
key,value=zip(*x.most_common())
if len(key)==1:
  print(n//2)
else:
  cnt=0
  for i in range(2, len(key)):
    cnt+=value[i]
  print(cnt)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
b=a[0]
c=a[1]
if b==c:
  print(n//2)
else:
  cnt=0
  for i in range(2, n):
    if i%2==0:
      if a[i]!=b:
        cnt+=1
    else:
      if a[i]!=c:
        cnt+=1
  print(cnt)

Submission status: Wrong Answer

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[2][1]
        if len(odd)-odd2 >= len(even) - even2:
            ans -= even2 + count_odd[0][1]
        else:
            ans -= 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: Wrong Answer

Solution code:
from collections import Counter

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

if len(set(v)) == 1:
    print(n//2)
else:
    ans = 0
    c1 = Counter(v[0::2])
    c2 = Counter(v[1::2])
    
    c1m = c1.most_common(1)[0]
    c2m = c2.most_common(1)[0]
    if c1m[1] < c2m[1]:
        ans += n//2-c2m[1]
        if c1m[0] != c2m[0]:
            ans += n//2-c1m[1]
        else:
            ans += n//2-c1.most_common(2)[1][1]
    else:
        ans += n//2-c1m[1]
        if c1m[0] != c2m[0]:
            ans += n//2-c2m[1]
        else:
            ans += n//2-c2.most_common(2)[1][1]
    print(ans)

Submission status: Wrong Answer

Solution code:
import itertools
import math
import fractions
import functools
import copy

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

kisu = [0]*(10**6)
gusu = [0]*(10**6)
for i in range(n):
    if i % 2 == 0:
        gusu[v[i]] += 1
    else:
        kisu[v[i]] += 1

count = 0 
gusu_m = gusu.index(max(gusu))
kisu_m = kisu.index(max(kisu))

if gusu_m == kisu_m:
    gusu[gusu_m] = 0
    kisu[kisu_m] = 0
    if max(gusu) > max(kisu):
        kisu_m = kisu.index(max(kisu))
    else:
        gusu_m = gusu.index(max(gusu))
        
for i in range(n):
    if i % 2 == 0 and gusu_m != v[i]:
        count += 1
    if i % 2 != 0 and kisu_m != v[i]:
        count += 1

print(count)

Submission status: Wrong Answer

Solution code:
import itertools
import math
import fractions
import functools
import copy

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

kisu = [0]*(10**6)
gusu = [0]*(10**6)
for i in range(n):
    if i % 2 == 0:
        gusu[v[i]] += 1
    else:
        kisu[v[i]] += 1

count = 0 
gusu_m = gusu.index(max(gusu))
kisu_m = kisu.index(max(kisu))
for i in range(n):
    if i % 2 == 0 and gusu_m != v[i]:
        count += 1
    if i % 2 != 0 and kisu_m != v[i]:
        count += 1

print(count)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
v = list(map(int,input().split()))
odd = v[::2 ]
even = v[1::2]
def count(aaa):
    if len(set(aaa))!=1:
        aaa_max = Counter(aaa).most_common(1)[0][1]
        aaa_min = len(aaa)-aaa_max
    else:
        aaa_min = 0
    return int(aaa_min)
if len(set(v))==1:
    print(int(n/2))
else:
    even_min = count(even)
    odd_min = count(odd)
    print(even_min+odd_min)

Submission status: Wrong Answer

Solution code:
import numpy as np
n = int(input())
v = list(map(int,input().split()))
odd = v[::2 ]
even = v[1::2]
def count(aaa):
    if len(set(aaa))!=1:
        aaa = np.array(aaa)
        aaa_min = np.argmax(np.bincount(aaa))
    else:
        aaa_min = 0
    return int(aaa_min)
if len(set(v))==1:
    print(int(n/2))
else:
    even_min = count(even)
    odd_min = count(odd)
    print(even_min+odd_min)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

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

c_odd = Counter(v_odd)
c_even = Counter(v_even)

for k, v in c_odd.items():
    rest_odd = len(v_odd) - v
    break

for k, v in c_even.items():
    rest_even = len(v_even) - v
    break

print(rest_odd + rest_even)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

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

row1 = a[0::2]
row2 = a[1::2]

r1 = defaultdict(int)
r2 = defaultdict(int)

for i in range(n//2):
    r1[row1[i]] += 1
    r2[row2[i]] += 1

r1 = sorted(r1.items(), key=lambda x:x[1])
r2 = sorted(r2.items(), key=lambda x:x[1])

if r1[0][0] == r2[0][0]:
    if len(r1) > 1 and len(r2) > 1:
        num1 = r1[0][1] + r2[1][1]
        num2 = r1[1][1] + r2[0][1]
        print(n - max(num1, num2))
    elif len(r1) == 1 and len(r2) > 1:
        print(n - r1[0][1] - r2[1][1])
    elif len(r1) > 1 and len(r2) == 1:
        print(n - r1[1][1] - r2[0][1])
    else:
        print(n - r1[0][1])
else:
    print(n - r1[0][1] - r2[0][1])

Submission status: Wrong Answer

Solution code:
n = int(input())
v_list = list(map(int,input().split()))
odd = v_list[0::2]
even = v_list[1::2]
import collections
c = collections.Counter(odd)
c = sorted(c.items(),reverse = True)
c.append((0,0))
c_max = c[0][1]
c_max_num = c[0][0]
c_second_max = c[1][1]

d = collections.Counter(even)
d = sorted(d.items(),reverse = True)
d.append((0,0))
d_max = d[0][1]
d_max_num = d[0][0]
d_second_max = d[1][1]

if d_max_num != c_max_num:
  print(len(v_list) - c_max - d_max)
else:
  print(min((len(v_list) - c_second_max - d_max),(len(v_list) - c_max - d_second_max)))

Submission status: Wrong Answer

Solution code:
n = int(input())
v_list = list(map(int,input().split()))
odd = v_list[0::2]
even = v_list[1::2]
import collections
c = collections.Counter(odd)
c = sorted(c.items(),reverse = True)
c.append((0,0))
c_max = c[0][1]
c_max_num = c[0][0]

d = collections.Counter(even)
d = sorted(d.items(),reverse = True)
d_max = d[0][1]
d_max_num = d[0][0]
d.append((0,0))

if d_max_num != c_max_num:
  print(len(v_list) - c_max - d_max)
elif c_max > d_max:
  print(len(v_list) - c_max - d[1][1])
else:
  print(len(v_list) - d_max - c[1][1])

Submission status: Wrong Answer

Solution code:
n = int(input())
v_list = list(map(int,input().split()))
odd = v_list[0::2]
even = v_list[1::2]
import collections
c = collections.Counter(odd)
c = sorted(c.items(),reverse = True)
c.append((0,0))
c_max = c[0][1]
c_max_num = c[0][0]

d = collections.Counter(even)
d = sorted(d.items(),reverse = True)
d_max = d[0][1]
d_max_num = d[0][0]
d.append((0,0))

if d_max_num != c_max_num:
  print(len(v_list) - c_max - d_max)
elif c_max >= d_max:
  print(len(v_list) - c_max - d[1][1])
else:
  print(len(v_list) - d_max - c[1][1])

Submission status: Wrong Answer

Solution code:
n = int(input())
v_list = list(map(int,input().split()))
odd = v_list[0::2]
even = v_list[1::2]
import collections
c = collections.Counter(odd)
c = sorted(c.items(),reverse = True)
c.append((0,0))
c_max = c[0][1]
c_max_num = c[0][0]

d = collections.Counter(even)
d = sorted(d.items(),reverse = True)
d_max = d[0][1]
d_max_num = d[0][0]
d.append((0,0))

if d_max_num != c_max_num:
  print(len(v_list) - c_max - d_max)
elif c_max >= d_max:
  print(len(v_list) - c_max - d[1][0])
else:
  print(len(v_list) - d_max - c[1][0])

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

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

row1 = a[0::2]
row2 = a[1::2]

r1 = defaultdict(int)
r2 = defaultdict(int)

for i in range(n//2):
    r1[row1[i]] += 1
    r2[row2[i]] += 1

r1 = sorted(r1.items(), key=lambda x:x[1])
r2 = sorted(r2.items(), key=lambda x:x[1])

if r1[0][0] == r2[0][0]:
    if len(r1) > 1 and len(r2) > 1:
        num1 = r1[0][1] + r2[1][1]
        num2 = r1[1][1] + r2[0][1]
        print(n - max(num1, num2))
    elif len(r1) == 1 and len(r2) > 1:
        print(n - r1[0][1] - r2[1][1])
    elif len(r1) > 1 and len(r2) == 1:
        print(n - r2[1][1] - r2[0][1])
    else:
        print(n - r1[0][1])
else:
    print(n - r1[0][1] - r2[0][1])

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# hello worldと表示する
#dpでできないかな？
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

n=I()
lis=LI()
ev,od=[],[]
for i in range(n):
    if i%2==0:
        ev.append(lis[i])
    else:
        od.append(lis[i])
c=Counter(ev)
d=Counter(od)
#print(c.most_common()[0][1])
#-c.most_common()[0]-d.most_common()[0]
ans=len(ev)+len(od)-c.most_common()[0][1]-d.most_common()[0][1]
print(ans)