Problem:


Score : 300 points

Problem Statement

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

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

Exactly two different numbers appear in the sequence.

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

Constraints

2 \leq n \leq 10^5

n is even.

1 \leq v_i \leq 10^5

v_i is an integer.

Input

Input is given from Standard Input in the following format:

n
v_1 v_2 ... v_n

Output

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

Sample Input 1

4
3 1 3 2

Sample Output 1

1

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

Sample Input 2

6
105 119 105 119 105 119

Sample Output 2

0

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

Sample Input 3

4
1 1 1 1

Sample Output 3

2

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



Sample input:
4
3 1 3 2


Sample output:
1

Submission status: Wrong Answer

Solution code:
from collections import Counter
N = int(input())
n = N // 2

index = 0
g_inputs = []
k_inputs = []

for i in input().split():
    if index % 2 == 0:
        g_inputs.append(int(i))
        index += 1
    else:
        k_inputs.append(int(i))
        index += 1

g = Counter(g_inputs)
k = Counter(k_inputs)

g_max = max([(v,k) for k,v in g.items()])[1] 
k_max = max([(v,k) for k,v in k.items()])[1]

if g_max == k_max:
    if g[g_max] < k[k_max]:
        del g[g_max]
        g_max = max([(v,k) for k,v in g.items()])[1]
        print(N - g[g_max] - k[k_max])
    if g[g_max] > k[k_max]:
        del k[k_max]
        k_max = max([(v,k) for k,v in k.items()])[1]
        print(N - g[g_max] - k[k_max])
    else:
        del g[g_max]
        del k[k_max]
        if len(g) == 0 and len(k) == 0:
            print(n)
        if len(g) != 0 and len(k) == 0:
            print(n - g[max([(v,k) for k,v in g.items()])[1]])
        if len(g) == 0 and len(k) != 0:
            print(n - k[max([(v,k) for k,v in k.items()])[1]])
        if len(g) != 0 and len(k) != 0:
            g_temp = g_max
            k_temp = k_max
            g_max = max([(v,k) for k,v in g.items()])[1]
            k_max = max([(v,k) for k,v in k.items()])[1]
            if g[g_max] < k[k_max]:
                print(n - k[k_max])
            elif g[g_max] > k[k_max]:
                print(n - g[g_max])
            else:
                print(n - g[g_max])
else:
    print(N - g[g_max] - k[k_max])

Submission status: Wrong Answer

Solution code:
n=int(input())
v=[int(i) for i in input().split()]
a=[]
b=[]
for i in range(1,n,2):
    s=v[i]
    a.append(s)
for j in range(0,n-1,2):
    t=v[j]
    b.append(t)
if a==b:
    print(int(n/2))
else:    
    A=list(set(a))
    B=list(set(b))
    C=len(A)-1
    D=len(B)-1
    print(C+D)

Submission status: Wrong Answer

Solution code:
def exchange(v):
    cnt = 0
    pattern2 = 0
    for (i, num) in enumerate(v):
        if i == 0:
            pattern1 = num
        elif i % 2 == 0:
            if pattern1 != num:
                cnt += 1
        elif i % 2 == 1:
            if pattern2 == 0 and num != pattern1:
                pattern2 = num
                cnt += 1
            elif pattern2 != num:
                cnt += 1
    return cnt

        

if __name__ == "__main__":
    n = int(input())
    v = list(map(int,input().split()))
    print(exchange(v))

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [int(aa) for aa in input().split()]

def add_entry(hist, aa):
    if aa in hist:
        hist[aa] += 1
    else:
        hist[aa] = 1


def make_hist(a):
    even_hist = {}
    odd_hist = {}

    for i in range(len(a)//2):
        add_entry(even_hist, a[2*i])
        add_entry(odd_hist, a[2*i+1])

    return even_hist, odd_hist


def get_sorted_hist(hist):
    return sorted(hist.items(), key=lambda x: -x[0])


eh, oh = make_hist(a)
seh = get_sorted_hist(eh)
soh = get_sorted_hist(oh)



if seh[0][0] != soh[0][0]:
    print(len(a) - seh[0][1] - soh[0][1])
else:
    if len(seh) == 1 and len(soh) == 1:
        print(len(a)//2)
    elif len(seh) == 1:
        print(len(a) - seh[0][1] - soh[0][1])
    elif len(soh) == 1:
        print(len(a) - soh[0][1] - seh[0][1])
    else:
        print(min(len(a) - seh[0][1] - soh[0][1], len(a) - soh[0][1] - seh[0][1]))

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
v = [int(i) for i in input().split()]
e = []
o = []
for i, a in enumerate(v):
    if i % 2:
        o.append(a)
    else:
        e.append(a)
oc = Counter(o)
ec = Counter(e)
h = n//2
ans = h
for k, v in oc.most_common():
    for k2, v2 in ec.most_common():
        if k == k2:
            continue
        ans = min(ans, h - v + h - v2)
print(ans)

Submission status: Wrong Answer

Solution code:
import collections

n = int(input())

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

vo = []
ve = []

if v.count(v[0]) == n:
    print(n // 2)
    exit(0)
    

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

co = collections.Counter(vo)
ce = collections.Counter(ve)

if len(co) == len(ce):
    print("0")
    exit(0)

ovalues, ocounts = zip(*co.most_common())
evalues, ecounts = zip(*ce.most_common())


if ovalues[0] != evalues[0]:
    print(abs(len(co) - len(ce)))

else:
    if ocounts <= ecounts:
        a = evalues.count(evalues[0])
        print(max((n //2 - a), a))

    else:
        a = ovalues.count(ovalues[0])
        print(max((n // 2 - a), a))

Submission status: Wrong Answer

Solution code:
n = int(input())

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

v1 = {}

v2 = {}

for i in range(n//2):
    if  v[2 *i +1] in v1.keys():
        v1[v[2 * i +1]] += 1
    else:
        v1[v[2 * i + 1]] = 1

    if v[2 * i] in v2.keys():
        v2[v[2 * i]] += 1
    else:
        v2[v[2 * i]] = 1


v1 = sorted(v1.items(),key=lambda x: - x[0])
v2 = sorted(v2.items(),key=lambda x: - x[0])
v1.reverse()
v2.reverse()
v1.append((None,0))
v2.append((None,0))
print(v1)
if v1[0][0] == v2[0][0]:
    ans = max(v1[0][1]+v2[1][1] , v1[1][1] + v2[0][1])
else:
    ans = v1[0][1] + v2[0][1]

print(n - ans)

Submission status: Wrong Answer

Solution code:
import numpy as np

n = int(input())
v_ = map(int, input().split())
v = []
for val in v_:
	v.append(val)
v = np.array(v)
v_c = []

for a in range(0, 11, 1):
	if sum(v==a) != 0:
		v_c.append(sum(v==a))
if len(v_c) < 2:
	print(2)
elif len(v_c) == 2:
	print(0)
else:
	print(sum(sorted(v_c, reverse=True)[2:]))

Submission status: Wrong Answer

Solution code:
n = int(input())
array = [int(x) for x in input().split()]
tmp_dict = {}
tmp_dict2 = {}
tmp_array = array[::2]
tmp_array2 = array[1::2]
for i in tmp_array:
    if i in tmp_dict.keys():
        tmp_dict[i] += 1
    else:
        tmp_dict[i] = 1
for i in tmp_array2:
    if i in tmp_dict2.keys():
        tmp_dict2[i] += 1
    else:
        tmp_dict2[i] = 1

sorted_dict = sorted(tmp_dict.items(), key=lambda x: x[1], reverse=True)
sorted_dict2 = sorted(tmp_dict2.items(), key=lambda x: x[1], reverse=True)
tmp = sorted_dict[0][0]
tmp2 = sorted_dict2[0][0]

if sorted_dict == sorted_dict2:
    print(len(array)//2)
    exit()

if tmp == tmp2:
    if len(sorted_dict) == 1:
        tmp2 = sorted_dict2[1][0]
    elif len(sorted_dict2) == 1:
        tmp = sorted_dict[1][0]
    else:
        if sorted_dict2[1][1] > sorted_dict[1][1]:
            tmp2 = sorted_dict2[1][0]
        else:
            tmp = sorted_dict[1][0]
res = 0
for i in tmp_array:
    if i != tmp:
       res += 1
for i in tmp_array2:
    if i != tmp2:
       res += 1
print(res)

Submission status: Wrong Answer

Solution code:
n = int(input())
v = [int(i) for i in input().split()]
v1 = v[::2]
v2 = v[1::2]
v1_a = list(set(v1))
v2_a = list(set(v2))
v_a = list(set(v))

v1_1st = 0
v2_1st = 0

for i in range(len(v1_a)):
    if i == 0:
        v1_1st = v1_a[i]
        continue
    if v1.count(v1_1st) < v1.count(v1_a[i]):
        v1_1st = v1_a[i]

for i in range(len(v2_a)):
    if i == 0:
        v2_1st = v2_a[i]
        continue
    if v2.count(v2_1st) < v2.count(v2_a[i]):
        v2_1st = v2_a[i]

if v1_1st == v2_1st:
    print(min(len(v1) + len(v2) - v2.count(v2_1st) ,len(v2) + len(v1) - v1.count(v1_1st)))

else:
    print(len(v1)- v1.count(v1_1st)+ len(v2)- v2.count(v2_1st))

Submission status: Wrong Answer

Solution code:
from collections import Counter


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

A = v[0::2]
c = Counter(A)
a = c.most_common()[0][1]

B = v[1::2]
d = Counter(B)
b = d.most_common()[0][1]

X = (n / 2) - a
Y = (n / 2) - b

Z = X + Y
print(int(Z))

Submission status: Wrong Answer

Solution code:
n=int(input())

l=list(map(int,input().split()))
l1=[]
l2=[]

for i in range(n):
	if i%2==0:
		l1.append(l[i])
	else:
		l2.append(l[i])

count1=[]
count2=[]

for i in range(100000):
	count1.append(0)
	count2.append(0)

for i in range(n//2):
	count1[l1[i]-1]+=1
	count2[l2[i]-1]+=1

max1=0
max2=0

maxc1=[]
maxc2=[]

for i in range(100000):
	if count1[i]>=max1:
		max1=count1[i]
		maxc1.append(i)

	if count2[i]>=max2:
		max2=count2[i]
		maxc2.append(i)

# print('maxc1',maxc1)
# print('maxc2',maxc2)
# print('max1',max1)
# print('max2',max2)

if len(maxc2)+len(maxc1)>2 or (len(maxc2)+len(maxc1)==2 and maxc1[0]!=maxc2[0]):
	final=max1+max2

else :
	max3=0
	max4=0
	for i in range(100000):
		if i!=maxc1[0]:
			if count1[i]>=max3:
				max3=count1[i]
				maxc1.append(i)

		if i!=maxc2[0]:
			if count2[i]>=max4:
				max4=count2[i]
				maxc2.append(i)

	final=max(max1+max4,max2+max3)

print(n-final)

Submission status: Wrong Answer

Solution code:
def exchange(v):
    cnt = 0
    pattern2 = 0
    for (i, num) in enumerate(v):
        if i == 0:
            pattern1 = num
        elif i % 2 == 0:
            if pattern1 != num:
                cnt += 1
        elif i % 2 == 1:
            if pattern2 == 0 and num != pattern1:
                pattern2 = num  
            elif pattern2 != num:
                cnt += 1
    return cnt

        

if __name__ == "__main__":
    n = int(input())
    v = list(map(int,input().split()))
    print(exchange(v))

Submission status: Wrong Answer

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


def main():
    from collections import Counter

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

    if len(set(v)) == 1:
        print(half)
        exit()
    else:
        even = Counter(v[::2]).most_common(1)[0][0]
        odd = Counter(v[1::2]).most_common(1)[0][0]
        ans1 = 0

        c1 = Counter(v[::2]).most_common(1)[0][1]
        c2 = Counter(v[1::2]).most_common(1)[0][1]

        if even == odd:
            print(min(n - c1, n - c2))
            exit()

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

        print(ans1)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

N = int(input())
A = list(map(int, input().split(' ')))

up = A[0::2]
down = A[1::2]
upc = collections.Counter(up)
doc = collections.Counter(down)

umc = upc.most_common(2)
dmc = doc.most_common(2)

if len(umc) == len(dmc) and len(umc) == 0:
	if umc[0][0] == dmc[0][0]:
		if umc[0][1] > dmc[0][1]:
			dmc[0] = dmc[1]
		else:
			umc[0] = umc[1]


u = len(A)/2 - umc[0][1]
d = len(A)/2 - dmc[0][1]

if (u == 0 and d == 0) and umc[0][0] == dmc[0][0]:
	print(int(len(A)/2))
	exit()

print(int(u+d))

Submission status: Wrong Answer

Solution code:
#-*-coding:utf-8-*-
from collections import Counter

def main():
    n = int(input())
    v_list = list(map(int, input().split()))
    v_list_even = v_list[::2]
    v_list_odd = v_list[1::2]
    counter_even = Counter(v_list_even)
    counter_odd = Counter(v_list_odd)

    if counter_even.most_common()[0][0] == counter_odd.most_common()[0][0]:
        if len(counter_even.most_common()) == 1:
            if len(counter_odd.most_common()) == 1:
                ans = len(v_list_odd)
            else:
                ans = len(v_list_odd) - counter_odd.most_common()[1][1]
        else:
            if len(counter_odd.most_common()) == 1:
                ans = len(v_list_even) - counter_even.most_common()[1][1]
            else:
                if counter_even.most_common()[0][1] > counter_odd.most_common()[0][1]:
                    ans = len(v_list_even) - counter_even.most_common()[0][1] + len(v_list_odd) - counter_odd.most_common()[1][1]
                else:
                    ans = len(v_list_even) - counter_even.most_common()[1][1] + len(v_list_odd) - counter_odd.most_common()[0][1]
    else:
        ans = len(v_list_even) - counter_even.most_common()[0][1] + len(v_list_odd) - counter_odd.most_common()[0][1]
    print(ans)
    
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import collections
import statistics

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

#要素番号の奇偶で仕分け
odd = []
even = []
for i in range(n):
    if i % 2 == 0:
        even.append(v[i])
    else:
        odd.append(v[i])

#最頻値を取得。最頻値がなかったら(全部同じ回数)先頭の要素
evensame = False
try:
    evenmode = statistics.mode(even)
    evenchange = -1
except:
    evenmode = v[0]
    evenchange = int(n/2) 
    evensame = True

oddsame = False
try:
    oddmode = statistics.mode(odd)
    oddchange = -1
except:
    oddmode = v[1]
    oddchange = int(n/2)
    oddsame = True

#奇偶のグループのそれぞれで変える必要のある要素を数える
if evenchange < 0:
    evenchange = int(n/2) - even.count(evenmode)
if oddchange < 0:
    oddchange = int(n/2) - odd.count(oddmode)
answer = evenchange + oddchange

#もし奇偶の最頻値が同じ値だったら、
#次に最頻な値を最頻値としてもう一回考える
#最頻がなかったらまあ全部だよね。あ！－１かも。
if oddmode == evenmode and (oddsame or evensame):
    try:
        even2ndmode = even.most_common()[1][0]
        change2 = oddchange + int(n/2) - even.count(even2ndmode)
    except:
        change2 = oddchange + int(n/2)
    if even.count(oddmode) != int(n/2):
            change2 -= 1
               
    try:
        odd2ndmode = odd.most_common()[1][0]
        change1 = evenchange + int(n/2) - odd.count(odd2ndmode)
    except:
        change1 = evenchange + int(n/2)
    if odd.count(evenmode) != int(n/2):
            change1 -= 1
     
    answer = min(change1,change2)

print(answer)

Submission status: Wrong Answer

Solution code:
from collections import Counter
N = int(input())
n = N // 2

index = 0
g_inputs = []
k_inputs = []

for i in input().split():
    if index % 2 == 0:
        g_inputs.append(int(i))
        index += 1
    else:
        k_inputs.append(int(i))
        index += 1

g = Counter(g_inputs)
k = Counter(k_inputs)

g_max = max([(v,k) for k,v in g.items()])[1] 
k_max = max([(v,k) for k,v in k.items()])[1]

if g_max == k_max:
    if g[g_max] < k[k_max]:
        del g[g_max]
        g_max = max([(v,k) for k,v in g.items()])[1]
        print(N - g[g_max] - k[k_max])
    if g[g_max] > k[k_max]:
        del k[k_max]
        k_max = max([(v,k) for k,v in k.items()])[1]
        print(N - g[g_max] - k[k_max])
    else:
        del g[g_max]
        del k[k_max]
        if len(g) == 0 and len(k) == 0:
            print(n)
        if len(g) != 0 and len(k) == 0:
            print(n - g[max([(v,k) for k,v in g.items()])[1]])
        if len(g) == 0 and len(k) != 0:
            print(n - k[max([(v,k) for k,v in k.items()])[1]])
        if len(g) != 0 and len(k) != 0:
            g_temp = g_max
            k_temp = k_max
            g_max = max([(v,k) for k,v in g.items()])[1]
            k_max = max([(v,k) for k,v in k.items()])[1]
            if g[g_max] < k[k_max]:
                print(n - k[k_max])
            elif g[g_max] > k[k_max]:
                print(n - g[g_max])
            else:
                print(N - g[g_max] - k[k_max])
else:
    print(N - g[g_max] - k[k_max])

Submission status: Wrong Answer

Solution code:
n = int(input())
L = list(map(int,input().split()))
A = []
B = []
Q = [0,0]
R = [0,0]
S = [0,0]
T = [0,0]
J = 1
K = 1
for i in range(n):
  if (i%2 == 0):
    A.append(L[i])
  else:
    B.append(L[i])
A.sort()
B.sort()
A.append(-1)
B.append(-1)
for j in range(1,len(A)):
  if (A[j-1] == A[j]):
    J += 1
  else:
    if (J > Q[0]):
      Q[1] = Q[0]
      del Q[0]
      Q.insert(0,J)
      R[1] = R[0]
      del R[0]
      R.insert(0,A[j-1])
      j += J
      J = 1
    elif (Q[0] >= J > Q[1]):
      del Q[1]
      Q.append(J)
      del R[1]
      R.append(A[j-1])
      j += J
      J = 1
    else:
      j += J
      J = 1
for k in range(1,len(B)):
  if (B[k-1] == B[k]):
    K += 1
  else:
    if (K > S[0]):
      S[1] = S[0]
      del S[0]
      S.insert(0,K)
      T[1] = T[0]
      del T[0]
      T.insert(0,B[k-1])
      k += K
      K = 1
    elif (S[0] >= J > S[1]):
      del S[1]
      S.append(K)
      del T[1]
      T.append(B[k-1])
      k += K
      K = 1
    else:
      k += K
      K = 1
if (R[0] != T[0]):
  print(n-Q[0]-S[0])
else:
  if (Q[0] > S[0]):
    print(n-Q[0]-S[1])
  else:
    print(n-S[0]-Q[1])

Submission status: Wrong Answer

Solution code:
def cal(n,v):
    k=n//2
    even=range(0,2*k,2)
    odd=range(1,2*k+1,2)

    el=[]
    for i in even:
        el.append(v[i])
    ol=[]
    for i in odd:
        ol.append(v[i])

    d={}
    for i in el:
        if((i in d) is False):
            d[i]=0
        else:
            d[i]+=1

    f={}
    for i in ol:
        if((i in f) is False):
            f[i]=0
        else:
            f[i]+=1

    while(True):
        if(len(d)==0 or len(f)==0):
            return print(k)
        e = max(d, key=d.get)
        o = max(f, key=f.get)
        if(e==o):
            if(d[e]>=f[e]):
                del f[e]
            elif(d[e]<f[e]):
                del d[e]
        else:
            break

    sum=0
    for i in el:
        if(i!=e):
            sum+=1
    for i in ol:
        if(i!=o):
            sum+=1
    return print(sum)

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

Submission status: Wrong Answer

Solution code:
import collections


n = int(input())
v = list(map(int, input().split()))
odd = []
even = []
for i in range(int(n/2)):
    even.append(v[2*i])
    odd.append(v[2*i + 1])
evencount = collections.Counter(even)
oddcount = collections.Counter(odd)


def hoge(i):
    global ans
    try:
        if evencount.most_common()[i][0] == oddcount.most_common()[i][0]:

            if evencount.most_common()[i][1] > oddcount.most_common()[i][1]:
                ans = n - evencount.most_common()[i][1] - oddcount.most_common()[i][1]
                print(ans)
            elif evencount.most_common()[i][1] < oddcount.most_common()[i][1]:
                ans = n - evencount.most_common()[i][1] - oddcount.most_common()[i][1]
                print(ans)
            else:
                if len(evencount) == 1:
                    ans = int(n/2)
                    print(ans)
                else:
                    hoge(i+1)

        else: 
            ans = n - evencount.most_common()[i][1] - oddcount.most_common()[i][1]
            print(ans)
    except IndexError:   
        ans = n - evencount.most_common()[0][1] - oddcount.most_common()[1][1]
        print(ans) 


hoge(0)

Submission status: Wrong Answer

Solution code:
n = int(input())
v = []
x = input().split()
for i in range(1,n):
  v.append(int(x[i]))
p = []
for j in range(0,len(v),2):
  p.append(v[j])
q = []
for k in range(1,len(v),2):
  q.append(v[k])
import collections
c1 = collections.Counter(p)
c2 = collections.Counter(q)
x = (c1.most_common()[0][1])
y = (c2.most_common()[0][1])
print(len(v)-x-y)

Submission status: Wrong Answer

Solution code:
import collections

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

if len(set(v_l)) == 1:
    print(n // 2)
    exit()
elif len(set(v_l)) == n // 2:
    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])
times = 0
count_odd = collections.Counter(v_l_odd)
count_even = collections.Counter(v_l_even)
while True:
    mon = count_odd.most_common()[times][0]
    men = count_even.most_common()[times][0]

    v_l_odd_diff = []
    v_l_even_diff = []

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

    if len(set(v_l)) != 1:
        print(len(v_l_odd_diff) + len(v_l_even_diff))
        exit()
    else:
        times = times + 1

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
v = list(input().split())
v_odd = []
v_even =[]
for i in range(n):
    if i%2==0:
        v_odd.append(v[i])
    else:
        v_even.append(v[i])

count_odd = collections.Counter(v_odd)
count_even = collections.Counter(v_even)
temp_odd = list(count_odd.values())
temp_even = list(count_even.values())
# print(temp_odd)
# print(temp_even)
if list(count_even.keys())[0] != list(count_odd.keys())[0]:
    odd_sum = sum(temp_odd)-temp_odd[0]
    even_sum = sum(temp_even)-temp_even[0]
    print(odd_sum+even_sum)
else:
    if temp_odd[0]>temp_even[0]:
        odd_sum = sum(temp_odd)-temp_odd[0]
        try:
            even_sum = sum(temp_even)-temp_even[1]
        except:
            even_sum = temp_even[0]
        print(odd_sum+even_sum)
    elif temp_odd[0]<temp_even[0]: 
        try:
            odd_sum = sum(temp_odd)-temp_odd[1]
        except:
            odd_sum = temp_odd[0]
        even_sum = sum(temp_even)-temp_even[0]
        print(odd_sum+even_sum)
    else:
        odd_sum1 = sum(temp_odd)-temp_odd[0]
        try:
            even_sum1 = sum(temp_even)-temp_even[1]
        except:
            even_sum1 = temp_even[0]
        temp_ans1 = odd_sum1+even_sum1
        try:
            odd_sum2 = sum(temp_odd)-temp_odd[1]
        except:
            odd_sum2 = temp_odd[0]
        even_sum2 = sum(temp_even)-temp_even[0]
        temp_ans2 = odd_sum2+even_sum2


        print(min(temp_ans1,temp_ans2))

Submission status: Wrong Answer

Solution code:
from collections import Counter
N = int(input())
n = N // 2

index = 0
g_inputs = []
k_inputs = []

for i in input().split():
    if index % 2 == 0:
        g_inputs.append(int(i))
        index += 1
    else:
        k_inputs.append(int(i))
        index += 1

g = Counter(g_inputs)
k = Counter(k_inputs)

g_max = max([(v,k) for k,v in g.items()])[1] 
k_max = max([(v,k) for k,v in k.items()])[1]

if g_max == k_max:
    if g[g_max] < k[k_max]:
        del g[g_max]
        g_max = max([(v,k) for k,v in g.items()])[1]
        print(N - g[g_max] - k[k_max])
    if g[g_max] > k[k_max]:
        del k[k_max]
        k_max = max([(v,k) for k,v in k.items()])[1]
        print(N - g[g_max] - k[k_max])
    else:
        del g[g_max]
        del k[k_max]
        if len(g) == 0 and len(k) == 0:
            print(n)
        if len(g) != 0 and len(k) == 0:
            print(n - max([(v,k) for k,v in g.items()])[1])
        if len(g) == 0 and len(k) != 0:
            print(n - max([(v,k) for k,v in k.items()])[1])
        if len(g) != 0 and len(k) != 0:
            g_temp = g_max
            k_temp = k_max
            g_max = max([(v,k) for k,v in g.items()])[1]
            k_max = max([(v,k) for k,v in k.items()])[1]
            if g[g_max] < k[k_max]:
                print(n - k[k_max])
            elif g[g_max] > k[k_max]:
                print(n - g[g_max])
            else:
                print(N - g[g_max] - k[k_max])
else:
    print(N - g[g_max] - k[k_max])

Submission status: Wrong Answer

Solution code:
from collections import Counter

n = int(input())
v = list(map(int, input().split()))
odd_list = v[1::2]  # 偶数番目
even_list = v[::2]  # 奇数番目

odd_list_len = len(odd_list)
even_list_len = len(even_list)

odd_mode = Counter(odd_list).most_common(1)
even_mode = Counter(even_list).most_common(1)

ans = 0

if odd_mode >= even_mode:
    ans += odd_list_len - odd_mode[0][1]
    if odd_mode[0] != even_mode[0]:
        ans += even_list_len - even_mode[0][1]
    else:
        if len(Counter(even_list).most_common(2)) == 2:
            ans += even_list_len - Counter(even_list).most_common(2)[1][1]
        else:
            ans += even_list_len
else:
    ans += even_list_len - even_mode[0][1]
    if even_mode[0] != odd_mode[0]:
        ans += odd_list_len - odd_mode[0][1]
    else:
        if len(Counter(odd_list).most_common(2)) == 2:
            ans += odd_list_len - Counter(odd_list).most_common(2)[1][1]
        else:
            ans += odd_list_len
print(ans)

Submission status: Wrong Answer

Solution code:
import collections
n=int(input())
N=list(map(int,input().split(" ")))
list_odd=N[::2]
list_even=N[1::2]
c_odd = collections.Counter(list_odd)
c_even = collections.Counter(list_even)
most_odd=c_odd.most_common()[0][1]
most_even=c_even.most_common()[0][1]
if (n<=2):
    print("0")
elif (len(list_even)==most_even and len(list_odd)==most_odd and c_odd.most_common()[0][0]==c_even.most_common()[0][0]):
    print(most_odd)
else:
    print(len(list_even)+len(list_odd)-most_even-most_odd)
#c_odd.most_common()[0][0]==c_even.most_common()[0][0]

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:
        if v[i] in even:
            even[v[i]] += 1
        else:
            even[v[i]] = 1
    else:
        if v[i] in odd:
            odd[v[i]] += 1
        else:
            odd[v[i]] = 1

def check(dic1, dic2):
    if len(dic1) == 1 and len(dic2) == 1 and list(dic1.keys()) != list(dic2.keys()):
        return True
    else:
        return False

def maxkey(dic):
    maxkey = 0
    maxvalue = 0
    for key in dic:
        value = dic[key]
        if maxvalue < value:
            maxvalue = value
            maxkey = key
    return maxkey

if check(even, odd):
    print(0)
elif len(list(set(v))) == 1:
    print(int(n/2))
else:
    evenlist = sorted(list(even.values()))
    oddlist = sorted(list(odd.values()))
    evenlist.reverse()
    oddlist.reverse()
    if maxkey(even) == maxkey(odd):
        ans = n/2 - evenlist[0] + n/2 - oddlist[0]
        print(int(ans))
    else:
        if len(evenlist) == 1:
            ans = n/2-evenlist[0] + n/2-oddlist[1]
        elif len(oddlist) == 1:
            ans = n/2-evenlist[1] + n/2-oddlist[0]
        else:
            ans = min(n/2-evenlist[0] + n/2-oddlist[1], n/2-evenlist[1] + n/2-oddlist[0])
        print(int(ans))

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
num_list = input().split()
m=1
num_list_1 = []
num_list_2 = []
for n in range(0, n,2):
    num_list_1.append(num_list[n])
    num_list_2.append(num_list[n+1])
c_1 = collections.Counter(num_list_1)
c_2 = collections.Counter(num_list_2)

lib_1 = c_1.most_common()
lib_2 = c_2.most_common()
k = 0

z = len(lib_1)
for n in range(1,z):
    k += int(lib_1[n][1])

z = len(lib_2)
for n in range(1,z):
    k += int(lib_2[n][1])
    
if lib_1[0][0] != lib_2[0][0]:
    print(k)
else:
    if lib_1[0][1] >= lib_2[0][1]:
        print(k+lib_2[0][1])
    else:
        print(k+lib_2[0][1])

Submission status: Wrong Answer

Solution code:
n=int(input())
count=0
v=[]
v=[int(i) for i in input().split()]
for i in range(n-2):
    if v[i]==v[i+2]:
        pass
    else:
        count+=1
v.remove(v[0])
if len(v)==0:
    if n%2==0:
        count=int(n/2)
    else:
        count=int((n-1)/2)
print(count)

Submission status: Wrong Answer

Solution code:
n = int(input())
v = [int(i) for i in input().split()]
v1 = []
v2 = []
for i in range(n):
    if(i % 2 == 1):
        v1.append(v[i])
    else:
        v2.append(v[i])
count1 = [v1.count(v1[i]) for i in range(int(n/2))]
count1.sort()
count2 = [v2.count(v2[i]) for i in range(int(n/2))]
count2.sort()
if(count1[count1.index(max(count1))] == count2[count1.index(max(count1))]):
    print(int(n/2 - count1[0] + n/2 - count2[1]))
else:
    print(int(n/2 - count1[0] + n/2 - count2[0]))

Submission status: Wrong Answer

Solution code:
import collections

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

if len(set(v_l)) == 1:
    print(n // 2)
    exit()
elif len(set(v_l)) == n // 2:
    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])
times = 0
count_odd = collections.Counter(v_l_odd)
count_even = collections.Counter(v_l_even)
print(count_even)
while True:
    print(str(times) + "times")
    mon = count_odd.most_common()[times][0]
    print(mon)
    print(count_odd.most_common()[times][0])
    men = count_even.most_common()[times][0]
    print(men)

    v_l_odd_diff = []
    v_l_even_diff = []

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

    if len(set(v_l)) != 1:
        print(len(v_l_odd_diff) + len(v_l_even_diff))
        exit()
    else:
        times = times + 1

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import collections
# 整数の入力
n = int(input())
a = [int(b) for b in input().split()]
k1 = a[::2]
k2 = a[1::2]

c1 = collections.Counter(k1)
c2 = collections.Counter(k2)
mc1 = c1.most_common()[:2]
mc2 = c2.most_common()[:2]
#print(mc1)
#print(mc2)

res1 = mc1[0][1]
res2 = mc2[0][1]
flag,flag2 = True, True
try:
    resA = mc1[1][1]
except:
    flag = False
try:
    resB = mc2[1][1]
except:
    flag2 = False

if mc1[0][0] == mc2[0][0]:
    if flag and flag2:
        if mc1[1][1] <= mc2[1][1]:
            res1 = mc1[1][1]
        else:
            res2 = mc2[1][1]
    elif not flag:
        if not flag2:
            res1 = 0
        else:
            res2 = mc2[1][1]
    else:
        res1 = mc1[1][1]

print(n - res1 - res2)

Submission status: Wrong Answer

Solution code:
n = int(input())
v = list(map(int,input().split()))
l = list(range(n))
odd = [v[i] for i in l if i%2 == 0]
even = [v[i] for i in l if i%2 == 1]

import collections
oddm = collections.Counter(odd).most_common()
evenm = collections.Counter(odd).most_common()

if oddm[0][0] == evenm[0][0]:
    a = len(odd)
else:
    a = (n/2)-numodd+(n/2)-numeven
print(int(a))

Submission status: Wrong Answer

Solution code:
n = int(input())
v = list(map(int, input().split()))
count = len(set(v))
if count == 1:
    print(int(n/2))
elif count == 2:
    print(0)
else:
    print(count-2)