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()))
if len(set(v)) == 1:
	print (n//2)
	exit()
a = v[1::2]
b = v[0::2]
if len(set(a)) == 1 and len(set(b)) == 1:
	print (0)
	exit()

aa = collections.Counter(a)
bb = collections.Counter(b)
maa = aa.most_common()[0][1]
mbb = bb.most_common()[0][1]
if maa == mbb:
	if len(a) == 1:
		ans = (len(a) - maa) + (len(b) - bb.most_common()[1][1])
	elif len(b) == 1:
		ans = (len(a) - aa.most_common()[1][1]) + (len(b)-mbb)
	else:
		ans = (len(a) - maa) + (len(b) - bb.most_common()[1][1])
else:
	ans = len(a)-maa + len(b)-mbb
print (ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
v = list(map(int, input().split()))
if len(set(v)) == 1:
	print (n//2)
	exit()
a = v[1::2]
b = v[0::2]
aa = set(a)
bb = set(b)
ans = len(aa)-1 + len(bb)-1
print (ans)

Submission status: Wrong Answer

Solution code:
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate
import sys
import bisect
import string
import math
import time


def I(): return int(input())


def MI(): return map(int, input().split())


def S(): return input()


def MS(): return map(str, input().split())


def LI(): return [int(i) for i in input().split()]


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


def input(): return sys.stdin.readline().rstrip()


def show(*inp, end='\n'):
    if show_flg:
        print(*inp, end=end)


YN = {False: 'No', True: 'Yes'}
MOD = 10**9+7
inf = float('inf')
IINF = 10**10
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
# sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']


show_flg = True
show_flg = False


def main():
    N = I()
    v = LI()
    first_counter = {}
    second_counter = {}

    for i in range(N):
        if i % 2 == 0:
            if v[i] not in first_counter:
                first_counter[v[i]] = 0
            first_counter[v[i]] += 1
        else:
            if v[i] not in second_counter:
                second_counter[v[i]] = 0
            second_counter[v[i]] += 1

    first_items = sorted([(v, k) for k, v in first_counter.items()], reverse=True)
    second_items = sorted([(v, k)
                           for k, v in second_counter.items()], reverse=True)

    # print(first_items, second_items)
    first_counter, first_value = first_items.pop(0)
    second_counter, second_value = second_items.pop(0)

    first_total_count = (N + (2 - 1)) // 2
    second_total_count = N // 2

    if first_value != second_value:
        print(first_total_count - first_counter + second_total_count - second_counter)
    else:
        if first_counter >= second_total_count:
            if len(second_items) == 0:
                print(first_total_count - first_counter + second_total_count)
            else:
                second_counter, second_value = second_items.pop(0)
                print(first_total_count - first_counter + second_total_count - second_counter)
        else:
            if len(first_items) == 0:
                print(first_total_count + second_total_count - second_counter)
            else:
                first_counter, first_value = first_items.pop(0)
                print(first_total_count - first_counter + second_total_count - second_counter)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from collections import Counter
from operator import itemgetter

n = int(input())
v = [int(i) for i in input().split()]
a = sorted(Counter(v[::2]).items(), key=itemgetter(1))
b = sorted(Counter(v[1::2]).items(), key=itemgetter(1))
ka, va = a[-1]
kb, vb = b[-1]
if ka != kb:
    print(n - va - vb)
else:
    sa = a[-2][1] if len(a) > 1 else va
    sb = b[-2][1] if len(b) > 1 else vb
    if len(a) == len(b) == 1:
        sa = 0
    if sa < sb:
        print(n - sa - vb)
    else:
        print(n - va - sb)

Submission status: Wrong Answer

Solution code:
from collections import Counter
from operator import itemgetter

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

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

even =Counter(even)
even = list(even.items())
even = sorted(even,key=itemgetter(1),reverse = True)

odd =Counter(odd)
odd = list(odd.items())
odd = sorted(odd,key=itemgetter(1),reverse = True)

cnt = 0
if len(odd) == 1 and len(even) == 1:
    if odd[0][0] == even[0][0]:
        cnt = N // 2
    else:
        cnt = 0
elif even[0][1] != odd[0][1]:
    cnt = N - (even[0][1] + odd[0][1])
elif odd[0][1] == even[0][1]:
        cnt = N- (max(odd[0][1] + even[1][1],even[0][1] + odd[1][1]))

print(cnt)

Submission status: Wrong Answer

Solution code:
from collections import Counter
from operator import itemgetter

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

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

even =Counter(even)
even = list(even.items())
even = sorted(even,key=itemgetter(1),reverse = True)

odd =Counter(odd)
odd = list(odd.items())
odd = sorted(odd,key=itemgetter(1),reverse = True)

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

print(cnt)

Submission status: Wrong Answer

Solution code:
from collections import Counter
from operator import itemgetter

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

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

even =Counter(even)
even = list(even.items())
even = sorted(even,key=itemgetter(1),reverse = True)

odd =Counter(odd)
odd = list(odd.items())
odd = sorted(odd,key=itemgetter(1),reverse = True)

cnt = 0
if len(odd) == 1 and len(even) == 1:
    cnt = N // 2

elif even[0][1] != odd[0][1]:
    cnt = N - (even[0][1] + odd[0][1])
elif odd[0][1] == even[0][1]:
    if even[1][1] > odd[1][1]:
        cnt = N- (odd[0][1] + even[1][1])
    elif odd[1][1] > even[1][1]:
        cnt = N- (even[0][1] + odd[1][1])

print(cnt)

Submission status: Wrong Answer

Solution code:
from collections import Counter
from operator import itemgetter

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

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

even =Counter(even)
even = list(even.items())
even = sorted(even,key=itemgetter(1),reverse = True)

odd =Counter(odd)
odd = list(odd.items())
odd = sorted(odd,key=itemgetter(1),reverse = True)

cnt = 0
if len(odd) == 0 :
    if len(even) == 1:
        cnt = N // 2
    else:
        cnt = 0
elif len(even) == 0 :
    if len(odd) == 1:
        cnt = N // 2
    else:
        cnt = 0
elif even[0][1] != odd[0][1]:
    cnt = N - (even[0][1] + odd[0][1])
elif odd[0][1] == even[0][1]:
    if even[1][1] > odd[1][1]:
        cnt = N- (odd[0][1] + even[1][1])
    elif odd[1][1] > even[1][1]:
        cnt = N- (even[0][1] + odd[1][1])

print(cnt)

Submission status: Wrong Answer

Solution code:

from collections import Counter
from operator import itemgetter

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

C = list(V.items())
C = sorted(C,key=itemgetter(1),reverse = True)
#print(C)

#奇数、偶数に分ける
even = []
odd = []
for i in range(min(len(C),100)):
    if C[i][0] % 2 ==0:
        even.append(C[i])
    else:
        odd.append(C[i])
#print(even,odd)

cnt = 0
if len(odd) == 0 :
    if len(even) == 1:
        cnt = N // 2
    else:
        cnt = 0
elif len(even) == 0 :
    if len(odd) == 1:
        cnt = N // 2
    else:
        cnt = 0
#書き換える数は最頻出の上位２つ以外、つまりn-(even[0][1]+even[1][1])
elif even[0][1] > odd[0][1]:
    cnt = N - (even[0][1] + even[1][1])
elif odd[0][1] > even[0][1]:
    cnt = N - (odd[0][1] + odd[1][1])
elif odd[0][1] == even[0][1]:
    if even[1][1] > odd[1][1]:
        cnt = N- (even[0][1] + even[1][1])
    elif odd[1][1] > even[1][1]:
        cnt = N- (odd[0][1] + odd[1][1])

print(cnt)

Submission status: Wrong Answer

Solution code:
from collections import Counter
from operator import itemgetter

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

C = list(V.items())
C = sorted(C,key=itemgetter(1),reverse = True)

even = []
odd = []
for i in range(min(len(C),100)):
    if C[i][0] % 2 ==0:
        even.append(C[i])
    else:
        odd.append(C[i])


cnt = 0
if len(odd) == 0 :
    if len(even) == 1:
        cnt = N // 2
    else:
        cnt = 0
elif len(even) == 0 :
    if len(odd) == 1:
        cnt = N // 2
    else:
        cnt = 0
elif even[0][1] > odd[0][1]:
    cnt = even[0][1] - even[1][1]
elif odd[0][1] > even[0][1]:
    cnt = odd[0][1] - odd[1][1]
elif odd[0][1] == even[0][1]:
    if even[1][1] > odd[1][1]:
        cnt = even[0][1] - even[1][1]
    elif odd[1][1] > even[1][1]:
        cnt = odd[0][1] - odd[1][1]

print(cnt)

Submission status: Wrong Answer

Solution code:
from collections import Counter
from operator import itemgetter

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

#リスト化し頻出順にソート
C = list(V.items())
C = sorted(C,key=itemgetter(1),reverse = True)
#print(C)

#奇数、偶数に分ける
even = []
odd = []
for i in range(min(len(C),100)):
    if C[i][0] % 2 ==0:
        even.append(C[i])
    else:
        odd.append(C[i])
#print(even,odd)

cnt = 0
if len(odd) == 0 :
    if len(even) == 1:
        cnt = N // 2
    else:
        cnt = 0
elif len(even) == 0 :
    if len(odd) == 1:
        cnt = N // 2
    else:
        cnt = 0
elif even[0][1] > odd[0][1]:
    cnt = even[0][1] - even[1][1]
elif odd[0][1] > even[0][1]:
    cnt = odd[0][1] - odd[1][1]
elif odd[0][1] == even[0][1]:
    if even[1][1] > odd[1][1]:
        cnt = even[0][1] - even[1][1]
    elif odd[1][1] > even[1][1]:
        cnt = odd[0][1] - odd[1][1]

Submission status: Wrong Answer

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

def count(l):
    ans = 1
    l.sort()
    for i in range(len(l)-1):
        if l[i] != l[i+1]:
            ans += 1
    return ans

even = []
odd = []
for i in range(0, n, 2):
    even.append(v[i])
    
for j in range(1, n, 2):
    odd.append(v[j])
    
if odd == even:
    print(len(odd))
else:
    print(count(even) + count(odd) - 2)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3

n = int(input())
a = list(map(int,input().split()))
cnt = [0]*(10**5+1)
for i in a:
    cnt[i] += 1
cnt.sort()
#print(cnt[-1])
if cnt[-1] >= (n+1)//2: print(n//2 - cnt[-2])
else: print((n+1)//2 - cnt[-1]+ n//2 - cnt[-2])

Submission status: Wrong Answer

Solution code:
import collections

n = int(input())
u = [int(i) for i in input().split()]
a1 = collections.Counter(u[0::2]).most_common()
a2 = collections.Counter(u[1::2]).most_common()

if len(u) == 2:
    print(1)
    exit()
if len(a1) == 1 and len(a2) == 1:
    print(2)
    exit()

ans = 0
if len(a1) != 1:
    for i in range(1, len(a1)):
        ans += a1[i][1]
if len(a2) != 1:
    for i in range(1, len(a2)):
        ans += a2[i][1]
print(ans)

Submission status: Wrong Answer

Solution code:
import collections

n = int(input())
u = [int(i) for i in input().split()]
a1 = collections.Counter(u[0::2]).most_common()
a2 = collections.Counter(u[1::2]).most_common()

if len(a1) == 1 and len(a2) == 1:
    print(2)
    exit()

ans = 0
if len(a1) != 1:
    for i in range(1, len(a1)):
        ans += a1[i][1]
if len(a2) != 1:
    for i in range(1, len(a2)):
        ans += a2[i][1]
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
 
n = int(input())
v_array = list(map(int,input().split()))
 
v_odd = v_array[0::2]
v_even = v_array[1::2]
 
v_odd_common = Counter(v_odd).most_common()
v_even_common = Counter(v_even).most_common()

v_odd_common.append((0,0))
v_even_common.append((0,0))

print(v_odd_common[0])

if v_odd_common[0] != v_even_common[0]:
    print(n-v_odd_common[0][1]-v_even_common[0][1])
else:
    print(min(n-v_odd_common[0][1]-v_even_common[1][1],n-v_odd_common[1][1]-v_even_common[0][1]))

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
d = defaultdict(int)

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

for i in li:
  d[i] += 1
  
max1 = 0
max2 = 0

for s in d:
  if d[s] > max1:
    max1 = s
  elif max1 >= d[s] > max2:
    max2 = s
    
if len(d) == 1:
  max2 = max1 + 1
    
ans = 0
ans += abs(li[0] - max1) + abs(li[1] - max2)
li[0] = max1
li[1] = max2
  
for index, i in enumerate(li):
  if index == 0 or index == 1:
    continue
    
  ans += abs(li[index] - li[index-2])
  
ans1 = 0
ans1 += abs(li[0] - max2) + abs(li[1] - max1)
li[0] = max2
li[1] = max1

for index, i in enumerate(li):
  if index == 0 or index == 1:
    continue
    
  ans1 += abs(li[index] - li[index-2])
  


print(min(ans, ans1))

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
d = defaultdict(int)

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

for i in li:
  d[i] += 1
  
max1 = 0
max2 = 0

for s in d:
  if d[s] > max1:
    max1 = s
  elif max1 >= d[s] > max2:
    max2 = s
    
if len(d) == 1:
  max2 = max1 + 1
    
ans = 0
if abs(li[0] - max1) > abs(li[0] - max2):
  ans += abs(li[0] - max2)
  ans += abs(li[1] - max1)
  li[0] = max2
  li[1] = max1
else:
  ans += abs(li[0] - max1)
  ans += abs(li[1] - max2)
  li[0] = max1
  li[1] = max2
  
for index, i in enumerate(li):
  if index == 0 or index == 1:
    continue
    
  ans += abs(li[index] - li[index-2])

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
from collections import defaultdict

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

IN=lambda : map(int, input().split())
mod=1000000007

#+++++

def main():
	n = int(input())
	al = list(IN())
	odd_dd=defaultdict(lambda : 0)
	even_dd=defaultdict(lambda :0)
	for i, v in enumerate(al):
		if i%2==0:
			odd_dd[v] += 1
		else:
			even_dd[v] += 1
	
	odd_ll=[(odd_dd[key], key) for key in odd_dd.keys()]
	even_ll=[(even_dd[key], key) for key in even_dd.keys()]
	
	#全部同じ
	if len(odd_ll)==1 and len(even_ll)==1:
		if odd_ll[0][1]==even_ll[0][1]:
			return odd_ll[0][0]
		else:
			return 0
	odd_ll.sort(reverse=True)
	even_ll.sort(reverse=True)
	kk=n//2
	if odd_ll[0][1] == even_ll[0][1]:
		if odd_ll[0][0] >= even_ll[0][0]:
			return (kk-odd_ll[0][0])+(kk-even_ll[1][0])
		else:
			return (kk-odd_ll[1][0])+(kk-even_ll[0][0])
	else:
		return (kk-odd_ll[0][0])+(kk-even_ll[0][0])
	
	#pa(odd_ll)
	#print(str(a+b+c)+s)
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Submission status: Wrong Answer

Solution code:
# NG
from collections import Counter

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

even_l = l[0::2]
odd_l = l[1::2]

even_c = Counter(even_l)
odd_c = Counter(odd_l)
em = even_c.most_common()
om = odd_c.most_common()

ans = 0
if len(em) > 1 and len(om) > 1:
    if em[0][0] == om[0][0]:
        if em[0][1] > om[0][1]:
            ans += n - em[0][1] - om[1][1]
        else:
            ans += n - em[1][1] - om[0][1]
    else:
        ans += n - em[0][1] - om[0][1]
elif len(em) == 1 and len(om) == 1:
    if em[0][0] == om[0][0]:
        ans = n / 2
    else:
        ans = 0
elif len(em) == 1:
    ans = (n / 2) - om[1][1]
else:
    ans = (n / 2) - om[0][1]
print(int(ans))

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

even_l = l[0::2]
odd_l = l[1::2]

even_c = Counter(even_l)
odd_c = Counter(odd_l)
em = even_c.most_common()
om = odd_c.most_common()

ans = 0
if len(em) > 1 and len(om) > 1:
    if em[0][0] == om[0][0]:
        if em[0][1] > om[0][1]:
            ans += n - em[0][1] - om[1][1]
        else:
            ans += n - em[1][1] - om[0][1]
    else:
        ans += n - em[0][1] - om[0][1]
elif len(em) == 1 and len(om) == 1:
    if em[0][0] == om[0][0]:
        ans = n / 2
    else:
        ans = n - em[0][1] - om[0][1]
elif len(em) == 1:
    if em[0][0] == om[0][0]:
        ans = (n / 2) - om[1][1]
    else:
        ans = (n / 2) - om[1][1]
else:
    if em[0][0] == om[0][0]:
        ans = (n / 2) - om[0][1]
    else:
        ans = (n / 2) - om[0][1]
print(int(ans))

Submission status: Wrong Answer

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

cnt = [0] * 2
l = sorted(l, reverse=True)
tmp = l[0]
t = 0
for i in l:
    if tmp == i:
        cnt[t] += 1
    else:
        t += 1
        tmp = i
        if t >= 2:
            break
        cnt[t] += 1
w = n / 2

print(int(abs(w - cnt[0]) + abs(w - cnt[1])))

Submission status: Wrong Answer

Solution code:
n = int(input())
l = list(map(int, input().split()))
l = sorted(l)
s = set(l)
counts = {}
total = 0
for i in s:
    c = l.count(i)
    counts[i] = c
    total += c

if len(counts) == 1:
    print(total // 2)
elif len(counts) == 2:
    v = counts.values()
    print(max(v) - min(v))
else:
    a = counts.pop(max(counts, key=counts.get))
    b = counts.pop(max(counts, key=counts.get))
    print(total - a - b)

Submission status: Wrong Answer

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

even_v=[]
odd_v=[]
for i in range(N):
    if i%2==0:
        even_v.append(v[i])
    else:
        odd_v.append(v[i])

import collections
even_c = collections.Counter(even_v)
odd_c = collections.Counter(odd_v)

even_num = even_c.most_common()[0][0]
odd_num = odd_c.most_common()[0][0]
even_cnt = even_c.most_common()[0][1]
odd_cnt = odd_c.most_common()[0][1]

if even_num == odd_num:
    if len(odd_c.most_common())==1 and len(even_c.most_common())==1: # only one num
        odd_num=even_num+1
    elif len(odd_c.most_common())!=1 and len(even_c.most_common())==1: # change odd
        odd_num = odd_c.most_common()[1][0]
    elif len(odd_c.most_common())==1 and len(even_c.most_common())!=1: # change even
        even_num = even_c.most_common()[1][0]
    else:
        if odd_cnt==even_cnt:
            even_cnt2= even_c.most_common()[1][1]
            odd_cnt2 = odd_c.most_common()[1][1]
            if even_cnt2>odd_cnt2:
                even_num = even_c.most_common()[1][0]
            else:
                odd_num = odd_c.most_common()[1][0]
        if odd_cnt>even_cnt:
            even_num = even_c.most_common()[1][0]
        else:
            odd_num = odd_c.most_common()[1][0]
ans=0
for i in range(N):
    if i%2==0:
        num=even_num
    else:
        num=odd_num
    if num!=v[i]:
        ans+=1

print(ans)

Submission status: Wrong Answer

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

even_v=[]
odd_v=[]
for i in range(N):
    if i%2==0:
        even_v.append(v[i])
    else:
        odd_v.append(v[i])

import collections
even_c = collections.Counter(even_v)
odd_c = collections.Counter(odd_v)

even_num = even_c.most_common()[0][0]
odd_num = odd_c.most_common()[0][0]
even_cnt = even_c.most_common()[0][1]
odd_cnt = odd_c.most_common()[0][1]

if even_num == odd_num:
    if len(odd_c.most_common())==1 and len(even_c.most_common())==1: # only one num
        odd_num=even_num+1
    elif len(odd_c.most_common())!=1 and len(even_c.most_common())==1: # change odd
        odd_num = odd_c.most_common()[1][0]
    elif len(odd_c.most_common())==1 and len(even_c.most_common())!=1: # change even
        even_num = even_c.most_common()[1][0]
    else:
        if odd_cnt>even_cnt:
            even_num = even_c.most_common()[1][0]
        else:
            odd_num = odd_c.most_common()[1][0]
ans=0
for i in range(N):
    if i%2==0:
        num=even_num
    else:
        num=odd_num
    if num!=v[i]:
        ans+=1

print(ans)

Submission status: Wrong Answer

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

even_v=[]
odd_v=[]
for i in range(N):
    if i%2==0:
        even_v.append(v[i])
    else:
        odd_v.append(v[i])

import collections

even_c = collections.Counter(even_v)
odd_c = collections.Counter(odd_v)

even_num = even_c.most_common()[0][0]
odd_num = odd_c.most_common()[0][0]

if even_num == odd_num:
    if len(odd_c.most_common())==1:
        odd_num=even_num+1
    else:
        odd_num = odd_c.most_common()[1][0]

ans=0
for i in range(N):
    if i%2==0:
        num=even_num
    else:
        num=odd_num
    if num!=v[i]:
        ans+=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()[0][0]
odd=Counter(V[1::2]).most_common()[0][0]

cnt=0
for i,j in enumerate(V):
    if i%2==0 and j!=even:cnt +=1
    elif i%2==1 and j!=odd:cnt +=1

print(cnt if even!=odd else n//2)

Submission status: Wrong Answer

Solution code:
n=int(input())
v=list(map(int,input().split()))
from collections import defaultdict
dict_odd=defaultdict(lambda :0)
dict_even=defaultdict(lambda :0)
dict_even[0],dict_odd[0]=0,0
for i in range(0,n,2):
    dict_even[v[i]]+=1

for i in range(1,n,2):
    dict_odd[v[i]]+=1

even_val=list(dict_even.items())
odd_val=list(dict_odd.items())
even_val=sorted(even_val,reverse=True,key=lambda x: x[1])
odd_val=sorted(odd_val,reverse=True,key=lambda x: x[1])

if even_val[0][0]!=odd_val[0][0]:
    print(n-odd_val[0][1]-even_val[0][1])
else:
    ans1=n-odd_val[1][1]-even_val[0][1]
    ans2=n-odd_val[0][1]-even_val[1][1]
    print(max(ans1,ans2))

Submission status: Wrong Answer

Solution code:
from collections import Counter

import numpy as np

n = int(input())
v = np.array(list(map(int, input().split())))
# print('v', v)
# print('v odd', v[::2])
# print('v even', v[1::2])

odd_counter = tuple(Counter(v[::2]).items())
even_counter = tuple(Counter(v[1::2]).items())
odd_counter = sorted(odd_counter, key=lambda x: -x[0])
even_counter = sorted(even_counter, key=lambda x: -x[0])
# print('odd_counter', odd_counter)
# print('even_counter', even_counter)

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

i = 0
j = 0
if odd_counter[i][0] == even_counter[j][0]:
    if len(odd_counter) == 1:
        j += 1
    elif len(even_counter) == 1:
        i += 1
    else:
        odd_diff = odd_counter[0][1] - odd_counter[1][1]
        even_diff = even_counter[0][1] - even_counter[1][1]
        if odd_diff > even_diff:
            j += 1
        else:
            i += 1
ans = n - odd_counter[i][1] - even_counter[j][1]
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = input().split(" ")
A = [int(i) for i in A]

def mostFrequent(arr, n): 
    arr.sort() 
    max_count = 1; res = arr[0]; curr_count = 1
    for i in range(1, n):  
        if (arr[i] == arr[i - 1]): 
            curr_count += 1
        else : 
            if (curr_count > max_count):  
                max_count = curr_count 
                res = arr[i - 1] 
            curr_count = 1
    if (curr_count > max_count): 
        max_count = curr_count 
        res = arr[n - 1] 
    return max_count 

# print(A[::2])
ans = 0
	
if len(A) >2 :
	if len(set(A[::2])) != 1:
		# print("1")
		k = mostFrequent(A[::2],len(A[::2]))
		ans += len(A[::2])-k 
	if len(set(A[1::2])) != 1:
		k = mostFrequent(A[1::2],len(A[1::2]))
		ans += len(A[1::2])-k
elif len(A) == 2:
	if A[0] == A[1]:
		ans +=1

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = input().split(" ")
A = [int(i) for i in A]

def mostFrequent(arr, n): 
    arr.sort() 
    max_count = 1; res = arr[0]; curr_count = 1
    for i in range(1, n):  
        if (arr[i] == arr[i - 1]): 
            curr_count += 1
        else : 
            if (curr_count > max_count):  
                max_count = curr_count 
                res = arr[i - 1] 
            curr_count = 1
    if (curr_count > max_count): 
        max_count = curr_count 
        res = arr[n - 1] 
    return max_count 

# print(A[::2])
ans = 0
if len(A) >2 :
	if len(set(A[::2])) != 1:
		# print("1")
		k = mostFrequent(A[::2],len(A[::2]))
		ans += len(A[::2])-k 
	if len(set(A[1::2])) != 1:
		k = mostFrequent(A[1::2],len(A[1::2]))
		ans += len(A[1::2])-k
else:
	if A[0] == A[1]:
		ans +=1
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
def mostFrequent(arr, n): 
    arr.sort() 
    max_count = 1; res = arr[0]; curr_count = 1
    for i in range(1, n):  
        if (arr[i] == arr[i - 1]): 
            curr_count += 1
        else : 
            if (curr_count > max_count):  
                max_count = curr_count 
                res = arr[i - 1] 
            curr_count = 1
    if (curr_count > max_count): 
        max_count = curr_count 
        res = arr[n - 1] 
    return max_count 

A = input().split(" ")
A = [int(i) for i in A]
# print(A[::2])
ans = 0
if len(set(A[::2])) != 1:
	# print("1")
	k = mostFrequent(A[::2],len(A[::2]))
	ans += len(A[::2])-k 
if len(set(A[1::2])) != 1:
	k = mostFrequent(A[1::2],len(A[1::2]))
	ans += len(A[1::2])-k
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = input().split(" ")
A = [int(i) for i in A]
# print(A[::2])
ans = 0
if len(set(A[::2])) != 1:
	# print("1")
	counts= []
	set_1 = []
	set_1 = list(set(A[::2]))
	for each in set_1:
		# print(1)
		counts.append(set_1.count(each))
	m = max(counts)
	# print(m)
	ans += len(A[::2]) - m
if len(set(A[1::2])) != 1:
	counts= []
	set_1  =[]
	set_1 = list(set(A[1::2]))
	for each in set_1:
		counts.append(set_1.count(each))
	m = max(counts)
	ans += len(A[::2]) - m
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

import numpy as np

n = int(input())
v = np.array(list(map(int, input().split())))
# print('v', v)
# print('v odd', v[::2])
# print('v even', v[1::2])

odd_counter = tuple(Counter(v[::2]).items())
even_counter = tuple(Counter(v[1::2]).items())
odd_counter = sorted(odd_counter, key=lambda x: -x[0])
even_counter = sorted(even_counter, key=lambda x: -x[0])
# print('odd_counter', odd_counter)
# print('even_counter', even_counter)

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

i = 0
j = 0
if odd_counter[i][0] == even_counter[j][0]:
    if odd_counter[i][1] >= even_counter[j][1]:
        if len(even_counter) >= 2:
            j += 1
        else:
            i += 1
    else:
        if len(odd_counter) >= 2:
            i += 1
        else:
            j += 1
ans = n - odd_counter[i][1] - even_counter[j][1]
print(ans)

Submission status: Wrong Answer

Solution code:
import collections

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

Va, Vb = [], []
for i in range(N):
    if i % 2 == 0:
        Va.append(V[i])
    else:
        Vb.append(V[i])

Va_most = collections.Counter(Va).most_common()
Vb_most = collections.Counter(Vb).most_common()

if N == collections.Counter(V).most_common()[0][1]:
    print(N//2)
    exit()

if Va_most[0][0] == Vb_most[0][0]:
    typea = (len(Va) - Va_most[0][1]) + (len(Vb) - Vb_most[0][1])
    typeb = (len(Va) - Va_most[0][1]) + (len(Vb) - Vb_most[0][1])
    print(min(typea, typeb))
    exit()

print((len(Va) - Va_most[0][1]) + (len(Vb) - Vb_most[0][1]))

Submission status: Wrong Answer

Solution code:
import collections

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

Va, Vb = [], []
for i in range(N):
    if i % 2 == 0:
        Va.append(V[i])
    else:
        Vb.append(V[i])

Va_most = collections.Counter(Va).most_common()
Vb_most = collections.Counter(Vb).most_common()


if Va == Vb:
    print(len(Va))
    exit()

if Va_most == Vb_most:
    Va_most_sec = collections.Counter(Va).most_common()
    Vb_most_sec = collections.Counter(Vb).most_common()
    typea = (len(Va) - Va_most[0][1]) + (len(Vb) - Vb_most_sec[0][1])
    typeb = (len(Va) - Va_most_sec[0][1]) + (len(Vb) - Vb_most[0][1])
    print(min(typea, typeb))
    exit()

print((len(Va) - Va_most[0][1]) + (len(Vb) - Vb_most[0][1]))

Submission status: Wrong Answer

Solution code:
import collections
n=int(input())
v=list(map(int,input().split()))
a=[]
b=[]
for i in range(0,n,2):
    a.append(v[i])
    b.append(v[i+1])
    
a_count=collections.Counter(a)
b_count=collections.Counter(b)

if a_count.most_common()[0][0]==b_count.most_common()[0][0]:
    if a_count.most_common()[0][1]==n//2 :
        print(a_count.most_common()[0][1])
    else:
        print(min(a_count.most_common()[0][1]-a_count.most_common()[1][1],b_count.most_common()[0][1]-b_count.most_common()[1][1]))
else:
    ans=n-a_count.most_common()[0][1]-b_count.most_common()[0][1]
    print(ans)

Submission status: Wrong Answer

Solution code:
import collections
n=int(input())
v=list(map(int,input().split()))
a=[]
b=[]
for i in range(0,n,2):
    a.append(v[i])
    b.append(v[i+1])
    
a_count=collections.Counter(a)
b_count=collections.Counter(b)

if a_count.most_common()[0][0]==b_count.most_common()[0][0]:
    if a_count.most_common()[0][1]==n//2 :
        print(a_count.most_common()[0][1])
    elif a_count.most_common()[0][1]==n//2 and b_count.most_common()[0][1]!=n//2:
        print(b_count.most_common()[1][1])
    elif a_count.most_common()[0][1]!=n//2 and b_count.most_common()[0][1]==n//2:
        print(a_count.most_common()[1][1])
    else:
        print(min(a_count.most_common()[0][1]-a_count.most_common()[1][1],b_count.most_common()[0][1]-b_count.most_common()[1][1]))
else:
    ans=n-a_count.most_common()[0][1]-b_count.most_common()[0][1]
    print(ans)