Problem:


Score : 300 points

Problem Statement

A sequence a_1,a_2,... ,a_n is said to be /\/\/\/ when the following conditions are satisfied:

For each i = 1,2,..., n-2, a_i = a_{i+2}.

Exactly two different numbers appear in the sequence.

You are given a sequence v_1,v_2,...,v_n whose length is even.
We would like to make this sequence /\/\/\/ by replacing some of its elements.
Find the minimum number of elements that needs to be replaced.

Constraints

2 \leq n \leq 10^5

n is even.

1 \leq v_i \leq 10^5

v_i is an integer.

Input

Input is given from Standard Input in the following format:

n
v_1 v_2 ... v_n

Output

Print the minimum number of elements that needs to be replaced.

Sample Input 1

4
3 1 3 2

Sample Output 1

1

The sequence 3,1,3,2 is not /\/\/\/, but we can make it /\/\/\/ by replacing one of its elements: for example, replace the fourth element to make it 3,1,3,1.

Sample Input 2

6
105 119 105 119 105 119

Sample Output 2

0

The sequence 105,119,105,119,105,119 is /\/\/\/.

Sample Input 3

4
1 1 1 1

Sample Output 3

2

The elements of the sequence 1,1,1,1 are all the same, so it is not /\/\/\/.



Sample input:
4
3 1 3 2


Sample output:
1

Submission status: Wrong Answer

Solution code:
#encoding utf-8

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

even_v = []
odd_v = []

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

odd_dic = {}
even_dic = {}
for i in range(len(odd_v)):
    if odd_v[i] in odd_dic.keys():
        odd_dic[odd_v[i]] += 1
    else:
        odd_dic[odd_v[i]] = 1

for i in range(len(even_v)):
    if even_v[i] in even_dic.keys():
        even_dic[even_v[i]] += 1
    else:
        even_dic[even_v[i]] = 1


for k, v in sorted(even_dic.items(), key=lambda x: -x[1]):pass
for k, v in sorted(odd_dic.items(), key=lambda x: -x[1]):pass

# odd_dic = sorted(odd_dic.items(),key=lambda x:x[1])
# even_dic = sorted(even_dic.items(),key=lambda x:x[1])

odd_keys = list(odd_dic.keys())
even_keys = list(even_dic.keys())

for i in range(len(odd_keys)-1):
    if odd_dic[odd_keys[i]] == odd_dic[odd_keys[i+1]]:
        if odd_keys[i] > odd_keys[i+1]:
            tem = odd_keys[i]
            odd_keys[i] = odd_keys[i+1]
            odd_keys[i+1] = tem

for i in range(len(even_keys)-1):
    if even_dic[even_keys[i]] == even_dic[even_keys[i+1]]:
        if even_keys[i] > even_keys[i+1]:
            tem = even_keys[i]
            even_keys[i] = even_keys[i+1]
            even_keys[i+1] = tem


if odd_keys[0] != even_keys[0]:
    answer = n-int(odd_dic[odd_keys[0]])-int(even_dic[even_keys[0]])
else:
    if len(odd_keys) == 1 and len(even_keys) == 1:
        answer = len(odd_v)
    else:
        ans1 = n-int(odd_dic[odd_keys[0]])-int(even_dic[even_keys[1]])
        ans2 = n-int(odd_dic[odd_keys[1]])-int(even_dic[even_keys[0]])
        answer = min(ans1, ans2)
print(int(answer))

Submission status: Wrong Answer

Solution code:
#encoding utf-8

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

even_v = []
odd_v = []

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

odd_dic = {}
even_dic = {}
for i in range(len(odd_v)):
    if odd_v[i] in odd_dic.keys():
        odd_dic[odd_v[i]] += 1
    else:
        odd_dic[odd_v[i]] = 1

for i in range(len(even_v)):
    if even_v[i] in even_dic.keys():
        even_dic[even_v[i]] += 1
    else:
        even_dic[even_v[i]] = 1


for k, v in sorted(even_dic.items(), key=lambda x: -x[1]):pass
for k, v in sorted(odd_dic.items(), key=lambda x: -x[1]):pass

# odd_dic = sorted(odd_dic.items(),key=lambda x:x[1])
# even_dic = sorted(even_dic.items(),key=lambda x:x[1])

odd_keys = list(odd_dic.keys())
even_keys = list(even_dic.keys())

if odd_keys[0] != even_keys[0]:
    answer = n-int(odd_dic[odd_keys[0]])-int(even_dic[even_keys[0]])
else:
    if len(odd_keys) == 1 and len(even_keys) == 1:
        answer = len(odd_v)
    else:
        ans1 = n-int(odd_dic[odd_keys[0]])-int(even_dic[even_keys[1]])
        ans2 = n-int(odd_dic[odd_keys[1]])-int(even_dic[even_keys[0]])
        answer = min(ans1, ans2)
print(int(answer))

Submission status: Wrong Answer

Solution code:
#encoding utf-8

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

even_v = []
odd_v = []

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

odd_dic = {}
even_dic = {}
for i in range(len(odd_v)):
    if odd_v[i] in odd_dic.keys():
        odd_dic[odd_v[i]] += 1
    else:
        odd_dic[odd_v[i]] = 1

for i in range(len(even_v)):
    if even_v[i] in even_dic.keys():
        even_dic[even_v[i]] += 1
    else:
        even_dic[even_v[i]] = 1


for k, v in sorted(even_dic.items(), key=lambda x: -x[1]):pass
for k, v in sorted(odd_dic.items(), key=lambda x: -x[1]):pass

# odd_dic = sorted(odd_dic.items(),key=lambda x:x[1])
# even_dic = sorted(even_dic.items(),key=lambda x:x[1])

odd_keys = list(odd_dic.keys())
even_keys = list(even_dic.keys())

if odd_keys[0] != even_keys[0]:
    answer = n-int(odd_dic[odd_keys[0]])-int(even_dic[even_keys[0]])
else:
    if len(odd_keys) == 1 and len(even_keys) == 1:
        answer = len(odd_v)
    else:
        answer = min(int(odd_dic[odd_keys[1]])-int(even_dic[even_keys[0]]), int(odd_dic[odd_keys[0]])-int(even_dic[even_keys[1]]))

print(int(answer))


































# #encoding utf-8
#
# n = int(input())
# v = list(int(i) for i in input().split())
#
#
# v_odd = []
# v_even = []
# for i in range(n):
#     if i%2 == 0:
#         v_odd.append(v[i])
#     else:
#         v_even.append(v[i])
#
# #odd part
# count={}
# for i in range(len(v_odd)):
#     if v_odd[i] in count.keys():
#         count[v_odd[i]] += 1
#     else:
#         count[v_odd[i]] = 1
#
# for k, v in sorted(count.items(), key=lambda x: -x[1]):
#     pass
# keys = list(count.keys())
#
# #even part
# even_count={}
# for i in range(len(v_even)):
#     if v_even[i] in even_count.keys():
#         even_count[v_even[i]] += 1
#     else:
#         even_count[v_even[i]] = 1
#
# # print(even_count)
# for k, v in sorted(even_count.items(), key=lambda x: -x[1]):
#     pass
# even_keys = list(even_count.keys())
#
# if even_keys[0] == keys[0]:
#     if len(keys) == 1 and len(even_keys) == 1:
#         answer = int(n/2)
#     elif len(keys) == 1:
#         answer = int(n/2)-int(even_count[even_keys[1]])
#     elif len(even_keys) == 1:
#         answer = int(n/2)-int(count[keys[1]])
#     else:
#         if int(even_count[even_keys[0]]) > int(count[keys[0]]):
#             answer = n-int(count[keys[1]])-int(even_count[even_keys[0]])
#         elif int(even_count[even_keys[0]]) < int(count[keys[0]]):
#             answer = n-int(count[keys[0]])-int(even_count[even_keys[1]])
#         elif int(even_count[even_keys[0]]) == int(count[keys[0]]):
#             if int(even_count[even_keys[1]]) > int(count[keys[1]]):
#                 answer = n-int(even_count[even_keys[1]])-int(count[keys[0]])
#             elif int(even_count[even_keys[1]]) < int(count[keys[1]]):
#                 answer = n-int(even_count[even_keys[0]])-int(count[keys[1]])
#             else:
#                 answer = n-int(even_count[even_keys[1]])-int(count[keys[0]])
# else:
#     answer = n-int(count[keys[0]])-int(even_count[even_keys[0]])
# print(int(answer))

Submission status: Wrong Answer

Solution code:
import collections

n = input()
line = input().split()
odd = line[::2]
even = line[1::2]
o = collections.Counter(odd)
e = collections.Counter(even)
maxoddcnt = o.most_common()[0][1]
maxevencnt = e.most_common()[0][1]

#すべての値が同じときは半分を置換する
if odd == even:
    print(len(odd))
    exit(0)

#奇数列，偶数列それぞれの最頻の文字が同じ場合は，いずれかを2番目に多い文字に置換しなければならない
if o.most_common()[0][0] == e.most_common()[0][0]:
    if len(o.most_common()) > 1 and len(e.most_common()) <= 1:
        maxoddcnt = o.most_common()[1][1]
    if len(o.most_common()) <= 1 and len(e.most_common()) > 1:
        maxevencnt = e.most_common()[1][1]
    if o.most_common()[1][1] + e.most_common()[0][1] >= o.most_common()[0][1] + e.most_common()[1][1]:
        maxoddcnt = o.most_common()[1][1]
    else: #if o.most_common()[1][1] + e.most_common()[0][1] <= o.most_common()[0][1] + e.most_common()[1][1] :
        maxevencnt = e.most_common()[1][1]

print(len(odd)-maxoddcnt+len(even)-maxevencnt)

Submission status: Wrong Answer

Solution code:
import collections

n = input()
line = input().split()
odd = line[::2]
even = line[1::2]
o = collections.Counter(odd)
e = collections.Counter(even)
maxoddcnt = o.most_common()[0][1]
maxevencnt = e.most_common()[0][1]

#すべての値が同じときは半分を置換する
if odd == even:
    print(len(odd))
    exit(0)

#奇数列，偶数列それぞれの最頻の文字が同じ場合は，いずれかを2番目に多い文字に置換しなければならない
if o.most_common()[0][0] == e.most_common()[0][0]:
    if o.most_common()[1][1] + e.most_common()[0][1] >= o.most_common()[0][1] + e.most_common()[1][1]:
        maxoddcnt = o.most_common()[1][1]
    else: #if o.most_common()[1][1] + e.most_common()[0][1] <= o.most_common()[0][1] + e.most_common()[1][1] :
        maxevencnt = e.most_common()[1][1]

print(len(odd)-maxoddcnt+len(even)-maxevencnt)

Submission status: Wrong Answer

Solution code:
import collections

n = input()
line = input().split()
odd = line[::2]
even = line[1::2]
o = collections.Counter(odd)
e = collections.Counter(even)
maxoddcnt = o.most_common()[0][1]
maxevencnt = e.most_common()[0][1]

#すべての値が同じときは半分を置換する
if odd == even:
    print(len(odd))
    exit(0)

#奇数列，偶数列それぞれの最頻の文字が同じ場合は，いずれかを2番目に多い文字に置換しなければならない
if o.most_common()[0][0] == e.most_common()[0][0]:
    if o.most_common()[1][1] + e.most_common()[0][1] > o.most_common()[0][1] + e.most_common()[1][1]:
        maxoddcnt = o.most_common()[1][1]
    else: #if o.most_common()[1][1] + e.most_common()[0][1] <= o.most_common()[0][1] + e.most_common()[1][1] :
        maxevencnt = e.most_common()[1][1]

print(len(odd)-maxoddcnt+len(even)-maxevencnt)

Submission status: Wrong Answer

Solution code:
import collections

n = input()
line = input().split()
odd = line[::2]
even = line[1::2]
o = collections.Counter(odd)
e = collections.Counter(even)
maxoddcnt = o.most_common()[0][1]
maxevencnt = e.most_common()[0][1]

#すべての値が同じときは半分を置換する
if odd == even:
    print(len(odd))
    exit(0)

#奇数列，偶数列それぞれの最頻の文字が同じ場合は，いずれかを2番目に多い文字に置換しなければならない
if o.most_common()[0][0] == e.most_common()[0][0]:
    if o.most_common()[1][1] + e.most_common()[0][1] > o.most_common()[0][1] + e.most_common()[1][1]:
        maxoddcnt = o.most_common()[1][1]
    elif o.most_common()[1][1] + e.most_common()[0][1] <= o.most_common()[0][1] + e.most_common()[1][1] :
        maxevencnt = e.most_common()[1][1]

print(len(odd)-maxoddcnt+len(even)-maxevencnt)

Submission status: Wrong Answer

Solution code:
import collections

n = input()
line = input().split()
odd = line[::2]
even = line[1::2]
o = collections.Counter(odd)
e = collections.Counter(even)
maxoddcnt = o.most_common()[0][1]
maxevencnt = e.most_common()[0][1]

#すべての値が同じときは半分を置換する
if odd == even:
    print(len(odd))
    exit(0)

#奇数列，偶数列それぞれの最頻の文字が同じ場合は，いずれかを2番目に多い文字に置換しなければならない
if o.most_common()[0][0] == e.most_common()[0][0]:
    if o.most_common()[1][1] + e.most_common()[0][1] > o.most_common()[0][1] + e.most_common()[1][1]:
        maxevencnt = e.most_common()[1][1]
    elif o.most_common()[1][1] + e.most_common()[0][1] <= o.most_common()[0][1] + e.most_common()[1][1] :
        maxoddcnt = o.most_common()[1][1]

print(len(odd)-maxoddcnt+len(even)-maxevencnt)

Submission status: Wrong Answer

Solution code:
n = int(input())
v = list(map(int, input().split()))
checklist = [0 for i in range(max(v))]
cnt = 0
for i in range(0, n, 2):
    checklist[v[i] - 1] += 1
    cnt += 1
ans = cnt - (max(checklist))
cnt2 = 0
checklist2 = [0 for i in range(max(v))]
for i in range(1, n, 2):
    checklist2[v[i] - 1] += 1
    cnt2 += 1

if checklist.index(max(checklist)) == checklist2.index(max(checklist2)):
    if max(checklist) >= max(checklist2):
        checklist2[checklist2.index(max(checklist2))] = 0
    else:
        checklist[checklist.index(max(checklist))] = 0

        
ans = cnt - max(checklist)
ans += cnt2 - (max(checklist2))

print(ans)

Submission status: Wrong Answer

Solution code:
#encoding utf-8

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


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

#odd part
count={}
for i in range(len(v_odd)):
    if v_odd[i] in count.keys():
        count[v_odd[i]] += 1
    else:
        count[v_odd[i]] = 1

for k, v in sorted(count.items(), key=lambda x: -x[1]):
    pass
keys = list(count.keys())

#even part
even_count={}
for i in range(len(v_even)):
    if v_even[i] in even_count.keys():
        even_count[v_even[i]] += 1
    else:
        even_count[v_even[i]] = 1

# print(even_count)
for k, v in sorted(even_count.items(), key=lambda x: -x[1]):
    pass
even_keys = list(even_count.keys())

if even_keys[0] == keys[0]:
    if len(keys) == 1 and len(even_keys) == 1:
        answer = int(n/2)
    elif len(keys) == 1:
        answer = int(n/2)-int(even_count[even_keys[1]])
    elif len(even_keys) == 1:
        answer = int(n/2)-int(count[keys[1]])
    else:
        if int(even_count[even_keys[0]]) > int(count[keys[0]]):
            answer = n-int(count[keys[1]])-int(even_count[even_keys[0]])
        elif int(even_count[even_keys[0]]) < int(count[keys[0]]):
            answer = n-int(count[keys[0]])-int(even_count[even_keys[1]])
        elif int(even_count[even_keys[0]]) == int(count[keys[0]]):
            if int(even_count[even_keys[1]]) > int(count[keys[1]]):
                answer = n-int(even_count[even_keys[1]])-int(count[keys[0]])
            elif int(even_count[even_keys[1]]) < int(count[keys[1]]):
                answer = n-int(even_count[even_keys[0]])-int(count[keys[1]])
            else:
                answer = n-int(even_count[even_keys[1]])-int(count[keys[0]])
else:
    answer = n-int(count[keys[0]])-int(even_count[even_keys[0]])
print(int(answer))

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

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

ki = Counter(ki)
gu = Counter(gu)

ki = ki.most_common()
gu = gu.most_common()

ans = 0

if ki[0][0] == gu[0][0]:
    if len(ki) == 1 and len(gu) == 1:
        ans = int(n / 2)
    elif len(ki) == 1:
        ans = n - ki[0][1] - gu[1][1]
    elif len(gu) == 1:
        ans = n - ki[1][1] - gu[0][1]
    else:
        if ki[0][1] > gu[0][1]:
            ans = n - ki[0][1]
        else:
            ans = n - gu[0][1]
else:
    ans = n - ki[0][1] - gu[0][1]

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

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

ki = Counter(ki)
gu = Counter(gu)

ki = ki.most_common()
gu = gu.most_common()

ans = 0

if ki[0][0] == gu[0][0]:
    if len(ki) == 1 and len(gu) == 1:
        ans = int(n / 2)
    else:
        if ki[0][1] > gu[0][1]:
            ans = n - ki[0][1]
        else:
            ans = n - gu[0][1]
else:
    ans = n - ki[0][1] - gu[0][1]

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
v = list(map(int,input().split()))
result = 0
li = list()
for i in range(n-2):
    if not v[i] in li:
        li.append(v[i])
    if v[i] != v[i+2]:
        v[i+2] = v[i]
        result += 1
if len(li) < 2 and result == 0:
    result = 2
print(result)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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


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

ki = Counter(ki)
gu = Counter(gu)

ki = ki.most_common()
gu = gu.most_common()


ans = 0

if ki[0][0] == gu[0][0]:
    if len(ki) == 1 and len(gu) == 1:
        ans = int(n / 2)

    else:
        if ki[0][1] > gu[0][1]:
            ans = n - ki[0][1]
        else:
            ans = n - gu[0][1]
else:
    ans = n - ki[0][1] - gu[0][1]

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
v = list(map(int,input().split()))
result = 0
li = list()
for i in range(n-2):
    if not v[i] in li:
        li.append(v[i])
    if v[i] != v[i+2]:
        v[i+2] = v[i]
        result += 1
if len(li) < 2:
    result = 2
print(result)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

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

ki = Counter(ki)
gu = Counter(gu)

ki = ki.most_common()
gu = gu.most_common()

print(ki)
print(gu)

ans = 0

if ki[0][0] == gu[0][0]:
    if len(ki) == 1 and len(gu) == 1:
        ans = int(n / 2)
    else:
        if ki[1][1] > gu[1][1]:
            ans = n - ki[1][1] - gu[0][1]
        else:
            ans = n - ki[0][1] - gu[1][1]
else:
    ans = n - ki[0][1] - gu[0][1]

print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from collections import defaultdict


def solve():
    n = int(input())
    v = [int(i) for i in input().split()]
    d1 = defaultdict(int)
    d2 = defaultdict(int)
    for i in range(n):
        if i % 2 == 0:
            d1[v[i]] += 1
        else:
            d2[v[i]] += 1
    rd1 = defaultdict(list)
    rd2 = defaultdict(list)
    for k, v in d1.items():
        rd1[v].append(k)
    for k, v in d2.items():
        rd2[v].append(k)
    a1 = [i for i in sorted(rd1.keys(), reverse=True)]
    a2 = [i for i in sorted(rd2.keys(), reverse=True)]
    ans = n
    la1 = len(a1) - 1
    la2 = len(a2) - 1
    for h in range(3):
        for i in range(3):
            aa1 = rd1[a1[min(h, la1)]]
            aa2 = rd2[a2[min(i, la2)]]
            s1 = set(aa1)
            s2 = set(aa2)
            if len(s1) > 1 or len(s2) > 1:
                ans = min(
                    ans, (n // 2) - a1[min(h, la1)] + (n // 2) - a2[min(i, la2)])
            else:
                ans = min(ans, (n // 2) - a1[min(h, la1)] + (n // 2) - a2[min(i, la2)]
                          + min(a1[min(h, la1)], a2[min(i, la2)]))
    print(ans)


if __name__ == "__main__":
    solve()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from collections import defaultdict


def solve():
    n = int(input())
    v = [int(i) for i in input().split()]
    d1 = defaultdict(int)
    d2 = defaultdict(int)
    for i in range(n):
        if i % 2 == 0:
            d1[v[i]] += 1
        else:
            d2[v[i]] += 1
    rd1 = defaultdict(list)
    rd2 = defaultdict(list)
    for k, v in d1.items():
        rd1[v].append(k)
    for k, v in d2.items():
        rd2[v].append(k)
    a1 = [i for i in sorted(rd1.keys(), reverse=True)]
    a2 = [i for i in sorted(rd2.keys(), reverse=True)]
    ans = n
    la1 = len(a1) - 1
    la2 = len(a2) - 1
    for h in range(5):
        for i in range(5):
            aa1 = rd1[a1[min(h, la1)]]
            aa2 = rd2[a2[min(i, la2)]]
            s1 = set(aa1)
            s2 = set(aa2)
            if (s1 - s2) or (s2 - s1):
                ans = min(
                    ans, (n // 2) - a1[min(h, la1)] + (n // 2) - a2[min(i, la2)])
            else:
                ans = min(ans, (n // 2) - a1[min(h, la1)] + (n // 2) - a2[min(i, la2)]
                          + min(a1[min(h, la1)], a2[min(i, la2)]))
    print(ans)


if __name__ == "__main__":
    solve()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from collections import defaultdict


def solve():
    n = int(input())
    v = [int(i) for i in input().split()]
    d1 = defaultdict(int)
    d2 = defaultdict(int)
    for i in range(n):
        if i % 2 == 0:
            d1[v[i]] += 1
        else:
            d2[v[i]] += 1
    rd1 = defaultdict(list)
    rd2 = defaultdict(list)
    for k, v in d1.items():
        rd1[v].append(k)
    for k, v in d2.items():
        rd2[v].append(k)
    a1 = [i for i in sorted(rd1.keys(), reverse=True)]
    a2 = [i for i in sorted(rd2.keys(), reverse=True)]
    ans = n
    la1 = len(a1) - 1
    la2 = len(a2) - 1
    for h in range(3):
        for i in range(3):
            aa1 = rd1[a1[min(h, la1)]]
            aa2 = rd2[a2[min(i, la2)]]
            s1 = set(aa1)
            s2 = set(aa2)
            if (s1 - s2) or (s2 - s1):
                ans = min(
                    ans, (n // 2) - a1[min(h, la1)] + (n // 2) - a2[min(i, la2)])
            else:
                ans = min(ans, (n // 2) - a1[min(h, la1)] + (n // 2) - a2[min(i, la2)]
                          + min(a1[min(h, la1)], a2[min(i, la2)]))
    print(ans)


if __name__ == "__main__":
    solve()

Submission status: Wrong Answer

Solution code:
import math
import collections

n = int(input())
nums = list(map(int, input().split()))
ans1 = 0
ans2 = 0

even_list = []
odd_list = []
# 偶数・奇数のリストを作る
for i in range(0, len(nums)):
    if i % 2 == 0:
        even_list.append(nums[i])
    else:
        odd_list.append(nums[i])

# 偶数最頻値を取得
even_mod = collections.Counter(even_list).most_common()
# 奇数最頻値を取得
odd_mod = collections.Counter(odd_list).most_common()
if even_mod == odd_mod:
    print(n // 2)
elif even_mod[0][0] != odd_mod[0][0]:
    for i in range(0, len(nums)):
        if i % 2 == 0:
            if nums[i] != even_mod[0][0]:
                ans1 += 1
        else:
            if nums[i] != odd_mod[0][0]:
                ans1 += 1
    print(ans1)
else:
    for i in range(0, len(nums)):
        if i % 2 == 0:
            if nums[i] != even_mod[0][0]:
                ans1 += 1
        else:
            if nums[i] != odd_mod[1][1]:
                ans1 += 1

    for i in range(0, len(nums)):
        if i % 2 == 0:
            if nums[i] != even_mod[1][1]:
                ans2 += 1
        else:
            if nums[i] != odd_mod[0][0]:
                ans2 += 1
    if ans1 < ans2:
        print(ans1)
    else:
        print(ans2)

Submission status: Wrong Answer

Solution code:
import statistics
import math
import collections

n = int(input())
nums = list(map(int, input().split()))
ans1 = 0
ans2 = 0

even_list = []
odd_list = []
# 偶数・奇数のリストを作る
for i in range(0, len(nums)):
    if i % 2 == 0:
        even_list.append(nums[i])
    else:
        odd_list.append(nums[i])

# 偶数最頻値を取得
even_mod = collections.Counter(even_list).most_common()
# 奇数最頻値を取得
odd_mod = collections.Counter(odd_list).most_common()
if even_mod == odd_mod:
    print(n // 2)
elif even_mod[0][0] != odd_mod[0][0]:
    for i in range(0, len(nums)):
        if i % 2 == 0:
            if nums[i] != even_mod[0][0]:
                ans1 += 1
        else:
            if nums[i] != odd_mod[0][0]:
                ans1 += 1
    print(ans1)
else:
    for i in range(0, len(nums)):
        if i % 2 == 0:
            if nums[i] != even_mod[0][0]:
                ans1 += 1
        else:
            if nums[i] != odd_mod[1][1]:
                ans1 += 1

    for i in range(0, len(nums)):
        if i % 2 == 0:
            if nums[i] != even_mod[1][1]:
                ans2 += 1
        else:
            if nums[i] != odd_mod[0][0]:
                ans2 += 1
    if ans1 < ans2:
        print(ans1)
    else:
        print(ans2)

Submission status: Wrong Answer

Solution code:
import numpy as np

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

# import ipdb; ipdb.set_trace()

if np.unique(v).size == 1:
    print(int(n/2))
else:
    # 偶数要素と奇数要素に分ける
    vo = v[::2]
    ve = v[1::2]
    # それぞれについて最大数の要素を見つける
    vof = np.bincount(vo).argmax()
    vef = np.bincount(ve).argmax()

    if vof == vef:
        vef2 = np.bincount(ve[ve!=vef]).argmax()
        vof2 = np.bincount(vo[vo!=vef]).argmax()
        if (sum(vo == vof)+sum(vo==vof2)) > (sum(ve == vef)+sum(ve==vef2)):
            vef = np.bincount(ve[ve!=vef]).argmax()
        elif (sum(vo == vof)+sum(vo==vof2)) < (sum(ve == vef)+sum(ve==vef2)):
            vof = np.bincount(vo[vo!=vof]).argmax()
        else :
            vof = np.bincount(vo[vo!=vof]).argmax()
    
    # それぞれについて最大数の数では無い要素数を数える
    vonf = sum(vo != vof)
    venf = sum(ve != vef)
    # 足しあげる
    print(vonf+venf)

Submission status: Wrong Answer

Solution code:
import numpy as np

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

# import ipdb; ipdb.set_trace()

if np.unique(v).size == 1:
    print(int(n/2))
else:
    # 偶数要素と奇数要素に分ける
    vo = v[::2]
    ve = v[1::2]
    # それぞれについて最大数の要素を見つける
    vof = np.bincount(vo).argmax()
    vef = np.bincount(ve).argmax()

    if vof == vef:
        if sum(vo == vof) > sum(ve == vef):
            vef = np.bincount(ve[ve!=vef]).argmax()
        elif sum(ve == vef) > sum(vo == vof):
            vof = np.bincount(vo[vo!=vof]).argmax()
        else :
            vof = np.bincount(vo[vo!=vof]).argmax()
    
    # それぞれについて最大数の数では無い要素数を数える
    vonf = sum(vo != vof)
    venf = sum(ve != vef)
    # 足しあげる
    print(vonf+venf)

Submission status: Wrong Answer

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

from collections import Counter

def prg_divide(s):
    arr = []
    for i in range(s,N,2):
        arr.append(prg[i])
        
    counter = Counter(arr)
    counter = sorted(counter.items(),key=lambda x: x[1],reverse=True)
    
    if len(counter) > 1:
        c1 = counter[0]
        c2 = counter[1]
    else:
        c1 = c2 = counter[0]
        
    return arr, c1, c2


prg_A, A1, A2 = prg_divide(0)
prg_B, B1, B2 = prg_divide(1)

if prg_A == prg_B:
    result = N // 2
elif A1[0] != B1[0]:
    result = ( len(prg_A) - A1[1] ) + ( len(prg_B) - B1[1] )
else:
    pattern = []
    
    if A2[0] != B1[0]:
        pattern.append(( len(prg_A) - A2[1] ) + ( len(prg_B) - B1[1] ))
    if A1[0] != B2[0]:
        pattern.append(( len(prg_A) - A1[1] ) + ( len(prg_B) - B2[1] ))
        
    pattern = sorted(pattern)
    result = pattern[0]
    
print(result)

Submission status: Wrong Answer

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

from collections import Counter

def prg_divide(s):
    arr = []
    for i in range(s,N,2):
        arr.append(prg[i])
        
    counter = Counter(arr)
    counter = sorted(counter.items(),key=lambda x: x[1],reverse=True)
    
    if len(counter) > 1:
        c1 = counter[0]
        c2 = counter[1]
    else:
        c1 = c2 = counter[0]
    
    return arr, c1, c2


prg_A, A1, A2 = prg_divide(0)
prg_B, B1, B2 = prg_divide(1)

if prg_A == prg_B:
    result = N // 2
elif A1[0] != B1[0]:
    result = ( len(prg_A) - A1[1] ) + ( len(prg_B) - B1[1] )
else:
    pattern = []
    pattern.append(( len(prg_A) - A2[1] ) + ( len(prg_B) - B1[1] ))
    pattern.append(( len(prg_A) - A1[1] ) + ( len(prg_B) - B2[1] ))
    pattern = sorted(pattern)
    result = pattern[0]
    
print(result)

Submission status: Wrong Answer

Solution code:

def answer(in0, in1):
    even = {}
    odd = {}

    list = in1.split(" ")

    for i in range(len(list)):
        n = list[i]
        if i % 2 == 0:
            odd[n] = odd.get(n, 0) + 1
        else:
            even[n] = even.get(n, 0) + 1

    oddMaxKey = getMaxKey(odd)
    evenMaxKey = getMaxKey(even)

    if len(even) == 1 and len(odd) == 1 and oddMaxKey == evenMaxKey:
        return int(int(in0) / 2)
    else:
        oddCount = 0
        evenCount = 0

        for k in odd:
            if k  != oddMaxKey:
                oddCount += odd[k]

        for k in even:
            if k  != evenMaxKey:
                evenCount += even[k]

        return oddCount + evenCount

def getMaxKey(dicts):
    maxValue= 0
    maxKey = ''

    for k in dicts:
        if maxValue < dicts[k]:
            maxValue = dicts[k]
            maxKey = k

    return maxKey

print(answer(input(), input()))

Submission status: Wrong Answer

Solution code:
from sys import stdin

n = int(stdin.readline().rstrip())
v = [int(i) for i in stdin.readline().rstrip().split()]

e = [0] * (10**5 + 10)
o = [0] * (10**5 + 10)

# 各要素の個数をカウント
for i in range(len(v)):
    if i % 2 == 0:
        e[v[i]] += 1
    else:
        o[v[i]] += 1

# 最頻値のその次に多い数字の個数、その数字を求める
e_max, e_max2, o_max, o_max2 = 0, 0, 0, 0
e_max_num, e_max2_num, o_max_num, o_max2_num = 0, 0, 0, 0

for i in range(len(e)):
    if e[i] > e_max:
        e_max2 = e_max
        e_max = e[i]
        e_max2_num = e_max_num
        e_max_num = i
    elif e[i] > e_max2_num:
        e_max2 = e[i]
        e_max2_num = i

    if o[i] > o_max:
        o_max2 = o_max
        o_max = o[i]
        o_max2_num = o_max_num
        o_max_num = i
    elif o[i] > o_max2:
        o_max2 = o[i]
        o_max2_num = i

if e_max_num == o_max_num:
    if n > 2:
        print(n - max(e_max + o_max2, o_max + e_max2))
    else:
        print(n - e_max)

else:
    print(n - (e_max + o_max))

Submission status: Wrong Answer

Solution code:
from sys import stdin

n = int(stdin.readline().rstrip())
v = [int(i) for i in stdin.readline().rstrip().split()]

e = [0] * (10**5 + 10)
o = [0] * (10**5 + 10)

# 各要素の個数をカウント
for i in range(len(v)):
    if i % 2 == 0:
        e[v[i]] += 1
    else:
        o[v[i]] += 1

# 最頻値のその次に多い数字の個数、その数字を求める
e_max, e_max2, o_max, o_max2 = 0, 0, 0, 0
e_max_num, e_max2_num, o_max_num, o_max2_num = 0, 0, 0, 0

for i in range(len(e)):
    if e[i] > e_max:
        e_max2 = e_max
        e_max = e[i]
        e_max2_num = e_max_num
        e_max_num = i
    elif e[i] > e_max2_num:
        e_max2 = e[i]
        e_max2_num = i

    if o[i] >= o_max:
        o_max2 = o_max
        o_max = o[i]
        o_max2_num = o_max_num
        o_max_num = i
    elif o[i] > o_max2:
        o_max2 = o[i]
        o_max2_num = i

if e_max_num != o_max_num:
    print(n - (e_max + o_max))
else:
    print(n - max(e_max + o_max2, o_max + e_max2))

Submission status: Wrong Answer

Solution code:
from sys import stdin

n = int(stdin.readline().rstrip())
v = [int(i) for i in stdin.readline().rstrip().split()]

e = [0] * (10**5 + 10)
o = [0] * (10**5 + 10)

# 各要素の個数をカウント
for i in range(len(v)):
    if i % 2 == 0:
        e[v[i]] += 1
    else:
        o[v[i]] += 1

# 最頻値のその次に多い数字の個数、その数字を求める
e_max, e_max2, o_max, o_max2 = 0, 0, 0, 0
e_max_num, e_max2_num, o_max_num, o_max2_num = 0, 0, 0, 0

for i in range(len(e)):
    if e[i] > e_max:
        e_max2 = e_max
        e_max = e[i]
        e_max2_num = e_max_num
        e_max_num = i
    elif e[i] > e_max2_num:
        e_max2 = e[i]
        e_max2_num = i

    if o[i] > o_max:
        o_max2 = o_max
        o_max = o[i]
        o_max2_num = o_max_num
        o_max_num = i
    elif o[i] > o_max2:
        o_max2 = o[i]
        o_max2_num = i

if e_max_num != o_max_num:
    print(n - (e_max + o_max))
else:
    print(n - max(e_max + o_max2, o_max + e_max2))

Submission status: Wrong Answer

Solution code:
from sys import stdin

n = int(stdin.readline().rstrip())
v = [int(i) for i in stdin.readline().rstrip().split()]

e = [0] * (10**5 + 10)
o = [0] * (10**5 + 10)

# 各要素の個数をカウント
for i in range(len(v)):
    if i % 2 == 0:
        e[v[i]] += 1
    else:
        o[v[i]] += 1

# 最頻値のその次に多い数字の個数、その数字を求める
e_max, e_max2, o_max, o_max2 = 0, 0, 0, 0
e_max_num, e_max2_num, o_max_num, o_max2_num = 0, 0, 0, 0

for i in range(len(e)):
    if e[i] > e_max:
        e_max2 = e_max
        e_max = e[i]
        e_max2_num = e_max_num
        e_max_num = i

    if o[i] > o_max:
        o_max2 = o_max
        o_max = o[i]
        o_max2_num = o_max_num
        o_max_num = i

if e_max_num != o_max_num:
    print(n - (e_max + o_max))
else:
    print(n - max(e_max + o_max2, o_max + e_max2))

Submission status: Wrong Answer

Solution code:
n=int(input())
v=list(map(int,input().split()))
even=v[0::2]
odd=v[1::2]
import collections
c=collections.Counter(even)
d=collections.Counter(odd)
e=c.most_common()[0][0]
o=d.most_common()[0][0]
e2=c.most_common()[0][1]
o2=d.most_common()[0][1]
if e==o:
    if even.count(e)>odd.count(o):
        o=o2
    else:
        e=e2
count=len(v)-(even.count(e)+odd.count(o))
print(count)