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:
from collections import Counter

n = int(input())
if(n == 2):
    print(0)
else:
    v = [int(i) for i in input().split()]
    v1 = Counter(v[::2])
    v2 = Counter(v[1::2])
    v1mc = v1.most_common()
    v2mc = v2.most_common()
    if(v1mc[0][0] == v2mc[0][0]):
        if(len(v1mc) == 1 and len(v2mc) == 1):
            print(n/2)
        elif(len(v1mc) == 1):
            print(n - (v1mc[0][1]+v2mc[1][1]))
        elif(len(v2mc) == 1):
            print(n - (v2mc[0][1]+v1mc[1][1]))
        else:
            print(n - max(v1mc[0][1]+v2mc[1][1], v2mc[0][1]+v1mc[1][1]))
    else:
        print(n - (v1mc[0][1]+v2mc[0][1]))

Submission status: Wrong Answer

Solution code:
from collections import Counter

n = int(input())
if(n == 2):
    print(0)
else:
    v = [int(i) for i in input().split()]
    v1 = Counter(v[::2])
    v2 = Counter(v[1::2])
    v1mc = v1.most_common()
    v2mc = v2.most_common()
    print(len(v1mc))
    if(v1mc[0][0] == v2mc[0][0]):
        if(len(v1mc) == 1 and len(v2mc) == 1):
            print(n/2)
        elif(len(v1mc) == 1):
            print(n - (v1mc[0][1]+v2mc[1][1]))
        elif(len(v2mc) == 1):
            print(n - (v2mc[0][1]+v1mc[1][1]))
        else:
            print(n - max(v1mc[0][1]+v2mc[1][1], v2mc[0][1]+v1mc[1][1]))
    else:
        print(n - (v1mc[0][1]+v2mc[0][1]))

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
import numpy as np

n = input()
m = input().strip().split()
l = [0] * 100001
k = [0] * 100001
b = m[0::2]
c = m[1::2]

for i in b:
    i = int(i)
    l[i] = l[i] + 1

for j in c:
    j = int(j)
    k[j] = k[j] + 1

print(len(b)-int(max(l))+len(c)-int(max(k)))

Submission status: Wrong Answer

Solution code:
from collections import Counter
n=int(input())
origin_list=list(map(int,input().split()))
list_1=[]
list_2=[]
for i in range(1,n,2):
    list_1.append(origin_list[i])
for i in range(0,n,2):
    list_2.append(origin_list[i])
counter_1=Counter(list_1)
counter_2=Counter(list_2)
mode1=counter_1.most_common(1)[0][1]
mode2=counter_2.most_common(1)[0][1]
print(n-(mode1+mode2))

Submission status: Wrong Answer

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

v_k_count = collections.Counter(v[0::2] ).most_common()
v_g_count = collections.Counter(v[1::2]).most_common()

i = 0
v_k = v_k_count[i]
v_g = v_g_count[i]
if v_k[0] == v_g[0]:
    if len(v_k_count) > 1:
        v_k_next = v_k_count[i+1]
    else:
        v_k_next = (0 ,0)
    if len(v_g_count) > 1:
        v_g_next = v_g_count[i+1]
    else:
        v_g_next = (0, 0)
        
    if v_k[1] + v_g_next[1] > v_k_next[1] + v_g[0]:
        v_g = v_g_next
    else:
        v_k = v_k_next
            
re = n - v_k[1] - v_g[1]
print(re)

Submission status: Wrong Answer

Solution code:
import collections

n=int(input())
v=[]
v=input().split()
v1=[]
v2=[]
for i in range(n):
    if i%2==0:
        v1.append(v[i])
    else:
        v2.append(v[i])

V1=collections.Counter(v1)
V2=collections.Counter(v2)
        
v1_num=V1.most_common()[0][0]
v1_cou=V1.most_common()[0][1]
v2_num=V2.most_common()[0][0]
v2_cou=V2.most_common()[0][1]

Ans=10000
if v1_cou==n/2 and v2_cou==n/2:
    if v1_num==v2_num:
        Ans=int(n/2)
    else:
        Ans=0
else:
    Ans=n-v1_cou-v2_cou

print(Ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter


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

A = v[0::2]
c = Counter(A)
a = c.most_common()[0][1]
B = v[1::2]
d = Counter(B)
b = d.most_common()[0][1]

g = c.most_common()[0][0]
h = d.most_common()[0][0]

X = (n / 2) - a
Y = (n / 2) - b

if A == B:
    print(int(n / 2))
elif A != B and a != b:
    Z = X + Y
    print(int(Z))

if g == h:
    if len(c) > len(d):
        for i in range(len(d)):
            H = c.most_common()[i][0] - d.most_common()[i][0]
            if H != 0:
                J = c.most_common()[i][1] - d.most_common()[i][1]
                if J > 0:
                    print(int((n / 2) - c.most_common()[i][1] + Y))
                elif J < 0:
                    print(int((n / 2) - d.most_common()[i][1] + X))
                elif J == 0:
                    break
    elif len(d) >= len(c):
        for i in range(len(c)):
            H = c.most_common()[i][0] - d.most_common()[i][0]
            if H != 0:
                J = c.most_common()[i][1] - d.most_common()[i][1]
                if J > 0:
                    print(int((n / 2) - c.most_common()[i][1] + Y))
                elif J < 0:
                    print(int((n / 2) - d.most_common()[i][1] + X))
                elif J == 0:
                    break

Submission status: Wrong Answer

Solution code:
from collections import Counter


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

A = v[0::2]
c = Counter(A)
a = c.most_common()[0][1]
B = v[1::2]
d = Counter(B)
b = d.most_common()[0][1]

g = c.most_common()[0][0]
h = d.most_common()[0][0]

X = (n / 2) - a
Y = (n / 2) - b

if A == B:
    print(int(n / 2))
elif g == h:
    if a > b:
        f = d.most_common()[1][1]
        print(int((n / 2) - f + X))
    elif a < b:
        e = d.most_common()[1][1]
        print(int((n / 2) - e + Y))
    elif a == b:
        f = d.most_common()[1][1]
        e = d.most_common()[1][1]
        if f > e:
            print(int((n / 2) - f + X))
        elif e > f:
            print(int((n / 2) - e + Y))
if A != B and a != b:
    Z = X + Y
    print(int(Z))

Submission status: Wrong Answer

Solution code:
import sys 
import collections

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

v1 = collections.Counter(v[0::2])
v2 = collections.Counter(v[1::2])

if v1.most_common()[0][0] == v2.most_common()[0][0]:
  if len(v1.most_common()) == 1 and len(v2.most_common()) == 1:
    print(int(n/2))
    exit()
  if v1.most_common()[0][1] >= v2.most_common()[1][1]:
    ans = n - v1.most_common()[0][1] - v2.most_common()[1][1]
    print(ans)
    exit()
  else :
    ans = n - v1.most_common()[1][1] - v2.most_common()[0][1]
    print(ans)
    exit()

ans = n - v1.most_common()[0][1] - v2.most_common()[0][1]
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
v = list(map(int, input().split()))
e = []
o = []
for i in range(n):
    if i % 2 == 0:
        e.append(v[i])
    else:
        o.append(v[i])
e_counter = Counter(e)
o_counter = Counter(o)
e_most = e_counter.most_common()
o_most = o_counter.most_common()
E1 = e_most[0][0]
E2 = E1
if len(e_most) > 1:
    E2 = e_most[1][0]
O1 = o_most[0][0]
O2 = O1
if len(o_most) > 1:
    O2 = o_most[1][0]
e_cnt = n // 2 - e.count(E1)
o_cnt = n // 2 - o.count(O1)
if e_cnt == 0 and o_cnt == 0:
    if e[0] == o[0]:
        print(n // 2)
    else:
        print(0)
else:
    if E1 != O1:
        print(e_cnt + o_cnt)
    else:
        if E1 == O2:
            e_cnt = n // 2 - e.count(E2)
        elif E2 == O1:
            o_cnt = n // 2 - o.count(O2)
        print(e_cnt + o_cnt)

Submission status: Wrong Answer

Solution code:
# N個のスペース区切りの数値を取得
N = int(input())
A = [int(N) for N in input().split()]


# 奇数番目と偶数番目に出てくる数字の頻度順にそれぞれソートして、
odd = []
even = []

for i in range(N):
    if i%2 == 0:
        odd.append(A[i])
    else:
        even.append(A[i])

import collections
c_odd = collections.Counter(odd)
c_even = collections.Counter(even)
#print(c_odd.most_common()[0][0], c_even.most_common()[0][0])



# 最頻な数字が一致してない場合はそれぞれの最頻値以外の合計値、
if c_odd.most_common()[0][0] != c_even.most_common()[0][0] :
    print(len(set(odd))-1 + len(set(even))-1)
    exit()


# 一致してる場合は片方が最頻を諦めた場合の合計値を両パターン求めて小さい方
if c_odd.most_common()[0][0] == c_even.most_common()[0][0] :

    # 偶数と奇数の数列が完全一致のパターンでないかチェック
    if len(c_odd.most_common()) == 1 and len(c_even.most_common()) == 1:
        print(N//2)

    # oddが1種類しかない場合
    elif len(c_odd.most_common()) == 1:
        print(N//2 - c_even.most_common()[1][1])
    # evenが1種類しかない場合
    elif len(c_even.most_common()) == 1:
        print(N//2 - c_odd.most_common()[1][1])
    #両方が2種類以上で構成されている場合
    else:
        ans = N - max(c_odd.most_common()[0][1]+c_even.most_common()[1][1], c_odd.most_common()[1][1]+c_even.most_common()[0][1] )
        print(ans)

Submission status: Wrong Answer

Solution code:
# N個のスペース区切りの数値を取得
N = int(input())
A = [int(N) for N in input().split()]


# 奇数番目と偶数番目に出てくる数字の頻度順にそれぞれソートして、
odd = []
even = []

for i in range(N):
    if i%2 == 0:
        odd.append(A[i])
    else:
        even.append(A[i])

import collections
c_odd = collections.Counter(odd)
c_even = collections.Counter(even)
#print(c_odd.most_common()[0][0], c_even.most_common()[0][0])


# 偶数と奇数の数列が完全一致のパターンでないかチェック
if odd == even:
    print(N//2)
    exit()


# 最頻な数字が一致してない場合はそれぞれの最頻値以外の合計値、
if c_odd.most_common()[0][0] != c_even.most_common()[0][0] :
    print(len(set(odd))-1 + len(set(even))-1)
    exit()


# 一致してる場合は片方が最頻を諦めた場合の合計値を両パターン求めて小さい方
if c_odd.most_common()[0][0] == c_even.most_common()[0][0] :

    # oddが1種類しかない場合
    if len(c_odd.most_common()) == 1:
        print(N//2 - c_even.most_common()[1][1])
    # evenが1種類しかない場合
    elif len(c_even.most_common()) == 1:
        print(N//2 - c_odd.most_common()[1][1])
    #両方が2種類以上で構成されている場合
    else:
        ans = N - max(c_odd.most_common()[0][1]+c_even.most_common()[1][1], c_odd.most_common()[1][1]+c_even.most_common()[0][1] )
        print(ans)
        exit()

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
v = list(map(int, input().split()))
e = []
o = []
for i in range(n):
    if i % 2 == 0:
        e.append(v[i])
    else:
        o.append(v[i])
e_counter = Counter(e)
o_counter = Counter(o)
e_most = e_counter.most_common()
o_most = o_counter.most_common()
E1 = e_most[0][0]
O1 = o_most[0][0]
e_cnt = n // 2 - e.count(E1)
o_cnt = n // 2 - o.count(O1)
if e_cnt == 0 and o_cnt == 0:
    if e[0] == o[0]:
        print(n // 2)
    else:
        print(0)
else:
    print(e_cnt + o_cnt)

Submission status: Wrong Answer

Solution code:
n = int(input())
i = list(map(int, input().split())) 
if(i[0]==i[1] and i[1] ==i[2]):
    print(int(n/2))
    exit()
k = 0
j = 0
for p in range(j,int(n/2)):
    if (i[0] != i[j]):
        k =  k + 1
    j = j + 1
    if(i[1] != i[j]):
        k = k + 1
    j = j + 1
if (k >= n / 2):
    k = n - k
if(k == 0 and i[0] > i[1]):
    k = int(n / 2)
print(k)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
v = list(map(int, input().split()))
evens = []
odds = []
for i in range(0, n, 2):
    evens.append(v[i])
for i in range(1, n, 2):
    odds.append(v[i])
evens_cnts = Counter(evens)
odds_cnts = Counter(odds)
evens_change = sum(evens_cnts.values()) - max(evens_cnts.values())
odds_change = sum(odds_cnts.values()) - max(odds_cnts.values())
if evens_change == 0 and odds_change == 0:
    if evens[0] == odds[0]:
        print(n // 2)
    else:
        print(0)
else:
    print(evens_change + odds_change)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
v = list(map(int, input().split()))
if v.count(v[0]) == n:
    print(n // 2)
    exit()
e = []
o = []
for i in range(n):
    if i % 2 == 0:
        e.append(v[i])
    else:
        o.append(v[i])
e_counter = Counter(e)
o_counter = Counter(o)
E1 = list(e_counter.keys())[0]
if len(list(e_counter.keys())) > 1:
    E2 = list(e_counter.keys())[1]
else:
    E2 = E1
O1 = list(o_counter.keys())[0]
if len(list(o_counter.keys())) > 1:
    O2 = list(o_counter.keys())[1]
else:
    O2 = O1
e_cnt = n // 2 - e.count(E1)
o_cnt = n // 2 - o.count(O1)
if e_cnt == 0 and o_cnt == 0:
    print(0)
else:
    print(e_cnt + o_cnt)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
v = list(map(int, input().split()))
if v.count(v[0]) == n:
    print(n // 2)
    exit()
e = []
o = []
for i in range(n):
    if i % 2 == 0:
        e.append(v[i])
    else:
        o.append(v[i])
e_counter = Counter(e)
o_counter = Counter(o)
E1 = list(e_counter.keys())[0]
if len(list(e_counter.keys())) > 1:
    E2 = list(e_counter.keys())[1]
else:
    E2 = E1
O1 = list(o_counter.keys())[0]
if len(list(o_counter.keys())) > 1:
    O2 = list(o_counter.keys())[1]
else:
    O2 = O1
e_cnt = n // 2 - e.count(E1)
o_cnt = n // 2 - o.count(O1)
print(e_cnt, o_cnt)
if e_cnt == 0 and o_cnt == 0:
    print(0)
else:
    print(e_cnt + o_cnt)

Submission status: Wrong Answer

Solution code:
# N個のスペース区切りの数値を取得
N = int(input())
A = [int(N) for N in input().split()]


# 奇数番目と偶数番目に出てくる数字の頻度順にそれぞれソートして、
odd = []
even = []

for i in range(N):
    if i%2 == 0:
        odd.append(A[i])
    else:
        even.append(A[i])

import collections
c_odd = collections.Counter(odd)
c_even = collections.Counter(even)
#print(c_odd.most_common()[0][0], c_even.most_common()[0][0])


# 偶数と奇数の数列が完全一致のパターンでないかチェック
if odd == even:
    print(N//2)
    exit()


# 最頻な数字が一致してない場合はそれぞれの最頻値以外の合計値、
if c_odd.most_common()[0][0] != c_even.most_common()[0][0] :
    print(len(set(odd))-1 + len(set(even))-1)
    exit()


# 一致してる場合は片方が最頻を諦めた場合の合計値を両パターン求めて小さい方
if c_odd.most_common()[0][0] == c_even.most_common()[0][0] :

    # oddが1種類しかない場合
    if len(c_odd.most_common()) == 1:
        print(N//2 - c_even.most_common()[1][1])
    # evenが1種類しかない場合
    elif len(c_even.most_common()) == 1:
        print(N//2 - c_odd.most_common()[1][1])
    #両方が2種類以上で構成されている場合
    else:

        # 最頻を諦める ＝ 2番めに頻出な数値を採用
        temp_odd_retire = N//2 - c_odd.most_common()[1][1] #個数
        temp_even_retire = N//2 - c_even.most_common()[1][1] #個数
        #print('temps are ', temp_odd_retire, temp_even_retire)

        # oddを諦めたほうが良い場合
        if temp_odd_retire < temp_even_retire:
            print(temp_odd_retire + N//2 - c_even.most_common()[0][1])
        # even()
        else:
            print(temp_even_retire + N//2 - c_odd.most_common()[0][1])
        exit()

print('unexpected!')

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
v = list(map(int, input().split()))
if v.count(v[0]) == n:
    print(n // 2)
    exit()
e = []
o = []
for i in range(n):
    if i % 2 == 0:
        e.append(v[i])
    else:
        o.append(v[i])
e_counter = Counter(e)
o_counter = Counter(o)
E1 = list(e_counter.keys())[0]
if len(list(e_counter.keys())) > 1:
    E2 = list(e_counter.keys())[1]
else:
    E2 = E1
O1 = list(o_counter.keys())[0]
if len(list(o_counter.keys())) > 1:
    O2 = list(o_counter.keys())[1]
else:
    O2 = O1
if E1 != O1:
    print(n // 2 - e.count(E1) + n // 2 - o.count(O1))
else:
    if E1 != O2:
        cnt1 = n // 2 - e.count(E1) + n // 2 - o.count(O2)
    else:
        cnt1 = 10 ** 6
    if E2 != O1:
        cnt2 = n // 2 - e.count(E2) + n // 2 - o.count(O1)
    else:
        cnt2 = 10 ** 6
    print(min(cnt1, cnt2))

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
v = list(map(int,input().split()))
o,e = v[0::2],v[1::2]
o_mode,e_mode = Counter(o).most_common(),Counter(e).most_common()
if o == e:
  print(int(n/2))
elif o_mode[0][0] == e_mode[0][0]:
  if len(o_mode) != 1 and len(e_mode) != 1:
    print(n-max(o_mode[1][1],e_mode[1][1])-o_mode[0][1])
  elif len(o_mode) == 1:
    print(n-o_mode[0][1]-e_mode[1][1])
  elif len(e_mode) == 1:
    print(n-e_mode[0][1]-o_mode[1][1])
else:
  print(n-o_mode[0][1]-e_mode[0][1])

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
v = list(map(int, input().split()))
if v.count(v[0]) == n:
    print(n // 2)
    exit()
e = []
o = []
for i in range(n):
    if i % 2 == 0:
        e.append(v[i])
    else:
        o.append(v[i])
e_counter = Counter(e)
o_counter = Counter(o)
E1 = list(e_counter.keys())[0]
if len(list(e_counter.keys())) > 1:
    E2 = list(e_counter.keys())[1]
else:
    E2 = E1
O1 = list(o_counter.keys())[0]
if len(list(o_counter.keys())) > 1:
    O2 = list(o_counter.keys())[1]
else:
    O2 = O1
# e を E1 で書き換え、o を O2 で書き換える
cnt1 = 0
if E1 == O2:
    cnt1 = 10 ** 6
else:
    for i in e:
        if i != E1:
            cnt1 += 1
    for i in o:
        if i != O2:
            cnt1 += 1
# e を E2 で書き換え、o を O1 で書き換える
cnt2 = 0
if E2 == O1:
    cnt2 = 10 ** 6
else:
    for i in e:
        if i != E2:
            cnt2 += 1
    for i in o:
        if i != O1:
            cnt2 += 1
print(min(cnt1, cnt2))

Submission status: Wrong Answer

Solution code:
# N個のスペース区切りの数値を取得
N = int(input())
A = [int(N) for N in input().split()]


# 奇数番目と偶数番目に出てくる数字の頻度順にそれぞれソートして、
odd = []
even = []

for i in range(N):
    if i%2 == 0:
        odd.append(A[i])
    else:
        even.append(A[i])

import collections
c_odd = collections.Counter(odd)
c_even = collections.Counter(even)
#print(c_odd.most_common()[0][0], c_even.most_common()[0][0])


# 偶数と奇数の数列が完全一致のパターンでないかチェック
if odd == even:
    print(N//2)
    exit()


# 最頻な数字が一致してない場合はそれぞれの最頻値以外の合計値、
if c_odd.most_common()[0][0] != c_even.most_common()[0][0] :
    print(len(set(odd))-1 + len(set(even))-1)
    exit()


# 一致してる場合は片方が最頻を諦めた場合の合計値を両パターン求めて小さい方
if c_odd.most_common()[0][0] == c_even.most_common()[0][0] :
    # 最頻を諦める ＝ 2番めに頻出な数値を採用
    temp_odd_retire = N//2 - c_odd.most_common()[1][1] #個数
    temp_even_retire = N//2 - c_even.most_common()[1][1] #個数
    #print('temps are ', temp_odd_retire, temp_even_retire)

    # oddを諦めたほうが良い場合
    if temp_odd_retire < temp_even_retire:
        print(temp_odd_retire + N//2 - c_even.most_common()[0][1])
    # even()
    else:
        print(temp_even_retire + N//2 - c_odd.most_common()[0][1])
    exit()

print('unexpected!')

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
v = list(map(int, input().split()))
e = []
o = []
for i in range(n):
    if i % 2 == 0:
        e.append(v[i])
    else:
        o.append(v[i])
e_counter = Counter(e)
o_counter = Counter(o)
E1 = list(e_counter.keys())[0]
if len(list(e_counter.keys())) > 1:
    E2 = list(e_counter.keys())[1]
else:
    E2 = E1
O1 = list(o_counter.keys())[0]
if len(list(o_counter.keys())) > 1:
    O2 = list(o_counter.keys())[1]
else:
    O2 = O1
# e を E1 で書き換え、o を O2 で書き換える
cnt1 = 0
for i in e:
    if i != E1:
        cnt1 += 1
for i in o:
    if i != O2:
        cnt1 += 1
# e を E2 で書き換え、o を O1 で書き換える
cnt2 = 0
for i in e:
    if i != E2:
        cnt2 += 1
for i in o:
    if i != O1:
        cnt2 += 1
if E1 == E2 == O1 == O2:
    print(n // 2)
else:
    print(cnt1) if cnt1 <= cnt2 else print(cnt2)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
v = [int(i) for i in input().split()]
e = []
o = []
for i, a in enumerate(v):
    if i % 2:
        o.append(a)
    else:
        e.append(a)
oc = Counter(o)
ec = Counter(e)
h = n//2
if len(oc) == 1:
    print(h)
    exit()
E1 = E2 = 0
for i, (k, v) in enumerate(ec.most_common(2)):
    if i == 0:
        E2 = E1 = k
    else:
        E2 = k
O1 = O2 = 0
for i, (k, v) in enumerate(oc.most_common(2)):
    if i == 0:
        O2 = O1 = k
    else:
        O2 = k
print(min(h-ec[E1] + h - oc[O2], h - ec[E2] + h - oc[O1]))

Submission status: Wrong Answer

Solution code:
n = int(input())
AllList = list(map(int, input().split()))
OddList = [0 for i in range(100001)]
EvenList = [0 for i in range(100001)]
for i in range(n):
    if i % 2 == 0:
        OddList[AllList[i]] += 1
    else:
        EvenList[AllList[i]] += 1

OddMax = max(OddList)
EvenMax = max(EvenList)
OddMaxNum = OddList.index(OddMax)
EvenMaxNum = EvenList.index(EvenMax)

if OddMaxNum == EvenMaxNum:
    if OddMax > EvenMax:
        EvenList[EvenMaxNum] = 0
    else:
        OddList[OddMaxNum] = 0

OddMax = max(OddList)
EvenMax = max(EvenList)

ans = n - OddMax - EvenMax

print(ans)

Submission status: Wrong Answer

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

v_odd=[]
v_even=[]
for i in range(int(n/2)):
	v_odd.append(v[i*2])
	v_even.append(v[i*2+1])

v_odd.sort()
v_even.sort()

v_odd_max_count=0
v_even_max_count=0
v_odd_max_num=0
v_even_max_num=0

a=1
for i in range(int(n/2)-1):
	if v_odd[i]!=v_odd[i+1]:
		if a>v_odd_max_count:
			v_odd_max_count=a
			v_odd_max_num=v_odd[i]
			a=1
	else: a+=1
if a>v_odd_max_count:
	v_odd_max_count=a
	v_odd_max_num=v_odd[i]
a=1
for i in range(int(n/2)-1):
	if v_even[i]!=v_even[i+1]:
		if a>v_even_max_count:
			v_even_max_count=a
			v_even_max_num=v_even[i]
			a=1
	else: a+=1
if a>v_even_max_count:
	v_even_max_count=a
	v_even_max_num=v_even[i]

if v_odd_max_num!=v_even_max_num:
	print(n-v_odd_max_count-v_even_max_count)
else:
	v_odd_sec_count=0
	v_even_sec_count=0
	v_odd=[i for i in v_odd if not i == v_odd_max_num]
	v_even=[i for i in v_even if not i == v_even_max_num]
	if not v_odd: v_odd_sec_count=0
	else:
		a=1
		for i in range(len(v_odd)-1):
			if v_odd[i]!=v_odd[i+1]:
				if a>v_odd_sec_count:
					v_odd_sec_count=a
					a=1
			else: a+=1
		if a>v_odd_sec_count:
			v_odd_sec_count=a
	if not v_even: v_even_sec_count=0
	else:
		a=1
		for i in range(len(v_even)-1):
			if v_even[i]!=v_even[i+1]:
				if a>v_even_sec_count:
					v_even_sec_count=a
					a=1
			else: a+=1
		if a>v_even_sec_count:
			v_even_sec_count=a
	if v_odd_max_count+v_even_sec_count>v_odd_sec_count+v_even_max_count: print(n-v_odd_max_count-v_even_sec_count)
	else: print(n-v_odd_sec_count-v_even_max_count)

Submission status: Wrong Answer

Solution code:
n = int(input())
AllList = list(map(int, input().split()))
OddList = [0 for i in range(100001)]
EvenList = [0 for i in range(100001)]
for i in range(n):
    if i % 2 == 0:
        OddList[AllList[i]] += 1
    else:
        EvenList[AllList[i]] += 1

OddMax = max(OddList)
EvenMax = max(EvenList)
OddMaxNum = OddList.index(OddMax)
EvenMaxNum = EvenList.index(EvenMax)

if OddMaxNum == EvenMaxNum:
    if OddMax >= EvenMax:
        EvenList[EvenMaxNum] = 0
    else:
        OddList[OddMaxNum] = 0

OddMax = max(OddList)
EvenMax = max(EvenList)

ans = n - OddMax - EvenMax

print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

input()
numbers = tuple(map(int, input().split()))

evenNumberToCount = dict()

oddNumberToCount = dict()

for i, n in enumerate(numbers):
    if i % 2 == 0:
        evenNumberToCount[n] = evenNumberToCount.get(n, 0) + 1
    else:
        oddNumberToCount[n] = oddNumberToCount.get(n, 0) + 1

evenCountToNumber = list()
for n, i in evenNumberToCount.items():
    evenCountToNumber.append((i, n))
evenCountToNumber.sort(reverse=True)

oddCountToNumber = list()
for n, i in oddNumberToCount.items():
    oddCountToNumber.append((i, n))
oddCountToNumber.sort(reverse=True)

if oddCountToNumber[0][1] == evenCountToNumber[0][1]:
    if len(numbers) // 2 == oddCountToNumber[0][0] == evenCountToNumber[0][0]:
        print(len(numbers) // 2)
    elif oddCountToNumber[0][0] <= evenCountToNumber[0][0]:
        print(len(numbers) - oddCountToNumber[1][0] - evenCountToNumber[0][0])
    else:
        print(len(numbers) - oddCountToNumber[0][0] - evenCountToNumber[1][0])
else:
    print(len(numbers) - oddCountToNumber[0][0] - evenCountToNumber[0][0])

Submission status: Wrong Answer

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

v_odd=[]
v_even=[]
for i in range(int(n/2)):
	v_odd.append(v[i*2])
	v_even.append(v[i*2+1])

v_odd.sort()
v_even.sort()

v_odd_max_count=0
v_even_max_count=0
v_odd_max_num=0
v_even_max_num=0

a=1
for i in range(int(n/2)-1):
	if v_odd[i]!=v_odd[i+1]:
		if a>v_odd_max_count:
			v_odd_max_count=a
			v_odd_max_num=v_odd[i]
			a=1
	else: a+=1
a=1
for i in range(int(n/2)-1):
	if v_even[i]!=v_even[i+1]:
		if a>v_even_max_count:
			v_even_max_count=a
			v_even_max_num=v_even[i]
			a=1
	else: a+=1

if v_odd_max_num!=v_even_max_num:
	print(n-v_odd_max_count-v_even_max_count)
else:
	v_odd_sec_count=0
	v_even_sec_count=0
	v_odd=[i for i in v_odd if not i == v_odd_max_num]
	v_even=[i for i in v_even if not i == v_even_max_num]
	a=1
	for i in range(len(v_odd)-1):
		if v_odd[i]!=v_odd[i+1]:
			if a>v_odd_sec_count:
				v_odd_sec_count=a
				v_odd_sec_num=v_odd[i]
				a=1
		else: a+=1
	a=1
	for i in range(len(v_even)-1):
		if v_even[i]!=v_even[i+1]:
			if a>v_even_sec_count:
				v_even_sec_count=a
				v_even_sec_num=v_even[i]
				a=1
		else: a+=1
	if v_odd_max_count+v_even_sec_count>v_odd_sec_count+v_even_max_count: print(n-v_odd_max_count-v_even_sec_count)
	else: print(n-v_odd_sec_count-v_even_max_count)

Submission status: Wrong Answer

Solution code:
n = int(input())
L = list(map(int,input().split()))
A = []
B = []
Q = [0,0]
R = [0,0]
S = [0,0]
T = [0,0]
J = 1
K = 1
for i in range(n):
  if (i%2 == 0):
    A.append(L[i])
  else:
    B.append(L[i])
A.sort()
B.sort()
A.append(-1)
B.append(-1)
for j in range(1,len(A)):
  if (A[j-1] == A[j]):
    J += 1
  else:
    if (J > Q[0]):
      Q[1] = Q[0]
      del Q[0]
      Q.insert(0,J)
      R[1] = R[0]
      del R[0]
      R.insert(0,A[j-1])
      j += J
      J = 1
    elif (Q[0] >= J > Q[1]):
      del Q[1]
      Q.append(J)
      del R[1]
      R.append(A[j-1])
      j += J
      J = 1
    else:
      j += J
      J = 1
for k in range(1,len(B)):
  if (B[k-1] == B[k]):
    K += 1
  else:
    if (K > S[0]):
      S[1] = S[0]
      del S[0]
      S.insert(0,K)
      T[1] = T[0]
      del T[0]
      T.insert(0,B[k-1])
      k += K
      K = 1
    elif (S[0] >= J > S[1]):
      del S[1]
      S.append(K)
      del T[1]
      T.append(B[k-1])
      k += K
      K = 1
    else:
      k += K
      K = 1
if (R[0] != T[0]):
  print(n-Q[0]-S[0])
else:
  print(n-max(S[0]+Q[1],S[1]+Q[0]))

Submission status: Wrong Answer

Solution code:
from collections import Counter


def solve(V):
    n = len(V)
    odd = Counter()
    even = Counter()
    total = Counter()
    for i, c in enumerate(V):
        total.update([c])
        if i % 2 == 0:
            even.update([c])
        else:
            odd.update([c])

    total_max = total.most_common()[0]
    if total_max[1] == len(V):
        return len(V) / 2

    even_maxs = even.most_common(2)
    odd_maxs = odd.most_common(2)
    if len(odd_maxs) > 1:
        odd_max, odd_2nd_max = odd_maxs[0], odd_maxs[1]
    else:
        odd_max, odd_2nd_max = odd_maxs[0], None

    if len(even_maxs) > 1:
        even_max, even_2nd_max = even_maxs[0], even_maxs[1]
    else:
        even_max, even_2nd_max = even_maxs[0], None

    ans = 0
    if odd_max[0] != even_max[0]:
        return n - odd_maxs[0][1] - even_maxs[0][1]
    elif odd_2nd_max != None and even_2nd_max == None:
        return n - odd_maxs[1][1] - even_maxs[0][1]
    elif odd_2nd_max == None and even_2nd_max != None:
        return n - odd_maxs[0][1] - even_maxs[1][1]
    else:  # odd_2nd_max != None and even_2nd_max != None:
        return n - max(even_maxs[0][1] + odd_maxs[1][1],
                       even_maxs[1][1] + odd_maxs[0][1])

    for key, count in even.items():
        if key != even_max:
            ans += count
    for key, count in odd.items():
        if key != odd_max:
            ans += count
    return ans


if __name__ == "__main__":
    n = int(input())
    l = input()
    print(solve(l.split(" ")))

Submission status: Wrong Answer

Solution code:
from collections import Counter


def solve(V):
    n = len(V)
    odd = Counter()
    even = Counter()
    total = Counter()
    for i, c in enumerate(V):
        total.update([c])
        if i % 2 == 0:
            even.update([c])
        else:
            odd.update([c])

    total_max = total.most_common()[0]
    if total_max[1] == len(V):
        return len(V) / 2

    even_maxs = even.most_common(2)
    odd_maxs = odd.most_common(2)
    if len(odd_maxs) > 1:
        odd_max, odd_2nd_max = odd_maxs[0], odd_maxs[1]
    else:
        odd_max, odd_2nd_max = odd_maxs[0], None

    if len(even_maxs) > 1:
        even_max, even_2nd_max = even_maxs[0], even_maxs[1]
    else:
        even_max, even_2nd_max = even_maxs[0], None

    ans = 0
    if odd_max[0] != even_max[0]:
        return n - odd_maxs[0][1] - even_maxs[0][1]
    elif odd_2nd_max != None and even_2nd_max == None:
        return n - odd_maxs[1][1] - even_maxs[0][1]
    elif odd_2nd_max == None and even_2nd_max != None:
        return n - odd_maxs[0][1] - even_maxs[1][1]
    else:  # odd_2nd_max != None and even_2nd_max != None:
        return n - max(even_maxs[0][1] + odd_maxs[1][1],
                       even_maxs[1][1] + odd_maxs[0][1])

    for key, count in even.items():
        if key != even_max:
            ans += count
    for key, count in odd.items():
        if key != odd_max:
            ans += count
    return ans

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

"""
まずは偶数番目、奇数番目をカウントする
次に数を調べる
2個目から先を足す
"""

#forループを回さなくても解ける方法があるよ。
#listの要素を取るときに[::2]とすると、２個おきにとってきてくれる
odd = Counter(v[1::2]).most_common()
even = Counter(v[0::2]).most_common()

print(len(odd),len(even))
#most_comon()は、（要素、出現回数）のリストを返してくれる

if odd[0][0] != even[0][0]:
	answer = n - odd[0][1] - even[0][1]

else:
	if len(odd) == 1 and len(even) >1:
		answer = n - even[0][1]
	elif len(even) == 1 and len(odd) >1:
		answer = n - odd[0][1]
	elif len(even) == 1 and len(odd) ==1:
		answer = n - even[0][1]
	else:		
		if odd[0][1] > even[0][1]:
			answer = n - odd[0][1] - even[1][1]
		elif odd[0][1] < even[0][1]:
			answer = n - even[0][1] - odd[1][1]
		else:
			if odd[1][1] > even[1][1]:
				answer = n - even[0][1] - odd[1][1]
			elif odd[1][1] < even[1][1]:
				answer = n - odd[0][1] - even[1][1]
			else:
				answer = n - odd[0][1] - even[1][1]
		
print(answer)

"""
半分waになってしまった...なにがいけなかったんだろう
"""