Problem:


Score : 300 points

Problem Statement

A sequence a_1,a_2,... ,a_n is said to be /\/\/\/ when the following conditions are satisfied:

For each i = 1,2,..., n-2, a_i = a_{i+2}.

Exactly two different numbers appear in the sequence.

You are given a sequence v_1,v_2,...,v_n whose length is even.
We would like to make this sequence /\/\/\/ by replacing some of its elements.
Find the minimum number of elements that needs to be replaced.

Constraints

2 \leq n \leq 10^5

n is even.

1 \leq v_i \leq 10^5

v_i is an integer.

Input

Input is given from Standard Input in the following format:

n
v_1 v_2 ... v_n

Output

Print the minimum number of elements that needs to be replaced.

Sample Input 1

4
3 1 3 2

Sample Output 1

1

The sequence 3,1,3,2 is not /\/\/\/, but we can make it /\/\/\/ by replacing one of its elements: for example, replace the fourth element to make it 3,1,3,1.

Sample Input 2

6
105 119 105 119 105 119

Sample Output 2

0

The sequence 105,119,105,119,105,119 is /\/\/\/.

Sample Input 3

4
1 1 1 1

Sample Output 3

2

The elements of the sequence 1,1,1,1 are all the same, so it is not /\/\/\/.



Sample input:
4
3 1 3 2


Sample output:
1

Submission status: Wrong Answer

Solution code:
n = int(input())
v = list(map(int, input().split()))
v1 = []
v2 = []
for i in range(n):
	if i%2 == 0:
		v1.append(v[i])
	else:
		v2.append(v[i])
v1.sort()
v2.sort()

cnt1 = []
cnt2 = []
now = v1[0]
con = 1
for i in range(1, len(v1)):
	if now == v1[i]:
		con += 1
	else:
		now = v1[i]
		cnt1.append(con)
		con = 1
cnt1.append(con)
now = v2[0]
con = 1
for i in range(1, len(v2)):
	if now == v2[i]:
		con += 1
	else:
		now = v2[i]
		cnt2.append(con)
		con = 1
cnt2.append(con)
if cnt1.index(max(cnt1)) != cnt2.index(max(cnt2)):
	cnt1.sort()
	cnt2.sort()
	print(sum(cnt1[:len(cnt1)-1])+sum(cnt2[:len(cnt2)-1]))
else:
	cnt1.sort()
	cnt2.sort()
	ans = max(sum(cnt1[:len(cnt1)-2])+cnt1[len(cnt1)-1]+sum(cnt2[:len(cnt2)-1]), sum(cnt1[:len(cnt1)-1])+cnt2[len(cnt2)-1]+sum(cnt2[:len(cnt2)-2]))
	print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
v = list(map(int, input().split()))
v1 = []
v2 = []
for i in range(n):
	if i%2 == 0:
		v1.append(v[i])
	else:
		v2.append(v[i])
v1.sort()
v2.sort()

cnt1 = []
cnt2 = []
now = v1[0]
con = 1
for i in range(1, len(v1)):
	if now == v1[i]:
		con += 1
	else:
		now = v1[i]
		cnt1.append(con)
		con = 1
cnt1.append(con)
now = v2[0]
con = 1
for i in range(1, len(v2)):
	if now == v2[i]:
		con += 1
	else:
		now = v2[i]
		cnt2.append(con)
		con = 1
cnt2.append(con)
cnt1.sort()
cnt2.sort()
print(sum(cnt1[:len(cnt1)-1])+sum(cnt2[:len(cnt2)-1]))

Submission status: Wrong Answer

Solution code:
n = int(input())
V = [int(x) for x in input().split()]
cnt1 = [0] * (100100)
cnt2 = [0] * (100100)
for i in range(n):
    if (i % 2): cnt1[V[i]] += 1
    else: cnt2[V[i]] += 1 
lst1 = sorted(cnt1, reverse=True)
lst2 = sorted(cnt2, reverse=True)
o1 = cnt1.index(lst1[0])
cnt1[o1] = 0
o2 = cnt1.index(lst1[1])
e1 = cnt2.index(lst2[0])
cnt2[e1] = 0
e2 = cnt2.index(lst2[1])
if (e1 == o1 or e1 == o2 or e2 == o1 or e2 == o2):
    ans = 0
    i = 2
    while (lst1[i] != 0 or lst2[i] != 0):
        if (lst1[i] != 0): ans += lst1[i]
        if (lst2[i] != 0): ans += lst2[i]
        i += 1
    print(ans + max(lst1[0]+lst2[1], lst1[1]+lst2[0]))
else:
    i = 1
    ans = 0
    while (lst1[i] != 0 or lst2[i] != 0):
        if (lst1[i] != 0): ans += lst1[i]
        if (lst2[i] != 0): ans += lst2[i]
        i += 1
    print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
V = [int(x) for x in input().split()]
cnt1 = [0] * (100100)
cnt2 = [0] * (100100)
for i in range(n):
    if (i % 2): cnt1[V[i]] += 1
    else: cnt2[V[i]] += 1 
lst1 = sorted(cnt1, reverse=True)
lst2 = sorted(cnt2, reverse=True)
o1 = cnt1.index(lst1[0])
cnt1[o1] = 0
o2 = cnt1.index(lst1[1])
e1 = cnt2.index(lst2[0])
cnt2[e1] = 0
e2 = cnt2.index(lst2[1])
if (e1 == o1):
    ans = 0
    i = 2
    while (lst1[i] != 0 or lst2[i] != 0):
        if (lst1[i] != 0): ans += lst1[i]
        if (lst2[i] != 0): ans += lst2[i]
        i += 1
    print(ans + max(lst1[0]+lst2[1], lst1[1]+lst2[0]))
else:
    i = 1
    ans = 0
    while (lst1[i] != 0 or lst2[i] != 0):
        if (lst1[i] != 0): ans += lst1[i]
        if (lst2[i] != 0): ans += lst2[i]
        i += 1
    print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
V = [int(x) for x in input().split()]
cnt1 = [0] * (100100)
cnt2 = [0] * (100100)
for i in range(n):
    if (i % 2): cnt1[V[i]] += 1
    else: cnt2[V[i]] += 1 
lst1 = sorted(cnt1, reverse=True)
lst2 = sorted(cnt2, reverse=True)
c1 = set(filter(lambda c: c==lst1[0], cnt1))
c2 = set(filter(lambda c: c==lst2[0], cnt2))
if (c1 == c2):
    ans = 0
    i = 2
    while (lst1[i] != 0 or lst2[i] != 0):
        if (lst1[i] != 0): ans += lst1[i]
        if (lst2[i] != 0): ans += lst2[i]
        i += 1
    print(ans + max(lst1[0]+lst2[1], lst1[1]+lst2[0]))
else:
    i = 1
    ans = 0
    while (lst1[i] != 0 or lst2[i] != 0):
        if (lst1[i] != 0): ans += lst1[i]
        if (lst2[i] != 0): ans += lst2[i]
        i += 1
    print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
V = [int(x) for x in input().split()]
cnt1 = [0] * (100100)
cnt2 = [0] * (100100)
for i in range(n):
    if (i % 2): cnt1[V[i]] += 1
    else: cnt2[V[i]] += 1 
lst1 = sorted(cnt1, reverse=True)
lst2 = sorted(cnt2, reverse=True)
c1 = list(filter(lambda c: c==lst1[0], cnt1))
c2 = list(filter(lambda c: c==lst2[0], cnt2))
if (len(c1) > 1 or len(c2) > 1):
    ans = 0
    i = 2
    while (lst1[i] != 0 or lst2[i] != 0):
        if (lst1[i] != 0): ans += lst1[i]
        if (lst2[i] != 0): ans += lst2[i]
        i += 1
    print(ans + max(lst1[0]+lst2[1], lst1[1]+lst2[0]))
else:
    i = 1
    ans = 0
    while (lst1[i] != 0 or lst2[i] != 0):
        if (lst1[i] != 0): ans += lst1[i]
        if (lst2[i] != 0): ans += lst2[i]
        i += 1
    print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
V = [int(x) for x in input().split()]
cnt1 = [0] * (100100)
cnt2 = [0] * (100100)
for i in range(n):
    if (i % 2): cnt1[V[i]] += 1
    else: cnt2[V[i]] += 1 
c1 = cnt1.index(max(cnt1))
c2 = cnt2.index(max(cnt2))    
lst1 = sorted(cnt1, reverse=True)
lst2 = sorted(cnt2, reverse=True)
if (c1 == c2 and (lst1[0] != lst1[1] or lst2[0] != lst2[1])):
    ans = 0
    i = 2
    while (lst1[i] != 0 or lst2[i] != 0):
        if (lst1[i] != 0): ans += lst1[i]
        if (lst2[i] != 0): ans += lst2[i]
        i += 1
    print(ans + max(lst1[0]+lst2[1], lst1[1]+lst2[0]))
else:
    i = 1
    ans = 0
    while (lst1[i] != 0 or lst2[i] != 0):
        if (lst1[i] != 0): ans += lst1[i]
        if (lst2[i] != 0): ans += lst2[i]
        i += 1
    print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
V = [int(x) for x in input().split()]
cnt1 = [0] * (100100)
cnt2 = [0] * (100100)
for i in range(n):
    if (i % 2): cnt1[V[i]] += 1
    else: cnt2[V[i]] += 1 
c1 = cnt1.index(max(cnt1))
c2 = cnt2.index(max(cnt2))    
lst1 = sorted(cnt1, reverse=True)
lst2 = sorted(cnt2, reverse=True)
if (c1 == c2 and lst1[0] != lst1[1] and lst2[0] != lst2[1]):
    ans = 0
    i = 2
    while (lst1[i] != 0 or lst2[i] != 0):
        if (lst1[i] != 0): ans += lst1[i]
        if (lst2[i] != 0): ans += lst2[i]
        i += 1
    print(ans + max(lst1[0]+lst2[1], lst1[1]+lst2[0]))
else:
    i = 1
    ans = 0
    while (lst1[i] != 0 or lst2[i] != 0):
        if (lst1[i] != 0): ans += lst1[i]
        if (lst2[i] != 0): ans += lst2[i]
        i += 1
    print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
V = [int(x) for x in input().split()]
cnt1 = [0] * (100100)
cnt2 = [0] * (100100)
for i in range(n):
    if (i % 2): cnt1[V[i]] += 1
    else: cnt2[V[i]] += 1 
c1 = cnt1.index(max(cnt1))
c2 = cnt2.index(max(cnt2))    
lst1 = sorted(cnt1, reverse=True)
lst2 = sorted(cnt2, reverse=True)
if (c1 == c2):
    ans = 0
    i = 2
    while (lst1[i] != 0 or lst2[i] != 0):
        if (lst1[i] != 0): ans += lst1[i]
        if (lst2[i] != 0): ans += lst2[i]
        i += 1
    print(ans + max(lst1[0]+lst2[1], lst1[1]+lst2[0]))
else:
    i = 1
    ans = 0
    while (lst1[i] != 0 or lst2[i] != 0):
        if (lst1[i] != 0): ans += lst1[i]
        if (lst2[i] != 0): ans += lst2[i]
        i += 1
    print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
V = [int(x) for x in input().split()]
cnt1 = [0] * (100100)
cnt2 = [0] * (100100)
for i in range(n):
    if (i % 2): cnt1[V[i]] += 1
    else: cnt2[V[i]] += 1 
c1 = cnt1.index(max(cnt1))
c2 = cnt2.index(max(cnt2))    
lst1 = sorted(cnt1, reverse=True)
lst2 = sorted(cnt2, reverse=True)
i = 1
ans = 0
if (c1 == c2):
    ans += min(lst1[0], lst2[0])
while (lst1[i] != 0 or lst2[i] != 0):
    if (lst1[i] != 0): ans += lst1[i]
    if (lst2[i] != 0): ans += lst2[i]
    i += 1
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
V = [int(x) for x in input().split()]
cnt = [0] * (10**5+100)
for v in V:
    cnt[v] += 1
cnt.sort(reverse=True)
i = 2
ans = max(0, cnt[0]-n//2)
while (cnt[i] != 0):
    ans += cnt[i]
    i += 1
print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    v = list(map(int,input().split()))
    odd={}
    even={}
    for i in range(n):
        if i%2==0:
            if v[i] not in odd:
                odd[v[i]]=1
            else:
                odd[v[i]]+=1
        else:
            if v[i] not in even:
                even[v[i]]=1
            else:
                even[v[i]]+=1
    cnt_o=[]
    cnt_e=[]
    for i in odd:
        cnt_o.append([odd[i],i])
    for i in even:
        cnt_e.append([even[i],i])
    cnt_o.append([0,10**6])
    cnt_e.append([0,10**6])
    cnt_o.sort(reverse=True)
    cnt_o.sort(reverse=True)
    
    if cnt_o[0][1]!=cnt_e[0][1]:
        print(n-cnt_o[0][0]-cnt_e[0][0])
        return
    else:
        print(min(n-cnt_o[1][0]-cnt_e[0][0],n-cnt_o[0][0]-cnt_e[1][0]))
        return
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import itertools
n,*l=map(int,open(0).read().split())
f=lambda g:sorted([[len(list(v)),k]for k,v in itertools.groupby(g)])[-9:]
print(n-max([n//2]+[a+c for c,d in f(l[1::2])for a,b in f(l[::2])if b-d]))

Submission status: Wrong Answer

Solution code:
from itertools import groupby
n = int(input())
a = list(map(int,input().split()))
p, q = a[::2], a[1::2]
res = n // 2
for k1, v1 in groupby(p):
    for k2, v2 in groupby(q):
        if k1 == k2:
            continue
        res = max(res, len(list(v1)) + len(list(v2)))
print(n - res)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

even = V[0::2]
odd = V[1::2]
even_max_cnt = Counter(even).most_common()
odd_max_cnt = Counter(odd).most_common()

if even_max_cnt[0][1] == len(even) and \
        odd_max_cnt[0][1] == len(odd) and \
        even_max_cnt[0][0] == odd_max_cnt[0][0]:
    ans = len(even)
else:
    ans = (len(even) - even_max_cnt[0][1]) + (len(odd) - odd_max_cnt[0][1])

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

even = V[0::2]
odd = V[1::2]
even_counter = Counter(even).most_common()
odd_counter = Counter(odd).most_common()

if even_counter[0][0] == odd_counter[0][0]:
    ans = len(even)
else:
    ans = (len(even) - even_counter[0][1]) + (len(odd) - odd_counter[0][1])

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

even = V[0::2]
odd = V[1::2]
even_max_cnt = Counter(even).most_common()
odd_max_cnt = Counter(odd).most_common()

ans = (len(even) - even_max_cnt[0][1]) + (len(odd) - odd_max_cnt[0][1])

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
v = list(map(int,input().split()))
even = []
odd = []

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

odd.sort()
even.sort()

def min(a,b):
	if a <= b:
		return a
	else:
		return b

def solve(tag):
	l = len(tag)
	bef = 0
	counter = 1
	max1,value1,max2,value2 = 0,0,0,0
	for i in range(l):
		if bef == tag[i]:
			counter = counter + 1
		else:
			if(max1 <= counter and value1 != bef):
				max2 = max1
				value2 = value1
				max1 = counter
				value1 = bef
			counter = 1
		bef = tag[i]
	if(max1 <= counter and value1 != bef):
		max2 = max1
		value2 = value1
		max1 = counter
		value1 = bef
	lis = [max1,value1,max2,value2]
	return [max1,value1,max2,value2]

res = len(v)
odr = solve(odd)
evr = solve(even)

if(odr[1] != evr[1]):
	print(n - odr[0] - evr[0])
else:
	if(odr[1] == evr[3]):
		print(n - odr[2] - evr[0])
	elif(odr[3] == evr[1]):
		print(n - odr[0] - evr[2])
	else:
		print(min(n - odr[2] - evr[0],n - odr[0] - evr[2]))

# max1 value1 max2 value2
# それぞれのvalue1が異なるなら引けばいい
# 同じならmax2を比較して大きい方を適用する。

Submission status: Wrong Answer

Solution code:
n = int(input())
v = list(map(int,input().split()))
even = []
odd = []

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

odd.sort()
even.sort()

def min(a,b):
	if a <= b:
		return a
	else:
		return b

def solve(tag):
	l = len(tag)
	bef = 0
	counter = 1
	max1,value1,max2,value2 = 0,0,0,0
	for i in range(l):
		if bef == tag[i]:
			counter = counter + 1
		else:
			if(max1 <= counter and value1 != bef):
				max2 = max1
				value2 = value1
				max1 = counter
				value1 = bef
			counter = 1
		bef = tag[i]
	if(max1 <= counter and value1 != bef):
		max2 = max1
		value2 = value1
		max1 = counter
		value1 = bef
	lis = [max1,value1,max2,value2]
	return [max1,value1,max2,value2]

res = len(v)
odr = solve(odd)
evr = solve(even)

if(odr[1] != evr[1]):
	print(n - odr[0] - evr[0])
else:
	print(min(n-odr[0]-evr[2],n-odr[2]-evr[0]))

# max1 value1 max2 value2
# それぞれのvalue1が異なるなら引けばいい
# 同じならmax2を比較して大きい方を適用する。

Submission status: Wrong Answer

Solution code:
n = int(input())
v = list(map(int,input().split()))
even = []
odd = []

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

odd.sort()
even.sort()

def min(a,b):
	if a <= b:
		return a
	else:
		return b

def solve(tag):
	l = len(tag)
	bef = 0
	counter = 1
	max1,value1,max2,value2 = 0,0,0,0
	for i in range(l):
		if bef == tag[i]:
			counter = counter + 1
		else:
			if(max1 <= counter):
				max2 = max1
				value2 = value1
				max1 = counter
				value1 = bef
			counter = 1
		bef = tag[i]
	if(max1 <= counter):
		if(value1 != 0):
			max2 = max1
			value2 = value1
		max1 = counter
		value1 = bef
	lis = [max1,value1,max2,value2]
	return [max1,value1,max2,value2]

res = len(v)
odr = solve(odd)
evr = solve(even)

if(odr[1] != evr[1]):
	print(n - odr[0] - evr[0])
else:
	print(min(n-odr[0]-evr[2],n-odr[2]-evr[0]))

# max1 value1 max2 value2
# それぞれのvalue1が異なるなら引けばいい
# 同じならmax2を比較して大きい方を適用する。

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)


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

    if len(set(v)) == 1:
        print(0)
        exit()

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

    d1 = len(set(v1)) - 1
    d2 = len(set(v2)) - 1

    print(d1+d2)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import collections

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

odd = [v[i] for i in range(0, n, 2)]
even = [v[i] for i in range(1, n, 2)]

odd_mode = collections.Counter(odd)
odd_values, odd_counts = zip(*odd_mode.most_common())

even_mode = collections.Counter(even)
even_values, even_counts = zip(*even_mode.most_common())

if odd_values[0] == even_values[0] and odd_counts[0] == len(odd) and even_counts[0] == len(even):
    print(len(odd))
    exit()

if odd_values[0] == even_values[0]:
    if odd_counts[0] >= even_counts[0]:
        ans = (len(odd) - odd_counts[0]) + (len(even) - even_counts[1])
    else:
        ans = (len(odd) - odd_counts[1]) + (len(even) - even_counts[0])
else:
    ans = (len(odd) - odd_counts[0]) + (len(even) - even_counts[0])
print(ans)

Submission status: Wrong Answer

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

p=[0]+sorted(v[0:n-1:2])+[0]
l=r=o1=o2=0
for i in range(1,n//2+2):
  if p[i-1] != p[i]:
    if l>=o1:
      o2,o1,r=o1,l,p[i-1]
    l=1
  else:
    l+=1

pr = r
po1 = o1
po2 = o2

p=[0]+sorted(v[1:n:2])+[0]
l=r=o1=o2=0
for i in range(1,n//2+2):
  if p[i-1] != p[i]:
    if l>=o1:
      o2,o1,r=o1,l,p[i-1]
    l=1
  else:
    l+=1

if pr != r:
  print(n-po1-o1)
else:
  print(min(n-po1-o2,n-o1-po2))

Submission status: Wrong Answer

Solution code:
n=int(input())

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

p=[0]+sorted(v[0:n-1:2])+[0]
l=r=o1=o2=0
for i in range(1,n//2+2):
  if p[i-1] != p[i]:
    if l>=o1:
      o2,o1,r=o1,l,p[i-1]
    l=1
  else:
    l+=1

pr = r
po1 = o1
po2 = o2

p=[0]+sorted(v[1:n:2])+[0]
l=r=o1=o2=0
for i in range(1,n//2+2):
  if p[i-1] != p[i]:
    if l>=o1:
      o2,o1,r=o1,l,p[i-1]
    l=1
  else:
    l+=1

if pr != r:
  print(n-po1-o1)
elif po1 > o1:
  print(n-po1-o2)
else:
  print(n-o1-po2)

Submission status: Wrong Answer

Solution code:
n=int(input())

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

p=[0]+sorted(v[0:n-1:2])+[0]
l=r=o1=o2=0
for i in range(1,n//2+2):
  if p[i-1] != p[i]:
    if l>=o1:
      o2,o1,r=o1,l,p[i-1]
    l=1
  else:
    l+=1

pr = r
po1 = o1
po2 = o2

p=[0]+sorted(v[1:n:2])+[0]
l=r=o1=o2=0
for i in range(1,n//2+2):
  if p[i-1] != p[i]:
    if l>=o1:
      o2,o1,r=o1,l,p[i-1]
    l=1
  else:
    l+=1

if pr != r:
  print(n-po1-o1)
elif pr > r:
  print(n-po1-o2)
else:
  print(n-o1-po2)

Submission status: Wrong Answer

Solution code:
import collections


n = int(input())
odd = []
even = []
for i,j in enumerate(map(int,input().split())):
    if i % 2 == 0:
        even += [j]
    else:
        odd += [j]
odd = sorted(collections.Counter(odd).items(),key=lambda x:(x[1]),reverse=True)
even = sorted(collections.Counter(even).items(),key=lambda x:(x[1]),reverse=True)

if len(odd) == 1 and len(even) == 1:
    if odd[0][0] == even[0][0]:
        print(n//2)
        exit()
    else:
        print(0)
        exit()

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

Submission status: Wrong Answer

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

dict_odd = dict()
dict_even = dict()

for i in range(N):
	if i % 2 == 1:
		if V[i] in dict_odd:
			dict_odd[V[i]] += 1
		else:
			dict_odd[V[i]] = 1
			
	else:
		if V[i] in dict_even:
			dict_even[V[i]] += 1
		else:
			dict_even[V[i]] = 1
			
odd_sorted = sorted(dict_odd.items(), key=lambda x:x[1], reverse = True)
even_sorted = sorted(dict_even.items(), key=lambda x:x[1], reverse = True)

if odd_sorted != even_sorted:
	print(N - odd_sorted[0][1] - even_sorted[0][1])
else:
	if len(odd_sorted) == 1 and len(even_sorted) == 1:
		print(int(N // 2))
	elif len(odd_sorted) == 1:
		print(N - odd_sorted[0][1] - even_sorted[1][1])
	elif len(even_sorted) == 1:
		print(N - odd_sorted[1][1] - even_sorted[0][1])
	else:
		print(N - max(odd_sorted[0][1] + even_sorted[1][1], odd_sorted[1][1] + even_sorted[0][1]))

Submission status: Wrong Answer

Solution code:
import collections

n = int(input())
odd = []
even = []
for i, j in enumerate(map(int, input().split())):
    if i % 2 == 0:
        even += [j]
    else:
        odd += [j]
odd = sorted(collections.Counter(odd).items(), reverse=True, key=lambda x: x[1])
even = sorted(collections.Counter(even).items(), reverse=True, key=lambda x: x[1])

if len(odd) == 1 and len(even) == 1 and odd[0][0] == even[0][0]:
    print(n // 2)
elif odd[0][0] == even[0][0]:
    if odd[0][1] == even[0][1]:
        for i in range(2):
            if odd[i][1] == even[i][1]:
                continue
            elif odd[i][1] > even[i][1]:
                print((n // 2 - odd[0][1]) + (n // 2 - even[1][1]))
                break
            elif odd[i][1] < even[i][1]:
                print((n // 2 - odd[1][1]) + (n // 2 - even[0][1]))
                break
        else:
            print((n // 2 - odd[0][1]) + (n // 2 - even[1][1]))
else:
    print((n // 2 - odd[0][1]) + (n // 2 - even[0][1]))

Submission status: Wrong Answer

Solution code:
import collections

n = int(input())
odd = []
even = []
for i, j in enumerate(map(int, input().split())):
    if i % 2 == 0:
        even += [j]
    else:
        odd += [j]
odd = sorted(collections.Counter(odd).items(), reverse=True, key=lambda x: x[1])
even = sorted(collections.Counter(even).items(), reverse=True, key=lambda x: x[1])

if len(odd) == 1 and len(even) == 1 and odd[0][0] == even[0][0]:
    print(n // 2)
elif odd[0][0] == even[0][0]:
    if odd[0][1] == even[0][1]:
        for i in range(2):
            if odd[i][1] == even[i][1]:
                continue
            elif odd[i][1] > even[i][1]:
                print((n // 2 - odd[0][1]) + (n // 2 - even[1][1]))
                break
            elif odd[i][1] < even[i][1]:
                print((n // 2 - odd[1][1]) + (n // 2 - even[0][1]))
                break
        else:
            print((n // 2 - odd[0][1]) + (n // 2 - even[1][1]))
    elif odd[0][1] > even[0][1]:
        print((n // 2 - odd[0][1]) + (n // 2 - even[1][1]))
    elif odd[0][1] < even[0][1]:
        print((n // 2 - odd[1][1]) + (n // 2 - even[0][1]))
else:
    print((n // 2 - odd[0][1]) + (n // 2 - even[0][1]))

Submission status: Wrong Answer

Solution code:
import collections

n = int(input())
odd = []
even = []
for i, j in enumerate(map(int, input().split())):
    if i % 2 == 0:
        even += [j]
    else:
        odd += [j]
odd = sorted(collections.Counter(odd).items(), reverse=True, key=lambda x: x[1])
even = sorted(collections.Counter(even).items(), reverse=True, key=lambda x: x[1])

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

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
odd = []
even = []
for i,j in enumerate(map(int,input().split())):
    if i % 2 == 0:
        even += [j]
    else:
        odd += [j]
odd = sorted(collections.Counter(odd).items(),key=lambda x:x[1])
even = sorted(collections.Counter(even).items(),key=lambda x:x[1])

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

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
odd = []
even = []
for i,j in enumerate(map(int,input().split())):
    if i % 2 == 0:
        even += [j]
    else:
        odd += [j]
odd = sorted(collections.Counter(odd).items(),key=lambda x:x[1])
even = sorted(collections.Counter(even).items(),key=lambda x:x[1])

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

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
odd = []
even = []
for i,j in enumerate(map(int,input().split())):
    if i % 2 == 0:
        even += [j]
    else:
        odd += [j]
odd = sorted(collections.Counter(odd).items(),key=lambda x:x[1])
even = sorted(collections.Counter(even).items(),key=lambda x:x[1])

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

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
odd = []
even = []
for i,j in enumerate(map(int,input().split())):
    if i % 2 == 0:
        even += [j]
    else:
        odd += [j]
odd = sorted(collections.Counter(odd).items(),key=lambda x:x[1])
even = sorted(collections.Counter(even).items(),key=lambda x:x[1])

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

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
odd = []
even = []
for i,j in enumerate(map(int,input().split())):
    if i % 2 == 0:
        even += [j]
    else:
        odd += [j]
odd = max(collections.Counter(odd).items(),key=lambda x:x[1])
even = max(collections.Counter(even).items(),key=lambda x:x[1])
if odd[0] == even[0]:
    print(n//2)
else:
    print((n//2 - odd[1]) + (n//2 - even[1]))

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

s1 = Counter(V).most_common(2)[0]
s2 = Counter(V).most_common(2)[0]
V1 = V[0::2]
V2 = V[1::2]
x1, c1 = Counter(V1).most_common(1)[0]
x2, c2 = Counter(V2).most_common(1)[0]
if x1 == x2:
    if c1 > c2:
        x2, c2 = Counter(V2).most_common(2)[1]
    elif c1 < c2:
        x1, c1 = Counter(V1).most_common(2)[1]
    elif c1 == c2 == N // 2:
        c1, c2 = N//2, 0
    else:
        x2, c2 = Counter(V2).most_common(2)[1]

print(N - c1 - c2)

Submission status: Wrong Answer

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

dE={};dO={}
for i in range(n):
    dX=dE if i%2==0 else dO
    if v[i] in dX:
        dX[v[i]]+=1
    else:
        dX[v[i]]=1

lE=sorted(list(dE.items()),key=lambda x:x[1],reverse=True)
lO=sorted(list(dO.items()),key=lambda x:x[1],reverse=True)
ME=lE[0][1];MO=lO[0][1]
aE=lE[0][0];aO=lO[0][0]

if len(lE)==len(lO)==1:
    if aE==aO:
        ans=n//2
    else:
        ans=0
elif len(lE)>1:
    SE=lE[1][1]    
    if aE==aO:
        ans=n//2-SE
    else:
        ans=n//2-ME
elif len(lO)>1:
    SO=lO[1][1]
    if aE==aO:
        ans=n//2-SO
    else:
        ans=n//2-MO
else:
    if aE==aO:
        ans=n-max(ME+SO,MO+SE)
    else:
        ans=n-(ME+MO)

print(ans)

Submission status: Wrong Answer

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

dE={};dO={}
for i in range(n):
    dX=dE if i%2==0 else dO
    if v[i] in dX:
        dX[v[i]]+=1
    else:
        dX[v[i]]=1

lE=sorted(list(dE.items()),key=lambda x:x[1],reverse=True)
lO=sorted(list(dO.items()),key=lambda x:x[1],reverse=True)

ME=lE[0][1];MO=lO[0][1]
if lE[0][0]!=lO[0][0]:
    ans=n-ME-MO
elif len(lE)==len(lO)==1:
    ans=n//2
elif len(lE)>1:
    SE=lE[1][1]
    ans=n-SE-MO
elif len(lO)>1:
    SO=lO[1][1]
    ans=n-ME-SO

print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
V=list(map(int,input().split()))
A=[0]*(10**5+1)
B=[0]*(10**5+1)
for i in range(N):
  if(i%2==0):
    A[V[i]]+=1
  else:
    B[V[i]]+=1
MA=0
NA=A[0]
NA2=A[0]
MB=0
NB=B[0]
NB2=B[0]
for i in range(10**5+1):
  if(A[i]>=NA):
    NA2=NA
    NA=A[i]
    MA=i
  if(B[i]>=NB):
    NB2=NB
    NB=B[i]
    MB=i
if(MA!=MB):
  print(N-NA-NB)
else:
  print(min(N-NA-NB2,N-NA2-NB))
print(MA,MB,NA,NA2,NB,NB2)

Submission status: Wrong Answer

Solution code:
N=int(input())
V=list(map(int,input().split()))
A=[0]*(10**5+1)
B=[0]*(10**5+1)
for i in range(N):
  if(i%2==0):
    A[V[i]]+=1
  else:
    B[V[i]]+=1
MA=0
NA=A[0]
NA2=A[0]
NA3=0
MB=0
NB=B[0]
NB2=B[0]
NB3=0
for i in range(10**5+1):
  if(A[i]>NA):
    NA2=NA
    NA=A[i]
    MA=i
  elif(A[i]==NA):
    NA3=A[i]
  if(B[i]>NB):
    NB2=NB
    NB=B[i]
    MB=i
  elif(B[i]==NB):
    NB3=B[i]
if(MA!=MB or NA==NA3 or NB==NB3):
  print(N-NA-NB)
else:
  print(min(N-NA-NB2,N-NA2-NB))

Submission status: Wrong Answer

Solution code:
import collections

n = int(input())
v = list(map(int, input().split()))
even = []
odd = []
for i in range(0, n, 2):
    odd.append(v[i])
for i in range(1, n, 2):
    even.append(v[i])
odd_counter = collections.Counter(odd)
even_counter = collections.Counter(even)

odd_counter_sorted = sorted(odd_counter.items(),
                            key=lambda x: x[1],
                            reverse=True)
even_counter_sorted = sorted(even_counter.items(),
                             key=lambda x: x[1],
                             reverse=True)
if odd_counter_sorted[0][0] != even_counter_sorted[0][0]:
    print(
        len(odd) - odd_counter_sorted[0][1] + len(even) -
        even_counter_sorted[0][1])
else:
    if (len(odd) - odd_counter_sorted[0][1]) > (len(even) -
                                                even_counter_sorted[0][1]):
        if len(odd_counter_sorted) > 1:
            print(
                len(odd) - odd_counter_sorted[1][1] + len(even) -
                even_counter_sorted[0][1])
        else:
            print(len(odd) + len(even) - even_counter_sorted[0][1])
    else:
        if len(even_counter_sorted) > 1:
            print(
                len(odd) - odd_counter_sorted[0][1] + len(even) -
                even_counter_sorted[1][1])
        else:
            print(len(odd) - odd_counter_sorted[0][1] + len(even))

Submission status: Wrong Answer

Solution code:
import collections

n = int(input())
v = list(map(int, input().split()))
even = []
odd = []
for i in range(0, n, 2):
    odd.append(v[i])
for i in range(1, n, 2):
    even.append(v[i])
odd_counter = collections.Counter(odd)
even_counter = collections.Counter(even)

odd_counter_sorted = sorted(odd_counter.items(),
                            key=lambda x: x[1],
                            reverse=True)
even_counter_sorted = sorted(even_counter.items(),
                             key=lambda x: x[1],
                             reverse=True)
if odd_counter_sorted[0][0] != even_counter_sorted[0][0]:
    print(
        len(odd) - odd_counter_sorted[0][1] + len(even) -
        even_counter_sorted[0][1])
else:
    if (len(odd) - odd_counter_sorted[0][1]) >= (len(even) -
                                                 even_counter_sorted[0][1]):
        if len(odd_counter_sorted) > 1:
            print(
                len(odd) - odd_counter_sorted[1][1] + len(even) -
                even_counter_sorted[0][1])
        else:
            print(len(odd) + len(even) - even_counter_sorted[0][1])
    else:
        if len(even_counter_sorted) > 1:
            print(
                len(odd) - odd_counter_sorted[0][1] + len(even) -
                even_counter_sorted[1][1])
        else:
            print(len(odd) - odd_counter_sorted[0][1] + len(even))