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(map(int,input().split()))

list_odd=v[1::2]
list_even=v[0::2]

cnt_odd=Counter(list_odd)
cnt_even=Counter(list_even)

cnt_odd_sorted=sorted(cnt_odd.items(),reverse=True,key=lambda x:x[1])
cnt_even_sorted=sorted(cnt_even.items(),reverse=True,key=lambda x:x[1])

if cnt_odd_sorted[0][0]!=cnt_even_sorted[0][0]:
    ans=len(list_odd)-cnt_odd_sorted[0][1]
    ans+=len(list_even)-cnt_even_sorted[0][1]

else:
    if len(cnt_odd)==1 and len(cnt_even)==1:
        ans=len(list_even)
    elif len(cnt_odd)==1:
        ans=len(list_even)-cnt_even_sorted[1][1]
    elif len(cnt_even)==1:
        ans=len(list_odd)-cnt_odd_sorted[1][1]
    else:
        ans1=len(list_even)-cnt_even_sorted[1][1]
        ans2=len(list_odd)-cnt_odd_sorted[1][1]
        ans=max(ans1,ans2)

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
N = int(input())
A = list(map(int,input().split()))
D1 = defaultdict(int)
D2 = defaultdict(int)

for i in range(0,N,2):
  D1[A[i]]+=1
for i in range(1,N,2):
  D2[A[i]]+=1
print(N//2-max(D1.values())+N//2-max(D2.values()))

Submission status: Wrong Answer

Solution code:
n = int(input())
v = list(map(int, input().split()))
v1 = v[0::2]
v2 = v[1::2]

from collections import Counter
c1 = list(Counter(v1).items())
c2 = list(Counter(v2).items())

c1 = sorted(c1, key= lambda x: x[1], reverse= True)
c2 = sorted(c2, key= lambda x: x[1], reverse= True)

c1.append((0,0))
c2.append((0,0))

print(c1[:3], c2[:3])
if c1[0][0] != c2[0][0]:
    print(n - c1[0][1] - c2[0][1])
else:
    a = c1[0][1] + c2[1][1]
    b = c1[1][1] + c2[0][1]
    if a < b:
        print(n - b)
    else:
        print(n - a)

Submission status: Wrong Answer

Solution code:
n = int(input())
v = list(map(int, input().split()))
v1 = v[0::2]
v2 = v[1::2]

from collections import Counter
c1 = list(Counter(v1).items())
c2 = list(Counter(v2).items())

c1 = sorted(c1, key= lambda x: x[1], reverse= True)
c2 = sorted(c2, key= lambda x: x[1], reverse= True)

c1.append((0,0))
c2.append((0,0))

if c1[0][0] != c2[0][0]:
    print(n - c1[0][1] - c2[0][1])
else:
    a = c1[0][1] + c2[1][1]
    b = c1[1][1] + c2[0][1]
    if a > b:
        print(n - b)
    else:
        print(n - a)

Submission status: Wrong Answer

Solution code:
n = int(input())
v = list(map(int, input().split()))
even = [v[i] for i in range(1, n, 2)]
odd = [v[i] for i in range(0, n - 1, 2)]
e_list = [0] * 10**5
o_list = [0] * 10**5

for i in range(n // 2):
    e_list[even[i] - 1] += 1
    o_list[odd[i] - 1] += 1

ans = n - max(e_list) - max(o_list)
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
V = list(map(int, input().split()))
odd_dict = {}
even_dict = {}
for i in range(N):
    if i % 2 == 0:
        if odd_dict.get(V[i]) is None:
            odd_dict[V[i]] = 1
        else:
            odd_dict[V[i]] += 1
    else:
        if even_dict.get(V[i]) is None:
            even_dict[V[i]] = 1
        else:
            even_dict[V[i]] += 1

odd_dict_sorted = sorted(odd_dict.items(), key=lambda a: a[1])
even_dict_sorted = sorted(even_dict.items(), key=lambda a: a[1])

odd_dict_max = odd_dict_sorted.pop()
even_dict_max = even_dict_sorted.pop()
if odd_dict_max[0] == even_dict_max[0] and N // 2 == odd_dict_max[1]:
    ans = N // 2
elif odd_dict_max[0] == even_dict_max[0]:
    odd_dict_max_t = odd_dict_sorted.pop()
    even_dict_max_t = even_dict_sorted.pop()
    ans = N - odd_dict_max[0] - max(even_dict_max_t[1],odd_dict_max_t[1])
else:
    ans = N - odd_dict_max[1] - even_dict_max[1]
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
V = list(map(int, input().split()))
odd_dict = {}
even_dict = {}
for i in range(N):
    if i % 2 == 0:
        if odd_dict.get(V[i]) is None:
            odd_dict[V[i]] = 1
        else:
            odd_dict[V[i]] += 1
    else:
        if even_dict.get(V[i]) is None:
            even_dict[V[i]] = 1
        else:
            even_dict[V[i]] += 1

odd_dict_sorted = sorted(odd_dict.items(), key=lambda a: a[1])
even_dict_sorted = sorted(even_dict.items(), key=lambda a: a[1])

odd_dict_max = odd_dict_sorted.pop()
even_dict_max = even_dict_sorted.pop()
if odd_dict_max[0] == even_dict_max[0] and N // 2 == odd_dict_max[1]:
    ans = N // 2
elif odd_dict_max[0] == even_dict_max[0]:
    odd_dict_max_t = odd_dict_sorted.pop()
    even_dict_max_t = even_dict_sorted.pop()
    ans = N - odd_dict_max_t[1] - even_dict_max_t[1]
else:
    ans = N - odd_dict_max[1] - even_dict_max[1]
print(ans)

Submission status: Wrong Answer

Solution code:
import collections
N = int(input())
N_List = list(map(int,input().split()))
hanN = N//2
ki = N_List[1::2]
gu = N_List[0::2]
kicnt = collections.Counter(ki)
gucnt = collections.Counter(gu)

kidict = kicnt.most_common()
gudict = gucnt.most_common()

kilen = len(kidict)
gulen = len(gudict)

if kilen == 1 & gulen == 1:
    if kidict == gudict:
        ans = hanN
    else:
        ans = 0
elif kidict[0][0] == gudict[0][0]:
    if kidict[0][1] >= gudict[0][1]:
        ans = sum(map(lambda x:x[1],kidict[1:])) + sum(map(lambda x:x[1],gudict[2:])) + gudict[0][1]
    else:
        ans = sum(map(lambda x:x[1],gudict[1:])) + sum(map(lambda x:x[1],kidict[2:])) + kidict[0][1]

else:
    ans = sum(map(lambda x:x[1],gudict[1:])) + sum(map(lambda x:x[1],kidict[1:]))

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter


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

x = a[0]
y = b[0]
if x[0] == y[0]:
    if x[1] >= y[1]:
        if len(b) > 1:
            y = b[1]
        else:
            y = (0, 0)
    else:
        if len(a) > 0:
            x = a[1]
        else:
            x = (0, 0)
ans = (n//2) - x[1] + (n//2) - y[1]
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
N=int(input())
v=list(map(int,input().split()))
even=[]
odd=[]
for n in range(N):
    if n%2==0:
        even.append(v[n])
    else:
        odd.append(v[n])
evens=Counter(even)
odds=Counter(odd)
even_value_max=max(evens.values())
odds_value_max=max(odds.values())
even_numbers=[]
odds_numbers=[]
for key,value in evens.items():
    if value==even_value_max:
        even_numbers.append(key)
for key,value in odds.items():
    if value==odds_value_max:
        odds_numbers.append(key)
if len(evens)==1 and len(odds)==1 and v[0]==v[1]:
    answer=N//2
elif len(even_numbers)>=2 or len(odds_numbers)>=2:
    answer=N-even_value_max-odds_value_max
else:
    even=even_numbers[0]
    odd=odds_numbers[0]
    if even!=odds:
        answer=N-even_value_max-odds_value_max
    else:
        evens[even]=0
        odds[odd]=0
        if max(odds.values())>=max(evens.values()):
            answer=N-max(odds.values())-even_value_max
        else:
            answer=N-max(evens.values())-odds_value_max
print(answer)

Submission status: Wrong Answer

Solution code:
from collections import Counter
N=int(input())
v=list(map(int,input().split()))
even=[]
odd=[]
for n in range(N):
    if n%2==0:
        even.append(v[n])
    else:
        odd.append(v[n])
evens=Counter(even)
odds=Counter(odd)
if max(evens.values()) >= max(odds.values()):
    saidai = []
    lar=max(evens.values())
    for key, value in evens.items():
        if value == lar:
            saidai.append(key)
    answer = N // 2 - lar
    if len(saidai)>=2:
        answer+=(N//2-max(odds.values()))
    else:
        odds[saidai[0]]=0
        answer+=(N//2-max(odds.values()))
    print(answer)
else:
    saidai = []
    lar=max(odds.values())
    for key, value in odds.items():
        if value == lar:
            saidai.append(key)
    answer = N // 2 - max(odds.values())
    if len(saidai) >= 2:
        answer +=( N // 2 - max(evens.values()))
    else:
        evens[saidai[0]] = 0
        answer += (N // 2 - max(evens.values()))
    print(answer)

Submission status: Wrong Answer

Solution code:
from collections import Counter
N=int(input())
v=list(map(int,input().split()))
even=[]
odd=[]
for n in range(N):
    if n%2==0:
        even.append(v[n])
    else:
        odd.append(v[n])
evens=Counter(even)
odds=Counter(odd)
if max(evens.values()) >= max(odds.values()):
    saidai = []
    lar=max(evens.values())
    for key, value in evens.items():
        if value == lar:
            saidai.append(key)
    answer = N // 2 - max(evens.values())
    if len(saidai)>=2:
        answer+=N//2-max(odds.values())
    else:
        odds[saidai[0]]=0
        answer+=N//2-max(odds.values())
    print(answer)
else:
    saidai = []
    lar=max(odds.values())
    for key, value in odds.items():
        if value == lar:
            saidai.append(key)
    answer = N // 2 - max(odds.values())
    if len(saidai) >= 2:
        answer += N // 2 - max(evens.values())
    else:
        evens[saidai[0]] = 0
        answer += N // 2 - max(evens.values())
    print(answer)

Submission status: Wrong Answer

Solution code:
from collections import Counter
N=int(input())
v=list(map(int,input().split()))
even=[]
odd=[]
for n in range(N):
    if n%2==0:
        even.append(v[n])
    else:
        odd.append(v[n])
evens=Counter(even)
odds=Counter(odd)
if max(evens.values()) >= max(odds.values()):
    saidai = []
    lar=max(evens.values())
    for key, value in evens.items():
        if value == lar:
            saidai.append(key)
    answer = N // 2 - max(evens.values())
    if len(saidai)>=2:
        answer+=N//2-max(odds.values())
    else:
        odds[saidai[0]]=0
        answer+=N//2-max(odds.values())
    print(answer)
else:
    saidai = []
    lar=max(odds.values())
    for key, value in odds.items():
        if value == lar:
            saidai.append(key)
    answer = N // 2 - max(odds.values())
    if len(saidai) >= 2:
        answer += N // 2 - max(evens.values())
    else:
        odds[saidai[0]] = 0
        answer += N // 2 - max(evens.values())
    print(answer)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
v = list(map(int, input().split()))
ev = Counter([v[i] for i in range(0, n, 2)])
od = Counter([v[i] for i in range(1, n, 2)])
evk = list(ev.keys())
odk = list(od.keys())
ev_key = evk[0]
for k in evk:
    if ev[k] > ev[ev_key]:
        ev_key = k
od_key = odk[0]
for k in odk:
    if od[k] > od[ev_key]:
        od_key = k
evv = list(ev.values()) + [0]
evv.sort(reverse = True)
odv = list(od.values()) + [0]
odv.sort(reverse = True)

if ev_key != od_key:
    print(n - evv[0] - odv[0])
else:
    print(min(n - evv[0] - odv[1], n - evv[1] - odv[0]))

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
v = list(map(int, input().split()))
ev = Counter([v[i] for i in range(0, n, 2)])
od = Counter([v[i] for i in range(1, n, 2)])
evk = list(ev.keys())
odk = list(od.keys())
ev_key = evk[0]
for k in evk:
    if ev[k] > ev[ev_key]:
        ev_key = k
od_key = odk[0]
for k in odk:
    if od[k] > od[ev_key]:
        od_key = k
evv = list(ev.values()) + [0]
evv.sort(reverse = True)
odv = list(od.values()) + [0]
odv.sort(reverse = True) 
if ev_key != od_key:
    print(n - evv[0] - odv[0])
else:
    if evv[0] - evv[1] > odv[0] - odv[1]:
        print(n - evv[0] - odv[1])
    else:
        print(n - evv[1] - odv[0])

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
v = list(map(int, input().split()))
o = Counter([i for i in v[::2]]).most_common()
e = Counter([h for h in v[1::2]]).most_common()
if len(o) == 1 and len(e) == 1:
    if o[0][0] != e[0][0]:
        print(0)
    else:
        print(e[0][1])
elif len(o) == 1:
    if e[0][0] != o[0][0]:
        print(len(e)-e[0][1])
    else:
        print(len(e)-e[1][1])
elif len(e) == 1:
    if e[0][0] != o[0][0]:
        print(len(o)-o[0][1])
    else:
        print(len(o)-o[1][1])
else:
    if o[0][0] != e[0][0]:
        print(len(o)+len(e)-o[0][1]-e[0][1])
    else:
        print(min(len(o)+len(e)-o[0][1]-e[1][1],len(o)+len(e)-o[1][1]-e[0][1]))

Submission status: Wrong Answer

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

vo = v[::2]
ve = v[1::2]
ans = 0
if len(set(v))==1:
    print(len(v)//2)
    exit()
else:
    for i in range(len(v)//2-1):
        if vo[i] != vo[i+1] or ve[i] != ve[i+1]:
                   ans += 1
    print(ans)

Submission status: Wrong Answer

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

c1=collections.Counter(V[0::2]).most_common()
c2=collections.Counter(V[1::2]).most_common()
c1.append([0,0])
c2.append([0,0])
if c1[0][0]!=c2[0][0]:
    print(N-c1[0][1]-c2[0][1])
else:
    print(min(N-c1[0][1]-c2[1][0],N-c1[1][0]-c2[0][1]))

Submission status: Wrong Answer

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

import collections

c1=collections.Counter(V[0::2])
c1=sorted(c1.items(), key=lambda x: x[1], reverse=True)
e=c1[0][0]

c2=collections.Counter(V[1::2])
c2=sorted(c2.items(), key=lambda x: x[1], reverse=True)
o=c2[0][0]

if e!=o:
    cnt=sum(e!=i for i in V[0::2])
    cnt+=sum(o!=i for i in V[1::2])
else:
    if len(c1)==1 and len(c2)==1:
        cnt=N/2
    elif len(c1)==1:
        cnt=sum(e!=i for i in V[0::2])
        cnt+=sum(c2[1][0]!=i for i in V[1::2])
    elif len(c2)==1:
        cnt=sum(c1[1][0]!=i for i in V[0::2])
        cnt+=sum(o!=i for i in V[1::2])
    else:    
        cnt1=sum(e!=i for i in V[0::2])
        cnt1+=sum(c2[1][0]!=i for i in V[1::2])
        
        cnt2=sum(c1[1][0]!=i for i in V[0::2])
        cnt2+=sum(o!=i for i in V[1::2])
        cnt=min(cnt1,cnt2)
print(cnt)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
v = list(map(int, input().split()))
kisu = []
gusu = []
for i in range(n):
    if i % 2 == 0:
        kisu.append(v[i])
    else:
        gusu.append(v[i])
k = sorted(Counter(kisu).items(), key=lambda x: x[1], reverse=True)
g = sorted(Counter(gusu).items(), key=lambda x: x[1], reverse=True)
ans1 = 0
ans2 = 0
#print(k, g)
if k[0][0] == g[0][0]:
    if k[0][1] >= g[0][1]:
        ans1 = (n//2) - k[0][1]
        if len(g) < 2:
            ans2 = n // 2
        else:
            ans2 = (n//2) - g[1][1]
    else:
        ans1 = (n//2) - g[0][1]
        if len(k) < 2:
            ans2 = n // 2
        else:
            ans2 = (n//2) - k[1][1]
else:
    ans1 = (n // 2) - k[0][1]
    ans2 = (n // 2) - g[0][1]
print(ans1 + ans2)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
v = list(map(int, input().split()))
kisu = []
gusu = []
for i in range(n):
    if i % 2 == 0:
        kisu.append(v[i])
    else:
        gusu.append(v[i])
k = sorted(Counter(kisu).items(), key=lambda x: x[1])
g = sorted(Counter(gusu).items(), key=lambda x: x[1])
ans1 = 0
ans2 = 0
#print(k, g)
if k[0][0] == g[0][0]:
    if k[0][1] >= g[0][1]:
        ans1 = (n//2) - k[0][1]
        if len(g) < 2:
            ans2 = n // 2
        else:
            ans2 = (n//2) - g[1][1]
    else:
        ans1 = (n//2) - g[0][1]
        if len(k) < 2:
            ans2 = n // 2
        else:
            ans2 = (n//2) - k[1][1]
else:
    ans1 = (n // 2) - k[0][1]
    ans2 = (n // 2) - g[0][1]
print(ans1 + ans2)

Submission status: Wrong Answer

Solution code:

from collections import Counter

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

evens = Counter(X[::2])
odds = Counter(X[1::2])

cnt_evens = sorted(evens.items(), key=lambda x: -x[1])
cnt_odds = sorted(odds.items(), key=lambda x: -x[1])

res = sum(odds.values()) - max(odds.values())
if cnt_evens[0][1] == cnt_odds[0][1]:
    if len(cnt_evens) == 1:
        res += sum(evens.values())
    else:
        res += sum(evens.values()) - cnt_evens[1][1]
else:
    res += sum(evens.values()) - max(evens.values())

print(res)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
l1=[0]*100001
l2=[0]*100001
if a.count(a[0])==n:
    print(n//2)
    exit()

for i in range(0,n,2):
    l1[a[i]]+=1
for i in range(1,n,2):
    l2[a[i]]+=1
l1.sort(reverse=True)
l2.sort(reverse=True)
#print(l1,l2)
ans=((n//2-l1[0])+(n//2-l2[0]))
print(ans)

Submission status: Wrong Answer

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

e = Counter(v[0::2]).most_common()
o = Counter(v[1::2]).most_common()

ans = 0
if e[0][0] != o[0][0]:
  for i in range(1, len(e)): ans += e[i][1]
  for i in range(1, len(o)): ans += o[i][1]
  print(ans)
else:
  for i in range(1, len(e)): ans += e[i][1]
  for i in range(len(o)):
    if i == 1: continue
    ans += o[i][1]
    print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
N=int(input())
v=list(map(int,input().split()))
even=[]
odd=[]
for n in range(N):
    if n%2==0:
        even.append(v[n])
    else:
        odd.append(v[n])
evens=Counter(even)
odds=Counter(odd)
if max(evens.values()) >= max(odds.values()):
    saidai = []
    for key, value in evens.items():
        if value == max(evens.values()):
            saidai.append(key)
    answer = N // 2 - max(evens.values())
    if len(saidai)>=2:
        answer+=N//2-max(odds.values())
    else:
        odds[saidai[0]]=0
        answer+=N//2-max(odds.values())
    print(answer)
else:
    saidai = []
    for key, value in odds.items():
        if value == max(odds.values()):
            saidai.append(key)
    answer = N // 2 - max(odds.values())
    if len(saidai) >= 2:
        answer += N // 2 - max(evens.values())
    else:
        odds[saidai[0]] = 0
        answer += N // 2 - max(evens.values())
    print(answer)

Submission status: Wrong Answer

Solution code:
from collections import Counter
N=int(input())
v=list(map(int,input().split()))
even=[]
odd=[]
for n in range(N):
    if n%2==0:
        even.append(v[n])
    else:
        odd.append(v[n])
evens=Counter(even)
odds=Counter(odd)
if len(evens)==1 and len(odds)==1 and v[0]!=v[1]:
    print(0)
elif len(evens)==1 and len(odds)==1 and v[0]!=v[1]:
    print(N//2)
elif len(evens)==1:
    number=0
    for key,value in odds.items():
        if key==v[0]:
            pass
        else:
            number=max(number,value)
    print(number)
elif len(odds)==1:
    number = 0
    for key, value in evens.items():
        if key == v[1]:
            pass
        else:
            number = max(number, value)
    print(N//2-number)
else:
    if max(evens.values()) >= max(odds.values()):
        saidai=[]
        for key,value in evens.items():
            if value==max(evens.values()):
                saidai.append(key)
        answer=N//2-max(evens.values())
        number=0
        for key,value in odds.items():
            if not key in saidai or len(saidai)>=2:
                number=max(number,value)
        answer+=N//2-number
        print(answer)
    else:
        saidai = []
        for key, value in odds.items():
            if value == max(odds.values()):
                saidai.append(key)
        answer = N//2-max(odds.values())
        number = 0
        for key, value in evens.items():
            if not key in saidai or len(saidai) >= 2:
                number = max(number, value)
        answer += N // 2 - number
        print(answer)

Submission status: Wrong Answer

Solution code:
from collections import Counter
N=int(input())
v=list(map(int,input().split()))
even=[]
odd=[]
for n in range(N):
    if n%2==0:
        even.append(v[n])
    else:
        odd.append(v[n])
evens=Counter(even)
odds=Counter(odd)
if max(evens.values()) >= max(odds.values()):
    saidai = []
    for key, value in evens.items():
        if value == max(evens.values()):
            saidai.append(key)
    answer = N // 2 - max(evens.values())
    number = 0
    for key, value in odds.items():
        if not key in saidai or len(saidai) >= 2:
            number = max(number, value)
    answer += N // 2 - number
    print(answer)
else:
    saidai = []
    for key, value in odds.items():
        if value == max(odds.values()):
            saidai.append(key)
    answer = N // 2 - max(odds.values())
    number = 0
    for key, value in evens.items():
        if not key in saidai or len(saidai) >= 2:
            number = max(number, value)
    answer += N // 2 - number
    print(answer)

Submission status: Wrong Answer

Solution code:
from collections import *
n=int(input())
l=list(map(int,input().split()))
x,y=[],[]
c=0
for i in range(0,n,2):
    x.append(l[i])
for i in range(1,n,2):
    y.append(l[i])
xx=-1
if(len(set(x))==1):
    xx=x[0]
else:
    d=defaultdict(int)
    for i in x:
        d[i]+=1
    m=0
    xx=-1
    for i in d:
        if(d[i]>m):
            xx=i
            m=d[i]
    c+=sum(d.values())-m
if(len(set(y))>1 or (len(set(y))==1 and y[0]==xx)):
    d=defaultdict(int)
    for i in y:
        d[i]+=1
    m=0
    yy=-1
    for i in d:
        if(d[i]>m and i!=xx):
            yy=i
            m=d[i]
    c+=sum(d.values())-m
print(c)

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
v = list(map(int,input().split()))
v_gu = collections.deque()
v_ki = collections.deque()
for i in range(n):
    if i%2==0:
        v_gu.append(v[i])
    else:
        v_ki.append(v[i])
gu_list = collections.Counter(v_gu)
ki_list = collections.Counter(v_ki)
#print(gu_list)
#print(ki_list)
if len(gu_list)==1 and len(ki_list)==1:
    if gu_list.most_common()[0][0]==ki_list.most_common()[0][0]:
        print(gu_list.most_common()[0][1])
    else:
        print(0)
elif len(gu_list)==1:
    if gu_list.most_common()[0][0]==ki_list.most_common()[0][0]:
        print(n//2 - ki_list.most_common()[1][1])
    else:
        print(n//2 - ki_list.most_common()[0][1])
elif len(ki_list)==1:
    if gu_list.most_common()[0][0]==ki_list.most_common()[0][0]:
        print(n//2 - gu_list.most_common()[1][1])
    else:
        print(n//2 - gu_list.most_common()[0][1])
else:
    if gu_list.most_common()[0][0]==ki_list.most_common()[0][0]:
        if gu_list.most_common()[0][1]>ki_list.most_common()[0][1]:
            print((n//2 - gu_list.most_common()[0][1]) + (n//2 - ki_list.most_common()[1][1]))
        else:
            print((n//2 - gu_list.most_common()[1][1]) + (n//2 - ki_list.most_common()[0][1]))
    else:
        print((n//2 - gu_list.most_common()[0][0]) + (n//2 - ki_list.most_common()[0][0]))

Submission status: Wrong Answer

Solution code:
def main():
    import collections
    n = int(input())
    v = list(map(int,input().split()))
    f,s = [], []
    for i in range(n):
        if i%2==0:
            f.append(v[i])
        else:
            s.append(v[i])
    f = collections.Counter(f)
    s = collections.Counter(s)
    if max(f)!=max(s):
        print(n-f[max(f)]-s[max(s)])
    else:
        if f[max(f)]>s[max(s)]:
            s[max(s)] = 0
            print(n-f[max(f)]-s[max(s)])
        else:
            f[max(f)] = 0
            print(n-f[max(f)]-s[max(s)])

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

if len(set(v)) == 2:
    if len(set(v[::2])) == 1 and len(set(v[1::2])) == 1:
        print(0)
    elif len(set(v[::2])) != 1 and len(set(v[1::2])) != 1:
        for i in range(0,n-2,2):
            if v[i] != v[i+2]:
                ans += 1
        for j in range(1,n-2,2):
            if v[j] != v[j+2]:
                ans += 1
        print(ans)
    elif len(set(v[::2])) != 1:
        for i in range(0,n-2,2):
            if v[i] != v[i+2]:
                ans += 1
        print(ans)
    else:
        for j in range(1,n-2,2):
            if v[j] != v[j+2]:
                ans += 1
        print(ans)

elif len(set(v)) == 1:
    ans = len(v)//2
    if len(set(v[::2])) == 1 and len(set(v[1::2])) == 1:
        print(ans)
        
    elif len(set(v[::2])) != 1 and len(set(v[1::2])) != 1:
        for i in range(0,n-2,2):
            if v[i] != v[i+2]:
                ans += 1
        for j in range(1,n-2,2):
            if v[j] != v[j+2]:
                ans += 1
        print(ans)
    elif len(set(v[::2])) != 1:
        for i in range(0,n-2,2):
            if v[i] != v[i+2]:
                ans += 1
        print(ans)
    else:
        for j in range(1,n-2,2):
            if v[j] != v[j+2]:
                ans += 1
        print(ans)



else:
    dic = {}
    for i in range(n):
        if v[i] not in dic:
            dic[v[i]] = 1
        else:
            dic[v[i]] += 1
    dic = sorted(dic.items(),key = lambda x:x[1])
    for i in range(len(dic)-2):
        ans += dic[i][1]
    print(ans)

Submission status: Wrong Answer

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

if len(set(v)) == 2:
    print(0)
elif len(set(v)) == 1:
    print(len(v)//2)
else:
    dic = {}
    for i in range(n):
        if v[i] not in dic:
            dic[v[i]] = 1
        else:
            dic[v[i]] += 1
    dic = sorted(dic.items(),key = lambda x:x[1])
    for i in range(len(dic)-2):
        ans += dic[i][1]
    print(ans)

Submission status: Wrong Answer

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

count = np.zeros(10**5, dtype=int)
for i in range(n):
  idx = v[i]
  count[idx-1] += 1
count = sorted(count, reverse=True)

total = count[0] + count[1]
if total == n:
  if count[0] == count[1]:
    print(0)
  else:
    print(abs(count[0]-count[1])//2)
else:
  print(n-total)

Submission status: Wrong Answer

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

eq_lis = []
odd_lis = []
for i in range(n):
    if i %2 ==0:
        eq_lis.append(vs[i])
    else:
        odd_lis.append(vs[i])
        
a = Counter(eq_lis)
b = Counter(odd_lis)
if max(list(a.values()))==max(list(b.values())):
    ans_a = list(a.values())
    ans_a.sort()
    ans_b = list(b.values())
    ans_b.sort()
    #print(ans_a)
    #print(ans_b)
    if len(ans_a) != 1 or len(ans_b)!=1: 
        if ans_a[-2] >=ans_b[-2]:
            print(n-ans_a[-2]-ans_b[-1])
        else:
            print(n-ans_a[-1]-ans_b[-2])
    else:
        print(n-ans_a[0])
    

else:
    print(n-max(list(a.values()))-max(list(b.values())))

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
vs = list(map(int, input().split()))
ans = 0
eq_lis = []
odd_lis = []
for i in range(n):
    if i %2 ==0:
        eq_lis.append(vs[i])
    else:
        odd_lis.append(vs[i])
        
a = Counter(eq_lis)
b = Counter(odd_lis)
print(n-max(list(a.values()))-max(list(b.values())))

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
m = n // 2
v = list(map(int,input().split()))
a = Counter(v[::2])
b = Counter(v[1::2])
akey = list(a.keys())
avalues = list(a.values())
avalues.append(0)
bkey = list(b.keys())
bvalues = list(b.values())
bvalues.append(0)
if akey[0] != bkey[0]:
    print((m - avalues[0]) + (m - bvalues[0]))
else:
    print(min((m - avalues[0]) + (m - bvalues[1]),(m - avalues[1]) + (m - bvalues[0])))

Submission status: Wrong Answer

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

v_even = [0]*100000
v_odd = [0]*100000

for i in range(n):
  if i%2==0:
    v_even[v[i]-1] += 1 
  else:
    v_odd[v[i]-1] += 1
    
res1 = max(v_even)
res2 = max(v_odd)
if v_even.index(res1) == v_odd.index(res2):
  if res1 >= res2:
    v_odd[v_odd.index(res2)] = 0
    res2 = max(v_odd)
  else:
    v_even[v_even.index(res1)] = 0
    res1 = max(v_even)
print(n//2-res1 + n//2-res2)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

v0=list(Counter(v[::2]).items())
v1=list(Counter(v[1::2]).items())

v0.sort(key=lambda x:x[1],reverse=True)
v1.sort(key=lambda x:x[1],reverse=True)

k0,ma0=v0[0]
k1,ma1=v1[0]

if k0==k1 and len(v0)==1 and len(v1)==1:
    print(n//2)
elif k0==k1 and len(v0)==1:
    print((n+1)//2-v1[1][1])
elif k0==k1 and len(v1)==1:
    print(n//2-v0[1][1])
elif k0==k1:
    print(min((n+1)//2-v1[1][1],n//2-v0[1][1]))
else:
    print((n+1)//2-ma0+n//2-ma1)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

v0=list(Counter(v[::2]).items())
v1=list(Counter(v[1::2]).items())

v0.sort(key=lambda x:x[1],reverse=True)
v1.sort(key=lambda x:x[1],reverse=True)

k0,ma0=v0[0]
k1,ma1=v1[0]

if k0==k1 and len(v0)==1 and len(v1)==1:
    print(n//2)
elif k0==k1 and len(v0)==1:
    print((n+1)//2-v1[1][1])
elif k0==k1 and len(v1)==1:
    print(n//2-v0[1][1])
elif k0==k1:
    print(max((n+1)//2-v1[1][1],n//2-v0[1][1]))
else:
    print((n+1)//2-ma0+n//2-ma1)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

m1=max(list(Counter(v[::2]).values()))
m2=max(list(Counter(v[1::2]).values()))

print((n+1)//2-m1+n//2-m2)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
v = list(map(int, input().split()))
v1 = Counter(v).most_common()
if len(v1) == 1:
    print(n//2)
elif len(v1) == 2 and abs(v1[0][1]-v1[1][1]) <= 1:
    print(0)
else:
    o = [v[i] for i in range(0,n,2)]
    e = [v[h] for h in range(1,n,2)]
    o1 = Counter(o).most_common()
    e1 = Counter(e).most_common()
    print(len(o)-o1[0][1] + len(e)-e1[0][1])

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
v = list(map(int, input().split()))
v = Counter(v).most_common()
if len(v) == 1:
    print(n//2)
elif len(v) == 2 and abs(v[0][1]-v[1][1]) <= 1:
    print(0)
else:
    print(n-v[0][1]-v[1][1])

Submission status: Wrong Answer

Solution code:
n = int(input())
l = list(map(int, input().split()))
a = {}
b = {}
for i in range(n // 2):
    key_a = l[i * 2]
    key_b = l[i * 2 + 1]
    if key_a in a:
        a[key_a] = a[key_a] + 1
    else:
        a[l[i * 2]] = 1
    if key_b in b:
        b[key_b] = b[key_b] + 1
    else:
        b[key_b] = 1
sorted(a.items(), key=lambda x: x[1], reverse=True)
sorted(b.items(), key=lambda x: x[1], reverse=True)
a = list(a.items())
b = list(b.items())
ca_max = a[0]
cb_max = b[0]
ca_max_num = a[0][1]
cb_max_num = b[0][1]
same_num = ca_max_num + cb_max_num
if ca_max[0] == cb_max[0]:
    if len(a) > 1:
        next_ca_max = a[1][1]
    else:
        next_ca_max = 0
    if len(b) > 1:
        next_cb_max = b[1][1]
    else:
        next_cb_max = 0
    same_num = max(ca_max_num + next_cb_max, cb_max_num + next_ca_max)
print(n - same_num)