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:
def resolve():
    '''
    code here
    '''
    n = int(input())
    vs = [int(item) for item in input().split()]
    num_max = max(vs)

    memo_ev = [0 for _ in range(num_max+1)]
    memo_od = [0 for _ in range(num_max+1)]

    for i in range(n-2):
        if i%2 == 0:
            if vs[i] == vs[i+2]:
                memo_ev[vs[i]] +=1
        else:
            if vs[i] == vs[i+2]:
                memo_od[vs[i]] +=1
    
    ev_max = max(memo_ev)
    od_max = max(memo_od)

    if memo_ev.index(ev_max) == memo_od.index(od_max):
        if ev_max >= od_max:
            memo_od.remove(od_max)
            if max(memo_od) > 0:
                print((n//2-(ev_max+1)) + (n//2 - (max(memo_od)+1)))
            else:
                print((n//2-(ev_max+1)) + (n//2 - (max(memo_od))))
        else:
            memo_ev.remove(ev_max)
            if max(memo_ev) > 0:
                print((n//2-(od_max+1)) + (n//2 - (max(memo_ev)+1)))
            else:
                print((n//2-(od_max+1)) + (n//2 - (max(memo_ev))))
    else:
        print((n//2-(ev_max+1)) +(n//2-(od_max+1)))


if __name__ == "__main__":
    resolve()

Submission status: Wrong Answer

Solution code:
def resolve():
    '''
    code here
    '''
    n = int(input())
    vs = [int(item) for item in input().split()]
    num_max = max(vs)

    memo_ev = [0 for _ in range(num_max+1)]
    memo_od = [0 for _ in range(num_max+1)]

    for i in range(n-2):
        if i%2 == 0:
            if vs[i] == vs[i+2]:
                memo_ev[vs[i]] +=1
        else:
            if vs[i] == vs[i+2]:
                memo_od[vs[i]] +=1
    
    ev_max = max(memo_ev)
    od_max = max(memo_od)

    if memo_ev.index(ev_max) == memo_od.index(od_max):
        if ev_max >= od_max:
            memo_od.remove(od_max)
            print((n//2-(ev_max+1)) + (n//2 - (max(memo_od)+1)))
        else:
            memo_ev.remove(ev_max)
            print((n//2-(od_max+1)) + (n//2 - (max(memo_ev)+1)))
    else:
        print((n//2-(ev_max+1)) +(n//2-(od_max+1)))


if __name__ == "__main__":
    resolve()

Submission status: Wrong Answer

Solution code:
from collections import *
N = int(input())
V = list(map(int,input().split()))
C1 = Counter(V[0::2]).most_common()
C2 = Counter(V[1::2]).most_common()

if len(set(V))==1:
  ans = N//2
else:
  if C1[0][0]==C2[0][0]:
    ans = min(N-C1[0][1]-C2[1][1],N-C1[1][0]-C2[0][1])
  else:
    ans = N-C1[0][1]-C2[0][1]

print(ans)

Submission status: Wrong Answer

Solution code:
# abc111_c.py
# https://atcoder.jp/contests/abc111/tasks/arc103_a

# C - /\/\/\/ /
# 実行時間制限: 2 sec / メモリ制限: 1024 MB
# 配点 : 300点

# 問題文
# 数列 a1,a2,...,anが以下の条件を満たすとき、 /\/\/\/ と呼ぶことにします。
#     各 i=1,2,...,n−2について、ai=ai+2
#     数列に現れる数はちょうど 2種類

# 偶数長の数列 v1,v2,...,vnが与えられます。 
# 要素をいくつか書き換えることでこの数列を /\/\/\/ にしたいです。 書き換える要素の数は最小でいくつになるか求めてください。

# 制約
#     2≤n≤105
#     nは偶数
#     1≤vi≤105
#     viは整数

# 入力
# 入力は以下の形式で標準入力から与えられる。
# n
# v1 v2 ... vn

# 出力
# 書き換える要素数の最小値を出力してください。

# 入力例 1
# 4
# 3 1 3 2

# 出力例 1
# 1

# 数列 3,1,3,2は /\/\/\/ ではありませんが、1 要素書き換えることで /\/\/\/ にすることができます。 
# 例えば、4 要素目を書き換えて 3,1,3,1とすればよいです。

# 入力例 2
# 6
# 105 119 105 119 105 119

# 出力例 2
# 0

# 数列 105,119,105,119,105,119は /\/\/\/ です。

# 入力例 3
# 4
# 1 1 1 1

# 出力例 3
# 2

# 数列 1,1,1,1は 1 種類の数からなる数列であるため、 /\/\/\/ ではありません。


def calculation(lines):
    n = int(lines[0])
    values = list(map(int, lines[1].split()))
    # n = lines[0]

    d_odd = dict()
    d_even = dict()
    for i in range(n):
        value = values[i]
        if i % 2 == 0:
            if value in d_even.keys():
                d_even[value] += 1
            else:
                d_even[value] = 1
        else:
            if value in d_odd.keys():
                d_odd[value] += 1
            else:
                d_odd[value] = 1

    n_even_max1st = 0
    n_even_max2nd = 0
    for key in d_even:
        ma = d_even[key]
        if n_even_max1st < ma:
            key_even = key
            n_even_max2nd = n_even_max1st
            n_even_max1st = ma

    n_odd_max1st = 0
    n_odd_max2nd = 0
    for key in d_odd:
        ma = d_odd[key]
        if n_odd_max1st < ma:
            key_odd = key
            n_odd_max2nd = n_odd_max1st
            n_odd_max1st = ma

    # 変数初期化
    result = 0

    # 奇数/偶数の最大値が異なる場合
    if key_even != key_odd:
        print('if d_even[key_even] != d_odd[key_odd]:')
        result += (int(n/2)-n_even_max1st)
        result += (int(n/2)-n_odd_max1st)
    else:
        m = max(n_even_max2nd, n_odd_max2nd)
        result += (int(n/2)-n_even_max1st)
        result += (int(n/2)-m)

    return [result]


# 引数を取得
def get_input_lines(lines_count):
    lines = list()
    for _ in range(lines_count):
        lines.append(input())
    return lines


# テストデータ
def get_testdata(pattern):
    if pattern == 1:
        lines_input = ['4', '3 1 3 2']
        lines_export = [1]
    if pattern == 2:
        lines_input = ['6', '105 119 105 119 105 119']
        lines_export = [0]
    if pattern == 3:
        lines_input = ['4', '1 1 1 1']
        lines_export = [2]
    return lines_input, lines_export


# 動作モード判別
def get_mode():
    import sys
    args = sys.argv
    if len(args) == 1:
        mode = 0
    else:
        mode = int(args[1])
    return mode


# 主処理
def main():
    import time
    started = time.time()
    mode = get_mode()
    if mode == 0:
        lines_input = get_input_lines(2)
    else:
        lines_input, lines_export = get_testdata(mode)

    lines_result = calculation(lines_input)

    for line_result in lines_result:
        print(line_result)

    # if mode > 0:
    #     print(f'lines_input=[{lines_input}]')
    #     print(f'lines_export=[{lines_export}]')
    #     print(f'lines_result=[{lines_result}]')
    #     if lines_result == lines_export:
    #         print('OK')
    #     else:
    #         print('NG')
    # finished = time.time()
    # duration = finished - started
    # print(f'duration=[{duration}]')


# 起動処理
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# 初期入力
from collections import Counter
import sys
input = sys.stdin.readline  #文字列では使わない
n = int(input())
v = list(map(int, input().split()))
vo1 =v[1::2]
ve2 =v[0::2]
co1_k,co1_v = zip(*Counter(vo1).most_common())
ce2_k,ce2_v = zip(*Counter(ve2).most_common())

ans =0

if vo1 ==ve2:
    ans =len(vo1)
elif len(co1_v) ==len(ce2_v) ==1:
    ans =0
elif co1_k[0] ==ce2_k[0]:
    if len(co1_v) ==1:
        ans =sum(ce2_v[1:])
    elif len(ce2_v) ==1:
        ans =sum(co1_v[1:])
    elif len(co1_v) ==len(ce2_v) ==2:
        ans1 =co1_v[1] +ce2_v[0]
        ans2 =co1_v[0] +ce2_v[1]
        ans =min(ans1,ans2)
    elif len(co1_v) ==2:
        ans1 =co1_v[1] +ce2_v[0] +sum(ce2_v[2:])
        ans2 =co1_v[0] +sum(ce2_v[1:])
        ans =min(ans1,ans2)
    elif len(ce2_v) ==2:
        ans1 =ce2_v[1] +co1_v[0] +sum(co1_v[2:])
        ans2 =ce2_v[0] +sum(co1_v[1:])
        ans =min(ans1,ans2)
    else:
        ans1 =sum(co1_v[1:]) +ce2_v[0] +sum(ce2_v[2:] )
        ans2 =sum(ce2_v[1:]) +co1_v[0] +sum(co1_v[2:] )
        ans =min(ans1,ans2)
else: 
    if len(co1_v) ==1:
        ans =sum(ce2_v[1:])
    elif len(ce2_v) ==1:
        ans =sum(co1_v[1:])
    else:
        ans =sum(co1_v[1:]) +sum(ce2_v[1:])  
   
print(ans)

Submission status: Wrong Answer

Solution code:
# 初期入力
from collections import Counter
import sys
input = sys.stdin.readline  #文字列では使わない
n = int(input())
v = list(map(int, input().split()))
vo1 =v[1::2]
ve2 =v[0::2]
co1 = Counter(vo1)
ce2 = Counter(ve2)
co1_l =list(co1.values())
ce2_l =list(ce2.values())
co1_l.sort(reverse=True)
ce2_l.sort(reverse=True)
ans =0

if vo1 ==ve2:
    ans =len(vo1)
elif list(co1.keys())[0] ==list(ce2.keys())[0]:
    if len(co1_l) ==2:
        ans1 =co1_l[1] +ce2_l[0]
        ans2 =ce2_l[1] +co1_l[0]
        ans =min(ans1,ans2)
    else:
        ans1 =sum(co1_l[1:]) +ce2_l[0] +sum(ce2_l[2:] )
        ans2 =sum(ce2_l[1:]) +co1_l[0] +sum(co1_l[2:] )
        ans =min(ans1,ans2)
else:   
    if len(co1_l) ==1 :
        ans =0
    else:
        ans =sum(co1_l[1:])

    if len(ce2_l) ==1:
        ans +=0
    else:
        ans +=sum(ce2_l[1:])
print(ans)

Submission status: Wrong Answer

Solution code:
# 初期入力
from collections import Counter
import sys
input = sys.stdin.readline  #文字列では使わない
n = int(input())
v = list(map(int, input().split()))
vo1 =v[1::2]
ve2 =v[0::2]
co1 = Counter(vo1)
ce2 = Counter(ve2)
co1_l =list(co1.values())
ce2_l =list(ce2.values())
co1_l.sort(reverse=True)
ce2_l.sort(reverse=True)
ans =0

if vo1 ==ve2:
    ans =len(vo1)
elif list(co1.keys())[0] ==list(ce2.keys())[0]:
    if len(co1_l) ==2:
        ans1 =co1_l[1] +ce2_l[0]
        ans2 =ce2_l[1] +co1_l[0]
    else:
        ans1 =sum(co1_l[1:]) +ce2_l[0] +sum(ce2_l[2:] )
        ans2 =sum(ce2_l[1:]) +co1_l[0] +sum(co1_l[2:] )
        ans =min(ans1,ans2)
else:   
    if len(co1_l) ==1 :
        ans =0
    else:
        ans =sum(co1_l[1:])

    if len(ce2_l) ==1:
        ans +=0
    else:
        ans +=sum(ce2_l[1:])
print(ans)

Submission status: Wrong Answer

Solution code:
# 初期入力
from collections import Counter
import sys
input = sys.stdin.readline  #文字列では使わない
n = int(input())
v = list(map(int, input().split()))
vo1 =v[1::2]
ve2 =v[0::2]
co1 = Counter(vo1)
ce2 = Counter(ve2)
co1_l =list(co1.values())
ce2_l =list(ce2.values())
co1_l.sort(reverse=True)
ce2_l.sort(reverse=True)
ans =0

if vo1 ==ve2:
    ans =len(vo1)
elif list(co1.keys())[0] ==list(ce2.keys())[0]:
    if len(co1_l) ==2:
        ans =co1_l[1] +ce2_l[0]
    else:
        ans =sum(co1_l[1:]) +ce2_l[0] +sum(ce2_l[2:] )
else:   
    if len(co1_l) ==1 :
        ans =0
    else:
        ans =sum(co1_l[1:])

    if len(ce2_l) ==1:
        ans +=0
    else:
        ans +=sum(ce2_l[1:])
print(ans)

Submission status: Wrong Answer

Solution code:
# 初期入力
from collections import Counter
import sys
input = sys.stdin.readline  #文字列では使わない
n = int(input())
v = list(map(int, input().split()))
vo1 =v[1::2]
ve2 =v[0::2]
co1 = Counter(vo1)
ce2 = Counter(ve2)
co1_l =list(co1.values())
ce2_l =list(ce2.values())
co1_l.sort(reverse=True)
ce2_l.sort(reverse=True)
ans =0

if vo1 ==ve2:
    ans =len(vo1)
elif co1_l[0] ==ce2_l[0]:
    if len(co1_l) ==2:
        ans =sum(co1_l[1:]) +ce2_l[0]
    else:
        ans =sum(co1_l[1:]) +ce2_l[0] +sum(ce2_l[2:] )
else:   
    if len(co1_l) ==1 :
        ans =0
    else:
        ans =sum(co1_l[1:])

    if len(ce2_l) ==1:
        ans +=0
    else:
        ans +=sum(ce2_l[1:])
print(ans)

Submission status: Wrong Answer

Solution code:
# 初期入力
from collections import Counter
import sys
input = sys.stdin.readline  #文字列では使わない
n = int(input())
v = list(map(int, input().split()))
vo1 =v[1::2]
ve2 =v[0::2]
co1 = Counter(vo1)
ce2 = Counter(ve2)
co1_l =list(co1.values())
ce2_l =list(ce2.values())
co1_l.sort(reverse=True)
ce2_l.sort(reverse=True)
ans =0

if vo1 ==ve2:
    ans =len(vo1)
else:   
    if len(co1_l) ==1 :
        ans =0
    else:
        ans =sum(co1_l[1:])

    if len(ce2_l) ==1:
        ans +=0
    else:
        ans +=sum(ce2_l[1:])
print(ans)

Submission status: Wrong Answer

Solution code:
# 初期入力
from collections import Counter
import sys
input = sys.stdin.readline  #文字列では使わない
n = int(input())
v = list(map(int, input().split()))
vo1 =v[1::2]
ve2 =v[0::2]
co1 = Counter(vo1)
ce2 = Counter(ve2)
co1_l =list(co1.values())
ce2_l =list(ce2.values())
co1_l.sort(reverse=True)
ce2_l.sort(reverse=True)
ans =0

if vo1 ==ve2:
    ans =len(vo1)
else:   
    if len(co1_l) ==1 :
        ans +=0
    else:
        ans +=sum(co1_l[1:])

    if len(ce2_l) ==1:
        ans +=0
    else:
        ans +=sum(ce2_l[1:])
print(ans)

Submission status: Wrong Answer

Solution code:
# 初期入力
from collections import Counter
import sys
input = sys.stdin.readline  #文字列では使わない
n = int(input())
v = list(map(int, input().split()))
vo1 =v[1::2]
ve2 =v[0::2]
co1 = Counter(vo1)
ce2 = Counter(ve2)
co1_l =list(co1.values())
ce2_l =list(ce2.values())
co1_l.sort(reverse=True)
ce2_l.sort(reverse=True)
ans =0

if vo1 ==ve2:
    ans =len(vo1)
if len(co1_l) ==1 :
    ans +=0
else:
    ans +=sum(co1_l[1:])

if len(ce2_l) ==1:
    ans +=0
else:
    ans +=sum(ce2_l[1:])
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
v = list(map(int, input().split()))
odd = [v[2*i] for i in range(n//2)]
even = [v[2*i+1] for i in range(n//2)]

co = Counter(odd)
ce = Counter(even)
co = co.most_common()
ce = ce.most_common()
if co[0][0] == ce[0][0]:
  if (len(co)>1) and (len(ce)>1):
    ans = min(n//2-co[1][1], n//2-ce[1][1])
  elif len(co) > 1:
    ans = n//2 - co[1][1]
  elif len(ce) > 1:
    ans = n//2 - ce[1][1]
  else:
    ans = n//2
else:
  ans = n//2-co[0][1] + n//2-ce[0][1]
print(ans)

Submission status: Wrong Answer

Solution code:
import collections
N = int(input())
V = list(map(int,input().split()))
E = []
O = []
for i in range(N):
    if i % 2 == 0:
        O.append(V[i])
    else:
        E.append(V[i])
EC = collections.Counter(E).most_common()
OC = collections.Counter(O).most_common()
if len(EC) == 1 and len(OC) == 1:
    if EC[0][0] == OC[0][0]:
        print(N//2)
    else:
        print(0)
elif len(EC) == 1 and len(OC) != 1:
    if EC[0][0] == OC[0][0]:
        print(N//2-OC[1][1])
    else:
        print(N//2-OC[0][1])
elif len(EC) != 1 and len(OC) == 1:
    if EC[0][0] == OC[0][0]:
        print(N//2-EC[1][1])
    else:
        print(N//2-EC[0][1])
elif EC[0][0] == OC[0][0]:
    if EC[0][1]+OC[1][1] == EC[1][1]+OC[0][1]:
        print(N-EC[0][1]-OC[1][1])
    elif EC[0][1]+OC[1][1] > EC[1][1]+OC[0][1]:
        print(N-EC[0][1]-OC[1][1])
    else:
        print(N-EC[1][1]-OC[0][1])
else:
    print(N-EC[0][0]-OC[0][0])

Submission status: Wrong Answer

Solution code:
from collections import Counter

n, *v = map(int, open(0).read().split())
vo = Counter(v[::2])
ve = Counter(v[1::2])
vo_mc = vo.most_common()[0]
ve_mc = ve.most_common()[0]
if vo_mc[0] == ve_mc[0]: 
    if vo_mc[1] > ve_mc[1]:
        ans = n//2 - vo_mc[1]
        if ve_mc[1] != n//2:
            ans += n//2 - ve.most_common()[1][1]
        else:
            ans += n//2
    elif vo_mc[1] <= ve_mc[1]:
        ans =  n//2 - ve_mc[1]
        if vo_mc[1] != n//2:
            ans += n//2 - vo.most_common()[1][1]
        else:
            ans += n//2
else:
    ans = n//2 - vo_mc[1] + n//2 - ve_mc[1]
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

n, *v = map(int, open(0).read().split())
vo = Counter(v[::2])
ve = Counter(v[1::2])
vo_mc = vo.most_common()[0]
ve_mc = ve.most_common()[0]
if vo_mc[0] == ve_mc[0]: 
    if vo_mc[1] >= ve_mc[1]:
        ans = n//2 - vo_mc[1]
        if ve_mc[1] != n//2:
            ans += n//2 - ve.most_common()[1][1]
        else:
            ans += n//2
    elif vo_mc[1] < ve_mc[1]:
        ans =  n//2 - ve_mc[1]
        if vo_mc[1] != n//2:
            ans += n//2 - vo.most_common()[1][1]
        else:
            ans += n//2
else:
    ans = n//2 - vo_mc[1] + n//2 - ve_mc[1]
print(ans)

Submission status: Wrong Answer

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

odd_list =[]
num_list =[]

for i in range(n):
    if i%2 == 0:
        odd_list.append(arr[i])
    if i%2 != 0:
        num_list.append(arr[i])

odd_count = Counter(odd_list)
num_count = Counter(num_list)
odd1 = odd_count[odd_count.most_common()[0][0]]
num1 = num_count[num_count.most_common()[0][0]]


if len(set(odd_count)) == 1 and len(set(num_count)) == 1:
    print(int(n/2))
    exit()

if len(set(odd_count)) == 1 and len(set(num_count)) != 1:
    num2 = num_count[num_count.most_common()[1][0]]
    if odd_count[0] == num_count.most_common()[0][0]:
        print(n-num2)
        exit()
    if odd_count[0] != num_count.most_common()[0][0]:
        print(n-num1)
        exit()

if len(set(odd_count)) != 1 and len(set(num_count)) == 1:
    odd2 = odd_count[odd_count.most_common()[1][0]]
    if num_count[0] == odd_count.most_common()[0][0]:
        print(n-odd2)
        exit()
    if num_count[0] != odd_count.most_common()[0][0]:
        print(n-odd1)
        exit()

odd2 = odd_count[odd_count.most_common()[1][0]]
num2 = num_count[num_count.most_common()[1][0]]

if odd_count.most_common()[0][0] != num_count.most_common()[0][0]:
    print(n-odd1-num1)

if odd_count.most_common()[0][0] == num_count.most_common()[0][0]:
    print(min(n-odd1-num2, n-odd2-num1))

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:

    c1 = Counter(v[::2])
    c2 = Counter(v[1::2])
    print(n-c1.most_common(2)[0][1]-c2.most_common(2)[0][1])

Submission status: Wrong Answer

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

if len(set(v)) == 1:
    print(n // 2)
else:
    a = v[::2]
    b = v[1::2]
    ca = Counter(a)
    cb = Counter(b)
    values_a, counts_a = zip(*ca.most_common())
    values_b, counts_b = zip(*cb.most_common())
    print(sum(counts_a[1:]) + sum(counts_b[1:]))

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# FileName: 	C
# CreatedDate:  2020-07-18 13:07:51 +0900
# LastModified: 2020-07-18 14:05:48 +0900
#


import os
import sys
from collections import Counter


def main():
    n = int(input())
    v = list(map(int, input().split()))
    v_even = [v[s] for s in range(0, n, 2)]
    v_odd = [v[s] for s in range(1, n, 2)]
    even_cnt = Counter(v_even)
    odd_cnt = Counter(v_odd)
    even_cnt_list = sorted(map(list, even_cnt.items()), key=lambda x: x[1], reverse = True)
    odd_cnt_list = sorted(map(list, odd_cnt.items()), key = lambda x: x[1], reverse = True)
    e = 0
    o = 0
    rest_e = -1
    rest_o = -1
    while 1:
        if len(even_cnt_list) <= e or len(odd_cnt_list) <= o:
            break
        if even_cnt_list[e][0] == odd_cnt_list[o][0]:
            if even_cnt_list[e][1]>odd_cnt_list[o][1]:
                rest_e = even_cnt_list[e][0]
                rest_o = odd_cnt_list[o+1][0]
                break
            elif even_cnt_list[e][1]<odd_cnt_list[0][1]:
                rest_o = odd_cnt_list[o][0]
                rest_e = even_cnt_list[e+1][0]
                break
            else:
                e += 1
                o += 1
        else:
            rest_e = even_cnt_list[e][0]
            rest_o = odd_cnt_list[o][0]
            break
    even_sum = sum(even_cnt.values()) - even_cnt[rest_e]
    odd_sum = sum(odd_cnt.values()) - odd_cnt[rest_o]
    
    other_sum = 0
    if rest_e == -1 and rest_o == -1:
        other_sum = sum(even_cnt.values())
        even_sum = 0
        odd_sum = 0

    print(even_sum+odd_sum+other_sum)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# FileName: 	C
# CreatedDate:  2020-07-18 13:07:51 +0900
# LastModified: 2020-07-18 13:30:23 +0900
#


import os
import sys
# import numpy as np
# import pandas as pd
from collections import Counter


def main():
    n = int(input())
    v = list(map(int, input().split()))
    v_even = [v[s] for s in range(0, n, 2)]
    v_odd = [v[s] for s in range(1, n, 2)]
    even_cnt = Counter(v_even)
    odd_cnt = Counter(v_odd)
    other_cnt = 0
    if len(even_cnt.keys()) == 1:
        even_sum = 0
    else:
        even_sum = sum(even_cnt.values()) - max(even_cnt.values())
    if len(odd_cnt.keys()) == 1:
        odd_sum = 0
    else:
        odd_sum = sum(odd_cnt.values()) - max(odd_cnt.values())

    even_cnt_list = list(map(int, even_cnt.keys()))
    odd_cnt_list = list(map(int, odd_cnt.keys()))
    if len(even_cnt.keys()) == 1 and len(odd_cnt.keys()) == 1 and even_cnt_list[0] == odd_cnt_list[0]:
        other_cnt = sum(even_cnt.values())
    print(even_sum + odd_sum + other_cnt)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
from collections import Counter
n=int(input())
v=list(map(int,input().split()))
v1=[]
v2=[]
for i in range(n//2):
    v1.append(v[2*i])
    v2.append(v[2*i+1])
v1_count=Counter(v1)
v2_count=Counter(v2)
if v1==v2:
  print(n//2)
elif v1_count.most_common()[0][0]!=v2_count.most_common()[0][0]:
    print(n-v1_count.most_common()[0][1]-v2_count.most_common()[0][1])
else:
    if v1_count.most_common()[0][1]==n//2:
      print(n-v2_count.most_common()[1][1]-v1_count.most_common()[0][1])
    elif v2_count.most_common()[0][1]==n//2:
      print(n-v1_count.most_common()[1][1]-v2_count.most_common()[0][1])
    elif v1_count.most_common()[0][0]-v1_count.most_common()[1][0]>=v2_count.most_common()[0][0]-v2_count.most_common()[1][0]:
        print(n-v2_count.most_common()[1][1]-v1_count.most_common()[0][1])
    else:
        print(n-v1_count.most_common()[1][1]-v2_count.most_common()[0][1])

Submission status: Wrong Answer

Solution code:
from collections import Counter
n=int(input())
v=list(map(int,input().split()))
v1=[]
v2=[]
for i in range(n//2):
    v1.append(v[2*i])
    v2.append(v[2*i+1])
v1_count=Counter(v1)
v2_count=Counter(v2)
if v1==v2:
  print(n//2)
elif v1_count.most_common()[0][0]!=v2_count.most_common()[0][0]:
    print(n-v1_count.most_common()[0][1]-v2_count.most_common()[0][1])
else:
    if v1_count.most_common()[0][0]-v1_count.most_common()[1][0]>=v2_count.most_common()[0][0]-v2_count.most_common()[1][0]:
        print(n-v2_count.most_common()[1][1]-v1_count.most_common()[0][1])
    else:
        print(n-v1_count.most_common()[1][1]-v2_count.most_common()[0][1])

Submission status: Wrong Answer

Solution code:
from collections import Counter
n=int(input())
v=list(map(int,input().split()))
v1=[]
v2=[]
for i in range(n//2):
    v1.append(v[2*i])
    v2.append(v[2*i+1])
v1_count=Counter(v1)
v2_count=Counter(v2)
if v1==v2:
  print(n//2)
elif v1_count.most_common()[0][0]!=v2_count.most_common()[0][0]:
    print(n-v1_count.most_common()[0][1]-v2_count.most_common()[0][1])
    print(v1_count.most_common())
    print(v1)
else:
    if v1_count.most_common()[0][0]-v1_count.most_common()[1][0]>=v2_count.most_common()[0][0]-v2_count.most_common()[1][0]:
        print(n-v2_count.most_common()[1][1]-v1_count.most_common()[0][1])
    else:
        print(n-v1_count.most_common()[1][1]-v2_count.most_common()[0][1])

Submission status: Wrong Answer

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

even = {}
odd = {}
for i in range(n):
    if i%2 == 0:
        if a[i] not in even:
            even[a[i]] = 1
        else:
            even[a[i]] += 1
    else:
        if a[i] not in odd:
            odd[a[i]] = 1
        else:
            odd[a[i]] += 1

sorted_even = sorted(even.items(), reverse=True, key=lambda x:x[1])
sorted_odd = sorted(odd.items(), reverse=True, key=lambda x:x[1])

if sorted_even[0][0] != sorted_odd[0][0]:
    print(n - sorted_even[0][1] - sorted_odd[0][1])
elif sorted_even[0][1] == sorted_odd[0][1]:
    if len(sorted_even) == 1 and len(sorted_odd) == 1:
        print(n//2)
    else:
        print(n - sorted_even[0][1] - sorted_odd[0][1])
elif sorted_even[0][1] > sorted_odd[0][1]:
    print(n - sorted_even[0][1] - sorted_odd[1][1])
else:
    print(n - sorted_even[1][1] - sorted_odd[0][1])

Submission status: Wrong Answer

Solution code:
def mi(a, b, m, an, bn):
    cnt = 0
    for i in range(m):
        cnt += (a[i]-an) + (b[i]-bn)
    return cnt

from collections import Counter
def solve():
    n = int(input())
    v = list(map(int, input().split()))

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

    m = n//2
    ac = Counter(a)
    bc = Counter(b)
    an1 = 0
    an2 = 0
    bn1 = 0
    bn2 = 0
    for i,j in ac.items():
        if an1 < j:
            an1 = i
        elif an2 < j:
            an2 = i
    for i,j in bc.items():
        if bn1 < j:
            bn1 = i
        elif bn2 < j:
            bn2 = i

    if an1 != bn1:
        return mi(a, b, m, an1, bn1)
    else:
        return min(mi(a, b, m, an1, bn2), mi(a, b, m, an2, bn1))
    

print(solve())

Submission status: Wrong Answer

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

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

    m = n//2
    a_mean = sum(a)//m
    b_mean = sum(b)//m
    cnt = 0
    if a_mean == b_mean: b_mean = -(-sum(b)//m)
    if a_mean == b_mean: b_mean -= 1
    for i in range(m):
        cnt += (a[i]-a_mean) + (b[i]-b_mean)
        
    return cnt

print(solve())

Submission status: Wrong Answer

Solution code:
from collections import Counter
def main():
    n=int(input())
    v=list(map(int,input().split()))
    v0=Counter(v[0::2]).most_common(2)
    v1=Counter(v[1::2]).most_common(2)
    
    print(v0)
    print(v1)
    print(n, v0[0], v1[0])
    if v0[0][0] != v1[0][0]:
        print(n - v0[0][1] - v1[0][1])
    else:
        if len(v0) == 1 and len(v1) == 1:
            print(n//2)
        else:
            print(n-max(v0[0][1]+v1[1][1], v0[1][1]+v1[0][1]))
    
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
from collections import Counter
def main():
    n=int(input())
    v=list(map(int,input().split()))
    v0=sorted(Counter(v[::2]).items(), key=lambda x: x[1])
    v1=sorted(Counter(v[1::2]).items(), key=lambda x: x[1])
    vv = v1[-1][1]
    if v0[-1][0] == v1[-1][0]:
        if len(v0) > 1 and len(v1) > 0:
            vv = min(v0[-2][1], v1[-2][1])
        elif len(v0) > 1:
            vv = v0[-2][1]
        elif len(v1) > 1:
            vv = v1[-2][1]
        else:
            print(n//2)
            return
    #print(n, v0[-1][1], vv)
    print(n-v0[-1][1]-vv)
    
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
from collections import Counter
def main():
    n=int(input())
    v=list(map(int,input().split()))
    v0=sorted(Counter(v[::2]).items(), key=lambda x: x[1])
    v1=sorted(Counter(v[1::2]).items(), key=lambda x: x[1])
    vv = v1[-1][0]
    if v0[-1][0] == v1[-1][0]:
        if len(v0) > 1 and len(v1) > 0:
            vv = min(v0[-2][1], v1[-2][1])
        elif len(v0) > 1:
            vv = v0[-2][1]
        elif len(v1) > 1:
            vv = v1[-2][1]
        else:
            print(n//2)
            return
    print(n-v0[-1][1]-vv)
    
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

dico = {}
dice = {}
for i in range(N):
  if i % 2 == 0:
    if As[i] not in dice:
      dice[As[i]] = 1
    else:
      dice[As[i]] += 1
  else:
    if As[i] not in dico:
      dico[As[i]] = 1
    else:
      dico[As[i]] += 1
    
cnto = [0,0]
cnte = [0,0]

o = -1
e = -1
for k in dico:
  if dico[k] > cnto[0]:
    cnto[1] = cnto[0]
    cnto[0] = dico[k]
    o = k
  elif dico[k] > cnto[1]:
    cnto[1] = dico[k]
    
for k in dice:
  if dice[k] > cnte[0]:
    cnte[1] = cnte[0]
    cnte[0] = dice[k]
    e = k
  elif dice[k] > cnte[1]:
    cnte[1] = dice[k]
  
if o == k:
  if cnto[0] == cnte[0]:
    print(N-cnto[0]-max(cnto[1],cnte[1]))
  else:
    print(N-max(cnto[0]+cnte[1],cnte[0]+cnto[1]))
else:  
  print(N-cnto[0]-cnte[0])

Submission status: Wrong Answer

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

dico = {}
dice = {}
for i in range(N):
  if i % 2 == 0:
    if As[i] not in dice:
      dice[As[i]] = 1
    else:
      dice[As[i]] += 1
  else:
    if As[i] not in dico:
      dico[As[i]] = 1
    else:
      dico[As[i]] += 1
    
cnto = [0,0]
cnte = [0,0]

o = -1
e = -1
for k in dico:
  if dico[k] > cnto[0]:
    cnto[1] = cnto[0]
    cnto[0] = dico[k]
    o = k
  elif dico[k] > cnto[1]:
    cnto[1] = dico[k]
    
for k in dice:
  if dice[k] > cnte[0]:
    cnte[1] = cnte[0]
    cnte[0] = dice[k]
    e = k
  elif dice[k] > cnte[1]:
    cnte[1] = dice[k]
  
if o == k:
  if cnto[0] == cnte[0]:
    print(N-cnto[0]-max(cnto[1],cnte[1]))
  else:
    print(N-max(cnto[0]+cnte[1],cnte[0]+cnto[1]))
else:  
  print(N-cnto[0]-cnte[1])

Submission status: Wrong Answer

Solution code:
from collections import Counter
import sys
n = int(input())
v = [int(x) for x in input().split()]
test = [x == v[0] for x in v]
if all(test):
    print(int(n/2))
    sys.exit()
odd = sorted([int(x) for x in v[0::2]])
even = sorted([int(x) for x in v[1::2]])
odd_count = Counter(odd)
key1 = list(odd_count)
even_count = Counter(even)
key2 = list(even_count)
if len(key1) > 1:
    o1 = odd_count[key1[0]]
    o2 = odd_count[key1[1]]
else:
    o1 = odd_count[key1[0]]
    o2 = 0
if len(key2) > 1:
    e1 = even_count[key2[0]]
    e2 = even_count[key2[1]]
else:
    e1 = even_count[key2[0]]
    e2 = 0
if key1[0] == key2[0]:
    print(n-o1-e1+min(o1-o2,e1-e2))
else:
    print(n-o1-e1)

Submission status: Wrong Answer

Solution code:
from collections import Counter
import sys
n = int(input())
v = [int(x) for x in input().split()]
test = [x == v[0] for x in v]
if all(test):
    print(int(n/2))
    sys.exit()
odd = [int(x) for x in v[0::2]]
even = [int(x) for x in v[1::2]]
odd_count = Counter(odd)
key1 = list(odd_count)
even_count = Counter(even)
key2 = list(even_count)
if len(key1) > 1:
    o1 = odd_count[key1[0]]
    o2 = odd_count[key1[1]]
else:
    o1 = odd_count[key1[0]]
    o2 = 0
if len(key2) > 1:
    e1 = even_count[key2[0]]
    e2 = even_count[key2[1]]
else:
    e1 = even_count[key2[0]]
    e2 = 0
if key1[0] == key2[0]:
    print(n-o1-e1+min(o1-o2,e1-e2))
else:
    print(n-o1-e1)

Submission status: Wrong Answer

Solution code:
from collections import Counter
import sys
n = int(input())
v = [int(x) for x in input().split()]
test = [x == v[0] for x in v]
if all(test):
    print(int(n/2))
    sys.exit()
odd = [int(x) for x in v[0::2]]
even = [int(x) for x in v[1::2]]
odd_count = Counter(odd)
key1 = list(reversed(list(odd_count)))
even_count = Counter(even)
key2 = list(reversed(list(even_count)))
if len(key1) > 1:
    o1 = odd_count[key1[0]]
    o2 = odd_count[key1[1]]
else:
    o1 = odd_count[key1[0]]
    o2 = 0
if len(key2) > 1:
    e1 = even_count[key2[0]]
    e2 = even_count[key2[1]]
else:
    e1 = even_count[key2[0]]
    e2 = 0
if key1[0] == key2[0]:
    print(n-o1-e1+min(o1-o2,e1-e2))
else:
    print(n-o1-e1)