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 = input()
V = list(map(int, input().split(" ")))

v1 = V[0::2]
v2 = V[1::2]

f1 = Counter(v1).most_common(2)
f2 = Counter(v2).most_common(2)

ans = 0

if len(set(v1)) == len(set(v2)) == 1:
    if v1 == v2:
        ans = min(len(v1), len(v2))
else:
    if f1[0][0] != f2[0][0]:
        ans = (len(v1) - f1[0][1]) + (len(v2) - f2[0][1])
    else:
        if f1[0][1] >= f2[0][1]:
            ans = (len(v1) - f1[0][1]) + (len(v2) - f2[1][1])
        else:
            ans = (len(v1) - f1[1][1]) + (len(v2) - f2[0][1])

print(ans)

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())

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

array_0 = collections.Counter(array[::2]).most_common()
array_1 = collections.Counter(array[1::2]).most_common()


if array_0[0][0] == array_1[0][0]:
    if len(array_0) * len(array_1) == 1:
        print(n // 2)
        exit()
    elif array_0[0][1] > array_1[0][1]:
        print(len(array) - array_1[1][1] - array_0[0][1])
        exit()
    else:
        print(len(array) - array_1[0][1] - array_0[1][1])
        exit()

print(len(array) - array_1[0][1] - array_0[0][1])

Submission status: Wrong Answer

Solution code:
import collections

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

v1 = [v[i] for i in range(0,n,2)]
v2 = [v[i] for i in range(1,n,2)]

count1 = collections.Counter(v1)
count2 = collections.Counter(v2)

if len(count1) == 1 and len(count2) == 1:
    if v1 == v2:
        print(len(v1))
    else:
        print(0)

elif v1 == v2:
    res1 = len(v1) - max(count1.values())
    count2.pop(max(count2,key=count2.get))
    res1 = res1 + len(v2) - max(count2.values())

    res2 = len(v2) - max(count2.values())
    count1.pop(max(count1,key=count1.get))
    res2 = res2 + len(v1) - max(count1.values())
    print(min(res1,res2))

else:
    res = len(v1) - max(count1.values()) + len(v2) - max(count2.values())
    print(res)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = input()
V = list(map(int, input().split(" ")))

v1 = V[0::2]
v2 = V[1::2]

f1 = Counter(v1).most_common(2)
f2 = Counter(v2).most_common(2)

ans = 0

if len(set(v1)) == len(set(v2)) == 1:
    if v1 == v2:
        ans = min(len(v1), len(v2))
else:
    if f1[0][0] != f2[0][0]:
        ans = (len(v1) - f1[0][1]) + (len(v2) - f2[0][1])
    else:
        if f1[0][1] > f2[0][1]:
            ans = (len(v1) - f1[0][1]) + (len(v2) - f2[1][1])
        else:
            ans = (len(v1) - f1[1][1]) + (len(v2) - f2[0][1])

print(ans)

Submission status: Wrong Answer

Solution code:
import collections

n = int(input())

al = [int(l) for l in input().split()]

a = []
b = []
for i, x in enumerate(al):
    if i%2 == 0:
        a.append(x)
    else:
        b.append(x)

ac = collections.Counter(a).most_common()
bc = collections.Counter(b).most_common()

if ac[0][0] != bc[0][0]:
    print(n-ac[0][1]-bc[0][1])
else:
    if len(ac) >= 2 and ac[0][1] == ac[1][1]:
        print(n-ac[0][1]-bc[0][1])
    elif len(bc) >= 2 and bc[0][1] == bc[1][1]:
        print(n-ac[0][1]-bc[0][1])

    min_c = n//2

    if len(bc) >= 2:
        min_c = min(min_c, n-ac[0][1]-bc[1][1])
    else:
        min_c = min(min_c, n-ac[0][1])
    if len(ac) >= 2:
        min_c = min(min_c, n-ac[1][1]-bc[0][1])
    else:
        min_c = min(min_c, n-bc[0][1])
        
    if len(ac) >= 2 and len(bc) >= 2:
        min_c = min(min_c, n-bc[1][1]-ac[1][1])
    print(min_c)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
v = list(map(int, input().split()))
gu = []
ki = []
ans = 0
k,g = False,False

if v.count(v[0]) == len(v):#全部同じ
    ans += len(v) // 2
else:
    for i, v in enumerate(v,1):
        if i % 2 == 1:
            ki.append(v)
        else:
            gu.append(v)

    kic = Counter(ki)
    guc = Counter(gu)
    k1 = kic.most_common(2)
    g1 = guc.most_common(2)
    if k1[0][0] == g1[0][0]:
        if k1[1][1] < g1[1][1]:
            k = True
        else:
            g = True

    kic = list(kic.values())
    guc = list(guc.values())
    kic.sort(reverse = True)
    guc.sort(reverse = True)
    if len(kic) != 1:
        if k:
            ans += kic[0]
            ans += sum(kic[2::])
        else:
            ans += sum(kic[1::]) 
    if len(guc) != 1:
        if g:
            ans += guc[0]
            ans += sum(guc[2::])
        else:
            ans += sum(guc[1::])

print(ans)

Submission status: Wrong Answer

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

num_v = {}
for v_ in v:
	if v_ not in num_v:
		num_v[v_]  = 1
	else:
		num_v[v_] += 1
if len(num_v) == 1:
	print n / 2
else:
	sorted_num_v = sorted(num_v.items(), key=lambda x:x[1])
	v_1st = sorted_num_v[-1][0]
	v_2nd = sorted_num_v[-2][0]
	res = float('inf')
	for j in range(len(sorted_num_v) - 1):
		odd = 0
		even = 0
		if v_2nd != sorted_num_v[-2-j][0]:
			break
		for i in range(n):
			v_2nd = sorted_num_v[-2-j][0]
			if v[i] == v_1st and i % 2 == 0:
				odd += 1	
			if v[i] == v_1st and i % 2 != 0:
				even += 1
			if v[i] == v_2nd and i % 2 == 0:
				even += 1
			if v[i] == v_2nd and i % 2 != 0:
				odd += 1
		res = min(res, n - max(even, odd))
	print res

Submission status: Wrong Answer

Solution code:
n = int(input())
lst = list(map(int, input().split()))
ma = {}
ma[lst[0]] = 1
mb = {}
mb[lst[1]] = 1
for i in range(2, n, 2):
    lst[i] in ma
    if lst[i] in ma:
        ma[lst[i]] += 1
    else:
        ma[lst[i]] = 1
    lst[i+1] in mb
    if lst[i+1] in mb:
        mb[lst[i+1]] += 1
    else:
        mb[lst[i+1]] = 1
if max(ma, key=ma.get) > max(mb, key=mb.get) and max(ma, key=ma.get) in mb:
    mb[max(ma, key=ma.get)] = 0
elif  max(ma, key=ma.get) <= max(mb, key=mb.get) and max(mb, key=mb.get) in ma:
    ma[max(mb, key=mb.get)] = 0
d = n - max(ma.values()) - max(mb.values())
print(d)

Submission status: Wrong Answer

Solution code:
a = int(input())

b = list(map(int,input().split()))
d = max(b)
c = [0 for i in range(pow(10,5)+1)]
cc = [0 for i in range(pow(10,5)+1)]
for i in range(a):
    if i % 2 == 0:
        c[b[i]-1] += 1
    else:
        cc[b[i]-1] += 1

one = 0
onee = 0
two = 0
twoo = 0
k = 0
kk = 0
for i in range(len(c)):
    if one <= c[i]:
        onee = one
        one = c[i]
        k = i
    if two <= cc[i]:
        twoo = two
        two = cc[i]
        kk = i

t = max(one+twoo,onee+two)

if k != kk:
    print(a-one-two)
else:
    print(a-t)

Submission status: Wrong Answer

Solution code:
n = int(input())
numberL = list(map(int, input().split()))
 
kisuuSyuL=[]
kisuuKosuL=[]
kisuuKosuL2=[]
gusuSyuL=[]
gusuKosuL=[]
gusuKosuL2=[]
 
index=0
while index<n:
    if index==0:
        gusuSyuL.append(numberL[index])
        gusuKosuL.append(1)
        gusuKosuL2.append(1)
    elif index==1:
        kisuuSyuL.append(numberL[index])
        kisuuKosuL.append(1)
        kisuuKosuL2.append(1)
    else:
        if index%2==0:
            if numberL[index] in gusuSyuL:
                tarI = gusuSyuL.index(numberL[index])
                gusuKosuL[tarI]+=1
                gusuKosuL2[tarI]+=1
            else:
                gusuSyuL.append(numberL[index])
                gusuKosuL.append(1)
                gusuKosuL2.append(1)
        else:
            if numberL[index] in kisuuSyuL:
                tarI = kisuuSyuL.index(numberL[index])
                kisuuKosuL[tarI]+=1
                kisuuKosuL2[tarI]+=1
            else:
                kisuuSyuL.append(numberL[index])
                kisuuKosuL.append(1)
                kisuuKosuL2.append(1)
    index+=1
 
 
if len(kisuuSyuL)==1 and len(gusuSyuL)==1:
    if kisuuSyuL[0]==gusuSyuL[0]:
        print(int(n/2))
    else:
        print(0)
else:
    kiIndex = kisuuKosuL.index(max(kisuuKosuL))
    guIndex = gusuKosuL.index(max(gusuKosuL))
    if kisuuSyuL[kiIndex]!=gusuSyuL[guIndex]:
        noC=max(kisuuKosuL)+max(gusuKosuL)
        print(n-noC)
    else:
        kisuuKosuL2.sort()
        gusuKosuL2.sort()
        if max(kisuuKosuL)< max(gusuKosuL):
            noC=kisuuKosuL2[len(kisuuKosuL2)-2]+max(gusuKosuL)
            print(n-noC)
        else:
            noC=gusuKosuL2[len(gusuKosuL2)-2]+max(kisuuKosuL)
            print(n-noC)

Submission status: Wrong Answer

Solution code:
import collections

n = input()
nums = list(map(int, input().split()))
odd = nums[0::2]
even = nums[1::2]
odd_c = collections.Counter(odd)
even_c = collections.Counter(even)


if odd_c.most_common(1)[0][0] == even_c.most_common(1)[0][0]:
    if len(odd_c) >= 3 and len(even_c) >= 3:
        odd_first_count = len(odd) - odd_c.most_common(1)[0][1]
        even_first_count = len(even) - even_c.most_common(1)[0][1]
        odd_second_count = len(odd) - odd_c.most_common(2)[1][1]
        even_second_count = len(even) - even_c.most_common(2)[1][1]
        if odd_first_count + even_second_count < odd_second_count + even_first_count:
            print(odd_first_count + even_second_count)
            exit()
        else:
            print(odd_second_count + even_first_count)
            exit()
    odd_next_most = 0
    even_next_most = 0
    if len(odd_c) >= 2:
        odd_next_most = odd_c.most_common(2)[1][1]
    if len(even_c) >= 2:
        even_next_most = even_c.most_common(2)[1][1]
    if odd_next_most > even_next_most:
        print(len(odd) - odd_next_most + len(even) - even_c.most_common(1)[0][1])
    else:
        print(len(odd) - odd_c.most_common(1)[0][1] + len(even) - even_next_most)
else:
    print("else")
    odd_change = len(odd) - odd_c.most_common(1)[0][1]
    even_change = len(even) - even_c.most_common(1)[0][1]
    print(odd_change + even_change)

Submission status: Wrong Answer

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

A=[[0,i] for i in range(max(V)+1)]
B=[[0,i] for i in range(max(V)+1)]

for i in range(0,n,2):
    A[V[i]][0]+=1
for i in range(1,n,2):
    B[V[i]][0]+=1

A.sort(reverse=1)
B.sort(reverse=1)

#print(A[:10])
#print(B[:10])

Ma=[]
Mb=[]

ma=A[0][0]
mb=B[0][0]
i=0
j=0
while A[i][0]==ma :
    Ma.append(A[i][1])
    i+=1

while B[j][0]==mb :
    Mb.append(B[j][1])
    j+=1

if Ma==Mb :
    print(min(n-ma-B[j][0],n-mb-A[i][0],n-1))
else :
    print(n-ma-mb)

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)
print(sum(v==3))

u = np.unique(v)
if len(u) < 2:
	print(2)
elif len(u) == 2:
	print(0)
else:
	v_c = np.array([sum(v==a) for a in u if sum(v==a) != 0])
	v_c = v_c[np.nonzero(v_c)]
	print(sum(sorted(v_c, reverse=True)[2:]))

Submission status: Wrong Answer

Solution code:
a = int(input())

b = list(map(int,input().split()))
d = max(b)
c = [0 for i in range(pow(10,5)+100)]
cc = [0 for i in range(pow(10,5)+100)]
for i in range(a):
    if i % 2 == 0:
        c[b[i]] += 1
    else:
        cc[b[i]] += 1

one = 0
onee = 0
two = 0
twoo = 0
k = 0
kk = 0
for i in range(len(c)):
    if one <= c[i]:
        onee = one
        one = c[i]
        k = i
    if two <= cc[i]:
        twoo = two
        two = cc[i]
        kk = i

t = max(one+twoo,onee+two)

if k != kk:
    print(a-one-two)
else:
    print(a-t)

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(min(n-S[0]-Q[1],n-S[1]-Q[0]))

Submission status: Wrong Answer

Solution code:
n = int(input())
v = [int(i) for i in input().split()] 
lv0 = []
dv0 = {}
lv1 = []
dv1 = {}

v.sort()
ans = -1

def func():
    count0 = 0
    count1 = 0
    for i,x in enumerate(v):
            if i%2 == 0:
                if x not in lv0:
                    lv0.append(x)
                    dv0[x] = 1
                else:
                    dv0[x] += 1
                if dv0[x] > count0:
                    count0 = dv0[x]
            else:
                if x not in lv1:
                    lv1.append(x)
                    dv1[x] = 1
                else:
                    dv1[x] += 1
                if dv1[x] > count1:
                    count1 = dv1[x]
    ans = n - count0 - count1



for i in range(int(n/2)):
    i0 = 2*i
    i1 = 2*i + 1
    if v[0] != v[1]:
        func()
        break
    if v[i0] != v[i1]:
        count = 0
        if v[i0] != v[i0-2]:
            for x in range(i,int(n/2)):
                x0 = 2*x
                if v[i0] != v[x0]:
                    break
                count += 1
        if v[i1] != v[i1-2]:
            for x in range(i,int(n/2)):
                x1 = 2*x + 1
                if v[i1] != v[x1]:
                    break
                count += 1
        ans = n - (i+1) - count
        break
print(ans)

Submission status: Wrong Answer

Solution code:
import collections as cl

n=int(input())
vlist=list(input().split())

vg=vlist[0::2]
vk=vlist[1::2]

vgcnt=cl.Counter(vg)
vkcnt=cl.Counter(vk)

vgmax=max(vgcnt,key=vgcnt.get)
vkmax=max(vkcnt,key=vkcnt.get)

if vgmax==vkmax:
    if vgcnt[vgmax]<vkcnt[vkmax]:
        vgcnt.pop(vgmax)
        if len(vgcnt)!=0:
            vgmax=max(vgcnt)
        else:
            vgmax='a'
    else:
        vkcnt.pop(vkmax)
        if len(vkcnt)!=0:
            vkmax=max(vkcnt)
        else:
            vkmax='a'

ans=0
for i in range(len(vg)):
    if vg[i]!=vgmax:
        ans+=1
for i in range(len(vk)):
    if vk[i]!=vkmax:
        ans+=1

print(ans)

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:
        if not flag2:
          res2 = 0
        else:
          res1 = mc1[1][1]


#print(flag,flag2)
print(n - res1 - res2)

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:
                if num != pattern1:
                    pattern2 = num
                else:
                    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())
input_numbers = input().split(" ")
count_list1 = {}
count_list2 = {}
sum = 0
max1 = 0
max2 = 0
max2_sub = 0
i = 0

while i < n:
    if input_numbers[i] in count_list1:
        count_list1[input_numbers[i]] += 1
    else:
        count_list1[input_numbers[i]] = 1
    i += 1
    if input_numbers[i] in count_list2:
        count_list2[input_numbers[i]] += 1
    else:
        count_list2[input_numbers[i]] = 1
    i += 1

for x in count_list1:
    if int(x) > max1:
        max1_sub = max1
        max1 = int(x)
    elif int(x) > max1_sub:
        max1_sub = int(x)
    sum += int(x)
sum -= max1
for x in count_list2:
    if int(x) > max2:
        max2_sub = max2
        max2 = int(x)
    elif int(x) > max2_sub:
        max2_sub = int(x)
    sum += int(x)
sum -= max2

if max1 == max2:
    # if max1 < max2:
    #     sum += max2
    #     sum -= max2_sub
    # else:
    #     sum += max1
    #     sum -= max1_sub
    sum = int(n/2)
print(sum)

Submission status: Wrong Answer

Solution code:
n = int(input())

v = [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[1])
v2 = sorted(v2.items(),key=lambda x: - x[1])
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:
n = input()
arr = list(map(int,input().split()))

arr1 = arr[::2]
arr2 = arr[1::2]

count1 = []
count2 = []

for i in range(9):
    count1.append(int(arr1.count(i)))
    count2.append(int(arr2.count(i)))

    
if count1.index(max(count1)) == count2.index(max(count2)): 
    count1.sort()
    count2.sort()
    if count1[0] > count2[0]:
        ans1 = sum(count1) - count1[-1]
        ans2 = sum(count2) - count2[-2]
        print(1)
    elif count1[0] < count2[0]:
        ans1 = sum(count1) - count1[-2]
        ans2 = sum(count2) - count2[-1]
        print(2)
    elif count1[0] == count2[0] and count1[1] > count2[1]:
        ans1 = sum(count1) - count1[-1]
        ans2 = sum(count2) - count2[-2]
        print(3)
    else:
        ans1 = sum(count1) - count1[-2]
        ans2 = sum(count2) - count2[-1]

else:
    ans1 = sum(count1) - max(count1)
    ans2 = sum(count2) - max(count2) 

print(ans1+ans2)

Submission status: Wrong Answer

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

c1 = None
c2 = None
t_cnt = 0
for i in range(0,len(v)):
    if c1 == None:
        c1 = i
        continue
    if c2 == None:
        c2 = i
        continue
    if v[c1] == v[c2]:
        c2 = None
        continue

    if i % 2 == c1 % 2:
        tar = v[c1]
    else:
        tar = v[c2]

    if v[i] == tar:
        t_cnt += 1

    else:
        i -= 1
        c1 = None
        c2 = None
        t_cnt = 0
    
    if t_cnt > cnt:
        cnt = t_cnt

print(n - (cnt+2))

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:
    try:
        sum_odd1 = sum(temp_odd) - temp_odd[1]
    except:
        sum_odd1 = temp_odd[0]
    sum_even1 = sum(temp_even) - temp_odd[0]
    sum1 = sum_even1+sum_odd1

    try:
        sum_even2 = sum(temp_even) - temp_even[1]
    except:
        sum_even2 = temp_even[0]
    sum_odd2 = sum(temp_odd) - temp_odd[0]
    sum2 = sum_even2+sum_odd2
    print(min(sum1,sum2))

    # 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))

# print(count_even)
# print(list(count_even.keys())[0])
# print(count_odd)
# 8
# 1 1 1 1 1 1 1 1
"""
8
1 1 1 1 1 2 1 1

10
3 3 3 3 3 3 1 2 2 

10
3 3 3 3 3 3 3 2 3 1

8
3 2 3 2 3 2 1 3

6 
3 2 3 2 3 2

12
3 3 3 3 3 3 1 2 1 2 2 1

12
3 3 3 3 3 3 1 2 1 2 1 4

"""

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

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


    ans = 0
    vc = Counter(v)
    vc0 = Counter(v[::2])
    vc1 = Counter(v[1::2])

    if len(set(v[::2])) == 1:
        if v[0] == vc1.most_common(1)[0][0]:
            print(vc1.most_common(1)[0][1])
        else:
            print(len(v)//2 - vc1.most_common(1)[0][1])

        exit()
    elif len(set(v[1::2])) == 1:
        if v[1] == vc0.most_common(1)[0][0]:
            print(vc0.most_common(1)[0][1])
        else:
            print(len(v)//2 - vc0.most_common(1)[0][1])
        exit()

    if vc.most_common(1)[0][1] >= len(v)//2:
        if vc0.most_common(2)[1][1] > vc1.most_common(2)[1][1]:
            if len(set(v[::2])) !=1:
                ans += len((v[::2])) - vc0.most_common(2)[1][1]
            ans += len((v[1::2])) - vc1.most_common(1)[0][1]
        else:
            ans += len((v[::2])) - vc0.most_common(1)[0][1]
            if len(set(v[1::2])) !=1:
                ans += len((v[1::2])) - vc1.most_common(2)[1][1]

    else:
        ans += len((v[::2])) - vc0.most_common(1)[0][1]
        ans += len((v[1::2])) - vc1.most_common(1)[0][1]

    print(ans)

if __name__ == "__main__":
        main()

Submission status: Wrong Answer

Solution code:
from collections import Counter


def solve(V):
    odd = Counter()
    even = Counter()
    total = Counter()
    for i, c in enumerate(V):
        total.update([c])
        if i % 2 == 0:
            even.update([c])
        else:
            odd.update([c])

    total_max = total.most_common()[0]
    if total_max[1] == len(V):
        return len(V) / 2

    even_maxs = even.most_common(2)
    odd_maxs = odd.most_common(2)
    if len(odd_maxs) > 1:
        odd_max, odd_2nd_max = odd_maxs[0], odd_maxs[1]
    else:
        odd_max, odd_2nd_max = odd_maxs[0], None

    if len(even_maxs) > 1:
        even_max, even_2nd_max = even_maxs[0], even_maxs[1]
    else:
        even_max, even_2nd_max = even_maxs[0], None

    ans = 0
    if odd_max[0] != even_max[0]:
        odd_max = odd_max[0]
        even_max = even_max[0]
    elif odd_2nd_max != None and even_2nd_max == None:
        odd_max = odd_2nd_max[0]
        even_max = even_max[0]
    elif odd_2nd_max == None and even_2nd_max != None:
        odd_max = odd_max[0]
        even_max = even_2nd_max[0]
    else:
        if odd_max[0] == even_2nd_max[0]:
            odd_max = odd_2nd_max[0]
            even_max = even_max[0]
        elif odd_2nd_max[0] == even_max[0]:
            odd_max = odd_max[0]
            even_max = even_2nd_max[0]
        else:
            if odd_max[1] + even_2nd_max[1] > odd_2nd_max[1] + even_max[1]:
                odd_max = odd_max[0]
                even_max = even_2nd_max[0]
            else:
                odd_max = odd_2nd_max[0]
                even_max = even_max[0]

    for key, count in even.items():
        if key != even_max:
            ans += count
    for key, count in odd.items():
        if key != odd_max:
            ans += count
    return ans


if __name__ == "__main__":
    n = int(input())
    l = input()
    print(solve(l.split(" ")))

Submission status: Wrong Answer

Solution code:
# c

from collections import Counter

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

odd = a[::2]
even = a[1::2]
#print(odd,even)

cnt_odd = Counter(odd)
cnt_even = Counter(even)

#if odd==even: print(N//2)
if sorted(cnt_odd.values())[0]==sorted(cnt_even.values())[0] and sorted(cnt_odd.values())[0]==N//2: print(N//2)
elif len(cnt_odd)==1:
    for i,key in enumerate(cnt_odd):
        ko = key
    ve = sorted(cnt_even.values())[-1]
    if cnt_even[ko]!=ve:
        print(N//2 - sorted(cnt_even.values())[-1])
    else: print(N//2 - sorted(cnt_even.values())[-2])

elif len(cnt_even)==1:
    for i,key in enumerate(cnt_even):
        ke = key
    vo = sorted(cnt_odd.values())[-1]
    if cnt_odd[ke]!=vo:
        print(N//2 - sorted(cnt_odd.values())[-1])
    else: print(N//2 - sorted(cnt_odd.values())[-2])

else:
    vo1 = sorted(cnt_odd.values())[-1]
    vo2 = sorted(cnt_odd.values())[-2]
    ve1 = sorted(cnt_even.values())[-1]
    ve2 = sorted(cnt_even.values())[-2]
    for i,key in enumerate(cnt_odd):
        if cnt_odd[key]==vo1: ko1 = key
    for i,key in enumerate(cnt_odd):
        if cnt_odd[key]==vo2: ko2 = key
    for i,key in enumerate(cnt_even):
        if cnt_even[key]==ve1: ke1 = key
    for i,key in enumerate(cnt_even):
        if cnt_even[key]==ve2: ke2 = key
    if ko1!=ke1: print(N - sorted(cnt_odd.values())[-1] - sorted(cnt_even.values())[-1])
    else:
        ans1 = N - sorted(cnt_odd.values())[-1] - sorted(cnt_even.values())[-2]
        ans2 = N - sorted(cnt_odd.values())[-2] - sorted(cnt_even.values())[-1]
        print(min(ans1,ans2))

Submission status: Wrong Answer

Solution code:
n = int(input())
nums = list(map(int, input().split()))
a = nums[0]
b = 0
ct = 0
for i in range(0, len(nums)):
    if nums[i] % 2 != 0:
        if a != nums[i]:
            b = nums[i]
            break

for i in range(0, len(nums)):
    if i % 2 == 0:
        if nums[i] != a:
            ct += 1
    elif i != 1:
        if nums[i] != b:
            ct += 1

print(ct)

Submission status: Wrong Answer

Solution code:
import math,sys,copy

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

e = [0]*(max(v)+1)
o = [0]*(max(v)+1)
for i, x in enumerate(v):
	if i % 2 == 0: # 1,3,5,....
		o[x] += 1
	else: # 2,4,6,...
		e[x] += 1

o_ = o[1:]
if o_.index(max(o_))+1 == e.index(max(e)):
	c = zip(e,range(len(e)))
	c = sorted(c, reverse=True)
	e_, ie = zip(*c)
	
	c = zip(o_,range(len(o_)))
	c = sorted(c, reverse=True)
	o__, io = zip(*c)

	for x in range(len(ie)-1):
		if ie[x] != io[x]+1:
			break
	if e_[x] < o__[x]:
		om = o__[x]
		em = max(e)
	elif e_[x] == o__[x] and o__[x] == 0:
		om = 1
		em = max(e)
	else:
		om = max(o)
		em = e_[x]

else:
	om = max(o_)
	em = max(e)

print(sum(o) + sum(e) - om - em)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
v = list(map(int,input().split()))
o = v[0::2]
e = v[1::2]
o_mode = Counter(o).most_common()
e_mode = Counter(e).most_common()
if o == e:
  print(int(n/2))
else:
  print(n-o_mode[0][1]-e_mode[0][1])

Submission status: Wrong Answer

Solution code:
n = int(input())
m = input().split(" ")
li = [int(i) for i in m]
li_0 = [k for ix, k in enumerate(li) if ix%2 == 0]
li_1 = [k for ix, k in enumerate(li) if ix%2 == 1]

#li_0
se_0 = set(li_0)
li_02 = list(se_0) 
s0 = []
for i in range(len(li_02)):
    c = li_0.count(li_02[i])
    s0.append(c)
change_0 = sum(s0) - max(s0)

#li_1
se_1 = set(li_1)
li_12 = list(se_1) 
s1 = []
for i in range(len(li_12)):
    c = li_1.count(li_12[i])
    s1.append(c)
s1.sort()
change_1 = sum(s1) - max(s1)

print(change_0 + change_1)

Submission status: Wrong Answer

Solution code:
from collections import Counter

n=int(input())
v = input().split()
c=Counter(v)
c1=c.most_common()[0][1]

if (c1==n):
    print(n//2)
else:
    c2=c.most_common()[1][1]
    print(n-c1-c2)

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

        if even == odd:
            print(min(n - even, n - odd))
            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:
import collections as cl

n=int(input())
vlist=list(input().split())

vg=vlist[0::2]
vk=vlist[1::2]

vgcnt=cl.Counter(vg)
vkcnt=cl.Counter(vk)

vgmax=max(vgcnt,key=vgcnt.get)
vkmax=max(vkcnt,key=vkcnt.get)

if vgmax==vkmax:
    if vgcnt[vgmax]<=vkcnt[vkmax]:
        vgcnt.pop(vgmax)
        if len(vgcnt)>0:
            vgmax=max(vgcnt)
        else:
            vgmax='a'
    else:
        vkcnt.pop(vkmax)
        if len(vkcnt)>0:
            vkmax=max(vkcnt)
        else:
            vkmax='a'

ans=0
for i in range(len(vg)):
    if vg[i]!=vgmax:
        ans+=1
for i in range(len(vk)):
    if vk[i]!=vkmax:
        ans+=1

print(ans)

Submission status: Wrong Answer

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

c1 = None
c2 = None
t_cnt = 0
for i in range(0,len(v)):
    if c1 == None:
        c1 = i
        continue
    if c2 == None:
        c2 = i
        continue
    if v[c1] == v[c2]:
        c2 = None
        continue

    if i % 2 == c1 % 2:
        tar = v[c1]
    else:
        tar = v[c2]

    if v[i] == tar:
        t_cnt += 1

    else:
        i -= 1
        c1 = None
        c2 = None
        t_cnt = 0
    
    if t_cnt > cnt:
        cnt = t_cnt

if cnt == 0:
    print(int(n/2))
else:
    print(int(n - (cnt+2)))