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()))
s=[]
t=[]
for i in range(0,len(v)):
    if i%2==0:
        s.append(v[i])
    else:
        t.append(v[i])
p=collections.Counter(s)
q=collections.Counter(t)
a=p.most_common()[0][0]
a1=p.most_common()[0][1]
b=q.most_common()[0][0]
b1=q.most_common()[0][1]
if a==b:
    if a==len(v)/2:
        print(len(v))
    else:
        if len(set(s))!=1:
            c=p.most_common()[1][1]
        else:
            c=0
        if len(set(s))!=1:
            d=p.most_common()[1][1]
        else:
            d=0
        print(min(len(v)-c-b1,len(v)-d-a1))
else:
    print(len(v)-a1-b1)

Submission status: Wrong Answer

Solution code:
import collections

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

odd = []
even = []

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

counter_even = collections.Counter(even)
counter_odd = collections.Counter(odd)

change_even = len(even) - counter_even.most_common()[0][1]
change_odd = len(odd) - counter_odd.most_common()[0][1]
if len(counter_even.most_common()) == 1 and len(counter_odd.most_common()) == 1 and counter_even.most_common()[0][0] == counter_odd.most_common()[0][0]:
	print(n//2)
elif counter_even.most_common()[0][0] != counter_odd.most_common()[0][0]:
	print(change_odd + change_even)
else:
	if change_even < change_odd:
		change_odd_2 = len(odd) - counter_odd.most_common()[1][1]
		print(change_odd_2 + change_even)
	elif change_even > change_odd:
		change_even_2 = len(even) - counter_even.most_common()[1][1]
		print(change_even_2 + change_odd)
	else:
		change_even_2 = len(even) - counter_even.most_common()[1][1]
		change_odd_2 = len(odd) - counter_odd.most_common()[1][1]
		if change_even_2 < change_odd_2:
			print(change_odd_2 + change_even)
		else:
			print(change_even_2 + change_odd)

Submission status: Wrong Answer

Solution code:
n = int(raw_input())
v = raw_input().split()
vl = list(v)
sl = set(v)
c = 0
for i in xrange(0, n-2):
    if vl[i] != vl[i+2]:
        c+=1
if c < 1 and len(sl) < 2:
    c = len(vl)/2
print(c)

Submission status: Wrong Answer

Solution code:
import collections

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

odd = []
even = []

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

counter_even = collections.Counter(even)
counter_odd = collections.Counter(odd)

change_even = len(even) - counter_even.most_common()[0][1]
change_odd = len(odd) - counter_odd.most_common()[0][1]
if len(counter_even.most_common()) == 1 and len(counter_odd.most_common()) == 1 and counter_even.most_common()[0][0] == counter_odd.most_common()[0][0]:
	print(n//2)
elif counter_even.most_common()[0][0] != counter_odd.most_common()[0][0]:
	print(change_odd + change_even)
else:
	if change_even < change_odd:
		change_odd_2 = len(odd) - counter_odd.most_common()[1][1]
		print(change_odd_2 + change_even)
	else:
		change_even_2 = len(even) - counter_even.most_common()[1][1]
		print(change_even_2 + change_odd)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

# 最終的な2値をx, yとしたとき書き換える要素が最小の場合は、
# xは、書き換えが最も少ない数。つまり、もともと最も多い数
# yも同様。
# ただ、xとyがかぶる場合があるので、それに対処。
if len(Counter(v)) > 1:
    v1 = v[0:n+1:2]
    # print(v)
    # print(v1)
    v2 = v[1:n+2:2]
    # print(v2)
    v1_count = Counter(v1)
    v2_count = Counter(v2)

    v1_1st_common = v1_count.most_common(1)
    v2_1st_common = v2_count.most_common(1)
    sols = []
    # print(v1_1st_common[0][1], v2_1st_common[0][1])
    # v1を基準として多い方を考える場合。
    n1 = v1_1st_common[0][1]
    # v1の1位とv2の1位がかぶる場合
    if v1_1st_common[0][0] == v2_1st_common[0][0]:
        if len(v2_count) >= 2:
            v2_2nd_common = v2_count.most_common(2)
            n2 = v2_2nd_common[0][1]
        else:
            print(n//2)
    else:
        n2 = v2_1st_common[0][1]
    sols.append(n-n1-n2)

    # v2を基準として多い方を考える場合。
    n2 = v2_1st_common[0][1]
    # v1の1位とv2の1位がかぶる場合
    if v1_1st_common[0][0] == v2_1st_common[0][0]:
         if len(v1_count) >= 2:
            v1_2nd_common = v1_count.most_common(2)
            n1 = v1_2nd_common[0][1]
         else:
            print(n//2)
    else:
        n1 = v1_1st_common[0][1]
    sols.append(n-n1-n2)
    print(min(sols))
else:
    print(n//2)

Submission status: Wrong Answer

Solution code:
n = int(raw_input())
v = raw_input().split()
vl = list(v)
sl = set(v)
c = 0
for i in xrange(0, n-2):
    if vl[i] != vl[i+2]:
        c+=1
if c == 0 and len(sl) == 1:
    c = 2
print(c)

Submission status: Wrong Answer

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

cnt = 1
for i in v:
	if cnt % 2 != 0:
		odd.append(i)
	else:
		even.append(i)
	cnt += 1

oc = len(set(odd)) - 1
ec = len(set(even)) - 1

print(oc+ec)

Submission status: Wrong Answer

Solution code:
import collections

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

list_e = [list[i] for i in range(0,n-1,2)]
list_o = [list[i] for i in range(1,n,2)]
e = collections.Counter(list_e)
o = collections.Counter(list_o)
mode_e=e.most_common(2)
mode_o=o.most_common(2)
mode_e.append((-1,0))
mode_o.append((-1,0))
if mode_e[0][0]==mode_o[0][0]:
    if mode_e[0][1]>mode_o[0][1]:
        mode_e_value=mode_e[0][1]
        mode_o_value=mode_o[1][1]
    else:
        mode_e_value=mode_e[1][1]
        mode_o_value=mode_o[0][1]
else:
    mode_e_value = mode_e[0][1]
    mode_o_value = mode_o[0][1]
print(n-mode_e_value-mode_o_value)

Submission status: Wrong Answer

Solution code:
from collections import Counter
a,b,n = 0,0,int(input())
n1 = n//2 + n%2
n2 = n//2
z = list(map(int,input().split()))
a,b = Counter(z[0::2]).most_common(2),Counter(z[1::2]).most_common(2)

if a[0] == b[0]:
	print(n-a[0][1]-b[0][1])
elif len(a) == 1 and len(b) == 1:
    print(int(n/2))
else:
	print(n-a[0][1]-b[0][1])

Submission status: Wrong Answer

Solution code:
from collections import Counter
a,b,n = 0,0,int(input())
n1 = n//2 + n%2
n2 = n//2
z = list(map(int,input().split()))
a,b = Counter(z[0::2]).most_common(2),Counter(z[1::2]).most_common(2)

if a[0] == b[0]:
	print(n2)
elif len(a) == 1 and len(b) == 1:
    print(int(n/2))
else:
	print(n1 - a[0][1]+n2 - b[0][1])

Submission status: Wrong Answer

Solution code:
from collections import Counter
a,b,n = 0,0,int(input())
n1 = n//2 + n%2
n2 = n//2
z = list(map(int,input().split()))
a,b = Counter(z[0::2]).most_common(2),Counter(z[1::2]).most_common(2)

if a[0] == b[0]:
	print(n2)
else:
	print(n1 - a[0][1]+n2 - b[0][1])

Submission status: Wrong Answer

Solution code:
def maxElem( lis ):
	L = lis[:]#copy
	S = set(lis)
	S = list(S)
	MaxCount=0
	ret='nothing...'

	for elem in S:
		c=0
		while elem in L:
			ind = L.index(elem)
			foo = L.pop(ind)
			c+=1
		if c>MaxCount:
			MaxCount=c
			ret = elem
	return ret,MaxCount

n = int(input())
n1 = n//2 + n%2
n2 = n//2
z = list(map(int,input().split()))

s1,m1 = maxElem(z[0::2])
s2,m2 = maxElem(z[1::2])

count = 0
print(n1-m1+n2-m2)

Submission status: Wrong Answer

Solution code:
def maxElem( lis ):
	L = lis[:]#copy
	S = set(lis)
	S = list(S)
	MaxCount=0
	old_MaxCount=[0,0]
	ret='nothing...'

	for elem in S:
		c=0
		while elem in L:
			ind = L.index(elem)
			foo = L.pop(ind)
			c+=1
		old_MaxCount.append(c)
		if c>MaxCount:
			MaxCount=c
			ret = elem
	old_MaxCount.sort(reverse=True)
	return ret,old_MaxCount[0]

n = int(input())
n = n//2 + n%2
z = list(map(int,input().split()))

s1,m1 = maxElem(z[0::2])
s2,m2 = maxElem(z[1::2])

count = 0
print(n-m1+n-m2)

Submission status: Wrong Answer

Solution code:

def maxElem( lis ):
	L = lis[:]#copy
	S = set(lis)
	S = list(S)
	MaxCount=0
	old_MaxCount=[0,0]
	ret='nothing...'

	for elem in S:
		c=0
		while elem in L:
			ind = L.index(elem)
			foo = L.pop(ind)
			c+=1
		old_MaxCount.append(c)
		if c>MaxCount:
			MaxCount=c
			ret = elem
	old_MaxCount.sort(reverse=True)
	return ret,old_MaxCount[1],old_MaxCount[0]

n = int(input())
z = list(map(int,input().split()))
s,m1,m2 = maxElem(z)
n1,n2 = n//2,n//2+1

count = 0
while n2 != m2:
	if m2 > n2:
		m2 -= 1
		m1 += 1
		count +=1
	elif m2 < n2:
		m2 += 1
		m1 -= 1
		count +=1
print(count)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!

import collections

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

if len(set(v_l)) == 1:
    print(n // 2)
    exit()

v_l_odd = []
v_l_even = []

for i in range(n):
    if i % 2 == 0:
        v_l_odd.append(v_l[i])
    else:
        v_l_even.append(v_l[i])

max_odd = collections.Counter(v_l_odd)
mon = max_odd.most_common(1)[0][0]
max_even = collections.Counter(v_l_even)
men = max_even.most_common(1)[0][0]

if mon == men:
    if max(max_odd.most_common(2)[1][1], max_even.most_common(2)[1][1]) == max_odd.most_common(2)[1][1]:
        mon = max_odd.most_common(2)[1][1]
    else:
        men = max_even.most_common(2)[1][1]

v_l_odd_l = []
v_l_even_l = []

for i in range(n):
    if i % 2 == 0:
        if v_l[i] != mon:
            v_l_odd_l.append(v_l[i])
    else:
        if v_l[i] != men:
            v_l_even_l.append(v_l[i])

print(len(v_l_odd_l) + len(v_l_even_l))

Submission status: Wrong Answer

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

if len(set(v)) == 1:
	print(n // 2)
else:
	d = [{},{}]
	maxes = [0,0]
	for i in range(n):
		try:
			d[i&1][v[i]] += 1
		except:
			d[i&1][v[i]] = 1
		if d[i&1][v[i]] > maxes[i&1]:
			maxes[i&1] = d[i&1][v[i]]
	print(n // 2 - maxes[1] + n // 2 - maxes[0])

Submission status: Wrong Answer

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

if set(v) == 1:
	print(n // 2)
else:
	d = [{},{}]
	maxes = [0,0]
	for i in range(n):
		try:
			d[i&1][v[i]] += 1
		except:
			d[i&1][v[i]] = 1
		if d[i&1][v[i]] > maxes[i&1]:
			maxes[i&1] = d[i&1][v[i]]
	print(n // 2 - maxes[1] + (n - (n // 2)) - maxes[0])

Submission status: Wrong Answer

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

x = []
y = []

for i in range(N):
  if(i % 2 == 0):
    x.append(a[i])
  else:
    y.append(a[i])

def addition(l):
  s = set(l)
  li = list(s)
  if (len(li) == 1):
    return 0
  ans_l = []
  for i in range(len(li)):
    ans_l.append(l.count(li[i]))
  return min(ans_l)

ans = addition(x) + addition(y)


if (x == y):
  print(len(x))
else:
  print(addition(x))

Submission status: Wrong Answer

Solution code:
n = int(input().rstrip())
v_list = input().rstrip().split(' ')

result = 0
finish_num = n // 2
skip_flag = False

top_num = v_list[0]
count_top = v_list.count(top_num)
if count_top == len(v_list):
  print(finish_num)
  skip_flag = True

if not skip_flag:
  for i in range(finish_num):
    if v_list[i] != v_list[i+2]:
      result += 1
  print(result)

Submission status: Wrong Answer

Solution code:
n = int(input().rstrip())
v_list = input().rstrip().split(' ')

result = 0
finish_num = n // 2

for i in range(finish_num):
  if v_list[i] != v_list[i+2]:
    result += 1

print(result)

Submission status: Wrong Answer

Solution code:
n=int(input())
v=list(map(int,input().split()))
max1=1
max2=1
for i in range(1,int(n/2)):
    cnt1=1
    cnt2=1
    for j in range(0,i):
        if v[2*i]==v[j*2]:
            cnt1=cnt1+1
        if v[2*i+1]==v[2*j+1]:
            cnt2=cnt2+1
    if max1<cnt1:
        max1=cnt1
    if max2<cnt2:
        max2=cnt2
print(n-max1-max2)

Submission status: Wrong Answer

Solution code:
N = int(input())
V = list(map(int, input().split()))
first = V[::2]
latter = V[1::2]

cnt = 0
for f, l in zip(first, latter):
    if abs(f-l) >= 2:
        continue
    else:
        cnt += 1

print(cnt)

Submission status: Wrong Answer

Solution code:
n = int(input())

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


evens = [ v for index, v in enumerate(vs) if index%2 == 0 ]
odds  = [ v for index, v in enumerate(vs) if index%2 == 1 ]

#print(evens)
#print(odds)

from collections import Counter
even_most_freq = sorted( dict(Counter(evens)).items(), key=lambda x:x[1] )[-1][0]
odd_most_freq  = sorted( dict(Counter(odds)).items(), key=lambda x:x[1] )[-1][0]

#print(even_most_freq, odd_most_freq)
if even_most_freq != odd_most_freq:
    count_evens = sum( [1 for x in evens if x != even_most_freq] )
    count_odds = sum( [1 for x in odds if x != odd_most_freq] )
    print( count_evens + count_odds)
else:
    maxed = min( [len(evens), len(odds)] ) 
    count_evens = sum( [1 for x in evens if x != even_most_freq] )
    count_odds = sum( [1 for x in odds if x != odd_most_freq] )
    print( count_evens + count_odds + maxed)

Submission status: Wrong Answer

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

count = 0
for i in range(N-2):
  if v[i+2] != v[i]:
    v[i+2] = v[i]
    count += 1
  if v[i+1] == v[i]:
    v[i+1] += 1
    count += 1
print(count)

Submission status: Wrong Answer

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

count = 0
for i in range(N-2):
  if v[i+2] != v[i]:
    v[i+2] = v[i]
    count += 1
  elif v[i+1] == v[i]:
    v[i+1] += 1
    count += 1
print(count)

Submission status: Wrong Answer

Solution code:
import sys
import math
import collections
import itertools
import array
import inspect

# Set max recursion limit
sys.setrecursionlimit(1000000)


# Debug output
def chkprint(*args):
    names = {
        id(v): k
        for k, v in inspect.currentframe().f_back.f_locals.items()
    }
    print(', '.join(
        names.get(id(arg), '???') + ' = ' + repr(arg) for arg in args))


# Binary converter
def to_bin(x):
    return bin(x)[2:]


def li_input():
    return [int(_) for _ in input().split()]


def gcd(n, m):
    if n % m == 0:
        return m
    else:
        return gcd(m, n % m)


def gcd_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = gcd(v, L[i])

    return v


def lcm(n, m):
    return (n * m) // gcd(n, m)


def lcm_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = lcm(v, L[i])

    return v


# Width First Search (+ Distance)
def wfs_d(D, N, K):
    """
    D: 隣接行列(距離付き)
    N: ノード数
    K: 始点ノード
    """

    dfk = [-1] * (N + 1)
    dfk[K] = 0

    cps = [(K, 0)]
    r = [False] * (N + 1)
    r[K] = True
    while len(cps) != 0:
        n_cps = []
        for cp, cd in cps:
            for i, dfcp in enumerate(D[cp]):
                if dfcp != -1 and not r[i]:
                    dfk[i] = cd + dfcp
                    n_cps.append((i, cd + dfcp))
                    r[i] = True

        cps = n_cps[:]

    return dfk


# Depth First Search (+Distance)
def dfs_d(v, pre, dist):
    """
    v:  現在のノード
    pre: １つ前のノード
    dist: 現在の距離

    以下は別途用意する
    D: 隣接リスト(行列ではない)
    D_dfs_d: dfs_d関数で用いる，始点ノードから見た距離リスト
    """

    global D
    global D_dfs_d

    D_dfs_d[v] = dist

    for next_v, d in D[v]:
        if next_v != pre:
            dfs_d(next_v, v, dist + d)

    return


def sigma(N):
    ans = 0
    for i in range(1, N + 1):
        ans += i
    return ans


def comb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2, r + 1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p - 1, r, p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

def bisearch(L, target):
    low = 0
    high = len(L) - 1
    
    while low <= high:
        mid = (low + high) // 2
        guess = L[mid]
        if guess == target:
            return True
        elif guess < target:
            low = mid + 1
        elif guess > target:
            high = mid - 1
    if guess != target:
        return False

# --------------------------------------------

dp = None


def main():
    N = int(input())
    V = li_input()

    VE = V[::2]
    VO = V[1::2]

    DE = collections.defaultdict(lambda: 0)
    DO = collections.defaultdict(lambda: 0)

    for ve in VE:
        DE[ve] += 1

    for vo in VO:
        DO[vo] += 1

    E1_k, E1_v = max(DE), DE[max(DE)]
    O1_k, O1_v = max(DO), DO[max(DO)]

    DE[max(DE)] = 0
    DO[max(DO)] = 0

    E2_k, E2_v = max(DE), DE[max(DE)]
    O2_k, O2_v = max(DO), DO[max(DO)]

    if E1_k != O1_k:
        ans = 0
        ans += len(VE) - E1_v
        ans += len(VO) - O1_v

    else:
        if E1_k == E2_k and O1_k == O2_k:
            ans = len(VO)
        else:
            ans_prio_E = 0
            ans_prio_E += len(VE) - E1_v
            ans_prio_E += len(VO) - O2_v

            ans_prio_O = 0
            ans_prio_O += len(VE) - E2_v
            ans_prio_O += len(VO) - O1_v

            ans = min(ans_prio_E, ans_prio_O)
    
    print(ans)

main()

Submission status: Wrong Answer

Solution code:

def answer(in0, in1):
    even = {}
    odd = {}

    list = in1.split(" ")

    for i in range(len(list)):
        n = list[i]
        if i % 2 == 0:
            odd[n] = odd.get(n, 0) + 1
        else:
            even[n] = even.get(n, 0) + 1

    odd = sorted(
        [{'key': k, 'value': odd[k]} for k in odd],
        key=lambda x: (-x['value'], int(x['key'])))

    even = sorted(
        [{'key': k, 'value': even[k]} for k in even],
        key=lambda x: (-x['value'], int(x['key'])))

    oddMax = odd[0]
    evenMax = even[0]

    # 奇数偶数ともにトップのキーが一緒
    if oddMax['key'] == evenMax['key']:
        # 文字列が全部同じだからどっちかを書き換えればOK
        if len(even) == 1 and len(odd) == 1:
            return int(int(in0) / 2)

        if oddMax['value'] > evenMax['value']:
            evenMax = even[1]
        else:
            oddMax = odd[1]

    oddCount = 0
    evenCount = 0

    for v in odd:
        if v['key'] != oddMax['key']:
            oddCount += v['value']

    for v in even:
        if v['key'] != evenMax['key']:
            evenCount += v['value']

    return oddCount + evenCount

print(answer(input(), input()))

Submission status: Wrong Answer

Solution code:

def answer(in0, in1):
    even = {}
    odd = {}

    list = in1.split(" ")

    for i in range(len(list)):
        n = list[i]
        if i % 2 == 0:
            odd[n] = odd.get(n, 0) + 1
        else:
            even[n] = even.get(n, 0) + 1

    odd = sorted([{'key': k, 'value': odd[k]}for k in odd], key=lambda x: -x['value'])

    even = sorted([{'key': k, 'value': even[k]}for k in even], key=lambda x: -x['value'])

    oddMax = odd[0]
    evenMax = even[0]

    # 書き換え後が同数になる
    if oddMax['key'] == evenMax['key']:
        # 文字列が全部同じだからどっちかを書き換えればOK
        if len(even) == 1 and len(odd) == 1 and oddMax['key'] == evenMax['key']:
            return int(int(in0) / 2)
        if oddMax['value'] > evenMax['value']:
            evenMax = even[1]
        else:
            oddMax = odd[1]

    oddCount = 0
    evenCount = 0

    for v in odd:
        if v['key'] != oddMax['key']:
            oddCount += v['value']

    for v in even:
        if v['key'] != evenMax['key']:
            evenCount += v['value']

    return oddCount + evenCount

print(answer(input(), input()))

Submission status: Wrong Answer

Solution code:

def answer(in0, in1):
    even = {}
    odd = {}

    list = in1.split(" ")

    for i in range(len(list)):
        n = list[i]
        if i % 2 == 0:
            odd[n] = odd.get(n, 0) + 1
        else:
            even[n] = even.get(n, 0) + 1

    oddMaxKey = getMaxKey(odd)
    evenMaxKey = getMaxKey(even)

    if len(even) == 1 and len(odd) == 1 and oddMaxKey == evenMaxKey:
        return int(int(in0) / 2)
    else:
        oddCount = 0
        evenCount = 0

        for k1 in odd:
            if k1 != oddMaxKey:
                oddCount += odd[k1]

        for k2 in even:
            if k2 != evenMaxKey:
                evenCount += even[k2]

        return oddCount + evenCount

def getMaxKey(dicts):
    maxValue= 0
    maxKey = ''

    for k in dicts:
        if maxValue < dicts[k]:
            maxValue = dicts[k]
            maxKey = k

    return maxKey

print(answer(input(), input()))

Submission status: Wrong Answer

Solution code:
#encoding utf-8
def main(n,v):
    # n = int(input())
    # v = list(int(i) for i in input().split())
    even_v = []
    odd_v = []

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

    odd_dic = {}
    even_dic = {}
    for i in range(len(odd_v)):
        if odd_v[i] in odd_dic.keys():
            odd_dic[odd_v[i]] += 1
        else:
            odd_dic[odd_v[i]] = 1

    for i in range(len(even_v)):
        if even_v[i] in even_dic.keys():
            even_dic[even_v[i]] += 1
        else:
            even_dic[even_v[i]] = 1

    tem_dic = {}
    for k, v in sorted(even_dic.items(), key=lambda x: -x[1]):
        tem_dic[k] = v
    even_dic = tem_dic
    tem_dic = {}
    for k, v in sorted(odd_dic.items(), key=lambda x: -x[1]):
        tem_dic[k] = v
    odd_dic = tem_dic

    # odd_dic = sorted(odd_dic.items(),key=lambda x:x[1])
    # even_dic = sorted(even_dic.items(),key=lambda x:x[1])

    odd_keys = list(odd_dic.keys())
    even_keys = list(even_dic.keys())

    for i in range(len(odd_keys)-1):
        if odd_dic[odd_keys[i]] == odd_dic[odd_keys[i+1]]:
            if odd_keys[i] > odd_keys[i+1]:
                tem = odd_keys[i]
                odd_keys[i] = odd_keys[i+1]
                odd_keys[i+1] = tem

    for i in range(len(even_keys)-1):
        if even_dic[even_keys[i]] == even_dic[even_keys[i+1]]:
            if even_keys[i] > even_keys[i+1]:
                tem = even_keys[i]
                even_keys[i] = even_keys[i+1]
                even_keys[i+1] = tem


    # print(even_dic,odd_dic)
    # print(even_keys,odd_keys)
    if (len(odd_keys) == 1 and len(even_keys) == 1) and odd_keys[0] == even_keys[0]:
        answer = n/2
    elif odd_keys[0] == even_keys[0]:
        if odd_dic[odd_keys[0]] == even_dic[even_keys[0]]:
            if len(odd_keys) == 1:
                answer = n-even_dic[even_keys[1]]
            elif len(even_keys) == 1:
                answer = n-odd_dic[odd_keys[1]]
            else:
                ans1 = n-int(odd_dic[odd_keys[0]])-int(even_dic[even_keys[1]])
                ans2 = n-int(odd_dic[odd_keys[1]])-int(even_dic[even_keys[0]])
                answer = min(ans1, ans2)
        elif len(odd_keys) == 1:
            answer = n-odd_dic[odd_keys[0]]-even_dic[even_keys[1]]
        elif len(even_keys) == 1:
            answer = n-odd_dic[odd_keys[1]]-even_dic[even_keys[0]]
        else:
            ans1 = n-int(odd_dic[odd_keys[0]])-int(even_dic[even_keys[1]])
            ans2 = n-int(odd_dic[odd_keys[1]])-int(even_dic[even_keys[0]])
            answer = min(ans1, ans2)
    else:
        answer = n-int(odd_dic[odd_keys[0]])-int(even_dic[even_keys[0]])

    print(int(answer))
    # return(int(answer))

if __name__ == "__main__":
    n = int(input())
    v = list(int(i) for i in input().split())
    main(n,v)

Submission status: Wrong Answer

Solution code:
#encoding utf-8
def main(n,v):
    # n = int(input())
    # v = list(int(i) for i in input().split())
    even_v = []
    odd_v = []

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

    odd_dic = {}
    even_dic = {}
    for i in range(len(odd_v)):
        if odd_v[i] in odd_dic.keys():
            odd_dic[odd_v[i]] += 1
        else:
            odd_dic[odd_v[i]] = 1

    for i in range(len(even_v)):
        if even_v[i] in even_dic.keys():
            even_dic[even_v[i]] += 1
        else:
            even_dic[even_v[i]] = 1

    tem_dic = {}
    for k, v in sorted(even_dic.items(), key=lambda x: -x[1]):
        tem_dic[k] = v
    even_dic = tem_dic
    tem_dic = {}
    for k, v in sorted(odd_dic.items(), key=lambda x: -x[1]):
        tem_dic[k] = v
    odd_dic = tem_dic

    # odd_dic = sorted(odd_dic.items(),key=lambda x:x[1])
    # even_dic = sorted(even_dic.items(),key=lambda x:x[1])

    odd_keys = list(odd_dic.keys())
    even_keys = list(even_dic.keys())

    for i in range(len(odd_keys)-1):
        if odd_dic[odd_keys[i]] == odd_dic[odd_keys[i+1]]:
            if odd_keys[i] > odd_keys[i+1]:
                tem = odd_keys[i]
                odd_keys[i] = odd_keys[i+1]
                odd_keys[i+1] = tem

    for i in range(len(even_keys)-1):
        if even_dic[even_keys[i]] == even_dic[even_keys[i+1]]:
            if even_keys[i] > even_keys[i+1]:
                tem = even_keys[i]
                even_keys[i] = even_keys[i+1]
                even_keys[i+1] = tem


    print(even_dic,odd_dic)
    print(even_keys,odd_keys)
    if (len(odd_keys) == 1 and len(even_keys) == 1) and odd_keys[0] == even_keys[0]:
        answer = n/2
    elif odd_keys[0] == even_keys[0]:
        if odd_dic[odd_keys[0]] == even_dic[even_keys[0]]:
            if len(odd_keys) == 1:
                answer = n-even_dic[even_keys[1]]
            elif len(even_keys) == 1:
                answer = n-odd_dic[odd_keys[1]]
            else:
                ans1 = n-int(odd_dic[odd_keys[0]])-int(even_dic[even_keys[1]])
                ans2 = n-int(odd_dic[odd_keys[1]])-int(even_dic[even_keys[0]])
                answer = min(ans1, ans2)
        elif len(odd_keys) == 1:
            answer = n-odd_dic[odd_keys[0]]-even_dic[even_keys[1]]
        elif len(even_keys) == 1:
            answer = n-odd_dic[odd_keys[1]]-even_dic[even_keys[0]]
        else:
            ans1 = n-int(odd_dic[odd_keys[0]])-int(even_dic[even_keys[1]])
            ans2 = n-int(odd_dic[odd_keys[1]])-int(even_dic[even_keys[0]])
            answer = min(ans1, ans2)
    else:
        answer = n-int(odd_dic[odd_keys[0]])-int(even_dic[even_keys[0]])

    print(int(answer))
    # return(int(answer))

if __name__ == "__main__":
    n = int(input())
    v = list(int(i) for i in input().split())
    main(n,v)

Submission status: Wrong Answer

Solution code:
#encoding utf-8
def main(n,v):
    # n = int(input())
    # v = list(int(i) for i in input().split())
    even_v = []
    odd_v = []

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

    odd_dic = {}
    even_dic = {}
    for i in range(len(odd_v)):
        if odd_v[i] in odd_dic.keys():
            odd_dic[odd_v[i]] += 1
        else:
            odd_dic[odd_v[i]] = 1

    for i in range(len(even_v)):
        if even_v[i] in even_dic.keys():
            even_dic[even_v[i]] += 1
        else:
            even_dic[even_v[i]] = 1

    tem_dic = {}
    for k, v in sorted(even_dic.items(), key=lambda x: -x[1]):
        tem_dic[k] = v
    even_dic = tem_dic
    tem_dic = {}
    for k, v in sorted(odd_dic.items(), key=lambda x: -x[1]):
        tem_dic[k] = v
    odd_dic = tem_dic

    # odd_dic = sorted(odd_dic.items(),key=lambda x:x[1])
    # even_dic = sorted(even_dic.items(),key=lambda x:x[1])

    odd_keys = list(odd_dic.keys())
    even_keys = list(even_dic.keys())

    for i in range(len(odd_keys)-1):
        if odd_dic[odd_keys[i]] == odd_dic[odd_keys[i+1]]:
            if odd_keys[i] > odd_keys[i+1]:
                tem = odd_keys[i]
                odd_keys[i] = odd_keys[i+1]
                odd_keys[i+1] = tem

    for i in range(len(even_keys)-1):
        if even_dic[even_keys[i]] == even_dic[even_keys[i+1]]:
            if even_keys[i] > even_keys[i+1]:
                tem = even_keys[i]
                even_keys[i] = even_keys[i+1]
                even_keys[i+1] = tem


    print(even_dic,odd_dic)
    print(even_keys,odd_keys)
    if (len(odd_keys) == 1 and len(even_keys) == 1) and odd_keys[0] == even_keys[0]:
        answer = n/2
    elif odd_keys[0] == even_keys[0]:
        if odd_dic[odd_keys[0]] == even_dic[even_keys[0]]:
            if len(odd_keys) == 1:
                answer = n-even_dic[even_keys[1]]
            elif len(even_keys) == 1:
                answer = n-odd_dic[odd_keys[1]]
            else:
                ans1 = n-int(odd_dic[odd_keys[0]])-int(even_dic[even_keys[1]])
                ans2 = n-int(odd_dic[odd_keys[1]])-int(even_dic[even_keys[0]])
                answer = min(ans1, ans2)
        elif len(odd_keys) == 1:
            print("a")
            answer = n-odd_dic[odd_keys[0]]-even_dic[even_keys[1]]
        elif len(even_keys) == 1:
            answer = n-odd_dic[odd_keys[1]]-even_dic[even_keys[0]]
        else:
            ans1 = n-int(odd_dic[odd_keys[0]])-int(even_dic[even_keys[1]])
            ans2 = n-int(odd_dic[odd_keys[1]])-int(even_dic[even_keys[0]])
            answer = min(ans1, ans2)
    else:
        answer = n-int(odd_dic[odd_keys[0]])-int(even_dic[even_keys[0]])

    print(int(answer))
    # return(int(answer))

if __name__ == "__main__":
    n = int(input())
    v = list(int(i) for i in input().split())
    main(n,v)