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:
from collections import Counter

n = int(input())
v_list = [int(i) for i in input().split()]
odd_v = v_list[::2]
even_v = v_list[1::2]

cnt_odd = Counter(odd_v).most_common()+[(0, 0)]
cnt_even = Counter(even_v).most_common()+[(0, 0)]

if cnt_odd[0][0] == cnt_even[0][0]:
    print(max(n-cnt_odd[0][1]-cnt_even[1][1], \
              n-cnt_odd[1][1]-cnt_even[0][1]))
else:
    print(n-cnt_odd[0][1]-cnt_even[0][1])

Submission status: Wrong Answer

Solution code:
n = int(input())
vi = list(map(int,input().split()))
odd = [vi[k] for k in range(0,n,2)]
even = [vi[k+1] for k in range(0,n,2)]
odd.sort()
even.sort()

odd.append(-1)
even.append(-1)

oddset = []
oddcounter = []
pos = 0
while pos<n/2:
    oddset.append(odd[pos])
    counter = 1
    now = odd[pos]
    pos += 1
    while now == odd[pos]:
        counter +=1
        pos += 1
    oddcounter.append([counter,now])

evenset = []
evencounter = []
pos = 0
while pos<n/2:
    evenset.append(even[pos])
    counter = 1
    now = even[pos]
    pos += 1
    while now == even[pos]:
        counter +=1
        pos += 1
    evencounter.append([counter,now])

oddcounter.sort(key=lambda x:x[0])
evencounter.sort(key=lambda x:x[0])

oc = oddcounter
ec = evencounter

if len(oc)==1 and len(ec)==1:
    if oc[0][1]!=ec[0][1]:
        print(0)
    else:
        print(int(n/2))
elif len(oc)==1 and len(ec)>1:
    if oc[0][1]!=ec[0][1]:
        print(int(n/2)-ec[0][0])
    else:
        print((int(n/2)-ec[1][0]))
elif len(oc)>1 and len(ec)==1:
    oc,ec=ec,oc
    if oc[0][1]!=ec[0][1]:
        print(int(n/2)-ec[0][0])
    else:
        print((int(n/2)-ec[1][0]))
else:
    if oc[0][0]==oc[1][0]:
        print(n-oc[0][0]-ec[0][0])
    elif ec[0][0]==ec[1][0]:
        print(n-oc[0][0]-ec[0][0])
    elif oc[0][1]!=ec[0][1]:
        print(n-oc[0][0]-ec[0][0])
    else:
        print(n-max(oc[0][0]+ec[1][0],oc[1][0]+ec[0][0]))

Submission status: Wrong Answer

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

odv = []
evv = []

for i in range(n):
    if i%2 == 1:
        odv.append(v[i])
    else:
        evv.append(v[i])

odvc=collections.Counter(odv)
evvc=collections.Counter(evv)

odvs=len(odvc.most_common())
evvs=len(evvc.most_common()) 

if evvc.most_common()[0][0] != odvc.most_common()[0][0]:
    print( odvs-odvc.most_common()[0][1] + evvs-evvc.most_common()[0][1] )
else:
    if odvs > 1 and evvs > 1:
        print( min(odvs-odvc.most_common()[0][1] + evvs-evvc.most_common()[1][1] ,
                   odvs-odvc.most_common()[1][1] + evvs-evvc.most_common()[0][1] ) )
    else:
        if odvs > 1:
            print( odvs-odvc.most_common()[0][1] )
        elif evvs > 1:
            print( evvs-evvc.most_common()[0][1] )
        else:
            print(min(odvs,evvs))

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
n = int(input())
v = list(map(int, input().split()))
rec = defaultdict(int)
for k in v:
    rec[k] += 1

rec1 = []
for i, k in rec.items():
    rec1.append((i, k))

m = n // 2
rec1 = sorted(rec1, key=lambda x: abs(x[1] - m))

if len(rec1) == 1:
    print(m)
else:
    print(abs(m - rec1[1][1]) - abs(rec1[0][1] - m))

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

even = Counter(v[::2])
odd = Counter(v[1::2])
even_most_common = even.most_common(2)
odd_most_common = odd.most_common(2)


ans = 0
if even_most_common[0][0] == odd_most_common[0][0]:
    if len(even_most_common) == 1 and len(odd_most_common) == 1:
        ans += n // 2
    elif even_most_common[0][1] > odd_most_common[0][1]:
        ans += n // 2 - even_most_common[0][1]
        ans += n // 2 - odd_most_common[1][1]
    else:
        ans += n // 2 - even_most_common[1][1]
        ans += n // 2 - odd_most_common[0][1]
else:
    ans += n // 2 - even_most_common[0][1]
    ans += n // 2 - odd_most_common[0][1]

print(ans)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!

import collections

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

ae = [a[i] for i in range(n) if i%2==0]
ao = [a[i] for i in range(n) if i%2==1]

aedic = collections.Counter()

aodic = collections.Counter()

for i in ae:
    aedic[i]+=1
for i in ao:
    aodic[i]+=1

p=aedic.most_common(2)
q=aodic.most_common(2)

#print(p,q)

if p[0][0] != q[0][0]:
#    print("a")
    print(n-p[0][1]-q[0][1])
elif len(p)==1 and len(q)!=1:
#    print("b")
    print(n-p[0][1]-q[1][1])
elif len(p)!=1 and len(q)==1:
#    print("c")
    print(n-p[1][1]-q[0][1])
else:
#    print("d")
    a=min(n-p[-1][1]-q[0][1], n-p[0][1]-q[-1][1])
    print(a)

Submission status: Wrong Answer

Solution code:
from sys import stdin
il = lambda func=int: list(map(func, stdin.readline().rstrip().split()))
ils = lambda n, s="int(input())": [eval(s) for _ in range(n)]

n = int(input())
v = il()
a = dict()
b = dict()
for i in range(n):
    if i&1:
        if v[i] in a:
            a[v[i]] += 1
        else:
            a[v[i]] = 1
    else:
        if v[i] in b:
            b[v[i]] += 1
        else:
            b[v[i]] = 1
ans = 0
a = sorted(a.items(), key=lambda x:x[1])
b = sorted(b.items(), key=lambda x:x[1])
if a[-1][0] == b[-1][0]:
    ans += min(a[-1][1], b[-1][1])
else:
    if len(a) > 1:
        ans += n//2 - a[-1][1]
    if len(b) > 1:
        ans += n//2 - b[-1][1]

print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
arr=list(map(int,input().split()))
a=[]
b=[]
for i in range(n):
	if i%2==0:
		a.append(arr[i])
	else:
		b.append(arr[i])
freqa=[0]*(100005)
freqb=[0]*(100005)
for i in a:
	freqa[i]+=1
for j in b:
	freqb[j]+=1
ma=max(freqa)
mb=max(freqb)
ma1=freqa.index(ma)
mb1=freqb.index(mb)
if max(freqa)==(len(a)):
	if max(freqb)==len(b):
		if ma1!=mb1:
			print('0')
		else:
			print(min(len(a),len(b)))
	else:
		print(len(b)-max(freqb))
else:
	if max(freqb)==len(b):
		print(len(a)-max(freqa))
	else:
		aa=len(a)-max(freqa)
		bb=len(b)-max(freqb)
		print(aa+bb)

Submission status: Wrong Answer

Solution code:
from collections import Counter

n = int(input())
v_list = [int(i) for i in input().split()]
odd_v = v_list[::2]
even_v = v_list[1::2]

cnt_odd = Counter(odd_v)
cnt_even = Counter(even_v)
o_key, o_value = list(cnt_odd.keys()), list(cnt_odd.values())+[0]
e_key, e_value = list(cnt_even.keys()), list(cnt_even.values())+[0]

if o_key[0] == e_key[0]:
    print(max(n-o_value[0]-e_value[1], \
              n-o_value[1]-e_value[0]))
else:
    print(n-o_value[0]-e_value[0])

Submission status: Wrong Answer

Solution code:
import sys
stdin = sys.stdin

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

from collections import Counter

n = ni()
a = list(li())

even = Counter(a[::2])
odd = Counter(a[1::2])

es = [(0,0)]
for ek,ev in even.items():
    es.append((ev,ek))
    
es.sort()
    
    
os = [(0,0)]
for ok,ov in odd.items():
    os.append((ov,ok))
    
os.sort()
    

if es[-1][1] != os[-1][1]:
    print((n//2-es[-1][0]) + (n//2-os[-1][0]))
else:
    print(max((n//2-es[-1][0]) + (n//2-os[-2][0]),
              (n//2-es[-2][0]) + (n//2-os[-1][0])))

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
try: from typing import Any, Union, List, Tuple, Dict
except ImportError: pass
sys.setrecursionlimit(10**6)
def debug(*args): print(*args, file=sys.stderr)
def exit(): sys.exit(0)

from collections import Counter

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

c = Counter(v)
if len(c) == 1:
    print(n//2)
    exit()
# fc = c.most_common(2)
# count1 = fc[0][1]
# count2 = fc[1][1]
# ok = 0
# debug(fc)

# if count1 <= n//2:
#     ok += count1
# else:
#     ok += n//2
# ok += count2


# print(n-ok)

odd = [v[2*i+1] for i in range(n//2)]
even = [v[2*i] for i in range(n//2)]
# odd_count = Counter(odd).most_common(1)[0][1]
# even_count = Counter(even).most_common(1)[0][1]

oc = Counter(odd).most_common()
ec = Counter(even).most_common()

if oc[0][0] != ec[0][0]:
    odd_count = oc[0][1]
    even_count = ec[0][1]
else:
    if oc[0][1] > ec[0][1]:
        odd_count = oc[0][1]
        even_count = ec[1][1]
    else:
        odd_count = oc[1][1]
        even_count = ec[0][1]

print(n-odd_count-even_count)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input().strip())
vs = [int(i) for i in input().split(' ')]
vs1 = vs[::2]
vs2 = vs[1::2]
a = Counter(vs1).most_common()
b = Counter(vs2).most_common()

if a[0][0] != b[0][0]:
    print(n - a[0][1] - b[0][1])
else:
    candidates = []
    candidates.append(len(vs2))
    if len(a) != 1:
        candidates.append(n - a[1][1] - b[0][1])
    if len(b) != 1:
        candidates.append(n - a[0][1] - b[1][1])
    print(min(candidates))

Submission status: Wrong Answer

Solution code:
import sys
stdin = sys.stdin

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

from collections import Counter

n = ni()
a = list(li())

even = Counter(a[::2])
odd = Counter(a[1::2])

es = [(0,0)]
for ek,ev in even.items():
    es.append((ev,ek))
    
es.sort(reverse=True)
    
    
os = [(0,0)]
for ok,ov in odd.items():
    os.append((ov,ok))
    
os.sort(reverse=True)
    

if es[-1][1] != os[-1][1]:
    print((n//2-es[-1][0]) + (n//2-os[-1][0]))
else:
    print(max((n//2-es[-1][0]) + (n//2-os[-2][0]),
              (n//2-es[-2][0]) + (n//2-os[-1][0])))

Submission status: Wrong Answer

Solution code:
from collections import Counter



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

even = a[0::2]
odd= a[1::2]
even_counter = Counter(even)
odd_counter = Counter(odd)
#print(even_counter.most_common()[0][0])
#print(odd_counter.most_common()[0][0])

cnt = 0
for i in range(int(n/2)):
	if a[i*2] != even_counter.most_common()[0][0]:
		cnt = cnt+1
	if a[i*2-1] != odd_counter.most_common()[0][0]:
		cnt = cnt+1
       
print(cnt)

Submission status: Wrong Answer

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

v0 = collections.Counter([v[2 * i] for i in range(n // 2)])
v1 = collections.Counter([v[2 * i + 1] for i in range(n // 2)])

if v0.most_common()[0][0] != v1.most_common()[0][0]:
    ans = n - v0.most_common()[0][1] - v1.most_common()[0][1]
else:
    if len(v0) == 1:
        if len(v1) == 1:
            ans = n // 2
        else:
            ans = n - v1.most_common()[1][1]
    else:
        if len(v1) == 1:
            ans = n - v0.most_common()[1][1]
        else:
            ans = max(n - v0.most_common()[0][1] - v1.most_common()[1][1], n - v0.most_common()[1][1] - v1.most_common()[0][1])

print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
v=[int(i) for i in input().split()]
if N==2:
    if v[0]==v[1]:
        print(1)
        exit()
    else:
        print(0)
        exit()
A=dict()
B=dict()
L=0
R=0
def inc(D,k):
    if k in D:
        D[k]+=1
    else:
        D[k]=1
for i in range(N):
    if i%2==0:
        L+=1
        inc(A,v[i])
    else:
        R+=1
        inc(B,v[i])
X=[(L,-1)]
Y=[(R,-2)]
for i in A:
    X.append((L-A[i],i))
for i in B:
    Y.append((R-B[i],i))
while(True):
    if X[-1][1]!=Y[-1][1]:
        print(X[-1][0]+Y[-1][0])
        exit()
    else:
        vl=X[-1][0]+Y[-2][0]
        vr=X[-2][0]+Y[-1][0]
        if vl<vr:
            Y.pop()
            R-=1
        else:
            X.pop()
            L-=1

Submission status: Wrong Answer

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

v1 = {}
v2 = {}
for i in range(len(v)):
    if(i % 2 == 0):
        if((v[i] in v1) == True):
            v1[v[i]] += 1
        else:
            v1[v[i]] = 1
    else: 
        if((v[i] in v2) == True):
            v2[v[i]] += 1
        else:
            v2[v[i]] = 1

max_k1 = max(v1, key=v1.get)
max_k2 = max(v2, key=v2.get)

if(max_k1 == max_k2):
    if(v1[max_k1] > v2[max_k2]):
        v2[max_k2] = 0
        max_k2 = max(v2, key=v2.get)
    else:
        v1[max_k1] = 0
        max_k1 = max(v1, key=v1.get)

if(n % 2 == 0):
    ans = n // 2 - v1[max_k1]
else: ans = n // 2 + 1 - v1[max_k1]
ans += n // 2 - v2[max_k2]

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

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

ODD = defaultdict(int)
EVEN = defaultdict(int)
NUMBER = set()

for i in range(n):
    if i%2==0:
        EVEN[V[i]] += 1
    else:
        ODD[V[i]] += 1
    NUMBER.add(V[i])
    
if len(NUMBER)==1:
    print(n//2)
else:
    flag = True
    
    max_ODD = max(ODD, key=ODD.get)
    ans = n-ODD[max_ODD]
    for k,v in sorted(EVEN.items(),key = lambda x:x[1],reverse=True):
        if max_ODD != k:
            print(ans-v)
            flag = False
            break
            
    if flag:
        max_EVEN = max(EVEN, key=EVEN.get)
        ans = n-EVEN[max_EVEN]
        for k,v in sorted(ODD.items(),key = lambda x:x[1],reverse=True):
            if max_EVEN != k:
                print(ans-v)
                flag = False
                break

Submission status: Wrong Answer

Solution code:
from collections import Counter

n = int(input())
V = [int(_) for _ in input().split()]

A = V[::2]
B = V[1::2]

resA = Counter(A).most_common()
resB = Counter(B).most_common()


if resA[0][0] == resB[0][0]:
    if resB[0][1] > resA[0][1]:
        resA, resB = resB, resA

    sumA = sum([num for x, num in resA[1:]])
    sumB = resB[0][1] + sum([num for x, num in resB[2:]])

    print(sumA + sumB)
else:
    if len(resA) == 1 and len(resB) == 1:
        print(0)
    else:
        sumA = sum([num for x, num in resA[1:]])
        sumB = sum([num for x, num in resB[1:]])
        print(sumA + sumB)

Submission status: Wrong Answer

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

b=[a[i] for i in range(0,n,2)]
c=[a[i] for i in range(1,n,2)]
from collections import Counter
xb=list(Counter(b).items())
xc=list(Counter(c).items())
xb=sorted(xb, key=lambda x:-x[1])
xc=sorted(xc, key=lambda x:-x[1])
ans=[]
print(xb,xc)
if xb[0][0]==xc[0][0]:
    print(len(xc),len(xb))
    if len(xc)>1:
        ans.append(n//2-xb[0][1]-(-n//2)-xc[1][1])
    if len(xb)>1:
        ans.append(n//2-xb[1][1]-(-n//2)-xc[0][1])
    if len(xc)==1 and len(xb)==1:
        ans.append(n//2)
else:
    ans.append(n//2-xb[0][1]-(-n//2)-xc[0][1])
print(min(ans))

Submission status: Wrong Answer

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

import collections
import itertools


def solve(vs):
    up_vals = vs[::2]
    up_ctr = collections.Counter(up_vals)
    down_vals = vs[1::2]
    down_ctr = collections.Counter(down_vals)
    if up_vals == down_vals:
        return len(up_vals)
    up_mcs = up_ctr.most_common(3)
    down_mcs = down_ctr.most_common(3)
    g = itertools.product(up_mcs, down_mcs)
    c = min(len(up_vals) + len(down_vals) - v1 - v2 for ((k1, v1), (k2, v2)) in g if k1 != k2)
    return c


def main():
    _ = input()
    vs = [int(v) for v in input().split()]
    print(solve(vs))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

odd = [0 for i in range(10**5)]
even = [0 for i in range(10**5)]

for i in range(n):
    if i % 2 == 0:
        odd[a[i]-1] += 1
    else:
        even[a[i]-1] += 1
        
oddmax = 0
evenmax = 0

oddfirst = 0
oddsecond = 0
evenfirst = 0
evensecond = 0

for i in range(10**5):
    if odd[i] >= oddfirst:
        oddsecond = oddfirst
        oddfirst = odd[i]
        oddmax = i
    if even[i] >= evenfirst:
        evensecond = evenfirst
        evenfirst = even[i]
        evenmax = i

a = 0
if oddmax == evenmax:
    a = min(oddfirst - oddsecond, evenfirst - evensecond)
        
ans = n - oddfirst - evenfirst + a
print(ans)

Submission status: Wrong Answer

Solution code:
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#

"""
ARC103 C
"""

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

evli = vli[::2]
ovli = vli[1::2]

from collections import Counter
Cevli = Counter(evli).most_common(2)
Covli = Counter(ovli).most_common(2)

vem,iem=Cevli[0]
vom,iom=Covli[0]

if vem!=vom:
    ans = n-iem-iom
elif iem == n//2 and iom == n//2:
    ans = n//2
else:
    vem2,iem2=Cevli[1]
    vom2,iom2=Cevli[1]
    ans1 = n-iem-iom2
    ans2 = n-iem2-iom
    ans = min(ans1,ans2)

print(ans)

Submission status: Wrong Answer

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

v0 = collections.Counter([v[2 * i] for i in range(n // 2)])
v1 = collections.Counter([v[2 * i + 1] for i in range(n // 2)])

if v0.most_common()[0][0] != v1.most_common()[0][0]:
    ans = n - v0.most_common()[0][1] - v1.most_common()[0][1]
else:
    if len(v0) == 1:
        if len(v1) == 1:
            ans = n // 2
        else:
            ans = n - v1.most_common()[1][1]
    else:
        if len(v1) == 1:
            ans = n - v0.most_common()[1][1]
        else:
            ans = max(n - v0.most_common()[0][1] - v1.most_common()[1][1], n - v0.most_common()[1][0] - v1.most_common()[0][1])

print(ans)

Submission status: Wrong Answer

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

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

max_e = [(0,0),(0,0)]
max_o = [(0,0),(0,0)]
for i in range(10**5+1):
	if max_e[1][0] < v_e_cnt[i]:
		if max_e[0][0] < v_e_cnt[i]:
			max_e[1] = max_e[0]
			max_e[0] = (v_e_cnt[i], i)
		else:
			max_e[1] = (v_e_cnt[i], i)
	if max_o[1][0] < v_o_cnt[i]:
		if max_o[0][0] > v_o_cnt[i]:
			max_o[1] = max_o[0]
			max_o[0] = (v_o_cnt[i], i)
		else:
			max_o[0] = (v_o_cnt[i], i)

ans = 10**10
for e in max_e:
	for o in max_o:
		if e[1] == o[1]:
			continue
		ans = min(ans, n - e[0] - o[0])
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
stdin = sys.stdin

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

from collections import Counter

n = ni()
a = list(li())

even = Counter(a[::2])
odd = Counter(a[1::2])

emax = [0]
ekey = [0]
for ek,ev in even.items():
    emax.append(ev)
    ekey.append(ek)
    
ek = ekey[emax.index(max(emax))]
emax.sort()
    
omax = [0]
okey = [0]
for ok,ov in odd.items():
    omax.append(ov)
    okey.append(ok)
    
ok = okey[omax.index(max(omax))]
omax.sort()

if ek != ok:
    print((n//2-emax[-1]) + (n//2-omax[-1]))
else:
    print(max((n//2-emax[-1]) + (n//2-omax[-2]),
              (n//2-emax[-2]) + (n//2-omax[-1])))

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

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

ODD = defaultdict(int)
EVEN = defaultdict(int)
NUMBER = set()

for i in range(n):
    if i%2==0:
        EVEN[V[i]] += 1
    else:
        ODD[V[i]] += 1
    NUMBER.add(V[i])
    
if len(NUMBER)==1:
    print(n//2)
else:
    flag = True
    
    max_ODD = max(ODD, key=ODD.get)
    ans = n-ODD[max_ODD]
    for k,v in sorted(EVEN.items(),key = lambda x:x[1]):
        if max_ODD != k:
            print(ans-v)
            flag = False
            break
            
    if flag:
        max_EVEN = max(EVEN, key=EVEN.get)
        ans = n-EVEN[max_EVEN]
        for k,v in sorted(ODD.items(),key = lambda x:x[1]):
            if max_EVEN != k:
                print(ans-v)
                flag = False
                break

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**6)

def main():
	n = int(input())
	v = [int(i) for i in input().split()]
	v1 = [0] * 100001
	v2 = [0] * 100001
	v11 = 0
	v21 = 0
	v12 = 0
	v22 = 0
	ans = 0
	for i in range(n):
		if i % 2 == 0:
			v1[v[i]] += 1
		else:
			v2[v[i]] += 1
	for i in range(100001):
		if v1[i] > v1[v11]:
			v12 = v11
			v11 = i
		elif v1[i]>v[v12]:
			v12 = i
		if v2[i] > v2[v21]:
			v22 = v21
			v21 = i
		elif v1[i]>v[v22]:
			v22 = i
	if v11 == v21:
		ans = min(n-v1[v11] - v2[v22], n-v1[v12]-v2[v21])
	else:
		ans = n - v1[v11] - v2[v21]
	print(ans)

main()

Submission status: Wrong Answer

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

d = {}
for i, li in enumerate(l):
    if (li, i % 2 == 0) in d:
        d[(li, i % 2 == 0)] += 1
    else:
        d[(li, i % 2 == 0)] = 1

dd = [(st, cnt) for st, cnt in d.items()];

sorted(dd, key=lambda ddi: ddi[1])
prev = dd[0][0]
ans = n // 2 - dd[0][1]
yet = True
for ddi in dd[1:]:
    if prev[1] == ddi[0][1]:
        continue
    if prev[0] == ddi[0][0]:
        continue
    yet = False
    ans += n // 2 - ddi[1];
    break
if yet:
    ans += n // 2
print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
try: from typing import Any, Union, List, Tuple, Dict
except ImportError: pass
sys.setrecursionlimit(10**6)
def debug(*args): print(*args, file=sys.stderr)
def exit(): sys.exit(0)

from collections import Counter

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

c = Counter(v)
if len(c) == 1:
    print(n//2)
    exit()
# fc = c.most_common(2)
# count1 = fc[0][1]
# count2 = fc[1][1]
# ok = 0
# debug(fc)

# if count1 <= n//2:
#     ok += count1
# else:
#     ok += n//2
# ok += count2


# print(n-ok)

odd = [v[2*i+1] for i in range(n//2)]
even = [v[2*i] for i in range(n//2)]
odd_count = Counter(odd).most_common(1)[0][1]
even_count = Counter(even).most_common(1)[0][1]

print(n-odd_count-even_count)

Submission status: Wrong Answer

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

l0 = [0 for i in range(10**5+1)]
l1 = [0 for i in range(10**5+1)]

a0 = [v[i] for i in range(0, n, 2)]
a1 = [v[i] for i in range(1, n, 2)]

for i in a0:
    l0[i] += 1
for i in a1:
    l1[i] += 1

first0 = 0
index0 = 0
for i in range(len(l0)):
    if l0[i] > first0:
        first0 = l0[i]
        index0 = i

l0[index0] = 0
second0 = max(l0)

first1 = 0
index1 = 0
for i in range(len(l1)):
    if l1[i] > first1:
        first1 = l1[i]
        index1 = i

l1[index1] = 0
second1 =max(l1)

if index0 != index1:
    print(n - first0 - first1)
else:
    print(max(n - first0 - second1, n - first1 - second0))

Submission status: Wrong Answer

Solution code:
n=int(input())
v=list(map(int,input().split()))
w=sorted(a for a in v[0::2])
x=sorted(a for a in v[1::2])
a=[[0,i]for i in range(10**5+1)]
b=[[0,i]for i in range(10**5+1)]
for t in w:
    a[t][0]+=1
for t in x:
    b[t][0]+=1
c=sorted(a)
d=sorted(b)
e=c[len(c)-1][0]
i=c[len(c)-1][1]
f=d[len(d)-1][0]
g=c[len(c)-1][0]
h=d[len(d)-1][0]
for t in range(len(c)):
    if i!=d[len(d)-1][1]:break
    e=c[len(c)-t-1][0]
    i=c[len(c)-t-1][1]
i=d[len(d)-1][1]
for t in range(len(d)):
    if i!=c[len(c)-1][1]:break
    g=d[len(d)-t-1][0]
    i=d[len(d)-t-1][1]
print(max(n-e-f,n-g-h))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(10000)


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, V):
    v1 = [v for v in V[::2]]
    v2 = [v for v in V[1::2]]

    v1c = Counter(v1)
    v2c = Counter(v2)
    v1 = v1c.most_common(2)[::-1]
    v2 = v2c.most_common(2)[::-1]
    v1.append((-1, 0))
    v2.append((-1, 0))

    v1_1, v1_2 = v1[:2]
    v2_1, v2_2 = v2[:2]

    if v1_1[0] != v2_1[0]:
        return (N//2 - v1_1[1]) + (N//2 - v2_1[1])

    return min(
        (N//2 - v1_1[1]) + (N//2 - v2_2[1]),
        (N//2 - v1_2[1]) + (N//2 - v2_1[1]),
    )


def main():
    N = read_int()
    V = read_int_n()
    print(slv(N, V))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!

import collections

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

ae = [a[i] for i in range(n) if i%2==0]
ao = [a[i] for i in range(n) if i%2==1]

aedic = collections.Counter()

aodic = collections.Counter()

for i in ae:
    aedic[i]+=1
for i in ao:
    aodic[i]+=1

p=aedic.most_common(2)
q=aodic.most_common(2)

#print(p,q)

if p[0][0] != q[0][0]:
    print(n-p[0][1]-q[0][1])
elif len(p)!=1 or len(q)!=1:
    a=max(n-p[-1][1]-q[0][1], n-p[0][1]-q[-1][1])
    print(a)
else:
    print(n//2)

Submission status: Wrong Answer

Solution code:
import collections
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])
    
ac = collections.Counter(a)
bc = collections.Counter(b)

atemp = []
for i in ac:
    atemp.append(ac[i])
btemp = []
for i in bc:
    btemp.append(bc[i])

mxma = max(atemp)
mxmb = max(btemp)
for i in ac:
    if ac[i] == mxma:
        mxma = i
        break
for i in bc:
    if bc[i] == mxmb:
        mxmb = i
        break

atemp.sort()
btemp.sort()

if mxma != mxmb:
    print(n-max(atemp)-max(btemp))
else:
    if len(atemp) == 1 and len(btemp) == 1:
        print(n-max(atemp))
    else:
        temp = [atemp[-2]+btemp[-1],atemp[-1],btemp[-2]]
        print(n-max(temp))

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**6)

def main():
	n = int(input())
	v = [int(i) for i in input().split()]
	v1 = [0] * 100001
	v2 = [0] * 100001
	v11 = 0
	v21 = 0
	v12 = 0
	v22 = 0
	ans = 0
	for i in range(n):
		if i % 2 == 0:
			v1[v[i]] += 1
		else:
			v2[v[i]] += 1
	for i in range(10001):
		if v1[i] > v1[v11]:
			v12 = v11
			v11 = i
		elif v1[i]>v[v12]:
			v12 = i
		if v2[i] > v2[v21]:
			v22 = v21
			v21 = i
		elif v1[i]>v[v22]:
			v22 = i
	if v11 == v21:
		ans = min(n-v1[v11] - v2[v22], n-v1[v12]-v2[v21])
	else:
		ans = n - v1[v11] - v2[v21]
	print(ans)

main()

Submission status: Wrong Answer

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

b=[a[i] for i in range(0,n,2)]
c=[a[i] for i in range(1,n,2)]
from collections import Counter
xb=list(Counter(b).items())
xc=list(Counter(c).items())
xb=sorted(xb, key=lambda x:-x[1])
xc=sorted(xc, key=lambda x:-x[1])
ans=[]
if xb[0][0]==xc[0][0]:
    if len(xc)>1:
        ans.append(n//2-xb[0][0]-(-n//2)-xc[1][1])
    if len(xb)>1:
        ans.append(n//2-xb[1][0]-(-n//2)-xc[0][1])
    if len(xc)==1 and len(xb)==1:
        ans.append(n//2)
else:
    ans.append(n//2-xb[0][1]-(-n//2)-xc[0][1])
print(min(ans))

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
v = list(map(int,input().split()))
a = v[0::2]
b = v[1::2]
a = sorted(a)
b = sorted(b)
a = collections.Counter(a).most_common()
b = collections.Counter(b).most_common()
if a[0][0]!=b[0][0]:
    print(n - a[0][1] - b[0][1])
elif a==b:
    print(n//2)
elif len(a)==1:
    print(n-a[0][1]-b[1][1])
elif len(b)==1:
    print(n-a[1][1]-b[0][1])
else:
    print(min(n-a[0][1]-b[1][1],n-a[1][1]-b[0][1]))

Submission status: Wrong Answer

Solution code:
n=int(input())
arr=list(map(int,input().split()))
a=[]
b=[]
for i in range(n):
	if i%2==0:
		a.append(arr[i])
	else:
		b.append(arr[i])
freqa=[0]*(100005)
freqb=[0]*(100005)
for i in a:
	freqa[i]+=1
for j in b:
	freqb[j]+=1
if max(freqa)==(len(a)):
	if max(freqb)==len(b):
		if max(freqa)!=max(freqb):
			print('0')
		else:
			print(min(len(a),len(b)))
	else:
		print(len(b)-max(freqb))
else:
	if max(freqb)==len(b):
		print(len(a)-max(freqa))
	else:
		aa=len(a)-max(freqa)
		bb=len(b)-max(freqb)
		print(aa+bb)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict


def main():
    n = input()
    vv = map(int, raw_input().split())
    d1 = defaultdict(int)
    for x in vv[::2]:
        d1[x] += 1
    d2 = defaultdict(int)
    for x in vv[1::2]:
        d2[x] += 1
    d1 = sorted([[c, x] for x, c in d1.items()], reverse=True)
    d2 = sorted([[c, x] for x, c in d2.items()], reverse=True)
    if d1[0][1] != d2[0][1]:
        print(n - d1[0][0] - d2[0][0])
        return
    if len(d1) == len(d2) == 1:
        print(n // 2)
        return
    c1 = d1[0][0]
    if len(d1) == 1:
        c2 = d1[0][0]
    else:
        c2 = d1[1][0]
    if len(d2) == 1:
        c1 += d2[0][0]
        c2 += d2[0][0]
    else:
        c1 += d2[1][0]
        c2 += d2[0][1]
    print(n - max(c1, c2))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

b=[a[i] for i in range(0,n,2)]
c=[a[i] for i in range(1,n,2)]
from collections import Counter
xb=list(Counter(b).items())
xc=list(Counter(c).items())
xb=sorted(xb, key=lambda x:-x[1])
xc=sorted(xc, key=lambda x:-x[1])
ans=[]
if xb[0][0]==xc[0][0]:
    if len(xc)>1:
        ans.append(n//2-xb[0][0]-(-n//2)-xc[1][1])
    if len(xb)>1:
        ans.append(n//2-xb[1][0]-(-n//2)-xc[0][1])
    else:
        ans.append(n//2)
else:
    ans.append(n//2-xb[0][1]-(-n//2)-xc[0][1])
print(ans[0])