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:
n = int(input())
a = list(map(int,input().split()))
cnt = 0
if len(set(a)) == 1:
    print(n//2)
    exit()
for i in range(2,n,2):
    if a[i] != a[0]:
        cnt += 1
for i in range(3,n,2):
    if a[i] != a[1]:
        cnt += 1
print(cnt)

Submission status: Wrong Answer

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

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

A = [0] * 100010
B = [0] * 100010

for i in range(int(n/2)):
    A[a[i]] += 1
    B[b[i]] += 1

sorted(A)
sorted(B)

if A.index(max(A)) == B.index(max(B)):
    if max(A) > max (B):
        BB = sorted(B)
        print(len(b) - BB[-2] + len(a) - max(A))
    else:
        AA = sorted(A)
        print(len(a) - AA[-2] + len(b) - max(B))
else:
    print(n - max(A) - max(B))

Submission status: Wrong Answer

Solution code:
# vim: set fileencoding=utf-8:
from collections import Counter


def main():
    n = input()
    v = [int(ele) for ele in raw_input().split()]

    # aとbのカウンターを見て、要素の少ない方の出現数をカウントしていく？
    a = Counter(v[::2])
    b = Counter(v[1::2])

    A = []
    B = []

    # a, b双方のすべての要素に対して、それ以外の和を計算しておく
    for num, ct in a.items():
        A.append([num, ct, sum(a.values()) - ct])

    for num, ct in b.items():
        B.append([num, ct, sum(a.values()) - ct])

    sorted(A)
    sorted(B)

    cal_ans(A, B)


def cal_ans(A, B):
    flag = 0
    ans = 0
    # どっちも最大派閥のやつが同じ数だったらどうすんの？
    for a, b in zip(A, B):
        if flag == "a":
            ans += a[2]
            break

        if flag == "b":
            ans += b[2]
            break

        if a[0] != b[0]:
            """
            幸せなパターン。 
            """
            ans += a[2] + b[2]
            break
        else:
            """
            不幸せなパターン
            """
            # この場合は、変換に必要なコストを比較する。同じだったら次のにいく...で、いいのか？
            if a[2] == b[2]:
                continue
            elif a[2] > b[2]:
                # bのほうが変換コストが小さいので、bを選択。
                ans += b[2]
                flag = "a"

            elif a[2] < b[2]:
                ans += a[2]
                flag = "b"

    if ans == 0 and A[0][0] == B[0][0]:
        ans = min(A[0][1], B[0][1])

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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


def main():
    from collections import Counter

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

    if len(set(v)) == 1:
        print(half)
        exit()
    else:
        even = Counter(v[::2]).most_common(1)[0][0]
        odd = Counter(v[1::2]).most_common(1)[0][0]
        ans1 = 0

        for i in range(n):
            if i % 2 == 0:
                if v[i] != even:
                    ans1 += 1
            else:
                if v[i] != odd:
                    ans1 += 1

        print(ans1)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from collections import Counter

if __name__ == '__main__':
    n = int(input())
    vs = list(map(int, input().split()))

    even = vs[::2]
    odd = vs[1::2]

    def solve(even, odd):
        ce = Counter(even)
        co = Counter(odd)
        
        emode = ce.most_common()
        omode = co.most_common()
        
        result = 0
        if emode[0][0] != omode[0][0]:
            for i in range(1, len(emode)):
                result += emode[i][1]
            for i in range(1, len(omode)):
                result += omode[i][1]
            
            return result
        
        else:
            if emode[0][1] > omode[0][1]:
                for i in range(1, len(even)):
                    result += emode[i][1]
                    
                if len(omode) == 1:
                    result += len(odd)
                else:
                    for i in range(len(omode)):
                        if i == 1:
                            continue
                        else:
                            result += omode[i][1]
                            
            else:
                for i in range(1, len(omode)):
                    result += omode[i][1]
                    
                if len(emode) == 1:
                    result += len(even)
                else:
                    for i in range(len(emode)):
                        if i == 1:
                            continue
                        else:
                            result += emode[i][1]
            return result
        
    print(solve(even, odd))

Submission status: Wrong Answer

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

def main():
    import collections

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

    vs_even = []
    vs_odd = []
    while True:
        if len(vs) == 0:
            break
        vs_even.append(vs.pop(0))
        vs_odd.append(vs.pop(0))

    if vs_even == vs_odd:
        # 1種類の数からなる数列のとき
        print(len(vs_even))
        exit()

    most_evens = collections.Counter(vs_even).most_common(2)
    most_odds = collections.Counter(vs_odd).most_common(2)

    len_vs_even = len(vs_even)
    if most_evens[0][0] == most_odds[0][0]:
        # 変換したら、1種類の数になってしまう
        # ex.) vs = [1 2 1 2 1 2 2 2 2 2 2 2 2 2]
        # ex.) vs = [1 1 1 1 1 1 3 2 3 2]
        # ので、2番目に大きい数字で変換する
        if most_evens[0][1] > most_odds[0][1]:
            ans = 0
            ans += len_vs_even - most_odds[1][1]
            ans += len_vs_even - most_evens[0][1]
            print(ans)
            exit()
        elif most_evens[0][1] == most_odds[0][1]:
            if most_evens[1][1] >= most_odds[1][1]:
                ans = 0
                ans += len_vs_even - most_evens[1][1]
                ans += len_vs_even - most_odds[0][1]
                print(ans)
                exit()
            else:
                ans = 0
                ans += len_vs_even - most_odds[1][1]
                ans += len_vs_even - most_evens[0][1]
                print(ans)
                exit()
        else:
            ans = 0
            ans += len_vs_even - most_evens[1][1]
            ans += len_vs_even - most_odds[0][1]
            print(ans)
            exit()
    ans = 0
    ans += len_vs_even - most_evens[0][1]
    ans += len_vs_even - most_odds[0][1]
    print(ans)



if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n=int(input())
N=list(map(int,input().split()))
even=[]
odd=[]
for i in range(len(N)):
    if i%2==0:
        even.append(N[i])
    if i%2==1:
        odd.append(N[i])
import collections
c = collections.Counter(even)
x=c.most_common()[0][0]
o=even.count(x)
d= collections.Counter(odd)
y=d.most_common()[0][0]
p=odd.count(y)
s=len(even)-even.count(x)
t=len(odd)-odd.count(y)
if x!=y and o==len(even) and p==len(odd):
    print(0)
elif x==y and o==len(even) and p==len(odd):
    print(n/2)
elif x==y:
    if o>p:
        y=d.most_common()[1][0]
        s=len(even)-even.count(x)
        t=len(odd)-odd.count(y)
        print(s+t)
    else:
        x=c.most_common()[1][0]
        s=len(even)-even.count(x)
        t=len(odd)-odd.count(y)
        print(s+t)
else:
    print(s+t)

Submission status: Wrong Answer

Solution code:
#Bad_Beast
n=int(input())
a=list(map(int,input().split()))
if len(set(a))==1:
    print(int(n/2))
else:    
    i=0
    oc=[0]*100005
    for i in range(n):
        oc[a[i]]+=1
    m=0    
    cur1=0
    cur2=0
    for i in range(100005):
        if oc[i]>m:
            m=oc[i]
            cur1=i
    oc[cur1]=0
    m=0
    for i in range(100005):
        if oc[i]>m:
            m=oc[i]
            cur2=i
    ind1=100005
    ind2=100005
    for i in range(n):
        if a[i]==cur1:
            if i<ind1:
                ind1=i
            
        elif a[i]==cur2:
            if i<ind2   : 
                ind2=i
    #print(ind1,ind2)
    if ind1>ind2:
        total=0
        i=0
        while i<n:
            if a[i]!=cur2:
                total+=1
            if a[i+1]!=cur1:
                total+=1
            i+=2    
        print(total)
    elif ind1<ind2:
        total=0
        i=0
        while i<n:
            
            if a[i]!=cur1:
                total+=1
            if a[i+1]!=cur2:
                total+=1
            i+=2 
        print(total)

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:
    res = len(v1) - max(count1.values()) + len(v2) - max(count2.values())
    print(res)

Submission status: Wrong Answer

Solution code:
import collections
m=int(input())
n=list(map(int,input().split()))
kisuu=[]
guusuu=[]
answer=m/2
for i in range(m):
    if i%2==1:
        guusuu.append(n[i])
    else:
        kisuu.append(n[i])
a=collections.Counter(guusuu)
b=collections.Counter(kisuu)
try:
    if a.most_common()[0][0]==a.most_common()[0][0]:

        if a.most_common()[1][0]>a.most_common()[0][0]:
            answer=answer-a.most_common()[1][1]+answer-b.most_common()[0][1]
        else:
            answer=answer-b.most_common()[1][1]+answer-a.most_common()[0][1]
    else:
        answer=a.most_common()[0][1]+answer-b.most_common()[0][1]
except:
    answer=a.most_common()[0][1]+answer-b.most_common()[0][1]
print(int(answer))

Submission status: Wrong Answer

Solution code:
import collections

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()

array_0_v = array_0[0][0]
array_1_v = array_1[0][0]

if array_0_v == array_1_v:
    if len(array_0) == 1:
        print(n // 2)
        exit()
    elif array_0[0][1] > array_1[0][1]:
        array_1_v = array_1[1][0]
    else:
        array_0_v = array_0[1][0]

count = 0
for i in range(n // 2):
    count += array[i * 2] != array_0_v
    count += array[i * 2 + 1] != array_1_v

print(count)

Submission status: Wrong Answer

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

kisu = [str(v) for i,v in enumerate(V) if i % 2 == 1]
gusu = [str(v) for i,v in enumerate(V) if i % 2 == 0]

from collections import Counter

kisu_c = Counter(kisu).most_common()
gusu_c = Counter(gusu).most_common()

ans = 0


if len(kisu_c) == 1 and len(gusu_c) == 1:
    if kisu_c[0][0] == gusu_c[0][0]:
        print(kisu_c[0][1])
    else:
        print(0)
    exit()
elif len(kisu_c) == 1:
    gusu_c.pop(1)

    for i in gusu_c:
        ans += i[1]
    print(ans)
    exit()
elif len(gusu_c) == 1:
    kisu_c.pop(1)

    for i in kisu_c:
        ans += i[1]
    print(ans)
    exit()



if kisu_c[0][0] == gusu_c[0][0]:
    if kisu_c[0][1] < gusu_c[0][1]:
        gusu_c.pop(0)
        kisu_c.pop(1)
    elif kisu_c[0][1] > gusu_c[0][1]:
        gusu_c.pop(1)
        kisu_c.pop(0)
    else:
        if kisu_c[1][1] < gusu_c[1][1]:
            kisu_c.pop(1)
            gusu_c.pop(0)
        else:
            kisu_c.pop(0)
            gusu_c.pop(1)

else:
    kisu_c.pop(0)
    gusu_c.pop(0)


for i in kisu_c:
    ans += i[1]
for i in gusu_c:
    ans += i[1]

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
cnt = 0
if len(set(a)) == 1:
    print(n//2)
    exit()
for i in range(2,n-1,2):
    if a[i] != a[0]:
        cnt += 1
for i in range(3,n,2):
    if a[i] != a[1]:
        cnt += 1
print(cnt)

Submission status: Wrong Answer

Solution code:
from collections import Counter
N = int(input())
A = list(map(int, input().split()))
c1 = Counter(A[::2])
c2 = Counter(A[1::2])
c1m = max(c1.items(), key=lambda x:x[1])
c2m = max(c2.items(), key=lambda x:x[1])
if len(set(A)) == 1:
    print(N // 2)
    exit()
c1c2 = max(c for k,c in c2.items() if c1m[0]!=k)
c2c1 = max(c for k,c in c1.items() if c2m[0]!=k)
print(max(N - c1m[1] - c1c2, N - c2m[1] - c2c1))

Submission status: Wrong Answer

Solution code:
from collections import Counter
N = int(input())
n = N // 2

index = 0
g_inputs = []
k_inputs = []

for i in input().split():
    if index % 2 == 0:
        g_inputs.append(int(i))
        index += 1
    else:
        k_inputs.append(int(i))
        index += 1

g = Counter(g_inputs)
k = Counter(k_inputs)

g_max = max([(v,k) for k,v in g.items()])[1] 
k_max = max([(v,k) for k,v in k.items()])[1]

if g_max == k_max:
    if g[g_max] < k[k_max]:
        del g[g_max]
        g_max = max([(v,k) for k,v in g.items()])[1]
        print(N - g[g_max] - k[k_max])
    if g[g_max] > k[k_max]:
        del k[k_max]
        k_max = max([(v,k) for k,v in k.items()])[1]
        print(N - g[g_max] - k[k_max])
    else:
        del g[g_max]
        del k[k_max]
        if len(g) == 0 and len(k) == 0:
            print(n)
        if len(g) != 0 and len(k) == 0:
            print(n - g_max - max([(v,k) for k,v in g.items()])[1])
        if len(g) == 0 and len(k) != 0:
            print(n - k_max - max([(v,k) for k,v in k.items()])[1])
        if len(g) != 0 and len(k) != 0:
            g_temp = g_max
            k_temp = k_max
            g_max = max([(v,k) for k,v in g.items()])[1]
            k_max = max([(v,k) for k,v in k.items()])[1]
            if g[g_max] < k[k_max]:
                print(N - g[g_max] - k[k_max])
            elif g[g_max] < k[k_max]:
                print(N - g[g_max] - k[k_max])
            else:
                print(N - g[g_max] - k[k_max])
else:
    print(N - g[g_max] - k[k_max])

Submission status: Wrong Answer

Solution code:
def cal(n,v):
    k=n//2
    even=range(0,2*k,2)
    odd=range(1,2*k+1,2)

    el=[]
    for i in even:
        el.append(v[i])
    ol=[]
    for i in odd:
        ol.append(v[i])

    d={}
    for i in el:
        if((i in d) is False):
            d[i]=0
        else:
            d[i]+=1

    f={}
    for i in ol:
        if((i in f) is False):
            f[i]=0
        else:
            f[i]+=1

    while(True):
        e = max(d, key=d.get)
        o = max(f, key=f.get)
        if(e==o):
            if(d[e]>f[e]):
                del f[e]
            elif(d[e]<f[e]):
                del d[e]
            else:
                return print(k)
        else:
            break

    sum=0
    for i in el:
        if(i!=e):
            sum+=1
    for i in ol:
        if(i!=o):
            sum+=1
    return print(sum)

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

Submission status: Wrong Answer

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

Vdic = [{}, {}]
# 0: even 1: odd
for i in range(len(V_list)):
    v = V_list[i]

    tmp = (i + 1) % 2
    Vdic[tmp][v] = Vdic[tmp].get(v, 0) + 1

even = sorted(Vdic[0].values())
odd = sorted(Vdic[1].values())

ans_even = [(-1, 0)]
ans_odd = [(-2, 0)]
if(len(even) == 1):
    t = max(Vdic[0], key=Vdic[0].get)
    ans_even.append((t, even[0]))
else:
    n1 = even[-1]
    n2 = even[-2]

    f1 = True
    f2 = True
    f3 = True
    for k, v in Vdic[0].items():
        if(v == n1 and f1 and f2):
            if(f1 is False):
                f2 = False
            f1 = False
            ans_even.append((k, v))
        if(v == n2 and f3):
            f3 = False
            ans_even.append((k, v))

if(len(odd) == 1):
    t = max(Vdic[1], key=Vdic[1].get)
    ans_odd.append((t, odd[0]))
else:
    n1 = odd[-1]
    n2 = odd[-2]

    f1 = True
    f2 = True
    f3 = True
    for k, v in Vdic[1].items():
        if(v == n1 and f1 and f2):
            if(f1 is False):
                f2 = False
            f1 = False
            ans_odd.append((k, v))
        if(v == n2 and f3):
            f3 = False
            ans_odd.append((k, v))


# print(ans_even, ans_odd)

ans = []
for ke, ve in ans_even:
    for ko, vo in ans_odd:
        if(ke != ko):
            ans.append(n - ve - vo)

print(min(ans))

Submission status: Wrong Answer

Solution code:
# coding:utf-8

n = int(input())
a = input().split()

even = dict()
odd = dict()

for i, c in enumerate(a):
    if i%2 == 0:
        if c in even:
            even[c] += 1
        else:
            even[c] = 1
    else:
        if c in odd:
            odd[c] += 1
        else:
            odd[c] = 1

even_key = [k for k, v in even.items() if v == max(even.values())][0]
odd_key = [k for k, v in odd.items() if v == max(odd.values())][0]

if(even_key == odd_key):
    alpha = int(n/2)
else:
    alpha = 0


kotae = n - max(even.values()) - max(odd.values()) + alpha
print(kotae)

Submission status: Wrong Answer

Solution code:
import numpy as np

n = int(input())
v_ = map(int, input().split())
v = []
for val in v_:
	v.append(val)
v = np.array(v)

u = np.unique(v)
if len(u) < 2:
	print(2)
elif len(u) == 2:
	print(0)
else:
	u_hat = sorted(u)
	v_c = []

	print(u_hat)
	for a in u_hat:
		if sum(v==a) != 0:
			v_c.append(sum(v==a))
	print(sum(sorted(v_c, reverse=True)[2:]))

Submission status: Wrong Answer

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

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

from collections import defaultdict
s = defaultdict(int)
t = defaultdict(int)

for i in range(n):
	if i%2 == 0:
		s[i] += v[i]
	else:
		t[i] += v[i]

import collections

ss = collections.Counter(s.values())
tt = collections.Counter(t.values())
#print(ss,tt)

sss = list(ss.values())
ttt = list(tt.values())
#print(sss,ttt)

ssss = list(ss)
tttt = list(tt)

answer = sum(sss) + sum(ttt) - sss[0] - ttt[0]

if ssss == tttt:
	if sss[0]<= ttt[0]:
		answer = answer + sss[0]
	else:
		answer = answer + ttt[0]

print(answer)

Submission status: Wrong Answer

Solution code:
n=int(input())
v=list(map(int,input().split()))
 
k=n//2
even=range(0,2*k,2)
odd=range(1,2*k+1,2)
 
el=[]
for i in even:
    el.append(v[i])
ol=[]
for i in odd:
    ol.append(v[i])
 
d={}
for i in el:
    if((i in d)is False ):
        d[i]=0
    else:
        d[i]+=1
e = max(d, key=d.get)
 
d={}
for i in ol:
    if((i in d)is False ):
        d[i]=0
    else:
        d[i]+=1
o = max(d, key=d.get)
 
if(el==ol):
    print(k)
else:
    sum=0
    for i in el:
        if(i!=e):
            sum+=1
    for i in ol:
        if(i!=o):
            sum+=1
    print(sum)

Submission status: Wrong Answer

Solution code:
n = int(input())
array = [int(x) for x in input().split()]
tmp_dict = {}
tmp_dict2 = {}
tmp_array = array[::2]
tmp_array2 = array[1::2]
for i in tmp_array:
    if i in tmp_dict.keys():
        tmp_dict[i] += 1
    else:
        tmp_dict[i] = 1
for i in tmp_array2:
    if i in tmp_dict2.keys():
        tmp_dict2[i] += 1
    else:
        tmp_dict2[i] = 1

sorted_dict = sorted(tmp_dict.items(), key=lambda x: x[1], reverse=True)
sorted_dict2 = sorted(tmp_dict2.items(), key=lambda x: x[1], reverse=True)
tmp = sorted_dict[0][0]
tmp2 = sorted_dict2[0][0]

if sorted_dict == sorted_dict2:
    print(len(array)//2)
    exit()

if tmp == tmp2:
    if len(sorted_dict) == 1:
        tmp2 = sorted_dict2[1][0]
    else:
        tmp = sorted_dict[1][0]

res = 0
for i in tmp_array:
    if i != tmp:
       res += 1
for i in tmp_array2:
    if i != tmp2:
       res += 1
print(res)

Submission status: Wrong Answer

Solution code:
from collections import Counter

n = int(input())
v = list(map(int, input().split()))
odd_list = v[1::2]  # 偶数番目
even_list = v[::2]  # 奇数番目

odd_list_len = len(odd_list)
even_list_len = len(even_list)

odd_mode = Counter(odd_list).most_common(1)
even_mode = Counter(even_list).most_common(1)

ans = 0
ans += odd_list_len - odd_mode[0][1]
if odd_mode[0] != even_mode[0]:
    ans += even_list_len - even_mode[0][1]
else:
    if len(Counter(even_list).most_common(2)) == 2:
        ans += even_list_len - Counter(even_list).most_common(2)[1][1]
    else:
        ans += even_list_len
print(ans)

Submission status: Wrong Answer

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

def w2(x):
    return x[::2], x[1:][::2]

def isnnn(x):
    return len(set(x))==2 and len(set(x[::2]))==1 and len(set(x[1:][::2]))==1

def sa(v):
    vd = {}
    for i in v:
        if i in vd:
            vd[i] += 1
        else:
            vd[i] = 1
    max_k = max(vd, key=vd.get)
    return max_k, len(v) - vd[max_k], 

if isnnn(vs):
    print(0)
elif len(set(vs))==1:
    print(int(len(vs)/2))
else:
    v1, v2 = w2(vs)
    v1_k, sa1 = sa(v1)
    v2_k, sa2 = sa(v2)
    if v1_k != v2_k:
        print(sa1+sa2)
    elif sa1 > sa2:
        v1_s = list(filter(lambda x: x != v1_k, v1))
        v1_k2, sa12 = sa(v1_s)
        print(sa12+sa2+v1.count(v1_k))
    else:
        v2_s = list(filter(lambda x: x != v2_k, v2))
        v2_k2, sa22 = sa(v2_s)
        print(sa1+sa22+v2.count(v2_k))

Submission status: Wrong Answer

Solution code:
import collections

n = int(input())

al = [int(l) for l in input().split()]

a = al[::2]
b = al[1::2]

ac = collections.Counter(a).most_common()
bc = collections.Counter(b).most_common()

if ac[0][0] != bc[0][0]:
    print(n-ac[0][1]-bc[0][1])
else:
    if ac[0][1] >= bc[0][1]:
        if len(bc) <= 1:
            print(n-ac[0][1])
        else:
            print(n-ac[0][1]-bc[1][1])
    else:
        if len(ac) <= 1:
            print(n-bc[0][1])
        else:
            print(n-ac[1][1]-bc[0][1])

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
v = input().split()
v_int = [int(i) for i in v]
v_odd = []
v_even = []
for i in range(int(n/2)):
  v_even.append(v_int[i*2])
  v_odd.append(v_int[i*2+1])
c_odd = collections.Counter(v_odd)
c_even = collections.Counter(v_even)
max_odd = 0
second_odd = 0
max_key_odd = 0
for key in c_odd:
  if max_odd < c_odd[key]:
    second_odd = max_odd
    max_odd = c_odd[key]
    max_key_odd = key
  elif second_odd < c_odd[key]:
    second_odd = c_odd[key]
    
max_even = 0
second_even = 0
max_key_even = 0
for key in c_even:
  if max_even < c_even[key]:
    second_even = max_even
    max_even = c_even[key]
    max_key_even = key
  elif second_even < c_even[key]:
    second_even = c_even[key]
    
if max_key_even != max_key_odd:
  print(int(n)- max_even - max_odd)
else:
  if max_even > max_odd:
    if max_even == second_even:
      print(int(n) - max_even - max_odd)
    else:
      print(int(n) - max_even - second_odd)
  else:
    if max_odd == second_odd:
      print(int(n) - max_odd - max_even)
    else:
      print(int(n) - max_odd - second_even)

Submission status: Wrong Answer

Solution code:
import collections
N=int(input())
A=list(map(int,input().split()))

A1=[]
A2=[]
for i in range(len(A)):
    if i%2==0:
        A1.append(A[i])
    else:
        A2.append(A[i])
        
B1=collections.Counter(A1)
B2=collections.Counter(A2)

if N==2:
    print(0)

elif B1.most_common(2)[0][1]==B2.most_common(2)[0][1] and B1.most_common(2)[0][1]==int(N/2):
    print(int(N/2))
else:
    
    
    if B1.most_common(1)==B2.most_common(1):
        if B1.most_common(2)[1][1]>=B2.most_common(2)[1][1]:
            ans=N-B1.most_common(2)[1][1]-B2.most_common(2)[0][1]
        else:
            ans=N-B2.most_common(2)[1][1]-B1.most_common(2)[0][1]
    elif B1.most_common(2)[0][0]==B2.most_common(2)[0][0]:
        if B1.most_common(2)[0][1]>=B2.most_common(2)[0][1]:
            ans=N-B1.most_common(2)[0][1]-B2.most_common(2)[1][1]
        else:
            ans=N-B2.most_common(2)[0][1]-B1.most_common(2)[1][1]
    else:
        ans=N-B1.most_common(2)[0][1]-B2.most_common(2)[0][1]
    print(ans)

Submission status: Wrong Answer

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

a = []
b = []

a_dic = {}
b_dic = {}

for i in range(n):
    if i % 2 == 0:
        if v[i] in a_dic.keys():
            a_dic[v[i]] += 1
        else:
            a_dic[v[i]] = 1
    else:
        if v[i] in b_dic.keys():
            b_dic[v[i]] += 1
        else:
            b_dic[v[i]] = 1

max_a = 0
max_b = 0

for val in a_dic.values():
    if val > max_a:
        max_a = val

for val in b_dic.values():
    if val > max_b:
        max_b = val

ans = (int(n / 2) - max_a) + (int(n / 2) - max_b)

if len(a_dic) == 1 and len(b_dic) == 1:
    print(int(n / 2))
else:
    print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
cnt = 0
if len(set(a)) == 1:
    print(n//2)
    exit()
for i in range(1,n-1,2):
    if a[i] != a[0]:
        cnt += 1
for i in range(2,n,2):
    if a[i] != a[1]:
        cnt += 1
print(cnt)

Submission status: Wrong Answer

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

guM1=0
guC1=0
guM2=0
guC2=0

kiM1=0
kiC1=0
kiM2=0
kiC2=0

beforeG=0
countG=0
beforeK=0
countK=0
index=0
while index<len(numberL):
    if index==0:
        beforeG=numberL[index]
        countG+=1
    elif index==1:
        beforeK=numberL[index]
        countK+=1
    else:
        if index%2==0:
            if beforeG==numberL[index]:
                countG+=1
            else:
                if guC1 < countG:
                    guC2=guC1
                    guM2=guM1
                    guC1=countG
                    guM1=beforeG
                    beforeG=numberL[index]
                    countG=1
                elif guC2 < countG:
                    guC2=countG
                    guM2=beforeG
                    beforeG=numberL[index]
                    countG=1
        else:
            if beforeK==numberL[index]:
                countK+=1
            else:
                if kiC1 < countK:
                    kiC2=kiC1
                    kiM2=kiM1
                    kiC1=countK
                    kiM1=beforeK
                    beforeK=numberL[index]
                    countK=1
                elif kiC2 < countK:
                    kiC2=countK
                    kiM2=beforeK
                    beforeK=numberL[index]
                    countK=1
    index+=1

if guC1 < countG:
    guC2=guC1
    guM2=guM1
    guC1=countG
    guM1=beforeG
elif guC2 < countG:
    guC2=countG
    guM2=beforeG

if kiC1 < countK:
    kiC2=kiC1
    kiM2=kiM1
    kiC1=countK
    kiM1=beforeK                   
elif kiC2 < countK:
    kiC2=countK
    kiM2=beforeK
    

if guM1 != kiM1:
    print(n-guC1-kiC1)
else:
    if (guC1-guC2) < (kiC1-kiC2):
        print(n-guC2-kiC1)
    else:
        print(n-kiC2-guC1)

Submission status: Wrong Answer

Solution code:
import collections

n = int(input())
vs = [int(i) for i in input().split()]
evens = []
odds = []
for i,num in enumerate(vs):
    if i % 2 == 0:
        evens.append(num)
    elif i % 2 == 1:
        odds.append(num)

def plana():
    if (len(set(vs)) == 2) and (len(set(evens)) == 1) and (len(set(odds)) == 1):
        return 0
    elif (len(set(vs)) == 1):
        return len(evens)
    ec = collections.Counter(evens)
    oc = collections.Counter(odds)

    # check
    if ec.most_common()[0][0]==oc.most_common()[0][0]:
        if ec.most_common()[0][1] >= oc.most_common()[0][1]:
            count = 0
            count += (len(evens) - ec.most_common()[0][1])
            count += (len(odds) - oc.most_common()[1][1])
            return count
        elif ec.most_common()[0][1] < oc.most_common()[0][1]:
            count = 0
            count += (len(evens) - ec.most_common()[1][1])
            count += (len(odds) - oc.most_common()[0][1])
            return count

    count = 0
    count += (len(evens) - ec.most_common()[0][1])
    count += (len(odds) - oc.most_common()[0][1])
    return count

# if len(set(vs)) == 1:
#     print(int(len(vs)/2))
# elif (len(set(evens)) == 1) and (len(set(odds)) == 1):
#     print(0)
# else:
print(int(plana()))

Submission status: Wrong Answer

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

N = int(input())
A = list(map(int, input().split(' ')))

up = A[0::2]
down = A[1::2]
upc = collections.Counter(up)
doc = collections.Counter(down)

umc = upc.most_common(1)
dmc = doc.most_common(1)
u = len(A)/2 - umc[0][1]
d = len(A)/2 - dmc[0][1]

if (u == 0 and d == 0) and umc[0][0] == dmc[0][0]:
	print(int(len(A)/2))
	exit()

print(int(u+d))

Submission status: Wrong Answer

Solution code:

import collections

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


def map_all(li):
    return all([e == li[0] for e in li[1:]]) if li else False


evel = collections.Counter()
evel2 = []
odd = collections.Counter()
odd2 = []
for index, v in enumerate(V):
    if index % 2 == 0:
        evel[v] += 1
        evel2.append(v)
    else:
        odd[v] += 1
        odd2.append(v)

if map_all(evel2) and map_all(odd2):
    print(int(n / 2))
else:
    el = evel.most_common(100)
    ol = odd.most_common(100)
    max_val = 0
    for index_e, num_e in el:
        for index_o, num_o in ol:
            if index_e != index_o:
                max_val = max(max_val, num_e + num_o)
    ans = n - max_val
    print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

v_1 = []
v_2 = []

k = int(n / 2)

for i in range(k):
    s = (v[2*i])
    t = (v[2*i+1])
    v_1.append(s)
    v_2.append(t)

a = Counter(v_1)
a_1 = a.most_common()
a_2 = a_1[0][1]
b = Counter(v_2)
b_1 = b.most_common()
b_2 = b_1[0][1]
c = Counter(v)
c_1 = c.most_common()
c_2 = c_1[0][1]


if c_2 == n:
    print(k)
elif a_1[0][0] == b_1[0][0]:
    if a_2 > b_2:
        print(n - a_2 - b_1[1][1])
    else:
        print(n - a_1[1][1] - b_2)
else:
    print(n - a_2 - b_2)

Submission status: Wrong Answer

Solution code:
import collections


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


def hoge(i):
    try:
        if evencount.most_common()[i][0] == oddcount.most_common()[i][0]:

            if evencount.most_common()[i][1] > oddcount.most_common()[i][1]:
                ans = n - evencount.most_common()[i][1] - oddcount.most_common()[i][1]
            elif evencount.most_common()[i][1] < oddcount.most_common()[i][1]:
                ans = n - evencount.most_common()[i][1] - oddcount.most_common()[i][1]
            else:
                if len(evencount) == 1:
                    ans = int(n/2)
                else:
                    hoge(i+1)

        else: 
            ans = n - evencount.most_common()[i][1] - oddcount.most_common()[i][1]
    except IndexError:    
        ans = n - evencount.most_common()[0][1] - oddcount.most_common()[1][1]
        print(ans)
    

hoge(0)