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:
#!/usr/bin/env python3
import sys
import statistics
import collections

def solve(n: int, v: "List[int]"):
    half_length = len(v) // 2
    O = [v[i] for i in range(1, n, 2)]
    E = [v[i] for i in range(0, n, 2)]

    co = list(collections.Counter(O).most_common())
    ce = list(collections.Counter(E).most_common())
    o1 = co[0][0]
    e1 = ce[0][0]

    O_ = list(filter(lambda o: o != o1, O))
    E_ = list(filter(lambda e: e != e1, E))
    num_o_1 = len(O_) 
    num_e_1 = len(E_)
    if False and e1 != o1:
        num = num_o_1 + num_e_1
    else:
        if len(co) == 1 and len(ce) == 1:
            num = half_length
        elif len(co) == 1:
            e2 = ce[1][0]
            num_e_2 = len(list(filter(lambda e: e != e2, E)))
            num = num_o_1 + num_e_2
        elif len(ce) == 1:
            o2 = co[1][0]
            num_o_2 = len(list(filter(lambda o: o != o2, O)))
            num = num_o_2 + num_e_1
        else:
            e2 = ce[1][0]
            o2 = co[1][0]
            num = min(num_o_1 + num_e_2, num_o_2 + num_e_1)
    print(num)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    n = int(next(tokens))  # type: int
    v = [ int(next(tokens)) for _ in range(n) ]  # type: "List[int]"
    solve(n, v)

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
import sys
import statistics
import collections

def solve(n: int, v: "List[int]"):
    half_length = len(v) // 2
    O = [v[i] for i in range(1, n, 2)]
    E = [v[i] for i in range(0, n, 2)]

    co = list(collections.Counter(O).most_common())
    ce = list(collections.Counter(E).most_common())
    o1 = co[0][0]
    e1 = ce[0][0]

    O_ = list(filter(lambda o: o != o1, O))
    E_ = list(filter(lambda e: e != e1, E))
    num_o_1 = len(O_) 
    num_e_1 = len(E_)
    if e1 != o1:
        num = num_o_1 + num_e_1
    else:
        if len(co) == 1 and len(ce) == 1:
            num = half_length
        elif len(co) == 1:
            e2 = ce[1][0]
            num_e_2 = len(list(filter(lambda e: e != e2, E)))
            num = num_o_1 + num_e_2
        elif len(ce) == 1:
            o2 = co[1][0]
            num_o_2 = len(list(filter(lambda o: o != o2, O)))
            num = num_o_2 + num_e_1
        else:
            e2 = ce[1][0]
            o2 = co[1][0]
            num = min(num_o_1 + num_e_2, num_o_2 + num_e_1)
    print(num)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    n = int(next(tokens))  # type: int
    v = [ int(next(tokens)) for _ in range(n) ]  # type: "List[int]"
    solve(n, v)

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
import sys
import statistics
import collections

def solve(n: int, v: "List[int]"):
    half_length = len(v) // 2
    O = [v[i] for i in range(1, n, 2)]
    E = [v[i] for i in range(0, n, 2)]

    co = list(collections.Counter(O).most_common())
    ce = list(collections.Counter(E).most_common())
    o1 = co[0][0]
    e1 = ce[0][0]

    O_ = list(filter(lambda o: o != o1, O))
    E_ = list(filter(lambda e: e != e1, E))
    num_o_1 = len(O_) 
    num_e_1 = len(E_)
    if e1 != o1:
        num = num_o_1 + num_e_1
    else:
        if len(co) == 1 and len(ce) == 1:
            num = half_length
        elif len(co) == 1:
            e2 = ce[1][0]
            num_e_2 = len(filter(lambda e: e != e2, E))
            num = num_o_1 + num_e_2
        elif len(ce) == 1:
            o2 = co[1][0]
            num_o_2 = len(filter(lambda o: o != o2, O))
            num = num_o_2 + num_e_1
        else:
            e2 = ce[1][0]
            o2 = co[1][0]
            num = min(num_o_1 + num_e_2, num_o_2 + num_e_1)
    print(num)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    n = int(next(tokens))  # type: int
    v = [ int(next(tokens)) for _ in range(n) ]  # type: "List[int]"
    solve(n, v)

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
import sys
import statistics
import collections

def solve(n: int, v: "List[int]"):
    half_length = len(v) // 2
    O = [v[i] for i in range(1, n, 2)]
    E = [v[i] for i in range(0, n, 2)]

    co = list(collections.Counter(O).most_common())
    ce = list(collections.Counter(E).most_common())
    o1 = co[0][0]
    e1 = ce[0][0]

    O_ = list(filter(lambda o: o != o1, O))
    E_ = list(filter(lambda e: e != e1, E))
    num_o_1 = len(O_) 
    num_e_1 = len(E_)
    if e1 != o1:
        num = num_o_1 + num_e_1
    else:
        if len(co) == 1 and len(ce) == 1:
            num = half_length
        elif len(co) == 1:
            e2 = ce[1][0]
            num_e_2 = len(filter(lambda e: e != e2, E))
            num = num_o_1 + num_e_2
        elif len(ce) == 1:
            o2 = co[1][0]
            num_o_2 = len(filter(lambda o: o != o2, O))
            num = num_o_2 + num_e_1
        else:
            e2 = ce[1][0]
            o2 = co[1][0]
            o1e2 = num_o_1 + num_e_2
            o2e1 = num_o_2 + num_e_1
            num = o1e2 if o1e2 < o2e1 else o2e1
    print(num)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    n = int(next(tokens))  # type: int
    v = [ int(next(tokens)) for _ in range(n) ]  # type: "List[int]"
    solve(n, v)

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
import sys
import statistics
import collections

def solve(n: int, v: "List[int]"):
    half_length = len(v) // 2
    O = [v[i] for i in range(1, n, 2)]
    E = [v[i] for i in range(0, n, 2)]

    co = list(collections.Counter(O).most_common(2))
    ce = list(collections.Counter(E).most_common(2))
    o1 = co[0][0]
    e1 = ce[0][0]

    O_ = list(filter(lambda o: o != o1, O))
    E_ = list(filter(lambda e: e != e1, E))
    num_o_1 = len(O_) 
    num_e_1 = len(E_)
    if e1 != o1:
        num = num_o_1 + num_e_1
    else:
        if len(co) == 1 and len(ce) == 1:
            num = half_length
        elif len(co) == 1:
            e2 = ce[1][0]
            num_e_2 = len(filter(lambda e: e != e2, E))
            num = num_o_1 + num_e_2
        elif len(ce) == 1:
            o2 = co[1][0]
            num_o_2 = len(filter(lambda o: o != o2, O))
            num = num_o_2 + num_e_1
        else:
            e2 = ce[1][0]
            o2 = co[1][0]
            o1e2 = num_o_1 + num_e_2
            o2e1 = num_o_2 + num_e_1
            num = o1e2 if o1e2 < o2e1 else o2e1
    print(num)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    n = int(next(tokens))  # type: int
    v = [ int(next(tokens)) for _ in range(n) ]  # type: "List[int]"
    solve(n, v)

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
import sys
import statistics
import collections

def solve(n: int, v: "List[int]"):
    half_length = len(v) // 2
    O = [v[2*i] for i in range(half_length)]
    E = [v[2*i+1] for i in range(half_length)]

    co = list(collections.Counter(O))
    ce = list(collections.Counter(E))
    o1 = co[0]
    e1 = ce[0]

    O_ = list(filter(lambda o: o != o1, O))
    E_ = list(filter(lambda e: e != e1, E))
    num_o_1 = len(O_) 
    num_e_1 = len(E_)
    if e1 != o1:
        num = num_o_1 + num_e_1
    else:
        if len(co) == 1 and len(ce) == 1:
            num = half_length
        elif len(co) == 1:
            e2 = ce[1]
            num_e_2 = len(filter(lambda e: e != e2, E))
            num = num_o_1 + num_e_2
        elif len(ce) == 1:
            o2 = co[1]
            num_o_2 = len(filter(lambda o: o != o2, O))
            num = num_o_2 + num_e_1
        else:
            e2 = ce[1]
            o2 = co[1]
            o1e2 = num_o_1 + num_e_2
            o2e1 = num_o_2 + num_e_1
            num = o1e2 if o1e2 < o2e1 else o2e1
    print(num)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    n = int(next(tokens))  # type: int
    v = [ int(next(tokens)) for _ in range(n) ]  # type: "List[int]"
    solve(n, v)

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import collections

n = int(input())
v = list(map(int,input().split()))
even = collections.Counter(v[0::2])
odd = collections.Counter(v[1::2])

if even.most_common()[0][0] != odd.most_common()[0][0]:
    ans1 = len(v)/2 - even.most_common()[0][1]
    ans2 = len(v)/2 - odd.most_common()[0][1]
elif even.most_common()[1][0] != odd.most_common()[0][0]:
    ans1 = len(v)/2 - even.most_common()[1][1]
    ans2 = len(v)/2 - odd.most_common()[0][1]
elif even.most_common()[0][0] != odd.most_common()[1][0]:
    ans1 = len(v)/2 - even.most_common()[0][1]
    ans2 = len(v)/2 - odd.most_common()[1][1]
    
if v[0::2] == v[1::2]:
    print(len(v[0::2]),end='')
else:
    print(int(ans1 + ans2),end='')

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
import sys
import statistics
import collections

def solve(n: int, v: "List[int]"):
    half_length = int(len(v)/2)
    O = [v[2*i] for i in range(half_length)]
    E = [v[2*i+1] for i in range(half_length)]

    co = list(collections.Counter(O))
    ce = list(collections.Counter(E))
    o1 = co[0]
    e1 = ce[0]

    O_ = list(filter(lambda o: o != o1, O))
    E_ = list(filter(lambda e: e != e1, E))
    num_o_1 = len(O_) 
    num_e_1 = len(E_)
    if e1 != o1:
        num = num_o_1 + num_e_1
    else:
        if num_o_1 <= 0:
            num_o_2 = len(O)
        else:
            o2 = co[1]
            num_o_2 = len(filter(lambda o: o != o2, O))
        if num_e_1 <= 0:
            num_e_2 = len(E)
        else:
            e2 = ce[1]
            num_e_2 = len(filter(lambda e: e != e2, E))
        if num_e_2 > num_o_2:
            num = num_o_2 + num_e_1
        else:
            num = num_o_1 + num_e_2
    print(num)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    n = int(next(tokens))  # type: int
    v = [ int(next(tokens)) for _ in range(n) ]  # type: "List[int]"
    solve(n, v)

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import collections

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

nod = collections.Counter(l[0::2])
even = collections.Counter(l[1::2])


if nod.most_common[0][0] == even.most_common[0][0]:
    if nod.most_common[0][1] > even.most_common[0][1]:
        ans = len(l)- nod.most_common()[0][1] - even.most_common()[1][1]
    else:
        ans = len(l)- nod.most_common()[1][1] - even.most_common()[0][1]
else:
    ans = len(l)- nod.most_common()[0][1] - even.most_common()[0][1]

print(ans)

Submission status: Runtime Error

Solution code:
import collections as col
from functools import reduce
from operator import add
n = int(input())

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

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

odd = v[1::2]
even = v[0::2]

co = col.Counter(odd).most_common()
coli = list(co.values())
ce = col.Counter(even).most_common()
celi = list(ce.values())

cov = list(co.keys())
cev = list(ce.keys())

if cov[0] != cev[0]:
    a = reduce(add, coli[1:], 0)
    b = reduce(add, celi[1:], 0)
    print(n - coli[0] - coli[0])
else:
    # a1 = reduce(add, coli[1:], 0)
    # b1 = reduce(add, celi[2:], 0)
    # b1 = celi[0] + b1

    # a2 = reduce(add, coli[2:], 0)
    # b2 = reduce(add, celi[1:], 0)
    # a2 = a2 + coli[0]
    if len(coli) <= 1:
        coli.append(0)
    if len(celi) <= 1:
        celi.append(0)

    ans1 = n - coli[1] - celi[0]
    ans2 = n - coli[0] - celi[1]

    print(min(ans1, ans2))

Submission status: Runtime Error

Solution code:
import collections as col
from functools import reduce
from operator import add
n = int(input())

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

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

odd = v[1::2]
even = v[0::2]

co = col.Counter(odd)
coli = list(co.values())
ce = col.Counter(even)
celi = list(ce.values())

cov = list(co.keys())
cev = list(ce.keys())

if cov[0] != cev[0]:
    a = reduce(add, coli[1:], 0)
    b = reduce(add, celi[1:], 0)
    print(a + b)
else:
    # a1 = reduce(add, coli[1:], 0)
    # b1 = reduce(add, celi[2:], 0)
    # b1 = celi[0] + b1

    # a2 = reduce(add, coli[2:], 0)
    # b2 = reduce(add, celi[1:], 0)
    # a2 = a2 + coli[0]
    ans1 = n - coli[1] - celi[0]
    ans2 = n - coli[0] - celi[1]

    print(min(ans1, ans2))

Submission status: Runtime Error

Solution code:
from collections import defaultdict

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

if len(set(v)) == 1:
    count = n//2
else:
    odd = defaultdict(lambda: 0)
    even = defaultdict(lambda: 0)
    for i in v[0::2]:
        odd[i] += 1
    for i in v[1::2]:
        even[i] += 1
    o1, o2, *_ = sorted(odd.items(), key=lambda x: x[1], reverse=True)
    e1, e2, *_ = sorted(even.items(), key=lambda x: x[1], reverse=True)
    if o1[0] != e1[0]:
        count = n - o1[1] - e1[1]
    elif o1[1] >= e1[1]:
        count = n - o1[1] - e2[1]
    elif o1[1] < e1[1]:
        count = n - o2[1] - e1[1]

print(count)

Submission status: Runtime Error

Solution code:
n = int(input())
ans = []
L = list(map(int,input().split()))
if len(list(filter(lambda x:x==L[0] ,L))) == len(L):
    print(n//2)
    quit()


import collections as col
L1 = L[::2]
L2 = L[1::2]
c1 = list(col.Counter(L1).items())
c2 = list(col.Counter(L2).items())

for i in range(2):
    for j in range(2):
        tmp1 = c1[i][0]
        tmp2 = c2[j][0]
        if tmp1 == tmp2 :
            continue
        a1 = n//2 - c1[i][1]
        a2 = n//2 - c1[j][1]
        ans.append(a1+a2)
print(min(ans))

Submission status: Runtime Error

Solution code:
n = int(input())
v = list(map(int,input().split()))
l1 = []
l2 = []
for i,v_ in enumerate(v):
    if i%2==0:
        l1.append(v_)
    else:
        l2.append(v_)

from collections import Counter
if set(l1)==set(l2):
    print(n//2)
else:
    c1 = Counter(l1).most_common(2)
    c2 = Counter(l2).most_common(2)
    if c1[0][0]==c2[0][0]:
        print(n-max(v[0][1]+v[1][1], v[1][1]+v[0][1]))
    else:
        print(n-v[0][1]-v[0][1])

Submission status: Runtime Error

Solution code:
from collections import Counter
# counter（l）.most_common()：リストについて出現回の多い順に（要素、要素数）で返す
a=int(input())
A=list(map(int,input().split()))
bx=[A[i] for i in range(a) if i%2==0]
cx=[A[i] for i in range(a) if i%2==1]
#　全部同じ数の時
if b==c and len(set(b))==1 and len(set(c))==1:
    print(a//2)
else:
    bc=Counter(b).most_common()
    cc=Counter(c).most_common()
    if bc[0][0]==cc[0][0]:
        print(a-max(bc[1][1]+cc[0][1],bc[0][1]+cc[1][1]))
    else: print(a-bc[0][1]-cc[0][1])

Submission status: Runtime Error

Solution code:
import collections

n=int(input())


X=list(map(int,input().split()))
odd=[]
even=[]
for i in range(int(n/2)):
    odd.append(X[2*i+1])
    even.append(X[2*i])

odd_counter=collections.Counter(odd) #登場回数とその値の辞書型
even_counter=collections.Counter(even)

odd_count=sorted(odd_counter.values(),reverse=True) #登場回数の多い順に並べた配列
even_count=sorted(even_counter.values(),reverse=True)

max_odd_value=max(odd_counter,key=odd_counter.get) #登場回数が最大の値
max_even_value=max(even_counter,key=even_counter.get)

if max_odd_value!=max_even_value:
    print(n-odd_count[0]-even_count[0])

else:
    print(min(n-odd_count[0]-even_count[1],n-odd_count[1]-even_count[0]))

Submission status: Runtime Error

Solution code:
import collections
l=list(map(int,input().split()))
c1=collections.Counter(l[0::2])
c2=collections.Counter(l[1::2])
m1=c1.most_common()[0]
m2=c2.most_common()[0]
if m1[0] !=m2[0]:
  print(len(l)-m1[1]-m2[1])
else:
  print(len(l)-m1[1])

Submission status: Runtime Error

Solution code:
import collections
l=list(map(int,input().split()))
c1=collections.Counter(l[0::2])
c2=collections.Counter(l[1::2])
print(len(l)-c1.most_common()[0][1]\
            -c2.most_common()[0][1])

Submission status: Runtime Error

Solution code:
### from collections import Counter

n = int(input())
vn = list(map(int,input().split()))
vn_odd = [vn[i] for i in range(n) if i%2==1]
vn_even = [vn[i] for i in range(n) if i%2==0]
odd_freq = Counter(vn_odd).most_common(2)
even_freq = Counter(vn_even).most_common(2)

ans = 0

if odd_freq[0][0] != even_freq[0][0]:
    ans += n - odd_freq[0][1] - even_freq[0][1]
else:
    ans += n - max(odd_freq[0][1]+even_freq[1][1], odd_freq[1][1]+even_freq[0][1])
            
print(ans)

Submission status: Runtime Error

Solution code:
from collections import Counter

n = int(input())
vn = list(map(int,input().split()))
vn_odd = [vn[i] for i in range(n) if i%2==1]
vn_even = [vn[i] for i in range(n) if i%2==0]
odd_freq = Counter(vn_odd).most_common(2)
even_freq = Counter(vn_even).most_common(2)

ans = 0

if odd_freq[0][0] != even_freq[0][0]:
    ans += n - odd_freq[0][1] - even_freq[0][1]
else:
    if odd_freq[0][1] > even_freq[0][1]:
        ans += n - odd_freq[0][1] - even_freq[1][1]
    elif odd_freq[0][1] < even_freq[0][1]:
        ans += n - odd_freq[1][1] - even_freq[0][1]
    else:
        if odd_freq[1][1] >= even_freq[1][1]:
            ans += n - odd_freq[1][1] - even_freq[0][1]
        else:
            ans += n - odd_freq[0][1] - even_freq[1][1]

            
print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np
N=int(input())
s=np.array(list(map(int,input().split())))

d_even=np.zeros(10)
d_odd=np.zeros(10)

for i in range(N//2):
    d_even[s[2*i]]+=1
    d_odd[s[2*i+1]]+=1
    
se=np.argsort(d_even)[::-1]
so=np.argsort(d_odd)[::-1]

e1=se[0]
e2=se[1]
o1=so[0]
o2=so[1]

if e1!=o1:
    ans=N-d_even[e1]-d_odd[o1]
else:
    ans=min(N-d_even[e1]-d_odd[o2],N-d_even[e2]-d_odd[o1])     
        
print(int(ans))

Submission status: Runtime Error

Solution code:
from collections import Counter
n = int(input())
vl = [int(i) for i in input().split()]
oc = Counter(a for i, a in enumerate(vl) if i % 2 == 0)
ec = Counter(a for i, a in enumerate(vl) if i % 2 == 1)
ol = sorted(((v, k) for k, v in oc.items()), reverse=True)
el = sorted(((v, k) for k, v in ec.items()), reverse=True)

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

Submission status: Runtime Error

Solution code:
n = int(input())
vl = [int(i) for i in input().split()]
oc = Counter(a for i, a in enumerate(vl) if i % 2 == 0)
ec = Counter(a for i, a in enumerate(vl) if i % 2 == 1)
ol = sorted(((v, k) for k, v in oc.items()), reverse=True)
el = sorted(((v, k) for k, v in ec.items()), reverse=True)

if ol[0][1] != el[0][1]:
    print(n - ol[0][0] - el[0][0])
else:
    if ol[0][0] >= el[0][0]:
        if len(el) >= 2:
            print(n - ol[0][0] - el[1][0])
        else:
            print(n - ol[0][0])
    else:
        if len(ol) >= 2:
            print(n - ol[1][0] - el[0][0])
        else:
            print(n - el[0][0])

Submission status: Runtime Error

Solution code:
import collections
n = int(input())
v = list(map(int, input().split()))
ve = v[0::2]
vo = v[1::2]
# print(ve,vo)

ce=collections.Counter(vo).most_common(2)
co=collections.Counter(ve).most_common(2)

if(ce[0][0] != co[0][0]):
    ans = len(v) - ce[0][1] - co[0][1]
elif(len(ce)==1 and len(co)==1):
    ans = len(v) // 2
elif(len(ce)==1):
    ans = len(v) // 2 - co[1][1]
elif(len(co)==1):
    ans = len(v) // 2 - ce[1][1]
print(ans)

Submission status: Runtime Error

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

from statistics import mode
if len(set(v))  == 1:
    print(int(len(v) / 2))
else:
    print(len(v[0::2]) - collections.Counter(v[0::2]).most_common()[0][1] + len(v[1::2]) - collections.Counter(v[1::2]).most_common()[0][1])

Submission status: Runtime Error

Solution code:
a=[0]*100001
b=[0]*100001

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

for i in range(0,n,2):
  a[v[i]]+=1
for i in range(1,n,2):
  b[v[i]]+=1

if a.index(max(a))==b.index(max(b)):
  a= sorted(a[v[i]])
  b= sorted(b[v[i]])
  print(min(n-a[2]+b[1],n-a[1]-b[2]))
elif max(a)+max(b)==n and v[1]==v[0]:
  print(n//2)
else:
  print(n-max(a)-max(b))

Submission status: Runtime Error

Solution code:
a=[0]*100000
b=[0]*100000

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

for i in range(0,n,2):
  a[v[i]]+=1


for i in range(1,n,2):
  b[v[i]]+=1

if max(a)+max(b)==n and v[1]==v[0]:
  print(n//2)
else:
  print(n-max(a)-max(b))

Submission status: Runtime Error

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


def m():
    first = V[0::2]
    second = V[1::2]
    fdic = {}
    sdic = {}
    for i in range(N//2):
        if fdic.get(first[i], 0) == 0:
            fdic[first[i]] = 1
        else:
            fdic[first[i]] +=1

        if sdic.get(second[i], 0) == 0:
            sdic[second[i]] = 1
        else:
            sdic[second[i]] +=1
    flist = list(fdic.items())
    slist = list(sdic.items())

    flist.sort(reverse=True, key=lambda x:x[1])
    slist.sort(reverse=True, key=lambda x:x[1])

    if flist[0][0] != slist[0][0] and len(flist) == 1 and len(slist) == 1:
        return 0

    if flist[0][0] != slist[0][0]:
        ans = 0
        for k, v in flist[1:]:
            ans += v
        for k, v in slist[1:]:
            ans += v
        return ans

    if flist[0][1] > slist[0][1]:
        ans = 0
        for k, v in flist[1:]:
            ans += v
        for k, v in slist[2]:
            ans += v
        ans += slist[0][0]
        return ans
    else:
        ans = 0
        for k, v in slist[1:]:
            ans += v
        for k, v in flist[2]:
            ans += v
        ans += flist[0][0]
        return ans

print(m())

Submission status: Runtime Error

Solution code:
def main():
    n = int(input())
    v = list(map(int, input().split()))
    e = [0 for _ in range(10 ** 5)]
    o = [0 for _ in range(10 ** 5)]
    for i in range(0, n, 2):
        e[v[i]] += 1
        o[v[i + 1]] += 1
    ans = 0
    if n == max(e) + max(o):
        ans = n // 2
    else:
        if n // 2 > max(e):
            ans += n // 2 - max(e)
        if n // 2 > max(o):
            ans += n // 2 - max(o)
    print(ans)


main()

Submission status: Runtime Error

Solution code:
def main(n:int,lst:list)->int:
    lst1 = lst[::2]
    lst2 = lst[1::2]
    ans1 =count2(lst1)
    ans2 =count2(lst2)
    if ans1[0][0] == ans2[0][0]:
        if ans1[1] and ans2[1]:
            return n - max(ans1[0][1] + ans2[1],ans2[0][1] + ans1[1])
        else:
            return n//2
    else:
        return n - ans1[0][1] - ans2[0][1]
def count2(lst):
    lst.sort()
    ans = [["",0],0]
    last =lst[0]
    a = 0
    for e in lst:
        if last == e:
            a +=1
        else:
            ans = check(a,ans)
            last = e
            a = 1
    return check(a,ans)
def check(a,ans):
    if a > ans[0][1]:
        ans[1] = ans[0][1]
        ans[0][0] = e
        ans[0][1] = a
    elif a > ans[1]:
        ans[1] = a
    return ans
n = int(input())
lst = input().split()
print(main(n,lst))

Submission status: Runtime Error

Solution code:
from collections import Counter
def main(n:int,lst:list)->int:
    lst1 = lst[::2]
    lst2 = lst[1::2]
    c1 = Counter(lst1).most_common()
    c2 = Counter(lst2).most_common()
    if c1[0][0] == c2[0][0]:
        if len(c1)!=1 and len(c2)!=1:
            return n - max(c1[0][1] + c2[1],c2[0][1] + c1[1])
        else:
            return n//2
    else:
        return n - c1[0][1] - c2[0][1]

n = int(input())
lst = input().split()
print(main(n,lst))

Submission status: Runtime Error

Solution code:
from collections import Counter
def main(n:int,lst:list)->int:
    lst1 = lst[::2]
    lst2 = lst[1::2]
    c1 = Counter(lst1).most_common(2)
    c2 = Counter(lst2).most_common(2)
    if c1[0][0] == c2[0][0]:
        if len(c1)!=1 and len(c2)!=1:
            return n - max(c1[0][1] + c2[1],c2[0][1] + c1[1])
        else:
            return n//2
    else:
        return n - c1[0][1] - c2[0][1]

n = int(input())
lst = input().split()
print(main(n,lst))

Submission status: Runtime Error

Solution code:
from collections import Counter
def main(n:int,lst:list)->int:
    lst1 = [::2]
    lst2 = [1::2]
    c1 = Counter(lst1).most_common(2)
    c2 = Counter(lst2).most_common(2)
    if c1[0][0] == c2[0][0]:
        if len(c1)!=1 and len(c2)!=1:
            return n - max(c1[0][1] + c2[1],c2[0][1] + c1[1])
        else:
            return n//2
    else:
        return n - c1[0][1] - c2[0][1]

n = int(input())
lst = input().split()
print(main(n,lst))

Submission status: Runtime Error

Solution code:
def main(n:int,lst:list)->int:
    b = True
    lst1 = []
    lst2 = []
    for e in lst:
        if b:
            lst1.append(e)
        else:
            lst2.append(e)
        b = not b
    lst1.sort()
    lst2.sort()
    c1 = [["",0],0]
    c2 = [["",0],0]
    last =lst1[0]
    a = 0
    for e in lst1:
        if last == e:
            a +=1
        else:
            if a >= c1[0][1]:
                c1[1] = c1[0][1]
                c1[0][0] = e
                c1[0][1] = a
            elif a > c1[1]:
                c1[1] = a
            last = e
            a = 1
    if a >= c1[0][1]:
        c1[1] = c1[0][1]
        c1[0][0] = e
        c1[0][1] = a
    elif a > c1[1]:
        c1[1] = a

    last =lst2[0]
    a = 0
    for e in lst2:
        if last == e:
            a +=1
        else:
            if a >= c2[0][1]:
                c2[1] = c2[0][1]
                c2[0][0] = e
                c2[0][1] = a
            elif a > c2[1]:
                c2[1] = a
            last = e
            a = 1
    if a >= c2[0][1]:
        c2[1] = c2[0][1]
        c2[0][0] = e
        c2[0][1] = a
    elif a > c2[1]:
        c2[1] = a

    if c1[0][0] == c2[0][0]:
        if c1[0][1] > c2[0][1] or(c1[0][1] == c2[0][1] and c2[1] > c1[1]):
            return n - c1[0][1] - c2[1]
        else:
            return n - c2[0][1] - c1[1]
    else:
        return n - c1[0][1] - c2[0][1]

n = int(input())
lst = input().split())
print(main(n,lst))

Submission status: Runtime Error

Solution code:
def main(n:int,lst:list)->int:
    b = True
    lst1 = []
    lst2 = []
    for e in lst:
        if b:
            lst1.append(e)
        else:
            lst2.append(e)
        b = not b
    lst1.sort()
    lst2.sort()
    c1 = [["",0],0]
    c2 = [["",0],0]
    last =lst1[0]
    a = 0
    for e in lst1:
        if last == e:
            a +=1
        else:
            if a > c1[0][1]:
                c1[1] = c1[0][1]
                c1[0][0] = e
                c1[0][1] = a
            elif a > c1[1]:
                c1[1] = a
            last = e
            a = 1
    if a > c1[0][1]:
        c1[0][0] = e
        c1[0][1] = a
    elif a > c1[1][1]:
        c1[1][0] = e
        c1[1][1] = a

    last =lst2[0]
    a = 0
    for e in lst2:
        if last == e:
            a +=1
        else:
            if a > c2[0][1]:
                c2[1] = c2[0][1]
                c2[0][0] = e
                c2[0][1] = a
            elif a > c2[1]:
                c2[1] = a
            last = e
            a = 1
    if a > c2[0][1]:
        c2[1] = c2[0][1]
        c2[0][0] = e
        c2[0][1] = a
    elif a > c2[1]:
        c2[1] = a

    if c1[0][0] == c2[0][0]:
        if c1[0][1] > c2[0][1] or(c1[0][1] == c2[0][1] and c2[1][1] > c1[1][1]):
            return n - c1[0][1] - c2[1][1]
        else:
            return n - c2[0][1] - c1[1][1]
    else:
        return n - c1[0][1] - c2[0][1]

n = int(input())
lst = list(map(int,input().split()))
print(main(n,lst))

Submission status: Runtime Error

Solution code:
import sys
import statistics

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

if len(set(vs)) == 1:
    print(len(vs)//2)
    sys.exit()

evens = []
odds = []

for i in range(2, len(vs)):
    if i%2 == 0:
        evens.append(vs[i])
    else:
        odds.append(vs[i])

even_mode = statistics.mode(evens)
odd_mode = statistics.mode(odds)
count = 0

for i in range(len(vs)):
    if i%2 == 0 and vs[i] != even_mode:
        count += 1
    if i%2 == 1 and vs[i] != odd_mode:
        count += 1
print(count)

Submission status: Runtime Error

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

e = a[0::2]
o = a[1::2]
e = collections.Counter(e)
o = collections.Counter(o)

def E(i,j):
    return e.most_common()[i][j]
def O(i,j):
    return o.most_common()[i][j]


if E(0,0) != O(0,0):
    print(n-E(0,1) - O(0,1))
elif E(0,1) > O(0,1):
    if len(set(a[1::2])) == O(0,1):
        print(n-E(0,1))
    else:
        print(n-E(0,1)-O(1,1))
else:
    if len(set(a[0::2])) == E(0,1):
        print(n-O(0,1))
    else:
        print(n-O(0,1)-E(1,1))

Submission status: Runtime Error

Solution code:
N = int(input())
V = list(map(int,input().split()))
nums = [v for v in V if V.count(x) != int(N/2)]
print(int(len(nums)/2))

Submission status: Runtime Error

Solution code:
import collections
n = int(input())
v = [int(i) for i in input().split()]

dummy = (-1, -1)
(av1, ak1), (av2, ak2) = (collections.Counter(v[::2]).most_common(2) + dummy)[:2]
(bv1, bk1), (bv2, bk2) = (collections.Counter(v[1::2]).most_common(2) + dummy)[:2]

if av1 != bv1:
    print(n-ak1-bk1)
elif ak1 < bk1:
    print(n-ak2-bk1)
else:
    print(n-ak1-bk2)