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


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]:
        odd_max = odd_max[0]
        even_max = even_max[0]
    elif odd_2nd_max != None and even_2nd_max == None:
        even_max = even_max[0]
        odd_max = odd_2nd_max[0]
    elif odd_2nd_max == None and even_2nd_max != None:
        odd_max = odd_max[0]
        even_max = even_2nd_max[0]
    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]:
        odd_max = odd_max[0]
        even_max = even_max[0]
    elif odd_2nd_max != None and even_2nd_max == None:
        even_max = even_max[0]
        odd_max = odd_2nd_max[0]
    elif odd_2nd_max == None and even_2nd_max != None:
        odd_max = odd_max[0]
        even_max = even_2nd_max[0]
    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 = [int(_) for _ in input().split()]
v1 = []
v2 = []
for i in range(n):
    if i % 2 == 0:
        v1.append(v[i])
    else:
        v2.append(v[i])
v_count = Counter(v)
v1_count = Counter(v1)
v2_count = Counter(v2)
# print("v1_count", v1_count)
# print("v2_count", v2_count)
v1_comm = v1_count.most_common(1)
v2_comm = v1_count.most_common(1)
sols = []
# print("v1_comm", v1_comm)
# print("v2_comm", v2_comm)
if len(v_count) == 1:
    print(n//2)
else:
    key1 = v1_comm[0][1]
    if v1_comm[0][0] == v2_comm[0][0]:
        v2_comm = v2_count.most_common(2)
        key2 = v2_comm[0][1]
    else:
        key2 = v2_comm[0][1]
    sols.append(n-key1-key2)
    key1 = v2_comm[0][1]
    if v1_comm[0][0] == v2_comm[0][0]:
        v1_comm = v1_count.most_common(2)
        key2 = v1_comm[0][1]
    else:
        key2 = v1_comm[0][1]
    sols.append(n-key1-key2)
    print(min(sols))

Submission status: Wrong Answer

Solution code:
from collections import Counter


def solve(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]:
        odd_max = odd_max[0]
        even_max = even_max[0]
    elif odd_2nd_max != None and even_2nd_max == None:
        even_max = even_max[0]
        odd_max = odd_2nd_max[0]
    elif odd_2nd_max == None and even_2nd_max != None:
        odd_max = odd_max[0]
        even_max = even_2nd_max[0]
    else:  # odd_2nd_max != None and even_2nd_max != None:
        if odd_max[1] + even_2nd_max[1] >= odd_2nd_max[1] + even_max[1]:
            odd_max = odd_max[0]
            even_max = even_2nd_max[0]
        else:
            odd_max = odd_2nd_max[0]
            even_max = even_max[0]

    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
n = int(input())
v = [int(_) for _ in input().split()]
v1 = []
v2 = []
for i in range(n):
    if i % 2 == 0:
        v1.append(v[i])
    else:
        v2.append(v[i])
v_count = Counter(v)
v1_count = Counter(v1)
v2_count = Counter(v2)
# print("v1_count", v1_count)
# print("v2_count", v2_count)
v1_comm = v1_count.most_common(1)
v2_comm = v1_count.most_common(1)
sols = []
# print("v1_comm", v1_comm)
# print("v2_comm", v2_comm)
if len(v_count) == 1:
    print(n//2)
else:
    if v1_comm[0][1] >= v2_comm[0][1]:
        key1 = v1_comm[0][1]
        if v1_comm[0][0] == v2_comm[0][0]:
            v2_comm = v2_count.most_common(2)
            key2 = v2_comm[0][1]
        else:
            key2 = v2_comm[0][1]
    else:
        key1 = v2_comm[0][1]
        if v1_comm[0][0] == v2_comm[0][0]:
            v1_comm = v1_count.most_common(2)
            key2 = v1_comm[0][1]
        else:
            key2 = v1_comm[0][1]
    print(n-key1-key2)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
v = [int(_) for _ in input().split()]
v1 = []
v2 = []
for i in range(n):
    if i % 2 == 0:
        v1.append(v[i])
    else:
        v2.append(v[i])
v_count = Counter(v)
v1_count = Counter(v1)
v2_count = Counter(v2)
# print("v1_count", v1_count)
# print("v2_count", v2_count)
v1_comm = v1_count.most_common(1)
v2_comm = v1_count.most_common(1)
sols = []
# print("v1_comm", v1_comm)
# print("v2_comm", v2_comm)
if len(v_count) == 1:
    print(n//2)
else:
    if v1_comm[0][1] >= v2_comm[0][1]:
        key1 = v1_comm[0][1]
        if v1_comm[0][0] == v2_comm[0][0]:
            v2_comm = v2_count.most_common(2)
            key2 = v2_comm[0][1]
        else:
            key2 = v2_comm[0][1]

    else:
        key1 = v1_comm[0][1]
        if v1_comm[0][0] == v2_comm[0][0]:
            v2_comm = v2_count.most_common(2)
            key2 = v2_comm[0][1]
        else:
            key2 = v2_comm[0][1]
    print(n-key1-key2)

Submission status: Wrong Answer

Solution code:
import collections
n=int(input())
v=[int(i) for i in input().split()]
a=[]
b=[]
for i in range(1,n,2):
    s=v[i]
    a.append(s)
for j in range(0,n-1,2):
    t=v[j]
    b.append(t)
if a==b:
    print(int(n/2))
else:
    x=list(set(a))
    y=list(set(b))
    my1=collections.Counter(a)
    my2=collections.Counter(b)
    A=my1.most_common()[0][1]
    B=my2.most_common()[0][1]
    C=my1.most_common()[0][0]
    D=my2.most_common()[0][0]
    if len(x)>=2:
        E=my1.most_common()[1][1]
    else:
        E=-1
    if len(y)>=2:
        F=my2.most_common()[1][1]
    else:
        F=-1
    if A==E or B==F:
        print(n-A-B)
    else:
        if C==D:
            print(n/2-A-B)
        else:
            print(n-A-B)

Submission status: Wrong Answer

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

import collections

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

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

v1 = v[::2]
v2 = v[1::2]

c1 = collections.Counter(v1)
c2 = collections.Counter(v2)

sorted_c1 = sorted(c1, reverse=True)
if len(sorted_c1) == 1:
    a1, b1 = sorted_c1[0], sorted_c1[0]
else:
    a1, b1 = sorted_c1[0], sorted_c1[1]

sorted_c2 = sorted(collections.Counter(v2), reverse=True)
if len(c2) == 1:
    a2, b2 = sorted_c2[0], sorted_c2[0]
else:
    a2, b2 = sorted_c2[0], sorted_c2[1]

if a1 == a2:
    ans = min(sum(c1.values()) + sum(c2.values()) - c1[a1] - c2[b2],
              sum(c1.values()) + sum(c2.values()) - c1[b1] - c2[a2])
else:
    ans = sum(c1.values()) + sum(c2.values()) - c1[a1] - c2[a2]
print(ans)

Submission status: Wrong Answer

Solution code:
import collections
 
n = int(input())
v = [int(i) for i in input().split()]
 
v1 = [v[i] for i in range(0,n,2)]
v2 = [v[i] for i in range(1,n,2)]
 
count1 = collections.Counter(v1).most_common(2)
count2 = collections.Counter(v2).most_common(2)

if count1[0][0] != count2[0][0]:
    res = len(v1) - count1[0][0] + len(v2) - count2[0][0]
    print(res)
else:
    if len(count1) == 1:
        print(len(v1))
    else:
        res1 = len(v1) - count1[0][1] + len(v2) - count2[1][1]
        res2 = len(v1) - count1[1][1] + len(v2) - count2[0][1]
        print(min(res1,res2))

Submission status: Wrong Answer

Solution code:
n = int(input())
numberL = list(map(int, input().split()))
 
kisuuSyuL=[]
kisuuKosuL=[]
gusuSyuL=[]
gusuKosuL=[]
 
index=0
while index<n:
    if index==0:
        gusuSyuL.append(numberL[index])
        gusuKosuL.append(1)
    elif index==1:
        kisuuSyuL.append(numberL[index])
        kisuuKosuL.append(1)
    else:
        if index%2==0:
            if numberL[index] in gusuSyuL:
                tarI = gusuSyuL.index(numberL[index])
                gusuKosuL[tarI]+=1
            else:
                gusuSyuL.append(numberL[index])
                gusuKosuL.append(1)
        else:
            if numberL[index] in kisuuSyuL:
                tarI = kisuuSyuL.index(numberL[index])
                kisuuKosuL[tarI]+=1
            else:
                kisuuSyuL.append(numberL[index])
                kisuuKosuL.append(1)
    index+=1
 
 
if len(kisuuSyuL)==1 and len(gusuSyuL)==1:
    if kisuuSyuL[0]==gusuSyuL[0]:
        print(int(n/2))
    else:
        print(0)
else:
    kiIndex = kisuuKosuL.index(max(kisuuKosuL))
    guIndex = gusuKosuL.index(max(gusuKosuL))
    if kisuuSyuL[kiIndex]!=gusuSyuL[guIndex]:
        noC=max(kisuuKosuL)+max(gusuKosuL)
        print(n-noC)
    else:
        if max(kisuuKosuL)< max(gusuKosuL):
            kisuuKosuL.remove(max(kisuuKosuL))
            next = max(kisuuKosuL)
            noC=next+max(gusuKosuL)
            print(n-noC)
        else:
            gusuKosuL.remove(max(gusuKosuL))
            next = max(gusuKosuL)
            noC=next+max(kisuuKosuL)
            print(n-noC)

Submission status: Wrong Answer

Solution code:
def c_zigzag(N, V):
    from collections import defaultdict
    count_seq_even = defaultdict(int)  # 数列の(0-indexedで)偶数番目の要素の出現頻度
    count_seq_odd = defaultdict(int)  # 出現頻度(奇数番目)
    for v in V[0:N - 1:2]:
        count_seq_even[v] += 1
    for v in V[1:N:2]:
        count_seq_odd[v] += 1

    count_seq_even_s = sorted(count_seq_even.items(), key=lambda x: x[1], reverse=True)
    count_seq_odd_s = sorted(count_seq_odd.items(), key=lambda x: x[1], reverse=True)

    # 偶数番目からなる数列と奇数番目からなる数列のそれぞれについて、
    # 基本的には最も出現回数の多い要素に書き換えればいい。
    # ただし、それらの要素が一致する場合は書き換えられないので、
    # 2番目に出現回数の多い要素も(あれば)調べておく。(それより後はいらない)
    seq_even_select = [count_seq_even_s[k][0] for k in range(min(2, len(count_seq_even)))]
    seq_odd_select = [count_seq_odd_s[k][0] for k in range(min(2, len(count_seq_odd)))]

    ans = float('inf')
    # 両方の数列についてそれぞれ1種の要素しかなく、かつそれらが一致する
    # (全要素が等しい値)場合は、奇数番目か偶数番目かどちらかの要素を
    # すべて書き換えなければならない
    if len(seq_even_select) == 1 and len(seq_odd_select) == 1 and seq_even_select[0] == seq_odd_select[0]:
        return N // 2

    for e in seq_even_select:
        for o in seq_odd_select:
            ans = min(ans, N - count_seq_even[e] - count_seq_odd[o])
    return ans

N = int(input())
V = [int(i) for i in input().split()]
print(c_zigzag(N,V))

Submission status: Wrong Answer

Solution code:
a = int(input())

b = list(map(int,input().split()))
d = max(b)
c = [0 for i in range(pow(10,6)+1)]
cc = [0 for i in range(pow(10,6)+1)]
for i in range(len(b)):
    if i % 2 == 0:
        cc[b[i]-1] += 1
    else:
        c[b[i]-1] += 1

one = 0
onee = 0
two = 0
twoo = 0
k = 0
kk = 0
for i in range(len(c)):
    if one <= c[i]:
        onee = one
        one = c[i]
        k = i
    if two <= cc[i]:
        twoo = two
        two = cc[i]
        kk = i

t = max(one+twoo,onee+two)

if k != kk:
    print(a-one-two)
else:
    print(a-t)

Submission status: Wrong Answer

Solution code:
n = int(input())
A = [int(x) for x in input().split()]

from collections import Counter
import operator
def f():
    evn = Counter(A[::2])
    odd = Counter(A[1::2])

    a = sorted(odd.most_common(2), key=operator.itemgetter(1, 0), reverse=True)
    b = sorted(evn.most_common(2), key=operator.itemgetter(1, 0), reverse=True)

    ac = a[0][1]
    bc = b[0][1]
    ret = n - (ac + bc)
    if a[0][0] == b[0][0]:
        bc_2 = b[1][1] if len(b) != 1 else n // 2
        ac_2 = a[1][1] if len(a) != 1 else n // 2
        ret = n - max(ac + bc_2, ac_2 + bc)
    return ret
print(f())

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

"""数字が1種類の場合は半分を書き換える必要が確定"""
if len(set(v)) == 1:
    print(len(v) // 2)
    exit()

"""要素出現数を集計"""
odd_count = Counter(v[1::2])
even_count = Counter(v[::2])

"""一番多く出現する2つの数字を探す"""
max_hit = 0
odd = None
even = None
for odd_val, odd_hit in odd_count.most_common():
    if max_hit > odd_hit:
        break  # もう最大値は更新されないので打ち止め
    for even_val, even_hit in even_count.most_common():
        if max_hit > even_hit:
            break  # もう最大値は更新されないので打ち止め
        if odd_val == even_val:
            continue  # 数字は2種類ないとダメ
        if odd_hit + even_hit > max_hit:
            max_hit = odd_hit + even_hit
            odd = odd_val
            even = even_val

"""一致していない要素が書き換え必要回数"""
print(len(v) - max_hit)

Submission status: Wrong Answer

Solution code:
n = int(input())
A = [int(x) for x in input().split()]

from collections import Counter
import operator
def f():
    evn = Counter(A[::2])
    odd = Counter(A[1::2])

    a = sorted(odd.most_common(2), key=operator.itemgetter(1, 0), reverse=True)
    b = sorted(evn.most_common(2), key=operator.itemgetter(1, 0), reverse=True)

    ac = a[0][1]
    bc = b[0][1]
    ret = n - ac + bc
    if a[0][0] == b[0][0]:
        bc_2 = b[1][1] if len(b) != 1 else n // 2
        ac_2 = a[1][1] if len(a) != 1 else n // 2
        ret = n - max(ac + bc_2, ac_2 + bc)
    return ret
print(f())

Submission status: Wrong Answer

Solution code:
n = int(input())
A = [int(x) for x in input().split()]

from collections import Counter
import operator
def f():
    evn = Counter(A[::2])
    odd = Counter(A[1::2])

    a = sorted(odd.most_common(2), key=operator.itemgetter(1, 0), reverse=True)
    b = sorted(evn.most_common(2), key=operator.itemgetter(1, 0), reverse=True)

    ac = a[0][1]
    bc = b[0][1]
    ret = n - ac + bc
    if a[0][0] == b[0][0]:
        bc_2 = b[1][1] if len(b) != 1 else 0
        ac_2 = a[1][1] if len(a) != 1 else 0
        ret = n - max(ac + bc_2, ac_2 + bc)
    return ret
print(f())

Submission status: Wrong Answer

Solution code:
a = int(input())

b = list(map(int,input().split()))
d = max(b)
c = [0 for i in range(pow(10,5)+1)]
cc = [0 for i in range(pow(10,5)+1)]
for i in range(len(b)):
    if i % 2 == 0:
        cc[b[i]-1] += 1
    else:
        c[b[i]-1] += 1

one = c[0]
onee = 0
two = cc[0]
twoo = 0
k = 0
kk = 0
for i in range(len(c)):
    if one <= c[i]:
        onee = one
        one = c[i]
        k = i
    if two <= cc[i]:
        twoo = two
        two = cc[i]
        kk = i

t = max(one+twoo,onee+two)

if k != kk:
    print(a-one-two)
else:
    print(a-t)

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 oc.most_common(1)[0][0] != ec.most_common(1)[0][0]:
    a = h - oc.most_common(1)[0][1]
    b = h - ec.most_common(1)[0][1]
    print(a+b)
else:
    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:
a = int(input())

b = list(map(int,input().split()))
d = max(b)
c = [0 for i in range(pow(10,5)+1)]
cc = [0 for i in range(pow(10,5)+1)]
for i in range(len(b)):
    if i % 2 == 0:
        cc[b[i]-1] += 1
    else:
        c[b[i]-1] += 1

one = 0
onee = 0
two = 0
twoo = 0
k = 0
kk = 0
for i in range(len(c)):
    if one <= c[i]:
        onee = one
        one = c[i]
        k = i
    if two <= cc[i]:
        twoo = two
        two = cc[i]
        kk = i

t = max(one+twoo,onee+two)

if k != kk:
    print(a-one-two)
else:
    print(a-t)

Submission status: Wrong Answer

Solution code:
a = int(input())

b = list(map(int,input().split()))
d = max(b)
c = [0 for i in range(pow(10,5)+10)]
cc = [0 for i in range(pow(10,5)+10)]
for i in range(len(b)):
    if i % 2 == 0:
        c[b[i]-1] += 1
    else:
        cc[b[i]-1] += 1

one = 0
onee = 0
two = 0
twoo = 0
k = 0
kk = 0
for i in range(len(c)):
    if one <= c[i]:
        onee = one
        one = c[i]
        k = i
    if two <= cc[i]:
        twoo = two
        two = cc[i]
        kk = i

t = max(one+twoo,onee+two)

if k != kk:
    print(a-one-two)
else:
    print(a-t)

Submission status: Wrong Answer

Solution code:
a = int(input())

b = list(map(int,input().split()))
d = max(b)
c = [0 for i in range(pow(10,5)+1)]
cc = [0 for i in range(pow(10,5)+1)]
for i in range(len(b)):
    if i % 2 == 0:
        c[b[i]-1] += 1
    else:
        cc[b[i]-1] += 1

one = 0
onee = 0
two = 0
twoo = 0
k = 0
kk = 0
for i in range(len(c)):
    if one <= c[i]:
        onee = one
        one = c[i]
        k = i
    if two <= cc[i]:
        twoo = two
        two = cc[i]
        kk = i

t = max(one+twoo,onee+two)

if k != kk:
    print(a-one-two)
else:
    print(a-t)

Submission status: Wrong Answer

Solution code:
import collections
n=int(input())
v=[int(i) for i in input().split()]
a=[]
b=[]
for i in range(1,n,2):
    s=v[i]
    a.append(s)
for j in range(0,n-1,2):
    t=v[j]
    b.append(t)
if a==b:
    print(int(n/2))
else:
    mycounter1=collections.Counter(a)
    mycounter2=collections.Counter(b)
    A=mycounter1.most_common()[0][1]
    B=mycounter2.most_common()[0][1]
    C=int(A)
    D=int(B)
    if mycounter1.most_common()[0][0]==mycounter2.most_common()[0][0]:
        print(n/2-C-D)
    else:
        print(n-C-D)

Submission status: Wrong Answer

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

"""
9
1 1 1 1 2 2 2 4 
1 1 1 1 3 3 4 4
"""

#V = [1, 1, 1, 1, 1, 1, 1, 1, 2, 3, 2, 3, 2, 4, 4, 4]

v1 = V[0::2]
v2 = V[1::2]

f1 = Counter(v1).most_common(2)
f2 = Counter(v2).most_common(2)

ans = 0

if len(set(v1)) == len(set(v2)) == 1:
    if v1 == v2:
        ans = min(len(v1), len(v2))
else:
    if f1[0][0] != f2[0][0]:
        ans = (len(v1) - f1[0][1]) + (len(v2) - f2[0][1])
    else:
        if f1[1][1] > f2[1][1]:
            ans = (len(v1) - f1[0][1]) + (len(v2) - f2[1][1])
        else:
            ans = (len(v1) - f1[1][1]) + (len(v2) - f2[0][1])

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
v = list(map(int,input().split()))
o = v[0::2]
e = v[1::2]
o_mode = Counter(o).most_common()
e_mode = Counter(e).most_common()
if o == e:
  print(int(n/2))
elif o_mode[0][0] == e_mode[0][0]:
  print(n-max(o_mode[1][1],e_mode[1][1])-o_mode[0][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 = [int(i) for i in input().split()]

"""数字が1種類の場合は半分を書き換える必要が確定"""
if len(set(v)) == 1:
    print(int(len(v) / 2))
    exit()

"""要素出現数を集計"""
odd_nums = [v[i] for i in range(0, len(v), 2)]
odd_count = Counter(odd_nums)
even_nums = [v[i] for i in range(1, len(v), 2)]
even_count = Counter(even_nums)

"""一番多く出現する2つの数字を探す"""
max_hit = 0
odd = None
even = None
for odd_val, odd_hit in odd_count.most_common():
    if max_hit > odd_hit:
        break  # もう最大値は更新されないので打ち止め
    for even_val, even_hit in even_count.most_common():
        if max_hit > even_hit:
            break  # もう最大値は更新されないので打ち止め
        if odd_val == even_val:
            continue  # 数字は2種類ないとダメ
        if odd_hit + even_hit > max_hit:
            max_hit = odd_hit + even_hit
            odd = odd_val
            even = even_val

"""一致していない要素が書き換え必要回数"""
if v[-2] == odd:
    print(len(v) - max_hit)
else:
    # v[n-1] は書き換えなくていい
    print(len(v) - max_hit - 1)

Submission status: Wrong Answer

Solution code:
n = int(input())
lst = list(map(int, input().split()))
ma = {}
ma[lst[0]] = 1
mb = {}
mb[lst[1]] = 1
for i in range(2, n, 2):
    lst[i] in ma
    if lst[i] in ma:
        ma[lst[i]] += 1
    else:
        ma[lst[i]] = 1
    lst[i+1] in mb
    if lst[i+1] in mb:
        mb[lst[i+1]] += 1
    else:
        mb[lst[i+1]] = 1
if max(ma.values()) == max(mb.values()):
    ma2 = ma
    mb2 = mb
    ma2[max(ma, key=ma.get)] = 0
    mb2[max(mb, key=mb.get)] = 0
    d1 = n - max(ma.values()) - max(mb2.values())
    d2 = n - max(ma2.values()) - max(mb.values())
    d = min(d1, d2)
else:
    d = n - max(ma.values()) - max(mb.values())
print(d)

Submission status: Wrong Answer

Solution code:
a = int(input())

b = list(map(int,input().split()))
d = max(b)
c = [0 for i in range(pow(10,5)+1)]
cc = [0 for i in range(pow(10,5)+1)]
for i in range(a):
    if i % 2 == 0:
        c[b[i]-1] += 1
    else:
        cc[b[i]-1] += 1

one = 0
onee = 0
two = 0
twoo = 0
k = 0
kk = 0
for i in range(len(c)):
    if one <= c[i]:
        onee = one
        one = c[i]
        k = i
    if two <= cc[i]:
        twoo = two
        two = cc[i]
        kk = i

t = max(one+twoo,onee+two)

if k != kk:
    print(a-(one+two))
else:
    print(a-t)

Submission status: Wrong Answer

Solution code:
def isCorrect(n):
    l = [int(x) for x in list(str(n))]
    prev = l.pop(0)

    for num in l:
        if num != prev:
            return False
        prev = num
    return True

if __name__ == '__main__':
    n = int(input())
    nums = list(map(int, input().split()))
    s1 = set()
    s2 = set()

    for i in range(0, n, 2):
       s1.add(nums[i])

    for i in range(1, n, 2):
       s2.add(nums[i])

    s3 = s1.union(s2)

    if len(s3) == 1:
        print(int(n / 2))
    else:
        print(len(s1)+len(s2)-2)

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())

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

array_0 = collections.Counter(array[::2]).most_common()
array_1 = collections.Counter(array[1::2]).most_common()


if array_0[0][0] == array_1[0][0]:
    if len(array_0) * len(array_1) == 1:
        print(n // 2)
        exit()
    elif array_0[0][1] > array_1[0][1]:
        print(len(array) - array_1[1][1] - array_0[0][1])
        exit()
    elif array_0[0][1] < array_1[0][1]:
        print(len(array) - array_1[0][1] - array_0[1][1])
        exit()
    else:
        print(max(len(array) - array_1[0][1] - array_0[1][1], len(array) - array_1[1][1] - array_0[0][1]))
        exit()
print(len(array) - array_1[0][1] - array_0[0][1])

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())

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

array_0 = collections.Counter(array[::2]).most_common()
array_1 = collections.Counter(array[1::2]).most_common()


if array_0[0][0] == array_1[0][0]:
    if len(array_0) * len(array_1) == 1:
        print(n // 2)
        exit()
    elif array_0[0][1] > array_1[0][1]:
        print(len(array) - array_1[1][1] - array_0[0][1])
        exit()
    elif array_0[0][1] < array_1[0][1]:
        print(len(array) - array_1[0][1] - array_0[1][1])
        exit()
    else:
        max(len(array) - array_1[0][1] - array_0[1][1], len(array) - array_1[1][1] - array_0[0][1])
        exit()
print(len(array) - array_1[0][1] - array_0[0][1])

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
v = list(map(int, input().split()))
gu = v[::2]
ki = v[1::2]
ans = 0
k,g = False,False

if v.count(v[0]) == n:#全部同じ
    ans += n // 2
else:
    kic = Counter(ki)
    guc = Counter(gu)
    k1 = kic.most_common(2)
    g1 = guc.most_common(2)
    if k1[0][0] == g1[0][0]:
        if k1[1][1] < g1[1][1]:
            k = True
        elif k1[1][1] > g1[1][1]:
            g = True

    kic = list(kic.values())
    guc = list(guc.values())
    kic.sort(reverse = True)
    guc.sort(reverse = True)
    if len(kic) != 1:
        if k:
            ans += kic[0]
            ans += sum(kic[2::])
        else:
            ans += sum(kic[1::]) 
    if len(guc) != 1:
        if g:
            ans += guc[0]
            ans += sum(guc[2::])
        else:
            ans += sum(guc[1::])

print(ans)

Submission status: Wrong Answer

Solution code:
if __name__ == '__main__' :
    n = int(input())
    x = list(input().split())
    a = {}
    b = {}
    ai = 0
    bi = 0
    for i,t in enumerate(x):
        if i % 2 == 0:
            ai += 1
            if t in a:
                a[t] += 1
            else:
                a[t] = 1
        else:
            bi += 1
            if t in b:
                b[t] += 1
            else:
                b[t] = 1

    a_kv = max(a.items(), key=lambda x: x[1])
    b_kv = max(b.items(), key=lambda x: x[1])

    if a_kv[0] == b_kv[0]:
        if a_kv[1] > b_kv[1]:
            if bi - b_kv[1] == 0:
                print(bi)
            else:
                b.pop(b_kv[0])
                b_kv = max(b.items(), key=lambda x: x[1])
                print(ai-a_kv[1]+bi-b_kv[1])
        else:
            if ai - a_kv[1] == 0:
                print(ai)
            else:
                a.pop(a_kv[0])
                a_kv = max(a.items(), key=lambda x: x[1])
                print(ai-a_kv[1]+bi-b_kv[1])
    else:
        print(ai-a_kv[1]+bi-b_kv[1])

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
v_tmp = input().split()
v = [int(_) for _ in v_tmp]
v_count = Counter(v_tmp)
v2_tmp = []
for i in range(0, n-1,  2):
    v2_tmp.append((v[i], v[i+1]))
v2_count = Counter(v2_tmp)
# print(v_count)
if len(v_count) == 1:
    print(n//2)
elif len(v_count) == n:
    print(n-2)
else:
    val_mx = max(list(v2_count.values()))
    v2_list = v2_count.most_common(1)[0]
    sum = 0
    # print(v2_list[0][0])
    # print(v2_list[0][1])
    for i in range(n):
        if i % 2 == 0 and v[i] == v2_list[0][0]:
            sum += 1
        elif i % 2 == 1 and v[i] == v2_list[0][1]:
            sum += 1
    print(n-val_mx*2-(sum-val_mx*2))

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())

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

array_0 = collections.Counter(array[::2]).most_common()
array_1 = collections.Counter(array[1::2]).most_common()


if array_0[0][0] == array_1[0][0]:
    if len(array_0) * len(array_1) == 1:
        print(n // 2)
        exit()
    elif array_0[0][1] > array_1[0][1]:
        print(len(array) - array_1[1][1] - array_0[0][1])
        exit()
    elif array_0[0][1] < array_1[0][1]:
        print(len(array) - array_1[0][1] - array_0[1][1])
        exit()
    else:
        max(len(array) - array_1[0][1] - array_0[1][1], len(array) - array_1[1][1] - array_0[0][1])

print(len(array) - array_1[0][1] - array_0[0][1])

Submission status: Wrong Answer

Solution code:
import collections as cl

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

vg=vlist[0::2]
vk=vlist[1::2]

vgcnt=cl.Counter(vg)
vkcnt=cl.Counter(vk)

vgmax=max(vgcnt,key=vgcnt.get)
vkmax=max(vkcnt,key=vkcnt.get)

if vgmax==vkmax:
    if vgcnt[vgmax]<vkcnt[vkmax]:
        vgcnt.pop(vgmax)
        if len(vgcnt)!=0:
            vgmax=max(vgcnt)
        else:
            vgmax+=1
    else:
        vkcnt.pop(vkmax)
        if len(vkcnt)!=0:
            vkmax=max(vkcnt)
        else:
            vkmax+=1

ans=0
for i in range(len(vg)):
    if vg[i]!=vgmax:
        ans+=1
for i in range(len(vk)):
    if vk[i]!=vkmax:
        ans+=1

print(ans)

Submission status: Wrong Answer

Solution code:
import collections

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

v1 = [v[i] for i in range(0,n,2)]
v2 = [v[i] for i in range(1,n,2)]

count1 = collections.Counter(v1)
count2 = collections.Counter(v2)

if len(count1) == 1 and len(count2) == 1:
    if v1 == v2:
        print(len(v1))
    else:
        print(0)
        
else:
    if max(count1.values()) == max(count2.values()):
        res1 = len(v1) - max(count1.values())
        count2.pop(max(count2,key=count2.get))
        res1 = res1 + len(v2) - max(count2.values())

        res2 = len(v2) - max(count2.values())
        count1.pop(max(count1,key=count1.get))
        res2 = res2 + len(v1) - max(count1.values())
        print(min(res1,res2))
    else:
        res = len(v1) - max(count1.values()) + len(v2) - max(count2.values())
        print(res)