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


def main():
    n = int(input())
    aa = list(map(int, input().split()))
    cs_a0 = Counter(a for i, a in enumerate(aa) if i % 2 == 0)
    cs_a1 = Counter(a for i, a in enumerate(aa) if i % 2 == 1)

    vs_a0 = sorted(((v, k) for k, v in cs_a0.items()), reverse=True)
    vs_a1 = sorted(((v, k) for k, v in cs_a1.items()), reverse=True)

    if vs_a0[0][1] != vs_a1[0][1]:
        print(n - vs_a0[0][0] - vs_a1[0][0])
    else:
        res = n // 2
        if len(vs_a0) > 1:
            res = min(n - vs_a0[1][0] - vs_a1[0][0])
        if len(vs_a1) > 1:
            res = min(n - vs_a0[0][0] - vs_a1[1][0])
        print(res)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
N = int(input())
v = list(map(int,input().split()))
v_even = [0 for i in range(max(v)+1)]
v_odd = [0 for i in range(max(v))+1]
sum_even = 0
sum_odd = 0
for i in range(N):
    if i%2 :
        v_odd[v[i]] += 1
        sum_odd += 1
    else:
        v_even[v[i]] += 1
        sum_even += 1
max_odd = 0
odd = 0
max_even = 0
even = 0
for i in range(len(v_odd)):
    if v_odd[i] > max_odd:
        max_odd = v_odd[i]
        odd = i

for i in range(len(v_even)):
    if v_even[i] > max_even:
        max_even = v_even[i]
        even = i

if odd != even:
    ans = sum_even - max_even + sum_odd - max_odd
else:
    v_odd[odd] = 0
    v_even[even] = 0
    ans = min((sum_even - max_even + sum_odd - max(v_odd)), sum_even - max(v_even) + sum_odd - max_odd)

print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
v = list(map(int,input().split()))
v_even = [0 for i in range(10**5)]
v_odd = [0 for i in range(10**5)]
sum_even = 0
sum_odd = 0
for i in range(N):
    if i%2 :
        v_odd[v[i]] += 1
        sum_odd += 1
    else:
        v_even[v[i]] += 1
        sum_even += 1
max_odd = 0
odd = 0
max_even = 0
even = 0
for i in range(10**5):
    if v_odd[i] > max_odd:
        max_odd = v_odd[i]
        odd = i

for i in range(10**5):
    if v_even[i] > max_even:
        max_even = v_even[i]
        even = i

if odd != even:
    ans = sum_even - max_even + sum_odd - max_odd
else:
    v_odd[odd] = 0
    v_even[even] = 0
    ans = min((sum_even - max_even + sum_odd - max(v_odd)), sum_even - max(v_even) + sum_odd - max_odd)

print(ans)

Submission status: Runtime Error

Solution code:
from collections import defaultdict
d0 = defaultdict(int)
d1 = defaultdict(int)
N=int(input())
v=list(map(int,input().split()))
for i in range(N):
    if i%2==0:
        d0[v[i]]+=1
    else:
        d1[v[i]]+=1
D0=sorted(d0.items(), key=lambda x:x[1],reverse=True)
D1=sorted(d1.items(), key=lambda x:x[1],reverse=True)
if (D0[0][1]+D1[0][1])==len(v) and D0[0][0]==D1[0][0]:
    print(len(v)//2)
else:
    i0=0
    i1=0
    while i0<=len(D0) or i1<=len(D1):
        if D0[i0][0]!=D1[i1][0] or (i0==len(D0) and i1==len(D1)):
            print(len(v)-D0[i0][1]-D1[i1][1])
            break
        else:
            if D0[i0][1]>D1[i1][1]:
                i1+=1
            elif D0[i0][1]<D1[i1][1]:
                i0+=1
            else:
                if (len(D0)-1-i0)>0 and (len(D1)-1-i1)>0:
                    if D[i0+1][1]>D[i1+1][1]:
                        i0+=1
                    else:
                        i1+=1
                elif (len(D0)-1-i0)==0 :
                    i1+=1
                elif (len(D1)-1-i1)==0:
                    i0+=1

Submission status: Runtime Error

Solution code:
from collections import defaultdict
d0 = defaultdict(int)
d1 = defaultdict(int)
N=int(input())
v=list(map(int,input().split()))
for i in range(N):
    if i%2==0:
        d0[v[i]]+=1
    else:
        d1[v[i]]+=1
D0=sorted(d0.items(), key=lambda x:x[1],reverse=True)
D1=sorted(d1.items(), key=lambda x:x[1],reverse=True)
if (D0[0][1]+D1[0][1])==len(v) and D0[0][0]==D1[0][0]:
    print(len(v)//2)
else:
    i0=0
    i1=0
    while i0<=len(D0) or i1<=len(D1):
        if D0[i0][0]!=D1[i1][0]:
            print(len(v)-D0[i0][1]-D1[i1][1])
            break
        else:
            if D0[i0][1]>D1[i1][1]:
                i1+=1
            elif D0[i0][1]<D1[i1][1]:
                i0+=1
            else:
                if (len(D0)-1-i0)>0 and (len(D1)-1-i1)>0:
                    if D[i0+1][1]>D[i1+1][1]:
                        i0+=1
                    else:
                        i1+=1
                elif (len(D0)-1-i0)==0 :
                    i1+=1
                elif (len(D1)-1-i1)==0:
                    i0+=1

Submission status: Runtime Error

Solution code:
from collections import defaultdict
d0 = defaultdict(int)
d1 = defaultdict(int)
N=int(input())
v=list(map(int,input().split()))
for i in range(N):
    if i%2==0:
        d0[v[i]]+=1
    else:
        d1[v[i]]+=1
D0=sorted(d0.items(), key=lambda x:x[1],reverse=True)
D1=sorted(d1.items(), key=lambda x:x[1],reverse=True)
if (D0[0][1]+D1[0][1])==len(v) and D0[0][0]==D1[0][0]:
    print(len(v)//2)
else:
    i0=0
    i1=0
    while i0<=len(D0) and i1<=len(D1):
        if D0[i0][0]!=D1[i1][0]:
            print(len(v)-D0[i0][1]-D1[i1][1])
            break
        else:
            if D0[i0][1]>D1[i1][1]:
                i1+=1
            elif D0[i0][1]<D1[i1][1]:
                i0+=1
            else:
                if (len(D0)-1-i0)>0 and (len(D1)-1-i1)>0:
                    if D[i0+1][1]>D[i1+1][1]:
                        i0+=1
                    else:
                        i1+=1
                elif (len(D0)-1-i0)==0 :
                    i1+=1
                elif (len(D1)-1-i1)==0:
                    i0+=1

Submission status: Runtime Error

Solution code:
from collections import defaultdict
d0 = defaultdict(int)
d1 = defaultdict(int)
N=int(input())
v=list(map(int,input().split()))
for i in range(N):
    if i%2==0:
        d0[v[i]]+=1
    else:
        d1[v[i]]+=1
D0=sorted(d0.items(), key=lambda x:x[1],reverse=True)
D1=sorted(d1.items(), key=lambda x:x[1],reverse=True)
if (D0[0][1]+D1[0][1])==len(v) and D0[0][0]==D1[0][0]:
    print(len(v)//2)
else:
    i0=0
    i1=0
    while i0<=len(D0) and i1<=len(D1):
        if D0[i0][0]!=D1[i1][0]:
            print(len(v)-D0[i0][1]-D1[i1][1])
            break
        else:
            if D0[i0][1]>D1[i1][1]:
                i1+=1
            elif D0[i0][1]<D1[i1][1]:
                i0+=1
            else:
                if (D0-1-i0)>0 and (D1-1-i1)>0:
                    if D[i0+1][1]>D[i1+1][1]:
                        i0+=1
                    else:
                        i1+=1
                elif (D0-1-i0)==0:
                    i1+=1
                elif (D1-1-i1)==0:
                    i0+=1

Submission status: Runtime Error

Solution code:
from collections import defaultdict
d = defaultdict(int)
n=int(input())
v=list(map(int,input().split()))
for i in range(n):
    d[v[i]]+=1
D=sorted(d.items(), key=lambda x:x[1])
if len(D)==1:
    print(D[0][1]//2)
elif len(D)==2:
    print(0)
else len(D)>=3:
    h=0
    for i in range(len(D)-2):
        h+=D[i][1]
    print(h)

Submission status: Runtime Error

Solution code:
n = int(input())
v = [{}, {}]
for i, vi in enumerate(map(int, input().split())):
    j = i % 2
    if vi in v[j]:
        v[j][vi] += 1
    elif not (vi in v[j]):
        v[j][vi] = 1
f1 = lambda v, i: max(v[i], key=v[i].get) if len(v[i]) > 0 else 0
f2 = lambda v, i, k: v[i].pop(k) if len(v[i]) > 0 else 0
kMax = [[f1(v, 0), f1(v, 1)]]
vMax = [[f2(v, 0, kMax[0][0]), f2(v, 1, kMax[0][1])]]
if kMax[0][0] != kMax[0][1]:
    print(n - sum(vMax[0]))
else:
    kMax.append([f1(v, 0), f1(v, 1)])
    vMax.append([f2(v, 0, kMax[0][0]), f2(v, 1, kMax[0][1])])
    print(n - max([vMax[0][0] + vMax[1][1], vMax[0][1] + vMax[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*2])
	b.append(v[i*2+1])
A = collections.Counter(a)
B = collections.Counter(b)

if A.most_common()[0][0] != B.most_common()[0][0]:
	ans = n - A.most_common()[0][1] - B.most_common()[0][1]
elif len(A) > 1 and len(B) > 1:
	if A.most_common()[0][0] + B.most_common()[1][0] < A.most_common()[1][0] + B.most_common()[0][0]:
		ans = n - (A.most_common()[1][0] + B.most_common()[0][0])
	else:
		ans = n - (A.most_common()[0][0] + B.most_common()[1][0])
elif len(A)=1 and len(B)>1:
	ans = n - B.most_common()[1][0]
elif len(A)>1 and len(B)=1:
	ans = n - A.most_common()[1][0]
else:
	ans = n//2
print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
v = [int(i) for i in input().split()]
even = [0] * int(1e5+1)
odd = [0] * int(1e5+1)

for i, k in enumerate(v):
    if (i & 1 == 0):
        even[k] += 1
    else:
        odd[k] += 1

if even.index(max(even)) == odd.index(max(odd)):
    print(min(n - sorted(even, reverse=True)[1] - sorted(odd, reverse=True)[0],
              n - sorted(even, reverse=True)[0] - sorted(odd, reverse=True)[1]))
else:
    print(n - sorted(even, reverse=True)[0] - sorted(odd, reverse=True)[0])
n = int(input())
v = [int(i) for i in input().split()]
even = [0] * int(1e5+1)
odd = [0] * int(1e5+1)

for i, k in enumerate(v):
    if (i & 1 == 0):
        even[k] += 1
    else:
        odd[k] += 1

if even.index(max(even)) == odd.index(max(odd)):
    even.sort(reverse=True)
    odd.sort(reverse=True)
    print(min(n - even[1] - odd[0],
              n - even[0] - odd[1]))
else:
    even.sort(reverse=True)
    odd.sort(reverse=True)
    print(n - even[0] - odd[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*2])
	b.append(v[i*2+1])
A = collections.Counter(a)
B = collections.Counter(b)

if A.most_common()[0][0] != B.most_common()[0][0]:
	ans = n - A.most_common()[0][1] - B.most_common()[0][1]
else:
	if A.most_common()[0][0] + B.most_common()[1][0] < A.most_common()[1][0] + B.most_common()[0][0]:
		ans = n - (A.most_common()[1][0] + B.most_common()[0][0])
	else:
		ans = n - (A.most_common()[1][0] + B.most_common()[0][0])
print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
v = [int(i) for i in input().split()]
odd = [v[i] for i in range(n) if i % 2 == 1]
even = [v[i] for i in range(n) if i % 2 == 0]
summ_odd = {i: odd.count(i) for i in set(odd)}
summ_even = {i: even.count(i) for i in set(even)}
odd_max_k = max(summ_odd.items(), key=lambda x: x[1])[0]
even_max_k = max(summ_even.items(), key=lambda x: x[1])[0]
if odd_max_k == even_max_k:
    if len(summ_odd) == 1:
        if len(summ_even) == 1:
            print(n//2)
            exit()
        else:
            tmp = summ_even.pop(even_max_k)
            even_max_k = max(summ_even.items(), key=lambda x: x[1])[0]
            summ_even.upddate(tmp)
    else:
        tmp = summ_odd.pop(odd_max_k)
        odd_max_k = max(summ_odd.items(), key=lambda x: x[1])[0]
        summ_odd.upddate(tmp)

summ_odd.pop(odd_max_k)
summ_even.pop(even_max_k)
res = sum(summ_odd.values()) + sum(summ_even.values())
print(res)

Submission status: Runtime Error

Solution code:
from collections import Counter
 
n = int(input())
v_array = list(map(int,input().split()))
 
v_odd = v_array[0::2]
v_even = v_array[1::2]
 
v_odd_common = Counter(v_odd).most_common()
v_even_common = Counter(v_even).most_common()

v_odd_common.append((0,0))
v_even_common.append((0,0))

if v_odd_common[0] != v_even_common[0]:
    print(n-v_odd_common[0][1]-v_even_common[0][1])
else:
    print(min(n-v_odd_common[0][1]-v_even_common[1][1],n-v_odd_common[1][1]-v_even_common[0][1])

Submission status: Runtime Error

Solution code:
n-v_odd_common[0][1]-v_even_common[1][1]

Submission status: Runtime Error

Solution code:
from collections import Counter
from sys import exit

n = input()
v_array = list(map(int,input().split()))
 
v_odd = v_array[0::2]
v_even = v_array[1::2]
 
v_odd_common = Counter(v_odd).most_common()
v_even_common = Counter(v_even).most_common()

if len(set(v_array)) == 1:
    print(int(len(v_array)/2))
    exit()

for i in range(0,min(len(v_odd_common),len(v_even_common))):
    if v_odd_common[i] == v_even_common[i]:
        if v_odd_common[i+1][1] > v_even_common[i+1][1]:
            v_odd_common_candidate = v_odd_common[i][1]
            v_even_common_candidate = v_even_common[i+1][i]
            break
        elif v_odd_common[i+1][1] < v_even_common[i+1][1]:
            v_odd_common_candidate = v_odd_common[i+1][1]
            v_even_common_candidate = v_even_common[i][i]
            break
        else:
            v_odd_common_candidate = v_odd_common[i][1]
            v_even_common_candidate = v_even_common[i][i]
            break
    else:
        v_odd_common_candidate = v_odd_common[0][1]
        v_even_common_candidate = v_even_common[0][1]
    
print(len(v_odd) - v_odd_common_candidate + len(v_even) - v_even_common_candidate)

Submission status: Runtime Error

Solution code:
from collections import Counter
from sys import exit

n = input()
v_array = list(map(int,input().split()))
 
v_odd = v_array[0::2]
v_even = v_array[1::2]
 
v_odd_common = Counter(v_odd).most_common()
v_even_common = Counter(v_even).most_common()

if len(set(v_array)) == 1:
    print(int(len(v_array)/2))
    exit()

print(v_odd_common, v_even_common)
for i in range(0,min(len(v_odd_common),len(v_even_common))):
    if v_odd_common[i] == v_even_common[i]:
        if v_odd_common[i+1][1] > v_even_common[i+1][1]:
            v_odd_common_candidate = v_odd_common[i][1]
            v_even_common_candidate = v_even_common[i+1][i]
            break
        elif v_odd_common[i+1][1] < v_even_common[i+1][1]:
            v_odd_common_candidate = v_odd_common[i+1][1]
            v_even_common_candidate = v_even_common[i][i]
            break
        else:
            v_odd_common_candidate = v_odd_common[i][1]
            v_even_common_candidate = v_even_common[i][i]
            break
    else:
        v_odd_common_candidate = v_odd_common[0][1]
        v_even_common_candidate = v_even_common[0][1]
    
print(len(v_odd) - v_odd_common_candidate + len(v_even) - v_even_common_candidate)

Submission status: Runtime Error

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

ki = []
gu = []

ki = x[0::2]
gu = x[1::2]

a = set(ki)

dd = 0
z = ki.count(a[0])
b = [0,z]
for i in range(1,len(a)):
    c = ki.count(a[i])
    b.append(c)
    if z < c:
        dd = i

a2 = set(gu)

bb = 0
y = gu.count(gu[0])
d = [0,y]
for i in range(1,len(a2)):
    c = gu.count(a2[i])
    d.append(c)
    if y < c:
        bb = i

if a[dd] != a2[bb]:
    print(len(ki)-max(b)+len(gu)-max(d))
else:
    if max(a) > max(a2):
        d = sorted(d, reverse=True)
        print(len(ki)-max(b)+len(gu)-d[1])
    else:
        b = sorted(b, reverse=True)
        print(len(ki)-b[1]+len(gu)-max(d))

Submission status: Runtime Error

Solution code:
from sys.stdin import readline
input = readline
n = input()
x = list(map(int,input().split(' ')))

ki = []
gu = []

ki = x[0::2]
gu = x[1::2]

a = [ki[0]]

for i in range(1,len(ki)):
    if ki[0] != ki[i]:
        a.append(ki[i])

dd = 0
z = ki.count(a[0])
b = [0,z]
for i in range(1,len(a)):
    c = ki.count(a[i])
    b.append(c)
    if z < c:
        dd = i

a2 = [gu[0]]

for p in range(1,len(gu)):
    if gu[0] != gu[i]:
        a2.append(gu[i])

bb = 0
y = gu.count(gu[0])
d = [0,y]
for i in range(1,len(a2)):
    c = gu.count(a2[i])
    d.append(c)
    if y < c:
        bb = i

if a[dd] != a2[bb]:
    print(len(ki)-max(b)+len(gu)-max(d))
else:
    if max(a) > max(a2):
        d = sorted(d, reverse=True)
        print(len(ki)-max(b)+len(gu)-d[1])
    else:
        b = sorted(b, reverse=True)
        print(len(ki)-b[1]+len(gu)-max(d))

Submission status: Runtime Error

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

e = v[::2]
o = v[1::2]

ev = {}
ov = {}
for t in e :
    if t in ev :
        ev[t] = ev[t] + 1
    else :
        ev[t] = 1

for t in o :
    if t in ov:
        ov[t] = ov[t] + 1
    else :
        ov[t] = 1

print(ev)
print(ov)

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

eidx = 0
oidx = 0
et = list(ev.values())[eidx]
ot = list(ov.values())[oidx]

if et == ot :
    if ev[et] > ov[ot] :
        if len(ot) > 1:
            ot = list(ov.values())[oidx+1]
    else:
        if len(et) > 1:
            et = list(ov.values())[eidx+1]

ans = len(e) - et + len(o) - ot
print(ans)

Submission status: Runtime Error

Solution code:
from statistics import mode

n = int(input())
v = list(map(int, input.split()))
a = v[::1]
b = v[1::1]
slash = mode(a)
back_slash = mode(b)
a = [i for i in a if i != slash]
b = [j for j in b if j != back_slash]
print(len(a) + len(b))

Submission status: Runtime Error

Solution code:
from statistics import mode

n = int(input())
v = list(map(int, input.split()))
a = v[::1]
b = v[1::1]
slash = mode(a)
back_slash = mode(b)
a = [i for i in a if i == slash]
b = [j for j in b if j == back_slash]
print(len(a) + len(b))

Submission status: Runtime Error

Solution code:
from collections import Counter

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

list0 = []
list1 = []
for i, a in enumerate(v):
    if i % 2 == 0:
        list0.append(a)
    else:
        list1.append(a)

c0 = Counter(list0)
c1 = Counter(list1)

c0_most_common = c0.most_common(2)
c1_most_common = c1.most_common(2)

if c0_most_common[0][0] != c1_most_common[0][0]:
    print(n - (c0_most_common[0][1] + c1_most_common[0][1]))
else:
    print(min(n - (c0_most_common[0][1] + c1_most_common[1][1]), n - (c0_most_common[1][1] + c1_most_common[0][1])))

Submission status: Runtime Error

Solution code:
n=int(input())
v=map(int,input().split())
vodd={}
veven={}
for i,vi in enumerate(v):
    if i%2:
        if(vi in veven):
            veven[vi]+=1
        else:
            veven[vi]=1
    else:
        if(vi in vodd):
            vodd[vi]+=1
        else:
            vodd[vi]=1
veven=list(veven.items())
veven.sort(key=lambda x:x[1])
veven.reverse()
vodd=list(vodd.items())
vodd.sort(key=lambda x:x[1])
vodd.reverse()
if len(veven)==2 & len(vodd)==2:
    if veven[0][0]==vodd[0][0]:
        a=veven[0][1]+vodd[1][1]
        b=veven[1][1]+vodd[0][1]
        changeCnt=a if a<b else b
    else:
        changeCnt=veven[1][1]+vodd[1][1]
elif len(veven)==1 & len(vodd)==1:
    if veven[0][0]==vodd[0][0]:
        a=vodd[0][1]
        b=veven[0][1]
        changeCnt=a if a<b else b
    else:
        changeCnt=0
elif len(veven)==1:
    if veven[0][0]==vodd[0][0]:
        changeCnt=vodd[0][1]
    else:
        changeCnt=vodd[1][1]
elif len(vodd)==1:
    if veven[0][0]==vodd[0][0]:
        changeCnt=veven[0][1]
    else:
        changeCnt=veven[1][1]

print(changeCnt)

Submission status: Runtime Error

Solution code:
n=int(input())
v=map(int,input().split())
vodd=[]
voddNum={}
veven=[]
vevenNum={}
for i,vi in enumerate(v):
    if i%2:
        veven.append(vi)
        if(vi in vevenNum):
            vevenNum[vi]+=1
        else:
            vevenNum[vi]=1
    else:
        vodd.append(vi)
        if(vi in voddNum):
            voddNum[vi]+=1
        else:
            voddNum[vi]=1
vevenNum=list(vevenNum.items())
voddNum=list(voddNum.items())
vevenNum.sort(key=lambda x:x[1])
vevenNum.reverse()
voddNum.sort(key=lambda x:x[1])
voddNum.reverse()
if len(vevenNum)==2 & len(voddNum)==2:
    if vevenNum[0][0]==voddNum[0][0]:
        a=vevenNum[0][1]+voddNum[1][1]
        b=vevenNum[1][1]+voddNum[0][1]
        changeCnt=a if a<b else b
    else:
        changeCnt=vevenNum[1][1]+voddNum[1][1]
elif len(vevenNum)==1 & len(voddNum)==1:
    if vevenNum[0][0]==voddNum[0][0]:
        changeCnt=voddNum[0][1] if voddNum[0][1]<vevenNum[0][1] else vevenNum[0][1]
    else:
        changeCnt=0
elif len(vevenNum)==1:
    if vevenNum[0][0]==voddNum[0][0]:
        changeCnt=voddNum[0][1]
    else:
        changeCnt=voddNum[1][1]
elif len(voddNum)==1:
    if vevenNum[0][0]==voddNum[0][0]:
        changeCnt=vevenNum[0][1]
    else:
        changeCnt=vevenNum[1][1]

print(changeCnt)

Submission status: Runtime Error

Solution code:
N = int(input())
v_list = input().split()

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

v1_dict = {}
v2_dict = {}

for i, num in enumerate(v_list):
    if i%2 == 0:
        v1_dict[num] = v1_dict[num] + 1 if num in v1_dict else 0
    else:
        v2_dict[num] = v2_dict[num] + 1 if num in v2_dict else 0

v1_dict = sorted(v1_dict.items(), key=lambda x: -(len(v1_dict) - x[1]))
v2_dict = sorted(v2_dict.items(), key=lambda x: -(len(v2_dict) - x[1]))

if v1_dict[0][0] != v2_dict[0][0]:
    ans = v1_dict[0][1] + v2_dict[0][1]
elif max_value_v1 > max_value_v2:
    ans = v1_dict[1][1] + v2_dict[0][1]
else:
    ans = v1_dict[0][1] + v2_dict[1][1]
print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
v_list = input().split()

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

v1_dict = {}
v2_dict = {}

for i, num in enumerate(v_list):
    if i%2 == 0:
        v1_dict[num] = v1_dict[num] + 1 if num in v1_dict else 0
    else:
        v2_dict[num] = v2_dict[num] + 1 if num in v2_dict else 0

v1_dict = sorted(v1_dict.items(), key=lambda x: -x[1])
v2_dict = sorted(v2_dict.items(), key=lambda x: -x[1])

if v1_dict[0][0] != v2_dict[0][0]:
    ans = v1_dict[0][1] + v2_dict[0][1]
elif max_value_v1 > max_value_v2:
    ans = v1_dict[1][1] + v2_dict[0][1]
else:
    ans = v1_dict[0][1] + v2_dict[1][1]
print(ans)

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0;i < n;i++)
#define FOR(i, m, n) for(ll i = m;i < n;i++)

vector<pair<int, int>> counter(map<int, int> m) {
  vector<pair<int, int>> v;
  for (auto&& i : m) {
    v.push_back(make_pair(i.first, i.second));
  }
  return v;
}

int main() {
  cin.tie(0); ios::sync_with_stdio(false);

  int n;
  cin >> n;
  int v[100000];
  rep(i, n) cin >> v[i];

  map<int, int> a;
  map<int, int> b;
  rep(i, n) {
    if (i&1) {
      a[v[i]]++;
    } else {
      b[v[i]]++;
    }
  }

  vector<pair<int, int>> A = counter(a);
  vector<pair<int, int>> B = counter(b);
  sort(A.end(), A.end(), [](pair<int, int> a, pair<int, int> b){return a.second > b.second;});
  sort(B.end(), B.end(), [](pair<int, int> a, pair<int, int> b){return a.second > b.second;});

  if (A[0].first == B[0].first) {
    int a1 = (A.size() == 1 ? n/2 : A[1].second);
    int b1 = (B.size() == 1 ? n/2 : B[1].second);
    cout << n - max(a1, b1);
  } else {
    cout << n - A[0].second - B[0].second << endl;
  }
}

Submission status: Runtime Error

Solution code:
s2.sort(reverse=True)
t2.sort(reverse=True)
sc = -1
tc = -1
sk = 0
tk = 0

for i in s2:
    if sc == -1:
        sk = i
    elif sc == 0:
        sk = i
        break
    sc += 1
if sc == 0:
    sk = 0

for i in t2:
    if tc == -1:
        tk = i
    elif tc == 0:
        tk = i
        break
    tc += 1
if tc == 0:
    tk = 0

if q[s.index(max(s))] != r[t.index(max(t))]:
    print(n - max(s) - max(t))
else:
    if sk >= tk:
        print(n - sk - max(t))
    else:
        print(n - max(s) - tk)

Submission status: Runtime Error

Solution code:
import collections

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

ans = 0
gu = v[::2]
ki = v[1::2]

gudic = collections.Counter(gu)
kidic = collections.Counter(ki)

gumax = gudic.most_common()
kimax = kidic.most_common()



if gumax[0][0] != kimax[0][0]:
    print((n // 2 - gumax[0][1]) + (n // 2 - kimax[0][1]))
else:
    if len(gumax) == len(kimax) == 1:
        print(n // 2)
    elif len(gumax) == 1 and len(kimax) >= 2:
        print((n // 2 -gumax[0][1]) + (n // 2 - kimax[1][1]))
    
    elif len(gumax) >= 2 and len(kimax) == 1:
        print((n // 2 -gumax[1][1]) + (n // 2 - kimax[0][1]))
    else: 
        one = (n // 2 - gumax[0][1]) + (n // 2 - kimax[1][1])
        ano = (n // 2 - gumax[1][1]) + (n // 2 - kimax[0][[1]])
        print(max(one, ano))

Submission status: Runtime Error

Solution code:
import collections

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

ans = 0
gu = v[::2]
ki = v[1::2]

gudic = collections.Counter(gu)
kidic = collections.Counter(ki)

gumax = gudic.most_common()
kimax = kidic.most_common()

if gumax[0][0] != kimax[0][0]:
    print((n // 2 - gumax[0][1]) + (n // 2 - kimax[0][1]))
else:
    one = (n // 2 - gumax[0][1]) + (n // 2 - kimax[1][1])
    ano = (n // 2 - gumax[1][1]) + (n // 2 - kimax[0][[1]])
    print(max(one, ano))

Submission status: Runtime Error

Solution code:
from collections import Counter
n = int(input())
x = list(map(int,input().split()))
even = [j for i,j in enumerate(x) if i%2==0]
odd = [j for i,j in enumerate(x) if i%2==1]
evencnt = Counter(even).most_common()[0][1]
oddcnt = Counter(odd).most_common()[0][1]()
if set(x) == 1:
    print(n/2)
else:
    print(n-evencnt-oddcnt)

Submission status: Runtime Error

Solution code:
n=int(input())
v=[int(i) for i in input().split()]
v_0=[]
v_1=[]
for i in range(len(v)):
    mod=1%2
    if mod==0:
        v_0.append(v[i])
    else:
        v_1.append(v[i])
c_v0=[]
c_v1=[]
for i in v_0:
    ci=v_0.count(i)
    c_v0.append(ci)
for i in v_1:
    ci=v_1.count(i)
    c_v1.append(ci)
m=len(v)-max(c_v1)-max(c_v0)
print(m)

Submission status: Runtime Error

Solution code:
n=int(input())
v=[int(i) for i in input().split()]
v_0=[]
v_1=[]
for i in range(len(v)):
    mod=1%2
    if mod==0:
        v_0.append(v[i])
    else:
        v_1.append(v[i])
c_v0=[]
c_v1=[]
for i in v_0:
    ci=v_0.count(i)
    c_v0.append(ci)
for i in v_1:
    ci=v_1.count(i)
    c_v1.append(ci)
m=len(v)-max(c_v1)-max(c_v0)

Submission status: Runtime Error

Solution code:
from collections import Counter
n = int(input().strip())
a = list(map(int, input().strip().split()))
 
c1 = Counter(a[::2])
c2 = Counter(a[1::2])
c1f1 = max(c1, key = lambda k:c1[k])
c2f1 = max(c2, key = lambda k:c2[k])
 
if c1f1 != c2f1:
  return n - c1[c1f1] - c2[c2f1]
else:
  if c1[c1f1] > c2[c2f1]:
    del c2[c2f1]
    if not c2: return n-c1[c1f1]
    c2f1 = max(c2, key = lambda k:c2[k])
    return n-c1[c1f1] - c2[c2f1]
  else:
    del c1[c1f1]
    if not c1: return n-c2[c2f1]
    c1f1 = max(c1, key = lambda k:c1[k])
    return n-c1[c1f1] - c2[c2f1]

Submission status: Runtime Error

Solution code:
from collections import Counter

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

V1 = [V[i] for i in range(0, len(V), 2)]
V2 = [V[i] for i in range(1, len(V), 2)]

x = Counter(V1).most_common(2)
y = Counter(V2).most_common(2)
if x[0][1] < y[0][1]:
    x, y = y, x
elif x[0][1] == y[0][1] and x[1][1] > y[1][1]:
    x, y = y, x

l = int(N / 2)
res = l - x[0][1]
if y[0][0] == x[0][0]:
    res += l - (y[1][1] if len(y) > 1 else 0)
else:
    res += l - y[0][1]

print(res)

Submission status: Runtime Error

Solution code:
import collections

n = int(input())
V = [int(x) for x in input().split()]
V_even = collections.Counter([V[i] for i in range(len(V)) if i % 2 == 1])
V_odd = collections.Counter([V[i] for i in range(len(V)) if i % 2 == 0])
even_most = V_even.most_common()
odd_most = V_odd.most_common()
if len(even_most) == 1 and len(odd_most) == 1 and even_most[0][0] == odd_most[0][0]:
    ans = n/2
    print(int(ans))
elif len(even_most) == 1:
    ans = n/2 - V_even[even_most[0][0]] + n/2 - V_odd[odd_most[1][0]]
    print(int(ans))
elif len(odd_most) == 1:
    ans = n/2 - V_even[even_most[1][0]] + n/2 - V_odd[odd_most[0][0]]
    print(int(ans))
elif even_most[0][0] is not odd_most[0][0]:
    ans = n/2 - V_even[even_most[0][0]] + n/2 - V_odd[odd_most[0][0]]
    print(int(ans))
else:
    ans1 = n/2 - V_even[even_most[0][0]] + n/2 - V_odd[odd_most[1][0]]
    ans2 = n/2 - V_even[even_most[1][0]] + n/2 - V_odd[odd_most[0][0]]
    print(int(min(ans1, ans2)))

Submission status: Runtime Error

Solution code:
import collections

n = int(input())
V = [int(x) for x in input().split()]
V_even = collections.Counter([V[i] for i in range(len(V)) if i % 2 == 0])
V_odd = collections.Counter([V[i] for i in range(len(V)) if i % 2 == 1])
even_most = V_even.most_common()
odd_most = V_odd.most_common()
if even_most[0][0] is not odd_most[0][0]:
    ans = n/2 - V_even[even_most[0][0]] + n/2 - V_odd[odd_most[0][0]]
    print(int(ans))
else:
    if even_most[0][1] >= odd_most[0][1]:
        ans = n/2 - V_even[even_most[0][0]] + n/2 - V_odd[odd_most[1][0]]
    else:
        ans = n/2 - V_even[even_most[1][0]] + n/2 - V_odd[odd_most[0][0]]
    print(int(ans))

Submission status: Runtime Error

Solution code:
def solve(N, ls_v):
    # Uncomment the following if you want to check the input.
    #print('N =', N)
    #print('ls_v =', ls_v)
    di1={}
    di2={}
    i=11
    for line in ls_v:
        if i % 2 == 0:
            if line not in di2:
                di2[line] = 1
            else:
                di2[line] +=1
        else:
            if line not in di1:
                di1[line] = 1
            else:
                di1[line] +=1
        i += 1
        a = [i for i in di1.values()]
        b = [i for i in di2.values()]
        
    #print("偶数リスト→",di2)
    #print("奇数リスト→",di1) 
    #print(a,b)
    #print(max(b))
    if max(a) + max(b) == N:
        return 0
    elif N - (max(a)+max(b)) ==0:
        return N-(max(a)+max(b)/2)
    else:
        N - (max(a)+max(b))
    

def readQuestion():
    ws = sys.stdin.readline().strip().split()
    N = int(ws[0])
    ws = sys.stdin.readline().strip().split()
    ls_v = list(map(int, ws))
    return (N, ls_v)

def main():
    print(solve(*readQuestion()))

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import collections

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

b = a[::2]
c = a[1::2]

b_ =collections.Counter(b)
c_ =collections.Counter(c)

baa = b_.most_common(b_)
caa = c_.most_common(c_)

baa.append([0,0])
caa.append([0,0])

if baa[0][0] != caa[0][0]:
    print(N - baa[0][1] - caa[0][1])
else:
    print(max(N - baa[0][1] - caa[1][1],N - caa[0][1] - baa[1][1]))

Submission status: Runtime Error

Solution code:
import collections

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

b = a[::2]
c = a[1::2]

b_ =collections.Counter(b)
c_ =collections.Counter(c)

baa = b_.most_common(b_)
caa = c_.most_common(c_)

baa.append([0,0])
caa.append([0,0])

if baa[0][0] != caa[0][0]:
    print(N - baa[0][1] - caa[0][1])
else:
    print(max(N - baa[0][1] - caa[1][1],N - caa[0][1] - baa[1][1]))