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

c = collections.Counter

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

even_v = [v[i] for i in range(n) if i % 2 == 0]
odd_v = [v[i] for i in range(n) if i % 2 == 1]

c1 = c(even_v).most_common(2)
c2 = c(odd_v).most_common(2)


def calc(x, y):
    return len(even_v) - x[1] + len(odd_v) - y[1]


def main():
    if c1[0] != c2[0]:
        return calc(c1[0], c2[0])

    if len(c1) == 1 and len(c2) == 1:
        return len(odd_v)

    if c1[0] + c2[1] > c1[1] + c2[0]:
        return calc(c1[0], c2[1])
    else:
        return calc(c1[1], c2[0])


print(main())

Submission status: Wrong Answer

Solution code:
from collections import Counter

N = int(input())
V = input().split()
a = V[::2]
b = V[1::2]
h = int(N / 2)
ac = Counter(a)
bc = Counter(b)
ma = ac.most_common()
mb = bc.most_common()
if ma[0][0] == mb[0][0]:
  if len(ma) == len(mb) == 1:
    ans = h
  elif len(ma) == 1:
    ans = h - mb[1][1]
  elif len(mb) == 1:
    ans = h - ma[1][1]
  else:
    ans = min(2 * h - ma[0][1] - mb[1][1], h - mb[0][1] - ma[1][1])
else:
  ans = 2 * h - ma[0][1] - mb[0][1]
print(ans)

Submission status: Wrong Answer

Solution code:
# 2019/05/14
# AtCoder Beginner Contest 111 - C

from operator import itemgetter

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

l_even = list()
l_odd = list()

# Separate Odd or Even
for i in range(n):
    if i % 2 == 0:
        l_even.append(v[i])
    else:
        l_odd.append(v[i])

l_even.sort()
l_odd.sort()
wk_cnt_e = 1
wk_cnt_o = 1

cnt_even = list()
cnt_odd = list()

# Count
for x in range(int(n/2)-1):
    if l_even[x] != l_even[x+1]:
        cnt_even.append([l_even[x], wk_cnt_e])
        wk_cnt_e = 1
    else:
        wk_cnt_e += 1

    if l_odd[x] != l_odd[x+1]:
        cnt_odd.append([l_odd[x], wk_cnt_o])
        wk_cnt_o = 1
    else:
        wk_cnt_o += 1

cnt_even.append([l_even[x+1], wk_cnt_e])
cnt_odd.append([l_odd[x+1], wk_cnt_o])

cnt_even.sort(key=itemgetter(1),reverse=True)
cnt_odd.sort(key=itemgetter(1),reverse=True)

if len(cnt_even) == 1 and len(cnt_odd) == 1 and cnt_even[0][0] == cnt_odd[0][0]:
    ans = n / 2
elif len(cnt_even) == 1 and cnt_even[0][0] == cnt_odd[0][0]:
    ans = n / 2 - cnt_odd[0][1]
elif len(cnt_odd) == 1 and cnt_even[0][0] == cnt_odd[0][0]:
    ans = n / 2 - cnt_even[0][1]
elif cnt_even[0][0] == cnt_odd[0][0]:
    ans = n / 2 - min(cnt_even[0][1], cnt_odd[0][1])
else:
    ans = (n / 2 - cnt_even[0][1]) + (n / 2 - cnt_odd[0][1])
 
# Output
print(int(ans))

Submission status: Wrong Answer

Solution code:
# 2019/05/14
# AtCoder Beginner Contest 111 - C

from operator import itemgetter

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

l_even = list()
l_odd = list()

# Separate Odd or Even
for i in range(n):
    if i % 2 == 0:
        l_even.append(v[i])
    else:
        l_odd.append(v[i])

l_even.sort()
l_odd.sort()
wk_cnt_e = 1
wk_cnt_o = 1

cnt_even = list()
cnt_odd = list()

# Count
for x in range(int(n/2)-1):
    if l_even[x] != l_even[x+1]:
        cnt_even.append([l_even[x], wk_cnt_e])
        wk_cnt_e = 1
    else:
        wk_cnt_e += 1

    if l_odd[x] != l_odd[x+1]:
        cnt_odd.append([l_odd[x], wk_cnt_o])
        wk_cnt_o = 1
    else:
        wk_cnt_o += 1

cnt_even.append([l_even[x+1], wk_cnt_e])
cnt_odd.append([l_odd[x+1], wk_cnt_o])

cnt_even.sort(key=itemgetter(1))
cnt_odd.sort(key=itemgetter(1))

if len(cnt_even) == 1 and len(cnt_odd) == 1 and cnt_even[0][0] == cnt_odd[0][0]:
    ans = n / 2
elif len(cnt_even) == 1 and cnt_even[0][0] == cnt_odd[0][0]:
    ans = n / 2 - cnt_odd[0][1]
elif len(cnt_odd) == 1 and cnt_even[0][0] == cnt_odd[0][0]:
    ans = n / 2 - cnt_even[0][1]
elif cnt_even[0][0] == cnt_odd[0][0]:
    ans = n / 2 - min(cnt_even[0][1], cnt_odd[0][1])
else:
    ans = (n / 2 - cnt_even[0][1]) + (n / 2 - cnt_odd[0][1])
 
# Output
print(int(ans))

Submission status: Wrong Answer

Solution code:
# 2019/05/15
# AtCoder Beginner Contest 111 - C

from operator import itemgetter

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

l_even = list()
l_odd = list()

# Separate Odd or Even
for i in range(n):
    if i % 2 == 0:
        l_even.append(v[i])
    else:
        l_odd.append(v[i])

l_even.sort()
l_odd.sort()
wk_cnt_e = 1
wk_cnt_o = 1

cnt_even = list()
cnt_odd = list()

# Count
for x in range(int(n/2)-1):
    if l_even[x] != l_even[x+1]:
        cnt_even.append([l_even[x], wk_cnt_e])
        wk_cnt_e = 1
    else:
        wk_cnt_e += 1

    if l_odd[x] != l_odd[x+1]:
        cnt_odd.append([l_odd[x], wk_cnt_o])
        wk_cnt_o = 1
    else:
        wk_cnt_o += 1

cnt_even.append([l_even[x+1], wk_cnt_e])
cnt_odd.append([l_odd[x+1], wk_cnt_o])

cnt_even.sort(key=itemgetter(1))
cnt_odd.sort(key=itemgetter(1))

if len(cnt_even) == 1 and len(cnt_odd) == 1 and cnt_even[0][0] == cnt_odd[0][0]:
    ans = n / 2
elif len(cnt_even) == 1 and cnt_even[0][0] == cnt_odd[0][0]:
    ans = n / 2 - cnt_odd[0][1]
elif len(cnt_odd) == 1 and cnt_even[0][0] == cnt_odd[0][0]:
    ans = n / 2 - cnt_even[0][1]
elif cnt_even[0][0] == cnt_odd[0][0]:
    ans = n / 2 - min(cnt_even[0][1], cnt_odd[0][1])
else:
    ans = (n / 2 - cnt_even[0][1]) + (n / 2 - cnt_odd[0][1])
 
print(cnt_even, cnt_odd)
# Output
print(int(ans))

Submission status: Wrong Answer

Solution code:
n=int(input())
arr=list(map(int,input().split()))
cnt1=[0]*(10**5+1)
cnt2=[0]*(10**5+1)
for i in range(n):
  if i%2==0:
    cnt1[arr[i]]+=1
  else:
    cnt2[arr[i]]+=1
m1=max(cnt1)
m2=max(cnt2)
p1=cnt1.index(m1)
p2=cnt2.index(m2)
cnt1=sorted(cnt1,reverse=True)
cnt2=sorted(cnt2,reverse=True)
if n==2:
  if arr[0]!=arr[1]:
    print(0)
  else:
    print(1)
else:
  if p1==p2:
    if m1>m2:
      m2=cnt2[1]
    else:
      m1=cnt1[1]
  ans=n-m1-m2
  print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
arr=list(map(int,input().split()))
cnt1=[0]*(10**5+1)
cnt2=[0]*(10**5+1)
for i in range(n):
  if i%2==0:
    cnt1[arr[i]]+=1
  else:
    cnt2[arr[i]]+=1
m1=max(cnt1)
m2=max(cnt2)
p1=cnt1.index(m1)
p2=cnt2.index(m2)
cnt1=sorted(cnt1,reverse=True)
cnt2=sorted(cnt2,reverse=True)
if n==2:
  if arr[0]!=arr[1]:
    print(0)
  else:
    print(1)
else:
  if p1==p2:
    if m1>m2:
      m2=cnt2[1]
    else:
      m1=cnt1[1]
  ans=(n-m1)+(n-m2)
  print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
v=list(input().split())
v1=v[0:n:2]
v2=v[1:n:2]
import collections
c1=collections.Counter(v1)
a1=c1.most_common()[0][0]
a2=(c1.most_common()[1][0] if len(c1)>=2 else 0)
c2=collections.Counter(v2)
b1=c2.most_common()[0][0]
b2=(c2.most_common()[1][0] if len(c2)>=2 else 0)
if a1!=b1:
    cou=0
    for i in range(n//2):
        if v1[i]!=a1:
            v1[i]=a1
            cou+=1
    for i in range(n//2):
        if v2[i]!=b1:
            v2[i]=b1
            cou+=1
    print(cou)
else:
    cou1=0
    for i in range(n//2):
        if v1[i]!=a2:
            v1[i]=a2
            cou1+=1
    for i in range(n//2):
        if v2[i]!=b1:
            v2[i]=b1
            cou1+=1
    cou2=0
    for i in range(n//2):
        if v1[i]!=a1:
            v1[i]=a1
            cou2+=1
    for i in range(n//2):
        if v2[i]!=b2:
            v2[i]=b2
            cou2+=1
    print(min(cou1,cou2))

Submission status: Wrong Answer

Solution code:
n=int(input())
v=list(input().split())
v1=v[0:n:2]
v2=v[1:n:2]
import collections
c1=collections.Counter(v1)
a1=c1.most_common()[0][0]
a2=(c1.most_common()[1][0] if len(c1)>=2 else 0)
c2=collections.Counter(v2)
b1=c2.most_common()[0][0]
b2=(c2.most_common()[1][0] if len(c2)>=2 else 0)
if a1!=b1:
    cou=0
    for i in range(n//2):
        if v1[i]!=a1:
            v1[i]=a1
            cou+=1
    for i in range(n//2):
        if v2[i]!=b1:
            v2[i]=b1
            cou+=1
    print(cou)
else:
    cou1=0
    for i in range(n//2):
        if v1[i]!=a2:
            v1[i]=a2
            cou1+=1
    for i in range(n//2):
        if v2[i]!=b1:
            v2[i]=b1
            cou1+=1
    cou2=0
    for i in range(n//2):
        if v1[i]!=a2:
            v1[i]=a2
            cou2+=1
    for i in range(n//2):
        if v2[i]!=b2:
            v2[i]=b2
            cou2+=1
    print(min(cou1,cou2))

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    num_seq = list(map(int, input().split()))
    ans = 0
    for i in range(2, N):
        if num_seq[i-2] != num_seq[i]:
            ans += 1
        elif num_seq.count(num_seq[i-2]) == len(num_seq):
            ans += 2
            break;
    print(ans)
main()

Submission status: Wrong Answer

Solution code:
import collections
n= int(input())
v = list(map(int,input().split()))
num1 = []
num2 = []
counts =[0,0]
for i in range(len(v)):
    if i % 2 == 0:
        num1.append(v[i])
    else:
        num2.append(v[i])

n1 = collections.Counter(num1).most_common()[0][0]
n2 = collections.Counter(num2).most_common()[0][0]

for i in range(len(num2)):
    if n1 != num1[i]:
        counts[0] += 1

    if n2 != num2[i]:
        counts[1] += 1

if (n1 == n2) and sum(num2) == sum(num1):
    print(len(num1))
else:
    print(sum(counts))

Submission status: Wrong Answer

Solution code:
import collections

n = int(input())
v = list(map(int, input().split()))
odd, even = [], []

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

    
codd = collections.Counter(odd)
ceven = collections.Counter(even)
mostodd = codd.most_common()[0]
mosteven = ceven.most_common()[0]

if mostodd[0] != mosteven[0]:
  ans = n - mostodd[1] - mosteven[1]
else:
  if mostodd[1] >= mosteven[1]:
    if len(ceven.most_common()) > 1:
      even2nd = ceven.most_common()[1][1]
    else:
      even2nd = 0
    ans = n - mostodd[1] - even2nd
  else:
    if len(codd.most_common()) > 1:
      odd2nd = codd.most_common()[1][1]
    else:
      odd2nd = 0
    ans = n - odd2nd - mosteven[1] 
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter


def m():
    N = int(input())
    V = [int(i) for i in input().split()]
    vodds = V[0::2]
    vevens = V[1::2]

    odds_commons = Counter(vodds).most_common()
    even_commons = Counter(vevens).most_common()

    odds_top = odds_commons[0]
    evens_top = even_commons[0]
    if odds_top[0] != evens_top[0]:
        return N - odds_top[1] - evens_top[1]
    else:
        if len(odds_commons) > 1 and len(even_commons) > 1:
            return N // 2 - max(odds_commons[1][1], even_commons[1][1])
        elif len(odds_commons) > 1:
            return N // 2 - odds_commons[1][1]
        elif len(even_commons) > 1:
            return N // 2 - even_commons[1][1]
        else:
            return N // 2


print(m())

Submission status: Wrong Answer

Solution code:
from collections import Counter


def m():
    N = int(input())
    V = [int(i) for i in input().split()]
    vodds = V[0::2]
    vevens = V[1::2]

    odds_commons = Counter(vodds).most_common()
    even_commons = Counter(vevens).most_common()

    odds_top = odds_commons[0]
    evens_top = odds_commons[0]
    if odds_top[0] != evens_top[0]:
        return N - odds_top[1] - evens_top[1]
    else:
        if len(odds_commons) > 1 and len(even_commons) > 1:
            return N // 2 - max(odds_commons[1][1], even_commons[1][1])
        elif len(odds_commons) > 1:
            return N // 2 - odds_commons[1][1]
        elif len(even_commons) > 1:
            return N // 2 - even_commons[1][1]
        else:
            return N // 2


print(m())

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Fri May 10 23:15:55 2019

@author: Yamazaki Kenichi
"""

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

T = [[0 for i in range(10**5+1)], [0 for i in range(10**5+1)]]
counta = 0
for c in A:
    T[counta%2][c] += 1
    counta += 1

tmp = [[0]*4, [0]*4]
for i in range(10**5+1):
    for k in range(2):
        if T[k][i] > tmp[k][0]:
            tmp[k][2], tmp[k][3] = tmp[k][0], tmp[k][1]
            tmp[k][0], tmp[k][1] = T[k][i], i
        elif T[k][i] > tmp[k][2]:
            tmp[k][2], tmp[k][1] = T[k][i], i
if tmp[0][1] != tmp[1][1]:
    print(n-tmp[0][0]-tmp[1][0])
else:
    print(min(n-tmp[0][0]-tmp[1][2], n-tmp[0][2]-tmp[1][0]))

Submission status: Wrong Answer

Solution code:
import collections
n=int(input())
v=[int(i) for i in input().split()]
A=[]
B=[]
for i in range(n//2):
    A.append(v[2*i])
    B.append(v[2*i+1])
    
a=collections.Counter(A)
b=collections.Counter(B)
aa=a.most_common()
bb=b.most_common()


if len(a)==len(b)==1 and aa[0][0]!=bb[0][0]:
    print(0)
elif len(a)==len(b)==1 and aa[0][0]==bb[0][0]:
    print(n//2)
else:
    if aa[0][0]!=bb[0][0]:
        count=n-aa[0][1]-bb[0][1]
        print(count)
    elif aa[0][1]>=bb[0][1]:
        count=n-aa[0][1]-bb[1][1]
        print(count)
    else:
        count=n-aa[1][1]-bb[0][1]
        print(count)

Submission status: Wrong Answer

Solution code:
import collections
n=int(input())
v=[int(i) for i in input().split()]
A=[]
B=[]
for i in range(n//2):
    A.append(v[2*i])
    B.append(v[2*i+1])
    
a=collections.Counter(A)
b=collections.Counter(B)
aa=a.most_common()
bb=b.most_common()


if len(a)==len(b)==1 and aa[0][0]!=bb[0][0]:
    print(0)
elif len(a)==len(b)==1 and aa[0][0]==bb[0][0]:
    print(n//2)
else:
    if aa[0][0]!=bb[0][0]:
        count=n-aa[0][1]-bb[0][1]
        print(count)
    elif aa[0][1]>=bb[1][1]:
        count=n-aa[0][1]-bb[1][1]
        print(count)
    else:
        count=n-aa[1][1]-bb[0][1]
        print(count)

Submission status: Wrong Answer

Solution code:
import collections
n=int(input())
v=[int(i) for i in input().split()]
A=[]
B=[]
for i in range(n//2):
    A.append(v[2*i])
    B.append(v[2*i+1])
    
a=collections.Counter(A)
b=collections.Counter(B)
aa=a.most_common()
bb=b.most_common()


if len(a)==len(b)==1 and aa[0][0]!=bb[0][0]:
    print(0)
elif len(a)==len(b)==1 and aa[0][0]==bb[0][0]:
    print(n//2)
else:
    if aa[0][0]!=bb[0][0]:
        count=n-aa[0][1]-bb[0][1]
        print(count)
    elif aa[0][1]>=bb[1][1]:
        count=n-aa[0][1]-bb[1][1]
        print(count)
    else:
        count=n-aa[1][1]-bb[0][1]

Submission status: Wrong Answer

Solution code:
n=int(input())
v=[int(i) for i in input().split()]
A=[]
B=[]
for i in range(n//2):
    A.append(v[2*i])
    B.append(v[2*i+1])
    
a=set(A.copy())
b=set(B.copy())

if len(a)==len(b)==1 and a!=b:
    print(0)
elif len(a)==len(b)==1 and a==b:
    print(n//2)
else:
    print(len(a)+len(b)-2)

Submission status: Wrong Answer

Solution code:
n = int(input())
v = list(map(int, input().split()))
count = 0
odd_kind = list(set(v[1::2]))
even_kind = list(set(v[::2]))
odd_max = 0
even_max = 0
odd_suf = 0
odd_second_suf = 0
even_suf = 0
even_second_suf = 0

for i in range(len(odd_kind)):
    if v[1::2].count(odd_kind[i]) > odd_max:
        odd_max = v[1::2].count(odd_kind[i])
        odd_second_suf = odd_suf
        odd_suf = i
for i in range(len(even_kind)):
    if v[::2].count(even_kind[i]) > even_max:
        even_max = v[::2].count(even_kind[i])
        even_second_suf = even_suf
        even_suf = i
if odd_kind[odd_suf] != even_kind[even_suf]:
    print(n - v[1::2].count(odd_kind[odd_suf]) - v[::2].count(even_kind[even_suf]))
else:
    if v[1::2].count(odd_kind[odd_suf]) < v[::2].count(even_kind[even_suf]) :
        print(n - v[1::2].count(odd_kind[odd_suf]) -v[::2].count(even_kind[even_second_suf]))
    elif v[1::2].count(odd_kind[odd_suf]) > v[::2].count(even_kind[even_suf]):
        print(n - v[1::2].count(odd_kind[odd_second_suf]) -v[::2].count(even_kind[even_suf]))
    else:
        print(n//2)

Submission status: Wrong Answer

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

dic1, dic2 = dict(), dict()
#dic1[0] = 0
#dic2[0] = 0
for i, x in enumerate(lst):
    dic = dic1 if  i%2 == 0 else dic2
    if x not in dic.keys():
        dic[x] = 1
    else:
        dic[x] += 1
#print (type(dic1))
dic1 =sorted(dic1.items(), key = lambda x:x[1])[::-1]
dic2 =sorted(dic2.items(), key = lambda x:x[1])[::-1]

#print (type(dic2))
#print (dic1)
#print (dic2)

if dic1[0][0] != dic2[0][0]:
    print (N-dic1[0][1]-dic2[0][1])
elif len(dic1) == 1 and len(dic2) == 1:
    print (N//2)
elif len(dic1) == 1:
    print (N-dic1[0][1]-dic2[1][1])
elif len(dic2) == 1:
    print (N-dic1[1][1]-dic2[0][1])
else:
    print (max(N-dic1[0][1]-dic2[1][1], N-dic1[1][1]-dic2[0][1]))

Submission status: Wrong Answer

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

dic1, dic2 = dict(), dict()
dic1[0] = 0
dic2[0] = 0
for i, x in enumerate(lst):
    dic = dic1 if  i%2 == 0 else dic2
    if x not in dic.keys():
        dic[x] = 1
    else:
        dic[x] += 1
#print (type(dic1))
dic1 =sorted(dic1.items(), key = lambda x:x[1])[::-1]
dic2 =sorted(dic2.items(), key = lambda x:x[1])[::-1]

#print (type(dic2))
#print (dic1)
#print (dic2)

if dic1[0][0] != dic2[0][0]:
    print (N-dic1[0][1]-dic2[0][1])
else:
    print (max(N-dic1[0][1]-dic2[1][1], N-dic1[1][1]-dic2[0][1]))

Submission status: Wrong Answer

Solution code:
n=int(input())
v=input().split()
o=[("0",0)]
e=[("0",0)]
for i in range(n//2):
    I=2*i
    O=len(o)
    E=len(e)
    for j in range(O):
        if v[I]==o[j][0]:
            o[j]=(o[j][0],o[j][1]+1)
            break
        elif j==O-1:
            o.append((v[I],1))
    for k in range(E):
        if v[I+1]==e[k][0]:
            e[k]=(e[k][0],e[k][1]+1)
            break
        elif k==E-1:
            e.append((v[I+1],1))
o.sort(key=lambda x:-x[1])
e.sort(key=lambda x:-x[1])
if o[0][0]==e[0][0]:
    if o[0][1]<e[0][1]:
        m=e[0][1]+o[1][1]
    else:
        m=o[0][1]+e[1][1]
else:
    m=o[0][1]+e[0][1]
print(n-m)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
dic1,dic2=dict(),dict()
for i,x in enumerate(a):
    dic = dic1 if i%2==0 else dic2
    if x not in dic.keys():
        dic[x]=1
    else:
        dic[x]+=1
dic1=sorted(dic1.items(),key=lambda x:x[1])[::-1]
dic2=sorted(dic2.items(),key=lambda x:x[1])[::-1]

if dic1[0][0]!=dic2[0][0]:
    print(n-dic1[0][1]-dic2[0][1])
elif len(dic1)==1 and len(dic2)==1:
    print(n-max(dic1[0][1],dic2[0][1]))
elif len(dic1)==1:
    print(n-dic1[0][1]-dic2[1][1])
elif len(dic2)==1:
    print(n-dic2[0][1]-dic1[1][1])
else:
    print(n-max(dic1[0][1]-dic2[1][1], n-dic2[0][1]-dic1[1][1]))

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
dic1,dic2=dict(),dict()
for i,x in enumerate(a):
    dic = dic1 if i%2==0 else dic2
    if x not in dic.keys():
        dic[x]=1
    else:
        dic[x]+=1
dic1=sorted(dic1.items(),key=lambda x:x[1])[::-1]
dic2=sorted(dic2.items(),key=lambda x:x[1])[::-1]

if dic1[0][0]!=dic2[0][0]:
    print(n-dic1[0][1]-dic2[0][1])
elif len(dic1)==1 and len(dic2)==1:
    print(n-max(dic1[0][1],dic2[0][1]))
elif len(dic1)==1:
    print(n-dic1[0][1]-dic2[1][1])
elif len(dic2)==1:
    print(n-dic2[0][1]-dic1[1][1])
else:
    print(n-dic1[0][1]-dic2[1][1] if dic1[0][1]>dic2[0][1] else n-dic2[0][1]-dic1[1][1])

Submission status: Wrong Answer

Solution code:
import collections

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

nod = collections.Counter(l[0::2]).most_common()
even = collections.Counter(l[1::2]).most_common()

if len(set(l)) == 1:
    ans = int(n // 2)
else:
    if nod[0][0] == even[0][0]:
        ans = n - max(nod[0][1], nod[1][1], even[0][1], even[1][1])
    else:
        ans = n - nod[0][1] - even[0][1]

print(ans)

Submission status: Wrong Answer

Solution code:
import collections

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

nod = collections.Counter(l[0::2]).most_common()
even = collections.Counter(l[1::2]).most_common()

if len(set(l)) == 1:
    ans = int(n // 2)
elif nod[0][0] == even[0][0]:
    ans = n - max(nod[0][1], nod[1][1], even[0][1], even[1][1]) 
else:
    ans = n - nod[0][1] - even[0][1]

print(ans)

Submission status: Wrong Answer

Solution code:
import collections

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

nod = collections.Counter(l[0::2]).most_common()
even = collections.Counter(l[1::2]).most_common()

if len(set(l)) == 1:
    ans = n // 2
elif nod[0][0] == even[0][0]:
    ans = n - max(nod[0][1], nod[1][1], even[0][1], even[1][1]) 
else:
    ans = n - nod[0][1] - even[0][1]

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
v = list(map(int,input().split()))
v_odd = v[::2]
v_even = v[1::2]
c_odd = Counter(v_odd)
c_even = Counter(v_even)
if c_odd.most_common()[0] == c_even.most_common()[0]:
    ans = len(v) - max(c_odd.most_common()[0][1], c_even.most_common()[0][1])
    if c_odd.most_common()[0][1] >= c_even.most_common()[0][1]:
        if len(c_even.most_common()[1:]) > 0:
            ans -= c_even.most_common()[1][1]
    else:
        if len(c_odd.most_common()[1:]) > 0:
            ans -= c_odd.most_common()[1][1]
else:
    ans = len(v) - c_odd.most_common()[0][1] - c_even.most_common()[0][1]

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
v = list(map(int,input().split()))
v_odd = v[::2]
v_even = v[1::2]
c_odd = Counter(v_odd)
c_even = Counter(v_even)
if c_odd.most_common()[0] == c_even.most_common()[0]:
    ans = len(v) - max(c_odd.most_common()[0][1], c_even.most_common()[0][1])
    if c_odd.most_common()[0][0] >= c_even.most_common()[0][0]:
        if len(c_even.most_common()[1:]) > 0:
            ans -= c_even.most_common()[1][1]
    else:
        if len(c_odd.most_common()[1:]) > 0:
            ans -= c_odd.most_common()[1][1]
else:
    ans = len(v) - c_odd.most_common()[0][1] - c_even.most_common()[0][1]

print(ans)

Submission status: Wrong Answer

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

cnts = [collections.Counter(v[::2]), collections.Counter(v[1::2])]

hs = [[], []]
for i in range(2):
    for k, c in cnts[i].items():
        heapq.heappush(hs[i], (-c, k))
h0 = heapq.heappop(hs[0])
h1 = heapq.heappop(hs[1])
if h0[1] == h1[1]:
    if not hs[0] and not hs[1]:
        print(n//2)
    elif not hs[0]:
        print(n+h1[0])
    elif not hs[1]:
        print(n+h0[0])
    else:
        n0 = heapq.heappop(hs[0])
        n1 = heapq.heappop(hs[1])
        print(n - min(h0[0]+n1[0], n0[0]+h1[0]))
else:
    print(n+(h0[0]+h1[0]))

Submission status: Wrong Answer

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

cnts = [collections.Counter(v[::2]), collections.Counter(v[1::2])]

hs = [[], []]
for i in range(2):
    for k, c in cnts[i].items():
        heapq.heappush(hs[i], (-c, k))
h0 = heapq.heappop(hs[0])
h1 = heapq.heappop(hs[1])
if h0[1] == h1[1]:
    if not hs[0] and not hs[1]:
        print(n//2)
    elif not hs[0]:
        print(n+h1[0])
    elif not hs[1]:
        print(n+h0[0])
    else:
        n0 = heapq.heappop(hs[0])
        n1 = heapq.heappop(hs[1])
        print(n - max(-h0[0]-n1[0], -n0[0]-h1[0]))
else:
    print(n-(h0[0]+h1[0]))

Submission status: Wrong Answer

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

cnts = [collections.Counter(v[::2]), collections.Counter(v[1::2])]

if cnts[0] == cnts[1]:
    print(n//2)
    exit()

hs = [[], []]
for i in range(2):
    for k, c in cnts[i].items():
        heapq.heappush(hs[i], (-c, k))
h0 = heapq.heappop(hs[0])
h1 = heapq.heappop(hs[1])
if h0[1] == h1[1]:
    if cnts[0] == cnts[1]:
        print(n//2)
        exit()
    n0 = heapq.heappop(hs[0])
    n1 = heapq.heappop(hs[1])
    print(n - max(-h0[0]-n1[0], -n0[0]-h1[0]))
else:
    print(n-(h0[0]+h1[0]))

Submission status: Wrong Answer

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

cnts = [collections.Counter(v[::2]), collections.Counter(v[1::2])]

if cnts[0] == cnts[1]:
    print(n//2)
    exit()

hs = [[], []]
for i in range(2):
    for k, c in cnts[i].items():
        heapq.heappush(hs[i], (-c, k))
h0 = heapq.heappop(hs[0])
h1 = heapq.heappop(hs[1])
if h0[1] == h1[1]:
    n0 = heapq.heappop(hs[0])
    n1 = heapq.heappop(hs[1])
    print(n - max(-h0[0]-n1[1], -n0[0]-h1[0]))
else:
    print(n+h0[0]+h1[0])

Submission status: Wrong Answer

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

cnts = [collections.Counter(v[::2]), collections.Counter(v[1::2])]

if cnts[0] == cnts[1]:
    print(n//2)
    exit()

hs = [[], []]
for i in range(2):
    for k, c in cnts[i].items():
        heapq.heappush(hs[i], (-c, k))
h0 = heapq.heappop(hs[0])
h1 = heapq.heappop(hs[1])
if h0[1] == h1[1]:
    n0 = heapq.heappop(hs[0])
    n1 = heapq.heappop(hs[1])
    print(n - max(-h0[0]-n1[0], -n0[0]-h1[0]))
else:
    print(n+h0[0]+h1[0])

Submission status: Wrong Answer

Solution code:
n = int(input())
v = list(map(int,input().split()))
a = []
x = []
b = []
y = []

for i in range(n):
        if i%2==1:
                if v[i] in a:
                        x[a.index(v[i])] += 1
                else:
                        a.append(v[i])
                        x.append(1)
        else:
                if v[i] in b:
                        y[b.index(v[i])] += 1
                else:
                        b.append(v[i])
                        y.append(1)
x=sorted(x)[::-1]
y=sorted(y)[::-1]
maxx = x[0]
maxy = y[0]
sumx = sum(x)
sumy = sum(y)

if a[x.index(maxx)] != b[y.index(maxy)]:
        changea = sumx-maxx
        changeb = sumy-maxy
        print(changea + changeb)
else:
        p = x.index(maxx)
        q = y.index(maxy)
        x.pop(p)
        y.pop(q)
        tmp1 = 0
        tmp2 = 0
        if len(x) != 0:
                tmp1 = x[0]
        if len(y) != 0:
                tmp2 = y[0]

        x.append(maxx)
        y.append(maxy)    
        ans1 = sumx-maxx + sumy-tmp2
        ans2 = sumx-tmp1 + sumy-maxy
        print(min(ans1,ans2))

Submission status: Wrong Answer

Solution code:
n = int(input())
v = list(map(int,input().split()))
a = []
x = []
b = []
y = []

for i in range(n):
        if i%2==1:
                if v[i] in a:
                        x[a.index(v[i])] += 1
                else:
                        a.append(v[i])
                        x.append(1)
        else:
                if v[i] in b:
                        y[b.index(v[i])] += 1
                else:
                        b.append(v[i])
                        y.append(1)

maxx = max(x)
maxy = max(y)
sumx = sum(x)
sumy = sum(y)

if a[x.index(maxx)] != b[y.index(maxy)]:
        changea = sumx-maxx
        changeb = sumy-maxy
        print(changea + changeb)
else:
        p = x.index(maxx)
        q = y.index(maxy)
        xsub = x
        ysub = y
        xsub.pop(p)
        ysub.pop(q)
        tmp1 = 0
        tmp2 = 0
        if len(xsub) != 0:
                tmp1 = max(xsub)
        if len(ysub) != 0:
                tmp1 = max(xsub)

        x.append(maxx)
        y.append(maxy)    
        ans1 = sumx-maxx + sumy-tmp2
        ans2 = sumx-tmp1 + sumy-maxy
        print(min(ans1,ans2))

Submission status: Wrong Answer

Solution code:
n = int(input())
v = list(map(int,input().split()))
a = []
x = []
b = []
y = []
chengea = 0
chengeb = 0

for i in range(n):
        if i%2==1:
                if v[i] in a:
                        x[a.index(v[i])] += 1
                else:
                        a.append(v[i])
                        x.append(1)
        else:
                if v[i] in b:
                        y[b.index(v[i])] += 1
                else:
                        b.append(v[i])
                        y.append(1)

maxx = max(x)
maxy = max(y)
sumx = sum(x)
sumy = sum(y)

if a[x.index(maxx)] != b[y.index(maxy)]:
        chengea = sumx-maxx
        changeb = sumy-maxy
        print(chengea + chengeb)
else:
        p = x.index(maxx)
        q = y.index(maxy)
        xsub = x
        ysub = y
        xsub.pop(p)
        ysub.pop(q)
        tmp1 = 0
        tmp2 = 0
        if len(xsub) != 0:
                tmp1 = max(xsub)
        if len(ysub) != 0:
                tmp1 = max(xsub)

        x.append(maxx)
        y.append(maxy)    
        ans1 = sumx-maxx + sumy-tmp2
        ans2 = sumx-tmp1 + sumy-maxy
        print(min(ans1,ans2))

Submission status: Wrong Answer

Solution code:
n = int(input())
v = list(map(int,input().split()))
a = []
x = []
b = []
y = []
chengea = 0
chengeb = 0

for i in range(n):
        if i%2==1:
                if v[i] in a:
                        x[a.index(v[i])] += 1
                else:
                        a.append(v[i])
                        x.append(1)
        else:
                if v[i] in b:
                        y[b.index(v[i])] += 1
                else:
                        b.append(v[i])
                        y.append(1)

if a[x.index(max(x))] != b[y.index(max(y))]:
        chengea = sum(x)-max(x)
        changeb = sum(y)-max(y)
        print(chengea + chengeb)
else:
        p = x.index(max(x))
        q = y.index(max(y))
        maxx = max(x)
        maxy = max(y)
        xsub = x
        ysub = y
        xsub.pop(p)
        ysub.pop(q)
        tmp1 = 0
        tmp2 = 0
        if len(xsub) == 0:
                tmp1 = 0
        else:
                tmp1 = max(xsub)

        if len(ysub) == 0:
                tmp2 = 0
        else:
                tmp2 = max(ysub)  
        x.append(maxx)
        y.append(maxy)    
        ans1 = sum(x)-max(x) + sum(y)-tmp2
        ans2 = sum(x)-tmp1 + sum(y)-max(y)
        print(min(ans1,ans2))

Submission status: Wrong Answer

Solution code:
n = int(input())
v = list(map(int, input().split()))
even, odd = v[::2], v[1::2]

set_e = list(set(even))
set_o = list(set(odd))
set_e.sort(key=lambda x: even.count(x))
set_o.sort(key=lambda x: odd.count(x))
e1, o1 = set_e[0], set_o[0]
ce1, co1 = even.count(e1), odd.count(o1)

if e1 != o1:
    a, b = ce1, co1
    print(n-a-b)
    exit()
if len(set_o) == 1 and len(set_e) == 1:
    print(len(even))
    exit()
if len(set_o) == 1:
    e2 = set_e[1]
    a = even.count(e2)
    print(len(even)-a)
    exit()
if len(set_e) == 1:
    o2 = set_o[1]
    a = odd.count(o2)
    print(len(odd)-a)
    exit()

e2, o2 = set_e[1], set_o[1]
ce2, co2 = even.count(e2), odd.count(o2)

print(min(n-ce1-co2, n-ce2-co1))