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())
nums = list(map(int,input().split()))
odd,even={},{}
for i in range(n):
  if i%2 == 0:
    if nums[i] in even:
      even[nums[i]] += 1
    else:
      even[nums[i]] = 1
  else:
    if nums[i] in odd:
      odd[nums[i]] += 1
    else:
      odd[nums[i]] = 1

if len(odd) == 1 and len(even) == 1:
  if odd == even:
    print(n//2)
  else:
    print(0)
elif len(even) == 1 and 1 < len(odd):
  for a,b in even.items():
    for k,v in sorted(odd.items()):
      if a == k:
        continue
      else:
        print(n//2 - v)
        exit()
elif len(odd) == 1 and 1 < len(even):
  for a,b in odd.items():
    for k,v in sorted(even.items()):
      if a == k:
        continue
      else:
        print(n//2 - v)
        exit()
else:
  a = sorted(odd.items())
  b = sorted(even.items())
  if a[0][0] == b[0][0]:
    print(n - max(a[0][1]+b[1][1],a[1][1]+b[0][1]))
  else:
    print(n - a[0][1] - b[0][1])

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


min_trans = n//2
for x in ac:
    for y in bc:
        if x[0] == y[0]:
            continue
        else:
            print(x, y)
            min_trans = min(n-x[1]-y[1], min_trans)

print(min_trans)

Submission status: Wrong Answer

Solution code:
a = int(input())
b = list(map(int,input().split()))
c = []
d = []
e = 0
f = 0
for i in range(a):
    if i%2 == 0:
        c.append(b[i])
    else:
        d.append(b[i])
if c == d:
    print(int(a/2))
else:
    for i in range(int(a/2)):
        if i != 0:
            if c[0] != c[i]:
                e += 1
            if d[0] != d[i]:
                f += 1
    print(e+f)

Submission status: Wrong Answer

Solution code:
#n = list(map(int, input().split()))
import numpy as np
n = int(input())
v = list(map(int, input().split()))
data1 = [0]*(10**5 + 1)
data2 = [0]*(10**5 + 1)
for i in range(len(v) // 2):
    data1[v[2 * i]] += 1
    data2[v[2 * i + 1]] += 1
result = None
if np.argmax(np.array(data1)) == np.argmax(np.array(data2)):
    data1.sort()
    data2.sort()
    data1.reverse()
    data2.reverse()
    result = len(v) - data1[0] - data2[1]
else:
    data1.sort()
    data2.sort()
    data1.reverse()
    data2.reverse()
    result = len(v) - data1[0] - data2[0]
print(result)

Submission status: Wrong Answer

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

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

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

    odd_unq = set(odd)
    odd_even = set(even)
    print(int(len(odd_unq) + len(odd_even) - 2))

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(n):
    if i % 2 == 0:
        d[ v[i] ] = d[ v[i] ] + 1
    else:
        rd[ v[i]  ] = rd[ v[i] ] + 1

d = list(reversed(sorted(d.items(), key=lambda x: x[1])))
rd= list(reversed(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 sys 
import collections

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

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

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

Submission status: Wrong Answer

Solution code:
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()[0][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:
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:
n=int(input())

l=list(map(int,input().split()))
l1=[]
l2=[]

for i in range(n):
	if i%2==0:
		l1.append(l[i])
	else:
		l2.append(l[i])

count1=[]
count2=[]

for i in range(100000):
	count1.append(0)
	count2.append(0)

for i in range(n//2):
	count1[l1[i]-1]+=1
	count2[l2[i]-1]+=1

max1=0
max2=0

maxc1=[]
maxc2=[]

for i in range(100000):
	if count1[i]>max1:
		max1=count1[i]
		maxc1.append(i)

	if count2[i]>max2:
		max2=count2[i]
		maxc2.append(i)

# print('maxc1',maxc1)
# print('maxc2',maxc2)
# print('max1',max1)
# print('max2',max2)

if len(maxc2)+len(maxc1)>2 or (len(maxc2)+len(maxc1)==2 and maxc1[0]!=maxc2[0]):
	final=max1+max2

else :
	max3=0
	max4=0
	for i in range(100000):
		if i!=maxc1[0]:
			if count1[i]>max3:
				max3=count1[i]
				maxc1.append(i)

		if i!=maxc2[0]:
			if count2[i]>max4:
				max4=count2[i]
				maxc2.append(i)

	final=max(max1+max4,max2+max3)

print(n-final)

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=temp1-1
else:
    min=temp3-1


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

print(min2+min1)

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])
odd_max = sorted(odd.items(), key=lambda x: -x[1])

even_num = even_max[0][0]
odd_num = odd_max[0][0]

if odd_num == even_num:
    if len(odd_max) == 1:
        odd_num = 10 ** 5 + 1
    else:
        second_e = even_max[1][1]
        second_d = even_max[1][1]
        if second_e >= second_d:
            even_num = even_max[1][0]
        else:
            odd_num = odd_num[1][0]

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

Submission status: Wrong Answer

Solution code:
#coding: utf-8
import collections

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

c = 0
even, odd = [],[]

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

ce = collections.Counter(even)
co = collections.Counter(odd)
cV = collections.Counter(V)


if len(cV.keys()) != 2:
    c = min(ce.most_common()[-1][1], co.most_common()[-1][1])
elif len(ce.keys()) == 1 and len(co.keys()) == 1:
    c = 0
else:
    c = ce.most_common()[-1][1] + co.most_common()[-1][1]

print(c)

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:
    kiIndex = kisuuKosuL.index(max(kisuuKosuL))
    guIndex = gusuKosuL.index(max(gusuKosuL))
    if kisuuSyuL[kiIndex]!=gusuSyuL[guIndex]:
        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)
    else:
        if max(kisuuKosuL) < max(gusuKosuL):
            sum=max(kisuuKosuL)
            index2=0
            kisuuKosuL.sort()
            while index2<len(kisuuSyuL)-2:
                sum+=kisuuKosuL[index2]
                index2+=1
            index3=0
            gusuKosuL.sort()
            while index3< len(gusuSyuL)-1:
                sum+=gusuKosuL[index3]
                index3+=1
            print(sum)
        else:
            sum=max(gusuKosuL)
            index2=0
            kisuuKosuL.sort()
            while index2<len(kisuuSyuL)-1:
                sum+=kisuuKosuL[index2]
                index2+=1
            index3=0
            gusuKosuL.sort()
            while index3< len(gusuSyuL)-2:
                sum+=gusuKosuL[index3]
                index3+=1
            print(sum)

Submission status: Wrong Answer

Solution code:
from collections import deque
import numpy as np

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

num = np.unique(v)
if len(num) == 2:
    print(0)
elif len(num) == 1:
    print(n//2)
else:
    total = deque()
    for i in range(len(num)):
        total.append(np.sum(v == num[i]))

    if len(num) == 3:
        print(np.sort(total)[0])
    else:
        print(np.sum(np.sort(total)[0:2]))

Submission status: Wrong Answer

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

if max(v)==min(v):
	print(int(n/2))
else:
	dic1 = {}
	dic2 = {}
	
	for i in range(n):
		if i % 2 == 1:
			if str(v[i]) in dic1.keys():
				dic1[str(v[i])] = dic1[str(v[i])] + 1
			else:
				dic1[str(v[i])] = 1
	
		if i % 2 == 0:
			if str(v[i]) in dic2.keys():
				dic2[str(v[i])] = dic2[str(v[i])] + 1
			else:
				dic2[str(v[i])] = 1
	
	max1 = max(dic1, key=dic1.get)
	max2 = max(dic2, key=dic2.get)
	if max1 == max2:
		if dic1[max1] < dic2[max2]:
			dic1.pop(max1)
			max1 = max(dic1, key=dic1.get)
		else:
			dic2.pop(max2)
			max2 = max(dic2, key=dic2.get)
	p1 = dic1[max1]
	p2 = dic2[max2]
	
	print(n-p1-p2)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n=input()
A=map(int,raw_input().split())

M0=[]
M1=[]

for i in range(n):
	if i%2==0: M0.append(A[i])
	else: M1.append(A[i])

C0=Counter(M0)
C1=Counter(M1)

L0=sorted(C0.items(), key=lambda x:x[1], reverse=True)
L1=sorted(C1.items(), key=lambda x:x[1], reverse=True)

a0=None
a1=None

if L0[0][0]!=L1[0][0]:
	a0=L0[0][0]
	a1=L1[0][0]
elif L0[0][0]==L1[0][0]:
	a0=L0[0][0]
	if len(L1)==1:
		a1=-1
	else:
		a1=L1[1][0]


ans=0
for x in M0:
	if x!=a0:
		ans+=1

for x in M1:
	if x!=a1:
		ans+=1

print ans

Submission status: Wrong Answer

Solution code:
n = int(input())

vl = [int(x) for x in input().split()]

v1 = [v for i,v in enumerate(vl) if i%2 ==0]
v2 = [v for i,v in enumerate(vl) if i%2 ==1]

table1 = {}
table2 = {}

for x in v1:
    table1.setdefault(x,0)
    table1[x] += 1

for x in v2:
    table2.setdefault(x,0)
    table2[x] += 1

v1 = [(k,table1[k]) for k in table1]
v2 = [(k,table2[k]) for k in table2]

v1 = sorted(v1,key= lambda v: v[1],reverse=True)
v2 = sorted(v2,key= lambda v: v[1],reverse=True)

size= int(n/2)
ans=0
if v1[0][0] != v2[0][0]:
    ans += size - v1[0][1]
    ans += size - v2[0][1]
else:
    if len(v1) == 1:
        print(size)
        exit()
    if v1[1][0] < v2[1][0]:
        ans += v1[0][0]
        ans += v2[1][0]
    else:
        ans += v1[1][0]
        ans += v2[0][0]

print(ans)

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 = max(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:
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 array_0[0][1] > array_1[0][1]:
        if len(array_1) > 2:
            array_1_v = array_1[1][0]
        else:
            if array_0_v != 1:
                array_1_v = array_0_v - 1
            else:
                array_1_v = array_0_v + 1
    else:
        if len(array_0) > 2:
            array_0_v = array_0[1][0]
        else:
            if array_1_v != 1:
                array_0_v = array_1_v - 1
            else:
                array_0_v = array_1_v + 1
count = 0
for i in range(n // 2):
    if array[i * 2] != array_0_v:
        count += 1
    if array[i * 2 + 1] != array_1_v:
        count += 1

print(count)

Submission status: Wrong Answer

Solution code:
n=int(input())
v=[int(i) for i in input().split(' ')]

# 配列で最大登場する数を見つける
def find_most_common(array):
    max_int = 0
    mcnt = 0
    for s in set(array):
        if mcnt < array.count(s):
            max_int = s
            mcnt = array.count(s)
        
    return (max_int, mcnt)

# 配列で2番目に登場する数を見つける
def find_2nd_common(array):
    second_max, scnt = 0, 0
    max_int, mcnt = 0, 0
    
    for s in set(array):
        if mcnt < array.count(s):
            second_int, sec_cnt = max_int, mcnt
            max_int, mcnt  = s, array.count(s)

    return (second_int, scnt)

v_odd = v[1::2]
v_even = v[0::2]

v_odd_mc_val, v_odd_mc_cnt = find_most_common(v_odd)
v_even_mc_val, v_even_mc_cnt = find_most_common(v_even)

# 最大登場する数が同じ場合は登場回数が大きい方を採用して、少ない方は第２候補
if v_odd_mc_val == v_even_mc_val:
    if v_odd_mc_cnt > v_even_mc_cnt:
        v_even_mc_val, v_even_mc_cnt = find_2nd_common(v_even)
    else:
        v_odd_mc_val, v_odd_mc_cnt = find_2nd_common(v_odd)
    
print(len(v_odd) - v_odd_mc_cnt + len(v_even) - v_even_mc_cnt)

Submission status: Wrong Answer

Solution code:
import collections
def solve():
    _ = input()
    v = list(map(int, input().split()))
    if v.count(v[0]) == len(v):
        print(len(v) // 2)
        return
    even = v[0::2]
    odd = v[1::2]
    even_cnt = list(map(lambda x: x[0], sorted(collections.Counter(even).items(), key=lambda x: x[1], reverse=True)))
    odd_cnt = list(map(lambda x: x[0], sorted(collections.Counter(odd).items(), key=lambda x: x[1], reverse=True)))
    ev = even_cnt[0]
    od = odd_cnt[0]
    if ev == od:
        for i in range(1, len(even_cnt)):
            if even_cnt[i] == odd_cnt[i]:
                continue
            elif even_cnt[i] > odd_cnt[i]:
                ev = even_cnt[i]
                break
            else:
                od = odd_cnt[i]
                break
        else:
            ev = even_cnt[i]
    print(len(even) - even.count(ev) + len(odd) - odd.count(od))

if __name__ == '__main__':
    solve()

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)[1][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)[1][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:
import collections

N = int(input())
v = list(int(i) for i in input().split())


gu = v[0::2]
ki = v[1::2]


gc = collections.Counter(gu)
kc = collections.Counter(ki)

guc = gc.most_common()
kic = kc.most_common()

gv = gc.values()
kv = kc.values()

if guc[0][0] != kic[0][0]:
    gcount = sum(gv) - max(gv)
    kcount = sum(kv) - max(kv)
    print(gcount+kcount)
else:
    if len(guc) == 1 and len(kic) == 1 :
        print(str(guc[0][1]))
    else:
        if len(guc) == 1 and len(kic) != 1 :
            print(str(sum(gv)+sum(kv)-max(gv)-kic[1][1]))
        elif len(guc) != 1 and len(kic) == 1 :
            print(str(sum(gv)+sum(kv)-max(kv)-guc[1][1]))
        else:
            print(str(sum(gv)+sum(kv)-min((guc[1][1] + kic[0][1]), guc[0][1] + kic[1][1])))

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 = max(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:
#encoding utf-8

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


v_odd = []
v_even = []
for i in range(n):
    if i%2 == 0:
        v_odd.append(v[i])
    else:
        v_even.append(v[i])


#odd part
count={}
for i in range(len(v_odd)):
    if v_odd[i] in count.keys():
        count[v_odd[i]] += 1
    else:
        count[v_odd[i]] = 1

if len(count) == 1 or len(count) == 0:
    num = 0
else:
    for k, v in sorted(count.items(), key=lambda x: -x[1]):
        pass
    keys = list(count.keys())
    num = len(v_odd)-int(count[keys[0]])
# print(num)

#even part
count={}

for i in range(len(v_even)):
    if v_even[i] in count.keys():
        count[v_even[i]] += 1
    else:
        count[v_even[i]] = 1

if len(count) == 1 or len(count) == 0:
    num += 0
else:
    for k, v in sorted(count.items(), key=lambda x: -x[1]):
        pass
    even_keys = list(count.keys())
    num += len(v_even)-int(count[even_keys[0]])

print(num)

Submission status: Wrong Answer

Solution code:
n = int(input()) 

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

o = {}
e = {}

for i in range(int(n / 2)):
    if v[2 * i] in o:
        o[v[2 * i]] += 1
    else:
        o[v[2 * i]] = 1
    if v[2 * i+1] in e:
        e[v[2 * i+1]] += 1
    else:
        e[v[2 * i+1]] = 1

if len(e) == 1 and len(o) == 1:
    if e.keys() == o.keys():
        print(int(n / 2))
    else:
        print(0)
else:
    l = max(o.values())
    m = max(e.values())
    print(n-l-m)

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(n):
    if i % 2 == 0:
        d[ v[i] ] = d[ v[i] ] + 1
    else:
        rd[ v[i]  ] = rd[ v[i] ] + 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:
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(1)
a_2 = a_1[0][1]
b = Counter(v_2)
b_1 = b.most_common(1)
b_2 = b_1[0][1]

print(n - a_2 - b_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_key_even, most_val_even = collections.Counter(vs_even).most_common(1)[0]
    most_key_odd, most_val_odd = collections.Counter(vs_odd).most_common(1)[0]

    if most_key_even == most_key_odd:
        # 変換したら、1種類の数になってしまう
        # ex.) vs = [1 2 1 2 1 2 2 2 2 2 2 2 2 2]
        # ので、
        if most_val_even >= most_val_odd:
            print(most_val_odd)
        else:
            print(most_val_even)
        exit()

    ans = 0
    len_vs_even = len(vs_even)
    ans += len_vs_even - most_val_even
    ans += len_vs_even - most_val_odd

    print(ans)



if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
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)

    if count_seq_even[0][0] >= count_seq_odd[0][0]:
        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
    else:
        seq_odd_select = count_seq_odd[0][0]
        seq_even_select = -1
        for k, v in count_seq_even:
            if k != seq_odd_select:
                seq_even_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:
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]
res = 0
for i in tmp_array:
    if i != tmp:
       res += 1

tmp2 = sorted_dict2[0][0]
for i in tmp_array2:
    if i != tmp2:
       res += 1
print(res if sorted_dict != sorted_dict2 else len(array)//2)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
v = list(map(int, input().split()))
gu = []
ki = []
ans = 0
if v.count(v[0]) == len(v):
    ans += len(v) // 2
else:
    for i, v in enumerate(v,1):
        if i % 2 == 1:
            ki.append(v)
        else:
            gu.append(v)

    kic = list(Counter(ki).values())
    guc = list(Counter(gu).values())
    kic.sort(reverse = True)
    guc.sort(reverse = True)
    if len(kic) != 1:
        ans += sum(kic[1::]) 
    if len(guc) != 1:
        ans += sum(guc[1::])
print(ans)

Submission status: Wrong Answer

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


def main():
    from collections import Counter

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

    if len(v) == 1:
        print(half)
        exit()
    else:
        ans1 = 0
        ans2 = 0
        numbers = v.most_common(2)
        most_commons = [numbers[0][0], numbers[1][0]]

        for i, value in enumerate(v.keys()):
            if i % 2 == 0:
                if most_commons[0] != value:
                    ans1 += 1
            else:
                if most_commons[1] != value:
                    ans1 += 1

        for i, value in enumerate(v.keys()):
            if i % 2 == 0:
                if most_commons[1] != value:
                    ans2 += 1
            else:
                if most_commons[0] != value:
                    ans2 += 1

        print(min(ans1, ans2))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n=int(input())
V=list(map(int, input().split(" ")))
d1=[0 for i in range(100000)]
for i in V[::2]:
    d1[i-1]+=1
d2=[0 for i in range(100000)]
for i in V[1::2]:
    d2[i-1]+=1

in1=d1.index(max(d1))
in2=d2.index(max(d2))
if in1 == in2:
    if max(d1)>max(d2):
        d2[in2]=0
    else:
        d1[in1]=0

#print(d1[:5])
#print(d2[:5])
tmp1=n/2-max(d1)
tmp2=n/2-max(d2)
print(int(tmp1+tmp2))

Submission status: Wrong Answer

Solution code:
import collections

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

def count_elem(x):
    coll = collections.Counter(x)
    return coll.most_common()

b = count_elem(a[::2])
c = count_elem(a[1::2])

if b[0][0] != c[0][0]:
    print(len(a) - b[0][1] - c[0][1])
else:
    if b[0][1] >= c[0][1]:
        if len(c) > 1:
            print(len(a) - b[0][1] - c[1][1])
        else:
            print(len(a) - b[0][1])
    else:
        if len(b) > 1:
            print(len(a) - b[1][1] - c[0][1])
        else:
            print(len(a) - c[0][1])

Submission status: Wrong Answer

Solution code:
#!/Library/Frameworks/Python.framework/Versions/3.5/bin/python3
from collections import defaultdict

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

d0 = defaultdict(int)
d1 = defaultdict(int)
for i in range(len(v)):
    if i % 2 == 1:
        d1[v[i]] += 1
    else:
        d0[v[i]] += 1

max1 = 0
max12 = 0
for i in d1.keys():
    if max1 < d1[i]:
        max12 = max1
        max1 = d1[i]
        max1n = i
    elif max12 < d1[i]:
        max12 = d1[i]
max0 = 0
max02 = 0
for i in d0.keys():
    if max0 < d0[i]:
        max02 = max0
        max0 = d0[i]
        max0n = i
    elif max02 < d0[i]:
        max02 = d0[i]
if max1n == max0n:
    if max0 < max1:
        print(int(n / 2 - max02 + n / 2 - max1))
    else:
        print(int(n / 2 - max0 + n / 2 - max12))
else:
    print(int(n / 2 - max0 + n / 2 - max1))