Problem:


Score : 300 points

Problem Statement

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

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

Exactly two different numbers appear in the sequence.

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

Constraints

2 \leq n \leq 10^5

n is even.

1 \leq v_i \leq 10^5

v_i is an integer.

Input

Input is given from Standard Input in the following format:

n
v_1 v_2 ... v_n

Output

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

Sample Input 1

4
3 1 3 2

Sample Output 1

1

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

Sample Input 2

6
105 119 105 119 105 119

Sample Output 2

0

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

Sample Input 3

4
1 1 1 1

Sample Output 3

2

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



Sample input:
4
3 1 3 2


Sample output:
1

Submission status: Wrong Answer

Solution code:
from collections import Counter


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

v_odd = []
v_even = []
for index in range(len(v)):
    i = index + 1
    if i % 2 == 0:
        v_even.append(v[index])
    else:
        v_odd.append(v[index])
# print(v_odd)
# print(v_even)
# print(Counter(v_odd).most_common())
# print(Counter(v_even).most_common())

if Counter(v_odd).most_common()[0][1] != Counter(v_even).most_common()[0][1]:
    number_of_rewrites = len(v_odd) - Counter(v_odd).most_common()[0][1]
    number_of_rewrites += len(v_even) - Counter(v_even).most_common()[0][1]
else:
    if Counter(v_odd).most_common()[0][1] >= Counter(v_even).most_common()[0][1]:
        number_of_rewrites = len(v_odd) - Counter(v_odd).most_common()[0][1]
        foo = Counter(v_even).most_common()[1][1] if len(Counter(v_even).most_common()) >= 2 else 0
        number_of_rewrites += len(v_even) - foo
    else:
        foo = Counter(v_odd).most_common()[1][1] if len(Counter(v_odd).most_common()) >= 2 else 0
        number_of_rewrites = len(v_odd) - foo
        number_of_rewrites += len(v_even) - Counter(v_even).most_common()[0][1]


print(number_of_rewrites)

Submission status: Wrong Answer

Solution code:
from collections import Counter


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

v_odd = []
v_even = []
for index in range(len(v)):
    i = index + 1
    if i % 2 == 0:
        v_even.append(v[index])
    else:
        v_odd.append(v[index])
# print(v_odd)
# print(v_even)
# print(Counter(v_odd).most_common())
# print(Counter(v_even).most_common())

number_of_rewrites = len(v_odd) - Counter(v_odd).most_common()[0][1]
number_of_rewrites += len(v_odd) - Counter(v_even).most_common()[0][1]

print(number_of_rewrites)

Submission status: Wrong Answer

Solution code:
from collections import*
n, *v = map(int, open(0).read().split())
a, b = map(lambda x: Counter(x).most_common(), [v[::2], v[1::2]])
try:
 print(n-a[0][1]-b[0][1] if a[0][0]!=a[0][0] else n - max(a[0][1]+b[1][1], a[1][1]+b[0][1]))
except IndexError:
 print(n//2)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

if v1[0][0] != v2[0][0]:
    ans = n - (v1[0][1] + v2[0][1])
else:
    if v1[0][1] > v2[0][1]:
        if len(v2) >= 2:
            ans = n - (v1[0][1] + v2[1][1])
        else:
            ans = n - v1[0][1]

    else:
        if len(v1) >= 2:
            ans = n - (v2[0][1] + v1[1][1])
        else:
            ans = n - v2[0][1]

print(ans)

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
vlist = list(map(int,input().split()))
list_odd = [vlist[i] for i in  range(n) if i % 2 ==0]
list_even = [vlist[i] for i in range(n) if i % 2 !=0]

def f(list1):
  ary1 = [[0,i] for i in range(10**5+2)]
  len1 = len(list1)
  for i in range(len1):
    ary1[list1[i]+1][0] += 1
  ary2 = sorted(ary1)
  return [ary2[-1],ary2[-2]]

list3 = f(list_odd)
list4 = f(list_even)


if list3[0][1] != list4[0][1]:
  print(n-list3[0][0]-list4[0][0])
else:
  if list3[0][0] >= list4[0][0]:
    print(n-list3[0][0]-list4[1][0])
  else:
    print(n-list3[1][0]-list4[0][0])

Submission status: Wrong Answer

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

v0 =[]
v1 =[]

for i in range(n):
  if i % 2 == 0:
    v0.append(v[i])
  else:
    v1.append(v[i])
  
v0.sort()
v1.sort()

v0_count = [[0,0]]
v1_count = [[0,0]]

#print(len(v0_count))
k = 0
for i in range(n//2):
  if v0[i] == v0_count[k][0]:
    v0_count[k][1] += 1
  else:
    v0_count.append([v0[i],1])
    k += 1


v0_count.sort(key=lambda x: x[1], reverse=True)

k = 0
for i in range(n//2):
  if v1[i] == v1_count[k][0]:
    v1_count[k][1] += 1
  else:
    v1_count.append([v1[i],1])
    k += 1


v1_count.sort(key=lambda x: x[1], reverse=True)

if v0_count[0][0] != v1_count[0][0]:
  print(n - v0_count[0][1] - v1_count[0][1])
else:
  print(max( n - v0_count[1][1] - v1_count[0][1] , n - v0_count[0][1] - v1_count[1][1], n - v0_count[1][1] - v1_count[1][1]))

Submission status: Wrong Answer

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

v0 =[]
v1 =[]

for i in range(n):
  if i % 2 == 0:
    v0.append(v[i])
  else:
    v1.append(v[i])
  
v0.sort()
v1.sort()

v0_count = [[0,0]]
v1_count = [[0,0]]

#print(len(v0_count))
k = 0
for i in range(n//2):
  if v0[i] == v0_count[k][0]:
    v0_count[k][1] += 1
  else:
    v0_count.append([v0[i],1])
    k += 1


v0_count.sort(key=lambda x: x[1], reverse=True)

k = 0
for i in range(n//2):
  if v1[i] == v1_count[k][0]:
    v1_count[k][1] += 1
  else:
    v1_count.append([v1[i],1])
    k += 1


v1_count.sort(key=lambda x: x[1], reverse=True)

if v0_count[0][0] != v1_count[0][0]:
  print(n - v0_count[0][1] - v1_count[0][1])
else:
  print(max( n - v0_count[1][1] - v1_count[0][1] , n - v0_count[0][1] - v1_count[1][1]))

Submission status: Wrong Answer

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

v0 =[]
v1 =[]

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

v0_count = [[0,0]]
v1_count = [[0,0]]

#print(len(v0_count))
for i in range(n//2):
  for j in range(len(v0_count)):
    if v0_count[j][0] == v0[i]:
      v0_count[j][1] += 1
      break
    elif v0_count[j][0] == 0:
      v0_count[j][0] = v0[i]
      v0_count[j][1] = 1
      v0_count.append([0,0])
      break

v0_count.sort(key=lambda x: x[1], reverse=True)

for i in range(n//2):
  for j in range(len(v1_count)):
    if v1_count[j][0] == v1[i]:
      v1_count[j][1] += 1
      break
    elif v1_count[j][0] == 0:
      v1_count[j][0] = v1[i]
      v1_count[j][1] = 1
      v1_count.append([0,0])
      break

v1_count.sort(key=lambda x: x[1], reverse=True)

if v0_count[0][0] != v1_count[0][0]:
  print(n - v0_count[0][1] - v1_count[0][1])
else:
  print(max( n - v0_count[1][1] - v1_count[0][1] , n - v0_count[0][1] - v1_count[1][1]))

Submission status: Wrong Answer

Solution code:
n=int(input())
v=list(map(int,input().split()))
if n==2 and v[0]==v[1]:
    print(1)
else:
    c_e=[]
    c_o=[]
    for h in range(max(v)+1):
        c_e.append([0,h])
        c_o.append([0,h])

    for i in range(n):
        num=v[i]
        if i%2==0:
            c_e[num][0]+=1
        else:
            c_o[num][0]+=1

    c_e.sort(reverse=True)
    c_o.sort(reverse=True)
    ae=c_e[0][0]
    ao=c_o[0][0]

    if c_e[0][1]==c_o[0][1]:
        for j in range(1,n//2):
            if c_e[j][0]>=c_o[j][0]:
                ao=c_o[j][0]
                break
            elif c_e[j][0]<c_o[j][0]:
                ae=c_e[j][0]
                break
    print(n-ae-ao)

Submission status: Wrong Answer

Solution code:
n=int(input())
v=list(map(int,input().split()))
c_e=[]
c_o=[]
for h in range(max(v)+1):
    c_e.append([0,h])
    c_o.append([0,h])

for i in range(n):
    num=v[i]
    if i%2==0:
        c_e[num][0]+=1
    else:
        c_o[num][0]+=1

c_e.sort(reverse=True)
c_o.sort(reverse=True)
ae=c_e[0][0]
ao=c_o[0][0]

if c_e[0][1]==c_o[0][1]:
    for j in range(1,n//2):
        if c_e[j][0]>=c_o[j][0]:
            ao=c_o[j][0]
            break
        elif c_e[j][0]<c_o[j][0]:
            ae=c_e[j][0]
            break
print(n-ae-ao)

Submission status: Wrong Answer

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

v_ls0 = [0] * (n//2)
v_ls1 = [0] * (n//2)
for i in range(n):
    if i % 2 == 0:
        v_ls0[i//2] = v_ls[i]
    else:
        v_ls1[i//2] = v_ls[i]
counter0 = collections.Counter(v_ls0)
counter1 = collections.Counter(v_ls1)
value01, count01 = counter0.most_common(2)[0]
if len(counter0.most_common(2)) == 1:
    value02, count02 = 0,0
else:   
    value02, count02 = counter0.most_common(2)[1]
value11, count11 = counter1.most_common(2)[0]
if len(counter1.most_common(2)) == 1:
    value12, count12 = 0,0
else:
    value12, count12 = counter1.most_common(2)[1]

if value01 != value11:
    ans = n - count01 - count11
else:
    if count01 >= count11:
        ans = n - count01 - count12
    else:
        ans = n - count11 - count02
print(ans)

Submission status: Wrong Answer

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

a1 = a[::2]
a2 = a[1::2]

d = [0] * (10 ** 6)
for ai in a1:
	d[ai] += 1  
ans = n // 2 - max(d)

d = [0] * (10 ** 6)
for ai in a2:
	d[ai] += 1  

print(ans + n // 2 - max(d))

Submission status: Wrong Answer

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

cnt = {}
for v in V:
    if v not in cnt:
        cnt[v] = 1
    else:
        cnt[v] += 1

cnt = [[v, k] for k, v in cnt.items()]
cnt.sort(reverse=True)

# 1種類のみ
if len(cnt) == 1:
    print(N // 2)
elif len(cnt) == 2:
    res = max(0, (cnt[0][0] - cnt[1][0]) - 1)
    print(res)
else:
    c1 = cnt[0][0]
    c2 = cnt[1][0]
    s = sum([c for c, k in cnt[2:]])
    if c1 - c2 <= s:
        print(s)
    else:
        c2 += s
        res = max(0, (c1 - c2) - 1)
        print(res)

Submission status: Wrong Answer

Solution code:
import collections

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

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

even_cnt = collections.Counter(even)
odd_cnt = collections.Counter(odd)


if even_cnt.most_common()[0][0] != odd_cnt.most_common()[0][0]:
    ans = n - even_cnt.most_common()[0][1]- odd_cnt.most_common()[0][1]
else:
    if even_cnt.most_common()[0][1] == odd_cnt.most_common()[0][1]:
        if len(even_cnt.most_common()) >= 2:
            ans = n - even_cnt.most_common()[0][1]- max(even_cnt.most_common()[0][1],odd_cnt.most_common()[0][1])
        else:
            ans = n//2
    else:
        if even_cnt.most_common()[0][1] > odd_cnt.most_common()[0][1]:
            ans = n - even_cnt.most_common()[0][1] - odd_cnt.most_common()[1][1]
        else:
            ans = n - odd_cnt.most_common()[0][1] - even_cnt.most_common()[1][1]
print(ans)

Submission status: Wrong Answer

Solution code:
import collections

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

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

even_cnt = collections.Counter(even)
odd_cnt = collections.Counter(odd)

if list(even_cnt.keys())[0] != list(odd_cnt.keys())[0]:
    ans = n - list(even_cnt.values())[0] - list(odd_cnt.values())[0]
else:
    if list(even_cnt.values())[0] == list(odd_cnt.values())[0]:
        if len(list(even_cnt.values())) >= 2:
            ans = n - list(even_cnt.values())[0] - max(list(even_cnt.values())[1],list(odd_cnt.values())[1])
        else:
            ans = n//2
    else:
        if list(even_cnt.values())[0] > list(odd_cnt.values())[0]:
            ans = n - list(even_cnt.values())[0] - list(odd_cnt.values())[1]
        else:
            ans = n - list(odd_cnt.values())[0] - list(even_cnt.values())[1]
print(ans)

Submission status: Wrong Answer

Solution code:
import collections

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

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

even_cnt = collections.Counter(even)
odd_cnt = collections.Counter(odd)

if list(even_cnt.keys())[0] != list(odd_cnt.keys())[0]:
    ans = n - list(even_cnt.values())[0] - list(odd_cnt.values())[0]
else:
    if list(even_cnt.values())[0] == list(odd_cnt.values())[0]:
        if len(list(even_cnt.values())) >= 2:
            ans = n - list(even_cnt.values())[0] - max(list(even_cnt.values())[1],list(even_cnt.values())[1])
        else:
            ans = n//2
    else:
        if list(even_cnt.values())[0] > list(odd_cnt.values())[0]:
            ans = n - list(even_cnt.values())[0] - list(odd_cnt.values())[1]
        else:
            ans = n - list(odd_cnt.values())[0] - list(even_cnt.values())[1]
print(ans)

Submission status: Wrong Answer

Solution code:
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])
v1.sort()
v2.sort()
v1_max = 0
c1 = 1
a = v1[0]
for i in range(1,n//2):
    if (v1[i-1]==v1[i]):
        c1 += 1
    else:
        if (v1_max < c1):
            v1_max = c1
            a = v[i-1]
        c1 = 1
if (v1_max < c1):
    v1_max = c1

v2_max = 0
c2 = 1
b = v2[0]
for i in range(1,n//2):
    if (v2[i-1]==v2[i]):
        c2 += 1
    else:
        if (v2_max < c2):
            v2_max = c2
            b = v[i-1]
        c2 = 1
if (v1_max < c2):
    v1_max = c2

print(n-c1-c2)

Submission status: Wrong Answer

Solution code:
from collections import Counter

n = int(input())
v = list(map(int, input().split()))
ve = Counter(v[::2]).most_common()
vo = Counter(v[1::2]).most_common()

if ve[0][0] == vo[0][0]:
    ans = n - max(ve[0][1], vo[0][1])
else:
    ans = n - ve[0][1] - vo[0][1]
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
n = int(input())
v = list(map(int, input().split()))
gu = [0] * (10**5 + 5)
ki = [0] * (10**5 + 5)

for i in range(n):
  if i % 2:
    ki[v[i]] += 1
  else:
    gu[v[i]] += 1
ki = np.array(ki)
gu = np.array(gu)

a = np.argmax(ki)
b = np.argmax(gu)

if a != b:
  print(n-ki[a]-gu[b])
else:
  gu = sorted(gu)
  ki = sorted(ki)
  print(max(n-ki[-1] - gu[-2], n-ki[-2]-gu[-1]))

Submission status: Wrong Answer

Solution code:
import numpy as np
n = int(input())
v = list(map(int, input().split()))
gu = [0] * (10**5 + 5)
ki = [0] * (10**5 + 5)

for i in range(n):
  if i % 2:
    ki[v[i]] += 1
  else:
    gu[v[i]] += 1
ki = np.array(ki)
gu = np.array(gu)

a = np.argmax(ki)
b = np.argmax(gu)

if a != b:
  print(n-ki[a]-gu[b])
else:
  if ki[a] > gu[b]:
    gu = sorted(gu)
    print(n-ki[a] - gu[-2])
  else:
    ki = sorted(ki)
    print(n-ki[-2]-gu[b])

Submission status: Wrong Answer

Solution code:
import numpy as np
n = int(input())
v = list(map(int, input().split()))
gu = [0] * (10**5 + 5)
ki = [0] * (10**5 + 5)

for i in range(n):
  if i % 2:
    ki[v[i]] += 1
  else:
    gu[v[i]] += 1
ki = np.array(ki)
gu = np.array(gu)

a = np.argmax(ki)
b = np.argmax(gu)

if a != b:
  print(n-ki[a]-gu[b])
else:
  if a > b:
    gu = sorted(gu)
    print(n-ki[a] - gu[-2])
  else:
    ki = sorted(ki)
    print(n-ki[-2]-gu[b])

Submission status: Wrong Answer

Solution code:
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list
#from itertools import combinations # (string,3) 3回
#from collections import deque
#import collections.defaultdict(list)
#import bisect
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def main():
    n = int(input())
    V = readInts()
    from collections import Counter
    a = Counter(V[0::2]).most_common(1) # 最大のもの1こ
    b = Counter(V[1::2]).most_common(1)
    a.append([0,0])
    b.append([0,0])
    #print(a,b)
    #print(a[1][1],b[1][1])
    if a[0][0] != b[0][0]:
        # mostが違う
        print(n - (a[0][1] + b[0][1]))
    else:
        print(min(n-(a[1][1] + b[0][1]), n-(a[0][1] + b[1][1])))
if __name__ == '__main__':
  main()

Submission status: Wrong Answer

Solution code:
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list
#from itertools import combinations # (string,3) 3回
#from collections import deque
#import collections.defaultdict(list)
#import bisect
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def main():
    n = int(input())
    V = readInts()
    from collections import Counter
    a = Counter(V[0::2]).most_common(1) # 最大のもの1こ
    b = Counter(V[1::2]).most_common(1)
    a.append([0,0])
    b.append([0,0])
    #print(a,b)
    if a[0][0] != b[0][0]:
        # mostが違う
        print(n - (a[0][1] + b[0][1]))
    else:
        print(min(n-(a[1][1] - b[0][1]), n-(a[0][1] + b[1][1])))
if __name__ == '__main__':
  main()

Submission status: Wrong Answer

Solution code:
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list
#from itertools import combinations # (string,3) 3回
#from collections import deque
#import collections.defaultdict(list)
#import bisect
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def main():
    n = int(input())
    V = readInts()
    from collections import Counter
    a = Counter(V[0::2]).most_common(1) # 最大のもの1こ
    b = Counter(V[1::2]).most_common(1)
    a.append([0,0])
    b.append([0,0])
    print(a,b)
    if a[0][0] != b[0][0]:
        # mostが違う
        print(n - (a[0][1] + b[0][1]))
    else:
        print(min(n-(a[1][1] - b[0][1]), n-(a[0][1] + b[1][1])))
if __name__ == '__main__':
  main()

Submission status: Wrong Answer

Solution code:
import collections
n=int(input())
A=list(map(int,input().split()))
A0=[]
A1=[]
for i in range(n):
  if i%2==0:
    A0.append(A[i])
  else:
    A1.append(A[i])
A00=collections.Counter(A0)
A11=collections.Counter(A1)
A000=A00.most_common()
A111=A11.most_common()
A000.append(("-1",0))
A111.append(("-1",0))
if A000[0][0]!=A111[0][0]:
  print(n-A000[0][1]-A111[0][1])
else:
  if len(A000)!=1 and len(A111)!=1:
    print(max(n-A000[1][1]-A111[0][1],n-A000[0][1]-A111[1][1]))

Submission status: Wrong Answer

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

a = [v[i] for i in range(n) if i % 2 == 0]
b = [v[i] for i in range(n) if not i % 2 == 0]

a_count = Counter(a)
b_count = Counter(b)

a_sorted = sorted(a_count.items(), key=lambda x:x[1], reverse=True)
b_sorted = sorted(b_count.items(), key=lambda x:x[1], reverse=True)
print(a_sorted)
print(b_sorted)
ans = 0
if not a_sorted[0][0] == b_sorted[0][0]:
    ans = n - a_sorted[0][1] - b_sorted[0][1]
else:
    if len(b_sorted) == 1 and len(a_sorted) == 1:
        ans = n - a_sorted[0][1]
    elif len(b_sorted) == 1:
        ans = n - a_sorted[0][1]
    elif len(a_sorted) == 1:
        ans = n - b_sorted[0][1]
    else:
        ans = n - max(a_sorted[0][1] + b_sorted[1][1], a_sorted[1][1] + b_sorted[0][1])

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict


def main():

    n = int(input())

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

    odd = defaultdict(int)
    even = defaultdict(int)

    for i, num in enumerate(v):
        # print(i % 2)
        if (i % 2) == 0:
            even[num] += 1
        elif (i % 2) == 1:
            # print(i, ": ", num)
            odd[num] += 1

    even_list = [item for item in even.items()]
    odd_list = [item for item in odd.items()]
    sorted(even_list, key=lambda x: x[1], reverse=True)
    sorted(odd_list, key=lambda x: x[1], reverse=True)

    # 全パターン計算する
    ans_list = []
    if len(even_list) == 1:
        even_list.append((-1, 0))
    if len(odd_list) == 1:
        odd_list.append((-2, 0))

    for ev in even_list[:2]:
        for od in odd_list[:2]:
            if ev[0] != od[0]:
                ans = 0
                ans += n - (ev[1] + od[1])
                ans_list.append(ans)

    print(min(ans_list))


main()

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

n = int(input())

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

odd = defaultdict(int)
even = defaultdict(int)


for i, num in enumerate(v):
    # print(i % 2)
    if (i % 2) == 0:
        even[num] += 1
    elif (i % 2) == 1:
        # print(i, ": ", num)
        odd[num] += 1

even_list = [item for item in even.items()]
odd_list = [item for item in odd.items()]
sorted(even_list, key=lambda x: x[1], reverse=True)
sorted(odd_list, key=lambda x: x[1], reverse=True)

ans = 0
n2 = int(n / 2)

if even_list[0][0] != odd_list[0][0]:
    ans += (n2 - even_list[0][1]) + (n2 - odd_list[0][1])
elif even_list[0][0] == odd_list[0][0]:
    if even_list[0][1] >= odd_list[0][1]:
        ans += (n2 - even_list[0][1])
        try:
            ans += (n2 - odd_list[1][1])
        except IndexError:
            ans += n2
    elif even_list[0][1] < odd_list[0][1]:
        ans += (n2 - odd_list[0][1])
        try:
            ans += (n2 - even_list[1][1])
        except IndexError:
            ans += n2

print(ans)

Submission status: Wrong Answer

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

d_odd = {}
d_even = {}

for i in range(n):
    if i % 2 == 0:
        if v[i] in d_odd:
            d_odd[v[i]] += 1
        else:
            d_odd[v[i]] = 1
    else:
        if v[i] in d_even:
            d_even[v[i]] += 1
        else:
            d_even[v[i]] = 1

x = sorted(d_odd)
y = sorted(d_even)

if len(x) == 1 and len(y) == 1:
    print(n//2)
elif len(x) == 1:
    print(n//2 - d_even[y[0]])
elif len(y) == 1:
    print(n//2 - d_odd[x[0]])
else:
    if x[0] != y[0]:
        print(n//2-d_odd[x[0]] + n//2-d_even[y[0]])
    else:
        e = n//2 - d_odd[x[0]] + n//2 - d_even[y[1]]
        o = n//2 - d_odd[x[1]] + n//2 - d_even[y[0]]
        print(min([e, o]))

Submission status: Wrong Answer

Solution code:
from collections import Counter


def solve():

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

    evens = []
    odds = []

    for i in range(n):
        v = vlist[i]
        if i % 2 == 0:
            evens.append(v)
        else:
            odds.append(v)

    evensCollection = Counter(evens).most_common()
    oddsCollection = Counter(odds).most_common()

    ans = 0

    for i in range(1, len(evensCollection)):
        ans += evensCollection[i][1]

    for i in range(1, len(oddsCollection)):
        ans += oddsCollection[i][1]

    if evensCollection[0][0] == oddsCollection[0][0]:
        if evensCollection[0][1] >= oddsCollection[0][1]:
            ans += oddsCollection[0][1]
            if len(oddsCollection) > 1:
                ans -= oddsCollection[1][1]
        else:
            ans += evensCollection[0][1]
            if len(evensCollection) > 1:
                ans -= evensCollection[1][1]

    print(ans)


if __name__ == "__main__":
    solve()

Submission status: Wrong Answer

Solution code:
from collections import Counter


def solve():

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

    evens = []
    odds = []

    for i in range(n):
        v = vlist[i]
        if i % 2 == 0:
            evens.append(v)
        else:
            odds.append(v)

    evensCollection = Counter(evens).most_common()
    oddsCollection = Counter(odds).most_common()

    ans = 0

    for i in range(1, len(evensCollection)):
        ans += evensCollection[i][1]

    for i in range(1, len(oddsCollection)):
        ans += oddsCollection[i][1]

    if evensCollection[0][0] == oddsCollection[0][0]:
        ans += oddsCollection[0][1]
        if len(oddsCollection) > 1:
            ans -= oddsCollection[1][1]

    print(ans)


if __name__ == "__main__":
    solve()

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

v_even,v_odd = [],[]
for i in range(n):
    if i % 2 == 0:
        v_even.append(v[i])
    else:
        v_odd.append(v[i])

c_even = Counter(v_even)
c_odd = Counter(v_odd)

if len(set(v)) == 1:
    ans = n // 2
elif len(set(v_even)) == 1:
    if c_even.most_common()[0][0] == c_odd.most_common()[0][0]:
        ans = (n // 2) - c_odd.most_common()[1][1]
    else:
        ans = (n // 2) - c_odd.most_common()[0][1]
elif len(set(v_odd)) == 1:
    if c_odd.most_common()[0][0] == c_even.most_common()[0][0]:
        ans = (n // 2) - c_even.most_common()[1][1]
    else:
        ans = (n // 2) - c_even.most_common()[0][1]
else:
    if c_odd.most_common()[0][0] != c_even.most_common()[0][0]:
        ans = n - c_even.most_common()[0][1] - c_odd.most_common()[0][1]
    else:
        if c_odd.most_common()[1][0] < c_even.most_common()[1][0]:
            ans = n - c_even.most_common()[1][1] - c_odd.most_common()[0][1]
        else:
            ans = n - c_even.most_common()[0][1] - c_odd.most_common()[1][1]

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

v_even,v_odd = [],[]
for i in range(n):
    if i % 2 == 0:
        v_even.append(v[i])
    else:
        v_odd.append(v[i])

c_even = Counter(v_even)
c_odd = Counter(v_odd)

if len(set(v)) == 1:
    ans = n // 2
elif len(set(v_even)) == 1:
    if c_even.most_common()[0][0] == c_odd.most_common()[0][0]:
        ans = (n // 2) - c_odd.most_common()[1][1]
    else:
        ans = (n // 2) - c_odd.most_common()[0][1]
elif len(set(v_odd)) == 1:
    if c_odd.most_common()[0][0] == c_even.most_common()[0][0]:
        ans = (n // 2) - c_even.most_common()[1][1]
    else:
        ans = (n // 2) - c_even.most_common()[0][1]
else:
    ans = n - c_even.most_common()[0][1] - c_odd.most_common()[0][1]

print(ans)

Submission status: Wrong Answer

Solution code:
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list
#from itertools import combinations # (string,3) 3回

mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def main():
    n = int(input())
    V = readInts()
    Fi = {}
    Se = {}

    for i in range(0,n,2): # 奇数個
        if V[i] in Fi.keys():
            Fi[V[i]] += 1
        else:
            Fi[V[i]] = 1


    for i in range(1,n,2): # 偶数個
        if V[i] in Se.keys():
            Se[V[i]] += 1
        else:
            Se[V[i]] = 1
    #print(Fi,Se,sep='\n')
    # ソート
    sortFi = sorted(Fi.items(), key=lambda x:x[1]) # valuesでソートしてる！
    sortSe = sorted(Se.items(), key = lambda x:x[1])
    # リスト化しちゃう
    #print(Fi,Se,sep='\n')
    #na = '' # 繰り返し防止
    k,v = sortFi[0]
    mostFi = k
    #もじ、mostFiと、mostSeが一緒だったら、mostSeの方をずらす? 数字が小さいほうをずらしたほうがいい気もする?
    k,v = sortSe[0]
    mostSe = k
    if mostFi == mostSe:
        if len(sortSe) != 1:
            k,v = sortSe[1]
            mostSe = k
        else:
            mostSe = mostFi+1
    #print(mostFi)
    # 一番多くある数字に合わせる感じ
    cnt = 0
    for k,v in Fi.items():
        if mostFi == k:
            pass
        else:
            cnt += v
    for k,v in Se.items():
        if mostSe == k:
            pass
        else:
            cnt += v
    print(cnt)



if __name__ == '__main__':
  main()

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

v_even,v_odd = [],[]
for i in range(n):
    if i % 2 == 0:
        v_even.append(v[i])
    else:
        v_odd.append(v[i])

c_even = Counter(v_even)
c_odd = Counter(v_odd)

n1 = c_even.most_common(1)[0][1]
n2 = c_odd.most_common(1)[0][1]

ans = n - n1 - n2
if len(set(v)) == 1:
    ans = n // 2
print(ans)

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
vlist = list(map(int,input().split()))
even = vlist[0:n:2]
odd = vlist[1:n:2]
e_counter= collections.Counter(even)
o_counter = collections.Counter(odd)
e_v = list(e_counter.values())
e_k = list(e_counter.keys())
o_v = list(o_counter.values())
o_k = list(o_counter.keys())
ans = 10**9
#ans = len(even)-e + len(odd)-o
#print(e_k,e_v,o_k,o_v)
if e_k[0] == o_k[0]:
  if len(e_v) >= 2 and len(o_v) >= 2:
    ans = min(ans,len(even)-e_v[1]+len(odd)-o_v[0],len(even)-e_v[0]+len(odd)-o_v[1])
  elif len(e_v) >= 2:
    ans = min(ans,len(even)+len(odd)-e_v[1]-o_v[0],len(even)+len(odd)-e_v[0])
  elif len(o_v) >= 2:
    ans = min(ans,len(even)+len(odd)-o_v[1]-e_v[0],len(even)+len(odd)-o_v[0])
  else:
    ans = min(len(even)+len(odd)-e_v[0],len(even)+len(odd)-o_v[0])
else:
  ans = min(ans,len(even)+len(odd)-e_v[0]-o_v[0])
print(ans)

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
vlist = list(map(int,input().split()))
even = vlist[0:n:2]
odd = vlist[1:n:2]
e_counter= collections.Counter(even)
o_counter = collections.Counter(odd)
e_v = list(e_counter.values())
e_k = list(e_counter.keys())
o_v = list(o_counter.values())
o_k = list(o_counter.keys())
ans = 10**9
#ans = len(even)-e + len(odd)-o
print(e_k,e_v,o_k,o_v)
if e_k[0] == o_k[0]:
  if len(e_v) >= 2 and len(o_v) >= 2:
    ans = min(ans,len(even)-e_v[1]+len(odd)-o_v[0],len(even)-e_v[0]+len(odd)-o_v[1])
  elif len(e_v) >= 2:
    ans = min(ans,len(even)+len(odd)-e_v[1]-o_v[0],len(even)+len(odd)-e_v[0])
  elif len(o_v) >= 2:
    ans = min(ans,len(even)+len(odd)-o_v[1]-e_v[0],len(even)+len(odd)-o_v[0])
  else:
    ans = min(len(even)+len(odd)-e_v[0],len(even)+len(odd)-o_v[0])
else:
  ans = min(ans,len(even)+len(odd)-e_v[0]-o_v[0])
print(ans)

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
vlist = list(map(int,input().split()))
even = vlist[0:n:2]
odd = vlist[1:n:2]
e_counter= collections.Counter(even)
o_counter = collections.Counter(odd)
e_v = list(e_counter.values())
e_k = list(e_counter.keys())
o_v = list(o_counter.values())
o_k = list(o_counter.keys())
ans = 10**9
#ans = len(even)-e + len(odd)-o
#print(e_k,o_k)
if e_k[0] == o_k[0]:
  if len(e_v) >= 2 and len(o_v) >= 2:
    ans = min(ans,len(even)-e_v[1]+len(odd)-o_v[0],len(even)-e_v[0]+len(odd)-o_v[1])
  elif len(e_v) >= 2:
    ans = min(ans,len(even)+len(odd)-e_v[1]-o_v[0],len(even)+len(odd)-e_v[0])
  elif len(o_v) >= 2:
    ans = min(ans,len(even)+len(odd)-o_v[1]-e_v[0],len(even)+len(odd)-o_v[0])
  else:
    ans = min(len(even)+len(odd)-e_v[0],len(even)+len(odd)-o_v[0])
else:
  ans = min(ans,len(even)+len(odd)-e_v[0]-o_v[0])
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
v = list(map(int,input().split()))
v1 = v[0::2]
v2 = v[1::2]
count1 = Counter(v1)
count2 = Counter(v2)
print(n - max(count1.values()) - max(count2.values()))

Submission status: Wrong Answer

Solution code:
from collections import Counter
N=int(input())
V=list(map(int,input().split()))
V0=Counter(V[::2]).most_common()
V1=Counter(V[1::2]).most_common()
ans=0
if V0[0][0]==V1[0][0]:
  if len(V0)==1 and len(V1)==1:
    print(N//2)
    exit()
  elif len(V0)!=1 and len(V1)!=1:
    if V0[1][0]>=V1[1][0]:
      V0[0],V0[1]=V0[1],V0[0]
    else:
      V1[0],V1[1]=V1[1],V1[0]
  elif len(V0)>len(V1):
     V0[0],V0[1]=V0[1],V0[0]
  else:
    V1[0],V1[1]=V1[1],V1[0]
for i in range(1,len(V0)):
  ans+=V0[i][1]
for i in range(1,len(V1)):
  ans+=V1[i][1]
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
N=int(input())
V=list(map(int,input().split()))
V0=Counter(V[::2]).most_common()
V1=Counter(V[1::2]).most_common()
ans=0
for i in range(1,len(V0)):
  ans+=V0[i][1]
for i in range(1,len(V1)):
  ans+=V1[i][1]
print(ans)