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: Runtime Error

Solution code:
import collections

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

L1 = []
L2 = []

for i in range(N):
  if i % 2 == 0:
    L1.append(V[i])
  else:
    L2.append(V[i])
    
con1 = collections.Counter(L1).most_common()
con2 = collections.Counter(L2).most_common()

nums = 0


#全てが同じなら全体の半数を変える
if len(set(V)) == 1:
  print(N // 2)

#分割数列のそれぞれが全て等しい数からできているなら変える必要はない
elif len(set(L1)) == 1 and len(set(L2)) == 1:
  print(0)

else:
  ans = 0
  total = 0
  if con1[0][0] == con2[0][0]:
    for i in range(1,len(con1)):
      total += con1[i][1]
    for i in range(2,len(con2)):
      total += con2[i][1]
    total += con[0][1]
    for i in range(1,len(con2)):
      ans += con2[i][1]
    for i in range(2,len(con1)):
      ans += con1[i][1]
    ans += con1[0][1]
    ans = min(ans,total)
  else:
    for i in range(1,len(con1)):
      ans += con1[i][1]
    for i in range(1,len(con2)):
      ans += con2[i][1]
    
  print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np
import collections

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

if N == len(np.where(V == V[0])[0]):
    print(N // 2)
else:
    v0 = [V[i] for i in range(0, N - 1, 2)]
    v1 = [V[i] for i in range(1, N, 2)]
    v0_items = dict(collections.Counter(v0).items())
    v1_items = dict(collections.Counter(v1).items())
    v0_max_key = max(v0_items, key=v0_items.get)
    v1_max_key = max(v1_items, key=v1_items.get)
    
    if v0_max_key == v1_max_key:
        count = v0_items.pop(v0_max_key)
        count = (N // 2) - v1_items.pop(v1_max_key)
        tmp1 = v0_items.pop(v0_max_key)
        tmp2 = v1_items.pop(v1_max_key)
        count += (N // 2) - max(tmp1, tmp2)
        print(count)
    else:
        count = (N // 2) - max(collections.Counter(v0).values())
        count += (N // 2) - max(collections.Counter(v1).values())
        print(count)

Submission status: Runtime Error

Solution code:
import numpy as np
import collections

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

if N == len(np.where(V == V[0])[0]):
    print(N // 2)
else:
    v0 = [V[i] for i in range(0, N - 1, 2)]
    v1 = [V[i] for i in range(1, N, 2)]
    v0_items = dict(collections.Counter(v0).items())
    v1_items = dict(collections.Counter(v1).items())
    v0_max_key = max(v0_items, key=v0_items.get)
    v1_max_key = max(v1_items, key=v1_items.get)
    
    if v0_max_key == v1_max_key:
        count = v0_items.pop(v0_max_key)
        count = (N // 2) - v1_items.pop(v1_max_key)
        tmp1 = v0_items.pop(v0_max_key)
        tmp2 = v1_items.pop(v1_max_key)
        count += max(tmp1, tmp2)
        print(count)
    else:
        count = (N // 2) - max(collections.Counter(v0).values())
        count += (N // 2) - max(collections.Counter(v1).values())
        print(count)

Submission status: Runtime Error

Solution code:
import numpy as np
import collections

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

if N == len(np.where(V == V[0])[0]):
    print(N // 2)
else:
    v0 = [V[i] for i in range(0, N - 1, 2)]
    v1 = [V[i] for i in range(1, N, 2)]
    v0_items = dict(collections.Counter(v0).items())
    v1_items = dict(collections.Counter(v1).items())
    v0_max_key = max(v0_items, key=v0_items.get)
    v1_max_key = max(v1_items, key=v1_items.get)
    if v0_max_key == v1_max_key:
        count = v0_items.pop(v0_max_key)
        count = (N // 2) - v1_items.pop(v1_max_key)
        tmp1 = v0_items.pop(v0_max_key)
        tmp2 = v1_items.pop(v1_max_key)
        count += max(tmp1, tmp2)
        
    else:
        count = (N // 2) - max(collections.Counter(v0).values())
        count += (N // 2) - max(collections.Counter(v1).values())
        print(count)

Submission status: Runtime Error

Solution code:
import sys
N = int(input())
arr = list(map(int, input().split()))
if N == 2:
    print(0)
    sys.exit(0)


def update(start):
    dic = dict()
    for i in range(start, N, 2):
        if arr[i] in dic:
            dic[arr[i]] += 1
        else:
            dic[arr[i]] = 1
    return sorted(dic.items(), key=lambda ele: ele[1], reverse=True)


tuple_1 = update(0)
tuple_2 = update(1)

what_1, mx_1 = tuple_1[0]
what_2, mx_2 = tuple_2[0]

if what_1 == what_2:
    if len(tuple_1) == 1 and len(tuple_2) == 1:
        print(N//2)
    elif len(tuple_1 == 1):
        print(N//2 - tuple_2[1][1])
    elif len(tuple_2 == 1):
        print(N//2 - tuple_1[1][1])
    else:
        ans1 = N - tuple_1[0][1] - tuple_2[1][1]
        ans2 = N - tuple_1[1][1] - tuple_2[0][1]
        print(min(ans1, ans2))
else:
    print(N - mx_1 - mx_2)

Submission status: Runtime Error

Solution code:
from collections import Counter

n=int(input())
s=list(map(int,input().split()))
e=Counter(s[0::2])
o=Counter(s[1::2])
e[0]=0
o[0]=0
e1,e2=e.most_common(2)
o1,o2=o.most_common(2)
if e1[0]!=o1[0]:
    print(n-(e1[1]+o1[1]))
else:
    print(n-max(e1[1]+o2[1],e2[1]+o1[1]))z

Submission status: Runtime Error

Solution code:

N = int(raw_input())
A = [int(i) for i in raw_input().split()]

A0 = [A[i] for i in xrange(0, N, 2)]
A1 = [A[i] for i in xrange(1, N, 2)]

Count = 0
S0 = set(A0)
S1 = set(A1)
N0 = []
N1 = []

for s in S0:
    N0.append((s, sum(map(lambda x: x==s, A0))))

for s in S1:
    N1.append((s, sum(map(lambda x: x==s, A1))))

N0.sort(key=lambda x: x[1], reverse=True)
N1.sort(key=lambda x: x[1], reverse=True)

if N0[0][0] == N1[0][0]:
    if N0[0][0] < N1[0][0]:
        if len(N0) == 1:
            print N - N1[0][1]
        else:
            print N - N0[1][1] - N1[0][1]
    else:
        if len(N1) == 1:
            print N - N0[0][1]
        else:
            print N - N0[0][1] - N1[1][1]
else:
    print N - N0[

Submission status: Runtime Error

Solution code:

A = [int(i) for i in raw_input().split()]
N = len(A)
A0 = [A[i] for i in xrange(0, N, 2)]
A1 = [A[i] for i in xrange(1, N, 2)]

Count = 0
S0 = set(A0)
S1 = set(A1)
N0 = []
N1 = []

for s in S0:
    N0.append((s, sum(map(lambda x: x==s, A0))))

for s in S1:
    N1.append((s, sum(map(lambda x: x==s, A1))))

N0.sort(key=lambda x: x[1], reverse=True)
N1.sort(key=lambda x: x[1], reverse=True)

if N0[0][0] == N1[0][0]:
    if N0[0][0] < N1[0][0]:
        if len(N0) == 1:
            print N - N1[0][1]
        else:
            print N - N0[1][1] - N1[0][1]
    else:
        if len(N1) == 1:
            print N - N0[0][1]
        else:
            print N - N0[0][1] - N1[1][1]
else:
    print N - N0[0][1] - N1[0][1]

Submission status: Runtime Error

Solution code:
A = [int(i) for i in raw_input().split()]
N = len(A)
A0 = [A[i] for i in xrange(0, N, 2)]
A1 = [A[i] for i in xrange(1, N, 2)]

Count = 0
S0 = set(A0)
S1 = set(A1)
N0 = []
N1 = []

if len(S0) == 1:
    N0[0] = append((S0[0], len(A0)))
else:
    for s in S0:
        N0.append((s, sum(map(lambda x: x==s, A0))))


if len(S1) == 1:
    N1.append = (S1[0], len(A1))
else:
    for s in S1:
        N1.append((s, sum(map(lambda x: x==s, A1))))

N0.sort(key=lambda x: x[1], reverse=True)
N1.sort(key=lambda x: x[1], reverse=True)

if N0[0][0] == N1[0][0]:
    if N0[0][0] > N1[0][0]:
        if len(N1) == 1:
            print N - N0[0][1]
        else:
            print N - N0[0][1] - N1[1][1]
    else:
        if len(N0) == 0:
            print N - N1[0][1]
        else:
            print N - N0[1][1] - N1[0][1]
else:
    print N - N0[0][1] - N1[0][1]

Submission status: Runtime Error

Solution code:
n=int(input())
a=list(map(int,input().split()))
odd={}
even={}
for i in range(n):
  if i%2==0:
    if a[i] in odd:
      odd[a[i]] += 1
    else:
      odd[a[i]] = 1
  else:
    if a[i] in even:
      even[a[i]] += 1
    else:
      even[a[i]] = 1
ans=0
o_1=max(odd.values())
o_2=sorted(odd.values())[-2]
e_1=max(even.values())
e_2=sorted(even.values())[-2]
if max(even.values(),key=even.get) != max(odd.values(),key=odd.get):
  ans = n-o_1-e_1
else:
  ans=min(n-o_1-e_2,n-o_2-e_1)
print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
v = list(map(int,input().split()))
m = n/2
s = []
t = []
for i in range(m):
    s.append(a[2*i])
for i in range(m):
    t .append(a[2*i+1])
S = 0
T = 0
for i in range(m):
    p = s.count(a[2*i])
    if p > S:
        S = p
for i in range(m):
    q = t.count(a[2*i+1])
    if q > T:
        T = q
ans = n - S - Q
print(ans)

Submission status: Runtime Error

Solution code:
n=int(input())
v_list = list(map(int,input().split()))
odd_list = []
even_list = []

for i in range(n):
    if i % 2 == 0:
        odd_list.append(v_list[i]) 
    else:
        even_list.append(v_list[i])

import collections

odd_list_c = collections.Counter(odd_list)
even_list_c = collections.Counter(even_list)

if odd_list_c.most_common()[0][0] != even_list_c.most_common()[0][0]:
    ans = n - odd_list_c.most_common()[0][1] - even_list_c.most_common()[0][1]
else:
    if len(even_list_c) == 1 && len(odd_list_c) == 1:
        ans = n // 2
    else: 
        if odd_list_c.most_common()[0][1] >= even_list_c.most_common()[0][1]:
            ans = n - odd_list_c.most_common()[0][1] - even_list_c.most_common()[1][1]
        elif odd_list_c.most_common()[0][1] < even_list_c.most_common()[0][1]:
            ans = n - odd_list_c.most_common()[1][1] - even_list_c.most_common()[0][1]

print(ans)

Submission status: Runtime Error

Solution code:
n=int(input())
v_list = list(map(int,input().split()))
odd_list = []
even_list = []

for i in range(n):
    if i % 2 == 0:
        odd_list.append(v_list[i]) 
    else:
        even_list.append(v_list[i])

import collections

odd_list_c = collections.Counter(odd_list)
even_list_c = collections.Counter(even_list)

if odd_list_c.most_common()[0][0] != even_list_c.most_common()[0][0]:
    ans = n - odd_list_c.most_common()[0][1] - even_list_c.most_common()[0][1]
else:
    if odd_list_c.most_common()[0][1] >= even_list_c.most_common()[0][1]:
        ans = n - odd_list_c.most_common()[0][1] - even_list_c.most_common()[1][1]
    else:
        ans = n - odd_list_c.most_common()[1][1] - even_list_c.most_common()[0][1]

print(ans)

Submission status: Runtime Error

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

count = 0

if max(v) == min(v):
    print(int(n/2))
else:
    for i in range(int(n/2)):
        if v[0] != v[j+2]:
            count += 1
        if v[1] != v[j+3]:
            count =+ 1
        j = j+2
    print(count)

Submission status: Runtime Error

Solution code:
import collections

n=int(input())
v=list(map(int,input().split()))
count=0
vo=[]
ve=[]
for i in range(n):
    if i%2==0:
        ve.append(v[i])
    else:
        vo.append(v[i])
e=collections.Counter(ve)
o=collections.Counter(vo)

emax=e.most_common()[0][0]
omax=o.most_common()[0][0]

if emax==omax:
    omax2 = o.most_common()[1][0]
    emax2 = e.most_common()[1][0]
    tempe=0
    tempo=0
    for i in range(n // 2):
        if ve[i] != emax2:
            tempe += 1
    for i in range(n // 2):
        if vo[i] != omax:
            tempe += 1
    for i in range(n // 2):
        if ve[i] != emax:
            tempo += 1
    for i in range(n // 2):
        if vo[i] != omax2:
            tempo += 1
    count=min(tempe,tempo)
else:
    for i in range(n // 2):
        if ve[i] != emax:
            count += 1
    for i in range(n // 2):
        if vo[i] != omax:
            count += 1

print(count)

Submission status: Runtime Error

Solution code:
import collections

n=int(input())
v=list(map(int,input().split()))
count=0
vo=[]
ve=[]
for i in range(n):
    if i%2==0:
        ve.append(v[i])
    else:
        vo.append(v[i])
e=collections.Counter(ve)
o=collections.Counter(vo)

emax=e.most_common()[0][0]
emax2=e.most_common()[1][0]
omax=o.most_common()[0][0]
omax2=o.most_common()[1][0]

if emax==omax:
    tempe=0
    tempo=0
    for i in range(n // 2):
        if ve[i] != emax2:
            tempe += 1
    for i in range(n // 2):
        if vo[i] != omax:
            tempe += 1
    for i in range(n // 2):
        if ve[i] != emax:
            tempo += 1
    for i in range(n // 2):
        if vo[i] != omax2:
            tempo += 1
    count=min(tempe,tempo)
else:
    for i in range(n // 2):
        if ve[i] != emax:
            count += 1
    for i in range(n // 2):
        if vo[i] != omax:
            count += 1
    
print(count)

Submission status: Runtime Error

Solution code:
from collections import Counter
n=int(input())
v=list(map(int,input().split()))
c=Counter(v).most_common(2)
print(len(v)-c[0][1]-c[1][1])

Submission status: Runtime Error

Solution code:
from collections import Counter
N = int (input())
List = list(map(int, input().split()))
List_even = List[0::2]
List_odd = List[1::2]
e1 = Counter(List_even)
o1 = Counter(List_odd)

e1_v = e1.most_common(1)
e1_atai = e1_v[0][0]
e1_kosuu = e1_v[0][1]

o1_v = o1.most_common(1)
o1_atai = o1_v[0][0]
o1_kosuu = o1_v[0][1]

if List_even == List_odd:
    print (len(List_odd))
else:
    if e1_atai != o1_atai:
        count_e = len(List_even) - e1_kosuu
        count_o = len(List_odd) - o1_kosuu
        print (count_e + count_o)
    
    else:
        e2 = Counter(List_even.remove(e1_atai))
        o2 = Counter(List_odd.remove(o1_atai))
        e2_v = e2.most_common(1)
        e2_atai = e2_v[0][0]
        e2_kosuu = e2_v[0][1]
        o2_v = o2.most_common(1)
        o2_atai = o2_v[0][0]
        o2_kosuu = o2_v[0][1]
        if e1_kosuu > o1_kosuu:
            count_e = len(List_even) - e1_kosuu
            count_o = len(List_odd) - o2_kosuu
            print (count_e + count_o)
        elif o1_kosuu > e1_kosuu:
            count_e = len(List_even) - e2_kosuu
            count_o = len(List_odd) - o1_kosuu
            print (count_e + count_o)
        else:
            if e2_kosuu > o2_kosuu:
                count_e = len(List_even) - e2_kosuu
                count_o = len(List_odd) - o1_kosuu
                print (count_e + count_o)
            if o2_kosuu >= e2_kosuu:
                count_e = len(List_even) - e1_kosuu
                count_o = len(List_odd) - o2_kosuu
                print (count_e + count_o)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
#ARC103C
import sys
import collections

n= int(input())
tmp = input().split()
v = list(map(lambda a: int(a), tmp))

w=[]
x=[]
for i in range(0,n):
	if(i%2==0):
		w.append(v[i])
	else:
		x.append(v[i])

cw = collections.Counter(w)
cx = collections.Counter(x)

if(cw.most_common()[0][0]!=cx.most_common()[0][0]):
	print(n-cw.most_common()[0][1]-cx.most_common()[0][1])
else:
	if((len(cw.values()) ==1)and(len(cx.values())==1)):
		print(n//2)
	elif(len(cw.values())==1):
		print(n//2-cx.most_common()[1][1])
	elif(len(cx.values())==1):
		print(n//2-cw.most_common()[1][1])
	else:
		print(min(n-cw.most_common()[0][1]-cx.most_common()[1][1]),(n-cw.most_common()[1][1]-cx.most_common()[0][1]))

#print(cw.most_common()[0][1])
#print(cx.most_common()[0][1])
#print(v)
#print(w)
#print(x)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
#ARC103C
import sys
import collections

n= int(input())
tmp = input().split()
v = list(map(lambda a: int(a), tmp))

w=[]
x=[]
for i in range(0,n):
	if(i%2==0):
		w.append(v[i])
	else:
		x.append(v[i])

cw = collections.Counter(w)
cx = collections.Counter(x)

if(cw.most_common()[0][0]!=cx.most_common()[0][0]):
	print(n-cw.most_common()[0][1]-cx.most_common()[0][1])
else:
	if(len(cw.values()) ==1)and(len(cx.values())==1):
		print(n//2)
	elif(len(cw.values()) ==1):
		print(n//2-cx.most_common()[1][1])
	elif(len(cx.values())==1):
		print(n//2-cw.most_common()[1][1])
	else:
		print(min(n-cw.most_common()[0][1]-cx.most_common()[1][1]),(n-cw.most_common()[1][1]-cx.most_common()[0][1]))

#print(cw.most_common()[0][1])
#print(cx.most_common()[0][1])
#print(v)
#print(w)
#print(x)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
#ARC103C
import sys
import collections

n= int(input())
tmp = input().split()
v = list(map(lambda a: int(a), tmp))

w=[]
x=[]
for i in range(0,n):
	if(i%2==0):
		w.append(v[i])
	else:
		x.append(v[i])

cw = collections.Counter(w)
cx = collections.Counter(x)

if(cw.most_common()[0][0]!=cx.most_common()[0][0]):
	print(n-cw.most_common()[0][1]-cx.most_common()[0][1])
else:
	if(len(cw.values()) ==1)and(len(cx.values())==1):
		print(n//2)
	elif(len(cw.values()) ==1):
		print(n-cw.most_common()[0][1]-cx.most_common()[1][1])
	elif(len(cx.values())==1):
		print(n-cw.most_common()[1][1]-cx.most_common()[0][1])
	else:
		print(min(n-cw.most_common()[0][1]-cx.most_common()[1][1]),(n-cw.most_common()[1][1]-cx.most_common()[0][1]))

#print(cw.most_common()[0][1])
#print(cx.most_common()[0][1])
#print(v)
#print(w)
#print(x)

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(10000000)
def input():
    return sys.stdin.readline()[:-1]
from bisect import *
from collections import *
from heapq import *
from math import *
from itertools import *

def abc103():
    N = int(input())
    U, V = [None] * N, [None] * N
    OK = True
    for i in range(N):
        x, y = map(int, input().split())
        u, v = x+y, x-y
        U[i], V[i] = u, v
        if i != 0:
            if f ^ (u%2):
                OK = False
        f = u%2
    if OK == False:
        print(-1)
        exit()
    D = [2**i for i in range(30, -1, -1)] + [1]*f
    print(31-f)
    print(*D)
    for u, v in zip(U, V):
        ans = []
        pu, pv = 0, 0
        for d in D:
            if pu <= u and pv <= v:
                pu += d
                pv += d
                ans.append('R')
            elif pu <= u and pv >= v:
                pu += d
                pv -= d
                ans.append('U')
            elif pu >= u and pv >= v:
                pu -= d
                pv -= d
                ans.append('L')
            elif pu >= u and pv <= v:
                pu -= d
                pv += d
                ans.append('U')
        print(*ans, sep = '')

abc103()

Submission status: Runtime Error

Solution code:
from collections import Counter
from functools import reduce
n = int(input())
v = [*map(int, input().split())]
r1 = [v[i] for i in range(0, len(v), 2)]
r2 = [v[i] for i in range(1, len(v), 2)]
c1 = Counter(r1).most_common(1)[0][0]
c2 = Counter(r2).most_common(2)
if len(c2) > 1:
    c2 = c2[0][0] if c2[0][0] != c1 else c2[1][0]
else:
    c2 = -1
f = lambda e, v: 1 if e != v else 0
c = reduce(lambda x, y: x + f(y, c1), r1, 0)
c += reduce(lambda x, y: x + f(y, c2), r2, 0)
print(c)

Submission status: Runtime Error

Solution code:
n = int(input())
v = input().split()
set_v = set(v)
if set_v == 1:
  print(len(v)//2)
else:
  cnt_a , cnt_b = 0,0
  for i in range(3,n,2):
    if v[1] !=v[i]:
      cnt_a +=1
  for i in range(2,n+1,2):
    if v[0] !=v[i]:
      cnt_b +=1
  print(cnt_a+cnt_b)

Submission status: Runtime Error

Solution code:
nums = int(input())
odds = []
even = []
items = [int(i) for i in input().split(' ')]
for i,data in enumerate(items):
  if i%2 == 0:
    even.append(data)
  else:
    odds.append(data)

def get_frequent_data(dataset):
	return max(set(dataset), key=dataset.count)

def get_second_frequent(dataset):
  first = get_frequent_data(dataset)
  delete_first = [ i for i in dataset if i != first]
  second = get_frequent_data(delete_first)
  return second

most_frequent_odds = get_frequent_data(odds)
most_frequent_even = get_frequent_data(even)
second_frequent_odds = get_second_frequent(odds)
second_frequent_even = get_second_frequent(even)

if most_frequent_odds != most_frequent_even:
  print(len([i for i in odds if i != most_frequent_odds])+
  		len([i for i in even if i != most_frequent_even]))
else:
  even_len = len([i for i in odds if i == most_frequent_even])
  odds_len = len([i for i in odds if i == most_frequent_odds])
  if even_len > odds_len:
  	print(len([i for i in odds if i != second_frequent_odds])+
  		len([i for i in even if i != most_frequent_even]))
  elif even_len < odds_len:
  	print(len([i for i in odds if i != most_frequent_odds])+
  		len([i for i in even if i != second_frequent_even]))
  else:
    print(len([i for i in odds if i != second_frequent_odds])+
  		len([i for i in even if i != most_frequent_even]))

Submission status: Runtime Error

Solution code:
n = int(input())
v = list(map(int,input().split()))
l = []
r = []
for i in range(0,n//2):
    l.append(v[2*i])
    r.append(v[2*i+1])

lc = []
rc = []
vmax =max(max(l),max(r))
for i in range(1,vmax+1):
    lc.append([i, l.count(i)])
    rc.append([i, r.count(i)])
lc.sort(key=lambda x:x[1])
rc.sort(key=lambda x:x[1])
lc.reverse()
rc.reverse()
if lc[0][0] == rc[0][0]:
    if lc[0][1] == rc[0][1]:
        if lc[1][1] == rc[1][1]:
            print(n-lc[0][1]-rc[1][1])
        else:
            print(n-lc[0][1]-max(lc[1][1],rc[1][1]))
    else:
        print(n-max(lc[0][1]+rc[1][1],rc[0][1]+lc[1][1]))
else:
    print(n-lc[0][1]-rc[0][1])

Submission status: Runtime Error

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

_n = n // 2

def mode12(arr):
  _max = max(arr)
  mode1 = arr.index(_max)
  arr[mode1] = 0
  mode2 = arr.index(max(arr))
  arr[mode1] = _max
  return mode1, mode2

def mode12_count12(arr):
  counts = [0] * 100000
  for i in arr:
    counts[i] += 1
  mode1, mode2 = mode12(counts)
  return mode1, mode2, counts[mode1], counts[mode2]

mode1_even, mode2_even, n1_even, n2_even = mode12_count12(a[::2])
mode1_odd, mode2_odd, n1_odd, n2_odd = mode12_count12(a[1::2])

if not mode1_even == mode1_odd:
  result = 2 * _n - n1_even - n1_odd
else:
  result = min(2 * _n - n1_even - n2_odd, 2 * _n - n1_odd - n2_even)

print(result)

Submission status: Runtime Error

Solution code:
n = int(input()) # sを取得し、strに値を入れる
num= input()
num=list(map(int,num.split()))

from collections import defaultdict

d0=defaultdict(int)
d1=defaultdict(int)
for i in range(n):
    if i%2==0:
        d0[num[i]]+=1
    else:
        d1[num[i]]+=1

l0=[(k,d0[k]) for k in d0]
l1=[(k,d1[k]) for k in d1]
l0=sorted(l0, key=lambda d:d[1],reverse=True)
l1=sorted(l1,key=lambda d:d[1],reverse=True)

if l0[0][0]!=l1[0][0]:
    print(len(num)-l0[0][1]-l1[0][1])
elif len(num)==2:
    print(1)
else:
    s=0
    if l0[0][1]>=l1[0][1]:
        s=l0[0][1]+l1[1][1]
    else:
        s=l0[1][1]+l1[0][1]
    print(len(num)-s)

Submission status: Runtime Error

Solution code:
str = input() # sを取得し、strに値を入れる
num= input()
num=list(map(int,num.split()))

from collections import defaultdict

d0=defaultdict(int)
d1=defaultdict(int)
for i in range(len(num)):
    if i%2==0:
        d0[num[i]]+=1
    else:
        d1[num[i]]+=1

l0=[(k,d0[k]) for k in d0]
l1=[(k,d1[k]) for k in d1]
l0=sorted(l0, key=lambda d:d[1],reverse=True)
l1=sorted(l1,key=lambda d:d[1],reverse=True)

if l0[0][0]!=l1[0][0]:
    print(len(num)-l0[0][1]-l1[0][1])
elif len(num)==2:
    print(1)
else:
    s=0
    if l0[0][1]>=l1[0][1]:
        s=l0[0][1]+l1[1][1]
    else:
        s=l0[1][1]+l1[0][1]
    print(len(num)-s)

Submission status: Runtime Error

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

if n == 2:
    if l[0] == l[1]:
        print(1)
    else:
        print(0)
else:
    a = []
    b = []
    for i in range(n):
        if i % 2 == 0:
            a.append(l[i])
        else:
            b.append(l[i])

    da = {}
    for e in a:
        if e not in da:
            da[e] = (1,e)
        else:
            da[e] = (da[e][0]+1,da[e][1])

    db = {}
    for e in b:
        if e not in db:
            db[e] = (1,e)
        else:
            db[e] = (db[e][0]+1,db[e][1])

    la = list(reversed(sorted(list(da.values()))))
    lb = list(reversed(sorted(list(db.values()))))
    #print(la)
    #print(lb)

    la[-1] = (0,-1)
    lb[-1] = (0,-1)

    if la[0][1] == lb[0][1]:
        ans = n- (la[0][0] + max(la[1][0],lb[1][0]))
    else:
        ans = n - (la[0][0] + lb[0][0])
    print(ans)

Submission status: Runtime Error

Solution code:
str = input() # sを取得し、strに値を入れる
num= input()
num=list(map(int,num.split()))

from collections import defaultdict

d0=defaultdict(int)
d1=defaultdict(int)
for i in range(len(num)):
    if i%2==0:
        d0[num[i]]+=1
    else:
        d1[num[i]]+=1

l0=[(k,d0[k]) for k in d0]
l1=[(k,d1[k]) for k in d1]
l0=sorted(l0, key=lambda d:d[1],reverse=True)
l1=sorted(l1,key=lambda d:d[1],reverse=True)


if l0[0][0]!=l1[0][0]:
    print(len(num)-l0[0][1]-l1[0][1])
else:
    s=0
    if l0[0][1]>=l1[0][1]:
        s=l0[0][1]+l1[1][1]
    else:
        s=l0[1][1]+l1[0][1]
    print(len(num)-s)

Submission status: Runtime Error

Solution code:
import collections
n = int(input())
v = list(map(int, input().split()))
a = []
b = []
for i in range(n // 2):
    a.append(v[(i+1)*2-1])
    b.append(v[(i+1)*2-2])
a = collections.Counter(a)
b = collections.Counter(b)


if a.most_common()[0][0] != b.most_common()[0][0]:
    print(n - a.most_common()[0][1] - b.most_common()[0][1])
elif len(a.most_common()) == 1:
    print(n - a.most_common()[0][1] - b.most_common()[1][1])
elif len(b.most_common()) == 1:
    print(n - a.most_common()[1][1] - b.most_common()[0][1])
elif a.most_common()[1][1] + b.most_common()[0][1] > a.most_common()[0][1] + b.most_common()[1][1]:
    print(n - a.most_common()[1][1] - b.most_common()[0][1])
else:
    print(n - a.most_common()[0][1] - b.most_common()[1][1])

Submission status: Runtime Error

Solution code:
import collections
n = int(input())
v = list(map(int, input().split()))
a = []
b = []
for i in range(n // 2):
    a.append(v[(i+1)*2-1])
    b.append(v[(i+1)*2-2])
a = collections.Counter(a)
b = collections.Counter(b)


if a.most_common()[0][0] != b.most_common()[0][0]:
    print(n-a.most_common()[0][1]-b.most_common()[0][1])
elif a.most_common()[1][1] + b.most_common()[0][1] > a.most_common()[0][1] + b.most_common()[1][1]:
    print(n-a.most_common()[1][1] - b.most_common()[0][1])
else:
    print(n-a.most_common()[0][1] - b.most_common()[1][1])

Submission status: Runtime Error

Solution code:
import collections
n = int(input())
v = list(map(int, input().split()))
a = []
b = []
for i in range(n // 2):
    a.append(v[(i+1)*2-1])
    b.append(v[(i+1)*2-2])
a = collections.Counter(a)
b = collections.Counter(b)


if a.most_common()[0][0] != b.most_common()[0][0]:
    print(n-a.most_common()[0][1]-b.most_common()[0][1])
elif a.most_common()[1][0] + b.most_common()[0][0] > a.most_common()[0][0] + b.most_common()[1][0]:
    print(n-a.most_common()[1][0] - b.most_common()[0][0])
else:
    print(n-a.most_common()[0][0] - b.most_common()[1][0])

Submission status: Runtime Error

Solution code:
import collections
n = int(input())
v = list(map(int, input().split()))
a = []
b = []
for i in range(n // 2):
    a.append(v[(i+1)*2-1])
    b.append(v[(i+1)*2-2])
a = collections.Counter(a)
b = collections.Counter(b)


if a.most_common()[0][0] != b.most_common()[0][0]:
    print(n-a.most_common()[0][1]-b.most_common()[0][1])
elif a.most_common()[1][0] + b.most_common()[0][0] > a.most_common()[0][0] + b.most_common()[1][0]
    print(n-a.most_common()[1][0] - b.most_common()[0][0])
else:
    print(n-a.most_common()[0][0] - b.most_common()[1][0])

Submission status: Runtime Error

Solution code:
import collections
n = int(input())
v = list(map(int, input().split()))
even = [v[2*i] for i in range(n//2)]
odd = [v[2**i+1] for i in range(n//2)]
dEven = collections.Counter(even).most_common()
dOdd = collections.Counter(odd).most_common()
if dEven[0][0] != dOdd[0][0]:
    ans = n - dEven[0][1]  - dOdd[0][1]
else:
    ans = n - max(dEven[0][1]+dOdd[1][0], dEven[1][0]+dOdd[0][1])
print(ans)

Submission status: Runtime Error

Solution code:
n=input()
a=[]

a=map(int,raw_input().split())

b=[0]*100000
c=0
while c <= n-2:
    b[a[c]]+=1
    c+=2

d=[0]*100000
e=1
while e <= n-1:
    d[a[e]]+=1
    e+=2

f=sorted(b)[-2]
g=sorted(d)[-2]



if max(b) == n/2 and max(d) == n/2 and b.index(max(b)) == d.index(max(d)):
    print(n/2)
elif max(b) == n/2 and max(d) == n/2 and b.index(max(b)) != d.index(max(d)):
    print(0)
elif b.index(max(b)) == d.index(max(d)):
    print(n-max(b)-max(f,g))
else:
    print(n-max(b)-max(d))

Submission status: Runtime Error

Solution code:
n=input()
a=[]

a=map(int,raw_input().split())

b=[0]*100000
c=0
while c <= n-2:
    b[a[c]]+=1
    c+=2

d=[0]*100000
e=1
while e <= n-1:
    d[a[e]]+=1
    e+=2

f=sorted(b)[-2]
g=sorted(d)[-2]



if max(b) == n/2 and max(d) == n/2 and b.index(max(b)) == d.index(max(d)):
    print(n/2)
elif max(b) == n/2 and max(d) == n/2 and b.index(max(b)) != d.index(max(d)):
    print(0)
elif b.index(max(b)) == d.index(max(d)):
    print(n-max(b)-max(f,g))
else:
    print(n-max(b)-max(d))
~

Submission status: Runtime Error

Solution code:
n=input()
a=[]

a=map(int,raw_input().split())

b=[0]*10000
c=0
while c <= n-2:
    b[a[c]]+=1
    c+=2

d=[0]*10000
e=1
while e <= n-1:
    d[a[e]]+=1
    e+=2

f=sorted(b)[-2]
g=sorted(d)[-2]



if max(b) == n/2 and max(d) == n/2 and b.index(max(b)) == d.index(max(d)):
    print(n/2)
elif max(b) == n/2 and max(d) == n/2 and b.index(max(b)) != d.index(max(d)):
    print(0)
elif b.index(max(b)) == d.index(max(d)):
    print(n-max(b)-max(f,g))
else:
    print(n-max(b)-max(d))

Submission status: Runtime Error

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

odd = {}
even = {}

for i in range(len(v)):
    if i % 2 == 1:
        if v[i] in odd:
            odd[v[i]] += 1
        else:
            odd[v[i]] = 1
    else:
        if v[i] in even:
            even[v[i]] += 1
        else:
            even[v[i]] = 1

#ソートして一番目、二番目を見る
odd_sorted  = sorted(odd.items(), key = lambda x : -x[1])
even_sorted  = sorted(even.items(), key = lambda x : -x[1])


candidate_odd = []
candidate_even = []

candidate_odd.append



def count_rewrite(odd, even):
    ans = 0
    for i in range(len(v)):
        if i % 2:
            if v[i] != ans_odd:
                ans += 1
        else:
            if v[i] != ans_even:
                ans += 1
    return ans


ans = 1000002
#候補が同じ場合
if odd_sorted[0][0] == even_sorted[0][0]:
    #奇数も偶数も2番目が存在する？
    if len(odd.keys()) > 1 and len(even.keys()) > 1:
        ans = min(ans, count_rewrute(odd_sorted[0][0], even_sorted[1][0]))
        ans = min(ans, count_rewrute(odd_sorted[1][0], even_sorted[0][0]))
    #お互いに二番目が存在しない(ただし数は必ず一致するのでどちらか)
    elif len(odd.keys()) == 1 and len(even.keys()) == 1:
        ans = min(ans, count_rewrute(-1, even_sorted[0][0]))
    #奇数に2番目が存在しない
    elif len(odd.keys()):
        ans = min(ans, count_rewrute(odd_sorted[0][0], even_sorted[1][0]))
    #偶数に2番目が存在しない
    else: #len(even.keys()):
        ans = min(ans, count_rewrute(odd_sorted[1][0], even_sorted[0][0]))

else:
    ans = min(ans, count_rewrute(odd_sorted[0][0], even_sorted[0][0]))


print(ans)