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())
a=list(map(int,input().split()))

x=[]
y=[]

for i in range(n):
    if i%2==0:
        x.append(a[i])
    else:
        y.append(a[i])

cx=Counter(x)
cy=Counter(y)

ax=cx.most_common(2)
ay=cy.most_common(2)

if len(ax)==1:
    ax=ax+ax

if len(ay)==1:
    ay=ay+ay
   

if not ax[0][0]==ay[0][0]:
    print(n-ax[0][1]-ay[0][1])
else:
    if ax[0][1]==n//2:
        if ay[0][1]==n//2:
            print(n-ay[1][1])
        else:
            print(n//2-ay[1][1])
    elif ay[0][1]==n//2:
        print(n//2-ax[1][1])
    else:
        if ax[0][1]<ay[0][1]:
            print(n-ax[1][1]-ay[0][1])
        else:   
            print(n-ax[0][1]-ay[1][1])

Submission status: Wrong Answer

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

result = 0

for i in range(n - 2):
    if v[i] != v[i + 2]:
        result = result + 1

for i in range(0, n - 1, 2):
    if v[i] == v[i + 1]:
        result = result + 1

print(result)

Submission status: Wrong Answer

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

kisuuSyuL=[]
kisuuKosuL=[]
gusuSyuL=[]
gusuKosuL=[]

index=0
beforeG=""
countG=0
beforeK=""
countK=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:
                gusuSyuL.append(beforeG)
                gusuKosuL.append(countG)
                beforeG= numberL[index]
                countG=1
        else:
            if beforeK==numberL[index]:
                countK+=1
            else:
                kisuuSyuL.append(beforeK)
                kisuuKosuL.append(countK)
                beforeK=numberL[index]
                countK=1
    index+=1
gusuSyuL.append(beforeG)
gusuKosuL.append(countG)
kisuuSyuL.append(beforeK)
kisuuKosuL.append(countK)

if len(kisuuSyuL)==1 and len(gusuSyuL)==1:
    if kisuuSyuL[0]==gusuSyuL[0]:
        print(int(n/2))
    else:
        print(0)
else:
    sum=0
    index2=0
    kisuuKosuL.sort()
    while index2<len(kisuuSyuL)-1:
        sum+=kisuuKosuL[index2]
        index2+=1
    index3=0
    gusuKosuL.sort()
    while index3< len(gusuSyuL)-1:
        sum+=gusuKosuL[index3]
        index3+=1
    print(sum)

Submission status: Wrong Answer

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

sv1 = set(v1)
sv2 = set(v2)
if len(sv1) == 1 and len(sv2) == 1 :
    if sv1 != sv2:
        print(0)
    else:
        print(n//2)
else:
    dic1 = { i : 0 for i in sv1}
    dic2 = { i : 0 for i in sv2}
    for i in v1:
        dic1[i] = dic1[i] + 1
    for i in v2:
        dic2[i] = dic2[i] + 1
    #print(dic1, dic2)
    dic1 = sorted(dic1.items(), key=lambda x: -x[1])
    dic2 = sorted(dic2.items(), key=lambda x: -x[1])
    if dic1[0][0] != dic2[0][0]:
        print(n-(dic1[0][1]+dic2[0][0]))
    else:
        if len(dic1)==1:
            print(n- (dic1[0][1]+dic2[1][1]))
        elif len(dic2)==1:
            print(n- (dic1[1][1]+dic2[0][1]))
        elif dic1[1][1]+dic2[0][1] >= dic1[0][1]+dic2[1][1] :
            print(n- (dic1[1][1]+dic2[0][1]))
        else :
            print(n- (dic1[0][1]+dic2[1][1]))

Submission status: Wrong Answer

Solution code:
import collections
n=input()
N=list(map(int,input().split(" ")))
list_odd=N[::2]
list_even=N[1::2]
c_odd = collections.Counter(list_odd)
c_even = collections.Counter(list_even)
most_odd=c_odd.most_common()[0][1]
most_even=c_even.most_common()[0][1]
print(len(list_even)+len(list_odd)-most_even-most_odd)

Submission status: Wrong Answer

Solution code:
n = int(input())
v = list(map(int,input().split()))
v2 = []
for i in range(0, n - 1, 1):
    v2.append(abs(v[i] - v[i + 1]))
count = 0
for i in range(0, len(v2) - 1, 1):
    if v2[0] != v2[i + 1]:
        count += 1
if count > len(v2) - count:
    ans = len(v2) - count
else:
    ans = count
print(ans)

Submission status: Wrong Answer

Solution code:
ai = lambda: list(map(int,input().split()))
ai_ = lambda: [int(x)-1 for x in input().split()]

n = int(input())
a = ai()
if all(i == a[0] for i in a):
    print(n//2)
    exit()

a1 = a[::2]
a2 = a[1::2]

from collections import Counter
c1 = Counter(a1)
c2 = Counter(a2)
m1 = sorted(list(c1.values()))[0]
m2 = sorted(list(c2.values()))[0]
print(n-m1-m2)

Submission status: Wrong Answer

Solution code:
def c_zigzag(N, V):
    from collections import defaultdict
    count_seq_even = defaultdict(int)
    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

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

    seq_even_select = count_seq_even[0][0]
    seq_odd_select = -1
    for k, v in count_seq_odd:
        if k != seq_even_select:
            seq_odd_select = k
            break

    # print(seq_even_select, seq_odd_select)
    ans = 0
    for i in range(0, N - 1, 2):
        if V[i] != seq_even_select:
            V[i] = seq_even_select
            ans += 1
    for i in range(1, N, 2):
        if V[i] != seq_odd_select:
            V[i] = seq_odd_select
            ans += 1
    return ans

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

Submission status: Wrong Answer

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

import sys

n = int(raw_input())
v = raw_input().split(" ")

dict = {}
for i in v:
    if i in dict.keys():
        dict[i] += 1
    else:
        dict[i] = 1

#全て同じ数のときは半分を変えればいい
if len(dict) == 1:
    print n / 2
    sys.exit()
else:
    print max(dict.values()) - min(dict.values())
    sys.exit()

Submission status: Wrong Answer

Solution code:
a=int(input())
b=input()
c=b.split(" ")
map(int,c)
c.sort()
d=c[:a//2]
e=c[a//2:]
min1=0
min2=0

temp1=len(d)
temp2=len(e)
temp3=len(set(d))
temp4=len(set(e))


if temp3==1 and set(d)!=set(e):
    min1=0
elif temp1>temp3:
    min1=temp3
else:
    min1=temp1


if temp4==1 and set(d)!=set(e):
    min2=0
elif temp2>temp4:
    min2=temp4
else:
    min2=temp2

print(min2+min1)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n=int(input())
a=list(map(int, input().split()))
b=[a[i] for i in range(n) if i%2==0]
c=[a[i] for i in range(n) if i%2==1]
b2=Counter(b)
c2=Counter(c)
b3=b2.most_common(3)
c3=c2.most_common(3)
ans=n
for i in b3:
    for j in c3:
        if i[0]!=j[0]:
            ans=min(ans,n-i[1]-j[1])
print(ans)

Submission status: Wrong Answer

Solution code:
import collections

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

a = []
b = []
a_f = 0
b_f = 0
a_s = 0
b_s = 0
for i in range(N):
    if i%2 == 0:
        a.append(l[i])
    else:
        b.append(l[i])
        
c_a = collections.Counter(a)
c_b = collections.Counter(b)

a_f = c_a.most_common()[0]
b_f = c_b.most_common()[0]

if a_f[0] != b_f[0]:
    print(N - a_f[1] - b_f[1])

elif len(set(a)) == 1 and len(set(b)) == 1:
    print(int(N/2))
elif len(set(a)) == 1:
    print(int(N/2 - c_b.most_common()[1][1]))
elif len(set(b)) == 1:
    print(int(N/2 - c_a.most_common()[1][1]))
elif max(a_f[1], b_f[1]) == a_f[1]:
    print(int(N - a_f[1] - c_a.most_common()[1][1]))
else:
    print(int(N - b_f[1] - c_b.most_common()[1][1]))

Submission status: Wrong Answer

Solution code:
n = int(input())

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

v1 = {}

v2 = {}

for i in range(n//2):
    if  v[2 *i -1] in v1.keys():
        v1[v[2 * i -1]] += 1
    else:
        v1[v[2 * i - 1]] = 1

    if v[2 * i] in v2.keys():
        v2[v[2 * i]] += 1
    else:
        v2[v[2 * i]] = 1


v1 = sorted(v1.items())
v2 = sorted(v2.items())
v1.append((None,0))
v2.append((None,0))
ans = 0
if v1[0][0] == v2[0][0]:
    ans = min(v1[0][1]+v2[1][1] , v1[1][1] + v2[0][1])
else:
    ans = v1[0][1] + v2[0][1]

print(n - ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
v = list(map(int,input().split()))
l = list(range(n))
odd = [v[i] for i in l if i%2 == 0]
even = [v[i] for i in l if i%2 == 1]

oddm = sorted({i: odd.count(i) for i in set(odd)}.items(), key=lambda x: x[1], reverse=True)
evenm = sorted({i: even.count(i) for i in set(even)}.items(), key=lambda x: x[1], reverse=True)
numodd = oddm[0][1]
numeven = evenm[0][1]
if oddm[0][0] == evenm[0][0]:
    a = min(oddm[0][1],evenm[0][1])
else:
    a = len(odd)-numodd+len(even)-numeven
print(a)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
import sys
n=int(input().strip())
v=list(map(int, input().strip().split()))
counterO=defaultdict(int)
counterE=defaultdict(int)
for i in v[::2]:
    counterO[i]+=1
for i in v[1::2]:
    counterE[i]+=1
cOO=sorted(counterO.items(),key=lambda x:x[1],reverse=True)
cEE=sorted(counterE.items(),key=lambda x:x[1],reverse=True)
iO,iE=0,0
if cOO[iO][0]!=cEE[iE][0]:
    ans=sum(x[1] for x in cOO[:iO]+cOO[iO+1:])+sum(x[1] for x in cEE[:iE]+cEE[iE+1:])
else:
    vO,vE=sum(x[1] for x in cOO[:iO]+cOO[iO+1:]),sum(x[1] for x in cEE[:iE]+cEE[iE+1:])
    if vO>=vE:
        iE+=1
        ans=sum(x[1] for x in cOO[:iO]+cOO[iO+1:])+sum(x[1] for x in cEE[:iE]+cEE[iE+1:])
    else:
        iO+=1
        ans=sum(x[1] for x in cOO[:iO]+cOO[iO+1:])+sum(x[1] for x in cEE[:iE]+cEE[iE+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]:
        print(min(ai,bi))
    else:
        print(ai-a_kv[1]+bi-b_kv[1])

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())
vlist = list(map(int, input().split(" ")))

head = vlist[::2]
foll = vlist[1::2]

import collections
h_ = collections.Counter(head).most_common()[0][0]
f_ = collections.Counter(foll).most_common()[0][0]

if f_ == h_:
    f_ = -1.1

count = 0
for i in range(len(vlist)):
    if i % 2 == 0 and vlist[i] != h_:
        count += 1
    if i % 2 == 1 and vlist[i] != f_:
        count += 1

print(count)

Submission status: Wrong Answer

Solution code:
import sys
from collections import deque
import copy

def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline


def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    N = int(input_raw[0])
    input_raw = read_func().strip().split()
    A_dic = {}
    B_dic = {}
    for i in range(0, N):
        if i % 2 == 0:
            if input_raw[i] in A_dic:
                A_dic[input_raw[i]] += 1
            else:
                A_dic[input_raw[i]] = 1
        else:
            if input_raw[i] in B_dic:
                B_dic[input_raw[i]] += 1
            else:
                B_dic[input_raw[i]] = 1

    max_A_num = 0
    max_B_num = 0
    max_A = 0
    max_B = 0
    for A in A_dic:
        if max_A_num < A_dic[A]:
            max_A_num = A_dic[A]
            max_A = A
    for B in B_dic:
        if max_B_num < B_dic[B]:
            max_B_num = B_dic[B]
            max_B = B

    max_A_num2 = 0
    max_B_num2 = 0
    if max_A == max_B:

            for A in A_dic:
                if A != max_A:
                    max_A_num2 = max(max_A_num2, A_dic[A])

            for B in B_dic:
                if B != max_B:
                    max_B_num2 = max(max_B_num2, B_dic[B])

            if max_A_num2 > max_B_num2:
                max_A_num = max_A_num2
            else:
                max_B_num = max_B_num2

    print N - max_A_num - max_B_num

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))
    b = sorted(evn.most_common(2), key=operator.itemgetter(1, 0))
    
    if a[0][1] > b[0][1]:
        ac = (n // 2) - a[0][1]
        if a[0][0] == b[0][0]:
            bc = n // 2 - (n // 2 - b[1][1] if len(b) != 1 else 0)
            return ac + bc
        else:
            return ac + (n // 2) - b[0][1]
    else:
        bc = (n // 2) - b[0][1]
        if a[0][0] == b[0][0]:
            ac = n // 2 - (n // 2 - a[1][1] if len(a) != 1 else 0)
            return ac + bc
        else:
            return bc + (n // 2) - a[0][1]

print(f())

Submission status: Wrong Answer

Solution code:
n = int(input())
v = list(map(int,input().split()))
v2 = []
for i in range(0, n - 1, 1):
    v2.append(abs(v[i] - v[i + 1]))
count = 0
for i in range(0, len(v2) - 1, 1):
    if v2[i] != v2[i + 1]:
        count += 1
if count > len(v2) - count:
    ans = len(v2) - count
else:
    ans = count
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N=int(input())
li = input().split()

a = 0
b = 0
c = 0
while a < N / 2:
    if li[a] != li[a + 2]:
        b += 1
    a += 1

while c  < N:
    if li[c] == li[c + 1]:
        b += 1
    c += 2

print(b)

Submission status: Wrong Answer

Solution code:
# cook your dish here
import bisect
n=int(input())
v = list(map(int,input().split()))
x = []
y = []

for i in range(n):
    if i %2 ==0:
        x.append(v[i])
    else:
        y.append(v[i])
a = []
b = []
k = 0
l = 0
x.sort()
y.sort()

while k < len(x) :
    aa = bisect.bisect_right(x,x[k])
    a.append(aa-k)
    k = aa
while l < len(y) :
    
    bb = bisect.bisect_right(y,y[l])
    b.append(bb-l)
    l = bb

c = sorted(a)
d = sorted(b)
#print(x,y)
#print(a,b)
#print(c,d)
#print(a.index(c[-1]))
aaa = [i for i, xx in enumerate(a) if xx == c[-1]]
bbb = [i for i, xx in enumerate(b) if xx == d[-1]]
if len(aaa)>= 2 or len(bbb)>= 2:
    print(n-c[-1]-d[-1])
else:
    jkl = a.index(c[-1])
    jkll= b.index(d[-1])
    if x[jkl] == y[jkll]:
        ans = 100000000000000
        if len(d) >= 2:
            ans = n-c[-1]-d[-2]
        if len(c) >= 2:
            ans = min(ans,n-c[-2]-d[-1])
        if ans == 100000000000000:
            ans = n//2
        print(ans)
    else:
        print(n-c[-1]-d[-1])

Submission status: Wrong Answer

Solution code:
# coding: utf-8
import collections

n = int(input())
v = [int(s) for s in input().strip().split(" ")]
el = [0] * (n // 2)
ol = [0] * (n // 2)
ans = 0

for i in range(n):
    if i % 2 == 0:
        el[i//2] = v[i]
    else:
        ol[(i-1)//2] = v[i]
        
ec = collections.Counter(el)
oc = collections.Counter(ol)
e_num = ec.most_common()[0][0]
e_count = ec.most_common()[0][1]
o_num = oc.most_common()[0][0]
o_count = oc.most_common()[0][1]

if len(set(v)) == 1:
    ans = n //2
elif e_num != o_num:
    ans = n - e_count - o_count
elif e_count >= o_count:
    o_num = oc.most_common()[1][0]
    o_count = oc.most_common()[1][1]
    ans = n - e_count - o_count
else:
    e_num = ec.most_common()[1][0]
    e_count = ec.most_common()[1][1]
    ans = n - e_count - o_count

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

count_odd = Counter(v[1::2]).most_common()
count_even = Counter(v[0::2]).most_common()


if count_odd[0][0] != count_even[0][0]:
    ans = n - count_odd[0][1] - count_even[0][1]
else:
    if len(count_odd) > 1 and len(count_even) > 1:
        if count_odd[1][0] >= count_even[1][0]:
            ans = n - count_odd[1][1] - count_even[0][1]
        else:
            ans = n - count_odd[0][1] - count_even[1][1]
    elif len(count_odd) == 1 and len(count_even) == 1:
        ans = n/2
    else:
        if len(count_odd) == 1:
            ans = n - count_odd[0][1] - count_even[1][1]
        elif len(count_even) == 1:
            ans = n - count_odd[1][1] - count_even[0][1]

print(int(ans))

Submission status: Wrong Answer

Solution code:
import collections

n = input()
nums = list(map(int, input().split()))
odd = nums[0::2]
even = nums[1::2]
odd_c = collections.Counter(odd)
even_c = collections.Counter(even)

# Answer
odd_change = len(odd) - odd_c.most_common(1)[0][1]
even_change = len(even) - even_c.most_common(1)[0][1]

if odd_change + even_change == 0:
    if odd_c.most_common(1)[0][0] == even_c.most_common(1)[0][0]:
        print(len(even))
        exit()
print(odd_change + even_change)

Submission status: Wrong Answer

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

min_num = 0

even = {}
odd = {}

for i, v in enumerate(v_list):
    if i % 2 == 0:
        if v in even:
            even[v] += 1
        else:
            even[v] = 1
    else:
        if v in odd:
            odd[v] += 1
        else:
            odd[v] = 1
even_max = sorted(even.items(), key=lambda x: -x[1])[0][0]
odd_max = sorted(odd.items(), key=lambda x: -x[1])[0][0]

if odd_max == even_max:
    even_max = 10 ** 5 + 1

for i, v in enumerate(v_list):
    if i % 2 == 0:
        if v != even_max:
            min_num += 1
    else:
        if v != odd_max:
            min_num += 1
print(min_num)

Submission status: Wrong Answer

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

n = int(input())
v = [int(i) for i in input().split()]
INF = 10 ** 6

vd = {}
for vi in v:
    if vi in vd:
        vd[vi] += 1
    else:
        vd[vi] = 1

vl = sorted(vd.values())
if len(vl) == 1:
    print(n // 2)
else:
    m = INF
    for i, j in zip(vl, vl[1:]):
        if m > abs(n - i - j):
            m = i + j
    print(n - m)

Submission status: Wrong Answer

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

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

x1 = 0
x2 = 0
x1_count = 0
x2_count = 0

for i in range(10):
    count1 = v1.count(i)
    count2 = v2.count(i)
    if x1_count < count1:
        x1 = i
        x1_count = count1
    
    if x2_count < count2:
        x2 = i
        x2_count = count2

n = n//2
ans = (n - x1_count) + (n - x2_count)
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()

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])
    elif oddCountToNumber[0][0] > evenCountToNumber[0][0]:
        print(len(numbers) - oddCountToNumber[0][0] - evenCountToNumber[1][0])
    else:
        first = len(numbers) - oddCountToNumber[0][0] - evenCountToNumber[1][0]
        second = len(numbers) - oddCountToNumber[1][0] - evenCountToNumber[0][0]
        print(min(first, second))
else:
    print(len(numbers) - oddCountToNumber[0][0] - evenCountToNumber[0][0])

Submission status: Wrong Answer

Solution code:
n = int(input())
v = [int(_) for _ in input().split()]
s = set(v)
if len(s) == 1:
  print(int(n/2))
elif len(s) == 2:
  print(0)
else:
  print(int(n-len(s)))

Submission status: Wrong Answer

Solution code:
import sys
import collections
n = int(input())
half_n = n // 2
v = list(map(int,input().split()))
v1 = []
v2 = []
ans = 0

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

for i,j in enumerate(v):
    if i % 2 == 0:
        v1.append(j)
    else:
        v2.append(j)

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

for i in [v1, v2]:
    ans += half_n - i.most_common()[0][1]
print(ans)

Submission status: Wrong Answer

Solution code:
import collections

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

head = vlist[::2]
foll = vlist[1::2]

import collections
h_ = collections.Counter(head).most_common()[0][0]
f_ = collections.Counter(foll).most_common()[0][0]

if f_ == h_:
    f_ = -1

count = 0
for i in range(len(vlist)):
    if i % 2 == 0 and vlist[i] != h_:
        count += 1
    if i % 2 == 1 and vlist[i] != f_:
        count += 1

print(count)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

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

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

def f(v):
    d = defaultdict(int)
    d[0] = 0

    for i in v:
        d[i] += 1
    return d

d1 = f(v1)
d2 = f(v2)

v1_max = max(d1, key=d1.get)
v2_max = max(d2, key=d2.get)

if v1_max == v2_max:
    if d1[v1_max] < d2[v2_max]:
        w = (v1_max, d1.pop(v1_max))
        v1_max = max(d1, key=d1.get)
        d1[w[0]] = w[1]
    else:
        w = (v2_max, d2.pop(v2_max))
        v2_max = max(d2, key=d2.get)
        d2[w[0]] = w[1]

del d1[v1_max]
del d2[v2_max]

print(sum(d1.values()) + sum(d2.values()))

Submission status: Wrong Answer

Solution code:
from collections import Counter
n=int(input())
v=list(map(int,input().split()))
gu=[]
gubar=[]
ans1=0
ans2=0
for i in range(n):
    if i%2==0:
        gubar.append(v[i])
    else:
        gu.append(v[i])
a=Counter(gubar)
a_mode=a.most_common(1)
b=Counter(gu)
b_mode=b.most_common(1)
if a_mode[0][0]==b_mode[0][0]:
    if gubar.count(a_mode[0][0])<gu.count(b_mode[0][0]):
        ans2=len(gu)-gu.count(b_mode[0][0])
        a_mode=a.most_common(2)
        ans1=len(gubar)-gu.count(a_mode[0][0])
    elif gubar.count(a_mode[0][0])>gu.count(b_mode[0][0]):
        ans1=len(gubar)-gubar.count(a_mode[0][0])
        b_mode=b.most_common(2)
        ans2=len(gu)-gu.count(b_mode[0][0])
    else:
        ans2=n/2
else:
    ans1=len(gubar)-gubar.count(a_mode[0][0])
    ans2=len(gu)-gu.count(b_mode[0][0])
print(int(ans1+ans2))

Submission status: Wrong Answer

Solution code:
import sys
n = int(input())
v = list(map(int, input().split()))
e = {}
for i in v[::2]:
    if i in e:
        e[i] += 1
    else:
        e[i] = 1
o = {}
for i in v[1::2]:
    if i in o:
        o[i] += 1
    else:
        o[i] = 1
if len(list(set(v))) == 1:
    print(min(len(v[::2]), len(v[1::2])))
    sys.exit()
ans = 0
ans += (len(v[::2]) - max(list(e.values())))
ans += (len(v[1::2]) - max(list(o.values())))
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter


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

val = [
    Counter([v[i] for i in range(0, len(v), 2)]).most_common()[0][0],
    Counter([v[i] for i in range(1, len(v), 2)]).most_common()[0][0],
]

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

fix = 0
for i, x in enumerate(v):
    if x != val[i % 2]:
        fix += 1
print(fix)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n=int(input())
v=list(map(int, input().split()))
v1=[]
v2=[]
for i in range(0,n-1,2):
    v1.append(v[i])
    v2.append(v[i+1])

v1C=list(sorted(list(Counter(v1).items()), key=lambda x: x[1]))
v2C=list(sorted(list(Counter(v2).items()), key=lambda x: x[1]))

a=v1C[-1][1]
b=v2C[-1][1]
if v1C[-1][0]==v2C[-1][0]:
    if a>=b and len(v2C)>1:
        b=v2C[len(v2C)-2][1]
    elif a<b and len(v2C)>1:
        a=v1C[len(v1C)-2][1]
    else:
        a=n//2
        b=0

print(len(v1)-a+len(v2)-b)

Submission status: Wrong Answer

Solution code:
import collections

n = int(input())

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

ac = collections.Counter(a[::2]).most_common()
bc = collections.Counter(a[1::2]).most_common()


while True:
    if len(ac) == 0:
        print(n-bc[0][1])
        break
    elif len(bc) == 0:
        print(n-ac[0][1])
        break
            
    if ac[0][0] != bc[0][0]:
        print(n-ac[0][1]-bc[0][1])
        break
    elif ac[0][1] >= bc[0][1]:
        bc.pop()
        continue
    else:
        ac.pop()
        continue

Submission status: Wrong Answer

Solution code:
import numpy as np
import math

# K = int(input())
# N, K = map(int, input().split())
# A = list(map(int, input().split()))
# S = input() # String
# DP = np.zeros((N, Y), dtype=int)

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

Veven = []
Vodd = []

for i, v in enumerate(V):
    if i % 2 == 0:
        Veven.append(v)
    else:
        Vodd.append(v)


evD = dict()
for v in Veven:
    if v in evD:
        evD[v] += 1
    else:
        evD[v] = 1

maxV = 0
secMaxV = 0
maxEvK = None
for key, val in evD.items():
    if val == maxV:
        secMaxV = maxV
    if val > maxV:
        secMaxV = maxV
        maxV = val
        maxEvK = key

evenCost = int(N / 2) - maxV
if len(evD.items()) == 1:
    secEvenCost = int(N / 2)
else:
    secEvenCost = int(N / 2) - secMaxV

odD = dict()
for v in Vodd:
    if v in odD:
        odD[v] += 1
    else:
        odD[v] = 1

maxV = 0
secMaxV = 0
maxOdK = None
for key, val in odD.items():
    if val == maxV:
        secMaxV = maxV
    if val > maxV:
        secMaxV = maxV
        maxV = val
        maxOdK = key

odCost = int(N / 2) - maxV
if len(evD.items()) == 1:
    secOdCost = int(N / 2)
else:
    secOdCost = int(N / 2) - secMaxV

# print(maxOdK)
# print(maxEvK)
if maxOdK is not maxEvK:
    print(evenCost + odCost)
else:
    # print(evenCost)
    # print(secOdCost)
    # print(secEvenCost)
    # print(odCost)
    bet = min(evenCost + secOdCost, secEvenCost + odCost)
    print(bet)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n=input()
lists=input().split()
hi=[]
low=[]
c=True
for i in range(len(lists)):
    if(i==0):
        same_c=lists[i]
    if(same_c==lists[i] and c):
        pass
    else:
        c=False
        
    if(i%2==0):
        hi.append(lists[i])
    else:
        low.append(lists[i])
if(c):
    print(len(hi))
    exit(0)
hi_counter=Counter(hi)
low_counter=Counter(low)
print(len(hi)-hi_counter.most_common()[0][1]+len(low)-low_counter.most_common()[0][1])

Submission status: Wrong Answer

Solution code:
n = int(input())
v = list(map(int, input().split()))
v1 = set()
for i in range(0, n, 2):
    v1.add(v[i])
v2 = set()
for i in range(1, n, 2):
    v2.add(v[i])
print(len(v1) + len(v2) - 2)

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_common_even = collections.Counter(vs_even).most_common(1)[0][1]
    most_common_odd = collections.Counter(vs_odd).most_common(1)[0][1]

    ans = 0
    len_vs_even = len(vs_even)
    ans += len_vs_even - most_common_even
    ans += len_vs_even - most_common_odd

    print(ans)



if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import collections
n=int(input())
v=list(map(int,input().split()))
v1=[]
v2=[]
c=0
for i in range(len(v)):
    if c==0:
        v1.append(v[i])
        c=1
    else:
        v2.append(v[i])
        c=0
m1=collections.Counter(v1)
w1=m1.most_common()
m2=collections.Counter(v2)
w2=m2.most_common()
if w1[0][0]==w2[0][0]:
    if w1==w2:
        print(n//2)
    elif w1[0][1]>=w2[0][1]:
        print(n-w1[0][1]-w2[1][1])
    else:
        print(n-w1[1][1]-w2[0][1])
else:
    print(n-w1[0][1]-w2[0][1])

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
v = [int(i) for i in input().split()]


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

odd2 = Counter(odd)
even2 = Counter(even)

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

else:
    print(n - odd2.most_common()[0][1] - even2.most_common()[0][1])

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())

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

a = {}
b = {}

for i in range(n):
	if i % 2 == 1:
		if v[i] in a:
			a[v[i]] += 1
		else:
			a[v[i]] = 1
	else:
		if v[i] in b:
			b[v[i]] += 1
		else:
			b[v[i]] = 1

a[0] = 0
b[0] = 0

c = max(a)
d = max(b)
e = a[c]
f = b[d]

if c != d:
    print(n-e-f)
else:
    a.pop(c)
    b.pop(d)
    print(n-max(f+a[max(a)],e+b[max(b)]))