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:
import collections

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

v_odd = []
for i in range(0, n, 2):
    v_odd.append(v[i])
v_even = []
for i in range(1, n, 2):
    v_even.append(v[i])

odd_dic = collections.Counter(v_odd)
odd_sort = sorted(odd_dic.items(), key=lambda x: -x[1])
odd_maxkey = odd_sort[0][0]
odd_cnt1 = odd_sort[0][1]
if len(odd_sort) > 1:
    odd_cnt2 = odd_sort[1][1]
else:
    odd_cnt2 = 0

even_dic = collections.Counter(v_even)
even_sort = sorted(even_dic.items(), key=lambda x: -x[1])
even_maxkey = even_sort[0][0]
even_cnt1 = even_sort[0][1]
if len(even_sort) > 1:
    even_cnt2 = even_sort[1][1]
else:
    even_cnt2 = 0

ans = 0
if odd_maxkey == even_maxkey:
    ans = max(len(v_odd)-odd_cnt1 + len(v_even)-even_cnt2, len(v_odd)-odd_cnt2 + len(v_even)-even_cnt1)
else:
    ans = len(v_odd)-odd_cnt1 + len(v_even)-even_cnt1


#print(odd_cnt1)
#print(odd_cnt2)
#print(even_cnt1)
#print(even_cnt2)

print(ans)

Submission status: Wrong Answer

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


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

    if len(set(v)) == 1:
        print(half)
        exit()
    else:
        ans1 = 0
        ans2 = 0
        v1 = v[0]
        v2 = v[1]

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

        for i in range(2, n):
            if i % 2 == 0:
                if v[i] != v2:
                    ans2 += 1
            else:
                if v[i] != v1:
                    ans2 += 1

        print(min(ans1, ans2))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
nums = list(map(int,input().split()))
a = []
b = []
for i in range(n):
    if i%2 == 0:
        b.append(nums[i])
    else:
        a.append(nums[i])
acol = collections.Counter(a)
bcol = collections.Counter(b)
amost = acol.most_common()[0][1]
bmost = bcol.most_common()[0][1]
if acol.most_common()[0][0] != bcol.most_common()[0][0]:    
    f = amost + bmost
    print(n-f)
elif len(acol.most_common()) != 1 and len(bcol.most_common()) != 1:
    if acol.most_common()[0][1] + bcol.most_common()[1][1] > acol.most_common()[1][1] + bcol.most_common()[0][1]:
        print(n-acol.most_common()[0][1] + bcol.most_common()[1][1])
    else:
        print(n-acol.most_common()[1][1] + bcol.most_common()[0][1])
elif len(acol.most_common()) == 1 and len(bcol.most_common()) != 1:
    print(n-(acol.most_common()[0][1]+bcol.most_common()[1][1]))
elif len(bcol.most_common()) == 1 and len(acol.most_common()) != 1:
    print(n-(acol.most_common()[1][1]+bcol.most_common()[0][1]))
else:
    print(n//2)

Submission status: Wrong Answer

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


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

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

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

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

Submission status: Wrong Answer

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

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

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

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

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

Submission status: Wrong Answer

Solution code:
import collections

n = int(input())
v = list(map(int, input().split()))
a = v[::2]
b = v[1::2]
ac = collections.Counter(a)
bc = collections.Counter(b)
ac = sorted(ac.items(), key=lambda x: x[1], reverse=True)
bc = sorted(bc.items(), key=lambda x: x[1], reverse=True)
if ac[0][0] == bc[0][0]:
    if len(ac) == len(bc) and len(ac) == 1:
        print(ac[0][1])
        exit()
    if ac[0][1] > bc[0][1]:
        ac.remove(ac[0])
        bc.remove(bc[1])
    else:
        ac.remove(ac[1])
        bc.remove(bc[0])
else:
    ac.remove(ac[0])
    bc.remove(bc[0])
ans = 0
for i in range(len(ac)):
    ans += ac[i][1]
for i in range(len(bc)):
    ans += bc[i][1]
print(ans)

Submission status: Wrong Answer

Solution code:
import collections

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

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

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

Submission status: Wrong Answer

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

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

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

for i in range(n //2):
    if even[i] == odd[i]:
        result = result + 1

print(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 + 1

Submission status: Wrong Answer

Solution code:
from collections import Counter


def main():
    n = int(input())
    lines = [int(x) for x in input().split()]
    g = lines[::2]
    k = lines[1::2]
    sub = 0
    j = False
    if len(set(lines)) == 1:
        result = int(n / 2)
    elif len(set(g)) is len(set(k)) is 1:
        result = 0
    if len(set(g)) is not 1:
        sub += n / 2 - Counter(g).most_common()[0][1]
        j = True
    if len(set(k)) is not 1:
        sub += n / 2 - Counter(k).most_common()[0][1]
        j = True
    if j is True:
        result = int(sub)
    print(result)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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


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

    if len(set(v)) == 1:
        print(half)
        exit()
    else:
        ans = 0
        v1 = v[0]
        v2 = v[1]

        for i in range(2, n):
            if i % 2 == 0:
                if v[i] != v1:
                    ans += 1
            else:
                if v[i] != v2:
                    ans += 1

        print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())

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

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

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

c = 0
d = 0
e = 0
f = 0
g = 0
h = 0
for i in a:
    if a[i] >= c:
        c = i
        e = a[i]
for i in b:
    if b[i] >= d:
        d = i
        f = b[i]

if c != d:
    print(n-e-f)
else:
    a.pop(c)
    b.pop(d)
    for i in a:
        if a[i] >= g:
            g = a[i]
    for i in b:
        if b[i] >= h:
            h = b[i]
    print(n-(max(f+g,e+h)))

Submission status: Wrong Answer

Solution code:
# coding: utf-8
import collections

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

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

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

print(ans)

Submission status: Wrong Answer

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

v1 = V[0::2]
v2 = V[1::2]

f1 = Counter(v1).most_common(2)
f2 = Counter(v2).most_common(2)

ans = 0

if len(set(v1)) == len(set(v2)) == 1:
    if v1 != v2:
        ans = len(v2)
else:
    if f1[0][0] != f2[0][0]:
        ans = (len(v1) - f1[0][1]) + (len(v2) - f2[0][1])
    else:
        if f1[0][1] > f2[0][1]:
            ans = (len(v1) - f1[0][1]) + (len(v2) - f2[1][1])
        else:
            ans = (len(v1) - f1[1][1]) + (len(v2) - f2[0][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][1] == v1[0][1] or v2[1][1] == v2[0][1]:
        ans += size - v1[0][1]
        ans += size - v2[0][1]
    elif 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 = list(map(int, input().split()))

a = []
b = []

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

max_a = 0
max_b = 0

for ns in set(a):
    c_a = a.count(ns)
    if c_a > max_a:
        max_a = c_a
for ns in set(b):
    c_b = b.count(ns)
    if c_b > max_b:
        max_b = c_b

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

Submission status: Wrong Answer

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

a = set()
b = set()

for i in range(n):
    if i % 2 == 1:
        a.add(v[i])
for j in range(n):
    if j % 2 == 0:
        b.add(v[j])

if a == b:
    print(n//2)
else:
    print(len(a) + len(b) -2)

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 and len(even_max):
        odd_num = 10 ** 5 + 1
    elif len(odd_max) == 1:
        even_num = even_max[1][0]
    elif len(even_max) == 1:
        odd_num = odd_max[1][0]
    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_max[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:
n = int(input())
l = [int(_) for _ in input().split()]

dict_e = {}
for i in range(1, n, 2):
    if l[i] in dict_e.keys():
        dict_e[l[i]] += 1
    else:
        dict_e[l[i]] = 1

even_key, even_value = max(dict_e.items(),key = lambda x:x[1])

dict_a = {}
for i in range(0, n, 2):
    if l[i] in dict_a.keys():
        dict_a[l[i]] += 1
    else:
        dict_a[l[i]] = 1

add_key, add_value = max(dict_a.items(),key = lambda x:x[1])

if even_key != add_key:
    ans = n - even_value - add_value
else:
    if even_value > add_value:
        if len(dict_a) >= 2:
            add_value = sorted(dict_a.items(), key = lambda x:x[1])[-2][1]
        else:
            add_value = 0
        ans = n - even_value - add_value
    else:
        if len(dict_e) >= 2:
            even_value = sorted(dict_e.items(), key = lambda x:x[1])[-2][1]
        else:
            even_value = 0
        ans = n - even_value - add_value

print(ans)

Submission status: Wrong Answer

Solution code:
import collections

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

if odd_c.most_common(1)[0][0] == even_c.most_common(1)[0][0]:
    odd_next_most = 0
    even_next_most = 0
    if len(odd_c) >= 2:
        odd_next_most = odd_c.most_common(2)[1][1]
    if len(even_c) >= 2:
        even_next_most = even_c.most_common(2)[1][1]
    if odd_next_most > even_next_most:
        print(len(odd) - odd_next_most)
    else:
        print(len(even) - even_next_most)
else:
    odd_change = len(odd) - odd_c.most_common(1)[0][1]
    even_change = len(even) - even_c.most_common(1)[0][1]
    print(odd_change + even_change)

Submission status: Wrong Answer

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

O = A[0::2]
E = A[1::2]
mco = Counter(O).most_common()
mce = Counter(E).most_common()

l = len(O) # == len(E)
if mco[0][0] == mce[0][0]:
    if len(mco) == 1 and len(mce) == 1:
        print(l)
    elif len(mco) == 1:
        print(l - mce[1][1])
    elif len(mce) == 1:
        print(l - mco[1][1])
    else:
        print(l - max(mco[1][1], mce[1][1]))
else:
    print((len(O) - mco[0][1]) + (len(E) - mce[0][1]))

Submission status: Wrong Answer

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

d = defaultdict(lambda: 0)
rd = defaultdict(lambda: 0)
d[0] = 0
rd[0] = 0

ll = (n) // 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:
#coding: utf-8
from collections import Counter

n = int(input())
li = [int(x) for x in input().split()]
li_o = [li[i] for i in range(n) if i%2==0]
li_e = [li[i] for i in range(n) if i%2!=0]

if li_o == li_e:
    print(len(li_o))
else:
    val_o = Counter(li_o)
    val_o2 = len(li_o) - li_o.count(val_o.most_common()[0][0])

    val_e = Counter(li_e)
    val_e2 = len(li_e) - li_e.count(val_e.most_common()[0][0])
    print(val_o2 + val_e2)

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

if evel == odd:
    print(int(n / 2))
else:
    if evel.most_common()[0][0] == odd.most_common()[0][0]:
        el = evel.most_common(50)
        ol = odd.most_common(50)
        max_val = 0
        for index_e, num_e in el:
            for index_o, num_o in ol:
                if index_e != index_o:
                    max_val = max(max_val, num_e + num_o)
        ans = n - max_val
    else:
        ans = int(n / 2) - evel.most_common()[0][1] + int(n / 2) - odd.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(" ")))

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]
c = Counter(v)
c_1 = c.most_common(1)
c_2 = c_1[0][1]


if c_2 == n:
    print(k)
else:
    print(n - a_2 - b_2)

Submission status: Wrong Answer

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

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

while c < N:
    if li[c] == li[c + 1]:
        b += 1
    c += 2
while d < N:
    if N - d < 5:
        break
    else:
        if li[d] != li[d + 4]:
            b += 1
        d += 4

while e < N:
    if N - e < 5 :
        break
    else:
        if li[e] != li[e + 4]:
            b += 1
        e += 4


print(b)

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

t = max(one+twoo,onee+two)

if pp == 0:
    print(a-one-two)
else:
    print(a-t)

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 - 1

Submission status: Wrong Answer

Solution code:
a = int(input())
l = input().split(' ')
b = []
c = []
bb = {}
cc = {}

for i in range(0,a,2):
  b.append(l[i])
  bb[l[i]] = 0
  c.append(l[i+1])
  cc[l[i+1]] = 0

for i in range(a//2):
  bb[b[i]] += 1
  cc[c[i]] += 1


ans = 0
flag = True
for i in sorted(bb.items(), key=lambda x: -x[1]):
  if(flag):
    flag = False
  else:
    ans += i[1]

flag = True
for i in sorted(cc.items(), key=lambda x: -x[1]):
  if(flag):
    flag = False
  else:
    ans += i[1]



print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    v = list(map(int, input().split()))
    v_ki = v[1:N:2].copy()
    val_ki = []
    count_ki = []
    v_gu = v[0:N:2].copy()
    val_gu = []
    count_gu = []
    for i in range(N//2):
        if v_ki[i] in val_ki:
            count_ki[val_ki.index(v_ki[i])] += 1
        else:
            val_ki.append(v_ki[i])
            count_ki.append(1)
        if v_gu[i] in val_gu:
            count_gu[val_gu.index(v_gu[i])] += 1
        else:
            val_gu.append(v_gu[i])
            count_gu.append(1)
    
    ki = list(zip(count_ki, val_ki))
    ki.sort()
    ki_len = len(ki)
    gu = list(zip(count_gu, val_gu))
    gu.sort()
    gu_len = len(gu)
    if ki[-1][1] != gu[-1][1]:
        return N-(ki[-1][0])-(gu[-1][0])
    elif ki_len == gu_len:
        return N//2
    else:
        return min(N-(ki[-2][0])-(gu[-1][0]), N-(ki[-1][0])-(gu[-2][0]))

if __name__ == "__main__":
    print(main())

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)[-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) // 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:
n = int(input())
V_list = list(map(int, input().split()))

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

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

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

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

    key = [(k, v) for k, v in Vdic[0].items() if v == n1 or v == n2]
    ans_even.append((key[0][0], key[0][1]))
    ans_even.append((key[1][0], key[1][1]))

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

    key = [(k, v) for k, v in Vdic[1].items() if v == n1 or v == n2]
    ans_odd.append((key[0][0], key[0][1]))
    ans_odd.append((key[1][0], key[1][1]))
    ans_odd.append((-1, 0))

# print(ans_even, ans_odd)

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

print(min(ans))

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

if evel == odd:
    print(int(n / 2))
else:
    if evel.most_common()[0][0] == odd.most_common()[0][0]:
        # if evel.most_common()[0][1] >= odd.most_common()[0][1]:
        #     ans = int(n / 2) - evel.most_common()[0][1] + int(n / 2) - odd.most_common()[1][1]
        # else:
        #     ans = int(n / 2) - evel.most_common()[1][1] + int(n / 2) - odd.most_common()[0][1]
        el = evel.most_common(10)
        ol = odd.most_common(10)
        max_val = 0
        for index_e, num_e in el:
            for index_o, num_o in ol:
                if index_e != index_o:
                    max_val = max(max_val, num_e + num_o)
        ans = n - max_val
    else:
        ans = int(n / 2) - evel.most_common()[0][1] + int(n / 2) - odd.most_common()[0][1]
    print(ans)

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:
from collections import Counter
n = int(input())
v = [int(i) for i in input().split()]


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

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

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

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

Submission status: Wrong Answer

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

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

while c < N:
    if li[c] == li[c + 1]:
        b += 1
    c += 2
while d < N:
    if N - d < 5:
        break
    else:
        if li[d] != li[d + 4]:
            b += 1
        d += 4

while e < N:
    if N - e < 5 :
        break
    else:
        if li[e] != li[e + 4]:
            b += 1
        e += 4

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

print(evel.most_common(), odd.most_common())
if evel == odd:
    print(int(n / 2))
else:
    if evel.most_common()[0][0] == odd.most_common()[0][0]:
        # if evel.most_common()[0][1] >= odd.most_common()[0][1]:
        #     ans = int(n / 2) - evel.most_common()[0][1] + int(n / 2) - odd.most_common()[1][1]
        # else:
        #     ans = int(n / 2) - evel.most_common()[1][1] + int(n / 2) - odd.most_common()[0][1]
        el = evel.most_common(10)
        ol = odd.most_common(10)
        max_val = 0
        for index_e, num_e in el:
            for index_o, num_o in ol:
                if index_e != index_o:
                    max_val = max(max_val, num_e + num_o)
        ans = n - max_val
    else:
        ans = int(n / 2) - evel.most_common()[0][1] + int(n / 2) - odd.most_common()[0][1]
    print(ans)

Submission status: Wrong Answer

Solution code:
s = raw_input()
num = int(s)
l = map(int, raw_input().split())

retsulen = len(l)

odd = []
even = []

for i in range(retsulen//2):
    odd.append(l[2*i])
    even.append(l[2*i+1])

oddset = set(odd)
evenset = set(even)

allset = oddset | evenset



#print(oddset)
#print(evenset)

oddnum = 0
evennum = 0


oddcount = []
evencount = []

for i in oddset:
    oddcount.append(i)

#print(oddcount)

for i in evenset:
    evencount.append(i)

oddcount.sort()
evencount.sort()

for i in range(len(oddcount)-1):
    oddnum = oddnum + oddcount[i]

for i in range(len(evencount)-1):
    evennum = evennum + evencount[i]


#print (oddnum)
#print(evennum)
if len(allset) == 1:
    print(num//2)
else:
    print(oddnum + evennum)

Submission status: Wrong Answer

Solution code:
import collections

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

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

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

Submission status: Wrong Answer

Solution code:
n = int(input())
V = list(map(int,input().split()))
D1 = {}
D2 = {}
for i in range(n) :
    if i % 2 == 0 :
        if V[i] in D1 :
            D1[V[i]] += 1
        else :
            D1[V[i]] = 1
    else :
        if V[i] in D2 :
            D2[V[i]] += 1
        else :
            D2[V[i]] = 1
#print(D1)
#print(D2)
#print(sum(D2.values()))
l1 = len(D1)
l2 = len(D2)
if l1 == 1 and l2 == 1 :
    if V[0] == V[1] :
        print(n//2)
    else :
        print(0)
else :
    x1 = sum(D1.values())
    s1 = max(D1.values())
    x2 = sum(D2.values())
    s2 = max(D2.values())
    print(x2+x2-s1-s2)