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 defaultdict
import sys
n=int(input().strip())
v=list(map(int, input().strip().split()))
counterO=defaultdict(int)
counterE=defaultdict(int)
for i in v[::2]:
    counterO[i]+=1
for i in v[1::2]:
    counterE[i]+=1
cOO=sorted(counterO.items(),key=lambda x:x[1],reverse=True)
cEE=sorted(counterE.items(),key=lambda x:x[1],reverse=True)
if len(counterO)==1 and len(counterE)==1:
    if cOO[0][0]!=cEE[0][0]:
        print(0)
    else:
        print(min(cOO[0][1],cEE[0][1]))
else:
    iO,iE=0,0
    if cOO[iO][0]!=cEE[iE][0]:
        ans=sum(x[1] for x in cOO[:iO]+cOO[iO+1:])+sum(x[1] for x in cEE[:iE]+cEE[iE+1:])
    else:
        vO,vE=sum(x[1] for x in cOO[:iO]+cOO[iO+1:]),sum(x[1] for x in cEE[:iE]+cEE[iE+1:])
        if vO>=vE:
            iE+=1
            ans=sum(x[1] for x in cOO[:iO]+cOO[iO+1:])+sum(x[1] for x in cEE[:iE]+cEE[iE+1:])
        else:
            iO+=1
            ans=sum(x[1] for x in cOO[:iO]+cOO[iO+1:])+sum(x[1] for x in cEE[:iE]+cEE[iE+1:])
    print(ans)

Submission status: Wrong Answer

Solution code:
import collections


n = input()
s = input().split(' ')

even = collections.Counter(s[1::2])
odd = collections.Counter(s[0::2])
maxeven = even.most_common()[0]
maxodd = odd.most_common()[0]
ans = 0
if maxeven[0] != maxodd[0]:
    ans = len(s) - maxeven[1] - maxodd[1]
else:
    if len(s) == maxeven[1] + maxodd[1]:
        ans = len(s) - maxeven[1]
    else:
        if maxeven[1] >= maxodd[1]:
            nextodd = odd.most_common()[1]
            ans = len(s) - maxeven[1] - nextodd[1]
        else:
            nexteven = even.most_common()[1]
            ans = len(s) - maxodd[1] - nexteven[1]

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

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

def count(vs):
    d1 = defaultdict(int)
    d2 = defaultdict(int)
    for i, v in enumerate(vs):
        if i % 2 == 0:
            d1[v] += 1
        else:
            d2[v] += 1
    return d1, d2

d1, d2 = count(vs)
d1 = sorted([(v, k) for k, v in d1.items()], reverse=True)
d2 = sorted([(v, k) for k, v in d2.items()], reverse=True)
n1, v1 = d1[0]
n2, v2 = d2[0]
if v1 == v2:
    if n1 < n2:
        n1 = 0 if len(d1) == 1 else d1[1][0]
    else:
        n2 = 0 if len(d2) == 1 else d2[1][0]

print(n - n1 - n2)

Submission status: Wrong Answer

Solution code:
n = int(input())
odd = [[i, 0] for i in range(100000)]
even = [[i, 0] for i in range(100000)]
arr = list(map(int, input().split()))
odd_e = False
even_e = False
for i, e in enumerate(arr):
    if i % 2 == 0:
        odd[e - 1][1] += 1
        if not odd_e and arr[0] != e:
            odd_e = True
    else:
        even[e - 1][1] += 1
        if not even_e and arr[1] != e:
            even_e = True
odd.sort(key=lambda z: z[1])
even.sort(key=lambda z: z[1])
if odd[-1][0] == even[-1][0]:
    if odd_e or even_e:
        ans = n - even[-1][1]
    elif odd[-2][1] > even[-2][1]:
        ans = n - even[-1][1] - odd[-2][1]
    else:
        ans = n - even[-2][1] - odd[-1][1]
else:
    ans = n - odd[-1][1] - even[-1][1]
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
v = list(map(int,input().split()))
v2 = []
for i in range(0, n - 1, 1):
    v2.append(abs(v[i] - v[i + 1]))
count = 0
for i in range(0, len(v2) - 1, 1):
    if v2[i] != v2[i + 1]:
        count += 1
print(count)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
d={}
sum=0
maxs=-9999
maxs2=-9999
d[maxs]=d[maxs2]=0
for i in a:
    if i in d:
        d[i]+=1
        if d[i]>d[maxs] and i!=maxs:
            maxs2=maxs
            maxs=i
            continue
        if  d[i]>d[maxs2] and i!=maxs and i!=maxs2:
            maxs2=i
    else:
        d[i]=1
        sum+=1
        if d[i]>d[maxs] and i!=maxs:
            maxs2=maxs
            maxs=i
            continue
        if d[i]>d[maxs2] and i!=maxs and i!=maxs2:
            maxs2=i
if sum>2:
    if d[maxs]>n/2:
        print(int(n/2 - d[maxs2]))
    else:
        print(int(n-d[maxs]-d[maxs2]))
elif sum==2:
    print(int(n/2-d[maxs2]))
else:
    print(int(n/2))

Submission status: Wrong Answer

Solution code:
from collections import Counter
from operator import itemgetter

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

c0 = Counter(v)
if len(c0.values()) == 1:
    ans = n // 2
else:
    c1 = Counter(v[::2])
    c2 = Counter(v[1::2])

    x1 = sorted(c1.items(), reverse=True, key=itemgetter(1))
    x2 = sorted(c2.items(), reverse=True, key=itemgetter(1))

    ans = 0
    for _, v in x1 + x2:
        ans += v
    if x1[0][0] == x2[0][0]:
        if x1[0][1] < x2[0][1]:
            ans -= x2[0][1]
            if len(x1) > 1:
                ans -= x1[1][1]
            else:
                ans -= x1[0][1]
        else:
            ans -= x1[0][1]
            if len(x2) > 1:
                ans -= x2[1][1]
            else:
                ans -= x2[0][1]
    else:
        ans -= x1[0][1]
        ans -= x2[0][1]
print(ans)

Submission status: Wrong Answer

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

sorted_dict = sorted(dict_.items(), key=lambda x: x[1], reverse=True)
res = 0
if len(sorted_dict) == 1:
    print(len(array)//2)
else:
    tmp = sorted_dict[0][0]
    tmp2 = sorted_dict[1][0]
    tmp_cahnges = 0
    tmp2_cahnges = 0
    for i in array[::2]:
        if i != tmp:
            tmp_cahnges += 1
        else:
            tmp2_cahnges += 1
    for j in array[1::2]:
        if j != tmp2:
            tmp_cahnges += 1
        else:
            tmp2_cahnges += 1
    print(min(tmp2_cahnges, tmp_cahnges))

Submission status: Wrong Answer

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

odd, even = v[1::2], v[::2]
most_odd, most_even = -1, -1
odd_cnt, even_cnt = 0, 0

for o in set(odd):
    cnt = 0
    for odi in odd:
        if odi == o:   cnt += 1
    if odd_cnt < cnt:
      odd_cnt = cnt
      most_odd = o

for e in set(even):
    cnt = 0
    for evi in even:
        if evi == e:   cnt += 1
    if even_cnt < cnt:
      even_cnt = cnt
      most_even = e

if most_odd != most_even:
  print(n - even_cnt - odd_cnt )
else:
  print(n // 2)

Submission status: Wrong Answer

Solution code:
import collections as cole


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

v1 = v[::2]   #odd
v2 = v[1::2]  #even

d1 = cole.Counter(v1)
max1 = max(d1)

d2 = cole.Counter(v2)
max2 = max(d2)

count = 0
if max1 != max2:
    for i in v1:
        if i != max1:
            count += 1

    for i in v2:
        if i != max2:
            count += 1
else:
    count = len(v1)

print(count)

Submission status: Wrong Answer

Solution code:
n=int(input())
arr=list(map(int,input().strip().split()))
cnt=0
if len(set(arr))==1:
    print(n//2)
else:
    for i in range(n-2):
        if arr[i]!=arr[i+2]:
            cnt+=1
            arr[i+2]=arr[i]
    print(cnt)

Submission status: Wrong Answer

Solution code:
def most_used_num(nums):
    nums_uniq = set(nums)
    max_num = None
    max_count = 0
    for n in nums_uniq:
        num_count = nums.count(n)
        if num_count > max_count:
            max_count = num_count
            max_num = n
    return max_num, max_count


if __name__ == '__main__':
    n = int(input())
    v_list = list(map(int, input().split()))

    v_odd = v_list[1::2]
    v_even = v_list[::2]

    if v_odd == v_even:
        print(len(v_even))
        exit(0)

    _, v_odd_max_count = most_used_num(v_odd)
    _, v_even_max_count = most_used_num(v_even)

    change_num = (len(v_even) - v_even_max_count) + (len(v_odd) - v_odd_max_count)
    print(change_num)

Submission status: Wrong Answer

Solution code:
import collections

inLen = int(input())
inputs =  list(map(int, input().split()))

evenDict = collections.Counter(inputs[0::2])
oddDict = collections.Counter(inputs[1::2])

evenMost = evenDict.most_common(2)
oddMost = oddDict.most_common(2)

if(evenMost[0][0] != oddMost[0][0]):
    print(inLen - evenMost[0][1] - oddMost[0][1])
else:
    if(evenMost[0][1] < oddMost[0][1]):
        print(inLen - evenMost[1][1] - oddMost[0][1])
    elif (evenMost[0][1] > oddMost[0][1]):
        print(inLen - evenMost[0][1] - oddMost[1][1])
    else:
        print(int(inLen / 2))

Submission status: Wrong Answer

Solution code:
from collections import Counter

import numpy as np
n = int(input())
v = list(map(int,input().split()))

v = np.array(v)

if len(np.unique(v)) == 1:
    print(int(len(v)/2))
else:
    vodd = v[np.arange(0,len(v),2)]
    odd_count = Counter(vodd)

    veven = v[np.arange(1,len(v),2)]
    even_count = Counter(veven)
    

    d_odd = []
    odd_lis = list(odd_count.keys())
    for key in odd_count.keys():
        d_odd.append(odd_count[key])

    d_even = []
    even_lis = list(even_count.keys())
    for key in even_count.keys():
        d_even.append(even_count[key])

    
    if even_lis[np.argmax(d_even)] != odd_lis[np.argmax(d_odd)]:
        score = np.max(d_even) + np.max(d_odd)
    else:
        score1 = even_lis[np.argsort(d_even)[-1]] + odd_lis[np.argsort(d_odd)[-2]]
        score2 = even_lis[np.argsort(d_even)[-2]] + odd_lis[np.argsort(d_odd)[-1]]
        score = max(score1,score2)
    print(len(v) - score)

Submission status: Wrong Answer

Solution code:
from collections import Counter
N = int(input())
A = list(map(int, input().split()))
c1 = Counter(A[::2])
c2 = Counter(A[1::2])
c1m = sorted(c1.items(), key=lambda x:x[1])
c2m = sorted(c2.items(), key=lambda x:x[1])
tmp = N - c1m[0][1] - c2m[0][1]
if tmp == 0:
    if c1m[0][0] == c2m[0][0]:
        print(N // 2)
        exit()
else:
    if c1m[0][0] == c2m[0][0]:
        len_c1m = len(c1m)
        len_c2m = len(c2m)
        if c1m[0][1] == c2m[0][1]:
            if c1m[1][1] > c2m[1][1]:
                print(N - c2m[0][1] - c1m[1][1])
                exit()
            else:
                print(N - c1m[0][1] - c2m[1][1])
                exit()
print(tmp)

Submission status: Wrong Answer

Solution code:
n = int(input())
num_list = list(map(int, input().split()))
count = 0
for i in range(n -2):
  if num_list[i] != num_list[i + 2]:
    count +=1
  elif num_list[i] == num_list[i + 1]:
    count +=1
print(count)

Submission status: Wrong Answer

Solution code:
n = int(input())
v = [int(_) for _ in input().split()]
s = set(v)
if len(s) == 1:
  print(n/2)
elif len(s) == 2:
  print(0)
else:
  print(n-len(s))

Submission status: Wrong Answer

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

o=[]
e=[]
for i in range(len(v)):
    if i%2==0:
        o.append(v[i])
    else:
        e.append(v[i])

mo=0
no=0
me=0

for i in range(10):
    if mo < o.count(i):
        no=i
        mo=o.count(i)

for i in range(10):
    if me < e.count(i) and i!=no:
        me=e.count(i)

mo1=0
ne1=0
me1=0

for i in range(10):
    if me1 < e.count(i):
        ne1=i
        me1=e.count(i)

for i in range(10):
    if mo1 < o.count(i) and i!=ne1:
        mo1=o.count(i)

if mo+me > mo1+me1:
    print(len(v)-mo-me)
else:
    print(len(v)-mo1-me1)

Submission status: Wrong Answer

Solution code:
import collections

n = int(input())

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

ac = collections.Counter(a[::2]).most_common()
bc = collections.Counter(a[1::2]).most_common()


while True:
    if len(ac) == 0:
        print(n-bc[0][1])
        break
    elif len(bc) == 0:
        print(n-ac[0][1])
        break
            
    if ac[0][0] != bc[0][0]:
        print(n-ac[0][1]-bc[0][1])
        break
    elif ac[0][1] >= bc[0][0]:
        bc.pop()
        continue
    else:
        ac.pop()
        continue

Submission status: Wrong Answer

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

odd_cnt = {}
even_cnt = {}

for i,vi in enumerate(vn):
    if i % 2 == 0:
        if vi in even_cnt:
            even_cnt[vi] += 1
        else:
            even_cnt[vi] = 1
    else:
        if vi in odd_cnt:
            odd_cnt[vi] += 1
        else:
            odd_cnt[vi] = 1


if even_cnt == odd_cnt:
    print(n//2)
    exit()

even_max = 0
odd_max = 0
ans = 0
for k,v in even_cnt.items():
    ans += v
    if v > even_max:
        even_max = v

for k,v in odd_cnt.items():
    ans += v
    if v > odd_max:
        odd_max = v

ans = ans - odd_max - even_max
print(ans)

Submission status: Wrong Answer

Solution code:
import collections

n=int(input())
v=list(input().split())
k=v[0::2]
g=v[1::2]

c1 = collections.Counter(k)
c2 = collections.Counter(g)

res1 = n/2 - c1.most_common()[0][1]
res2 = n/2 - c2.most_common()[0][1]

if c1.most_common()[0][0] == c2.most_common()[0][0]:
    print(int(n/2))
else:
    print(int(res1+res2))

Submission status: Wrong Answer

Solution code:
import collections

N = int(input())
V = list(map(int, input().split()))
v1 = []
v2 = []
for i in range(N):
  if i % 2 == 0:
    v1.append(V[i])
  else:
    v2.append(V[i])
    
c1 = collections.Counter(v1)
c2 = collections.Counter(v2)

a1 = c1.most_common()
a2 = c2.most_common()

if a1[0][0] != a2[0][0]:
  print(len(V)-a1[0][1]-a2[0][1])
elif a1[0][1] > a2[0][1]:
  if len(a2) != 1:
    print(len(V)-a1[0][1]-a2[1][1])
  else:
    print(len(V)-a1[0][1])
else:
  if len(a1) != 1:
    print(len(V)-a1[1][1]-a2[0][1])
  else:
    print(len(V)-a2[0][1])

Submission status: Wrong Answer

Solution code:
#encoding utf-8

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

count={}
for i in range(len(v)):
    if v[i] in count.keys():
        count[v[i]] += 1
    else:
        count[v[i]] = 1

if len(count) == 1:
    print(int(n/2))
elif len(count) == 2:
    print(0)
else:
    for k, v in sorted(count.items(), key=lambda x: -x[1]):
        pass
    keys = list(count.keys())
    num = 0
    for i in range(2):
        num += int(count[keys[i]])
    print(n-num)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
c = 0
for i in range(n-2):
 if a[i] != a[i+2]:
  c += 1
print(c)

Submission status: Wrong Answer

Solution code:
n = int(input())

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

v_odd = {}
v_even = {}

for i in range(n):
    if i % 2 == 0:
        v = vs[i]
        if v in v_even:
            v_even[v] += 1
        else:
            v_even[v] = 1
    else:
        v = vs[i]
        if v in v_odd:
            v_odd[v] += 1
        else:
            v_odd[v] = 1

odd_sort = sorted(v_odd.items(), key=lambda x: -x[1])
even_sort = sorted(v_even.items(), key=lambda x: -x[1])

if odd_sort[0][0] == even_sort[0][0]:
    if len(odd_sort) >= 2:
        oddnext = odd_sort[1][1]
        if len(even_sort) >= 2:
            evennext = even_sort[1][1]
            ans = max(n-oddnext-even_sort[0][1], n-odd_sort[0][1]-evennext)
        else:
            ans = max(n-oddnext-even_sort[0][1], n-odd_sort[0][1])
    else:
        if len(even_sort) >= 2:
            evennext = even_sort[1][1]
            ans = max(n-odd_sort[0][1]-evennext, n-even_sort[0][1])
        else:
            ans = n // 2


else:
    ans = n - odd_sort[0][1] - even_sort[0][1]

print(ans)

Submission status: Wrong Answer

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

min_num = 0

even = {}
odd = {}

for i, v in enumerate(v_list):
    if i % 2 == 0:
        if v in even:
            even[v] += 1
        else:
            even[v] = 1
    else:
        if v in odd:
            odd[v] += 1
        else:
            odd[v] = 1

even_max = sorted(even.items(), key=lambda x: -x[1])[0][0]
odd_max = sorted(odd.items(), key=lambda x: -x[1])[0][0]

if odd_max == even_max:
    even_max = -1

for i, v in enumerate(v_list):
    if i % 2 == 0:
        if v != even_max:
            min_num += 1
    else:
        if v != odd_max:
            min_num += 1
print(min_num)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
v = list(map(int, input().split()))
gu = []
ki = []
ans = 0
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 = list(Counter(ki).values())
    guc = list(Counter(gu).values())
    while len(kic) != 1:
        ans += min(kic)
        del kic[kic.index(min(kic))]
    while len(guc) != 1:
        ans += min(guc)
        del guc[guc.index(min(guc))]

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n=input()
lists=input().split()
hi=[]
low=[]
for i in range(len(lists)):
    if(i%2==0):
        hi.append(lists[i])
    else:
        low.append(lists[i])
if(hi==low):
    print(len(hi))
    exit(0)
hi_counter=Counter(hi)
low_counter=Counter(low)
print(len(hi)-hi_counter.most_common()[0][1]+len(low)-low_counter.most_common()[0][1])

Submission status: Wrong Answer

Solution code:

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

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

    ans = 0

    if len(set(v[::2])) != 1:
        tmp = len(set(v[::2])) - 1
        ans += tmp

    if len(set(v[1::2])) != 1:
        tmp = len(set(v[1::2])) - 1
        ans += tmp

    print(ans)

if __name__ == "__main__":
        main()

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 v1 == v2:
    print(len(v1))

elif len(count1) == 1 and len(count2) == 1:
    print(0)

else:
    res = 0
    ct1 = list(count1.values())
    ct2 = list(count2.values())

    for i in range(len(ct1)):
        if i == 0:
            continue
        else:
            res = res + ct1[i]

    for i in range(len(ct2)):
        if i == 0:
            continue
        else:
            res = res + ct2[i]
    print(res)

Submission status: Wrong Answer

Solution code:
import math,sys

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

if len(list(set(v))) == 1:
	print(math.floor(n/2))
	sys.exit()

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

om = max(o)
em = max(e)

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

Submission status: Wrong Answer

Solution code:
import collections

n=int(input())
v=list(input().split())
k=v[0::2]
g=v[1::2]

c1 = collections.Counter(k)
c2 = collections.Counter(g)

res1 = n/2 - c1.most_common()[0][1]
res2 = n/2 - c2.most_common()[0][1]

if c1.most_common()[0][0] == c2.most_common()[0][0]:
    print(n/2)
else:
    print(res1+res2)

Submission status: Wrong Answer

Solution code:
import collections

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

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

A = collections.Counter(a).most_common()
B = collections.Counter(b).most_common()

sa, na = A[0]
sb, nb = B[0]
if sa == sb:
    if na == n // 2 and nb == n // 2:
        print(na)
    else:
        if na < nb:
            _, na = A[1]
            print(n - na - nb)
        else:
            _, nb = B[1]
            print(n - na - nb)
else:
    print(n - na - nb)

Submission status: Wrong Answer

Solution code:
n = int(input())
v = list(map(int,input().split()))
odd_first =[0,0]
odd_second = [0,0]
even_first = [0,0]
even_second = [0,0]

for i in range(1,10001):
    odd_num = v[::2].count(i)
    if odd_first[1] < odd_num:
        odd_second = odd_first
        odd_first = [i,odd_num]
    elif odd_second[1] < odd_num:
        odd_second = [i,odd_num]
    even_num = v[1::2].count(i)
    if even_first[1] < even_num:
        even_second = even_first
        even_first = [i,even_num]
    elif even_second[1] < even_num:
        even_second = [i,even_num]

if odd_first[0] == even_first[0]:
    ans_rev = max(odd_first[1]+even_second[1],odd_second[1]+even_first[1])
else:
    ans_rev = odd_first[1]+even_first[1]

print(n-ans_rev)

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

for i in range(a):
    c[b[i]-1] += 1

one = 0
two = 0

for i in range(d):
    if c[i] >= one:
        two = one
        one = c[i]

if a//2+1 > one and a//2+1 > two:
    print(a-one-two)
else:
    print(a-(one - a//2)-two)

Submission status: Wrong Answer

Solution code:
if __name__ == '__main__':                                                                                                                                                  
    n = int(input())
    vs = list(map(int, input().split()))

    even = vs[::2]
    odd = vs[1::2]

    from collections import Counter

    result = 0
    #evenの処理
    c = Counter(even)
    emode = c.most_common(1)[0][0]
    for i in range(len(even)):
        if even[i] != emode:
            result += 1

    c = Counter(odd)
    if c.most_common(1)[0][0] != emode:
        omode = c.most_common(1)[0][0]
    else:
        if len(c.most_common()) == 1:
            omode = -1
        else:
            omode = c.most_common(2)[0][0]


    for i in range(len(odd)):
        if odd[i] != omode:
            result += 1
    print(result)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
n=int(input())
v=[int(x) for x in input().split()]
if len(set(v))==1:
    print(n//2)
    import sys
    sys.exit()
from collections import Counter
v1=[]
v2=[]
for i in range(n):
    if i%2==0:
        v1.append(v[i])
    else:
        v2.append(v[i])
v1=Counter(v1)
v2=Counter(v2)
ans=10**10
# print(v1,v2)
for i1 in v1.most_common(min(len(v1),100)):
    for i2 in v2.most_common(min(len(v2),100)):
        # print(n-i1[1]-i2[1],i1,i2)
        ans=min(n-i1[1]-i2[1],ans)
print(ans)

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

try:
    evenmode = statistics.mode(even)
except:
    evenmode = v[0]    

try:
    oddmode = statistics.mode(odd)
except:
    oddmode = v[1]


evenchange = int(n/2) - even.count(evenmode)
oddchange = int(n/2) - odd.count(oddmode)
answer = evenchange + oddchange


if oddmode == evenmode:
    try:
        even2ndmode = even.most_common()[1][0]
        change2 = oddchange + int(n/2) - even.count(even2ndmode)
    except:
        change2 = oddchange + int(n/2)
        
    try:
        odd2ndmode = odd.most_common()[1][0]
        change1 = evenchange + int(n/2) - odd.count(odd2ndmode)
    except:
        change1 = evenchange + int(n/2)
     
    answer = min(change1,change2)

print(answer)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
from collections import defaultdict
from operator import itemgetter
def solve():
    n = int(input())
    V = list(map(int, input().split()))
    l = defaultdict(int)
    u = defaultdict(int)
    for i in range(0,n,2):
        l[V[i]] += 1
        u[V[i+1]] += 1

    l = sorted(list(l.items()),key=itemgetter(1))
    u = sorted(list(u.items()),key=itemgetter(1))
    if len(l) == len(u) == 1:
        if l[0][0] != u[0][0]:
            res = 0
        else:
            res = min(l[0][1], u[0][1])
    else:
        if l[0][0] != u[0][0]:
            res = sum(map(itemgetter(1), l[1:])) + sum(map(itemgetter(1), u[1:]))
        elif len(u) == 1 or (len(l) > 1 and l[1][1]+u[0][1] > l[0][1]+u[1][1]):
            res = l[0][1] + sum(map(itemgetter(1), l[2:])) + sum(map(itemgetter(1), u[1:]))
        else:
            res = u[0][1] + sum(map(itemgetter(1), l[1:])) + sum(map(itemgetter(1), u[2:]))

    return str(res)

if __name__ == '__main__':
    print(solve())

Submission status: Wrong Answer

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


def main():
    from collections import Counter

    n = int(input())
    v = sorted(Counter(list(map(int, input().split()))).items(), reverse=True)
    half = n // 2
    ans = 0

    if len(v) == 1:
        print(half)
        exit()
    else:
        for j in range(2):
            ans += abs(half - v[j][1])

        print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

odd_cnt = {}
even_cnt = {}

for i,vi in enumerate(vn):
    if i % 2 == 0:
        if vi in even_cnt:
            even_cnt[vi] += 1
        else:
            even_cnt[vi] = 1
    else:
        if vi in odd_cnt:
            odd_cnt[vi] += 1
        else:
            odd_cnt[vi] = 1

# print(even_cnt)
# print(odd_cnt)

even_max = 0
odd_max = 0
ans = 0
for k,v in even_cnt.items():
    ans += v
    if v > even_max:
        even_max = v

if even_cnt == odd_cnt:
    print(ans)
    exit()


for k,v in odd_cnt.items():
    ans += v
    if v > odd_max:
        odd_max = v

ans = ans - odd_max - even_max
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
import math

# K = int(input())
# N, K = map(int, input().split())
# A = list(map(int, input().split()))
# S = input() # String
# DP = np.zeros((N, Y), dtype=int)

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

Veven = []
Vodd = []

for i, v in enumerate(V):
    if i % 2 == 0:
        Veven.append(v)
    else:
        Vodd.append(v)


evD = dict()
for v in Veven:
    if v in evD:
        evD[v] += 1
    else:
        evD[v] = 1

maxV = 0
secMaxV = 0
maxEvK = None
for key, val in evD.items():
    if val == maxV:
        secMaxV = maxV
    if val > maxV:
        secMaxV = maxV
        maxV = val
        maxEvK = key

evenCost = int(N / 2) - maxV
if len(evD.items()) == 1:
    secEvenCost = int(N / 2)
else:
    secEvenCost = int(N / 2) - secMaxV

odD = dict()
for v in Vodd:
    if v in odD:
        odD[v] += 1
    else:
        odD[v] = 1

maxV = 0
maxOdK = key
for key, val in odD.items():
    if val == maxV:
        secMaxV = maxV
    if val > maxV:
        secMaxV = maxV
        maxV = val
        maxOdK = key

odCost = int(N / 2) - maxV
if len(evD.items()) == 1:
    secOdCost = int(N / 2)
else:
    secOdCost = int(N / 2) - secMaxV

# print(maxOdK)
# print(maxEvK)
if maxOdK is not maxEvK:
    print(evenCost + odCost)
else:
    # print(evenCost)
    # print(secOdCost)
    # print(secEvenCost)
    # print(odCost)
    bet = min(evenCost + secOdCost, secEvenCost + odCost)
    print(bet)

Submission status: Wrong Answer

Solution code:
import collections
n = int(int(input())/2)
a = list(map(int,input().split()))
o = []
e = []
for i in range(n):
  o.append(a[i*2])
  e.append(a[i*2+1])
o_c = collections.Counter(o)
e_c = collections.Counter(e)
o_most = o_c.most_common()[0][0]
o_num = o_c.most_common()[0][1]
e_most = e_c.most_common()[0][0]
e_num = e_c.most_common()[0][1]

ans = 0
if(o_most == e_most and o_num + e_num == n*2):
  ans = n
elif(o_most != e_most and o_num == n and e_num == n):
  ans = 0
else:
  if(o_num == e_num):
    if(len(o_c.most_common()) == 1):
      e_num = e_c.most_common()[1][1]
    elif(len(e_c.most_common()) == 1):
      o_num = o_c.most_common()[1][1]
    else:
      e_t = e_c.most_common()[1][1]
      o_t = o_c.most_common()[1][1]
      if(o_num - o_t <= e_num - e_t):
        o_num = o_t
      else:
        e_num = e_t

  ans = n*2 - o_num - e_num

print(ans)

Submission status: Wrong Answer

Solution code:
import collections

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

evel = collections.Counter()
odd = collections.Counter()
for index, v in enumerate(V):
    if index % 2 == 0:
        evel[v] += 1
    else:
        odd[v] += 1


if evel == odd:
    print(int(n / 2))
else:
    if evel.most_common()[0][0] == odd.most_common()[0][0]:
        if evel.most_common()[0][1] > odd.most_common()[0][1]:
            ans = int(n / 2) - evel.most_common()[0][1] + int(n / 2) - odd.most_common()[1][1]
        else:
            ans = int(n / 2) - evel.most_common()[1][1] + int(n / 2) - odd.most_common()[0][1]
    else:
        ans = int(n / 2) - evel.most_common()[0][1] + int(n / 2) - odd.most_common()[0][1]
    print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
from operator import itemgetter

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

c0 = Counter(v)
if len(c0.values()) == 1:
    ans = n // 2
else:
    c1 = Counter(v[::2])
    c2 = Counter(v[1::2])

    x1 = sorted(c1.items(), reverse=True, key=itemgetter(1))
    x2 = sorted(c2.items(), reverse=True, key=itemgetter(1))

    ans = 0
    if x1[0][0] == x2[0][0]:
        if x1[0][1] < x2[0][1]:
            ans += x1[0][1]
            for _, v in x1[2:] + x2[1:]:
                ans += v
        else:
            ans += x2[0][1]
            for _, v in x2[2:] + x1[1:]:
                ans += v
    else:
        for _, v in x1[1:] + x2[1:]:
            ans += v
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
d={}
sum=0
maxs=-9999
maxs2=-9999
d[maxs]=d[maxs2]=0
for i in a:
    if i in d:
        d[i]+=1
        if d[i]>d[maxs] and i!=maxs:
            maxs2=maxs
            maxs=i
            continue
        if  d[i]>d[maxs2] and i!=maxs and i!=maxs2:
            maxs2=i
    else:
        d[i]=1
        sum+=1
        if d[i]>d[maxs] and i!=maxs:
            maxs2=maxs
            maxs=i
            continue
        if d[i]>d[maxs2] and i!=maxs and i!=maxs2:
            maxs2=i
if sum>2:
    if d[maxs]>n/2:
        print(int(n  - d[maxs2]+d[maxs]-n/2))
    else:
        print(int(n-d[maxs]-d[maxs2]))
elif sum==2:
    print(int(n/2-d[maxs2]))
else:
    print(int(n/2))

Submission status: Wrong Answer

Solution code:
import collections

inLen = int(input())
inputs =  list(map(int, input().split()))

evenDict = collections.Counter(inputs[0::2])
oddDict = collections.Counter(inputs[1::2])

evenMost = evenDict.most_common(1)
oddMost = oddDict.most_common(1)


if(evenMost[0][0] != oddMost[0][0]):
    print(inLen - evenMost[0][1] - oddMost[0][1])
else:
    if(evenMost[0][1] < oddMost[0][1]):
        print(inLen - evenMost[1][1] - oddMost[0][1])
    elif (evenMost[0][1] > oddMost[0][1]):
        print(inLen - evenMost[0][1] - oddMost[1][1])
    else:
        print(int(inLen / 2))