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())
l=list(map(int,input().split()))
if len(set(l))==1:print(n//2)
else:
  x,y=sorted(l[::2]),sorted(l[1::2])
  from collections import Counter as co
  ans=0
  mx,my=co(x).most_common(100),co(y).most_common(100)
  for i in mx:
    for j in my:
      ans=max(ans,i[1]+j[1])
  print(n-ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
v = list(map(int,input().split()))
ans = 0
for i in range(N-2):
    if v[i] != v[i+2]:
        v[i+2] = v[i]
        ans += 1
    else:
        if v[i] == v[i+1]:
            v[i+1] = v[i]
            ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
v = list(map(int, input().split()))
e = []
o = []
for i in range(n):
    if i % 2 == 0:
        e.append(v[i])
    else:
        o.append(v[i])

even = collections.Counter(e)
odd = collections.Counter(o)

# print(even.most_common()[0][1])
# print(odd.most_common()[0][1])
# print(even, odd)
answer = n - even.most_common()[0][1] - odd.most_common()[0][1]
if even.most_common()[0][0] == odd.most_common()[0][0] and answer == 0:
    print(n // 2)
else:
    print(answer)

Submission status: Wrong Answer

Solution code:
n = int(input())
l = list(map(int, input().split()))
p = list(set(l))

if len(p) == 1:
    print(int(len(l)/2))
    exit()

gu, ki = [], []
for i in range(n):
    if i % 2 == 0:
        gu.append(l[i])
    else:
        ki.append(l[i])

gu.sort(reverse=1)
ki.sort(reverse=1)
gu_max =gu[0] 
ki_max =ki[0] 

x = 0
for j in range(int(len(l)/2)):
    if gu[j] != gu_max:
        x += 1
    if ki[j] != ki_max:
        x += 1
print(x)

Submission status: Wrong Answer

Solution code:
from collections import Counter
import sys

n = int(input())
v = [int(i) for i in input().split()]
sla = Counter(v[::2]).most_common()[0][0]
bsla = Counter(v[1::2]).most_common()[0][0]
ans = 0
for i in range(n):
    j = bsla if i % 2 else sla
    if v[i] != j:
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
import sys

n = int(input())
v = [int(i) for i in input().split()]
s = set(v)
if len(s) == 1:
    print(n//2)
    sys.exit()

sla = Counter(v[::2]).most_common()[0][0]
bsla = Counter(v[1::2]).most_common()[0][0]
ans = 0
for i in range(n):
    j = bsla if i % 2 else sla
    if v[i] != j:
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

Vodd = V[: len(V):2]
Veven = V[1: len(V):2]

if Vodd == Veven:
    print(n // 2)
    exit()


Voc = Counter(Vodd)
Vec = Counter(Veven)

Voc_val, Voc_cnt = zip(*Voc.most_common())
Vec_val, Vec_cnt = zip(*Vec.most_common())

Voc_val, Voc_cnt = list(Voc_val), list(Voc_cnt)
Vec_val, Vec_cnt = list(Vec_val), list(Vec_cnt)

num = Voc.most_common()[0][1] + Vec.most_common()[0][1]

if Voc_val[0] == Vec_val[0]:
    Voc_cnt.append(0)
    Vec_cnt.append(0)
    num += max(Voc_cnt[1] - Voc_cnt[0], Vec_cnt[1] - Vec_cnt[0])

print(n - num)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

Vodd = V[: len(V):2]
Veven = V[1: len(V):2]

if Vodd == Veven:
    print(n // 2)


Voc = Counter(Vodd)
Vec = Counter(Veven)

Voc_val, Voc_cnt = zip(*Voc.most_common())
Vec_val, Vec_cnt = zip(*Vec.most_common())

Voc_val, Voc_cnt = list(Voc_val), list(Voc_cnt)
Vec_val, Vec_cnt = list(Vec_val), list(Vec_cnt)

num = Voc.most_common()[0][1] + Vec.most_common()[0][1]

if Voc_val[0] == Vec_val[0]:
    Voc_cnt.append(0)
    Vec_cnt.append(0)
    num += max(Voc_cnt[1] - Voc_cnt[0], Vec_cnt[1] - Vec_cnt[0])

print(n - num)

Submission status: Wrong Answer

Solution code:
n=int(input())
v=list(map(int,input().split()))
v1 = [v[2*i] for i in range(n//2)]

if len(set(v))==1:
    print(n//2)
    exit()
d1 = {}
for x in v1:
    if x in d1.keys():
        d1[x] = d1[x] + 1
    else:
        d1[x] = 1
d1 = sorted(d1.items(), key=lambda x:-x[0])

d2 = {}
v2 = [v[2*i+1] for i in range(n//2)]
ma2=0
for x in v2:
    if x in d2.keys():
        d2[x] = d2[x] + 1
    else:
        d2[x] = 1
d2 = sorted(d2.items(), key=lambda x:-x[0])
if d1[0][0] != d2[0][0]:
    print(n-d1[0][1]-d2[0][1])
else:
    if len(d1) == 1:
        print(n-d1[0][1]-d2[1][1])
    elif len(d2) == 1:
        print(n-d1[1][1]-d2[0][1])
    else:
        print(n-max(d1[0][1]+d2[1][1],d1[1][1]+d2[0][1]))

Submission status: Wrong Answer

Solution code:
n=int(input())
v=list(map(int,input().split()))
v1 = [v[2*i] for i in range(n//2)]

if len(set(v))==1:
    print(n//2)
    exit()
d1 = {}
for x in v1:
    if x in d1.keys():
        d1[x] = d1[x] + 1
    else:
        d1[x] = 1
d1 = sorted(d1.items(), key=lambda x:-x[0])

d2 = {}
v2 = [v[2*i+1] for i in range(n//2)]
ma2=0
for x in v2:
    if x in d2.keys():
        d2[x] = d2[x] + 1
    else:
        d2[x] = 1
d2 = sorted(d2.items(), key=lambda x:-x[0])
if d1[0][0] != d2[0][0]:
    print(n-d1[0][1]-d2[0][1])
else:
    print(n-max(d1[0][1]+d2[1][1],d1[1][1]+d2[0][1]))

Submission status: Wrong Answer

Solution code:
n=int(input())
v=list(map(int,input().split()))
v1 = [v[2*i] for i in range(n//2)]

if len(set(v))==1:
    print(n//2)
    exit()
d = {}
for x in v1:
    if x in d.keys():
        d[x] = d[x] + 1
    else:
        d[x] = 1
ma1 = max(d.values())
d = {}
v2 = [v[2*i+1] for i in range(n//2)]
ma2=0
for x in v2:
    if x in d.keys():
        d[x] = d[x] + 1
    else:
        d[x] = 1
ma2 = max(d.values())
print(n-ma1-ma2)

Submission status: Wrong Answer

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

odd = Counter([x for x in v[0::2]])
even = Counter([x for x in v[1::2]])

if odd == even:
    print(n//2)
elif len(odd) == len(even):
    print(0)
else:
    print(sum(odd.values())-max(odd.values()) + sum(even.values())-max(even.values()))

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

Vodd = V[: len(V):2]
Veven = V[1: len(V):2]

for i in range(n):
    if V[0] != V[i]:
        break
    elif i == n - 1:
        print(min(len(Veven), len(Vodd)))
        exit()


Voc = Counter(Vodd)
Vec = Counter(Veven)

num = Voc.most_common()[0][1] + Vec.most_common()[0][1]


if Voc.most_common()[0][0] == Vec.most_common()[0][0]:
    if len(Vodd) - Voc.most_common()[0][1] < len(Veven) - Vec.most_common()[0][1]:
        num -= Voc.most_common()[0][1]
        num += Voc.most_common()[1][1]
    else:
        num -= Vec.most_common()[0][1]
        num += Vec.most_common()[1][1]


print(n - num)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

Vodd = V[: len(V):2]
Veven = V[1: len(V):2]

for i in range(n):
    if V[0] != V[i]:
        break
    elif i == n - 1:
        print(min(len(Veven), len(Vodd)))
        exit()


Voc = Counter(Vodd)
Vec = Counter(Veven)

num = Voc.most_common()[0][1] + Voc.most_common()[0][1]

if Voc.most_common()[0][0] == Vec.most_common()[0][0]:
    if len(Vodd) - Voc.most_common()[0][1] < len(Veven) - Vec.most_common()[0][1]:
        num -= Voc.most_common()[0][1]
        num += Voc.most_common()[1][1]
    else:
        num -= Vec.most_common()[0][1]
        num += Vec.most_common()[1][1]


print(n - num)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

Vodd = V[: len(V):2]
Veven = V[1: len(V):2]

for i in range(n):
    if V[0] != V[i]:
        break
    elif i == n - 1:
        print(min(len(Veven), len(Vodd)))
        exit()


Voc = Counter(Vodd)
Vec = Counter(Veven)

num = Voc.most_common()[0][1] + Voc.most_common()[0][1]

if Voc.most_common()[0][0] == Vec.most_common()[0][0]:
    if len(Vodd) - Voc.most_common()[0][1] < len(Veven) - Voc.most_common()[0][1]:
        num -= Voc.most_common()[0][1]
        num += Voc.most_common()[1][1]
    else:
        num -= Vec.most_common()[0][1]
        num += Vec.most_common()[1][1]


print(n - num)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

Vodd = V[: len(V):2]
Veven = V[1: len(V):2]

for i in range(n):
    if V[0] != V[i]:
        break
    elif i == n - 1:
        print(min(len(Veven), len(Vodd)))
        exit()


Voc = Counter(Vodd)
Vec = Counter(Veven)

num = Voc.most_common()[0][1] + Vec.most_common()[0][1]

print(n - num)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
n = int(input())
v = list(map(int,input().split()))
a = v[::2]
b = v[1::2]
def calc(l):
    d = defaultdict(int)
    for x in l:
        d[x] += 1
    return sorted([(d[x], x) for x in d],reverse=True)
A = calc(a)
B = calc(b)
al,ax = A[0]
bl,bx = B[0]
if ax != bx:
    print(n-al-bl)
elif al > bl:
    if len(B) > 1:
        bl,bx = B[1]
    print(n-al-bl)
elif al < bl:
    if len(A) > 1:
        al,ax = A[1]
    print(n-al-bl)
else:
    print(n//2)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
n = int(input())
v = list(map(int,input().split()))
a = v[::2]
b = v[1::2]
def calc(l):
    d = defaultdict(int)
    for x in l:
        d[x] += 1
    return sorted([(d[x], x) for x in d],reverse=True)
A = calc(a)
B = calc(b)
al,ax = A[0]
bl,bx = B[0]
print(a,b)
if ax != bx:
    print(n-al-bl)
elif al > bl:
    if len(B) > 1:
        bl,bx = B[1]
    print(n-al-bl)
elif al < bl:
    if len(A) > 1:
        al,ax = A[1]
    print(n-al-bl)
else:
    print(n//2)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
n = int(input())
v = list(map(int,input().split()))
a = v[::2]
b = v[1::2]
def calc(l):
    d = defaultdict(int)
    for x in l:
        d[x] += 1
    return sorted([(d[x], x) for x in d])
A = calc(a)
B = calc(b)
al,ax = A[0]
bl,bx = B[0]
if ax != bx:
    print(n-al-bl)
elif al > bl:
    if len(B) > 1:
        bl,bx = B[1]
    print(n-al-bl)
elif al < bl:
    if len(A) > 1:
        al,ax = A[1]
    print(n-al-bl)
else:
    print(n//2)

Submission status: Wrong Answer

Solution code:
import collections

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

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

counter1 = collections.Counter(l1)
counter2 = collections.Counter(l2)

mode_v1 = counter1.most_common()
mode_v2 = counter2.most_common()
# print(mode_v1, mode_v2)

if mode_v1[0][0] != mode_v2[0][0]:
    print(n - mode_v1[0][1] - mode_v2[0][1])
else:
    print(n // 2 )

Submission status: Wrong Answer

Solution code:
import collections

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

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

counter1 = collections.Counter(l1)
counter2 = collections.Counter(l2)

mode_v1 = counter1.most_common()
mode_v2 = counter2.most_common()
print(mode_v1, mode_v2)

if mode_v1[0][0] != mode_v2[0][0]:
    print(n - mode_v1[0][1] - mode_v2[0][1])
else:
    print(n // 2 )

Submission status: Wrong Answer

Solution code:
# ABC111c
from collections import Counter
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 6)


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

ans = 0
for i in range(len(v)):
    if i % 2 == 0:
        if v[i] != f:
            ans += 1
    else:
        if v[i] != f2:
            ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
# ABC111c
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

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

f = v[0]
f2 = ''

for i in v:
    if i != f:
        f2 = i
        break
ans = 0
for i in range(len(v)):
    if i % 2 == 0:
        if v[i] != f:
            ans += 1
    else:
        if v[i] != f2:
            ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())

arr = [int(s) for s in input().split(" ")]

def calculate(n, arr):
    evenDict = {}
    oddDict = {}

    for i in range(0, n, 2):
        if oddDict.get(arr[i]) == None:
            oddDict.__setitem__(arr[i], 1)
        else:
            oddDict.__setitem__(arr[i], oddDict.get(arr[i]) + 1)

    for i in range(1, n, 2):
        if evenDict.get(arr[i]) == None:
            evenDict.__setitem__(arr[i], 1)
        else:
            evenDict.__setitem__(arr[i], evenDict.get(arr[i]) + 1)

    if (len(evenDict.values()) == 1) and (len(oddDict.values()) == 1):
        if arr[0] == arr[1]:
            return n // 2

    evenMaxIndex = max(evenDict, key=evenDict.get)
    oddMaxIndex = max(oddDict, key=oddDict.get)

    s1 = (n // 2) - evenDict[evenMaxIndex]

    s2 = (n - n // 2) - oddDict[oddMaxIndex]

    return (s1 + s2)


result = calculate(n, arr)

print(result)

Submission status: Wrong Answer

Solution code:
n = int(input())

arr = [int(s) for s in input().split(" ")]

def calculate(n, arr):
    even = []
    odd = []
    evenDict = {}
    oddDict = {}

    for i in range(0, n, 2):
        odd.append(arr[i])
        if oddDict.get(arr[i]) == None:
            oddDict.__setitem__(arr[i], 1)
        else:
            oddDict.__setitem__(arr[i], oddDict.get(arr[i]) + 1)

    for i in range(1, n, 2):
        even.append(arr[i])
        if evenDict.get(arr[i]) == None:
            evenDict.__setitem__(arr[i], 1)
        else:
            evenDict.__setitem__(arr[i], evenDict.get(arr[i]) + 1)

    if (len(evenDict.values()) == 1) and (len(oddDict.values()) == 1):
        if even[0] == odd[0]:
            return n // 2

    evenMaxIndex = max(evenDict, key=evenDict.get)
    oddMaxIndex = max(oddDict, key=oddDict.get)

    s1 = len(even) - evenDict[evenMaxIndex]

    s2 = len(odd) - oddDict[oddMaxIndex]

    return (s1 + s2)


result = calculate(n, arr)

print(result)

Submission status: Wrong Answer

Solution code:
n = int(input())
vg = [0 for i in range(10**5+1)]
vk = [0 for i in range(10**5+1)]
v = [int(x) for x in input().rstrip().split()]


for i in range(n):
    if i%2 == 0:
        vg[v[i]-1]+=1
    else:
        vk[v[i]-1]+=1
vg_max = max(vg)
vk_max = max(vk)

if vg == vk:
    print(n//2)
else:

    print(n-vg_max-vk_max)

Submission status: Wrong Answer

Solution code:
n = int(input())
vg = [0 for i in range(10**5)]
vk = [0 for i in range(10**5)]
v = [int(x) for x in input().rstrip().split()]


for i in range(n):
    if i%2 == 0:
        vg[v[i]-1]+=1
    else:
        vk[v[i]-1]+=1
vg_max = max(vg)
vk_max = max(vk)

if vg == vk:
    print(n//2)
else:

    print(n-vg_max-vk_max)

Submission status: Wrong Answer

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

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

d_odds = {}
d_even = {}

for i in range(0, len(v), 2):
    if v[i] in d_even:
        d_even[v[i]] += 1
    else:
        d_even[v[i]] = 1
    
for i in range(1, len(v), 2):
    if v[i] in d_odds:
        d_odds[v[i]] += 1
    else:
        d_odds[v[i]] = 1
 
max_freq_even = max(d_even.values())
max_freq_odds = max(d_odds.values())

print(n - max_freq_even - max_freq_odds)

Submission status: Wrong Answer

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

lis1 = [v[i] for i in range(n) if i%2==0]
lis2 = [v[i] for i in range(n) if i%2!=0]

c1 = collections.Counter(lis1).most_common()
c2 = collections.Counter(lis2).most_common()
c1.append((0,0)) #len(set(lis1))==1対策
c2.append((0,0)) #len(set(lis2))==1対策

m=n//2 #n:even
if lis1==lis2: print(m)
else:
    if c1[0][0]!=c2[0][0]:#最頻値が異なる場合
        print(m-c1[0][1] + m-c2[0][1])
    else:#最頻値が同じである場合
        p1 = m-c1[0][1] + m-c2[1][1]
        p2 = m-c1[1][1] + m-c2[0][1]
        print(min(p1,p2))

Submission status: Wrong Answer

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

lis1 = [v[i] for i in range(n) if i%2==0]
lis2 = [v[i] for i in range(n) if i%2!=0]

c1 = collections.Counter(lis1)
c2 = collections.Counter(lis2)

m=n//2 #n:even
if lis1==lis2: print(m)
else:
    val1 = c1.most_common()[0][0] #lis1における最頻値
    val2 = c2.most_common()[0][0] #lis2における最頻値
    c1_1 = c1.most_common()[0][1] #最頻値の個数
    c1_2 = c1.most_common()[1][1] if len(set(lis1))>1 else c1_1 #二番目に多い値の個数
    c2_1 = c2.most_common()[0][1] #最頻値の個数
    c2_2 = c2.most_common()[1][1] if len(set(lis2))>1 else c2_1 #二番目に多い値の個数
    if val1!=val2:#最頻値が異なる場合
        print(m-c1_1 + m-c2_1)
    else:#最頻値が同じである場合
        p1 = m-c1_1 + m-c2_2
        p2 = m-c1_2 + m-c2_1
        print(min(p1,p2))

Submission status: Wrong Answer

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

lis1 = [v[i] for i in range(n) if i%2==0]
lis2 = [v[i] for i in range(n) if i%2!=0]

c1 = collections.Counter(lis1)
c2 = collections.Counter(lis2)

if lis1==lis2: print(n//2)
else:
    c1_1 = c1.most_common()[0][1] #一番多い
    c1_2 = c1.most_common()[1][1] if len(set(lis1))>1 else c1_1 #二番目に多い
    c2_1 = c2.most_common()[0][1]
    c2_2 = c2.most_common()[1][1] if len(set(lis2))>1 else c2_1
    p1 = n//2-c1_1 + n//2-c2_2
    p2 = n//2-c1_2 + n//2-c2_1
    print(min(p1,p2))

Submission status: Wrong Answer

Solution code:
import collections

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

lis1 = [v[i] for i in range(n) if i%2==0]
lis2 = [v[i] for i in range(n) if i%2!=0]

c1 = collections.Counter(lis1)
c2 = collections.Counter(lis2)

if lis1==lis2: print(n//2)
else: print(n//2-c1.most_common()[0][1] + n//2-c2.most_common()[0][1])

Submission status: Wrong Answer

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

l_odd = []
l_even = []
for i, value in enumerate(v, 1):
  # 偶数番目と奇数番目の要素のリストをそれぞれつくる
  if i % 2 == 1:
    l_odd.append(value)
  else:
    l_even.append(value)

# それぞれのリストで一番たくさん出てくる要素の数を数える
co = collections.Counter(l_odd)
ce = collections.Counter(l_even)
mc_odd = co.most_common()[0][1]
mc_even = ce.most_common()[0][1] 

ans = 0

if co.most_common()[0][0] == ce.most_common()[0][0]:
  if co.most_common()[0][1] == len(l_odd):
    ans = co.most_common()[0][1]
  elif ce.most_common()[0][1] == len(l_even):
    ans = ce.most_common()[0][1]
  else:
    ans = min(co.most_common()[0][1] - ce.most_common()[1][1], co.most_common()[1][1] - ce.most_common()[0][1])
  print(ans)
else:
  print(n - co.most_common()[0][1] - ce.most_common()[0][1])

Submission status: Wrong Answer

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

l_odd = []
l_even = []
for i, value in enumerate(v, 1):
  # 偶数番目と奇数番目の要素のリストをそれぞれつくる
  if i % 2 == 1:
    l_odd.append(value)
  else:
    l_even.append(value)

# それぞれのリストで一番たくさん出てくる要素の数を数える
co = collections.Counter(l_odd)
ce = collections.Counter(l_even)
mc_odd = co.most_common()[0][1]
mc_even = ce.most_common()[0][1] 

ans = 0
if co.most_common()[0][0] == ce.most_common()[0][0]:
  if co.most_common()[0][1] == len(l_odd):
    ans = co.most_common()[0][1]
  else:
    ans = min(co.most_common()[0][1] - ce.most_common()[1][1], co.most_common()[1][1] - ce.most_common()[0][1])
  print(ans)
else:
  print(n - co.most_common()[0][1] - ce.most_common()[0][1])

Submission status: Wrong Answer

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

l_odd = []
l_even = []
for i, value in enumerate(v, 1):
  # 偶数番目と奇数番目の要素のリストをそれぞれつくる
  if i % 2 == 1:
    l_odd.append(value)
  else:
    l_even.append(value)

# それぞれのリストで一番たくさん出てくる要素の数を数える
co = collections.Counter(l_odd)
ce = collections.Counter(l_even)
mc_odd = co.most_common()[0][1]
mc_even = ce.most_common()[0][1] 

ans = 0

# それぞれのリストの差分をたす
if mc_odd != len(l_odd):
  ans += len(l_odd) - mc_odd
if mc_even != len(l_even):
  ans += len(l_even) - mc_even

# 一番多い数が同じか比較
if co.most_common()[0][0]  == ce.most_common()[0][0]:
    ans += len(l_odd) if len(l_odd) - mc_odd <= len(l_even) - mc_even else len(l_even) - mc_even

print(ans)

Submission status: Wrong Answer

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

l_odd = []
l_even = []
for i, value in enumerate(v, 1):
  # 偶数番目と奇数番目の要素のリストをそれぞれつくる
  if i % 2 == 1:
    l_odd.append(value)
  else:
    l_even.append(value)

# それぞれのリストで一番たくさん出てくる要素の数を数える
co = collections.Counter(l_odd)
ce = collections.Counter(l_even)
mc_odd = co.most_common()[0][1]
mc_even = ce.most_common()[0][1] 

ans = 0

if mc_odd != len(l_odd):
  ans += len(l_odd) - mc_odd
if mc_even != len(l_even):
  ans += len(l_even) - mc_even

if co.most_common()[0][0]  == ce.most_common()[0][0]:
    ans += len(l_odd)

print(ans)

Submission status: Wrong Answer

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

l_odd = []
l_even = []
for i, value in enumerate(v, 1):
  # 偶数番目と奇数番目の要素のリストをそれぞれつくる
  if i % 2 == 1:
    l_odd.append(value)
  else:
    l_even.append(value)

# それぞれのリストで一番たくさん出てくる要素の数を数える
co = collections.Counter(l_odd)
ce = collections.Counter(l_even)
mc_odd = co.most_common()[0][1]
mc_even = ce.most_common()[0][1] 

ans = 0

if mc_odd != len(l_odd):
  ans += len(l_odd) - mc_odd
else:
  if co.most_common()[0][0]  == ce.most_common()[0][0]:
    ans += len(l_odd)
  else:
    if mc_even != len(l_even):
      ans += len(l_even) - mc_even
 
print(ans)

Submission status: Wrong Answer

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

l_odd = []
l_even = []
for i, value in enumerate(v, 1):
  # 偶数番目と奇数番目の要素のリストをそれぞれつくる
  if i % 2 == 1:
    l_odd.append(value)
  else:
    l_even.append(value)

# それぞれのリストで一番たくさん出てくる要素の数を数える
co = collections.Counter(l_odd)
ce = collections.Counter(l_even)
mc_odd = co.most_common()[0][1]
mc_even = ce.most_common()[0][1] 

ans = 0

if mc_odd != len(l_odd):
  ans += len(l_odd) - mc_odd
else:
  if co.most_common()[0][0]  == ce.most_common()[0][0]:
    ans += len(l_odd)

if mc_even != len(l_even):
  ans += len(l_even) - mc_even
 
print(ans)

Submission status: Wrong Answer

Solution code:
import collections 
n = int(input())
v = list(map(int,input().split()))
cnt = 0
e = []
o = []
for i in range(n):
    if (i+1) % 2 == 0:
        e.append(v[i])
    else:
        o.append(v[i])
E = collections.Counter(e)
O = collections.Counter(o)
list_e = []
list_o = []
set_e = set(e)
set_o = set(o)
E_1 = E.most_common()[0][0]
if len(set_e) != 1:
    E_2 = E.most_common()[1][0]
else:
    E_2 = E.most_common()[0][0]

O_1 = O.most_common()[0][0]
if len(set_o) != 1:
    O_2 = O.most_common()[1][0]
else:
    O_2 = O.most_common()[0][0]

if E_1 != O_1:
    ans = n - E.most_common()[0][1] - O.most_common()[0][1]
else:
    ans = min(n-E_2-O_1,n-E_1-O_2)
print(ans)

Submission status: Wrong Answer

Solution code:
from itertools import groupby
def main():
    _=input()
    vv=list(map(int,input().split()))
    ve=sorted(vv[0::2])
    vo=sorted(vv[1::2])
    le=len(set(ve))
    lo=len(set(vo))
    if le==lo==1:
        if ve[0]!=vo[0]:
            print(0)
            return
        else:
            print(len(ve))
            return
    if le==1 or lo==1:
        if lo==1:
            ve,vo=vo,ve
        c=0
        for k,g in groupby(vo):
            if k!=ve[0]:
                lg=len(list(g))
                if lg>c:
                    c=lg
        print(len(vo)-c)
        return
    ce=0
    ke=None
    for k,g in groupby(ve):
        lg=len(list(g))
        if lg>ce:
            ke=k
            ce=lg
    co=0
    ko=None
    for k,g in groupby(vo):
        lg=len(list(g))
        if lg>co:
            ko=k
            co=lg
    if ke!=ko:
        print(len(vo)*2-ce-co)
        return
    if ce<co:
        ke,ko=ko,ke
        ve,vo=vo,ve
        ce,co=co,ce
    c=0 
    for k,g in groupby(vo):
        if k!=ke:
            lg=len(list(g))
            if lg>c:
               c=lg
    print(len(vo)*2-c-ce)

main()

Submission status: Wrong Answer

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

tmp_even = {}
tmp_odd = {}

for i in range(N):
    u = U[i]
    if i % 2 == 0:
        if u not in tmp_even:
            tmp_even[u] = 0
        tmp_even[u] += 1
    else:
        if u not in tmp_odd:
            tmp_odd[u] = 0
        tmp_odd[u] += 1

even = [(e, tmp_even[e]) for e in tmp_even]
odd = [(o, tmp_odd[o]) for o in tmp_odd]
# print(even)
# print(odd)

even.sort(reverse=True, key = lambda x: x[1])
odd.sort(reverse=True, key = lambda x: x[1])
# print(even)
# print(odd)

if even[0][0] != odd[0][0]:
    print(N - even[0][1] - odd[0][1])
    exit()
if len(even) == 1 and len(odd) == 1:
    print(N // 2)
    exit()
if even[0][1] > odd[0][1]:
    print(N - even[0][1] - odd[1][1])
else:
    print(N - even[1][1] - odd[0][1])

Submission status: Wrong Answer

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

tmp_even = {}
tmp_odd = {}

for i in range(N):
    u = U[i]
    if i % 2 == 0:
        if u not in tmp_even:
            tmp_even[u] = 0
        tmp_even[u] += 1
    else:
        if u not in tmp_odd:
            tmp_odd[u] = 0
        tmp_odd[u] += 1

even = [(e, tmp_even[e]) for e in tmp_even]
odd = [(o, tmp_odd[o]) for o in tmp_odd]
# print(even)
# print(odd)

even.sort(reverse=True, key = lambda x: x[1])
odd.sort(reverse=True, key = lambda x: x[1])
# print(even)
# print(odd)

if even[0][0] != odd[0][0]:
    print(N - even[0][1] - odd[0][1])
    exit()
if len(even) == len(odd):
    print(N // 2)
    exit()
if even[0][1] > odd[0][1]:
    print(N - even[0][1] - odd[1][1])
else:
    print(N - even[1][1] - odd[0][1])

Submission status: Wrong Answer

Solution code:
def chkmax(ecnt):
    emax1=ecnt[0]
    vemax1=0
    if ecnt[1]>emax1:
        emax1=ecnt[1]
        vemax1=1
        emax2=ecnt[0]
    else:
        emax2=ecnt[1]
        
    for i in range(2,len(ecnt)):
        if ecnt[i]>emax1:
            emax2=emax1
            emax1=ecnt[i]
            vemax1=i
        elif ecnt[i]<=emax1 and ecnt[i]>emax2:
            emax2=ecnt[i]
    return emax1,emax2,vemax1    

n=int(input())
v=list(map(int,input().split()))
vmax=max(v)
vmin=min(v)

n2=n//2
ecnt=[0]*(vmax+1)
ocnt=[0]*(vmax+1)
for i in range(n2):
    ecnt[v[i*2]]=ecnt[v[i*2]]+1
    ocnt[v[i*2+1]]=ocnt[v[i*2+1]]+1

if vmax==vmin:
    print(n2)
else:
    emax1,emax2,vemax1=chkmax(ecnt)            
    omax1,omax2,vomax1=chkmax(ocnt)
    if vemax1!=vomax1:
        print(n-emax1-omax1)        
    elif emax1>omax1:
        print(n-emax1-omax2)        
    else:
        print(n-emax2-omax1)

Submission status: Wrong Answer

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

lisfnt = [0] * (max(v)+1)
lisbk = [0] * (max(v)+1)
for i in range(n):
    if i % 2 == 0:
        lisfnt[v[i]-1] += 1
    else:
        lisbk[v[i]-1] += 1

ans = sum(lisfnt) + sum(lisbk)
valfnt = 0
point = 0
for i in range(len(lisfnt)):
    if lisfnt[i] > valfnt:
        valfnt = lisfnt[i]
        point = i
valbk = 0
for i in range(len(lisbk)):
    if (lisbk[i] > valbk) and i != point:
        valbk = lisbk[i]
ans -= (valfnt + valbk)
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n=int(input())
A=list(map(int,input().split()))
A1=A[0::2]
A2=A[1::2]
ca1=Counter(A1)
ca2=Counter(A2)
nagasa1 = len(ca1)
nagasa2 = len(ca2)
num11=ca1.most_common()[0][0]
cnum11=ca1.most_common()[0][1]
num21=ca2.most_common()[0][0]
cnum21=ca2.most_common()[0][1]
if num11!=num21:
    print(n-cnum11-cnum21)
else:
    if nagasa1>1 and nagasa2>1:
        cnum12=ca1.most_common()[1][1]
        cnum22=ca2.most_common()[1][1]
        print(n-cnum11-min(cnum12,cnum22))
    elif nagasa1==1 and nagasa2==1:
        print(n-cnum11)
    elif nagasa1==1:
        cnum22=ca2.most_common()[1][1]
        print(n-cnum11-cnum22)
    else:
        cnum12=ca1.most_common()[1][1]
        print(n-cnum11-cnum12)

Submission status: Wrong Answer

Solution code:
from collections import Counter
N = int(input())
*V, = map(int, input().split())
if set(V) == 1:
    print(N//2)
    exit()
even, odd = Counter(V[::2]).most_common(), Counter(V[1::2]).most_common()
print(N - even[0][1] - odd[0][1])

Submission status: Wrong Answer

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

even = {}
odd = {}

for i in range(N):
    u = U[i]
    if i % 2 == 0:
        if u not in even:
            even[u] = 0
        even[u] += 1
    else:
        if u not in odd:
            odd[u] = 0
        odd[u] += 1

# print(even)
# print(odd)

max_even = 0
max_odd = 0
sum_even = 0
sum_odd = 0
for e in even:
    max_even = max(max_even, even[e])
    sum_even += even[e]
for o in odd:
    max_odd = max(max_odd, odd[o])
    sum_odd += odd[o]

if len(even) ==1 and len(odd) == 1:
    if U[0] == U[1]:
        print(N//2)
        exit()

print(sum_even + sum_odd - max_even - max_odd)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

odd = []
even = []

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

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

box_e = [0]*int(1e5+1)
box_o = [0]*int(1e5+1)

for i in range(n//2):
    box_e[even[i]] += 1
    box_o[odd[i]] += 1

mode_e = box_e.index(max(box_e))
mode_o = box_o.index(max(box_o))

ans = 0

for i in range(n//2):
    if odd[i] != mode_o:
        ans += 1
    if even[i] != mode_e:
        ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
v = list(map(int, input().split()))
if len(set(v)) == 1:
	print (n//2)
	exit()
a = v[1::2]
b = v[0::2]
if len(set(a)) == 1 and len(set(b)) == 1:
	print (0)
	exit()

aa = collections.Counter(a)
bb = collections.Counter(b)

yousoa = aa.most_common()[0][0]
maa = aa.most_common()[0][1]
yousob = bb.most_common()[0][0]
mbb = bb.most_common()[0][1]
if yousoa == yousob:
	if len(a) == 1:
		ans = (len(a) - maa) + (len(b) - bb.most_common()[1][1])
	elif len(b) == 1:
		ans = (len(a) - aa.most_common()[1][1]) + (len(b)-mbb)
	else:
		ans = (len(a) - maa) + (len(b) - bb.most_common()[1][1])
else:
	ans = len(a)-maa + len(b)-mbb
print (ans)