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

count = 0
for i in range(len(V)):
  if V[i] != V[i+2]:
    count += 1
  elif V[i] == V[i+1]:
    count += 1
  if i+2 == len(V)-1:
    break


print(count)

Submission status: Wrong Answer

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

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

even = {}
odd = {}
# 奇数番目と偶数番目に分けて集計
for i in range(N):
    if i % 2 == 0:
        even[vN[i]] = even.get(vN[i], 0) + 1
    else:
        odd[vN[i]] = odd.get(vN[i], 0) + 1

# 一番多い数字が同じだった場合は別処理(内容は自信ない)
while max(even, key=even.get) == max(odd, key=odd.get):

    if max(even.values()) >= max(odd.values()):
        odd.pop(max(odd, key=odd.get))
    else:
        even.pop(max(even, key=even.get))
    if len(odd) == 0 or len(even) == 0:
        print(N // 2)
        exit()

print(N - max(even.values()) - max(odd.values()))

Submission status: Wrong Answer

Solution code:
n = int(input())
a = input().split()
dic1 = {}
firitem1 = "0"
firnum1 = 0
secitem1 = "0"
secnum1 = 0
dic2 = {}
firitem2 = "0"
firnum2 = 0
secitem2 = "0"
secnum2 = 0

for i in range(len(a)):
  if i%2 == 0:
    if a[i] in dic1:
      dic1[a[i]] += 1
    else:
      dic1[a[i]] = 1
    if dic1[a[i]] > firnum1:
      if firitem1 == a[i]:
        firnum1 = dic1[a[i]]
      else:
        secitem1 = firitem1
        secnum1 = firnum1
        firitem1 = a[i]
        firnum1 = dic1[a[i]]
  else:
    if a[i] in dic2:
      dic2[a[i]] += 1
    else:
      dic2[a[i]] = 1
    if dic2[a[i]] > firnum2:
      if firitem2 == a[i]:
        firnum2 = dic2[a[i]]
      else:
        secitem2 = firitem2
        secnum2 = firnum2
        firitem2 = a[i]
        firnum2 = dic2[a[i]]

if firitem1 != firitem2:
  print(int(n/2-firnum1 + n/2-firnum2))
else:
  print(int(min(n/2-firnum1 + n/2-secnum2, n/2-secnum1 + n/2-firnum2)))

Submission status: Wrong Answer

Solution code:
n = int(input())
v = [int(c) for c in input().split()]
vo = v[::2]
ve = v[1::2]
counts_o = [(elm, vo.count(elm)) for elm in set(vo)]
counts_e = [(elm, ve.count(elm)) for elm in set(ve)]

Submission status: Wrong Answer

Solution code:
n = int(input())
v = [int(c) for c in input().split()]

Submission status: Wrong Answer

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

even = {}
odd = {}

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

# max_even = max(even, key = even.get) #evenの値を最大にするキー
# max_odd = max(odd, key = odd.get) #oddの値を最大にするキー
#
# if max_even == max_odd:

min = float("inf")

if len(even.keys()) ==1 and len(odd.keys()) == 1:
    print(n//2)
    exit()

for e in even.keys():
    for o in odd.keys():
        if (e != o) and (n-even[e]-odd[o]<min):
            min = n-even[e]-odd[o]

print(int(min))

Submission status: Wrong Answer

Solution code:
from collections import Counter
N, = map(int, raw_input().split())
v  = map(int, raw_input().split())
c = [Counter(), Counter()]
for i in range(N):
  c[i%2][v[i]]+=1
mk0, mc0 = c[0].most_common(1)[0]
mk1, mc1 = c[1].most_common(1)[0]
r=N
if mc0>=mc1:
  for k in c[0].keys():
    if k==mk0:
      c1=Counter(c[1])
      c1[k]=0
      mk1, mc1 = c1.most_common(1)[0]
      r=min(r, N-mc0-mc1)
else:
  for k in c[1].keys():
    if k==mk1:
      c0=Counter(c[0])
      c0[k]=0
      mk0, mc0 = c0.most_common(1)[0]
      r=min(r, N-mc0-mc1)
print r

Submission status: Wrong Answer

Solution code:
from collections import Counter
N, = map(int, raw_input().split())
v  = map(int, raw_input().split())
c = [Counter(), Counter()]
for i in range(N):
  c[i%2][v[i]]+=1
mk0, mc0 = c[0].most_common(1)[0]
mk1, mc1 = c[1].most_common(1)[0]
if mc0>=mc1:
  c[1][mk0]=0
  mk1, mc1 = c[1].most_common(1)[0]
else:
  c[0][mk1]=0
  mk0, mc0 = c[0].most_common(1)[0]
print N-mc0-mc1

Submission status: Wrong Answer

Solution code:
# /\/\/\/
from collections import Counter
n = int(input())
v = list(map(int, input().split()))
odd = Counter(v[0::2])
even = Counter(v[1::2])
odd_max = set([k for k, v in odd.items() if v == max(odd.values())])
even_max = set([k for k, v in odd.items() if v == max(even.values())])
if not (odd_max & even_max):
    print(n - max(odd.values()) - max(even.values()))
else:
    print(n - min(max(odd.values()), max(even.values())))

Submission status: Wrong Answer

Solution code:
# /\/\/\/
from collections import Counter
n = int(input())
v = list(map(int, input().split()))
p = 0
odd = Counter(v[0::2])
even = Counter(v[1::2])
odd_max = [k for k, v in odd.items() if v == max(odd.values())]
even_max = [k for k, v in odd.items() if v == max(even.values())]
if odd_max == even_max:
    print(n - min(max(odd.values()), max(even.values())))
else:
    print(n - max(odd.values()) - max(even.values()))

Submission status: Wrong Answer

Solution code:
# /\/\/\/
from collections import Counter
n = int(input())
v = list(map(int, input().split()))
odd = Counter(v[0::2])
even = Counter(v[1::2])
if odd[0] == even[lambda x: x, range(len(odd))]:
    print(n//2)
else:
    print(n - max(odd.values()) - max(even.values()))

Submission status: Wrong Answer

Solution code:
import collections
n=int(input())
m=n//2
v1=list(map(int,input().split()))
v2=[]
for j in range(m):
    v2.append(v1.pop(j))
a1=sorted((collections.Counter(v1)).items(),key=lambda x:x[1],reverse=True)
a2=sorted((collections.Counter(v2)).items(),key=lambda x:x[1],reverse=True)
if a1[0][1]<a2[0][1]:a1,a2=a2[:],a1[:]
if a1[0][0]!=a2[0][0]:
    print(n-a1[0][1]-a2[0][1])
elif len(a2)==1:
    print(m)
else:
    print(n-a1[0][1]-a2[1][1])

Submission status: Wrong Answer

Solution code:
import collections
n=int(input())
m=n//2
v1=list(map(int,input().split()))
v2=[]
for j in range(m):
    v2.append(v1.pop(j))
a1=sorted((collections.Counter(v1)).items(),key=lambda x:x[1],reverse=True)
a2=sorted((collections.Counter(v2)).items(),key=lambda x:x[1],reverse=True)
if a1[0][1]<a2[0][1]:a1,a2=a2[:],a1[:]
print(a2)
if a1[0][0]!=a2[0][0]:
    print(n-a1[0][1]-a2[0][1])
elif len(a2)==1:
    print(m)
else:
    print(n-a1[0][1]-a2[1][1])

Submission status: Wrong Answer

Solution code:
import collections
n=int(input())
m=n//2
v1=list(map(int,input().split()))
v2=[]
for j in range(m):
    v2.append(v1.pop(j))
a1=sorted((collections.Counter(v1)).items(),key=lambda x:x[1] )
a2=sorted((collections.Counter(v2)).items(),key=lambda x:x[1])
if a1[0][1]<a2[0][1]:a1,a2=a2[:],a1[:]
if a1[0][0]!=a2[0][0]:
    print(n-a1[0][1]-a2[0][1])
elif len(a2)==1:
    print(m)
else:
    print(n-a1[0][1]-a2[1][0])

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

if a[0][0] != b[0][0]:
    ans = n-a[0][1]-b[0][1]
else:
    if len(a) == 1 and len(b) == 1:
        ans = a[0][1]
    else:
        ans = min(n - a[1][1] - b[0][1], n - b[0][1] - a[1][1])

print(int(ans))

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

if a[0][0] != b[0][0]:
    ans = int(n-a[0][1]-b[0][1])
else:
    if len(a) == 1 and len(b) == 1:
        ans = a[0][1]
    else:
        ans = min(n - a[1][1] - b[0][1], n - b[0][1] - a[1][1])
print(int(ans))

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

if a[0][0] != b[0][0]:
    ans = int(n-a[0][1]-b[0][1])
else:
    if len(a) == 1 and len(b) == 1:
        ans = n/2
    else:
        ans = min(n - a[1][1] - b[0][1], n - b[0][1] - a[1][1])
print(int(ans))

Submission status: Wrong Answer

Solution code:
from collections import Counter

n = int(input())
v = list(map(int,input().split()))
a = Counter(v[0::2]).most_common()
b = Counter(v[1::2]).most_common()
if a[0][0] != b[0][0]:
    print(int(n-a[0][1]-b[0][1]))
else:
    print(int(n/2))

Submission status: Wrong Answer

Solution code:
n = int(input())

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

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


import numpy as np

a = np.array(vo)
b = np.array(ve)

count_a = np.bincount(a)
mode_a  = np.argmax(count_a)

count_b = np.bincount(b)
mode_b  = np.argmax(count_b)

c = 0

if mode_a == mode_b:
    c = c - 2

for i in a:
    if i == mode_a:
        c = c + 1
for i in b:
    if i == mode_b:
        c = c + 1
c = len(v)-(c)


print(c)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

n = int(input())
v = list(map(int,input().split()))
e, o =[], []
for i in range(n//2):
    e.append(v[2*i])
    o.append(v[2*i+1])
e.sort()
o.sort()
e.append(-1)
o.append(-1)
# print(e,o)

e1, e2, o1, o2 = 0,0,0,0
E1, O1 = e[0], o[0]
c = 1
for i in range(0,n//2):
    if e[i]==e[i+1]:
        c+= 1
        continue
    if c>e1:
        e2 = e1
        e1 = c
        c = 1
        E1 = e[i]
    elif c>e2:
        e2 = c
        c = 1

c=1
for i in range(0,n//2):
    if o[i]==o[i+1]:
        c+= 1
        continue
    if c>o1:
        o2 = o1
        o1 = c
        c = 1
        O1 = o[i]
    elif c>o2:
        o2 = c
        c = 1

# print(e1,e2,E1,o1,o2,O1)

if E1==O1:
    print(min(n-e1-o2,n-e2-o1))
else:
    print(n-e1-o1)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

n = int(input())
v = list(map(int,input().split()))
e, o =[], []
for i in range(n//2):
    e.append(v[2*i])
    o.append(v[2*i+1])
e.sort()
o.sort()

# print(e,o)

e1, e2, o1, o2 = 1,0,1,0
E1, O1 = e[0], o[0]
c = 0
for i in range(n//2-1):
    c+=1
    if e[i]==e[i+1]:
        if c == n//2-1:
            e1 = n//2
        continue
    elif c>e1:
        e2 = e1
        e1 = c
        c = 0
        E1 = e[i]
    elif c>e2:
        e2 = c
        c = 0

c=0
for i in range(n//2-1):
    c+=1
    if o[i]==o[i+1]:
        if c == n//2-1:
            o1 = n//2
        continue
    elif c>o1:
        o2 = o1
        o1 = c
        c = 0
        O1 = o[i]
    elif c>o2:
        o2 = c
        c = 0

# print(e1,E1,o1,O1)

if E1==O1:
    print(min(n-e1-o2,n-e2-o1))
else:
    print(n-e1-o1)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

n = int(input())
v = list(map(int,input().split()))
e, o =[], []
for i in range(n//2):
    e.append(v[2*i])
    o.append(v[2*i+1])
e.sort()
o.sort()

# print(e,o)

e1, e2, o1, o2 = 1,0,1,0
E1, O1 = e[0], o[0]
c = 0
for i in range(n//2-1):
    c+=1
    if e[i]==e[i+1]:
        if c == n//2-1:
            e1 = n//2
        continue
    elif c>e1:
        e2 = e1
        e1 = c
        c = 0
        E1 = e[i]
    elif c>e2:
        e2 = c
        c = 0

c=0
for i in range(n//2-1):
    c+=1
    if o[i]==o[i+1]:
        if c == n//2-1:
            o1 = n//2
        continue
    elif c>o1:
        o2 = o1
        o1 = c
        c = 0
        O1 = o[i]
    elif c>o2:
        o2 = c
        c = 0

# print(e1,E1,o1,O1)

if E1==O1:
    print(max(n-e1-o2,n-e2-o1))
else:
    print(n-e1-o1)

Submission status: Wrong Answer

Solution code:
n = int(input())

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

def p(v):
    if len(set(v)) == 1:
        return int(len(v)/2)
    v_eve = v[::2]
    v_odd = v[1::2]
    if len(set(v_eve)) == 1 and len(set(v_odd)) == 1:
        return 0
    d_eve = {}
    d_odd = {}
    for i in v_eve:
        if d_eve.get(i):
            d_eve[i] += 1
        else:
            d_eve[i] = 1
    for j in v_odd:
        if d_odd.get(j):
            d_odd[j] += 1
        else:
            d_odd[j] = 1

    r_eve = sorted(list(d_eve.values()))
    r_odd = sorted(list(d_odd.values()))
    if max(d_eve, key=d_eve.get) != max(d_odd, key=d_odd.get):
        return int(len(v) - r_eve[-1] - r_odd[-1])
    else:
        print(1)
        if r_eve[-1] <= r_odd[-1]:
            return int(r_eve[-1] + len(v_odd) - r_odd[-1])
        else:
            return int(len(v_eve) - r_eve[-1] + r_odd[-1])


print(p(v))

Submission status: Wrong Answer

Solution code:
n = int(input())

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

def p(v):
    if len(set(v)) == len(v):
        return len(v) - 2
    if len(set(v)) == 1:
        return int(len(v)/2)
    v_eve = v[::2]
    v_odd = v[1::2]
    if len(set(v_eve)) == 1 and len(set(v_odd)) == 1:
        return 0
    d_eve = {}
    d_odd = {}
    for num in v_eve:
        if d_eve.get(num):
            d_eve[num] += 1
        else:
            d_eve[num] = 1
    for num in v_odd:
        if d_odd.get(num):
            d_odd[num] += 1
        else:
            d_odd[num] = 1

    r_eve = sorted(list(d_eve.values()))
    r_odd = sorted(list(d_odd.values()))
    return int(len(v_eve)*2 - r_eve[-1] - r_odd[-1])

print(p(v))

Submission status: Wrong Answer

Solution code:
n = int(input())

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

def p(v):
    if len(set(v)) == 1:
        return int(len(v)/2)
    v_eve = v[::2]
    v_odd = v[1::2]
    if len(set(v_eve)) == 1 and len(set(v_odd)) == 1:
        return 0
    d_eve = {}
    d_odd = {}
    for num in v_eve:
        if d_eve.get(num):
            d_eve[num] += 1
        else:
            d_eve[num] = 1
    for num in v_odd:
        if d_odd.get(num):
            d_odd[num] += 1
        else:
            d_odd[num] = 1

    r_eve = sorted(list(d_eve.values()))
    r_odd = sorted(list(d_odd.values()))
    return int(len(v_eve)*2 - r_eve[-1] - r_odd[-1])

print(p(v))

Submission status: Wrong Answer

Solution code:
n = int(input())

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

def p(v):
    if len(set(v)) == 1:
        return len(v)/2
    v_eve = v[::2]
    v_odd = v[1::2]
    if len(set(v_eve)) == 1 and len(set(v_odd)) == 1:
        return 0
    d_eve = {}
    d_odd = {}
    for num in v_eve:
        if d_eve.get(num):
            d_eve[num] += 1
        else:
            d_eve[num] = 1
    for num in v_odd:
        if d_odd.get(num):
            d_odd[num] += 1
        else:
            d_odd[num] = 1

    r_eve = sorted(list(d_eve.values()))
    r_odd = sorted(list(d_odd.values()))
    return int(len(v_eve)*2 - r_eve[-1] - r_odd[-1])

print(p(v))

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

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

x = Counter(v[::2])
y = Counter(v[1::2])
vx = x.most_common()[0][1]
vy = y.most_common()[0][1]
print(n - vx - vy)

Submission status: Wrong Answer

Solution code:
import collections

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

c1 = collections.Counter(v[0::2])
c2 = collections.Counter(v[1::2])
if(n!=collections.Counter(v).most_common()[0][1]):
    print(len(v)-c1.most_common()[0][1]-c2.most_common()[0][1])
else:
    print(int(n/2))

Submission status: Wrong Answer

Solution code:
from collections import Counter
    
n = 12
v = list(map(int, '1 1 1 1 2 2 2 2 2 2 3 3'.split()))

a = Counter(v[0::2]).most_common()
b = Counter(v[1::2]).most_common()
a.append([0,0])
b.append([0,0])
if a[0][0] != b[0][0]:
    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])))

Submission status: Wrong Answer

Solution code:
import collections

n = int(input())
vs = list(map(int, input().split()))
odd = vs[::2]
even = vs[1::2]
c_odd = collections.Counter(odd)
c_even = collections.Counter(even)
v_odd = c_odd.most_common(1)[0][0]
v_even = c_even.most_common(1)[0][0]
if v_odd == v_even:
    if len(c_odd) == 1 and len(c_even) == 1:
        same = n//2
    elif len(c_odd) == 1 and len(c_even) != 1:
        same = n//2 + c_even.most_common(2)[1][1]
    elif len(c_odd) != 1 and len(c_even) == 1:        
        same = n//2 + c_odd.most_common(2)[1][1]
    else:
        v2_odd = c_odd.most_common(2)
        v2_even = c_even.most_common(2)    
        if v2_odd[1][1] > v2_even[1][1]:
            same = c_odd.most_common(1)[0][1] + v2_even[1][1]
        else:
            same =  v2_odd[1][1]+ c_even.most_common(1)[0][1]
else:
    same =  c_odd.most_common(1)[0][1] + c_even.most_common(1)[0][1]
print(n - same)

Submission status: Wrong Answer

Solution code:
import collections

n = int(input())
vs = list(map(int, input().split()))
odd = vs[::2]
even = vs[1::2]
c_odd = collections.Counter(odd)
c_even = collections.Counter(even)
v_odd = c_odd.most_common(1)[0][0]
v_even = c_even.most_common(1)[0][0]
if v_odd == v_even:
    if len(c_odd) == 1 & len(c_even) == 1:
        same = n//2
    elif len(c_odd) == 1 & len(c_even) != 1:
        same = n//2 + c_even.most_common(2)[1][1]
    elif len(c_odd) != 1 & len(c_even) == 1:
        same = n//2 + c_odd.most_common(2)[1][1]
    else:
        v2_odd = c_odd.most_common(2)
        v2_even = c_even.most_common(2)    
        if v2_odd[1][1] > v2_even[1][1]:
            same = c_odd.most_common(1)[0][1] + v2_even[1][1]
        else:
            same =  v2_odd[1][1]+ c_even.most_common(1)[0][1]
else:
    same =  c_odd.most_common(1)[0][1] + c_even.most_common(1)[0][1]
print(n - same)

Submission status: Wrong Answer

Solution code:
from collections import Counter
 
n = int(input())
v = list(map(int,input().split()))
v0 = []
v1 = []
for i,ev in enumerate(v):
    if i%2 == 0:
        v0.append(ev)
    else:
        v1.append(ev)
 
mcv0 = Counter(v0).most_common(2)
mcv1 = Counter(v1).most_common(2)
cmcv0 = mcv0[0][1]
cmcv1 = mcv1[0][1]
ans = n - cmcv0 - cmcv1
if mcv0[0][0] == mcv1[0][0]:
    if (len(mcv0) == 1) and (len(mcv1) == 1):
        ans = int(n/2)
    elif (len(mcv0) == 1) and (len(mcv1) != 1):
        ans = n - cmcv0 - mcv1[1][1]
    elif (len(mcv0) != 1) and (len(mcv1) == 1):
        ans = n - mcv0[1][1] - cmcv1
    else:
        if cmcv0 > cmcv1:
            ans = n - cmcv0 - mcv1[1][1]
        else:
            ans = n - mcv0[1][1] - cmcv1
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

n = int(input())
v = list(map(int,input().split()))
v0 = []
v1 = []
for i,ev in enumerate(v):
    if i%2 == 0:
        v0.append(ev)
    else:
        v1.append(ev)

mcv0 = Counter(v0).most_common(2)
mcv1 = Counter(v1).most_common(2)
cmcv0 = mcv0[0][1]
cmcv1 = mcv1[0][1]
ans = n - cmcv0 - cmcv1
if mcv0[0][0] == mcv1[0][0]:
    if (len(mcv0) == 1) and (len(mcv1) == 1):
        ans = int(n/2)
    else:
        ans = max(n - mcv0[1][1] - cmcv1, n - cmcv1 - mcv1[1][1])
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

n = int(input())
v = list(map(int,input().split()))
v0 = []
v1 = []
for i,ev in enumerate(v):
    if i%2 == 0:
        v0.append(ev)
    else:
        v1.append(ev)

mcv0 = Counter(v0).most_common()
mcv1 = Counter(v1).most_common()
cmcv0 = mcv0[0][1]
cmcv1 = mcv1[0][1]
ans = n - cmcv0 - cmcv1
if mcv0[0][0] == mcv1[0][0]:
    if (len(mcv0) == 1) and (len(mcv1) == 1):
        ans = int(n/2)
    else:
        ans = max(n - mcv0[1][1] - cmcv1, n - cmcv1 - mcv1[1][1])
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

n = int(input())
v = list(map(int,input().split()))
v0 = []
v1 = []
for i,ev in enumerate(v):
    if i%2 == 0:
        v0.append(ev)
    else:
        v1.append(ev)

mcv0 = Counter(v0).most_common()
mcv1 = Counter(v1).most_common()
cmcv0 = mcv0[0][1]
cmcv1 = mcv1[0][1]
ans = n - cmcv0 - cmcv1
if mcv0[0][0] == mcv1[0][0]:
    if (len(mcv0) == 1) and (len(mcv1) == 1):
        ans = int(n/2)
    elif (len(mcv0) == 1) and (len(mcv1) != 1):
        ans = n - cmcv0 - mcv1[1][1]
    elif (len(mcv0) != 1) and (len(mcv1) == 1):
        ans = n - mcv0[1][1] - cmcv1
    else:
        if cmcv0 > cmcv1:
            ans = n - cmcv0 - mcv1[1][1]
        else:
            ans = n - mcv0[1][1] - cmcv1
print(ans)

Submission status: Wrong Answer

Solution code:
import collections

n = int(input())
v = list(map(int,input().split()))
v0 = []
v1 = []
for i,ev in enumerate(v):
    if i == 0:
        v0 = []
        v1 = []
    if i%2 == 0:
        v0.append(ev)
    else:
        v1.append(ev)

mcv0 = collections.Counter(v0).most_common()
mcv1 = collections.Counter(v1).most_common()
cmcv0 = mcv0[0][1]
cmcv1 = mcv1[0][1]
if mcv0[0][0] == mcv1[0][0]:
    if (len(mcv0) == 1) and (len(mcv1) == 1):
        cmcv1 = 0
    else:
        if cmcv0 > cmcv1:
            cmcv1 = mcv1[1][1]
        else:
            cmcv0 = mcv0[1][1]
print(n-cmcv0-cmcv1)

Submission status: Wrong Answer

Solution code:
import collections

n = int(input())
v = list(map(int,input().split()))
v0 = []
v1 = []
for i,ev in enumerate(v):
    if i == 0:
        v0 = []
        v1 = []
    if i%2 == 0:
        v0.append(ev)
    else:
        v1.append(ev)

mcv0 = collections.Counter(v0).most_common()
mcv1 = collections.Counter(v1).most_common()
cmcv0 = mcv0[0][1]
cmcv1 = mcv1[0][1]
if mcv0[0][0] == mcv1[0][0]:
    if len(mcv0) != 1:
        if cmcv0 > cmcv1:
            cmcv1 = mcv1[1][1]
        else:
            cmcv0 = mcv0[1][1]
    else:
        cmcv1 = 0
print(n-cmcv0-cmcv1)

Submission status: Wrong Answer

Solution code:
n=int(input())
v=list(map(int,input().split()))
vodd=[v[i] for i in range(n) if i%2==1]
veven=[v[i] for i in range(n) if i%2==0]
vodd.sort()
veven.sort()
def matome(l):
    result=[]
    a=l[0]
    b=0
    for i in range(len(l)):
        if l[i]==a:
            b+=1
        else:
            result.append([a,b])
            b=1
            a=l[i]
    result.append([a,b])
    return result
odd=matome(vodd)
odd.sort(key=lambda x:-x[1])
even=matome(veven)
even.sort(key=lambda x:-x[1])

if len(odd)==1 and len(even)==1:
    if odd[0][0]==even[0][0]:
        print(n-odd[0][1]-even[0][1])
    else:
        print(n//2)
elif len(odd)==1:
    if odd[0][0]==even[0][0]:
        print(n-odd[0][1]-even[1][1])
    else:
        print(n-odd[0][1]-even[0][1])
elif len(even)==1:
    if odd[0][0]==even[0][0]:
        print(n-odd[1][1]-even[0][1])
    else:
        print(n-odd[0][1]-even[0][1])
else:
    
    
    if odd[0][0]==even[0][0]:
        if odd[1][1]>even[1][1]:
            print(n-odd[1][1]-even[0][1])
        else:
            print(n-odd[0][1]-even[1][1])
            
    else:
        print(n-odd[0][1]-even[0][1])

Submission status: Wrong Answer

Solution code:
n=int(input())
v=list(map(int,input().split()))
vodd=[v[i] for i in range(n) if i%2==1]
veven=[v[i] for i in range(n) if i%2==0]
vodd.sort()
veven.sort()
def matome(l):
    result=[]
    a=l[0]
    b=0
    for i in range(len(l)):
        if l[i]==a:
            b+=1
        else:
            result.append([a,b])
            b=1
            a=l[i]
    result.append([a,b])
    return result
odd=matome(vodd)
odd.sort(key=lambda x:-x[1])
even=matome(veven)
even.sort(key=lambda x:-x[1])

if len(odd)==1 and len(even)==1:
    print(n//2)
elif len(odd)==1:
    if odd[0][0]==even[0][0]:
        print(n-odd[0][1]-even[1][1])
    else:
        print(n-odd[0][1]-even[0][1])
elif len(even)==1:
    if odd[0][0]==even[0][0]:
        print(n-odd[1][1]-even[0][1])
    else:
        print(n-odd[0][1]-even[0][1])
else:
    
    
    if odd[0][0]==even[0][0]:
        if odd[1][1]>even[1][1]:
            print(n-odd[1][1]-even[0][1])
        else:
            print(n-odd[0][1]-even[1][1])
            
    else:
        print(n-odd[0][1]-even[0][1])

Submission status: Wrong Answer

Solution code:
n = int(input())

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

s = []
t = []


import collections

for i in range(0,n//2,2):
	s.append(v[i])
for i in range(1,n//2,2):
	t.append(v[i])

S = collections.Counter(s)
	
T = collections.Counter(t)

x = S.most_common()[0][0]  

z = T.most_common()[0][0]

print(n-s.count(x)-t.count(z))

Submission status: Wrong Answer

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

list_odd = list[::2]
list_even = list[1::2]

def cnt_element(x):
    dict = {}
    for i in x:
        if i not in dict:
            dict[i] = 1
        else:
            dict[i] += 1
    return [(v,k) for k,v in dict.items()]

cnt_odd = sorted(cnt_element(list_odd),reverse=True)
cnt_even = sorted(cnt_element(list_even),reverse=True)

#最頻値が同じの場合
if cnt_odd[0][1] == cnt_even[0][1]:
    #リスト内の値が１つの場合
    if len(cnt_odd) or len(cnt_even) == 1:
        ans =  int(n / 2)
    #リストが２つ以上の場合
    else:
        #第２最頻値の出現数が奇数の方が多い
        if cnt_odd[1][0] > cnt_even[1][0]:
            ans = n - cnt_odd[1][0] - cnt_even[0][0]
        #第二２最頻値の出現数が偶数の方が多い
        elif cnt_odd[1][0] < cnt_even[1][0]:
            ans = n - cnt_odd[0][0] - cnt_even[1][0]
#最頻値が異なる場合
else:
    ans = n - cnt_odd[0][0] - cnt_even[0][0]

print(ans)

Submission status: Wrong Answer

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

list_odd = list[::2]
list_even = list[1::2]

def cnt_element(x):
    dict = {}
    for i in x:
        if i not in dict:
            dict[i] = 1
        else:
            dict[i] += 1
    return [(v,k) for k,v in dict.items()]

cnt_odd = sorted(cnt_element(list_odd),reverse=True)
cnt_even = sorted(cnt_element(list_even),reverse=True)

#最頻値が同じの場合
if cnt_odd[0][1] == cnt_even[0][1]:
    #リスト内の値が１つの場合
    if len(cnt_odd) or len(cnt_even) == 1:
        ans =  int(n / 2)
    #リストが２つ以上の場合
    else:
        #第２最頻値の出現数が奇数の方が多い
        if cnt_odd[1][0] > cnt_even[1][0]:
            ans = n - cnt_odd[1][0] - cnt_even[0][0]
        #第二２最頻値の出現数が偶数の方が多い
        elif cnt_odd[1][0] < cnt_even[1][0]:
            ans = n - cnt_odd[0][0] - cnt_even[1][0]
#最頻値が異なる場合
else:
    ans = n - cnt_odd[0][0] - cnt_even[0][1]

print(ans)

Submission status: Wrong Answer

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

list_odd = list[::2]
list_even = list[1::2]

def cnt_element(x):
    dict = {}
    for i in x:
        if i not in dict:
            dict[i] = 1
        else:
            dict[i] += 1
    return [(v,k) for k,v in dict.items()]

cnt_odd = sorted(cnt_element(list_odd),reverse=True)
cnt_even = sorted(cnt_element(list_even),reverse=True)

#最頻値が同じの場合
if cnt_odd[0][1] == cnt_even[0][1]:
    #リスト内の値が１つの場合
    if len(cnt_odd) or len(cnt_even) == 1:
        ans =  n / 2
    #リストが２つ以上の場合
    else:
        #第２最頻値の出現数が奇数の方が多い
        if cnt_odd[1][0] > cnt_even[1][0]:
            ans = n - cnt_odd[1][0] - cnt_even[0][0]
        #第二２最頻値の出現数が偶数の方が多い
        elif cnt_odd[1][0] < cnt_even[1][0]:
            ans = n - cnt_odd[0][0] - cnt_even[1][0]
#最頻値が異なる場合
else:
    ans = n - cnt_odd[0][0] - cnt_even[0][1]

print(ans)

Submission status: Wrong Answer

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

list_odd = list[::2]
list_even = list[1::2]

def cnt_element(x):
    dict = {}
    for i in x:
        if i not in dict:
            dict[i] = 1
        else:
            dict[i] += 1
    return [(v,k) for k,v in dict.items()]

cnt_odd = sorted(cnt_element(list_odd),reverse=True)
cnt_even = sorted(cnt_element(list_even),reverse=True)

#最頻値が同じの場合
if cnt_odd[0][1] == cnt_even[0][1]:
    #リスト内の値が１つの場合
    if len(cnt_odd) or len(cnt_even) == 1:
        ans =  n //2
    #リストが２つ以上の場合
    else:
        #第２最頻値の出現数が奇数の方が多い
        if cnt_odd[1][0] > cnt_even[1][0]:
            ans = n - cnt_odd[1][0] - cnt_even[0][0]
        #第二２最頻値の出現数が偶数の方が多い
        elif cnt_odd[1][0] < cnt_even[1][0]:
            ans = n - cnt_odd[0][0] - cnt_even[1][0]
#最頻値が異なる場合
else:
    ans = n - cnt_odd[0][0] - cnt_even[0][1]

print(ans)

Submission status: Wrong Answer

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

even = {}
odd = {}
for i in range(0, n, 2):
    even[v[i + 1]] = even.get(v[i + 1], 0) + 1
    odd[v[i]] = odd.get(v[i], 0) + 1

max_even = 0
max_even_key = 0
second_max_even = -1
for key, value in even.items():
    if max_even <= value:
        second_max_even = max_even
        max_even = value
        max_even_key = key

max_odd = 0
max_odd_key = 0
second_max_odd = -1
for key, value in odd.items():
    if max_odd <= value:
        second_max_odd = max_odd
        max_odd = value
        max_odd_key = key

if max_even_key != max_odd_key:
    ans = n - max_even - max_odd
else:
    ans = min(n - second_max_even - max_odd, n - max_even - second_max_odd)

print(int(ans))

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

ki = v[::2]
gu = v[1::2]

ki = Counter(ki)
gu = Counter(gu)

ki = ki.most_common()
gu = gu.most_common()

if ki[0][0] == gu[0][0] :
    if len(ki) == 1 and len(gu) == 1 :
        print(n/2)
    else :
        if ki[1][1] > gu[1][1]  :
            print(n-ki[1][1]-gu[0][1])
        else :
            print(n-ki[0][1]- gu[1][1])

else :
    print(n-ki[0][1]-gu[0][1])

Submission status: Wrong Answer

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

even = {}
odd = {}
for i in range(0, n, 2):
    even[v[i + 1]] = even.get(v[i + 1], 0) + 1
    odd[v[i]] = odd.get(v[i], 0) + 1

max_even = 0
max_even_key = 0
second_max_even = -1
for key, value in even.items():
    if max_even <= value:
        second_max_even = max_even
        max_even = value
        max_even_key = key

max_odd = 0
max_odd_key = 0
second_max_odd = -1
for key, value in odd.items():
    if max_odd <= value:
        second_max_odd = max_odd
        max_odd = value
        max_odd_key = key

if max_even_key != max_odd_key:
    ans = n / 2 - max_even
    ans += n / 2 - max_odd
else:
    ans = min(n / 2 - second_max_even + n / 2 - max_odd, n /2 - max_even + n / 2 - second_max_odd)

print(int(ans))

Submission status: Wrong Answer

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

even = {}
odd = {}
for i in range(0, n, 2):
    even[v[i + 1]] = even.get(v[i + 1], 0) + 1
    odd[v[i]] = odd.get(v[i], 0) + 1

max_even = 0
max_even_key = 0
second_max_even = -1
for key, value in even.items():
    if max_even < value:
        second_max_even = max_even
        max_even = value
        max_even_key = key

max_odd = 0
max_odd_key = 0
second_max_odd = -1
for key, value in odd.items():
    if max_odd < value:
        second_max_odd = max_odd
        max_odd = value
        max_odd_key = key

if max_even_key != max_odd_key:
    ans = n - max_even - max_odd
else:
    ans = min(n - second_max_even - max_odd, n - max_even - second_max_odd)

print(int(ans))