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

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

evens = defaultdict(lambda: 0)
odds = defaultdict(lambda: 0)
for i in range(0, n, 2):
    evens[numbers[i]] += 1
    odds[numbers[i + 1]] += 1

evens = list(evens.items())
odds = list(odds.items())

evens.sort(key=lambda pair: pair[1], reverse=True)
odds.sort(key=lambda pair: pair[1], reverse=True)

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

if len(evens) == 1 or len(odds) == 1:
    pairs = evens if len(evens) > len(odds) else odds
    if evens[0][0] == odds[0][0]:
        del pairs[1]
    else:
        del pairs[0]
    print(sum([v for _, v in pairs]))
    exit()

if evens[0][0] == odds[0][0]:
    if evens[0][1] > odds[0][1]:
        del evens[0]
        del odds[1]
    else:
        del evens[1]
        del odds[0]
else:
    del evens[0]
    del odds[0]
print(sum([v for _, v in evens]) + sum([v for _, v in odds]))

Submission status: Wrong Answer

Solution code:
import collections
N=int(input())
L=list(map(int,input().split()))
E=[i for i in L[::2]]
O=[i for i in L[1::2]]
e = collections.Counter(E)
o = collections.Counter(O)
e1=e.most_common()[0][1]
e2=e.most_common()[-1][1]
o1=o.most_common()[0][1]
o2=o.most_common()[-1][1]

Ans=[N-e1-o2,N-e2-o1,N-e2-o2,N-o1-e1]

if len(set(L))==1:
  print(N//2)
else:
  print(min(Ans))

Submission status: Wrong Answer

Solution code:
import collections
N=int(input())
L=list(map(int,input().split()))
E=[i for i in L[::2]]
O=[i for i in L[1::2]]
e = collections.Counter(E)
o = collections.Counter(O)
e1=e.most_common()[0][1]
e2=e.most_common()[-1][1]
o1=o.most_common()[0][1]
o2=o.most_common()[-1][1]

Ans=[N-e1-o2,N-e2-o1,N-e1-o1]

if len(set(L))==1:
  print(N//2)
else:
  print(min(Ans))

Submission status: Wrong Answer

Solution code:
import collections
N=int(input())
L=list(map(int,input().split()))
E=[i for i in L[::2]]
O=[i for i in L[1::2]]
e = collections.Counter(E)
o = collections.Counter(O)
e1=e.most_common()[0][1]
e2=e.most_common()[-1][1]
o1=o.most_common()[0][1]
o2=o.most_common()[-1][1]

Ans=[N-e1-o2,N-e2-o1]

if len(set(L))==1:
  print(N//2)
else:
  print(min(Ans))

Submission status: Wrong Answer

Solution code:
import collections

n = int(input())
value = input().split()


  
odd = [int(value[i]) for i in range(n) if i % 2]
even = [int(value[i]) for i in range(n) if not i % 2]

odd_c = collections.Counter(odd)
even_c = collections.Counter(even)

freq_odd = odd_c.most_common()
freq_even = even_c.most_common()

if freq_odd == freq_even:
  freq = len(odd)
elif freq_odd[0][0] != freq_even[0][0]:
  freq = freq_odd[0][1] + freq_even[0][1]
elif freq_odd[1][0] != freq_even[0][0]:
  freq = freq_odd[1][1] + freq_even[0][1]
elif freq_odd[0][0] != freq_even[1][0]:
  freq = freq_odd[0][1] + freq_even[1][1]
print(n - freq)

Submission status: Wrong Answer

Solution code:
from collections import deque

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

for i in range(n//2):
    if not v[i*2] in even:
        even.append(v[i*2])
for i in range(n//2):
    if not v[i*2+1] in odd:
        odd.append(v[i*2+1])

num2=0
second2=0
for p in even:
    num=0
    for i in range(n//2):
        if p==v[i*2]:
            num+=1
    if num>num2:
        num2=num
        max2=p
    elif num>second2:
        second2=num

num3=0
second3=0
for p in odd:
    num=0
    for i in range(n//2):
        if p==v[i*2+1]:
            num+=1
    if num>num3:
        num3=num
        max3=p
    elif num>second3:
        second3=num3

if max2==max3 and len(even)==1 and len(odd)==1:
    print(n-num2)
elif max2==max3:
    print(min(n-num2-second3,n-num3-second2))
else:
    print(n-num2-num3)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
lst = [x for x in input().split()]

lst1 = Counter(lst[0::2]).most_common()
lst2 = Counter(lst[1::2]).most_common()

if lst1[0][0] != lst2[0][0]:
    print(n - lst1[0][1] - lst2[0][1])
else:
    if len(lst1) == 2 or len(lst2) == 2:
        a = n - lst1[1][1] - lst2[0][1]
        b = n - lst1[0][1] - lst2[1][1]
        print(n - max(a, b))
    else:
        print(n // 2)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
lst = [x for x in input().split()]

lst1 = Counter(lst[0::2]).most_common()
lst2 = Counter(lst[1::2]).most_common()

if lst1[0][0] != lst2[0][0]:
    print(n - lst1[0][1] - lst2[0][1])
else:
    if len(lst1) == 2 or len(lst2) == 2:
        a = n - lst1[1][1] - lst2[0][1]
        b = n - lst1[0][1] - lst2[1][1]
        print(min(a, b))
    else:
        print(n // 2)

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
v = list(map(int, input().split()))
ans = 0
c = collections.Counter(v)
if c.most_common()[0][1] <= n // 2 and len(c) != 1:
    ans = n - c.most_common()[0][1] - c.most_common()[1][1]
else:
    ans += c.most_common()[0][1] - n // 2
print(ans)

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
v = list(map(int, input().split()))
ans = 0
c = collections.Counter(v)
if c.most_common()[0][1] > n // 2:
    ans += c.most_common()[0][1] - n // 2
if len(c) != 1:
    ans += n - c.most_common()[0][1] - c.most_common()[1][1]
print(ans)

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
v = list(map(int, input().split()))
ans = 0
c = collections.Counter(v)
if c.most_common()[0][1] > n // 2:
    ans += c.most_common()[0][1] - n // 2
else:    
    ans += n - c.most_common()[0][1] - c.most_common()[1][1]
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
dic1=defaultdict(int)
dic2=defaultdict(int)
n=int(input())
l=list(map(int,input().split()))
for i in range(0,n-1,2):
  dic1[l[i]]+=1
for i in range(1,n,2):
  dic2[l[i]]+=1
max11=0
i1=0
max12=0
max21=0
i3=0
max22=0
for i in dic1:
  if dic1[i]>=max11:
    max12=max11
    max11=dic1[i]
    i1=i
  elif dic1[i]>max12:
    max12=dic1[i]
for i in dic2:
  if dic2[i]>=max21:
    max22=max21
    max21=dic2[i]
    i3=i
  elif dic2[i]>max22:
    max22=dic1[i]
if i1!=i3:
  print(n-max11-max21)
elif i1==i3:
  print(min(n-max11-max22,n-max21-max12))

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
dic1=defaultdict(int)
dic2=defaultdict(int)
n=int(input())
l=list(map(int,input().split()))
if n%2==0:
  for i in range(0,n-1,2):
    dic1[l[i]]+=1
  for i in range(1,n,2):
    dic2[l[i]]+=1
  max11=0
  i1=0
  max12=0
  i2=0
  max21=0
  i3=0
  max22=0
  i4=0
  for i in dic1:
    if dic1[i]>=max11:
      max12=max11
      max11=dic1[i]
      i2=i1
      i1=i
    elif dic1[i]>max12:
      max12=dic1[i]
      i2=i
  for i in dic2:
    if dic2[i]>=max21:
      max22=max21
      max21=dic2[i]
      i4=i3
      i3=i
    elif dic2[i]>max22:
      max22=dic1[i]
      i4=i
  if i1!=i3:
    print(n-max11-max21)
  elif i1==i3:
    print(min(n-max11-max22,n-max21-max12))

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
dic1=defaultdict(int)
dic2=defaultdict(int)
n=int(input())
l=list(map(int,input().split()))
if n%2==0:
  for i in range(0,n-1,2):
    dic1[l[i]]+=1
  for i in range(1,n,2):
    dic2[l[i]]+=1
  max11=0
  i1=0
  max12=0
  i2=0
  max21=0
  i3=0
  max22=0
  i4=0
  for i in dic1:
    if dic1[i]>max11:
      max12=max11
      max11=dic1[i]
      i2=i1
      i1=i
    elif dic1[i]>max12:
      max12=dic1[i]
      i2=i
  for i in dic1:
    if dic1[i]>max11:
      max12=max11
      max11=dic1[i]
      i4=i3
      i3=i
    elif dic1[i]>max12:
      max12=dic1[i]
      i4=i
  if i1!=i3:
    print(n-max11-max21)
  elif l1==l3:
    print(min(n-max11-max22,n-max21-max12))

Submission status: Wrong Answer

Solution code:
n = int(input())
ls = [int(i) for i in input().split()]


from collections import defaultdict
d1 = defaultdict(int)
d2 = defaultdict(int)

for i in range(n):
    if i%2==0:
        d1[ls[i]]+=1
    else:
        d2[ls[i]]+=1


d1=sorted(d1.items())
d2=sorted(d2.items())


if d1[0][0] != d2[0][0]:
    print(n-d1[0][1]-d2[0][1])
else:
    if len(d1)==1 and len(d2)==1:
        print(min(n-d1[0][1],n-d2[0][1]))
    elif len(d1)==1 and len(d2)==2:
        print(min(n-d1[0][1]-d2[1][1],n-d2[0][1]))
    elif len(d1)==2 and len(d2)==1:
        print(min(n-d1[1][1]-d2[0][1],n-d1[0][1]))
    else:
        print(min(n-d1[1][1]-d2[0][1],n-d1[0][1]-d2[1][1]))

Submission status: Wrong Answer

Solution code:
n = int(input())
ls = [int(i) for i in input().split()]


from collections import defaultdict
d1 = defaultdict(int)
d2 = defaultdict(int)

for i in range(n):
    if i%2==0:
        d1[ls[i]]+=1
    else:
        d2[ls[i]]+=1


d1=sorted(d1.items())
d2=sorted(d2.items())


if d1[0][0] != d2[0][0]:
    print(n-d1[0][1]-d2[0][1])
else:
    try:
        print(min(n-d1[1][1]-d2[0][1],n-d1[0][1]-d2[1][1]))
    except:
        print(min(n-d1[0][1],n-d2[0][1]))

Submission status: Wrong Answer

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

c = collections.Counter(v)
if len(c) == 1:
    print(n // 2)
else:
    print(n-(c.most_common()[0][1] + c.most_common()[1][1]))

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
dat_a = list(map(int, input().split()))
c = collections.Counter(dat_a)
cc = c.most_common(2)
c1_1 = c1_2 = c2_1 = c2_2 = 0
if len(cc) == 1:
    print(n//2)
else:
    for i in range(n):
        if i % 2 == 0:
            if dat_a[i] == cc[0][0]:
                c1_1 += 1
        else:
            if dat_a[i] == cc[1][0]:
                c1_2 += 1

    for i in range(n):
        if i % 2 == 1:
            if dat_a[i] == cc[0][0]:
                c2_1 += 1
        else:
            if dat_a[i] == cc[1][0]:
                c2_2 += 1

    import math
    if (c1_1 + c1_2) >= (c2_1 + c2_2):
        print( math.ceil(n/2) - c1_1 + math.ceil(n//2) - c1_2)
    else:
        print( math.ceil(n/2) - c2_1 + math.ceil(n//2) - c2_2)

Submission status: Wrong Answer

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

from collections import Counter

v = list(set(V))

if len(v)==1:
    print(n//2)
else:
    even = [V[2*i] for i in range(n//2)]
    odd = [V[2*j+1] for j in range(n//2)]
    e = Counter(even).most_common()
    o = Counter(odd).most_common()
    
    print(n-e[0][1]-o[0][1])

Submission status: Wrong Answer

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

from collections import Counter

even = [V[2*i] for i in range(n//2)]
odd = [V[2*j+1] for j in range(n//2)]

v = Counter(V).most_common()
e = Counter(even).most_common()
o = Counter(odd).most_common()

if len(v)==1:
    print(n//2)
else:
    E = sum([e[1:][i][1] for i in range(len(e)-1)])
    O = sum([o[1:][j][1] for j in range(len(o)-1)])
    print(E+O)

Submission status: Wrong Answer

Solution code:
def count_nums(v):
    counter = {}
    for x in v:
        if x not in counter:
            counter[x] = 0
        counter[x] += 1
    retval = list(counter.items())
    retval.sort(lambda a: a[1])
    # i : index
    # retval[i][0] : number
    # retval[i][1] : count
    # retval is sorted by count
    return retval


def main():
    n = int(input())
    v = list(map(int, input().split()))
    v1 = v[::2]
    v2 = v[1::2]

    cv1 = count_nums(v1)
    cv2 = count_nums(v2)

    if cv1[0][0] != cv2[0][0]:
        print(n - (cv1[0][1] + cv2[0][1]))
    elif len(cv1) == 1 and len(cv2) == 1:
        print(len(v2))
    elif len(cv1) == 1:
        print(len(v2) - cv2[1][1])
    elif len(cv2) == 1:
        print(len(v1) - cv1[1][1])
    else:
        print(n - max(cv1[0][1]+cv2[1][1], cv1[1][1]+cv2[0][1]))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from collections import Counter


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


lst_o = lst_v[::2]
lst_e = lst_v[1::2]
cnt_o = Counter(lst_o).most_common() + [(0, 0)]
cnt_e = Counter(lst_e).most_common() + [(0, 0)]
print(cnt_o)
print(cnt_e)

if cnt_o[0][0] == cnt_e[0][0]:
    rem_number = max(cnt_o[0][1] + cnt_e[1][1], cnt_o[1][1] + cnt_e[0][1])
else:
    rem_number = cnt_o[0][1] + cnt_e[0][1]
ans = n - rem_number


print(ans)

Submission status: Wrong Answer

Solution code:
#################################
#配列を二つに分ける
#引数
# values: 配列
# a,b   : 配列の格納先
#戻り値
# なし
#################################
def separate(values,a,b):
    for v in values:
        a.append(v)
        a,b = b,a


##############################
#登場回数の多い数と登場回数を返す
#引数
# values: ソートされた配列
#戻り値
# 辞書型配列
##############################
def getCount(values):
    currentNum=0
    currentCount=0
    ret={'First' :{'Num':[],'Cnt':0},
         'Second':{'Num':[],'Cnt':0}}
    for v in values:
        if v==currentNum:
            currentCount+=1
        else:
            #別の数字が表れた場合
            if ret['First']['Cnt'] < currentCount:
                #最大値より大きい場合、それが新たな最大値になる
                ret['Second']=ret['First'].copy()
                ret['First']={'Num':[currentNum],'Cnt':currentCount}
            elif ret['First']['Cnt'] == currentCount:
                #最大値タイ
                ret['First']['Num'].append(currentNum)
            elif ret['Second']['Cnt'] < currentCount:
                #2番目より大きい場合、それが新たな2番目になる。
                ret['Second']={'Num':[currentNum],'Cnt':currentCount}
            elif ret['Second']['Cnt'] == currentCount:
                #2位タイ
                ret['Second']['Num'].append(currentNum)

            currentNum=v
            currentCount=1

    #配列の最後まで来た場合
    if ret['First']['Cnt'] < currentCount:
        ret['Second']=ret['First'].copy()
        ret['First']={'Num':[currentNum],'Cnt':currentCount}
    elif ret['First']['Cnt'] == currentCount:
        ret['First']['Num'].append(currentNum)
    elif ret['Second']['Cnt'] < currentCount:
        ret['Second']={'Num':[currentNum],'Cnt':currentCount}
    elif ret['Second']['Cnt'] == currentCount:
        ret['Second']['Num'].append(currentNum)

    return ret


#############################
# メイン
#############################
vars = input ()
a=[]
b=[]
varArray=vars.split(" ")
separate(varArray,a,b)
a.sort()
b.sort()
a_result=getCount(a)
b_result=getCount(b)
if (len(a_result['First']['Num'])>1 or
    len(b_result['First']['Num'])>1):
    #最頻値が複数ある場合は素直に計算可
    xa=len(a)-a_result['First']['Cnt']
    xb=len(b)-b_result['First']['Cnt']
    x=xa+xb
else:
    #abどちらも最頻値が1種類の場合
    if a_result['First']['Num'][0]!=b_result['First']['Num'][0]:
        #abの最頻値が異なる場合は素直に計算可
        xa=len(a)-a_result['First']['Cnt']
        xb=len(b)-b_result['First']['Cnt']
        x=xa+xb
    else:
        #abの最頻値が同じ値の場合、どちらかは2番目の値を採用する必要あり
        xaa=len(a)-a_result['First']['Cnt']
        xab=len(b)-b_result['Second']['Cnt']
        xa=xaa+xab
        xba=len(a)-a_result['Second']['Cnt']
        xbb=len(b)-b_result['First']['Cnt']
        xb=xba+xbb
        x=xa if xa<xb else xb

print(x)

Submission status: Wrong Answer

Solution code:
# i=2からみてi-2と同じになればいい
# 偶数番目と奇数番目が同じが最終形態なので、実際にみて、登場回数の少ないものを書き換える
n = int(input())
s = list(map(int, input().split()))
o, e = dict(), dict()
for i in range(n):
    if i % 2 == 0:
        if s[i] in o:
            o[s[i]] += 1
        else:
            o[s[i]] = 1
    else:
        if s[i] in e:
            e[s[i]] += 1
        else:
            e[s[i]] = 1

if len(o) == 1 and len(e) == 1:
    if o.keys() == e.keys():
        print(n // 2)
    else:
        print(0)
else:
    o = list(sorted(o.items(), key=lambda x: x[1], reverse=True))
    e = list(sorted(e.items(), key=lambda x: x[1], reverse=True))
    if len(o) == 1:
        if o[0][0] == e[0][0]:
            print(n // 2 - e[1][0])
        else:
            print(n // 2 - e[0][0])
    elif len(e) == 1:
        if e[0][0] == o[0][0]:
            print(n // 2 - o[1][0])
        else:
            print(n // 2 - o[0][0])
    else:
        print(min(n // 2 - e[0][0], n // 2 - o[0][0]))

Submission status: Wrong Answer

Solution code:

import collections
n = int(input())
m = n // 2
num_list = [ int(v) for v in input().split() ]

odd_list = num_list[1::2]
even_list = num_list[::2]



odd_container = collections.Counter(odd_list)
even_container = collections.Counter(even_list)

if len(odd_container) == 1 and len(even_container) == 1:
    odd_top = odd_container.most_common(1)
    even_top = even_container.most_common(1)
    odd_top, even_top = odd_top[0], even_top[0]

    if odd_top[0] == even_top[0]: 
        ans = m
    else:
        ans = 0
elif len(odd_container) == 1:
    odd_top = odd_container.most_common(1)
    even_top, even_sec = even_container.most_common(2)
    odd_top = odd_top[0]
    if odd_top[0] != even_top[0]:
        ans = m - even_top[1]
    else:
        ans = m - even_sec[1]

elif len(even_container) == 1:
    even_top = even_container.most_common(1)
    odd_top, odd_sec = odd_container.most_common(2)
    even_top = even_top[0]
    if odd_top[0] != even_top[0]:
        ans = m - odd_top[1]
    else:
        ans = m - odd_sec[1]

else:
    odd_top, odd_sec = odd_container.most_common(2)
    even_top, even_sec = even_container.most_common(2)
    if odd_top[0] != even_top[0]:
        ans = n - odd_top[1] - even_top[1]
    else:
        if odd_top[1] >= even_top[1]:
            ans = n - odd_top[1] - even_sec[1]
        else:
            ans = n - even_top[1] - odd_sec[1]

print(ans)

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
m = n // 2
num_list = [ int(v) for v in input().split() ]

odd_list = num_list[1::2]
even_list = num_list[::2]



odd_container = collections.Counter(odd_list)
even_container = collections.Counter(even_list)

if len(odd_container) == 1 and len(even_container) == 1:
    odd_top = odd_container.most_common(1)
    even_top = even_container.most_common(1)
    odd_top, even_top = odd_top[0], even_top[0]
    print(even_top,odd_top)
    if odd_top[0] == even_top[0]: 
        ans = m
    else:
        ans = 0
elif len(odd_container) == 1:
    odd_top = odd_container.most_common(1)
    even_top, even_sec = even_container.most_common(2)
    odd_top = odd_top[0]
    if odd_top[0] != even_top[0]:
        ans = m - even_top[1]
    else:
        ans = m - even_sec[1]

elif len(even_container) == 1:
    even_top = even_container.most_common(1)
    odd_top, odd_sec = odd_container.most_common(2)
    even_top = even_top[0]
    if odd_top[0] != even_top[0]:
        ans = m - odd_top[1]
    else:
        ans = m - odd_sec[1]

else:
    odd_top, odd_sec = odd_container.most_common(2)
    even_top, even_sec = even_container.most_common(2)
    if odd_top[0] != even_top[0]:
        ans = n - odd_top[1] - even_top[1]
    else:
        if odd_top[1] >= even_top[1]:
            ans = n - odd_top[1] - even_sec[1]
        else:
            ans = n - even_top[1] - odd_sec[1]

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter


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


if len(set(lst_v)) == 1:
    ans = n // 2
else:
    lst_odd = [lst_v[i] for i in range(n) if i%2==0]
    lst_even = [lst_v[i] for i in range(n) if i%2!=0]


    cnt_odd = list(Counter(lst_odd).values())
    cnt_even = list(Counter(lst_even).values())


    ans = sum(cnt_odd) - max(cnt_odd) + sum(cnt_even) - max(cnt_even)


print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter


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


if len(set(lst_v)) == 1:
    ans = n // 2
else:
    lst_odd = [lst_v[i] for i in range(n) if i%2==0]
    lst_even = [lst_v[i] for i in range(n) if i%2!=0]
    print(lst_odd)
    print(lst_even)


    cnt_odd = list(Counter(lst_odd).values())
    cnt_even = list(Counter(lst_even).values())
    print(cnt_odd)
    print(cnt_even)

    ans = sum(cnt_odd) - max(cnt_odd) + sum(cnt_even) - max(cnt_even)


print(ans)

Submission status: Wrong Answer

Solution code:
import collections 

n = int(input())
lst = list(map(int,input().split()))
lst_mode_odd = collections.Counter(lst[::2]).most_common()
l_odd = len(lst_mode_odd)
n_odd = lst_mode_odd[0][1]
num_odd = lst_mode_odd[0][0]
lst_mode_even = collections.Counter(lst[::-2]).most_common()
l_even = len(lst_mode_even)
n_even = lst_mode_even[0][1]
num_even = lst_mode_even[0][0]
if l_odd == l_even ==1 and num_odd == num_even:
    print(int(len(lst)/2))
    exit()
if num_odd == num_even:
    if n_odd > n_even:
        n_even = lst_mode_even[1][1]
    elif n_odd < n_even:
        n_odd = lst_mode_odd[1][1]
    else:
        n_odd_2nd = lst_mode_odd[1][1]
        n_even_2nd = lst_mode_even[1][1]
        if n_odd_2nd >= n_even_2nd:
            n_even =  lst_mode_even[1][1]
        else:
            n_odd =  lst_mode_odd[1][1]
ans = len(lst) - n_odd -n_even
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
N=int(input())
p=N//2
L=list(map(int,input().split()))
print(p if len(set(L))==1 else p-(Counter(L[::2]).most_common()[0][1])+p-(Counter(L[1::2]).most_common()[0][1]))

Submission status: Wrong Answer

Solution code:
from collections import Counter
N=int(input())
L=list(map(int,input().split()))
print(N//2 if len(set(L))==1 else (N//2)-(Counter(L[::2]).most_common()[0][1])+(N//2)-(Counter(L[1::2]).most_common()[0][1]))

Submission status: Wrong Answer

Solution code:
from collections import Counter
N=int(input())
L=list(map(int,input().split()))
print(N//2 if sum(L)//N==L[0] else (N//2)-(Counter(L[::2]).most_common()[0][1])+(N//2)-(Counter(L[1::2]).most_common()[0][1]))

Submission status: Wrong Answer

Solution code:
from collections import Counter
N=int(input())
L=list(map(int,input().split()))
print(N//2 if sum(L)/N==L[0] else (N//2)-(Counter(L[::2]).most_common()[0][1])+(N//2)-(Counter(L[1::2]).most_common()[0][1]))

Submission status: Wrong Answer

Solution code:
from collections import Counter
n=int(input())
nums=list(map(int,input().split()))
a=set(nums)
if len(a)==1:
  print(n//2)
else:
  odd=nums[::2]
  even=nums[1::2]
  o=Counter(odd)
  e=Counter(even)
  ans=n-o.most_common()[0][1]-e.most_common()[0][1]
  if o.most_common()[0][0]==e.most_common()[0][0]:
    print(ans+min(o.most_common()[1][1]-o.most_common()[0][1],e.most_common()[1][1]-e.most_common()[0][1]))
  else:  
    print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n=int(input())
nums=list(map(int,input().split()))
a=set(nums)
if len(a)==1:
  print(n//2)
else:
  odd=nums[::2]
  even=nums[1::2]
  o=Counter(odd)
  e=Counter(even)
  print(n-o.most_common()[0][1]-e.most_common()[0][1])

Submission status: Wrong Answer

Solution code:
from collections import Counter
n=int(input())
nums=list(map(int,input().split()))
a=set(nums)
if len(a)==1:
  print(n//2)
else:
  odd=nums[::2]
  even=nums[1::2]
  o=Counter(odd)
  e=Counter(even)
  print(n-o.most_common()[0][0]-e.most_common()[0][0])

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
v = input().split()
cnt = list(Counter(v).values())
print(int(n/2) if len(cnt) == 1 else len(cnt) - 2)

Submission status: Wrong Answer

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

d = {s:0 for s in set(v)}
for i in v:
  d[i] += 1
if len(d) == 1:
  print(n//2)
else:
  top2 = sorted(d.items(),key=lambda x:-x[1])[:2]
  a,b = top2[0][0],top2[1][0]
  base = [i%2 for i in range(n)]
  alist = np.array([a if i else b for i in base])
  blist = np.array([b if i else a for i in base])
  print(n-max(sum(alist == v),sum(blist == v)))

Submission status: Wrong Answer

Solution code:
import collections

n=int(input())
v=list(map(int,input().split()))
v1=collections.Counter(v[0::2]).most_common()
v2=collections.Counter(v[1::2]).most_common()

if len(set(v)) == 1:
    ans=len(v[1::2])
else:
    if len(v1)==1:
        v1.append((0,0))
    if len(v2)==1:
        v2.append((0,0))
    ans=min(len(v) - v1[0][1] - v2[0][1],len(v) - v1[0][1] - v2[1][1],len(v) - v1[1][1] - v2[0][1])

print(ans)

Submission status: Wrong Answer

Solution code:
import collections

n=int(input())
v=list(map(int,input().split()))
v1=collections.Counter(v[0::2])
v2=collections.Counter(v[1::2])

if len(set(v)) == 1:
    ans=len(v[1::2])
elif v1.most_common()[0][0] == v2.most_common()[0][0]:
    if len(v1.most_common())==1 and len(v2.most_common())>=2:
        ans = len(v) - v1.most_common()[0][1] - v2.most_common()[1][1]
    elif len(v1.most_common())>=2 and len(v2.most_common())>=1:
        ans = len(v) - v1.most_common()[1][1] - v2.most_common()[0][1]
    elif v1.most_common()[0][1]-v1.most_common()[1][1] >= v2.most_common()[0][1]-v2.most_common()[1][1]:
        ans = len(v) - v1.most_common()[0][1] - v2.most_common()[1][1]
    else:
        ans = len(v) - v1.most_common()[1][1] - v2.most_common()[0][1]
else:
    ans= len(v) - v1.most_common()[0][1] - v2.most_common()[0][1]

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
ls = [int(i) for i in input().split()]


from collections import defaultdict
d1 = defaultdict(int)
d2 = defaultdict(int)

for i in range(n):
    if i%2==0:
        d1[ls[i]]+=1
    else:
        d2[ls[i]]+=1


d1=sorted(d1.items(),reverse=True)
d2=sorted(d2.items(),reverse=True)


if d1[0][0] != d2[0][0]:
    print(n-d1[0][1]-d2[0][1])
else:
    try:
        print(min(n-d1[1][1]-d2[0][1],n-d1[0][1]-d2[1][1]))
    except:
        print(min(n-d1[0][1],n-d2[0][1]))

Submission status: Wrong Answer

Solution code:
n = int(input())
ls = [int(i) for i in input().split()]


from collections import defaultdict
d1 = defaultdict(int)
d2 = defaultdict(int)

for i in range(n):
    if i%2==0:
        d1[ls[i]]+=1
    else:
        d2[ls[i]]+=1


d1=sorted(d1.items(),reverse=True)
d2=sorted(d2.items(),reverse=True)


if d1[0][0] != d2[0][0]:
    print(n-d1[0][1]-d2[0][1])
else:
    try:
        print(min(n-d1[1][1]-d2[0][1],n-d1[0][1]-d2[1][1]))
    except:
        print(n-d1[0][1])

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
v = list(map(int,input().split()))
v1 = v[::2]
v2 = v[1::2]
count1 = Counter(v1)
count2 = Counter(v2)
mode1_list = count1.most_common()
mode2_list = count2.most_common()

if mode1_list[0][0] == mode2_list[0][0]:
    if mode1_list[0][1] > mode2_list[0][1]:
        mode1 = mode1_list[0][1]
        mode2 = 0
    else:
        mode1 = 0
        mode2 = mode2_list[0][1]
else:
    mode1 = mode1_list[0][1]
    mode2 = mode2_list[0][1]

result = len(v1) - mode1 + len(v2) -mode2
print(result)

Submission status: Wrong Answer

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

for i in range(int(len(v)/2)):
    if (v[i] != v[i+2]) : count = count +1

print(count)

Submission status: Wrong Answer

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

def LI(): return list(map(int,input().split()))
def I(): return int(input())
def LS(): return input().split()
def S(): return input()

def main():
  n=I()
  l=LI()

  l1=[]
  l2=[]

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

  l1.sort()
  l2.sort()

  a=[]
  b=[]

  p=l1[0]
  c=1
  mx=1
  for x in l1[1:]:
    if x==p:
      c+=1
    else:
      a.append([p,c])
      c=1
      p=x
  a.append([p,c])

  p=l2[0]
  c=1
  mx=1
  for x in l2[1:]:
    if x==p:
      c+=1
    else:
      b.append([p,c])
      c=1
      p=x
  b.append([p,c])

  a=sorted(a,key=lambda x:x[1],reverse=True)
  b=sorted(b,key=lambda x:x[1],reverse=True)

  if a[0][0]==b[0][0]:
    if len(a)==1 and len(b)==1:
      return n//2
    if a[0][1]<=b[0][1]:
      return n-a[1][1]-b[0][1]
    return n-a[0][1]-b[1][1]
  return n-a[0][1]-b[0][1]

print(main())

Submission status: Wrong Answer

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

def LI(): return list(map(int,input().split()))
def I(): return int(input())
def LS(): return input().split()
def S(): return input()

def main():
  n=I()
  l=LI()

  l1=[]
  l2=[]

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

  l1.sort()
  l2.sort()

  a=[]
  b=[]

  p=l1[0]
  c=1
  mx=1
  for x in l1[1:]:
    if x==p:
      c+=1
    else:
      a.append([p,c])
      c=1
      p=x
  a.append([p,c])

  p=l2[0]
  c=1
  mx=1
  for x in l2[1:]:
    if x==p:
      c+=1
    else:
      b.append([p,c])
      c=1
      p=x
  b.append([p,c])

  a=sorted(a,key=lambda x:x[1],reverse=True)
  b=sorted(b,key=lambda x:x[1],reverse=True)

  if a[0][0]==b[0][0]:
    if len(a)==1 and len(b)==1:
      return n//2
    if a[0][1]<b[0][1]:
      return n-a[1][1]-b[0][1]
    else:
      return n-a[0][1]-b[1][1]
  else:
    return n-a[0][1]-b[0][1]

print(main())

Submission status: Wrong Answer

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

def LI(): return list(map(int,input().split()))
def I(): return int(input())
def LS(): return input().split()
def S(): return input()

def main():
  n=I()
  l=LI()

  l1=[]
  l2=[]

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

  l1.sort()
  l2.sort()

  a=[]
  b=[]

  p=l1[0]
  c=1
  mx=1
  for x in l1[1:]:
    if x==p:
      c+=1
    else:
      a.append([p,c])
      c=1
      p=x
  a.append([p,c])

  p=l2[0]
  c=1
  mx=1
  for x in l2[1:]:
    if x==p:
      c+=1
    else:
      b.append([p,c])
      c=1
      p=x
  b.append([p,c])

  a=sorted(a,key=lambda x:x[1],reverse=True)
  b=sorted(b,key=lambda x:x[1],reverse=True)

  if a[0][0]==b[0][0]:
    if a[0][1]==n//2:
      return n//2
    if a[0][1]<b[0][1]:
      return n-a[1][1]-b[0][1]
    else:
      return n-a[0][1]-b[1][1]
  else:
    return n-a[0][1]-b[0][1]

print(main())