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()))
v_odd = v[0::2]
v_even = v[1::2]
ans = 0
c_odd = Counter(v_odd)
c_even = Counter(v_even)
v_o, c_o = zip(*c_odd.most_common())
v_e, c_e = zip(*c_even.most_common())
if len(c_o) == 1:
    odd1 = 0
else:
    odd1 = c_o[1]
if len(c_e) == 1:
    even1 = 0
else:
    even1 = c_e[1]
if len(c_o) == 1 and len(c_e) == 1:
    print(0)
else:
    ans = min(sum(c_o) - c_o[0] + sum(c_e) - even1, sum(c_o) - odd1 + sum(c_e) - c_e[0])
    print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
V = list(map(int, input().split()))
E = {}
O = {}
n = 1
for i, v in enumerate(V):
    if n:
        if v in E.keys():
            E[v] += 1
        else:
            E[v] = 1
    else:
        if v in O.keys():
            O[v] += 1
        else:
            O[v] = 1
    n = 1 - n
E = sorted(E.items(), key=lambda x: -x[1])
O = sorted(O.items(), key=lambda x: -x[1])
if E[0][0] != O[0][0]:
    ans = n - E[0][1] - O[0][1]
    print(ans)
else:
    if len(E) == 1 and len(O) == 1:
        print(E[0][1])
    elif len(E) == 1:
        ans = n - E[0][1] - O[1][1]
        print(ans)
    elif len(O) == 1:
        ans = n -E[1][1] - O[0][1]
        print(ans)
    else:
        ans1 = n - E[0][1] - O[1][1]
        ans2 = n - E[1][1] - O[0][1]
        print(min(ans1, ans2))

Submission status: Wrong Answer

Solution code:
n = int(input())
V = list(map(int, input().split()))
E = {}
O = {}
n = 1
for i, v in enumerate(V):
    if n:
        if v in E.keys():
            E[v] += 1
        else:
            E[v] = 1
    else:
        if v in O.keys():
            O[v] += 1
        else:
            O[v] = 1
    n = 1 - n
E = sorted(E.items(), key=lambda x: -x[1])
O = sorted(O.items(), key=lambda x: -x[1])
if E[0][0] != O[0][0]:
    ans = sum([x[1] for x in E])-E[0][1]
    ans += sum([x[1] for x in O])-O[0][1]
    print(ans)
else:
    if len(E) == 1 and len(O) == 1:
        print(E[0][0])
    elif len(E) == 1:
        ans = sum([x[1] for x in E])-E[0][1]
        ans += sum([x[1] for x in O])-O[1][1]
        print(ans)
    elif len(O) == 1:
        ans = sum([x[1] for x in E])-E[1][1]
        ans += sum([x[1] for x in O])-O[0][1]
        print(ans)
    else:
        ans1 = sum([x[1] for x in E])-E[0][1]
        ans1 += sum([x[1] for x in O])-O[1][1]
        ans2 = sum([x[1] for x in E])-E[1][1]
        ans2 += sum([x[1] for x in O])-O[0][1]
        print(min(ans1, ans2))

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
v = list(map(int,input().split()))
even = Counter(v[::2]).most_common(2)
odd = Counter(v[1::2]).most_common(2)
if even[0][0] != odd[0][0]:
    ans =  n - even[0][1] - odd[0][1]
else:
    if len(even) == 1 or len(odd)==1:
        ans = n//2
    else:
        ans =  n - max(even[0][1] + odd[1][1],even[1][1],odd[0][1])
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
v = list(map(int,input().split()))
even = Counter(v[::2]).most_common(2)
odd = Counter(v[1::2]).most_common(2)
if even[0][0] != odd[0][0]:
    ans =  n - even[0][1] - odd[0][1]
else:
    if len(even) == 1:
        ans = n//2
    else:
        ans =  n - max(even[0][1] + odd[1][1],even[1][1],odd[0][1])
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
from operator import itemgetter
import sys
input = sys.stdin.readline

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

a = defaultdict(int)
b = defaultdict(int)
a[0] = 0
b[0] = 0

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

a_sorted = sorted(a.items(), key=itemgetter(1), reverse=True)
b_sorted = sorted(b.items(), key=itemgetter(1), reverse=True)
if a_sorted[0][0] == b_sorted[0][0]:
    if a_sorted[0][1] >= b_sorted[0][1]:
        c = n/2 - a_sorted[0][1]
        c += n/2 - b_sorted[1][1]
    else:
        c = n/2 - b_sorted[0][1]
        c += n/2 - a_sorted[1][1]
else:
    c = n/2 - a_sorted[0][1]
    c += n/2 - b_sorted[0][1]
print(int(c))

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
from operator import itemgetter
import sys
input = sys.stdin.readline

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

a = defaultdict(int)
b = defaultdict(int)
a[0] = 0
b[0] = 0

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

a_sorted = sorted(a.items(), key=itemgetter(1), reverse=True)
b_sorted = sorted(b.items(), key=itemgetter(1), reverse=True)
if a_sorted[0][0] == b_sorted[0][0]:
    if a_sorted[0][1] >= b_sorted[0][1]:
        c = n/2 - a_sorted[0][1]
        c += n/2 - b_sorted[1][1]
    else:
        c = n/2 - b_sorted[0][1]
        c += n/2 - a_sorted[1][1]
else:
    c = n/2 - a_sorted[0][1]
    c = n/2 - b_sorted[0][1]
print(int(c))

Submission status: Wrong Answer

Solution code:
n = int(input())
V = list(map(int,input().split()))
V_1 = V[::2]
V_1_a = []
V_2 = V[1::2]
V_2_a = []
for i in range(n//2):
    V_1_a.append(V_1.count(V_1[i]))
    V_2_a.append(V_2.count(V_2[i]))
a = max(V_1_a) + max(V_2_a)
print(n - a)

Submission status: Wrong Answer

Solution code:
n = int(input())
V = list(map(int,input().split()))
V_1 = V[::2]
V_1_a = []
V_2 = V[1::2]
V_2_a = []
while V_1 != []:
    V_1_a.append(V_1.count(V_1[0]))
    v = V_1[0]
    V_1.remove(v)
while V_2 != []:
    V_2_a.append(V_2.count(V_2[0]))
    v = V_2[0]
    V_2.remove(v)
a = max(V_1_a) + max(V_2_a)
print(n - a)

Submission status: Wrong Answer

Solution code:
import collections

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

def ct(lrg,sml):
    for lst in [lrg,sml]:
        if len(lst)==1:
            lst.append((0,0))
    if lrg[0][0]==sml[0][0]:
        if lrg[0][1]==lrg[1][1]:
            return n-lrg[1][1]-sml[0][1]
        else:
            return n-lrg[0][1]-sml[1][1]
    else:
        return n-lrg[0][1]-sml[0][1]


for i in range(len(a)):
    if i%2:
        evn.append(a[i])
    else:
        odd.append(a[i])
cevn=collections.Counter(evn).most_common()
codd=collections.Counter(odd).most_common()
if cevn[0][1]>=codd[0][1]:
    ans = ct(cevn,codd)
else:
    ans = ct(codd,cevn)
print(ans)

Submission status: Wrong Answer

Solution code:
import collections

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

def ct(lrg,sml):
    for lst in [lrg,sml]:
        if len(lst)==1:
            lst.append((0,0))
    if lrg[0][0]==sml[0][0]:
        if lrg[0][1]==lrg[1][1]:
            return n-lrg[1][1]-sml[0][1]
        else:
            return n-lrg[0][1]-sml[1][1]
    else:
        return n-lrg[0][1]-sml[0][1]


for i in range(len(a)):
    if i%2:
        evn.append(a[i])
    else:
        odd.append(a[i])
cevn=collections.Counter(evn).most_common()
codd=collections.Counter(odd).most_common()
if cevn[0][1]>codd[0][1]:
    ans = ct(cevn,codd)
else:
    ans = ct(codd,cevn)
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
V = list(map(int, input().split()))
o = {}
e = {}
for i, v in enumerate(V):
    if i % 2 == 1:
        if not v in e.keys():
            e[v] = 0
        e[v] += 1
    else:
        if not v in o.keys():
            o[v] = 0
        o[v] += 1

ol = sorted(o.values(), reverse=True)
el = sorted(e.values(), reverse=True)
e1 = sum(el[1:])
o1 = sum(ol[1:])
if e.keys() == o.keys():
    print(sum(ol))
elif e1 + o1 == 0:
    print(0)
else:
    e2 = el[0] + sum(el[2:])
    o2 = ol[0] + sum(ol[2:])
    ret = min(e1+o2, e2+o1)
    print(ret)

Submission status: Wrong Answer

Solution code:
N = int(input())
V = list(map(int, input().split()))
o = {}
e = {}
for i, v in enumerate(V):
    if i % 2 == 1:
        if not v in e.keys():
            e[v] = 0
        e[v] += 1
    else:
        if not v in o.keys():
            o[v] = 0
        o[v] += 1

ol = sorted(o.values(), reverse=True)
el = sorted(e.values(), reverse=True)
e1 = sum(el[1:])
o1 = sum(ol[1:])
if e.keys() == o.keys():
    print(len(ol))
elif e1 + o1 == 0:
    print(0)
else:
    e2 = el[0] + sum(el[2:])
    o2 = ol[0] + sum(ol[2:])
    ret = min(e1+o2, e2+o1)
    print(ret)

Submission status: Wrong Answer

Solution code:
N = int(input())
V = list(map(int, input().split()))
o = {}
e = {}
for i, v in enumerate(V):
    if i % 2 == 1:
        if not v in e.keys():
            e[v] = 0
        e[v] += 1
    else:
        if not v in o.keys():
            o[v] = 0
        o[v] += 1

ol = sorted(o.values(), reverse=True)
el = sorted(e.values(), reverse=True)
e1 = sum(el[1:])
o1 = sum(ol[1:])
if e.keys() == o.keys():
    print(len(e))
elif e1 + o1 == 0:
    print(0)
else:
    e2 = el[0] + sum(el[2:])
    o2 = ol[0] + sum(ol[2:])
    ret = min(e1+o2, e2+o1)
    print(ret)

Submission status: Wrong Answer

Solution code:
N = int(input())
V = list(map(int, input().split()))
o = {}
e = {}
for i, v in enumerate(V):
    if i % 2 == 1:
        if not v in e.keys():
            e[v] = 0
        e[v] += 1
    else:
        if not v in o.keys():
            o[v] = 0
        o[v] += 1

o = sorted(o.values(), reverse=True)
e = sorted(e.values(), reverse=True)
e1 = sum(e[1:])
o1 = sum(o[1:])
if e1 + o1 == 0:
    print(0)
else:
    e2 = e[0] + sum(e[2:])
    o2 = o[0] + sum(o[2:])
    ret = min(e1+o2, e2+o1)
    print(ret)

Submission status: Wrong Answer

Solution code:
N = int(input())
V = list(map(int, input().split()))
o = {}
e = {}
for i, v in enumerate(V):
    if i % 2 == 1:
        if not v in e.keys():
            e[v] = 0
        e[v] += 1
    else:
        if not v in o.keys():
            o[v] = 0
        o[v] += 1

o = sorted(o.values(), reverse=True)
e = sorted(e.values(), reverse=True)

e1 = sum(e[1:])
e2 = e[0] + sum(e[2:])
o1 = sum(o[1:])
o2 = o[0] + sum(o[2:])
ret = min(e1+o2, e2+o1)
print(ret)

Submission status: Wrong Answer

Solution code:
N = int(input())
V = list(map(int, input().split()))
o = {}
e = {}
for i, v in enumerate(V):
    if i % 2 == 0:
        if not v in e.keys():
            e[v] = 0
        e[v] += 1
    else:
        if not v in o.keys():
            o[v] = 0
        o[v] += 1
if o == e:
    print(sum(o.values()))
else:
    o = sorted(o.values(), reverse=True)
    e = sorted(e.values(), reverse=True)
    print(sum(o[1:]) + sum(e[1:]))

Submission status: Wrong Answer

Solution code:
N = int(input())
V = list(map(int, input().split()))
o = {}
e = {}
for i, v in enumerate(V):
    if i % 2 == 0:
        if not v in e.keys():
            e[v] = 0
        e[v] += 1
    else:
        if not v in o.keys():
            o[v] = 0
        o[v] += 1
if o == e:
    print(sum(o.values()))
else:
    o = sorted(o.values(), reverse=True)
    e = sorted(e.values(), reverse=True)
    print(len(o[1:]) + len(e[1:]))

Submission status: Wrong Answer

Solution code:
num = int(input())
array = [x for x in input().split(' ')]
x = array[::2]
y = array[1::2]
if x == y:
    print(int(len(array) / 2))
else:
    change_count = 0
    for ls in [x, y]:
        _set = set(ls)
        if len(_set) != 1:
            dic = { key: ls.count(key) for key in _set }
            if max(dic.values()) == 1:
                change_count += len(ls) - 1
            else:
                change_count += len(ls) - max(dic.values())
    print(change_count)

Submission status: Wrong Answer

Solution code:
num = int(input())
array = [x for x in input().split(' ')]
x = array[::2]
y = array[1::2]
if x == y:
    print(int(len(array) / 2))
else:
    change_count = 0
    for ls in [x, y]:
        _set = set(ls)
        if len(_set) != 1:
            dic = { key: ls.count(key) for key in _set }
            change_count += min(dic.values())
    print(change_count)

Submission status: Wrong Answer

Solution code:
import re
n = int(input())
vs = list(map(int, input().split()))
edic = {}
odic = {}

for i in range(n):
    item = vs[i]
    if i % 2 == 0:
        if item in edic:
            edic[item] += 1
        else:
            edic[item] = 1
    else:
        if item in odic:
            odic[item] += 1
        else:
            odic[item] = 1

elist = sorted(edic.items(), key=lambda x: -x[1])
olist = sorted(odic.items(), key=lambda x: -x[1])

if elist[0][0] != olist[0][0]:
    print(len(vs) - elist[0][1] - olist[0][1])
else:
    ogain = egain = 0
    if len(elist) >= 2:
        egain = elist[1][1]
    if len(olist) >= 2:
        ogain = olist[1][1]
    print(max(len(vs) - elist[0][1] - ogain, len(vs) - olist[0][1] - egain ))

Submission status: Wrong Answer

Solution code:
import sys
import collections
input = sys.stdin.readline

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

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

c_even = collections.Counter(v_even)
c_odd = collections.Counter(v_odd)
most_even = c_even.most_common(2)
most_odd = c_odd.most_common(2)


if most_even[0][0] != most_odd[0][0]:
    print(n - most_even[0][1] - most_odd[0][1])
elif len(most_even) == len(most_odd) == 1:
    print(int(n/2))
else:
    if most_even[0][1] >= most_odd[0][1]:
        print(n - most_even[0][1] - most_odd[1][1])
    else:
        print(n - most_odd[0][1] - most_even[1][1])

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
dict_odd = {}
dict_even = {}

for i in range(n):
  #リストの奇数番目、０始まりなのであまりは０
  if i %2 == 0:
    dict_odd[a[i]] = dict_odd.get(a[i], 0) + 1
  else:
    dict_even[a[i]] = dict_even.get(a[i], 0) + 1

v_odd_sorted = sorted(dict_odd.values())
v_even_sorted = sorted(dict_even.values())
odd_sorted = sorted(dict_odd.items(), key=lambda x : x[1])
even_sorted = sorted(dict_even.items(), key=lambda x : x[1])

ans = 0
#数字が一種類しかない場合は、一方を置き換える必要がある
if len(set(a)) == 1:
  ans = sum(v_odd_sorted)
  #print(sum(v_odd_sorted))
else:
  #偶数列と奇数列について、書き換えた後が同じ数字なら成立しないので、一方の書き換える先を次に多い数字にする
  if odd_sorted[-1][0] == even_sorted[-1][0]:
    if odd_sorted[-1][1] >= even_sorted[-1][1]:
      #偶数列を変更したほうが少ない場合
      ans = sum(v_odd_sorted[:-1]) + sum(v_even_sorted[:-2]) + v_even_sorted[-1]
    else:
      #奇数列を変更したほうが少ない場合
      ans = sum(v_even_sorted[:-1]) + sum(v_odd_sorted[:-2]) + v_odd_sorted[-1]
  else:
    ans = sum(v_odd_sorted[:-1]) + sum(v_even_sorted[:-1])
  #print(sum(v_odd_sorted[:-1]) + sum(v_even_sorted[:-1]))
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
dict_odd = {}
dict_even = {}

for i in range(n):
  #リストの奇数番目、０始まりなのであまりは０
  if i %2 == 0:
    dict_odd[a[i]] = dict_odd.get(a[i], 0) + 1
  else:
    dict_even[a[i]] = dict_even.get(a[i], 0) + 1

v_odd_sorted = sorted(dict_odd.values())
v_even_sorted = sorted(dict_even.values())
odd_sorted = sorted(dict_odd.items(), key=lambda x : x[1])
even_sorted = sorted(dict_even.items(), key=lambda x : x[1])

ans = 0
#数字が一種類しかない場合は、一方を置き換える必要がある
if len(set(a)) == 1:
  ans = sum(v_odd_sorted)
  #print(sum(v_odd_sorted))
else:
  #偶数列と奇数列について、書き換えた後が同じ数字なら成立しないので、一方の書き換える先を次に多い数字にする
  if odd_sorted[-1][0] == even_sorted[-1][0]:
    if odd_sorted[-1][1] > even_sorted[-1][1]:
      #偶数列を変更したほうが少ない場合
      ans = sum(v_odd_sorted[:-1]) + sum(v_even_sorted[:-2]) + v_even_sorted[-1]
    else:
      #奇数列を変更したほうが少ない場合
      ans = sum(v_even_sorted[:-1]) + sum(v_odd_sorted[:-2]) + v_odd_sorted[-1]
  else:
    ans = sum(v_odd_sorted[:-1]) + sum(v_even_sorted[:-1])
  #print(sum(v_odd_sorted[:-1]) + sum(v_even_sorted[:-1]))
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())

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


dict_odd = {}
dict_even = {}

for i in range(n):
  #リストの奇数番目、０始まりなのであまりは０
  if i %2 == 0:
    dict_odd[a[i]] = dict_odd.get(a[i], 0) + 1
  else:
    dict_even[a[i]] = dict_even.get(a[i], 0) + 1
    
#print(dict_odd, dict_even)    

v_odd_sorted = sorted(dict_odd.values())
v_even_sorted = sorted(dict_even.values())

#print(v_odd_sorted, v_even_sorted)    

#数字が一種類しかない場合は、一方を置き換える必要がある
if len(set(a)) == 1:
  print(sum(v_odd_sorted))
else:
  print(sum(v_odd_sorted[:-1]) + sum(v_even_sorted[:-1]))

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
dict_odd = {}
dict_even = {}

for i in range(n):
  #リストの奇数番目、０始まりなのであまりは０
  if i %2 == 0:
    dict_odd[a[i]] = dict_odd.get(a[i], 0) + 1
  else:
    dict_even[a[i]] = dict_even.get(a[i], 0) + 1 

v_odd_sorted = sorted(dict_odd.values())
v_even_sorted = sorted(dict_even.values())

#数字が一種類しかない場合は、一方を置き換える必要がある
if len(set(a)) == 1:
  print(sum(v_odd_sorted))
else:
  print(sum(v_odd_sorted[:-1]) + sum(v_even_sorted[:-1]))

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
v = list(map(int, input().split()))
c_odd  = collections.Counter(v[::2])
c_even = collections.Counter(v[1::2])
odd    = c_odd.most_common()[:2]
even   = c_even.most_common()[:2]
if (len(odd) == 1) & (len(even) == 1):
	if odd[0][0] == even[0][0]:
		ans = odd[0][1]
	else:
		ans = 0
elif len(odd) == 1:
	if odd[0][0] == even[0][0]:
		ans = n - odd[0][1] - even[1][1]
	else:
		ans = n - odd[0][1] - even[0][1]
elif len(even) == 1:
	if odd[0][0] == even[0][0]:
		ans = n - odd[1][1] - even[0][1]
	else:
		ans = n - odd[0][1] - even[0][1]
else:
	if odd[0][0] == even[0][0]:
		if odd[0][1] > even[0][1]:
			ans = n - odd[0][1] - even[1][1]
		else:
			ans = n - odd[1][1] - even[0][1]
	else:
		ans = n - odd[0][1] - even[0][1]
print(ans)

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
v = list(map(int, input().split()))
c_odd  = collections.Counter(v[::2])
c_even = collections.Counter(v[1::2])
odd    = c_odd.most_common()[:2]
even   = c_even.most_common()[:2]
if n == odd[0][1] + even[0][1]:
	ans = odd[0][1]
elif odd[0][0] != even[0][0]:
	ans = n - odd[0][1] - even[0][1]
elif odd[0][1] > even[0][1]:
	ans = n - odd[0][1] - even[1][1]
else:
	ans = n - odd[1][1] - even[0][1]
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

counted_v1 = Counter(v[::2])
counted_v2 = Counter(v[1::2])

most_v1 = counted_v1.most_common()[0]
most_v2 = counted_v2.most_common()[0]

if  most_v1[0] != most_v2[0]:
    print(n - most_v1[1] - most_v2[1])

elif len(counted_v1) == 1 and len(counted_v2) == 1:
    print(n // 2)

elif most_v1[1] < most_v2[1]:
    second_v1 = counted_v1.most_common()[1] if len(counted_v1) >= 2 else most_v1[1]
    print(n - second_v1[1] - most_v2[1])

else:
    second_v2 = counted_v2.most_common()[1] if len(counted_v2) >= 2 else most_v2[1]
    print(n - most_v1[1] - second_v2[1])

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

counted_v1 = Counter(v[::2])
counted_v2 = Counter(v[1::2])

most_v1 = counted_v1.most_common()[0]
most_v2 = counted_v2.most_common()[0]

if  most_v1[0] != most_v2[0]:
    print(n - most_v1[1] - most_v2[1])

elif len(counted_v1) == 1 and len(counted_v2) == 1:
    print(n // 2)

elif most_v1[1] <= most_v2[1]:
    second_v1 = counted_v1.most_common()[1] if len(counted_v1) >= 2 else most_v1[1]
    print(n - second_v1[1] - most_v2[1])

else:
    second_v2 = counted_v2.most_common()[1] if len(counted_v2) >= 2 else most_v2[1]
    print(n - most_v1[1] - second_v2[1])

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

counted_v1 = Counter(v[::2])
counted_v2 = Counter(v[1::2])

most_v1 = counted_v1.most_common()[0]
most_v2 = counted_v2.most_common()[0]

if  most_v1[0] != most_v2[0]:
    print(n - most_v1[1] - most_v2[1])


elif len(counted_v1) == 1 and len(counted_v2) == 1:
    print(n // 2)

elif most_v1[1] > most_v2[1]:
    second_v2 = counted_v2.most_common()[1] if len(counted_v2) >= 2 else most_v2[1]
    print(n - most_v1[1] - second_v2[1])

else:
    second_v1 = counted_v1.most_common()[1] if len(counted_v1) >= 2 else most_v1[1]
    print(n - second_v1[1] - most_v2[1])

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

counted_v1 = Counter(v[::2])
counted_v2 = Counter(v[1::2])

most_v1 = counted_v1.most_common()[0]
most_v2 = counted_v2.most_common()[0]

if  most_v1[0] != most_v2[0]:
    print(n - most_v1[1] - most_v2[1])


elif len(counted_v1) == 1 and len(counted_v2) == 1:
    print(n // 2)

elif most_v1[1] > most_v2[1] or len(counted_v1) == 1:
    second_v2 = counted_v2.most_common()[1]
    print(n - most_v1[1] - second_v2[1])

else:
    second_v1 = counted_v1.most_common()[1]
    print(n - second_v1[1] - most_v2[1])

Submission status: Wrong Answer

Solution code:
n = int(input())
v = [int(x) for x in input().split()]
w = v[0::2]
z = v[1::2]

x = [w.count(a) for a in set(w)]
y = [z.count(a) for a in set(z)]

c=[]
if len(x) != 1:
  c.append(sum(x)-max(x))
elif len(y) != 1:
  c.append(sum(y)-max(y))
  print(sum(c))
  exit()
elif w != z:
  print(0)
  exit()
else:
  print(n//2)

Submission status: Wrong Answer

Solution code:
import sys
from collections import Counter

sys.setrecursionlimit(10000)
INF = float('inf')

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

v1 = Counter(V[::2]).most_common(2)
v2 = Counter(V[1::2]).most_common(2)

if v1[0][0] != v2[0][0]:
    ans = N - (v1[0][1] + v2[0][1])
else:
    ans = INF
    ans = min(ans, N - (v1[0][1] + N // 2))
    ans = min(ans, N - (v2[0][1] + N // 2))
    if len(v1) >= 2:
        ans = min(ans, N - (v1[1][1] + v2[0][1]))
    if len(v2) >= 2:
        ans = min(ans, N - (v1[0][1] + v2[1][1]))
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
from collections import Counter

sys.setrecursionlimit(10000)
INF = float('inf')

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

v1 = Counter(V[::2]).most_common(2)
v2 = Counter(V[1::2]).most_common(2)

if v1[0][0] != v2[0][0]:
    ans = N - (v1[0][1] + v2[0][1])
else:
    ans = INF
    ans = min(ans, N - (v1[0][0] + N // 2))
    ans = min(ans, N - (v2[0][0] + N // 2))
    if len(v1) >= 2:
        ans = min(ans, N - (v1[1][1] + v2[0][1]))
    if len(v2) >= 2:
        ans = min(ans, N - (v1[0][1] + v2[1][1]))
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
from collections import Counter

sys.setrecursionlimit(10000)
INF = float('inf')

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

v1 = Counter(V[::2]).most_common(2)
v2 = Counter(V[1::2]).most_common(2)

if v1[0][0] != v2[0][0]:
    ans = N - (v1[0][1] + v2[0][1])
else:
    ans = N // 2
    if len(v1) >= 2:
        ans = min(ans, N - (v1[1][1] + v2[0][1]))
    if len(v2) >= 2:
        ans = min(ans, N - (v1[0][1] + v2[1][1]))
print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
from math import *
from itertools import *
from collections import *
from functools import *
try:
    from math import gcd
except Exception:
    from fractions import gcd


def solve(n: int, v: "List[int]"):
    e = v[0::2]
    o = v[1::2]

    ec = [(vv, k, 0) for k, vv in Counter(e).items()]
    oc = [(vv, k, 1) for k, vv in Counter(o).items()]
    ecoc = ec + oc

    res = [(0, ''), (0, '')]
    for n, k, t in sorted(ecoc, reverse=True):
        if res[t][1] != '' or res[1 - t][1] == k:
            continue

        res[t] = (n, k)
        if res[0][1] != '' and res[1][1] != '':
            break
    return len(v) - res[0][0] - res[1][0]


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    n = int(next(tokens))  # type: int
    v = [ int(next(tokens)) for _ in range(n) ]  # type: "List[int]"
    result = solve(n, v)
    print(result)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
from math import *
from itertools import *
from collections import *
from functools import *
try:
    from math import gcd
except Exception:
    from fractions import gcd


def solve(n: int, v: "List[int]"):
    e = v[0::2]
    o = v[1::2]

    ec = [(vv, k, 0) for k, vv in Counter(e).items()]
    oc = [(vv, k, 1) for k, vv in Counter(o).items()]
    ecoc = ec + oc

    res = [(0, ''), (0, '')]
    for n, k, t in sorted(ecoc):
        if res[t][1] != '' or res[1 - t][1] == k:
            continue

        res[t] = (n, k)
        if res[0][1] != '' and res[1][1] != '':
            break
    return len(v) - res[0][0] - res[1][0]


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    n = int(next(tokens))  # type: int
    v = [ int(next(tokens)) for _ in range(n) ]  # type: "List[int]"
    result = solve(n, v)
    print(result)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#ABC 111 C
N=int(input())
A=[int(j) for j in input().split()]
A_ele=list(set(A))
cnt1=[0]*max(A_ele)
cnt2=[0]*max(A_ele)
for i in range(0,N):
    for a in A_ele:
        if i%2==0 and A[i]==a:
            cnt2[a-1]+=1
        if i%2!=0 and A[i]==a:
            cnt1[a-1]+=1
print(sum(cnt2)-max(cnt2)+sum(cnt1)-max(cnt1))

Submission status: Wrong Answer

Solution code:
from collections import Counter as c
 
N = int(input())
V = list(map(int,input().split()))
eve=[]
odd=[]
 
for i in range(N):
    if i%2 == 0:
        eve.append(V[i])
    else:
        odd.append(V[i])
ev = c(eve).most_common(2)
od = c(odd).most_common(2)
 
if ev[0][0] == od[0][0] and len(ev) == len(od) == 1:
    ans = N//2
else:
    ans = min(N-ev[0][1]-od[-1][1],N-ev[-1][1]-od[0][1])
    
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter as c

N = int(input())
V = list(map(int,input().split()))
eve=[]
odd=[]

for i in range(N):
    if i%2 == 0:
        eve.append(V[i])
    else:
        odd.append(V[i])
ev = c(eve).most_common(2)
od = c(odd).most_common(2)

if ev[0][0] == od[0][0] and len(ev) == len(od) == 1:
    print('a')
    ans = N//2
else:
    ans = min(N-ev[0][1]-od[-1][1],N-ev[-1][1]-od[0][1])
    
print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
n = int(input())
v = list(map(int, input().split()))

odd = list(set(v[0::2]))
even = list(set(v[1::2]))
length = len(v)//2

if len(odd) == 1 and len(even) == 1:
    if odd[0] == even[0]:
        print(length)
    else:
        print(0)
else:
    print(len(even) + len(odd) - 2)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
n = int(input())
v = list(map(int, input().split()))

odd = list(set(v[0::2]))
even = list(set(v[1::2]))
length = len(v)//2

if odd == even:
    print(length)
elif len(odd) == 1 and len(even) == 1:
    print(0)
else:
    print(len(even) + len(odd) - 2)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
n = int(input())
v = list(map(int, input().split()))

odd = list(set(v[0::2]))
even = list(set(v[1::2]))
length = len(v)//2

if odd == even:
    print(length)
elif len(odd) == len(even):
    print(0)
else:
    if len(odd) > len(even):
        print(len(odd) - len(even))
    else:
        print(len(even) - len(odd))

Submission status: Wrong Answer

Solution code:
import collections
N = int(input())
Res = [int(i) for i in input().split()]
U = Res[0:N:2]
V = Res[1:N:2]
u = collections.Counter(U)
v = collections.Counter(V)

i,j = 0,0
u_len = len(u)
v_len = len(v)

while u.most_common()[i][0] == v.most_common()[j][0]:
    if j == v_len-1:
        print(N//2)
        exit()
    else:
        if u.most_common()[i+1][1] > v.most_common()[j+1][1]:
            i += 1
        else:
            j += 1
            
print(N//2 - min(u.most_common()[i][1],v.most_common()[j][1]))

Submission status: Wrong Answer

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

tmp = {}
for s in v:
    if not s in tmp:
        tmp[s] = 1
    else:
        tmp[s] += 1

max,smax,cnt = 0,0,0
for i in tmp.values():
    if i > max:
        max = i
    elif max >= i and i > smax:
        smax = i
    cnt += i
print(cnt-max-smax)

Submission status: Wrong Answer

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

e,o = v[0],v[1]
if e is o:
    o = -1
cnt = 0
for i,s in enumerate(v):
    if i%2 == 0 and s != e:
        cnt += 1
    elif i%2 == 1 and s != o:
        cnt += 1
print(cnt)

Submission status: Wrong Answer

Solution code:
import collections

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

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

if len(collections.Counter(v))==1:
    max_eq = max(len(odd),len(even))
    print(n - max_eq)
    exit()

odd_most = collections.Counter(odd).most_common(2)
even_most = collections.Counter(even).most_common(2)

max_count=0
for odd_top in odd_most:
    for even_top in even_most:
        max_count = max(max_count,odd_top[1]+even_top[1])
print(n-max_count)

Submission status: Wrong Answer

Solution code:
import collections

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

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

if len(collections.Counter(v)):
    max_eq = max(len(odd),len(even))
    print(n - max_eq)
    exit()

odd_most = collections.Counter(odd).most_common(2)
even_most = collections.Counter(even).most_common(2)

max_count=0
for odd_top in odd_most:
    for even_top in even_most:
        max_count = max(max_count,odd_top[1]+even_top[1])
print(n-max_count)

Submission status: Wrong Answer

Solution code:
n = int(input())
v = list(map(str, input().split(" ")))
v_even = v[::2]
v_odd = v[1::2]
v_even_elements = set(v_even)
v_odd_elements = set(v_odd)
v_common_elements = v_even_elements & v_odd_elements
v_even_elements = list(v_even_elements)
v_odd_elements = list(v_odd_elements)
v_common_elements = list(v_common_elements)

for i in range(len(v_common_elements)):
    v_even_elements.remove(v_common_elements[i])
    v_odd_elements.remove(v_common_elements[i])
cnt11 = 0
cnt12 = 0
cnt21 = 0
cnt22 = 0

for i in range(len(v_even_elements)):
    cnt1 = v_even.count(v_even_elements[i])
    cnt11 = max(cnt1,cnt11)

for i in range(len(v_odd_elements)):
  cnt2 = v_odd.count(v_odd_elements[i])
  cnt21 = max(cnt2,cnt21)

for i in range(len(v_common_elements)):
    cnt1 = v_even.count(v_common_elements[i])
    cnt2 = v_odd.count(v_common_elements[i])
    cnt12 = max(cnt1,cnt12)
    cnt22 = max(cnt2,cnt22)

if cnt11<cnt12 or cnt21<cnt22:
    if cnt12-cnt11>cnt22-cnt21:
        cnt11 = cnt12
    else:
        cnt21 = cnt22

print(n-cnt21-cnt11)

Submission status: Wrong Answer

Solution code:
import collections

N = int(input())
A = list(map(int, input().split()))
e = A[::2]
o = A[1::2]

if len(set(A))==1:
    print(len(A)//2)
else:
    ce = collections.Counter(e)
    co = collections.Counter(o)
    cnte = list(ce.values())[0]
    cnto = list(co.values())[0]
    print(len(e)-cnte+len(o)-cnto)