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())
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(v1C)>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:
# -*- coding: utf-8 -*-
import math,string,itertools,fractions,heapq,collections,re,array,bisect
import numpy as np

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

odd = V[::2]
even = V[1:N:2]

odd_d = collections.Counter(odd)
even_d = collections.Counter(even)

if odd == even and len(odd_d) == 1 and len(even_d) == 1:
    ans = len(odd)

elif len(odd_d) == 1 and len(even_d) == 1:
    ans = 0

else:
    for i,n in enumerate(odd_d.keys()):
        if i == 0:
            odd_ind = n
        elif i == 1:
            odd_ind2 = n
        else:
            break


    for i, n in enumerate(even_d.keys()):
        if i == 0:
            even_ind = n
        elif i == 1:
            even_ind2 = n
        else:
            break

    if odd_ind != even_ind:
        ans = (N//2 - odd_d[odd_ind]) + (N//2 - even_d[even_ind])
    else:
        if odd_ind > even_ind:
            ans = (N//2 - odd_d[odd_ind]) + (N//2 - even_d[even_ind2])
        else:
            ans = (N//2 - odd_d[odd_ind2]) + (N//2 - even_d[even_ind])
print(ans)

Submission status: Wrong Answer

Solution code:
import collections

def main():
    n = input()
    a = map(int, raw_input().split())
    odd = [a[2 * i] for i in range(n/2)]
    even = [a[2*i + 1] for i in range(n/2)]
    codd = collections.Counter(odd)
    ceven = collections.Counter(even)
    coddmostitem = codd.most_common()[0][0]
    coddmosttimes = codd.most_common()[0][1]
    cevenmostitem = ceven.most_common()[0][0]
    cevenmosttimes = codd.most_common()[0][1]
    if coddmostitem == cevenmostitem:
        if coddmosttimes >= cevenmosttimes:
            if len(ceven) == 1:
                cevennoreplace = 0
            else:
                cevennoreplace = ceven.most_common()[1][1]
            coddnoreplace = codd.most_common()[0][1]
        if coddmosttimes < cevenmosttimes:
            if len(codd) == 1:
                coddnoreplace = 0
            else:
                coddnoreplace = codd.most_common()[1][1]
            cevennoreplace = ceven.most_common()[1][1]
    else:
        coddnoreplace = codd.most_common()[0][1]
        cevennoreplace = ceven.most_common()[0][1]
    coddreplace = n/2 - coddnoreplace
    cevenreplace = n/2 - cevennoreplace
    print(coddreplace+cevenreplace)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import collections

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

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

v0cnt = collections.Counter(v0)
v1cnt = collections.Counter(v1)

v0most = v0cnt.most_common()[0]
v1most = v1cnt.most_common()[0]
if v0most[0] != v1most[0]:
    ans = n - v0most[1] -v1most[1]
else:
    if v0most[1] == v1most[1]:
        ans = n//2
    elif v0most[1] > v1most[1]:
        ans = n - v0most[1] - v1cnt.most_common()[1][1]
    else:
        ans = n - v1most[1] - v0cnt.most_common()[1][1]

print(ans)

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())
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[1:len(sss)]) + sum(ttt[1:len(ttt)])

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

odds = []
evens = []

for i in range(len(v)):
    if i % 2 == 0:
        odds.append(v[i])
    else:
        evens.append(v[i])

oddCount = {}
evenCount = {}

for i in range(len(v)):
    if i % 2 == 0:
        if v[i] in oddCount.keys():
            oddCount[v[i]] += 1
        else:
            oddCount[v[i]] = 1
    else:
        if v[i] in evenCount.keys():
            evenCount[v[i]] += 1
        else:
            evenCount[v[i]] = 1

oddCountSorted = {}
for k, v in sorted(oddCount.items(), key=lambda x: - x[1]):
    oddCountSorted[k] = v

evenCountSorted = {}
for k, v in sorted(evenCount.items(), key=lambda x: - x[1]):
    evenCountSorted[k] = v

oddValues = list(oddCountSorted.values())
evenValues = list(evenCountSorted.values())


oddMaxIndex = 0
evenMaxIndex = 0
if list(oddCountSorted.keys())[oddMaxIndex] == list(evenCountSorted.keys())[evenMaxIndex]:
    if oddValues[oddMaxIndex] > evenValues[evenMaxIndex]:
        evenMaxIndex += 1
    else:
        oddMaxIndex += 1

if oddMaxIndex <= len(oddValues) - 1:
    oddValues.pop(oddMaxIndex)
if evenMaxIndex <= len(evenValues) - 1:
    evenValues.pop(evenMaxIndex)
print(sum(oddValues) + sum(evenValues))

Submission status: Wrong Answer

Solution code:
from sys import stdin

n = int(stdin.readline().rstrip())
v = [int(i) for i in stdin.readline().rstrip().split()]

left = [0] * (10**5 + 1)
right = [0] * (10**5 + 1)

for i in range(len(v)):
    if i % 2 == 0:
        left[v[i]] += 1
    else:
        right[v[i]] += 1

left_max = 0
left_max_second = 0
right_max = 0
right_max_second = 0
left_flag = 0
right_flag = 0
for i in range(len(left)):
    if left_max < left[i]:
        left_max_second = left_max
        left_max = left[i]
        left_flag = i

    if right_max < right[i]:
        right_max_second = right_max
        right_max = right[i]
        right_flag = i

if left_flag == right_flag:
    tmp = min(left_max + right_max_second, right_max + left_max_second)
    # print(left_max, left_max_second, right_max, right_max_second)
    print(n - tmp)
else:
    print((n // 2 - left_max) + (n // 2 - right_max))

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 = (n // 2) - a[0][1]
    bc = (n // 2) - b[0][1]
    if a[0][0] == b[0][0]:
        if a[0][1] > b[0][1]:
            bc = n // 2 - (b[1][1] if len(b) != 1 else 0)
        else:
            ac = n // 2 - (a[1][1] if len(a) != 1 else 0)
    return ac + bc
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):
    if v2[0] != v2[i]:
        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())
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()

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

ans = 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:
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)
 
if evencount.most_common()[0][0] != oddcount.most_common()[0][0]:
    ans = n - evencount.most_common()[0][1] - oddcount.most_common()[0][1]
else:
    if evencount.most_common()[0][1] > oddcount.most_common()[0][1]:
        if len(oddcount)!=1:
            ans = n - evencount.most_common()[0][1] - oddcount.most_common()[1][1]
        else:
            ans = n - evencount.most_common()[0][1]
    else:
        if len(evencount)!=1:
            ans = n - evencount.most_common()[1][1] - oddcount.most_common()[0][1]
        else:
            ans = n - oddcount.most_common()[0][1]

    
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

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

counter = Counter(v1)
x1 = counter.most_common()[0][0]
counter = Counter(v2)
x2 = counter.most_common()[0][0]

x1_count = v1.count(x1)
x2_count = v2.count(x2)

n = n//2
ans = (n - x1_count) + (n - x2_count)
print(ans)

Submission status: Wrong Answer

Solution code:
a = input()
dict1 = dict()
dict2 = dict()
counter = 0
b = input()
for i in b:
	if counter % 2 == 0:
		if i not in dict1:
			dict1[i] = 1
		else:
			dict1[i] += 1
	elif counter % 2 == 1:
		if i not in dict2:
			dict2[i] = 1
		else:
			dict2[i] += 1
			
	counter += 1

dict1list = []
for i in dict1.keys():
	dict1list.append([i, dict1[i]])

dict2list = []
for i in dict2.keys():
	dict2list.append([i, dict2[i]])

dict1list.sort(key = lambda x: x[1])
dict2list.sort(key = lambda x: x[1])
print(dict1list,dict2list)
if dict1list[-1][0] == dict2list[-1][0] and len(dict2list) > 1 and dict1list[-1][1]  > dict2list[-1][1]:
	print(len(b) - dict1list[-1][1] - dict2list[-2][1])
elif dict1list[-1][0] == dict2list[-1][0] and len(dict2list) == 1 and dict1list[-1][1]  > dict2list[-1][1]:
	print(len(b) - dict1list[-1][1])
elif dict1list[-1][0] == dict2list[-1][0] and len(dict1list) > 1 and dict1list[-1][1]  < dict2list[-1][1]:
	print(len(b) - dict1list[-2][1] - dict2list[-1][1])
elif dict1list[-1][0] == dict2list[-1][0] and len(dict1list) == 1 and dict1list[-1][1]  < dict2list[-1][1]:
	print(len(b) - dict2list[-1][1])
elif dict1list[-1][0] == dict2list[-1][0] and dict1list[-1][1]  == dict2list[-1][1]:
	if len(dict1list) == 1 and len(dict2list) == 1:
		print(len(b) - dict2list[-1][1])
	elif len(dict1list) == 1 and len(dict2list) > 1:
		print(len(b) - dict2list[-2][1] - dict1list[-1][1])
	elif len(dict1list) > 1 and len(dict2list) == 1:
		print(len(b) - dict2list[-1][1] - dict1list[-2][1])
	else:
		if (dict2list[-2][-1] >= dict1list[-2][-1]):
			print(len(b) - dict2list[-2][1] - dict1list[-1][1])
		elif (dict2list[-2][-1] < dict1list[-2][-1]):
			print(len(b) - dict2list[-1][1] - dict1list[-2][1])
else:
	print(len(b) - dict1list[-1][1] - dict2list[-1][1])

Submission status: Wrong Answer

Solution code:
n = int(input())
lst = list(map(int, input().split()))
m = 0
for i in range(0,n-2):
    if lst[i] != lst[i+2]:
        lst[i+2] = lst[i]
        m += 1
    elif lst[i] == lst[i+1]:
        m += 1
print(m)

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

c = a[max(a)]
d = b[max(b)]
e = max(a)
f = max(b)
if e != f:
	print(n-c-d)
else:
	a.pop(e)
	b.pop(f)
	if len(a) == 0 and len(b) == 0:
		print(n//2)
	elif len(a) == 0:
		print(n//2-b[max(b)])
	elif len(b) == 0:
		print(n//2-a[max(a)])
	else:
		g = max(c+b[max(b)],d+a[max(a)])
		print(n-g)

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_b.most_common()[1][1]))
else:
    print(int(N - b_f[1] - c_a.most_common()[1][1]))

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:
    a,b = oc.most_common(1)[0][1] , ec.most_common(1)[0][1]
    if a > b:
        print(h-a+h-ec.most_common(2)[1][1])
    elif b < a:
        print(h-b+h-oc.most_common(2)[1][1])
    else:
        if len(oc) == 1:
            print(h)
        else:
            print(h-a+h-oc.most_common(2)[1][1])

Submission status: Wrong Answer

Solution code:
import collections
import statistics

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

#要素番号の奇偶で仕分け
odd = []
even = []
for i in range(n):
    if i % 2 == 0:
        even.append(v[i])
    else:
        odd.append(v[i])

#最頻値を取得。最頻値がなかったら先頭の要素
try:
    evenmode = statistics.mode(even)
except:
    evenmode = v[0]    

try:
    oddmode = statistics.mode(odd)
except:
    oddmode = v[1]

#奇偶のグループのそれぞれで変える必要のある要素を数える
evenchange = int(n/2) - even.count(evenmode)
oddchange = int(n/2) - odd.count(oddmode)
answer = evenchange + oddchange

#もし奇偶の最頻値が同じ値だったら、
#次に最頻な値を最頻値としてもう一回考える
#最頻がなかったらまあ全部だよね。あ！全部－１かも。
if oddmode == evenmode:
    try:
        even2ndmode = even.most_common()[1][0]
        change2 = oddchange + int(n/2) - even.count(even2ndmode)
    except:
        change2 = oddchange + int(n/2)
    if even.count(oddmode) != int(n/2):
            change2 -= 1
               
    try:
        odd2ndmode = odd.most_common()[1][0]
        change1 = evenchange + int(n/2) - odd.count(odd2ndmode)
    except:
        change1 = evenchange + int(n/2)
    if odd.count(evenmode) != int(n/2):
            change1 -= 1
     
    answer = min(change1,change2)

print(answer)

Submission status: Wrong Answer

Solution code:
from collections import Counter


def solve(V):
    odd = Counter()
    even = Counter()
    for i, c in enumerate(V):
        if i % 2 == 0:
            even.update([c])
        else:
            odd.update([c])
    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], odd_maxs[0]

    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], even_maxs[0]

    ans = 0
    if odd_max[0] != even_max[0]:
        odd_max = odd_max[0]
        even_max = even_max[0]
    elif odd_2nd_max[0] != even_2nd_max[0]:
        if odd_2nd_max[0] != even_max[0]:
            odd_max = odd_2nd_max[0]
            even_max = even_max[0]
        elif odd_max[0] != even_2nd_max[0]:
            odd_max = odd_max[0]
            even_max = even_2nd_max[0]
    else:
        if even_max[1] <= odd_max[1]:
            odd_max = odd_max[0]
            even_max = even_2nd_max[0]
            if odd_max == even_max:
                even_max = even_max + even_max
        else:
            odd_max = odd_2nd_max[0]
            even_max = even_max[0]
            if odd_max == even_max:
                odd_max = odd_max + odd_max

    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:
if __name__ == '__main__':
    n = int(input())
    vs = list(map(int, input().split()))

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

    from collections import Counter

    result = 0
    #evenの処理
    ce = Counter(even)
    emode = ce.most_common(1)[0]

    oe = Counter(odd)
    omode = oe.most_common(1)[0]
    if emode[0] == omode[0]:
        if emode[1] > omode[1]:
            for i in range(len(even)):
                if even[i] != emode[0]:
                    result += 1
            if len(oe.most_common()) == 1:
                omode = -1
                result += len(odd)
            else:
                omode = oe.most_common(2)[0][0]
                for i in range(len(odd)):
                    if odd[i] != omode:
                        result += 1

        else:
            for i in range(len(odd)):
                if odd[i] != omode[0]:
                    result += 1
            if len(ce.most_common()) == 1:
                emode = -1
                result += len(even)
            else:
                emode = ce.most_common(2)[0][0]
                for i in range(len(even)):
                    if even[i] != emode:
                        result += 1
    else:
        for i in range(len(even)):
            if even[i] != emode[0]:
                result += 1
        for i in range(len(odd)):
            if odd[i] != omode[0]:
                result += 1

    print(result)

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

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

ans = 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:
import math
n = int(input())
lis = list(map(int,input().split()))
lisa = lis[0::2]
lisb = lis[1::2]
  # print(lisa,lisb)
numa1 = math.ceil(sum(lisa) / len(lisa))
numa2 = math.floor(sum(lisa) / len(lisa))
numb1 = math.ceil(sum(lisb) / len(lisb))
numb2 = math.floor(sum(lisb) / len(lisb))

ans = []

cou = 0
co = 0
for i in range(len(lisa)):
  if numa1 != lisa[i]:cou += 1
  if numa2 != lisa[i]:co += 1
num = 0
nu = 0
for i in range(len(lisb)):
  if numb1 != lisb[i]:num += 1
  if numb2 != lisb[i]:nu += 1
if numa1 != numb1:ans.append(cou + num)
if numa1 != numb2:ans.append(cou + nu)
if numa2 != numb1:ans.append(co + num)
if numa2 != numb2:ans.append(co + nu)
if ans == []:ans.append(min(cou,co)+min(num,nu)+len(lisb))
print(min(ans))

Submission status: Wrong Answer

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

d = defaultdict(int)
rd = defaultdict(int)
d[0] = 0
rd[0] = 0

ll = (n + 1) // 2
rr = (n) // 2

for i in range(0, n, 2):
    d[ v[i] ] = d[v [i] ] + 1
    if i + 1 < n:
        rd[ v[i+1]  ] = rd[ v[i+1] ] + 1

d = sorted(d.items(), key=lambda x: -x[1])
rd= sorted(rd.items(), key=lambda x: -x[1])


i , j = 0, 0

while d[i][0] == rd[j][0] and i < len(d) and j < len(rd):
    if (ll - d[i][1] < rr - rd[j][1]):
        i += 1
    else:
        j += 1

print(ll - d[i][1] + rr - rd[j][1])

Submission status: Wrong Answer

Solution code:
import itertools

n = int(input())
v = [int(w) for w in input().split()]
assert len(v) == n

def elem_count(ls):
    '''Return the list of (num of elem, elem).'''
    ls.sort()
    ls = itertools.groupby(ls)
    cs = [(len(list(s)), e) for e, s in ls]
    #cs.sort(reverse=True)
    return cs

e = [v[i] for i in range(0, n, 2)]
o = [v[i] for i in range(1, n, 2)]

e = elem_count(e)
o = elem_count(o)

if e[0][1] != o[0][1]:
    ans = n - (e[0][0] + o[0][0])

elif len(e) == len(o) == 1:
    ans = n - e[0][0]

elif len(e) == 1:
    ans = n - (e[0][0] + o[1][0])

elif len(o) == 1:
    ans = n - (e[1][0] + o[0][0])

elif e[0][0] + o[1][0] > e[1][0] + o[0][0]:
    ans = n - (e[0][0] + o[1][0])
else:
    ans = n - (e[1][0] + o[0][0])

print(ans)

Submission status: Wrong Answer

Solution code:
import collections

inLen = int(input())
##inputs =  list(map(int, input().split()))
inputs = input().split()

evenDict = collections.Counter(inputs[0::2])
oddDict = collections.Counter(inputs[1::2])

evenMost = evenDict.most_common(2)
oddMost = oddDict.most_common(2)

if(evenMost[0][0] != oddMost[0][0]):
    print(inLen - evenMost[0][1] - oddMost[0][1])
else:
    if(evenMost[0][1] < oddMost[0][1]):
        print(inLen - evenMost[1][1] - oddMost[0][1])
    elif (evenMost[0][1] > oddMost[0][1]):
        print(inLen - evenMost[0][1] - oddMost[1][1])
    else:
        print(int(inLen / 2))

Submission status: Wrong Answer

Solution code:
import collections as cl

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

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

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

vgmax=max(vgcnt)
vkmax=max(vkcnt)

if vgmax==vkmax:
    if vgcnt[vgmax]<=vkcnt[vkmax]:
        vgcnt.pop(vgmax)
        if len(vgcnt)>0:
            vgmax=max(vgcnt)
        else:
            vgmax='a'
    else:
        vkcnt.pop(vkmax)
        if len(vkcnt)>0:
            vkmax=max(vkcnt)
        else:
            vkmax='a'

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:
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))
    
    ac = (n // 2) - a[0][1]
    bc = (n // 2) - b[0][1]
    if a[0][0] == b[0][0]:
        if a[0][1] > b[0][1]:
            bc = n // 2 - (b[1][1] if len(b) != 1 else 0)
        else:
            ac = n // 2 - (a[1][1] if len(a) != 1 else 0)
    return ac + bc

print(f())

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

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

odds_counter = defaultdict(int)
evens_counter = defaultdict(int)

for o in V[0::2]:
    odds_counter[o] += 1
for e in V[1::2]:
    evens_counter[e] += 1

odds = sorted(odds_counter.items(), key=lambda x: x[1], reverse=True)
evens = sorted(evens_counter.items(), key=lambda x: x[1], reverse=True)

if odds[0][0] != evens[0][0]:
    ans = n - odds[0][1] - evens[0][1]
else:
    if odds[0][1] >= evens[0][1]:
        if len(odds) == 1:
            ans = evens[0][1]
        else:
            ans = n - evens[0][1] - odds[1][1]
    else:
        if len(evens) == 1:
            ans = odds[0][1]
        else:
            ans = n - odds[0][1] - evens[1][1]
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
v = [int(x) for x in input().split()]
odd = {}
even = {}
for i in range(n):
	x = v[i]
	if i&1==1:
		if x in odd:
			odd[x]+= 1
		else:
			odd[x] = 1
	else:
		if x in even:
			even[x]+= 1
		else:
			even[x] = 1
			
oddl = []
for p, q in odd.items():
	oddl.append((p, q))
evenl = []
for p, q in even.items():
	evenl.append((p, q))
	
oddl = sorted(oddl, key=lambda x: x[1])
evenl = sorted(evenl, key=lambda x: x[1])

oddn = (n+1)>>1
evenn = n-oddn
result = []
if oddl[0][0] == evenl[0][0]:
	if len(oddl) > 1:
		result.append((oddn-oddl[1][1])+(evenn-evenl[0][1]))
	if len(evenl) > 1:
		result.append((oddn-oddl[0][1])+(evenn-evenl[1][1]))
	if len(oddl) == len(evenl) == 1:
		result.append(evenn)
else:
	result.append((oddn-oddl[0][1])+(evenn-evenl[0][1]))
print(min(result))

Submission status: Wrong Answer

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

num_v = {}
for v_ in v:
	if v_ not in num_v:
		num_v[v_]  = 1
	else:
		num_v[v_] += 1
if len(num_v) == 1:
	print n / 2
else:
	sorted_num_v = sorted(num_v.items(), key=lambda x:x[1])
	up = sorted_num_v[-1][1]
	down = sorted_num_v[-2][1]
	if up - down <= n - up - down:
		print n - up - down
	else:
		subs = n - up - down
		subs += (up - down - (n - up - down)) / 2
		print subs

Submission status: Wrong Answer

Solution code:
import collections

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

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

v_l_odd = []
v_l_even = []

for i in range(n):
    if i % 2 == 0:
        v_l_odd.append(v_l[i])
    else:
        v_l_even.append(v_l[i])

max_odd = collections.Counter(v_l_odd)
mon = max_odd.most_common(1)[0][0]
max_even = collections.Counter(v_l_even)
men = max_even.most_common(1)[0][0]

v_l_odd.clear()
v_l_even.clear()

for i in range(n):
    if i % 2 == 0:
        if v_l[i] != mon:
            v_l_odd.append(v_l[i])
    else:
        if v_l[i] != men:
            v_l_even.append(v_l[i])

print(len(v_l_odd) + len(v_l_even))

Submission status: Wrong Answer

Solution code:
n = int(input())
li = input().split(" ")
el = []
ol = []
for i in range(n):
    if i % 2 == 0:
        el.append(int(li[i]))
    else:
        ol.append(int(li[i]))
n_el = len(list(set(el)))
n_ol = len(list(set(ol)))
if n_el == 1 and n_ol == 1 and el[0] != ol[0]:
    print(0)
elif n_el == 1 and n_ol == 1 and el[0] == ol[0]:
    print(len(ol))
else:
    els = {}
    ols = {}
    for e in el:
        if(str(e) in els):
            els[str(e)] += 1
        else:
            els[str(e)] = 1
    for o in ol:
        if(str(o) in ols):
            ols[str(o)] += 1
        else:
            ols[str(o)] = 1
    elv = list(els.values())
    olv = list(ols.values())
    elk = sorted(list(els.keys()))
    olk = sorted(list(ols.keys()))
    is_same_key = 1
    for i in range(len(elk)):
        if elk[i] != olk[i]:
            is_same_key = 0
            break
    ans = 0
    if(not(is_same_key)):
        ans += sum(elv) - max(elv)
        ans += sum(olv) - max(olv)
        print(ans)
    else:
        tempe = []
        tempo = []
        for i in elk:
            tempe.append(n//2 - els[i])
            tempo.append(n//2 - ols[i])
        min_e = min(tempe)
        min_o = min(tempo)
        ind_min_e = tempe.index(min_e)
        ind_min_o = tempo.index(min_o)
        if ind_min_o != ind_min_e:
            print(min_e + min_o)
        else:
            if min_e >= min_o:
                tempo[ind_min_o] = 999999999
                print(min_e + min(tempo))
            else:
                tempo[ind_min_e] = 999999999
                print(min_o + min(tempe))

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))]
cc = [0 for i in range(pow(10,5))]
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
p = 0
pp = 0
for i in range(d):
    if one < c[i]:
        onee = one
        one = c[i]
        p += 1
    if two < cc[i]:
        twoo = two
        two = cc[i]
        p += 1
    if p == 2:
        pp = 1
    else:
        pp = 0
    p = 0
tt = max(one,two)
t = max(onee,twoo)

if pp == 0:
    if a//2+1 > one and a//2+1 > two:
        print(a-one-two)
    else:
        print(a-(one - a//2)-two)
else:
    if a//2+1 > t and a//2+1 > tt:
        print(a-t-tt)
    else:
        print(a-(tt - a//2)-t)

Submission status: Wrong Answer

Solution code:
n = int(input())
lst = [int(x) for x in input().split()]
d1 = {None : [-1, None]}
d2 = {None : [-1, None]}
for i in range(n // 2):
    if lst[2 * i] in d1:
        tmp1 = d1[lst[2 * i]]
        if tmp1[1] + 2 == 2 * i:
            tmp1[0] += 1
        tmp1[1] = 2 * i
    else:
        d1[lst[2 * i]] = [0, 2 * i] # 連続回数, 最後に登場したインデックス
        
    if lst[2 * i + 1] in d2:
        tmp2 = d2[lst[2 * i + 1]]
        if tmp2[1] + 2 == 2 * i + 1:
            tmp2[0] += 1
        tmp2[1] = 2 * i + 1
    else:
        d2[lst[2 * i + 1]] = [0, 2 * i + 1]
        

u1 = sorted(d1.items(), key = lambda x : x[1][0], reverse = True)
u2 = sorted(d2.items(), key = lambda x : x[1][0], reverse = True)

MAKE = lambda x : x[1][0] + 1

if u1[0][0] != u2[0][0]:
    a = MAKE(u1[0]) + MAKE(u2[0])
    print(n - a)
else:
    a1 = MAKE(u1[0]) + MAKE(u2[1])
    a2 = MAKE(u1[1]) + MAKE(u2[0])
    a = max(a1, a2)
    print(n - a)