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()))

odds = []
evens = []

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

evens_c = Counter(evens).most_common()
odds_c = Counter(odds).most_common()


if evens_c[0][0] != odds_c[0][0]:
    print(n - evens_c[0][1] - odds_c[0][1])
    exit()

cands = []

if len(evens_c) > 1:
    cands.append(n - evens_c[1][1] - odds_c[0][1])
if len(odds_c) > 1:
    cands.append(n - evens_c[0][1] - odds_c[1][1])

cands.append(n // 2)

print(max(cands))

Submission status: Wrong Answer

Solution code:
from collections import Counter

n = int(input())

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

odds = []
evens = []

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

evens_c = Counter(evens).most_common()
odds_c = Counter(odds).most_common()

ans = n

fl = 0

if evens_c[0][0] != odds_c[0][0]:
    print(n - evens_c[0][1] - odds_c[0][1])
    exit()

cands = []

if len(evens_c) > 1:
    cands.append(n - evens_c[1][1] - odds_c[0][1])
if len(odds_c) > 1:
    cands.append(n - evens_c[0][1] - odds_c[1][1])

cands.append(n // 2)

print(min(cands))

Submission status: Wrong Answer

Solution code:
from collections import Counter

n = int(input())

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

odds = []
evens = []

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

evens_c = Counter(evens).most_common()
odds_c = Counter(odds).most_common()

ans = n

fl = 0
for i in range(len(evens_c)):
    for j in range(len(odds_c)):
        fl = 0
        try:
            if evens_c[i][0] != odds_c[j][0]:
                ans = min(ans, n - evens_c[i][1] - odds_c[j][1])
                fl = 1
        except:
            continue

if fl == 1:
    print(ans)
    exit()
print(n // 2)

Submission status: Wrong Answer

Solution code:
from collections import Counter

n = int(input())

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

odds = []
evens = []

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

evens_c = Counter(evens).most_common()
odds_c = Counter(odds).most_common()

ans = 0

fl = 0
for i in range(len(evens_c)):
    for j in range(len(odds_c)):
        fl = 0
        try:
            if evens_c[i][0] != odds_c[j][0]:
                ans = min(ans, n - evens_c[i][1] - odds_c[j][1])
                fl = 1
        except:
            continue

if fl == 1:
    print(ans)
    exit()
print(n // 2)

Submission status: Wrong Answer

Solution code:
from collections import Counter

n = int(input())

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

odds = []
evens = []

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

evens_c = Counter(evens).most_common()
odds_c = Counter(odds).most_common()

ans = 0

fl = 0
for i in range(len(evens_c)):
    for j in range(len(odds_c)):
        fl = 0
        try:
            if evens_c[i][0] != odds_c[j][0]:
                ans = max(ans, n - evens_c[i][1] - odds_c[j][1])
                fl = 1
        except:
            continue

if fl == 1:
    print(ans)
    exit()
print(n // 2)

Submission status: Wrong Answer

Solution code:
from collections import Counter

n = int(input())

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

odds = []
evens = []

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

evens_c = Counter(evens).most_common()
odds_c = Counter(odds).most_common()

ans = 0
for i in range(len(evens_c)):
    for j in range(len(odds_c)):
        fl = 0
        try:
            if evens_c[i][0] != odds_c[j][0]:
                ans = max(ans, n - evens_c[i][1] - odds_c[j][1])
                fl = 1
        except:
            continue

print(n // 2)

Submission status: Wrong Answer

Solution code:
from collections import Counter

n = int(input())

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

odds = []
evens = []

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

evens_c = Counter(evens).most_common()
odds_c = Counter(odds).most_common()


for i in range(len(evens_c)):
    for j in range(len(odds_c)):
        fl = 0
        try:
            if evens_c[i][0] != odds_c[j][0]:
                print(n - evens_c[i][1] - odds_c[j][1])
                fl = 1
        except:
            continue
        finally:
            if fl == 1:
                exit()

print(n//2)

Submission status: Wrong Answer

Solution code:
from collections import Counter

n = int(input())

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

odds = []
evens = []

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

evens_c = Counter(evens).most_common()
odds_c = Counter(odds).most_common()

fl = 0
for i in range(len(evens_c)):
    for j in range(len(odds_c)):
        try:
            if evens_c[i][0] != odds_c[j][0]:
                print(n - evens_c[i][1] - odds_c[j][1])
                fl = 1
                exit()
        except:
            continue
if fl==0:
    print(n//2)

Submission status: Wrong Answer

Solution code:
from collections import Counter

n = int(input())

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

odds = []
evens = []

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

evens_c = Counter(evens).most_common()
odds_c = Counter(odds).most_common()

fl = 0
for i in range(len(evens_c)):
    for j in range(len(odds_c)):
        try:
            if evens_c[i][0] != odds_c[j][0]:
                print(n - odds_c[0][1] - evens_c[0][1])
                fl = 1
                exit()
        except:
            continue
if fl==0:
    print(n//2)

Submission status: Wrong Answer

Solution code:
import collections

N=int(input())
A=[0]*(N//2)
B=[0]*(N//2)
for i,j in enumerate(input().split()):
	if i%2:B[i//2]=int(j)
	else:A[i//2]=int(j)

ca=collections.Counter(A)
cb=collections.Counter(B)

ans=0
for i,j in zip(ca,cb):
	if ca[i] >= cb[j]:
		ans += N//2 - ca[i]
		t=cb
		k=i
	else:
		ans+=N//2 - cb[i]
		t=ca
		k=i


f=True
for i in t:
	if i!=k:
		ans+=N//2 - t[i]
		f=False
		break

if f:ans+=N//2

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    n=int(input()) # even
    V=list(map(int,input().split()))
    # 1種類しかないときはindexの関係上別処理する
    if len(set(V))==1:
        print(n//2)
        return
    from collections import Counter
    E=Counter(V[::2]).most_common() # list of tuple
    O=Counter(V[1::2]).most_common()
    if E[0][0]!=O[0][0]:
        print(n-E[0][1]-O[0][1])
    elif E[0][1]>=O[0][1]:
        print(n-E[0][1]-O[1][1])
    else:
        print(n-E[1][1]-O[0][1])
resolve()

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    n=int(input()) # even
    V=list(map(int,input().split()))
    if len(set(V))==1:
        print(n//2)
        return
    from collections import Counter
    E=Counter(V[::2])
    O=Counter(V[1::2])
    e=max(E.values())
    o=max(O.values())
    print(n-e-o)
resolve()

Submission status: Wrong Answer

Solution code:
import collections

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


odd=collections.Counter(v[::2])
even = collections.Counter(v[1::2])

if len(odd)==len(even) and odd.most_common()[0]==even.most_common()[0]:
	print(n//2)
elif odd.most_common()[0][0]==even.most_common()[0][0]:
	if len(odd)==1:
		print((n//2-odd.most_common()[0][1])+(n//2-even.most_common()[1][1]))
	elif len(even)==1:
		print((n//2-odd.most_common()[1][1])+(n//2-even.most_common()[0][1]))
	else:
		print(min((n//2-odd.most_common()[0][1])+(n//2-even.most_common()[1][1]), (n//2-odd.most_common()[1][1])+(n//2-even.most_common()[0][1])))
else:
	print((n//2-odd.most_common()[0][1])+(n//2-even.most_common()[0][1]))

Submission status: Wrong Answer

Solution code:
import collections

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


odd=collections.Counter(v[::2])
even = collections.Counter(v[1::2])

if len(odd)==len(even) and odd.most_common()[0]==even.most_common()[0]:
	print(n//2)
else:
	print((n//2-odd.most_common()[0][1])+(n//2-even.most_common()[0][1]))

Submission status: Wrong Answer

Solution code:
import collections

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


odd=collections.Counter(v[::2])
even = collections.Counter(v[1::2])

if len(odd)==len(even) and odd.most_common()[0]==even.most_common()[0]:
	print(n//2)
else:
	print(max((n//2-odd.most_common()[0][1]), (n//2-even.most_common()[0][1])))

Submission status: Wrong Answer

Solution code:
import numpy as np

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

list1=[0]*(1+10**5)
list2=[0]*(1+10**5)

for i in range(0, n, 2):
  list1[v[i]]+=1
  
for i in range(1, n, 2):
  list2[v[i]]+=1
  
n1=np.max(list1)
m1=np.argmax(list1)
n2=np.max(list2)
m2=np.argmax(list2)

if m1!=m2:
  print(n-(n1+n2))
else:
  list1[m1]=0
  list2[m2]=0
  n12=np.max(list1)
  n22=np.max(list2)
  print(min(n1+n22, n2+n12))

Submission status: Wrong Answer

Solution code:
import collections

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


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

vc_odd = collections.Counter(v_odd)
vc_even = collections.Counter(v_even)

odd_common = vc_odd.most_common()
even_common = vc_even.most_common()
if odd_common[0][0] != even_common[0][0]:
    print(n - odd_common[0][1] - even_common[0][1])
else:
    if len(odd_common) == 1 and len(even_common) == 1:
        print(len(v_even))
    elif len(odd_common) == 1:
        print(n - odd_common[0][1] - even_common[1][1])
    elif len(even_common) == 1:
        print(n - odd_common[1][1], even_common[0][1])
    else:
        cnt1 = n - odd_common[1][1], even_common[0][1]
        cnt2 = n - odd_common[0][1], even_common[1][1]
        print(min(cnt1, cnt2))

Submission status: Wrong Answer

Solution code:
import collections

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


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

def calc_sum(odd_v, even_v):
    sum = 0
    for v in v_odd:
        sum += abs(v - odd_v)
    for v in v_even:
        sum += abs(v - even_v)
    return sum

vc_odd = collections.Counter(v_odd)
vc_even = collections.Counter(v_even)

odd_common = vc_odd.most_common()
even_common = vc_even.most_common()
if odd_common[0][0] != even_common[0][0]:
    print(calc_sum(odd_common[0][0], even_common[0][0]))
else:
    if len(odd_common) == 1 and len(even_common) == 1:
        print(len(v_even))
    elif len(odd_common) == 1:
        print(calc_sum(odd_common[0][0], even_common[1][0]))
    elif len(even_common) == 1:
        print(calc_sum(odd_common[1][0], even_common[0][0]))
    else:
        cnt1 = calc_sum(odd_common[1][0], even_common[1][0])
        cnt2 = calc_sum(odd_common[0][1], even_common[1][0])
        print(min(cnt1, cnt2))

Submission status: Wrong Answer

Solution code:
import collections

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


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

def calc_sum(odd_v, even_v):
    sum = 0
    for v in v_odd:
        sum += abs(v - odd_v)
    for v in v_even:
        sum += abs(v - even_v)
    return sum

vc_odd = collections.Counter(v_odd)
vc_even = collections.Counter(v_even)

odd_common = vc_odd.most_common()
even_common = vc_even.most_common()
if odd_common[0][0] != even_common[0][0]:
    print(calc_sum(odd_common[0][0], even_common[0][0]))
else:
    if len(odd_common) == 1 and len(even_common) == 1:
        print(len(v_even))
    elif len(odd_common) == 1:
        print(calc_sum(odd_common[0][0], even_common[1][0]))
    else:
        print(calc_sum(odd_common[1][0], even_common[0][0]))

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

from collections import Counter as C
n=int(input())
l=list(map(int,input().split()))
odd=[0]
even=[0]
#odd
for i in range(0,n-1,2):
    odd.append(l[i])
odd=C(odd)
ele1=n//2-odd.most_common()[0][1]
check1=odd.most_common()[0]
#even
for _ in range(1,n,2):
    even.append(l[_])
even=C(even)
ele2=n//2-even.most_common()[0][1]
check2=even.most_common()[0]
if check1[0]==check2[0]:
    if check1[1]>=check2[1]:
        ele2=n//2-even.most_common()[1][1]
        if even.most_common()[1][0]==0:
            ele2=n//2
    else:
        ele1=n//2-odd.most_common()[1][1]
        if odd.most_common()[1][0]==0:
            ele1=n//2
print(ele1+ele2)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

from collections import Counter as C
n=int(input())
l=list(map(int,input().split()))
odd=[]
even=[0]
#odd
for i in range(0,n-1,2):
    odd.append(l[i])
odd=C(odd)
ele1=n//2-odd.most_common()[0][1]
check1=odd.most_common()[0][0]
#even
for _ in range(1,n,2):
    even.append(l[_])
even=C(even)
ele2=n//2-even.most_common()[0][1]
check2=even.most_common()[0][0]
if check1==check2:
    ele2=n//2-even.most_common()[1][1]
    if even.most_common()[1][0]==0:
        ele2=n//2
print(ele1+ele2)

Submission status: Wrong Answer

Solution code:
import collections

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

even = []
odd = []
for i in range(n):
    if i % 2 == 0:
        even.append(v[i])
    else:
        odd.append(v[i])
evenc = collections.Counter(even)
oddc = collections.Counter(odd)
#print(evenc, oddc)

evenm = evenc.most_common()
oddm = oddc.most_common()
if evenm[0][0] == oddm[0][0]:
    if len(oddm) == 1:
        ans = n // 2
    else:
        ans = n - evenm[0][1] - oddm[1][1]
else:
    ans = n - evenm[0][1] - oddm[0][1]
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
v = list(map(int, input().split()))
even_list = [0] * (n + 1)
odd_list = [0] * (n + 1)

for i in range(n):
    if i % 2 == 0:
        even_list[i] += 1

    else:
        odd_list[i] += 1

if even_list.index(max(even_list)) == odd_list.index(max(odd_list)):
    even_sorted, odd_sorted = sorted(even_list), sorted(odd_list)
    print(min(n - even_sorted[-1] - odd_sorted[-2], n - even_sorted[-2] - odd_sorted[-1]))

else:
    print(n - max(even_list) - max(odd_list))

Submission status: Wrong Answer

Solution code:
n = int(input())
v = list(map(int, input().split()))
even_list = [0] * (n + 1)
odd_list = [0] * (n + 1)

for i in range(n):
    if i % 2 == 0:
        even_list[i] += 1

    else:
        odd_list[i] += 1

if even_list.index(max(even_list)) == odd_list.index(max(odd_list)):
    even_sorted, odd_sorted = sorted(even_list), sorted(odd_list)
    print(n - min(even_sorted[-1] - odd_sorted[-2], n - even_sorted[-2] - odd_sorted[-1]))

else:
    print(n - max(even_list) - max(odd_list))

Submission status: Wrong Answer

Solution code:
n = int(input())
v = list(map(int, input().split()))
even_list = [0] * (n + 1)
odd_list = [0] * (n + 1)

for i in range(n):
    if i % 2 == 0:
        even_list[i] += 1

    else:
        odd_list[i] += 1

if even_list.index(max(even_list)) == odd_list.index(max(odd_list)):
    even_sorted, odd_sorted = sorted(even_list), sorted(odd_list)
    print(min(even_sorted[-1] + odd_sorted[-2], even_sorted[-2] + odd_sorted[-1]))

else:
    print(n - max(even_list) - max(odd_list))

Submission status: Wrong Answer

Solution code:
from collections import Counter
if __name__ == '__main__':
    N = int(input())
    V = list(map(int, input().split()))
    V_low = []
    V_up = []
    for i, v in enumerate(V):
        if i%2 == 0:
            V_low.append(v)
        else:
            V_up.append(v)
    

    count_low = Counter(V_low).most_common()
    count_up = Counter(V_up).most_common()
    
    low_most = count_low[0][0]
    up_most = count_up[0][0]
    
    if low_most != up_most:
        print(len(V_low) + len(V_up) - count_low[0][1] - count_up[0][1])
    else:
        if count_low[0][1] >= count_up[0][1]:
            if(len(count_up) == 1):
                print(len(V_low) + len(V_up) - count_low[0][1])
            else:
                print(len(V_low) + len(V_up) - count_low[0][1] - count_up[1][1])
        else:
            if(len(count_low) == 1):
                print(len(V_low) + len(V_up) - count_up[0][1])
            else:
                print(len(V_low) + len(V_up) - count_up[0][1] - count_low[1][1])

Submission status: Wrong Answer

Solution code:
from collections import Counter
if __name__ == '__main__':
    N = int(input())
    V = list(map(int, input().split()))
    V_low = []
    V_up = []
    for i, v in enumerate(V):
        if i%2 == 0:
            V_low.append(v)
        else:
            V_up.append(v)
    

    count_low = Counter(V_low).most_common()
    count_up = Counter(V_up).most_common()
    
    low_most = count_low[0][0]
    up_most = count_up[0][0]
    
    if low_most != up_most:
        print(len(V_low) + len(V_up) - count_low[0][1] - count_up[0][1])
    else:
        if count_low >= count_up:
            if(len(count_up) == 1):
                print(len(V_low) + len(V_up) - count_low[0][1])
            else:
                print(len(V_low) + len(V_up) - count_low[0][1] - count_up[1][1])
        else:
            if(len(count_low) == 1):
                print(len(V_low) + len(V_up) - count_up[0][1])
            else:
                print(len(V_low) + len(V_up) - count_up[0][1] - count_low[1][1])

Submission status: Wrong Answer

Solution code:
n=int(input())

seq=list(map(int,input().split()))
oddlist=[]
evenlist=[]

for i in range(n):
    if ( i+1)%2!=0:
    
        oddlist.append(seq[i])
    else:    
        evenlist.append(seq[i])
print(seq)
print(oddlist)
print(evenlist)
maxi=n/2
mini=n/2
if oddlist!=evenlist:
    for j in set(evenlist):
        if evenlist.count(j)==int(n/2):
            maxi=0
        else:
            if evenlist.count(j)<maxi:
                maxi=evenlist.count(j)
            else:
                maxi=maxi

    for k in set(oddlist):
        if oddlist.count(k)==int(n/2):
            mini=0
        else:
        
            if oddlist.count(k)<mini:
                mini=oddlist.count(k)
            else:
                mini=mini
    
    print(maxi+mini)    
else:
    print(2)

Submission status: Wrong Answer

Solution code:
from collections import Counter

def find_key_from_value(input_dict, target_value):
  return  [key for key, value in input_dict.items() if value == target_value][0]

N = int(input())
V= list(map(int,input().split()))
eve, odd  = Counter([V[i] for i in range(0,N,2)]), Counter([V[i] for i in range(1,N,2)])

ms_eve = eve.most_common()
ms_odd = odd.most_common()

if  len(ms_eve) == 1 and len(ms_odd) == 1 and ms_eve[0][0] == ms_odd[0][0]: print(N//2)
else: print(N-ms_eve[0][1]-ms_odd[0][1])

Submission status: Wrong Answer

Solution code:
from collections import Counter

def find_key_from_value(input_dict, target_value):
  return  [key for key, value in input_dict.items() if value == target_value][0]

N = int(input())
V= list(map(int,input().split()))
eve, odd  = Counter([V[i] for i in range(0,N,2)]), Counter([V[i] for i in range(1,N,2)])

eve_key = find_key_from_value(eve, max(eve.values()))
odd_key = find_key_from_value(odd, max(odd.values()))

if eve_key == odd_key: print(eve[eve_key])
else: print(N-eve[eve_key]-odd[odd_key])

Submission status: Wrong Answer

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

even_map = {}
odd_map = {}

for i in range(0, n, 2):
    v = V[i]
    if not v in even_map:
        even_map[v] = 1
    else:
        even_map[v] += 1


for i in range(1, n, 2):
    v = V[i]
    if not v in odd_map:
        odd_map[v] = 1
    else:
        odd_map[v] += 1

even_sorted = sorted(even_map.items(), key=lambda x: x[1])
odd_sorted = sorted(odd_map.items(), key=lambda x: x[1])

even1 = even_sorted[0][0]
odd1 = odd_sorted[0][0]

if even1 != odd1:
    print(n - (even_sorted[0][1] + odd_sorted[0][1]))
    exit()

l = []
if len(odd_sorted) != 1:
    l.append(n - (even_sorted[0][1] + odd_sorted[1][1]))
else:
    l.append(n - even_sorted[0][1])

if len(even_sorted) != 1:
    l.append(n - (odd_sorted[0][1] + even_sorted[1][1]))
else:
    l.append(n - odd_sorted[0][1])

print(min(l))

Submission status: Wrong Answer

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

even_map = {}
odd_map = {}

for i in range(0, n, 2):
    v = V[i]
    if not v in even_map:
        even_map[v] = 1
    else:
        even_map[v] += 1


for i in range(1, n, 2):
    v = V[i]
    if not v in odd_map:
        odd_map[v] = 1
    else:
        odd_map[v] += 1

even_sorted = sorted(even_map.items(), key=lambda x: x[1])
odd_sorted = sorted(odd_map.items(), key=lambda x: x[1])

even1 = even_sorted[0][0]
odd1 = odd_sorted[0][0]

if even1 != odd1:
    print(n - (even_sorted[0][1] + odd_sorted[0][1]))
    exit()

l = [n - even_sorted[0][1], n - odd_sorted[0][1]]
if len(odd_sorted) != 1:
    l.append(n - (even_sorted[0][1] + odd_sorted[1][1]))

if len(even_sorted) != 1:
    l.append(n - (odd_sorted[0][1] + even_sorted[1][1]))

print(min(l))

Submission status: Wrong Answer

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

even_map = {}
odd_map = {}

for i in range(0, n, 2):
    v = V[i]
    if not v in even_map:
        even_map[v] = 1
    else:
        even_map[v] += 1


for i in range(1, n, 2):
    v = V[i]
    if not v in odd_map:
        odd_map[v] = 1
    else:
        odd_map[v] += 1

even_sorted = sorted(even_map.items(), key=lambda x: x[1])
odd_sorted = sorted(odd_map.items(), key=lambda x: x[1])

even1 = even_sorted[0][0]
odd1 = odd_sorted[0][0]

if even1 != odd1:
    print(n - (even_sorted[0][1] + odd_sorted[0][1]))
    exit()

l = [n // 2]
if len(odd_sorted) != 1 and odd_sorted[1][0] != even_sorted[0][0]:
    l.append(n - (even_sorted[0][1] + odd_sorted[1][1]))

if len(even_sorted) != 1 and odd_sorted[0][0] != even_sorted[1][0]:
    l.append(n - (odd_sorted[0][1] + even_sorted[1][1]))

print(min(l))

Submission status: Wrong Answer

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

even_map = {}
odd_map = {}

for i in range(0, n, 2):
    v = V[i]
    if not v in even_map:
        even_map[v] = 1
    else:
        even_map[v] += 1


for i in range(1, n, 2):
    v = V[i]
    if not v in odd_map:
        odd_map[v] = 1
    else:
        odd_map[v] += 1

even_sorted = sorted(even_map.items(), key=lambda x: x[1])
odd_sorted = sorted(odd_map.items(), key=lambda x: x[1])

even1 = even_sorted[0][0]
odd1 = odd_sorted[0][0]

if even1 != odd1:
    print(n - (even_sorted[0][1] + odd_sorted[0][1]))
    exit()

if len(even_sorted) == 1 and len(odd_sorted) == 1:
    print(n // 2)
elif len(odd_sorted) != 1:
    print(n - (even_sorted[0][1] + odd_sorted[1][1]))
elif len(even_sorted) != 1:
    print(n - (odd_sorted[0][1] + even_sorted[1][1]))
else:
    print(n - max(even_sorted[0][1] + odd_sorted[1][1], even_sorted[1][1] + odd_sorted[0][1]))

Submission status: Wrong Answer

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

even_map = {}
odd_map = {}

for i in range(0, n, 2):
    v = V[i]
    if not v in even_map:
        even_map[v] = 1
    else:
        even_map[v] += 1


for i in range(1, n, 2):
    v = V[i]
    if not v in odd_map:
        odd_map[v] = 1
    else:
        odd_map[v] += 1

even_sorted = sorted(even_map.items(), key=lambda x: x[1])
odd_sorted = sorted(odd_map.items(), key=lambda x: x[1])

even1 = even_sorted[0][0]
odd1 = odd_sorted[0][0]

if even1 != odd1:
    print(n - (even_sorted[0][1] + odd_sorted[0][1]))
    exit()

if len(even_sorted) == 1 and len(odd_sorted) == 1:
    print(n - even_sorted[0][1])
elif len(even_sorted) == 1:
    print(n - (even_sorted[0][1] + odd_sorted[1][1]))
elif len(odd_sorted) == 1:
    print(n - (odd_sorted[0][1] + even_sorted[1][1]))
else:
    print(n - max(even_sorted[0][1] + odd_sorted[1][1], even_sorted[1][1] + odd_sorted[0][1]))

Submission status: Wrong Answer

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

even_map = {}
odd_map = {}

for i in range(0, n, 2):
    v = V[i]
    if not v in even_map:
        even_map[v] = 1
    else:
        even_map[v] += 1


for i in range(1, n, 2):
    v = V[i]
    if not v in odd_map:
        odd_map[v] = 1
    else:
        odd_map[v] += 1

even_n = -1
odd_n = -1
max_value = 0
for key, value in even_map.items():
    if max_value < value:
        max_value = value
        even_n = key

for key, value in odd_map.items():
    if max_value < value:
        max_value = value
        odd_n = key

max_even = 0
max_odd = 0
if odd_n >= 0:
    max_odd = max_value
    max_value = 0
    for key, value in even_map.items():
        if key == odd_n:
            continue
        if max_value < value:
            max_value = value
            even_n = key
    max_even = max_value

else:
    max_even = max_value
    max_value = 0
    for key, value in odd_map.items():
        if key == even_n:
            continue
        if max_value < value:
            max_value = value
            odd_n = key
    max_odd = max_value

print(n - (max_even + max_odd))

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
# coding: utf-8
# Your code here!
#一時保存
import collections

n=int(input())
li=list(map(int,input().split()))
l=[]
r=[]

for i in range(n):
    if i%2==0:
        l.append(li[i])
    else:
        r.append(li[i])

l_cnt=collections.Counter(l)
r_cnt=collections.Counter(r)


ll=l_cnt.most_common(2)
rr=r_cnt.most_common(2)
#if文多すぎ
if ll[0][0]==rr[0][0]:
    if ll[0][1]>=rr[0][1]:
        if len(rr)==1:
            print(n-ll[0][1])
        else:
            print(n-ll[0][1]-rr[1][1])
    else:
        if len(ll)==1:
            print(n-rr[0][1])
        else:
            print(n-rr[0][1]-ll[1][1])
        
else:
    print(n-ll[0][1]-rr[0][1])

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
# coding: utf-8
# Your code here!
#一時保存
import collections

n=int(input())
li=list(map(int,input().split()))
l=[]
r=[]

for i in range(n):
    if i%2==0:
        l.append(li[i])
    else:
        r.append(li[i])

l_cnt=collections.Counter(l)
r_cnt=collections.Counter(r)


ll=l_cnt.most_common(2)
rr=r_cnt.most_common(2)
#if文多すぎ
if ll[0][0]==rr[0][0]:
    if ll[0][1]>=rr[0][1]:
        if len(rr)==1:
            print(n-ll[0][1])
        else:
            print(n-ll[0][1]-rr[1][1])
    else:
        if len(ll)==1:
            print(n-rr[0][1])
        else:
            print(n-rr[0][1]-ll[1][1])
        
        print(n-rr[0][1]-ll[1][1])
else:
    print(n-ll[0][1]-rr[0][1])

Submission status: Wrong Answer

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

odd = collections.defaultdict(int)

even = collections.defaultdict(int)

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

    else:
        odd[v[i]] += 1

even = list(even.items())
odd = list(odd.items())

even.sort(key=lambda x: x[1], reverse=True)
odd.sort(key=lambda x: x[1], reverse=True)

if even[0][0] == odd[0][0]:
    if len(even) == 1 and len(odd) == 1:
        print(n // 2)

    elif even[0][1] > odd[0][1]:
        print(n - (even[0][1] + odd[1][1]))
    else:
        print(n - (even[1][1] + odd[0][1]))
else:
    print(n - (even[0][1] + odd[0][1]))

Submission status: Wrong Answer

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

odd = collections.defaultdict(int)

even = collections.defaultdict(int)

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

    else:
        odd[v[i]] += 1

even = list(even.items())
odd = list(odd.items())

even.sort(key=lambda x: x[1], reverse=True)
odd.sort(key=lambda x: x[1], reverse=True)

if even[0][0] == odd[0][0]:
    if len(even) == 1 and len(odd) == 1:
        print(n // 2)

    elif even[0][1] > odd[0][0]:
        print(n - (even[0][1] + odd[1][1]))
    else:
        print(n - (even[1][1] + odd[0][1]))
else:
    print(n - (even[0][1] + odd[0][1]))

Submission status: Wrong Answer

Solution code:
def sura_backsura():
    import collections

    N = int(input())
    vs = collections.Counter([int(i) for i in input().split()]).most_common(2)
    count = 0

    for v in vs:
        if v[1] != N/2:
            count += abs(v[1] - N/2)

    print(int(count))

if __name__ == "__main__":
    sura_backsura()

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
#一時保存
import collections

n=int(input())
li=list(map(int,input().split()))
l=[]
r=[]

for i in range(n):
    if i%2==0:
        l.append(li[i])
    else:
        r.append(li[i])

l_cnt=collections.Counter(l)
r_cnt=collections.Counter(r)


ll=l_cnt.most_common(2)
rr=r_cnt.most_common(2)

if ll[0][0]==rr[0][0]:
    print()

print(ll,rr)

Submission status: Wrong Answer

Solution code:
import collections as col
N= int(input())
A = [int(x) for x in input().split()]
a = A[::2]
print(a)
a = col.Counter(a)
b = A[1::2]
print(b)
b = col.Counter(b)
ans = 0
i = 0
j = 0
if len(a.most_common())==1 and len(b.most_common())==1 and a.most_common()[i][0]==b.most_common()[j][0]:
  print(N//2)
  exit()
while a.most_common()[i][0]==b.most_common()[j][0]:
  m=a.most_common()[i][1]
  n=b.most_common()[j][1]
  if m>n:
    j +=1
  elif m==n:
      if a.most_common()[i+1][1]>b.most_common()[j+1][1]:
        i+=1
      else:
        j +=1
  else:
    i +=1
#print(i,j,a,b)
ans += sum(a.values())+sum(b.values())-a.most_common()[i][1]-b.most_common()[j][1]
print(ans)

Submission status: Wrong Answer

Solution code:
import collections as col
N= int(input())
A = [int(x) for x in input().split()]
a = A[::2]
a = col.Counter(a)
b = A[1::2]
b = col.Counter(b)
ans = 0
i = 0
j = 0
if len(a.most_common())==1 and len(b.most_common())==1 and a.most_common()[i][0]==b.most_common()[j][0]:
  print(N//2)
  exit()
while a.most_common()[i][0]==b.most_common()[j][0]:
  m=a.most_common()[i][1]
  n=b.most_common()[j][1]
  if m>n:
    j +=1
  else:
    i +=1
ans += sum(a.values())+sum(b.values())-a.most_common()[i][1]-b.most_common()[j][1]
print(ans)

Submission status: Wrong Answer

Solution code:
import collections as col
N= int(input())
A = [int(x) for x in input().split()]
a = A[::2]
a = col.Counter(a)
b = A[1::2]
b = col.Counter(b)
ans = 0
i = 0
j = 0
while a.most_common()[i][0]==b.most_common()[j][0]:
  m=a.most_common()[i][1]
  n=b.most_common()[j][1]
  if m>n:
    j +=1
  else:
    i +=1
  if i==len(a.most_common())-1 or j==len(b.most_common())-1:
    if (i == len(a.most_common())-1 and i==0) or (j == len(b.most_common())-1 and j==0):
      print(N//2)
      exit()
    break
ans += sum(a.values())+sum(b.values())-a.most_common()[i][1]-b.most_common()[j][1]
print(ans)