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]==v1C[-1][0]:
    if a>=b:
        b=v2C[len(v2C)-2][1]
    else:
        a=v1C[len(v1C)-2][1]
if len(list(Counter(v).items()))==1:
    print(n//2)
else:
    print(len(v1)-a+len(v2)-b)

Submission status: Wrong Answer

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

sorted_dict = sorted(dict_.items(), key=lambda x: x[1], reverse=True)
res = 0
if len(sorted_dict) == 1:
    print(len(array)//2)
else:
    tmp = len(array)//2
    for j in sorted_dict[:3]:
        if j[1] > tmp:
            res += abs(j[1]-tmp)
    for i in sorted_dict[2:]:
        res += i[1]
    print(res)

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)[-1]
odd_max = sorted(odd)[-1]

if odd_max == even_max:
    even_max = -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:
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:
		print(n-max(c+b[max(b)],d+a[max(a)]))

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])
    else:
        print(len(numbers) - oddCountToNumber[0][0] - evenCountToNumber[1][0])
else:
    print(len(numbers) - oddCountToNumber[0][0] - evenCountToNumber[0][0])

Submission status: Wrong Answer

Solution code:
a = input()
dict1 = dict()
dict2 = dict()
counter = 0
b = input().split()
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])

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])
else:
	print(len(b) - dict1list[-1][1] - dict2list[-1][1])

Submission status: Wrong Answer

Solution code:
n = int(input())
list_v = list((map(int, input().split())))
list_e = list_v[::2]
list_o = list_v[1::2]
dict_e = {}
dict_o = {}
for number in set(list_e):
    dict_e[number] = 0
for i in range(0,int(n/2)):
    dict_e[list_e[i]] += 1
for number in set(list_o):
    dict_o[number] = 0
for i in range(0,int(n/2)):
    dict_o[list_o[i]] += 1
e_max = 0
o_max = 0
for key in dict_e.keys():
    if dict_e[key] > e_max:
        e_max = dict_e[key]
        e_key = key

for key in dict_o.keys():
    if dict_o[key] > o_max:
        o_max = dict_o[key]
        o_key = key

if e_key == o_key:
    if o_max >= e_max:
        e_max = 0
        for key in dict_e.keys():
            if dict_e[key] > e_max and key != o_key:
                e_max = dict_e[key]
                e_key = key
    else:
        o_max = 0
        for key in dict_o.keys():
            if dict_o[key] > o_max and key != e_key:
                o_max = dict_o[key]
                o_key = key

print(n - (e_max + o_max))

Submission status: Wrong Answer

Solution code:
n = int(input())

v_list = list(map(int, input().split()))
a1_dict = {}
a2_dict = {}
for i in range(int(n/2)):
  a1 = v_list[i*2]
  a2 = v_list[i*2 + 1]
  if a1 not in a1_dict:
    a1_dict[a1] = 1
  else:
    a1_dict[a1] += 1
  if a2 not in a2_dict:
    a2_dict[a2] = 1
  else:
    a2_dict[a2] += 1
a1_max = max(a1_dict.values())
a2_max = max(a2_dict.values())
print(n - a1_max - a2_max)

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 = n - evens[0][1]
        else:
            ans = n - evens[0][1] - odds[1][1]
    else:
        if len(evens) == 1:
            ans = ans = n - odds[0][1]
        else:
            ans = n - odds[0][1] - evens[1][1]
print(ans)

Submission status: Wrong Answer

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

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

_v = list(v)

print(len(_v[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 = Counter(ki).values()
    guc = Counter(gu).values()
    if len(kic) != 1:
        ans += min(kic)
    if len(guc) != 1:
        ans += min(guc)

print(ans)

Submission status: Wrong Answer

Solution code:
import collections as cole


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

v1 = v[::2]   #odd
v2 = v[1::2]  #even

d1 = cole.Counter(v1)
max1 = max(d1)

d2 = cole.Counter(v2)
max2 = max(d2)

count = 0

for i in v1:
    if i != max1:
        count += 1

for i in v2:
    if i != max2:
        count += 1


print(count)

Submission status: Wrong Answer

Solution code:
# coding:utf-8

INF = float('inf')


def inpl(): return list(map(int, input().split()))


N = int(input())
V = inpl()

tmp = {}
A = [0 for _ in range(10**5+1)]
for i in range(0, N, 2):
    A[V[i]] += 1
    if str(V[i]) not in tmp:
        tmp[str(V[i])] = 1
    else:
        tmp[str(V[i])] += 1

# print(max(tmp), tmp)

tmp2 = {}
for i in range(1, N, 2):
    if str(V[i]) not in tmp2:
        tmp2[str(V[i])] = 1
    else:
        tmp2[str(V[i])] += 1

# print(max(tmp2), tmp2)

if max(tmp) == max(tmp2):
    A.sort()
    ans = N - A[-2] - tmp2[max(tmp2)]
else:
    ans = N - tmp[max(tmp)] - tmp2[max(tmp2)]

print(ans)

Submission status: Wrong Answer

Solution code:
import collections


n = input()
s = input().split(' ')

even = collections.Counter(s[1::2])
odd = collections.Counter(s[0::2])
maxeven = even.most_common()[0]
maxodd = odd.most_common()[0]
ans = 0
if maxeven[0] != maxodd[0]:
    ans = len(s) - maxeven[1] - maxodd[1]
elif len(s) == maxeven[1] + maxodd[1]:
    ans = len(s) - maxeven[1]
else:
    nexteven = even.most_common()[1]
    nextodd = odd.most_common()[1]
    if maxeven[1] >= maxodd[1]:
        ans = len(s) - maxeven[1] - nextodd[1]
    else:
        ans = len(s) - maxodd[1] - nexteven[1]

print(ans)

Submission status: Wrong Answer

Solution code:
import collections

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

import collections
c = collections.Counter(vlist)

head = c.most_common()[0][0]
if c.most_common()[0][1] == n:
    foll = -1
else:
    foll = c.most_common()[1][0]


for i in range(len(vlist)):
    if vlist[i] == head:
        break
    if vlist[i] == foll:
        head, foll == foll, head
        break

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

print(count)

Submission status: Wrong Answer

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

fix = 0

for x in range(0, len(v) - 2):
    if v[x] != v[x + 2]:
        v[x + 2] = v[x]
        fix += 1

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

print(fix)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
d={}
sum=0
maxs=-9999
maxs2=-9999
d[maxs]=d[maxs2]=0
for i in a:
    if i in d:
        d[i]+=1
        if d[i]>d[maxs] and i!=maxs:
            maxs2=maxs
            maxs=i
            continue
        if  d[i]>d[maxs2] and i!=maxs and i!=maxs2:
            maxs2=i
    else:
        d[i]=1
        sum+=1
        if d[i]>d[maxs] and i!=maxs:
            maxs2=maxs
            maxs=i
            continue
        if d[i]>d[maxs2] and i!=maxs and i!=maxs2:
            maxs2=i
if sum>2:
    print(int(n-d[maxs]-d[maxs2]))
elif sum==2:
    print(int(n/2-d[maxs2]))
else:
    print(int(n/2))

Submission status: Wrong Answer

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

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

mo=0
me=0
for i in range(10):
    if mo < o.count(i):
        mo=o.count(i)

for i in range(10):
    if me < e.count(i):
        me=e.count(i)

print(len(v)-mo-me)

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)
n1=m1.most_common()[0][1]
m2=collections.Counter(v2)
n2=m2.most_common()[0][1]
print(n-n1-n2)

Submission status: Wrong Answer

Solution code:
n = int(input())
v = list(map(int,input().split()))
O = [0 for k in range(max(v)+1)]
E = [0 for k in range(max(v)+1)]

for k in range(n):
    if k%2 == 0:
        E[v[k]] += 1
    else:
        O[v[k]] += 1
if E.index(max(E)) != O.index(max(O)):
    print(n - max(E) - max(O))
else:
    if max(E) >= max(O):
        p = O.index(max(O))
        O[p] = 0
        q = max(O)
        print(n - max(E) - q)
    else:
        p = E.index(max(E))
        E[p] = 0
        q = max(E)
        print(n - max(O) - q)

Submission status: Wrong Answer

Solution code:
import collections

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

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

ans = int(n / 2) - evel.most_common()[0][1] + int(n / 2) - odd.most_common()[0][1]
if evel == odd:
    print(int(n / 2))
else:
    print(ans)

Submission status: Wrong Answer

Solution code:
import sys
Input = sys.stdin.readline

n = int(Input())
v = list(map(int, Input().split()))
count = 0
count1 = 0
count2 = 0

v1 = v[0::2]
v1_count = {}
for i in v1:
    if i not in v1_count:
        v1_count[i] = 1
    else:
        v1_count[i] += 1

v1_count = sorted(v1_count.items(), key=lambda i: i[1], reverse=True)
count1 += len(v1) - v1_count[0][1]

v2 = v[1::2]
v2_count = {}
for i in v2:
    if i not in v2_count:
        v2_count[i] = 1
    else:
        v2_count[i] += 1

v2_count = sorted(v2_count.items(), key=lambda i: i[1], reverse=True)
count2 += len(v1) - v2_count[0][1]

if v1_count[0][0] == v2_count[0][0]:
    if v1_count[0][1] >= v2_count[0][1]:
        count = count1 + len(v2)
    else:
        count = count2 + len(v1)
else:
    count = count1 + count2

print(count)

Submission status: Wrong Answer

Solution code:
from collections import Counter
N = int(input())
A = list(map(int, input().split()))
c1 = Counter(A[::2])
c2 = Counter(A[1::2])
c1m = sorted(c1.items(), key=lambda x:x[1])
c2m = sorted(c2.items(), key=lambda x:x[1])
tmp = N - c1m[0][1] - c2m[0][1]
if tmp == 0:
    if c1m[0][0] == c2m[0][0]:
        print(N // 2)
        exit()
else:
    if c1m[0] == c2m[0]:
        len_c1m = len(c1m)
        len_c2m = len(c2m)
        if c1m[0][1] == c2m[0][1]:
            if len_c1m == 2 and len_c2m == 2:
                if c1m[1][1] > c2m[1][1]:
                    print(N - c2m[0][1] - c1m[1][1])
                    exit()
                else:
                    print(N - c1m[0][1] - c2m[1][1])
                    exit()
            elif len_c1m == 2:
                print(N - c2m[0][1] - c1m[1][1])
                exit()
            else:
                print(N - c1m[0][1] - c2m[1][1])
                exit()
print(tmp)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
n=int(input())
v=[int(x) for x in input().split()]
if len(set(v))==1:
    print(n//2)
    import sys
    sys.exit()
from collections import Counter
v1=[]
v2=[]
for i in range(n):
    if i%2==0:
        v1.append(v[i])
    else:
        v2.append(v[i])
v1=Counter(v1)
v2=Counter(v2)
ans=10**10
# print(v1,v2)
for i1 in v1.most_common(min(len(v1),10)):
    for i2 in v2.most_common(min(len(v2),10)):
        # print(n-i1[1]-i2[1],i1,i2)
        ans=min(n-i1[1]-i2[1],ans)
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
d={}
sum=0
maxs=-9999
maxs2=-9999
d[maxs]=d[maxs2]=0
for i in a:
    if i in d:
        d[i]+=1
        if d[i]>d[maxs] and i!=maxs:
            maxs2=maxs
            maxs=i
        if d[i]<=d[maxs] and d[i]>d[maxs2] and i!=maxs and i!=maxs2:
            maxs2=i
    else:
        d[i]=1
        sum+=1
        if d[i]>d[maxs] and i!=maxs:
            maxs2=maxs
            maxs=i
        if d[i]<=d[maxs] and d[i]>d[maxs2] and i!=maxs and i!=maxs2:
            maxs2=i
if sum>2:
    print(int(n-d[maxs]-d[maxs2]))
elif sum==2:
    print(int(n/2-d[maxs2]))
else:
    print(int(n/2))

Submission status: Wrong Answer

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

min_num = 0

even = set()
odd = set()

for i, v in enumerate(v_list):
    if i % 2 == 0:
        even.add(v)
    else:
        odd.add(v)
even_max = max(list(even))
odd_max = max(list(odd))

if odd_max == even_max:
    even_max = -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:
from collections import Counter
n=int(input())
l=list(map(int,input().split()))
cou=Counter(l)
leng=len(list(cou.values()))
count=0
v=0
if(leng>=2):
    for i in range(n-2):
        if(l[i]!=l[i+2]):
            l[i+2]=l[i]
            count+=1
else:
    print(n//2)
    exit()
print(count)

Submission status: Wrong Answer

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

O = {}
E = {}

for i in range(N//2):
  if A[2*i] in O:
    O[A[2*i]] += 1
  else:
    O[A[2*i]] = 1
  if A[2*i+1] in E:
    E[A[2*i+1]] += 1
  else:
    E[A[2*i+1]] = 1

O = sorted(O.items(), key=itemgetter(1), reverse=True)      
E = sorted(E.items(), key=itemgetter(1), reverse=True)   

if O[0][0] != E[0][0]:
  print(N - O[0][1] - E[0][1])
else:
  if O[0][1] >= E[0][1]:
    print(N - O[0][1] - (E[1][1] if len(E) > 1 else 0))
  else:
    print(N - E[0][1] - (O[1][1] if len(O) > 1 else 0))

Submission status: Wrong Answer

Solution code:
import collections


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

V0 = [V[i] for i in range(len(V)) if i % 2 == 0]
V1 = [V[i] for i in range(len(V)) if i % 2 == 1]

c0 = collections.Counter(V0)
c1 = collections.Counter(V1)

R = (n // 2) + (n % 2) - c0.most_common()[0][1]

if c0.most_common()[0] != c1.most_common()[0]:
    R += (n // 2) - c1.most_common()[0][1]
else:
    try:
        R += (n // 2) - c1.most_common()[1][1]
    except:
        R += (n // 2)

print(R)

Submission status: Wrong Answer

Solution code:
n = int(input())

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

v.sort()

if v.count(v[0]) == n:
    print(n // 2)
    exit(0)

flag = 0
finish = []
finish_count = []


for i in range(n):
    if v[i] not in finish:
        finish.append(v[i])
        finish_count.append(v.count(v[i]))

#print(finish)
#print(finish_count)

if len(finish) == 2:
    print("0")

else:
    finish_count.sort()
    print(finish_count[0])

#print(v)

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)
if max(b2)!=max(c2):
    print(n-b2[max(b2)]-c2[max(c2)])
else:
    if b2[max(b2)] > c2[max(c2)]:
        c3=[i for i in c if i!=max(b2)]
        if len(c3)>0:
            c4=Counter(c3)
            print(n-b2[max(b2)]-c4[max(c4)])
        else:print(n-b2[max(b2)])
    else:
        b3=[i for i in b if i!=max(b2)]
        if len(b3)>0:
            b4=Counter(b3)
            print(n-b4[max(b4)]-c2[max(c2)])
        else:print(n-c2[max(c2)])

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())
    ans = 0
    ans += sum(elv) - max(elv)
    ans += sum(olv) - max(olv)
    print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
even={}
odd={}
for i,x in enumerate(list(map(int,input().split()))):
    if i%2==0:
        if even.get(x,0)==0:
            even[x]=1
        else:
            even[x]+=1
    else:
        if odd.get(x,0)==0:
            odd[x]=1
        else:
            odd[x]+=1

even=sorted(even.items(),key=lambda x:x[1])
odd=sorted(odd.items(),key=lambda x:x[1])
ans=0
if even[-1][0]==odd[-1][0]:
    if len(even)==1 and len(odd)==1:
        ans=n//2
    elif even[-1][1]>odd[-1][1]:
        ans=n-even[-1][1]-odd[-2][1]
    else:
        ans=n-even[-2][1]-odd[-1][1]
else:
    ans=n-even[-1][1]-odd[-1][1]
print(ans)

Submission status: Wrong Answer

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

numberL.sort()
syuruiL=[]
kosuuL=[]

index=0
beforeC=""
count=0
while index < n:
    if index==0:
        beforeC=numberL[index]
        count+=1
    else:
        if beforeC == numberL[index]:
            count+=1
        else:
            syuruiL.append(beforeC)
            kosuuL.append(count)
            beforeC=numberL[index]
            count=1
    index+=1
syuruiL.append(beforeC)
kosuuL.append(count)

if len(syuruiL)==2:
    print(0)
elif len(syuruiL)==1:
    print(int(kosuuL[0]/2))
else:
    kosuuL.sort()
    index2 =0
    sum=0
    while index2 < len(syuruiL)-2:
        sum+=kosuuL[index2]
        index2+=1
    print(sum)

Submission status: Wrong Answer

Solution code:
import collections

def inputN(typ=str):
    return map(typ, raw_input().split())


N = inputN(int)[0]
v = inputN(int)

col0 = collections.Counter(v[::2])
col1 = collections.Counter(v[1::2])
X0 = col0.most_common()
X1 = col1.most_common()


if X0[0][0] == X1[0][0]:
    if len(X0) == 1 and len(X1) == 1:
        k0 = N / 2
        k1 = 0
    elif X0[1][1] >= X1[1][1]:
        k0 = X0[0][1]
        k1 = X1[1][1]
    elif X0[1][1] < X1[1][1]:
        k0 = X0[1][1]
        k1 = X1[0][1]
else:
    k0 = X0[0][1]
    k1 = X1[0][1]

print N - k0 - k1

Submission status: Wrong Answer

Solution code:
def c_zigzag(N, V):
    ans = 0
    for i in range(2, N - 1, 2):
        if V[i] != V[i - 2]:
            ans += 1
            V[i] = V[i - 2]
    for i in range(1, N, 2):
        if V[i] != V[i - 2]:
            ans += 1
            V[i] = V[i - 2]
    if V[0] == V[1]:
        ans += N // 2
    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 = 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]
	subs = (up - down) / 2
	subs += n - up - down
	
	print subs

Submission status: Wrong Answer

Solution code:
def solve():
    _ = input()
    v = list(map(int, input().split()))
    if v.count(v[0]) == len(v):
        print(len(v) // 2)
        return
    even = sorted(v[0::2], reverse=True)
    odd = sorted(v[1::2], reverse=True)
    print(len(even) - even.count(even[0]) + len(odd) - odd.count(odd[0]))

if __name__ == '__main__':
    solve()

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-a-b[max(b)])
	elif len(b) == 0:
		print(n-b-a[max(a)])
	else:
		print(n-max(c+b[max(b)],d+a[max(a)]))

Submission status: Wrong Answer

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

odd_cnt = Counter([v[i] for i in range(0, n, 2)])
even_cnt = Counter([v[i] for i in range(1, n, 2)])
odd_maxv = odd_cnt.most_common()[0][0]
ans = 0
for i in range(0, n, 2):
    if v[i] == odd_maxv:
        continue
    ans += 1

even_maxv = 0
flag = False
falied = True
for t in even_cnt.most_common():
    even_maxv = t[0]
    if even_maxv != odd_maxv:
        falied = False
        break

if falied:
    ans += sum(1 for _ in range(1, n, 2))
    print(ans)
    import sys
    sys.exit()

for i in range(1, n, 2):
    if v[i] == even_maxv:
        continue
    ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

c0 = Counter(v)
if len(c0) == 1:
    ans = n // 2
else:
    c1 = Counter(v[::2])
    c2 = Counter(v[1::2])

    x1 = sum(c1.values()) - max(c1.values())
    x2 = sum(c2.values()) - max(c2.values())

    ans = x1 + x2
print(ans)

Submission status: Wrong Answer

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

_i = v[0]
j = 0

for i in v:
    if _i != i:
        break
else:
    print(int(n / 2))
    exit(0)

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

print(j)

Submission status: Wrong Answer

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

fix = 0

for x in range(0, len(v) - 2):
    if v[x] != v[x + 2]:
        fix += 1
    if v[x] == v[x + 1]:
        fix += 1

print(fix)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

odd = a[::2]
even = a[1::2]
#print(odd,even)
if odd==even: print(N//2)
else:
    cnt_odd = Counter(odd)
    cnt_even = Counter(even)
    #print(cnt_odd,cnt_even)
    print(N - sorted(cnt_odd.values())[-1] - sorted(cnt_even.values())[-1])

Submission status: Wrong Answer

Solution code:
n=int(input())
l=list(map(int,input().split()))
count=0
v=0
for i in range(n-2):
    if(l[i]!=l[i+2] or (l[i]==l[i+1] and v<2)):
        if(l[i]==l[i+1]):
            v+=1
        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

    if max_A == max_B:
        if max_A_num <= max_B_num:
            max_A_num = 0
            for A in A_dic:
                if A != max_A:
                    max_A_num = max(max_A_num, A_dic[A])
        else:
            max_B_num = 0
            for B in B_dic:
                if B != max_B:
                    max_B_num = max(max_B_num, B_dic[B])

    print N - max_A_num - max_B_num




if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n=int(input())
even={}
odd={}
for i,x in enumerate(list(map(int,input().split()))):
    if i%2==0:
        if even.get(x,0)==0:
            even[x]=1
        else:
            even[x]+=1
    else:
        if odd.get(x,0)==0:
            odd[x]=1
        else:
            odd[x]+=1

even=sorted(even.items())
odd=sorted(odd.items())
ans=0
if even[-1][0]==odd[-1][0]:
    if len(even)==1 and len(odd)==1:
        ans=n//2
    elif even[-1][1]>odd[-1][1]:
        ans=n-even[-1][1]-odd[-2][1]
    else:
        ans=n-even[-2][1]-odd[-1][1]
else:
    ans=n-even[-1][1]-odd[-1][1]
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
arr=list(map(int,input().strip().split()))
cnt=0
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:
n = int(input())
numberL = list(map(int, input().split()))

numberL.sort()
syuruiL=[]
kosuuL=[]

index=0
beforeC=""
count=0
while index < n:
    if index==0:
        beforeC=numberL[index]
        count+=1
    else:
        if beforeC == numberL[index]:
            count+=1
        else:
            syuruiL.append(beforeC)
            kosuuL.append(count)
            beforeC=numberL[index]
            count+=1
    index+=1
syuruiL.append(beforeC)
kosuuL.append(count)

if len(syuruiL)==2:
    print(0)
elif len(syuruiL)==1:
    print(int(kosuuL[0]/2))
else:
    kosuuL.sort()
    index2 =0
    sum=0
    while index2 < len(syuruiL)-2:
        sum+=kosuuL[index2]
        index2+=1
    print(sum)

Submission status: Wrong Answer

Solution code:
n = int(input())
arr = list(map(int, input().split()))
d0 = {}
d1 = {}
for i,a in enumerate(arr):
  if i%2==0:
    if a not in d0:
      d0[a] = 1
    else:
      d0[a] += 1
  else:
    if a not in d1:
      d1[a] = 1
    else:
      d1[a] += 1
maxlen0 = sorted(d0.items(), key=lambda x:-x[1])[0][1]
maxlen1 = sorted(d1.items(), key=lambda x:-x[1])[0][1]
print(n - maxlen0 - maxlen1)

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 len(list(Counter(v).items()))==1:
    print(n//2)
else:
    print(len(v1)-a+len(v2)-b)

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)):
  cou += abs(numa1 -lisa[i])
  co += abs(numa2 -lisa[i])
num = 0
nu = 0
for i in range(len(lisb)):
  num += abs(numb1 -lisb[i])
  nu += abs(numb2 -lisb[i])
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:
n = int(input())
array = [int(x) for x in input().split()]
dict_ = {}
for i in array:
    if i in dict_.keys():
        dict_[i] += 1
    else:
        dict_[i] = 1

sorted_dict = sorted(dict_.items(), key=lambda x: x[1], reverse=True)
res = 0
if len(sorted_dict) == 1:
    print(len(array)//2)
else:

    for i in sorted_dict[2:]:
        res += i[1]
    print(res)