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

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

if len(set(v)) == 1:
    print(n // 2)
else:
    v1 = [v[i] for i in range(0, n, 2)]
    v2 = [v[i + 1] for i in range(0, n, 2)]

    kw1 = Counter(v1)
    kw2 = Counter(v2)

    x1 = kw1.most_common()[0][0]
    x2 = kw2.most_common()[0][0]

    if x1 != x2:
        ans = 0
        for i in v1:
            if i != x1:
                ans += 1
        for i in v2:
            if i != x2:
                ans += 1
    else:
        y1 = kw1.most_common()[1][0]
        y2 = kw2.most_common()[1][0]

        ans1 = 0
        ans2 = 0

        for i in v1:
            if i != y1:
                ans1 += 1
        for i in v2:
            if i != x2:
                ans1 += 1

        for i in v1:
            if i != x1:
                ans2 += 1
        for i in v2:
            if i != y2:
                ans2 += 1

        ans = min(ans1, ans2)

print(ans)

Submission status: Runtime Error

Solution code:
from collections import Counter
n, *A = map(int, open(0).read().split())

a0 = Counter(A[::2]).most_common(2)
a1 = Counter(A[1::2]).most_common(2)

count = n
if a0[0][0] == a1[0][0]:
    count -= max(a0[1][1] + a1[0][1], a0[0][1] + a1[1][1])
else:
    count -= a0[0][1] + a1[0][1]
print(count)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n = int(input())
v = [int n , for i in range(n)]

Submission status: Runtime Error

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

    odd = v[1::2]
    count_e = collections.Counter(even)
    count_o = collections.Counter(odd)
    ce = count_e.most_common()
    co = count_o.most_common()
    if ce[0][0] != co[0][0]:
        print(n-ce[0][1] - co[0][1])
    else:
        if len(ce) == 1 and len(co) == 1:
            print(n//2)
        elif len(ce) == 1:
            print(n-co[1][1])
        elif len(co) == 1:
            print(n-ce[1][1])
        else:
            print(min(n-ce[0][1]-co[1][1], n-ce[1][1]-co[0][1]))




if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
from collections import Counter
n=int(input())
*v,=map(int,input().split())
if n==2 and len(set(v))==2:
    print(0)
    exit(0)
elif all(v[i]==v[i+2] for i in range(n-2)) and v[0]!=v[1]:
    print(0)
    exit(0)
odd=v[1::2]
odd_c=Counter(odd).most_common()[0][1]
even=v[::2]
even_c=Counter(even).most_common()[0][1]
cnt=0
if Counter(odd).most_common()[0][0]==Counter(even).most_common()[0][0]:
    if odd_c<even_c:
        odd_c=Counter(odd).most_common()[1][1]
    else:
        even_c=Counter(even).most_common()[1][1]
print(n-even_c-odd_c)

Submission status: Runtime Error

Solution code:
n=int(input())
v=list(map(int,input().split()))
da={}
db={}
maxa=0
maxa2=0
maxb=0
maxb2=0
if n==v.count(v[0]):
    print(n//2)
else:
    for i in range(n):
        if i%2==0:
            try:
                da[v[i]]+=1
            except:
                da[v[i]]=1
            if da[v[i]]>maxa:
                maxa2=maxa
                maxa=v[i]
        else:
            try:
                db[v[i]]+=1
            except:
                db[v[i]]=1
            if db[v[i]]>maxb:
                maxb2=maxb
                maxb=v[i]
    if maxa!=maxb:
        print(n-da[maxa]-db[maxb])
    else:
        print(min(n-da[maxa]-db[maxb2],n-da[maxa2]-db[maxb]))

Submission status: Runtime Error

Solution code:
from collections import Counter

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

Vodd = V[: len(V):2]
Veven = V[1: len(V):2]

if Vodd == Veven:
    print(n // 2)


Voc = Counter(Vodd)
Vec = Counter(Veven)

Voc_val, Voc_cnt = zip(*Voc.most_common())
Vec_val, Vec_cnt = zip(*Vec.most_common())

Voc_val, Voc_cnt = list(Voc_val), list(Voc_cnt)
Vec_val, Vec_cnt = list(Vec_val), list(Vec_cnt)

num = Voc.most_common()[0][1] + Vec.most_common()[0][1]

if Voc_val[0] == Vec_val[0]:
    Voc_cnt.append(0)
    Vec_cnt.append(0)
    num += max(Voc_val[1] - Voc_val[0], Vec_val[1] - Vec_val[0])

print(n - num)

Submission status: Runtime Error

Solution code:
n=int(input())
v=list(map(int,input().split()))
v1 = [v[2*i] for i in range(n//2)]

if len(set(v))==1:
    print(n//2)
    exit()
d1 = {}
for x in v1:
    if x in d1.keys():
        d1[x] = d1[x] + 1
    else:
        d1[x] = 1
d1 = sorted(d1.items(), key=lambda x:-x[0])

d2 = {}
v2 = [v[2*i+1] for i in range(n//2)]
ma2=0
for x in v2:
    if x in d2.keys():
        d2[x] = d2[x] + 1
    else:
        d2[x] = 1
d2 = sorted(d2.items(), key=lambda x:-x[0])
if d1[0][0] != d2[0][0]:
    print(n-d1[0][1]-d2[0][1])
else:
    if len(d1) == 1:
        print(n-d1[0][1]-d2[1][1])
    elif len(d2) == 1:
        print(n-d1[1][1]-d2[0][1])
    else:
        raise UnicodeError
        # print(n-max(d1[0][1]+d2[1][1],d1[1][1]+d2[0][1]))

Submission status: Runtime Error

Solution code:
n=int(input())
v=list(map(int,input().split()))
v1 = [v[2*i] for i in range(n//2)]

if len(set(v))==1:
    print(n//2)
    exit()
d1 = {}
for x in v1:
    if x in d1.keys():
        d1[x] = d1[x] + 1
    else:
        d1[x] = 1
d1 = sorted(d1.items(), key=lambda x:-x[0])

d2 = {}
v2 = [v[2*i+1] for i in range(n//2)]
ma2=0
for x in v2:
    if x in d2.keys():
        d2[x] = d2[x] + 1
    else:
        d2[x] = 1
d2 = sorted(d2.items(), key=lambda x:-x[0])
if d1[0][0] != d2[0][0]:
    print(n-d1[0][1]-d2[0][1])
else:
    if len(d1==1):
        print(n-d1[0][1]-d2[1][1])
    elif len(d2==1):
        print(n-d1[1][1]-d2[0][1])
    else:
        print(n-max(d1[0][1]+d2[1][1],d1[1][1]+d2[0][1]))

Submission status: Runtime Error

Solution code:
from collections import Counter

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

Vodd = V[: len(V):2]
Veven = V[1: len(V):2]

if Vodd == Veven:
    print(n // 2)


Voc = Counter(Vodd)
Vec = Counter(Veven)

Voc_val, Voc_cnt = zip(*Voc.most_common())
Vec_val, Vec_cnt = zip(*Vec.most_common())

num = Voc.most_common()[0][1] + Vec.most_common()[0][1]

if Voc_val[0] == Vec_val[0]:
    Voc_cnt += 0
    Vec_cnt += 0
    num += max(Voc_val[1] - Voc_val[0], Vec_val[1] - Vec_val[0])

print(n - num)

Submission status: Runtime Error

Solution code:
from collections import Counter

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

Vodd = V[: len(V):2]
Veven = V[1: len(V):2]

for i in range(n):
    if V[0] != V[i]:
        break
    elif i == n - 1:
        print(min(len(Veven), len(Vodd)))
        exit()


Voc = Counter(Vodd)
Vec = Counter(Veven)

if Vodd == Veven:
    if Voc.most_common()[1][1] - Voc.most_common()[0][1] > Vec.most_common()[1][1] - Vec.most_common()[0][1]:
        num = Voc.most_common()[0][1] + Vec.most_common()[1][1]
else:
    num = Voc.most_common()[0][1] + Vec.most_common()[0][1]


print(n - num)

Submission status: Runtime Error

Solution code:
from collections import defaultdict
n = int(input())
v = list(map(int,input().split()))
a = v[::2]
b = v[1::2]
def calc(l):
    d = defaultdict(int)
    for x in l:
        d[x] += 1
    return sorted([(d[x], x) for x in d],reverse=True)
A = calc(a)
B = calc(b)
al,ax = A[0]
bl,bx = B[0]
if ax != bx:
    print(n-al-bl)
else:
    ar,ay = A[1] if len(A) > 1 else 0,None
    br,by = B[1] if len(B) > 1 else 0,None
    print(min(n-al-br,n-ar-bl))

Submission status: Runtime Error

Solution code:
# ABC111c
from collections import Counter
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 6)


def calc():
    ans = 0
    for i in range(len(v)):
        if i % 2 == 0:
            if v[i] != f:
                ans += 1
        else:
            if v[i] != f2:
                ans += 1
    return ans


n = int(input())
v = list(map(int, input().split()))
f = Counter(v[::2]).most_common()[0][0]
f2 = Counter(v[1::2]).most_common()[0][0]
if f == f2:
    f2 = Counter(v[1::2]).most_common()[1][0]
    a = calc()
    f = Counter(v[::2]).most_common()[1][0]
    f2 = Counter(v[1::2]).most_common()[0][0]
    print(min(a, calc()))
else:
    print(calc())

Submission status: Runtime Error

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

# special case
if len(set(v)) == 1:
    print(len(v) // 2)
    exit()

d_odds = {}
d_even = {}

for i in range(0, len(v), 2):
    if v[i] in d_even:
        d_even[v[i]] += 1
    else:
        d_even[v[i]] = 1
    
for i in range(1, len(v), 2):
    if v[i] in d_odds:
        d_odds[v[i]] += 1
    else:
        d_odds[v[i]] = 1
 
max_freq_even = max(d_even.values())
if len(d_even.values()) > 1:
    max_freq_even_2nd = sorted(d_even.values())
else:
    max_freq_even_2nd = float("inf")

max_freq_odds = max(d_odds.values())
if len(d_odds.values()) > 1:
    max_freq_odds_2nd = sorted(d_odds.values())
else:
    max_freq_odds_2nd = float("inf")

if max_freq_even == max_freq_odds and max_freq_even_2nd != float("inf") and max_freq_even_2nd != float("inf"):
    print(max(n-max_freq_even-max_freq_odds_2nd, n-max_freq_even_2nd-max_freq_odds))
    exit()

print(n - max_freq_even - max_freq_odds)

Submission status: Runtime Error

Solution code:
n = int(input())


v = [int(c) for c in input().split()]
v1 = [0 for _ in range(10**5)]
v2 = [0 for _ in range(10**5)]
for i in range(n):
    if i % 2 == 0:
        v1[v[i]] += 1
    else:
        v2[v[i]] += 1

if v1.index(max(v1)) == v2.index(max(v2)):
    m1 = sorted(set(v1))[-2]
    m2 = sorted(set(v2))[-2]
    if m1 > m2:
        print(n-m1-max(v2))
    else:
        print(n-max(v1)-m2)
else:
    print(n-max(v1)-max(v2))

Submission status: Runtime Error

Solution code:
import itertools
import math
import sys

n = int(input())
v = list(map(int, input().split()))
if len(set(v)) == 1:
    print(n // 2)
else:
    odd_cnt = [0] * (10 ** 5)
    even_cnt = [0] * (10 ** 5)
    for i in range(len(v)):
        if i % 2 == 0:
            even_cnt[v[i]] += 1
        else:
            odd_cnt[v[i]] += 1
    odd = odd_cnt.index(max(odd_cnt))
    even = even_cnt.index(max(even_cnt))
    ans = 0
    for i in range(len(v)):
        if i % 2 == 0:
            if v[i] != even:
                ans += 1
        else:
            if v[i] != odd:
                ans += 1
    print(ans)

Submission status: Runtime Error

Solution code:
import itertools
import math
import sys

n = int(input())
v = list(map(int, input().split()))
if len(set(v)) == 1:
    print(n // 2)
else:
    odd_cnt = [0] * 10 ** 5
    even_cnt = [0] * 10 ** 5
    for i in range(len(v)):
        if i % 2 == 0:
            even_cnt[v[i]] += 1
        else:
            odd_cnt[v[i]] += 1
    odd = odd_cnt.index(max(odd_cnt))
    even = even_cnt.index(max(even_cnt))
    ans = 0
    for i in range(len(v)):
        if i % 2 == 0:
            if v[i] != even:
                ans += 1
        else:
            if v[i] != odd:
                ans += 1
    print(ans)

Submission status: Runtime Error

Solution code:
import itertools
import math
import sys

n = int(input())
v = list(map(int, input().split()))
if len(set(v)) == 1:
    print(n // 2)
else:
    odd_cnt = [0] * 10 ** 5
    even_cnt = [0] * 10 ** 5
    for i in range(len(v)):
        if i % 2 == 0:
            even_cnt[v[i]] += 1
        else:
            odd_cnt[v[i]] += 1
    odd = odd_cnt.index(max(odd_cnt))
    even = even_cnt.index(max(even_cnt))
    ans = 0
    print("odd =", odd)
    print("even =", even)
    for i in range(len(v)):
        if i % 2 == 0:
            if v[i] != even:
                ans += 1
        else:
            if v[i] != odd:
                ans += 1
    print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
l = list(input().split())
ll,lr = l[::2],l[1::2]
dl,dr = {},{}
for i in ll: dl[i] = dl.get(i,0)+1
for j in lr: dr[j] = dr.get(j,0)+1
ltl = sorted(dl.items(),key=lambda k:-k[1])
ltr = sorted(dr.items(),key=lambda k:-k[1])
if ltl[0][0] != ltr[0][0]:
  print(n-ltl[0][1]-ltr[0][1])
elif len(ltl)<2:
  print(n//2)
else:
  print(n-ltl[0][1]-max(lt1[1][1],ltr[1][1]))

Submission status: Runtime Error

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

odd = []
even = []

if len(set(v)) == 1:
    print(n//2)
    exit()

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

box_e = [0]*int(1e5)
box_o = [0]*int(1e5)

for i in range(n//2):
    box_e[even[i]] += 1
    box_o[odd[i]] += 1

mode_e = box_e.index(max(box_e))
mode_o = box_o.index(max(box_o))

ans = 0

for i in range(n//2):
    if odd[i] != mode_o:
        ans += 1
    if even[i] != mode_e:
        ans += 1

print(ans)

Submission status: Runtime Error

Solution code:
import collections
n = int(input())
v = list(map(int, input().split()))
if len(set(v)) == 1:
	print (n//2)
	exit()
a = v[1::2]
b = v[0::2]
if len(set(a)) == 1 and len(set(b)) == 1:
	print (0)
	exit()

aa = collections.Counter(a)
bb = collections.Counter(b)

yousoa = aa.most_common()[0][0]
maa = aa.most_common()[0][1]
yousob = bb.most_common()[0][0]
mbb = bb.most_common()[0][1]
if yousoa == yousob
	if len(a) == 1:
		ans = (len(a) - maa) + (len(b) - bb.most_common()[1][1])
	elif len(b) == 1:
		ans = (len(a) - aa.most_common()[1][1]) + (len(b)-mbb)
	else:
		ans = (len(a) - maa) + (len(b) - bb.most_common()[1][1])
else:
	ans = len(a)-maa + len(b)-mbb
print (ans)

Submission status: Runtime Error

Solution code:
from collections import Counter
from operator import itemgetter

n = int(input())
v = [int(i) for i in input().split()]
a = sorted(Counter(v[::2]).items(), key=itemgetter(1))
b = sorted(Counter(v[1::2]).items(), key=itemgetter(1))
ka, va = a[-1]
kb, vb = b[-1]
if ka != kb:
    print(n - va - vb)
else:
    sa = a[-2][1] if len(a) > 1 else va
    sb = b[-2][1] if len(b) > 1 else vb
    if len(a) == len(b) == 1:
        sa = 0
    if sa < sb:
        print(n - sa - vb)
    else:
        print(n - va - sb)
from collections import Counter
from operator import itemgetter

n = int(input())
v = [int(i) for i in input().split()]
a = sorted(Counter(v[::2]).items(), key=itemgetter(1))
b = sorted(Counter(v[1::2]).items(), key=itemgetter(1))
ka, va = a[-1]
kb, vb = b[-1]
if ka != kb:
    print(n - va - vb)
else:
    sa = a[-2][1] if len(a) > 1 else va
    sb = b[-2][1] if len(b) > 1 else vb
    if len(a) == len(b) == 1:
        sa = 0
    if sa < sb:
        print(n - sa - vb)
    else:
        print(n - va - sb)

Submission status: Runtime Error

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

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

even =Counter(even)
even = list(even.items())
even = sorted(even,key=itemgetter(1),reverse = True)

odd =Counter(odd)
odd = list(odd.items())
odd = sorted(odd,key=itemgetter(1),reverse = True)

cnt = 0
if len(odd) == 0 :
    if len(even) == 1:
        cnt = N // 2
    else:
        cnt = 0
elif len(even) == 0 :
    if len(odd) == 1:
        cnt = N // 2
    else:
        cnt = 0
#書き換える数は最頻出の上位２つ以外、つまりn-(even[0][1]+even[1][1])
elif even[0][1] != odd[0][1]:
    cnt = N - (even[0][1] + odd[0][1])
elif odd[0][1] == even[0][1]:
    if even[1][1] > odd[1][1]:
        cnt = N- (odd[0][1] + even[1][1])
    elif odd[1][1] > even[1][1]:
        cnt = N- (even[0][1] + odd[1][1])

print(cnt)

Submission status: Runtime Error

Solution code:
from collections import Counter
from operator import itemgetter

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

C = list(V.items())
C = sorted(C,key=itemgetter(1),reverse = True)
#print(C)

even = []
odd = []
for i in range(min(len(C),100)):
    if C[i][0] % 2 ==0:
        even.append(C[i])
    else:
        odd.append(C[i])
cnt = 0
if even[0][1] != odd[0][1]:
    for i in range(1,len(odd)):
        cnt += even[i][1]
    for i in range(1,len(even)):
        cnt += odd[i][1]
print(cnt)

Submission status: Runtime Error

Solution code:
from collections import Counter
from operator import itemgetter

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

#print(V)
#A = list(V.keys())
#B = list(V.values())
C = list(V.items())
C = sorted(C,key=itemgetter(0))

if len(C) == 3:
    ans = abs(C[0][1]- C[2][1])
elif len(C) == 2:
    ans = 0
elif len(C) == 1:
    ans = 2
print(ans)

Submission status: Runtime Error

Solution code:
from collections import Counter
N=int(input)
k=(N+1//2)
l=N-k
A=list(map(int,input()))
B=[]
for i in range(k)
	B.append(A.pop[i*2-1])
a=Counter(A)
b=Counter(B)
if a.most_common[0][0]==b.most_common[0][0]:
  if a.most_common[0][1]>=b.most_common[0][1]:
    x=l-a.most_common[0][1]
    y=b.most_common[1][1]
  else:
    x=l-a.most_common[1][1]
    y=b.most_common[0][1]
else:
  x=l-a.most_common[0][1]
  y=b.most_common[0][1]
print(x+y)

Submission status: Runtime Error

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

n = int(input())
a = list(map(int,input().split()))
cnt = [0]*(10**5)
for i in a:
    cnt[i] += 1
cnt.sort()
#print(cnt[-1])
if cnt[-1] >= (n+1)//2: print(n//2 - cnt[-2])
else: print((n+1)//2 - cnt[-1]+ n//2 - cnt[-2])

Submission status: Runtime Error

Solution code:
import sys
from collections import defaultdict

input_methods=['clipboard','file','key']
using_method=1
input_method=input_methods[using_method]

IN=lambda : map(int, input().split())
mod=1000000007

#+++++

def main():
	n = int(input())
	al = list(IN())
	odd_dd=defaultdict(lambda : 0)
	even_dd=defaultdict(lambda :0)
	for i, v in enumerate(al):
		if i%2==0:
			odd_dd[v] += 1
		else:
			even_dd[v] += 1
	
	odd_ll=[(odd_dd[key], key) for key in odd_dd.keys()]
	even_ll=[(even_dd[key], key) for key in even_dd.keys()]
	
	odd_ll.sort(reverse=True)
	even_ll.sort(reverse=True)
	kk=n//2
	pa(odd_ll)
	pa(even_ll)
	#全部同じ
	if len(odd_ll)==1 and len(even_ll)==1:
		a=4/0
		if odd_ll[0][1]==even_ll[0][1]:
			return kk
		else:
			return 0
	
	if odd_ll[0][1] == even_ll[0][1]:
		if odd_ll[0][0] >= even_ll[0][0]:
			return (kk-odd_ll[0][0])+(kk-even_ll[1][0])
		else:
			return (kk-odd_ll[1][0])+(kk-even_ll[0][0])
	else:
		return (kk-odd_ll[0][0])+(kk-even_ll[0][0])
	
	#pa(odd_ll)
	#print(str(a+b+c)+s)
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Submission status: Runtime Error

Solution code:
n = int(input())
l = list(map(int, input().split()))
l = sorted(l)
s = set(l)
counts = {}
total = 0
for i in s:
    c = l.count(i)
    counts[f'{i}'] = c
    total += c

if len(counts) == 1:
    print(total // 2)
elif len(counts) == 2:
    v = counts.values()
    print(max(v) - min(v))
else:
    a = counts.pop(max(counts, key=counts.get))
    b = counts.pop(max(counts, key=counts.get))
    print(total - a - b)

Submission status: Runtime Error

Solution code:
from collections import Counter
N = int(input())
V = list(map(int,input().split(" ")))
V1 = V[::2]
V2 = V[1::2]
ans = 0
if V1 == V2:
  ans = N//2
else:
  d1 = Counter(V1)
  d2 = Counter(V2)
  m1 = max(d1)
  m2 = max(d2)
  a = d1.pop(m1)
  b = d2.pop(m2)
  if a != b:
    if d1:
      ans += sum(d1.values())
    if d2:
      ans += sum(d2.values())
  else:
    c = max(d1.values())
    d = max(d2.values())
    tmp = N - a - d
    ans = min(tmp,N - b - c)
print(ans)

Submission status: Runtime Error

Solution code:
#111
from collections import Counter
n=int(input())
v=list(map(int,input().split()))
L=list(Counter(v[0::2]).items())
R=list(Counter(v[1::2]).items())


if L[0][0]!=R[0][0]:#再頻出の数がRとLで同一ではない場合
    ans=n-L[0][1]-R[0][1]
elif len(R)!=1 and len(L)!=1:
    ans=n-max(L[0][1]+R[1][1],L[1][1]+R[0][1])
elif len(R)!=1 and len(L)==1:
    ans=n-R[1][1]-L[0][1]
elif len(R)==1 and len(L)!=1:
    ans=n-R[0][1]-L[1][1]
elif : len(R)==1 and len(L)==1:
    ans=n//2
print(ans)

Submission status: Runtime Error

Solution code:
#112
from itertools import product

N=int(input())
px=[]
py=[]
ph=[]

for _ in range(N):
    x,y,h=map(int,input().split())
    if h!=0:
        px.append(x)
        py.append(y)
        ph.append(h)


        
def Calc_H(Cxi,Cyj,pxi,pyj,hi):
    return hi+abs(Cxi-pxi)+abs(Cyj-pyj)

    
    
for Cxi,Cyj in product(range(101),range(101)):
    preH=Calc_H(Cxi,Cyj,px[0],py[0],ph[0])
    for i in range(1,N):
        nowH=Calc_H(Cxi,Cyj,px[i],py[i],ph[i])
        if preH!=nowH:
            break
        preH=nowH
    else:
        print(Cxi,Cyj,nowH)

Submission status: Runtime Error

Solution code:
# n <= 10**5
n = int(input())
# vi <= 10**5
v = list(map(int, input().split()))
a = [[0, 0] for _ in range(100010)]
for i in range(n):
    a[i % 2][v[i]] += 1

od, ev = [], []
for i in range(100010):
    od.append([a[1][i], i])
    ev.append([a[0][i], i])
od.sort()
od.reverse()
ev.sort()
ev.reverse()
if od[0][1] != ev[0][1]: print(n - od[0][0] - ev[0][0])
else: print(n - max(od[0][0] + ev[[0][1], od[1][0] + ev[0][0]))

Submission status: Runtime Error

Solution code:
from collections import Counter
n=int(input())
A=list(map(int,input().split()))
A1=A[0:n-1:2]
A2=A[1:n:2]
L=Counter(A)
L1=Counter(A1)
L2=Counter(A2)
comon=L.most_common()
comon1=L1.most_common()
comon2=L2.most_common()
hanbun=n//2
if len(comon)==1:
    print(hanbun)
else:
    cnt=0
    saidai11=comon1[0][1]
    saidai21=comon2[0][1]
    if saidai11>=saidai21:
        cnt+=hanbun-saidai11
        if saidai11==saidai21:
            cnt+=hanbun-comon2[1][1]
        else:
            cnt+=hanbun-saidai21
    else:
        cnt+=hanbun-saidai11
        if saidai11==saidai21:
            cnt+=hanbun-comon1[1][1]
        else:
            cnt+=hanbun-saidai11
    print(cnt)

Submission status: Runtime Error

Solution code:
n = int(input())
l = list(map(int,input().split()))
dic1={}
dic2={}
for i in range(n):
  if i%2==0:
    if l[i] in dic1:
      dic1[l[i]] += 1
    else:
      dic1[l[i]].append(1)
  else:
    if l[i] in dic2:
      dic2[l[i]] += 1
    else:
      dic2[l[i]].append(1)
      
count = 0
ma = 0
check=0
for i in dic1.values():
  ma = max(ma,i)
  check += i
count += check-ma
ma = 0
check=0
for i in dic2.values():
  ma = max(ma,i)
  check += i
count += check-ma

print(count)

Submission status: Runtime Error

Solution code:
import sys

stdin = sys.stdin

mod = 1000000007

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()
nas = lambda: stdin.readline().split()

from collections import defaultdict

n = ni()
a = na()

d = defaultdict(int)
b = defaultdict(int)

for i in range(1, n + 1):
	if i % 2 == 0:
		d[a[i - 1]] += 1
	else:
		b[a[i - 1]] += 1

d_mkey, d_mval = [0] * 2
b_mkey, b_mval = [0] * 2

for k, v in d.items():
	if d_mval < v:
		d_mkey = k
		d_mval = v

for k, v in b.items():
	if b_mval < v:
		b_mkey = k
		b_mval = v

if d_mkey != b_mkey:
	print(n - d_mval - b_mval)
else:
	p = list(d.values())
	q = list(b.values())
	p.sort()
	q.sort()
	pv = p[len(p) - 2]
	qv = p[len(q) - 2]
	if pv <= qv:
		print((n - d_mval) + (n // 2 - qv))
	else:
		print((n - b_mval) + (n // 2 - pv))

Submission status: Runtime Error

Solution code:
from collections import Counter

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

if len(set(v)) != 1:
    a = Counter(v[0::2]).most_common()
    b = Counter(v[1::2]).most_common()

    if a[0] != b[0]:
        q = ((len(v[0::2]) - a[0][1]) + (len(v[1::2]) - b[0][1]))
        w = ((len(v[0::2]) - a[0][1]) + (len(v[1::2]) - b[1][1]))
        e = ((len(v[0::2]) - a[1][1]) + (len(v[1::2]) - b[0][1]))
        print(min(q, w, e))
else:
    print(len(v[1::2]))

Submission status: Runtime Error

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

even_idx_cnt = {}
odd_idx_cnt = {}
for idx, v in enumerate(V):
    if idx % 2 == 0:
        if v not in even_idx_cnt:
            even_idx_cnt[v] = 0
        even_idx_cnt[v] += 1
    else:
        if v not in odd_idx_cnt:
            odd_idx_cnt[v] = 0
        odd_idx_cnt[v] += 1

if len(even_idx_cnt) == 1 and len(odd_idx_cnt) == 1:
    if even_idx_cnt.keys() == odd_idx_cnt.keys():
        print(N - even_idx_cnt[V[0]])
    else:
        print(0)
    exit()

even_idx_cnt = sorted(even_idx_cnt.items(), key=lambda  x:x[1], reverse=True)
odd_idx_cnt = sorted(odd_idx_cnt.items(), key=lambda  x:x[1], reverse=True)

if even_idx_cnt[0][0] != odd_idx_cnt[0][0]:
    print(N - even_idx_cnt[0][1] - odd_idx_cnt[0][1])
elif len(even_idx_cnt[0][0]) == 1:
    print(N - even_idx_cnt[0][1] - odd_idx_cnt[1][1])
elif len(odd_idx_cnt[0][0]) == 1:
    print(N - even_idx_cnt[1][1] - odd_idx_cnt[0][1])
else:
    if even_idx_cnt[1][0] > odd_idx_cnt[1][0]:
        print(N - even_idx_cnt[0][1] - odd_idx_cnt[1][1])
    else:
        print(N - even_idx_cnt[1][1] - odd_idx_cnt[0][1])

Submission status: Runtime Error

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

even_idx_cnt = {}
odd_idx_cnt = {}
for idx, v in enumerate(V):
    if idx % 2 == 0:
        if v not in even_idx_cnt:
            even_idx_cnt[v] = 0
        even_idx_cnt[v] += 1
    else:
        if v not in odd_idx_cnt:
            odd_idx_cnt[v] = 0
        odd_idx_cnt[v] += 1

if len(even_idx_cnt) == 1 and len(odd_idx_cnt) == 1:
    if even_idx_cnt.keys() == odd_idx_cnt.keys():
        print(N - even_idx_cnt[V[0]])
    else:
        print(0)
    exit()

even_idx_cnt = sorted(even_idx_cnt.items(), key=lambda  x:x[1], reverse=True)
odd_idx_cnt = sorted(odd_idx_cnt.items(), key=lambda  x:x[1], reverse=True)

if even_idx_cnt[0][0] != odd_idx_cnt[0][0]:
    print(N - even_idx_cnt[0][1] - odd_idx_cnt[0][1])
elif even_idx_cnt[0][0] > odd_idx_cnt[0][0]:
    print(N - even_idx_cnt[0][1] - odd_idx_cnt[1][1])
else:
    print(N - even_idx_cnt[1][1] - odd_idx_cnt[0][1])
N = int(input())
V = list(map(int, input().split()))

even_idx_cnt = {}
odd_idx_cnt = {}
for idx, v in enumerate(V):
    if idx % 2 == 0:
        if v not in even_idx_cnt:
            even_idx_cnt[v] = 0
        even_idx_cnt[v] += 1
    else:
        if v not in odd_idx_cnt:
            odd_idx_cnt[v] = 0
        odd_idx_cnt[v] += 1

if len(even_idx_cnt) == 1 and len(odd_idx_cnt) == 1:
    if even_idx_cnt.keys() == odd_idx_cnt.keys():
        print(N - even_idx_cnt[V[0]])
    else:
        print(0)
    exit()

even_idx_cnt = sorted(even_idx_cnt.items(), key=lambda  x:x[1], reverse=True)
odd_idx_cnt = sorted(odd_idx_cnt.items(), key=lambda  x:x[1], reverse=True)

if even_idx_cnt[0][0] != odd_idx_cnt[0][0]:
    print(N - even_idx_cnt[0][1] - odd_idx_cnt[0][1])
elif len(even_idx_cnt[0][0]) == 1:
    print(N - even_idx_cnt[0][1] - odd_idx_cnt[1][1])
elif len(odd_idx_cnt[0][0]) == 1:
    print(N - even_idx_cnt[1][1] - odd_idx_cnt[0][1])
else:
    if even_idx_cnt[1][0] > odd_idx_cnt[1][0]:
        print(N - even_idx_cnt[0][1] - odd_idx_cnt[1][1])
    else:
        print(N - even_idx_cnt[1][1] - odd_idx_cnt[0][1])

Submission status: Runtime Error

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

even_idx_cnt = {}
odd_idx_cnt = {}
for idx, v in enumerate(V):
    if idx % 2 == 0:
        if v not in even_idx_cnt:
            even_idx_cnt[v] = 0
        even_idx_cnt[v] += 1
    else:
        if v not in odd_idx_cnt:
            odd_idx_cnt[v] = 0
        odd_idx_cnt[v] += 1

if len(even_idx_cnt) == 1 and len(odd_idx_cnt) == 1:
    if even_idx_cnt.keys() == odd_idx_cnt.keys():
        print(N - even_idx_cnt[V[0]])
    else:
        print(0)
    exit()

even_idx_cnt = sorted(even_idx_cnt.items(), key=lambda  x:x[1], reverse=True)
odd_idx_cnt = sorted(odd_idx_cnt.items(), key=lambda  x:x[1], reverse=True)

if even_idx_cnt[0][0] != odd_idx_cnt[0][0]:
    print(N - even_idx_cnt[0][1] - odd_idx_cnt[0][1])
elif even_idx_cnt[0][0] > odd_idx_cnt[0][0]:
    print(N - even_idx_cnt[0][1] - odd_idx_cnt[1][1])
else:
    print(N - even_idx_cnt[1][1] - odd_idx_cnt[0][1])
N = int(input())
V = list(map(int, input().split()))

even_idx_cnt = {}
odd_idx_cnt = {}
for idx, v in enumerate(V):
    if idx % 2 == 0:
        if v not in even_idx_cnt:
            even_idx_cnt[v] = 0
        even_idx_cnt[v] += 1
    else:
        if v not in odd_idx_cnt:
            odd_idx_cnt[v] = 0
        odd_idx_cnt[v] += 1

if len(even_idx_cnt) == 1 and len(odd_idx_cnt) == 1:
    if even_idx_cnt.keys() == odd_idx_cnt.keys():
        print(N - even_idx_cnt[V[0]])
    else:
        print(0)
    exit()

even_idx_cnt = sorted(even_idx_cnt.items(), key=lambda  x:x[1], reverse=True)
odd_idx_cnt = sorted(odd_idx_cnt.items(), key=lambda  x:x[1], reverse=True)

if even_idx_cnt[0][0] != odd_idx_cnt[0][0]:
    print(N - even_idx_cnt[0][1] - odd_idx_cnt[0][1])
else:
    if even_idx_cnt[1][0] > odd_idx_cnt[1][0]:
        print(N - even_idx_cnt[0][1] - odd_idx_cnt[1][1])
    else:
        print(N - even_idx_cnt[1][1] - odd_idx_cnt[0][1])

Submission status: Runtime Error

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

dic0 = [0 for i in range(10**5+1)]
dic1 = [0 for i in range(10**5+1)]
for i in range(n):
    if i%2==0:    
        dic0[v[i]] += 1
    if i%2==1:
        dic1[v[i]] += 1

MX0_1 = max(dic0)
MX1_1 = max(dic1)

li0 = []
li1 = []


for i in range(10**5+1):
    # if dic0[i]>10:
    #     print(i,dic0[i])
    # if dic1[i]>10:
    #     print(i,dic1[i],"\n")
    
    if dic0[i] == MX0_1:
        li0.append(i)
        dic0[i] = 0
    if dic1[i] == MX1_1:
        li1.append(i)
        dic1[i] = 0

# print(li0,li1)
# print(MX0_1,MX0_1)

if len(li0)>=2 or len(li1)>=2:
    print(n-MX0_1-MX1_1)
elif li0[0] == li1[0]:
    if MX0_1+max(dic1) >= MX1_1+max(dic0):
        print(n-MX0_1-max(dic1))
    else:
        print(n-MX1_1-max(dic0))
        print(1/0)

elif li0[0] != li1[0]:
    print(n-MX0_1-MX1_1)