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:
# -*- coding: utf-8 -*-
from collections import Counter
n = int(input())
v = [int(i) for i in input().split()] 

a1 = [0 for _ in range(n // 2)]
a2 = [0 for _ in range(n // 2)]
for i in range(n):
    if i % 2 == 0:
        a1[i // 2] = v[i]
    elif i % 2 == 1:
        a2[i // 2] = v[i]
#print(a1)
#print(a2)
tmp_a1 = Counter(a1)
tmp_a2 = Counter(a2)
#print(tmp_a1.most_common()[0][1] , tmp_a2.most_common()[0][1])
#if a1 == a2:
#    ans = n // 2
if tmp_a1.most_common()[0][0] == tmp_a2.most_common()[0][0]:
    ans = min(tmp_a1.most_common()[0][1], tmp_a2.most_common()[0][1]) + n // 2 - max(tmp_a1.most_common()[0][1], tmp_a2.most_common()[0][1])
else:
    ans = n - (tmp_a1.most_common()[0][1] + tmp_a2.most_common()[0][1])
print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
from collections import Counter
n = int(input())
v = [int(i) for i in input().split()] 

a1 = [0 for _ in range(n // 2)]
a2 = [0 for _ in range(n // 2)]
for i in range(n):
    if i % 2 == 0:
        a1[i // 2] = v[i]
    elif i % 2 == 1:
        a2[i // 2] = v[i]
#print(a1)
#print(a2)
tmp_a1 = Counter(a1)
tmp_a2 = Counter(a2)
#print(tmp_a1.most_common()[0][1] , tmp_a2.most_common()[0][1])
if a1 == a2:
    ans = n // 2
elif tmp_a1.most_common()[0][0] == tmp_a2.most_common()[0][0]:
    ans = min(tmp_a1.most_common()[0][1], tmp_a2.most_common()[0][1]) + n // 2 - max(tmp_a1.most_common()[0][1], tmp_a2.most_common()[0][1])
else:
    ans = n - (tmp_a1.most_common()[0][1] + tmp_a2.most_common()[0][1])
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
v = list(map(int,input().split()))
v1 = v[0::2]
v2 = v[1::2]
v1.sort()
v2.sort()
v1_hind = dict()
v2_hind = dict()
v1_hind[v1[0]] = 1
v2_hind[v2[0]] = 1
for i in range(1, len(v1)):
    if v1[i] != v1[i-1]:
        v1_hind[v1[i]] = 0
    if v2[i] != v2[i-1]:
        v2_hind[v2[i]] = 0
    v1_hind[v1[i]] += 1
    v2_hind[v2[i]] += 1
v1_it = list(v1_hind.items())
v2_it = list(v2_hind.items())
v1_it.sort(key=lambda x: x[1], reverse=True)
v2_it.sort(key=lambda x: x[1], reverse=True)
if v1_it[0][0] != v2_it[0][0]:
    print(len(v1)-v1_it[0][1] + len(v2)-v2_it[0][1])
elif v1_it[0][0] == v2_it[0][0] and len(v2_it) == 1:
    print(len(v2))
else:
    print(len(v1) - v1_it[0][1] + len(v2) - v2_it[1][1])

Submission status: Wrong Answer

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

du = {}
dl = {}
for i in range(n):
    if i%2 == 0:
        if V[i] not in du:
            du[V[i]] = 1
        else:
            du[V[i]] += 1
    else:
        if V[i] not in dl:
            dl[V[i]] = 1
        else:
            dl[V[i]] += 1

l = list(dl.values())
u = list(du.values())
if len(u) == 1 and len(l) == 1 and len(set(V)) != 1:
    print(0)
    exit()
elif len(u) == 1 and len(l) == 1 and len(set(V)) == 1:
    print(n//2)
    exit()
else:
    pass

if max(du, key=du.get) != max(dl, key=dl.get):
    ans = n//2-max(du.values())+n//2-max(dl.values())
else:
    if max(u) > max(l):
        l.sort(reverse=True)
        ans = n//2-max(u) +n//2-l[1]
    elif max(u) < max(l):
        u.sort(reverse=True)
        ans = n//2-max(l)+n//2-u[1]
    else:
        ans = min(n//2-max(l)+n//2-u[1], n//2-max(u)+n//2-l[1])
print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
from collections import Counter
n = int(input())
v = [int(i) for i in input().split()] 

a1 = [0 for _ in range(n // 2)]
a2 = [0 for _ in range(n // 2)]
for i in range(n):
    if i % 2 == 0:
        a1[i // 2] = v[i]
    elif i % 2 == 1:
        a2[i // 2] = v[i]
#print(a1)
#print(a2)
tmp_a1 = Counter(a1)
tmp_a2 = Counter(a2)
#print(tmp_a1.most_common()[0][1] , tmp_a2.most_common()[0][1])
if a1 == a2:
    ans = n // 2
elif tmp_a1.most_common()[0][0] == tmp_a2.most_common()[0][0]:
    ans = min(tmp_a1.most_common()[0][1], tmp_a2.most_common()[0][1]) + n - max(tmp_a1.most_common()[0][1], tmp_a2.most_common()[0][1])
else:
    ans = n - (tmp_a1.most_common()[0][1] + tmp_a2.most_common()[0][1])
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
*v, = map(int, input().split())

odds = [v[i] for i in range(n) if i % 2 == 0]
evens = [v[i] for i in range(n) if i % 2]

o = Counter(odds)
e = Counter(evens)

omx, *ol = sorted(o.items(), reverse=True, key=lambda x: x[1])
emx, *el = sorted(e.items(), reverse=True, key=lambda x: x[1])

ans = 0
if omx[0] != emx[0]:
    ans += n - omx[1] - emx[1]
else:
    r = [ol, el][omx[1] > emx[1]]
    if r:
        ans += n//2 - r[0][1]
    else:
        ans += n//2


print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
from collections import Counter
n = int(input())
v = [int(i) for i in input().split()] 

a1 = [0 for _ in range(n // 2)]
a2 = [0 for _ in range(n // 2)]
for i in range(n):
    if i % 2 == 0:
        a1[i // 2] = v[i]
    elif i % 2 == 1:
        a2[i // 2] = v[i]
#print(a1)
#print(a2)
tmp_a1 = Counter(a1)
tmp_a2 = Counter(a2)
#print(tmp_a1.most_common()[0][1] , tmp_a2.most_common()[0][1])
if a1 == a2:
    ans = n // 2
else:
    ans = n - (tmp_a1.most_common()[0][1] + tmp_a2.most_common()[0][1])
print(ans)

Submission status: Wrong Answer

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

du = {}
dl = {}
for i in range(n):
    if i%2 == 0:
        if V[i] not in du:
            du[V[i]] = 1
        else:
            du[V[i]] += 1
    else:
        if V[i] not in dl:
            dl[V[i]] = 1
        else:
            dl[V[i]] += 1

l = list(dl.values())
u = list(du.values())
if len(u) == 1 and len(l) == 1 and len(set(V)) != 1:
    print(0)
    exit()
elif len(u) == 1 and len(l) == 1 and len(set(V)) == 1:
    print(n//2)
    exit()
else:
    pass

if max(du, key=du.get) != max(dl, key=dl.get):
    ans = n//2-max(du.values())+n//2-max(dl.values())
else:
    if max(du.values()) > max(dl.values()):
        l = list(dl.values())
        l.sort(reverse=True)
        ans = n//2-max(du.values())+n//2-l[1]
    elif max(du.values()) < max(dl.values()):
        u = list(du.values())
        u.sort(reverse=True)
        ans = n//2-max(dl.values())+n//2-u[1]
    else:
        l = list(dl.values())
        u = list(du.values())
        ans = min(n//2-max(l)+n//2-u[1], n//2-max(u)+n//2-l[1])
print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    A = [int(i) for i in input().split()]
    odd = A[::2]
    even = A[1::2]
    from collections import Counter
    c_odd = Counter(odd)
    c_even = Counter(even)
    ans = 0
    if c_odd.most_common()[0][0] != c_even.most_common()[0][0]:
        ans = N - c_odd.most_common()[0][1] - c_even.most_common()[0][1]
    else:
        if c_odd.most_common()[0][1] > c_even.most_common()[0][1]:
            ans = N - c_odd.most_common()[0][1] - c_even.most_common()[1][1]
        elif c_odd.most_common()[0][1] < c_even.most_common()[0][1]:
            ans = N - c_odd.most_common()[1][1] - c_even.most_common()[0][1]
        else:
            odd_first = c_odd.most_common()[0][1]
            odd_second = c_odd.most_common()[1][1] if odd_first != N//2 else 0
            even_first = c_even.most_common()[0][1]
            even_second = c_even.most_common(
            )[1][1] if even_first != N//2 else 0
            if even_second > odd_second:
                ans = even_second + odd_first
            else:
                ans = even_first + odd_second
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys

def solve():
    input = sys.stdin.readline
    N = int(input())
    H = N // 2
    V = [int(v) for v in input().split()]
    odd, even = dict(), dict()
    for i, v in enumerate(V):
        if i % 2 == 0:
            if v in even: even[v] += 1
            else: even[v] = 1
        else:
            if v in odd: odd[v] += 1
            else: odd[v] = 1

    evenL = [(0, 0), (0, 0)]
    evenMax = set()
    for key in even:
        if even[key] >= evenL[0][0]: evenL = [(even[key], key), evenL[0]]
        elif even[key] >= evenL[1][0]: evenL[1] = (even[key], key)
    for key in even:
        if even[key] == evenL[0][0]: evenMax |= {key}
    oddL = [(0, 0), (0, 0)]
    oddMax = set()
    for key in odd:
        if odd[key] >= oddL[0][0]: oddL = [(odd[key], key), oddL[0]]
        elif odd[key] >= oddL[1][0]: oddL[1] = (odd[key], key)
    for key in odd:
        if odd[key] == oddL[0][0]: oddMax |= {key}

    if evenL[0][1] == oddL[0][1] and len(evenMax) == len(oddMax) == 1:
        if evenL[0][0] > oddL[0][0]: print(N - evenL[0][0] - oddL[1][0])
        else: print(N - evenL[1][0] - oddL[0][0])
    else: print(N - evenL[0][0] - oddL[0][0])

    return 0

if __name__ == "__main__":
    solve()

Submission status: Wrong Answer

Solution code:
import sys

def solve():
    input = sys.stdin.readline
    N = int(input())
    H = N // 2
    V = [int(v) for v in input().split()]
    odd, even = dict(), dict()
    for i, v in enumerate(V):
        if i % 2 == 0:
            if v in even: even[v] += 1
            else: even[v] = 1
        else:
            if v in odd: odd[v] += 1
            else: odd[v] = 1

    evenL = [(0, 0), (0, 0)]
    for key in even:
        if even[key] >= evenL[0][0]: evenL = [(even[key], key), evenL[0]]
        elif even[key] >= evenL[1][0]: evenL[1] = (even[key], key)
    oddL = [(0, 0), (0, 0)]
    for key in odd:
        if odd[key] >= oddL[0][0]: oddL = [(odd[key], key), oddL[0]]
        elif odd[key] >= oddL[1][0]: oddL[1] = (odd[key], key)

    if evenL[0][1] == oddL[0][1]:
        if evenL[0][0] > oddL[0][0]: print(N - evenL[0][0] - oddL[1][0])
        else: print(N - evenL[1][0] - oddL[0][0])
    else: print(N - evenL[0][0] - oddL[0][0])

    return 0

if __name__ == "__main__":
    solve()

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
*v, = map(int, input().split())

odds = [v[i] for i in range(n) if i % 2 == 0]
evens = [v[i] for i in range(n) if i % 2]

# print(odds, evens)

o = Counter(odds)
e = Counter(evens)

ans = 0

omx, *r = sorted(o.items(), reverse=True, key=lambda x: x[1])
ans += n//2 - omx[1]
emx, *r = sorted(e.items(), reverse=True, key=lambda x: x[1])
if omx[0] != emx[0]:
    ans += n//2 - emx[1]
else:
    if r:
        ans += n//2 - r[0][1]
    else:
        ans += n//2


print(ans)

Submission status: Wrong Answer

Solution code:
import sys

def solve():
    input = sys.stdin.readline
    N = int(input())
    H = N // 2
    V = [int(v) for v in input().split()]
    odd, even = dict(), dict()
    for i, v in enumerate(V):
        if i % 2 == 0:
            if v in even: even[v] += 1
            else: even[v] = 1
        else:
            if v in odd: odd[v] += 1
            else: odd[v] = 1

    evenL = [(0, 0), (0, 0)]
    for key in even:
        if even[key] > evenL[0][0]: evenL = [(even[key], key), evenL[0]]
        elif even[key] > evenL[1][0]: evenL[1] = (even[key], key)
    oddL = [(0, 0), (0, 0)]
    for key in odd:
        if odd[key] > oddL[0][0]: oddL = [(odd[key], key), oddL[0]]
        elif odd[key] > oddL[1][0]: oddL[1] = (odd[key], key)

    if evenL[0][1] == oddL[0][1]:
        if evenL[0][0] > oddL[0][0]: print(N - evenL[0][0] - oddL[1][0])
        else: print(N - evenL[1][0] - oddL[0][0])
    else: print(N - evenL[0][0] - oddL[0][0])

    return 0

if __name__ == "__main__":
    solve()

Submission status: Wrong Answer

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

from collections import Counter
a1 = Counter(v[i] for i in range(0,n,2)).most_common(2)
a2 = Counter(v[i] for i in range(1,n,2)).most_common(2)

n1 = a1[0][1]
n2 = a2[0][1]

if a1[0][0] == a2[0][0]:
    if a1[0][1] > a2[0][1]:
        if len(a2) > 1: n2 = a2[1][1]
        else: n2 = 0
    else:
        if len(a1) > 1: n1 = a1[1][1]
        else: n1 = 0

print(n-n1-n2)

Submission status: Wrong Answer

Solution code:
import collections

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

# 偶数列と奇数列に分ける
even_num = items[::2]
odd_num = items[1::2]

# それらの配列で一番数が多いものを判定、それに合わせる
even_dic = collections.Counter(even_num)
odd_dic = collections.Counter(odd_num)

max_even = max(even_dic, key=even_dic.get)
max_odd = max(odd_dic, key=odd_dic.get)

# もし二つの数が一緒であれば別の数字にする
# if max_even == max_odd:
#   if even_dic[max_even] >= odd_dic[max_odd]:
#     odd_dic.pop(max_odd)
#     if len(odd_dic) > 0:
#       max_odd = max(odd_dic, key=odd_dic.get)
#     else:
#       max_odd = -1
    
#   else:
#     even_dic.pop(max_even)
#     if len(even_dic) > 0:
#       max_even = max(even_dic, key=even_dic.get)
#     else:
#       max_even = -1

# 配列を文字数でカウントした辞書を作成して、設定した数以外である項目を変更すると考える
odd_ans = odd_dic[max_odd] if max_odd != -1 else 0
even_ans = even_dic[max_even] if max_even != -1 else 0 

ans = N - odd_ans - even_ans
print(ans)

Submission status: Wrong Answer

Solution code:
import collections

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

# 偶数列と奇数列に分ける
even_num = items[::2]
odd_num = items[1::2]

# それらの配列で一番数が多いものを判定、それに合わせる
even_dic = collections.Counter(even_num)
odd_dic = collections.Counter(odd_num)

max_even = max(even_dic, key=even_dic.get)
max_odd = max(odd_dic, key=odd_dic.get)

# もし二つの数が一緒であれば別の数字にする
if max_even == max_odd:
  if even_dic[max_even] >= odd_dic[max_odd]:
    # oddを変える
    # 基本は次に数が多い数字
    # ない場合はどうしようか、−１に設定しよう
    odd_dic.pop(max_odd)
    if len(odd_dic) > 0:
      max_odd = max(odd_dic, key=odd_dic.get)
    else:
      max_odd = -1
    
  else:
    # evenを変える
    even_dic.pop(max_even)
    if len(even_dic) > 0:
      max_even = max(even_dic, key=even_dic.get)
    else:
      max_even = -1

# 配列を文字数でカウントした辞書を作成して、設定した数以外である項目を変更すると考える
odd_ans = odd_dic[max_odd] if max_odd != -1 else 0
even_ans = even_dic[max_even] if max_even != -1 else 0 

ans = N - odd_ans - even_ans
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

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

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

    print(kw1)
    print(kw2)

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

    if x1 == x2:
        if kw1.most_common()[1][1] > kw2.most_common()[1][1]:
            x1 = kw1.most_common()[1][0]
        else:
            x2 = kw2.most_common()[1][0]

    ans = 0

    for i in v1:
        if i != x1:
            ans += 1

    for i in v2:
        if i != x2:
            ans += 1

    print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

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

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

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

    if x1 == x2:
        if kw1.most_common()[0][1] > kw2.most_common()[0][1]:
            x1 = kw1.most_common()[1][0]
        else:
            x2 = kw2.most_common()[1][0]

    ans = 0

    for i in v1:
        if i != x1:
            ans += 1

    for i in v2:
        if i != x2:
            ans += 1

    print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

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

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

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

    if x1 == x2:
        if kw1.most_common()[0][1] > kw2.most_common()[0][1]:
            x2 = kw2.most_common()[1][0]
        else:
            x1 = kw1.most_common()[1][0]

    ans = 0

    for i in v1:
        if i != x1:
            ans += 1

    for i in v2:
        if i != x2:
            ans += 1

    print(ans)

Submission status: Wrong Answer

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

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

    v1.sort(reverse=True)
    v2.sort(reverse=True)

    ans = 0

    val = v1[0]
    for i in v1:
        if i != val:
            ans += 1

    val = v2[0]
    for i in v2:
        if i != val:
            ans += 1

    print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
from collections import Counter
n = int(input())
a = list(map(int,input().split()))
a1 = a[0::2]
a2 = a[1::2]
if a1 == a2:
    ans = n // 2
else:
    Ca1 = Counter(a1)
    Ca2 = Counter(a2)
    Ca1 = Ca1.most_common()
    Ca2 = Ca2.most_common()
    if Ca1[0][0] == Ca2[0][0]:
        if Ca1[0][1] >= Ca2[0][1]:
            ans = len(a1) - int(Ca1[0][1])
            ans = ans + len(a2) - int(Ca2[1][1])
        else:
            ans = len(a1) - int(Ca1[1][1])
            ans = ans + len(a2) - int(Ca2[0][1])
        
    else:
        ans = len(a1) - int(Ca1[0][1])
        ans = ans + len(a2) - int(Ca2[0][1])
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
from collections import Counter
n = int(input())
a = list(map(int,input().split()))
a1 = a[0::2]
a2 = a[1::2]
if a1 == a2:
    ans = n // 2
else:
    Ca1 = Counter(a1)
    Ca2 = Counter(a2)
    Ca1 = Ca1.most_common()
    Ca2 = Ca2.most_common()
    ans = len(a1) - int(Ca1[0][1])
    ans = ans + len(a2) - int(Ca2[0][1])
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
from collections import Counter
n = int(input())
a = list(map(int,input().split()))
a1 = a[0::2]
a2 = a[1::2]
if a1 == a2:
    ans = n // 2
else:
    Ca1 = Counter(a1)
    Ca2 = Counter(a2)
    Ca1 = Ca1.most_common()
    Ca2 = Ca2.most_common()
    ans = len(a1) - int(Ca1[0][0])
    ans = ans + len(a2) - int(Ca2[0][0])
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
v = list(map(int, input().split()))
a, b = [0] * 100005, [0] * 100005
for i in range(len(v)):
    if i % 2: a[v[i]] += 1
    else: b[v[i]] += 1
a2, b2 = [], []
for i in range(len(a)):
    a2.append([a[i], i])
for i in range(len(b)):
    b2.append([b[i], i])
a2.sort()
a2.reverse()
b2.sort()
b2.reverse()

#a2 = [[2, 3], [1, 1], [0, 2], ...]
#b2 = [[2, 3], [1, 2], [0, 1], ...]
if a2[0][1] != b2[0][1]:
    print(n - a2[0][0] - b2[0][0])
else:
    print(n - max(a2[1][0] - b2[0][0], a2[0][0] - b2[1][0]))

#print(a2[:3])
#print(b2[:3])

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
n = int(input())
v = list(map(int, input().split()))
v0 = v[0::2]
v1 = v[1::2]
d0, d1 = defaultdict(int), defaultdict(int)

for i in range(n//2):
    d0[v0[i]] += 1
    d1[v1[i]] += 1

if v0==v1:
    print(n//2)
    exit()

res = 0
if len(d0)!=1:
    res += sum(d0.values()) - max(d0.values())

if len(d1)!=1:
    res += sum(d1.values()) - max(d1.values())
print(res)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
n = int(input())
v = list(map(int, input().split()))
v0 = v[0::2]
v1 = v[1::2]
d0, d1 = defaultdict(int), defaultdict(int)

for i in range(n//2):
    d0[v0[i]] += 1
    d1[v1[i]] += 1

if v0==v1:
    print(n//2)
    exit()

res = 0
if len(d0)!=1:
    res += min(d0.values())

if len(d1)!=1:
    res += min(d1.values())
print(res)

Submission status: Wrong Answer

Solution code:
N = int(input())
v = [int(x) for x in input().split()]

even = [v[2*i] for i in range(N//2)]
odd = [v[2*i+1] for i in range(N//2)]

from collections import Counter
dev = Counter(even)
dod = Counter(odd)

evmax = sorted(dev, key=dev.get, reverse = True)[0]
if len(dev) != 1 :
    ev2nd = sorted(dev, key=dev.get, reverse = True)[1]
odmax = sorted(dod, key=dod.get, reverse = True)[0]
if len(dod) != 1 :
    od2nd = sorted(dod, key=dod.get, reverse = True)[1]

if evmax != odmax :
    print(N//2 - max(dev[evmax],dod[odmax]))
elif len(dev) == 1 and len(dod) == 1 :
    print(N//2)
elif len(dev) == 1 :
    print(N//2 - max(dev[evmax],dod[od2nd]))
elif len(dod) == 1 :
    print(N//2 - max(dev[ev2nd],dod[odmax]))
else :
    print(min(N//2 - max(dev[evmax],dod[od2nd]), N//2 - max(dev[ev2nd],dod[odmax])))

Submission status: Wrong Answer

Solution code:
N = int(input())
v = [int(x) for x in input().split()]

even = [v[2*i] for i in range(N//2)]
odd = [v[2*i+1] for i in range(N//2)]

from collections import Counter
dev = Counter(even)
dod = Counter(odd)

evmax = sorted(dev, key=dev.get, reverse = True)[0]
if len(dev) != 1 :
    ev2nd = sorted(dev, key=dev.get, reverse = True)[1]
odmax = sorted(dod, key=dod.get, reverse = True)[0]
if len(dod) != 1 :
    od2nd = sorted(dod, key=dod.get, reverse = True)[1]

if evmax != odmax :
    print(N - dev[evmax] - dod[odmax])
elif len(dev) == 1 and len(dod) == 1 :
    print(N//2)
elif len(dev) == 1 :
    print(N - dev[evmax] - dod[od2nd])
elif len(dod) == 1 :
    print(N - dev[ev2nd] - dod[odmax])
else :
    print(min(N - dev[evmax] - dod[od2nd], 2*N - dev[ev2nd] - dod[odmax]))

Submission status: Wrong Answer

Solution code:
from collections import Counter
import sys
n = int(input())
v = list(map(int,input().split()))

a = Counter([x for x in v[0:n:2]])
b = Counter([x for x in v[1:n:2]])
a = sorted(a.items(),key = lambda z:z[1], reverse = True)
b = sorted(b.items(),key = lambda z:z[1], reverse = True)

if a == b:
    print(n//2)
    
elif a[0][0] == b[0][0]:
    if len(a) > 1 and len(b) > 1:
        c = (n//2 - a[0][1]) + (n//2 - b[1][1])
        d = (n//2 - a[1][1]) + (n//2 - b[0][1])
        print(min(c,d))
    else:
        print(min(a[0][1],b[0][1]))
        
else:
    print((n//2 - a[0][1]) + (n//2 - b[0][1]))

Submission status: Wrong Answer

Solution code:
from collections import Counter
import sys
n = int(input())
v = list(map(int,input().split()))

a = Counter([x for x in v[0:n:2]])
b = Counter([x for x in v[1:n:2]])
a = sorted(a.items(),key = lambda z:z[1], reverse = True)
b = sorted(b.items(),key = lambda z:z[1], reverse = True)

if a == b:
    print(n//2)
    
elif a[0] == b[0]:
    c = (n//2 - a[0][1]) + (n//2 - b[1][1])
    d = (n//2 - a[1][1]) + (n//2 - b[0][1])
    print(min(c,d))
else:
    print((n//2 - a[0][1]) + (n//2 - b[0][1]))

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

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

alpha = Counter(A[::2]).most_common(2)
beta = Counter(A[1::2]).most_common(2)

count = 0
if alpha[0][0] == beta[0][0]:
    if alpha[0][1] < beta[0][1]:
        alpha, beta = beta, alpha
    count += n//2 - alpha[0][1]
    count += n//2 - 0 if len(beta) == 1 else beta[1][1]
else:
    count += n//2 - alpha[0][1]
    count += n//2 - beta[0][1]
print(count)

Submission status: Wrong Answer

Solution code:
def run_length_compress(string):
    """文字列をランレングス圧縮する
    例) string = "aabccaaabb" -> [(2, a), (1, b), (2, c), (3, a), (2, b)]
    """
    string.append(-1) # string中に絶対に現れない文字を番兵とする
    n = len(string)

    begin = 0
    end = 1
    cnt = 1
    ans = []
    while True:
        if end >= n:
            break
        if string[begin] == string[end]:
            end += 1
            cnt += 1
        else:
            ans.append((cnt, string[begin]))
            begin = end
            end = begin + 1
            cnt = 1

    return ans
  
n = int(input())
v = list(map(int, input().split()))
even = []
odd = []

for i in range(n):
    if i % 2 == 0:
        even.append(v[i])
    else:
        odd.append(v[i])
memo_o = {}
for num in odd:
    if num not in memo_o:
        memo_o[num] = 1
    else:
        memo_o[num] += 1

even = sorted(even)
even =  run_length_compress(even)

ans = 10 ** 9
for i in memo_o:
    tmp = n // 2 - memo_o[i]
    tmp2 = n // 2
    for cnt, num in even[:2]:
        if i != num:
            tmp2 = min(n // 2 - cnt, tmp2)
    ans = min(ans, tmp + tmp2)
print(ans)

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
v = list(map(int,input().split()))
v1,v2 = v[0::2],v[1::2]
c1,c2 = collections.Counter(v1),collections.Counter(v2)
k1,k2 = list(c1.keys()),list(c2.keys())
val1,val2 = list(c1.values()),list(c2.values())
val1.append(0)
val2.append(0)
ans = n
if k1[0]==k2[0]:
    ans -= max(val1[0]+val2[1],val1[1]+val2[0])
else:
    ans -= val1[0]+val2[0]
print(ans)

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
v = list(map(int,input().split()))
v1,v2 = v[0::2],v[1::2]
c1,c2 = collections.Counter(v1),collections.Counter(v2)
k1,k2 = list(c1.keys()),list(c2.keys())
val1,val2 = list(c1.values()),list(c2.values())
ans = n
if k1[0]==k2[0]:
    if len(val1)==1 and len(val2)==1: ans -= val1[0]
    elif len(val1)==1: ans -= val2[1]
    elif len(val2)==1: ans-= val1[1]
    else: ans -= max(val1[0]+val2[1],val1[1]+val2[0])
else:
    ans -= val1[0]+val2[0]
print(ans)

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
v = list(map(int,input().split()))
v1,v2 = v[0::2],v[1::2]
c1,c2 = collections.Counter(v1),collections.Counter(v2)
k1,k2 = list(c1.keys()),list(c2.keys())
val1,val2 = list(c1.values()),list(c2.values())
ans = len(v1)+len(v2)
if k1[0]==k2[0]:
    if len(val1)==1: ans-=len(v1)
    elif len(val2)==1: ans-=len(v2)
    else: ans -= max(val1[0]+val2[1],val1[1]+val2[0])
else:
    ans -= val1[0]+val2[0]
print(ans)

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
v = list(map(int,input().split()))
v1,v2 = v[0::2],v[1::2]
ans = 0
c1 = list(collections.Counter(v1).values())
c2 = list(collections.Counter(v2).values())
if len(set(v1))==len(set(v2))==1 and set(v1)==set(v2):
    ans = len(v1)
else:
    ans = len(v1)-c1[0]+len(v2)-c2[0]
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
v=list(map(int,input().split()))
ans=0
x=dict()
y=dict()
z=dict()
for i in range(n):
    if v[i] in z:
        z[v[i]]+=1
    else:
        z[v[i]]=1
    if i%2==0:
        if v[i] in x:
            x[v[i]]+=1
        else:
            x[v[i]]=1
    else:
        if v[i] in y:
            y[v[i]]+=1
        else:
            y[v[i]]=1
c=len(z)
if c==1:
    ans=n//2
else:
    m1=0
    m2=0
    count=0
    flag=False
    for idx in y:
        if m1<y[idx]:
            tmp=idx
        m1=max(y[idx],m1)
    for idx in y:
        if m1==y[idx]:
            if tmp!=idx:
                flag=True
    for idx in x:
        if flag:
            m2=max(x[idx],m2)
        else:
            if idx!=tmp:
                m2=max(x[idx],m2)
    #print(m1)
    #print(m2)
    ans=(n//2-m1)+(n//2-m2)
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
v=list(map(int,input().split()))
ans=0
x=dict()
y=dict()
z=dict()
for i in range(n):
    if v[i] in z:
        z[v[i]]+=1
    else:
        z[v[i]]=1
    if i%2==0:
        if v[i] in x:
            x[v[i]]+=1
        else:
            x[v[i]]=1
    else:
        if v[i] in y:
            y[v[i]]+=1
        else:
            y[v[i]]=1
c=len(z)
if c==1:
    ans=n//2
else:
    m1=0
    m2=0
    count=0
    for idx in y:
        m1=max(y[idx],m1)
    for idx in x:
        m2=max(x[idx],m2)
    #print(m1)
    #print(m2)
    ans=(n//2-m1)+(n//2-m2)
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
from collections import Counter
def input(): return sys.stdin.readline().rstrip()

def main():
    n = int(input())
    v = tuple(map(int, input().split()))

    c_odd_most =  Counter(v[1::2]).most_common()
    c_even_most =  Counter(v[::2]).most_common()

    c_odd = c_odd_most[0][1]
    c_even = c_even_most[0][1]

    if c_odd_most[0][0] == c_even_most[0][0]:
        if c_odd > c_even:
            c_even = c_even_most[1][1]
        else:
            if len(c_odd_most) == 1:
                c_odd = 0
            else:
                c_odd = c_odd_most[1][1]
    print(n - c_odd - c_even)    

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
l = list(map(int,input().split()))
cnt = collections.Counter(l)
if(len(cnt)==1):
  print(n//2)
  exit()
max_cnt = cnt.most_common()[0][1]
second_cnt = cnt.most_common()[1][1]
print(abs(max_cnt - n // 2) + n - max_cnt - second_cnt)

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
l = list(map(int,input().split()))
cnt = collections.Counter(l)
if(len(cnt)==1):
  print(n//2)
  exit()
max_cnt = cnt.most_common()[0][1]
second_cnt = cnt.most_common()[1][1]
print((max_cnt - n // 2) + n - max_cnt - second_cnt)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
v_ = list(map(int,input().split()))
dic1 = {}
dic2 = {}
for i in range(n):
    if i%2 == 0:
        if v_[i] in dic1:
            dic1[v_[i]] += 1
        else:
            dic1[v_[i]] = 1
    else:
        if v_[i] in dic2:
            dic2[v_[i]] += 1
        else:
            dic2[v_[i]] = 1
a = max(dic1.values())
b = max(dic2.values())
if n-a-b != 0:
  print(n-a-b)
else:
  if v_[0] != v_[1]:
    print(0)
  else:
    print(n//2)

Submission status: Wrong Answer

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

n = int(input())
a = list(map(int,input().split()))
cnt_odd = [0]*(10**5+1)# a[2k]での個数
cnt_even = [0]*(10**5+1)
for i in range(n):
    if i  %2: cnt_odd[a[i]] += 1
    else: cnt_even[a[i]] += 1
odd,idx_odd=zip(*sorted(zip(cnt_odd,list(range(10**5+1)))))
even,idx_even=zip(*sorted(zip(cnt_even,list(range(10**5+1)))))
#print(odd[-1],even[-2],odd[-2],even[-1])
if idx_even[-1]!=idx_odd[-1]:
    print((n+1)//2 - odd[-1] + n//2 - even[-1])
else:
    print((n+1)//2 + n //2 - min(odd[-1]+even[-2],odd[-2]+even[-1]))