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:
import collections

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

counter_e = collections.Counter()
counter_o = collections.Counter()
for i, v in enumerate(vs):
    if i % 2 == 0:
        counter_e[v] += 1
    else:
        counter_o[v] += 1
key_e, max_e = sorted(counter_e.items(), key=lambda x: (x[1], -x[0]))[-1]
key_o, max_o = sorted(counter_o.items(), key=lambda x: (x[1], x[0]))[-1]
if key_e != key_o:
    print(n - max_e - max_o)
elif len(counter_e.keys()) == 1 and len(counter_o.keys()) == 1:
    print(n // 2)
elif len(counter_e.keys()) == 1:
    key_o2, max_o2 = sorted(counter_o.items(), key=lambda x: (x[1], x[0]))[-2]
    print(n - max_e - max_o2)
elif len(counter_e.keys()) == 2 and len(counter_o.keys()) == 1:
    key_e2, max_e2 = sorted(counter_e.items(), key=lambda x: (x[1], -x[0]))[-2]
    print(n - max_e2 - max_o)
else:
    key_e2, max_e2 = sorted(counter_e.items(), key=lambda x: (x[1], -x[0]))[-2]
    key_o2, max_o2 = sorted(counter_o.items(), key=lambda x: (x[1], x[0]))[-2]
    print(min(n - max_e - max_o2, n - n - max_e2 - max_o))

Submission status: Wrong Answer

Solution code:
import collections

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

counter_e = collections.Counter()
counter_o = collections.Counter()
for i, v in enumerate(vs):
    if i % 2 == 0:
        counter_e[v] += 1
    else:
        counter_o[v] += 1
key_e, max_e = sorted(counter_e.items(), key=lambda x: (x[1], -x[0]))[-1]
key_o, max_o = sorted(counter_o.items(), key=lambda x: (x[1], x[0]))[-1]
if key_e != key_o:
    print(n - max_e - max_o)
elif len(counter_e.keys()) == 1 and len(counter_o.keys()) == 1:
    print(n // 2)
elif len(counter_e.keys()) == 1:
    key_o2, max_o2 = sorted(counter_o.items(), key=lambda x: (x[1], x[0]))[-2]
    print(n - max_e - max_o2)
elif len(counter_e.keys()) == 2 and len(counter_o.keys()) == 1:
    key_e2, max_e2 = sorted(counter_e.items(), key=lambda x: (x[1], -x[0]))[-2]
    print(n - max_e2 - max_o)
else:
    key_e2, max_e2 = sorted(counter_e.items(), key=lambda x: (x[1], -x[0]))[-2]
    key_o2, max_o2 = sorted(counter_o.items(), key=lambda x: (x[1], x[0]))[-2]
    print(max(n - max_e - max_o2, n - n - max_e2 - max_o))

Submission status: Wrong Answer

Solution code:
import collections

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

counter_e = collections.Counter()
counter_o = collections.Counter()
for i, v in enumerate(vs):
    if i % 2 == 0:
        counter_e[v] += 1
    else:
        counter_o[v] += 1
key_e, max_e = sorted(counter_e.items(), key=lambda x: (x[1], -x[0]))[-1]
key_o, max_o = sorted(counter_o.items(), key=lambda x: (x[1], x[0]))[-1]
if key_e != key_o:
    print(n - max_e - max_o)
else:
    print(n // 2)

Submission status: Wrong Answer

Solution code:
import collections

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

counter_e = collections.Counter()
counter_o = collections.Counter()
for i, v in enumerate(vs):
    if i % 2 == 0:
        counter_e[v] += 1
    else:
        counter_o[v] += 1
key_e, max_e = sorted(counter_e.items(), key=lambda x: (x[1], x[0]))[-1]
key_o, max_o = sorted(counter_o.items(), key=lambda x: (x[1], x[0]))[-1]
if key_e != key_o:
    print(n - max_e - max_o)
else:
    print(n // 2)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

odd=[S[i] for i in range(n) if i%2==1]
even=[S[i] for i in range(n) if i%2==0]
oddcount=[]
for s in set(odd):
  oddcount.append(odd.count(s))
evencount=[]
for s in set(even):
  evencount.append(even.count(s))

if odd==even:
  print(len(odd))
elif len(oddcount)==1 and len(evencount):
  print(0)
else:
  print(min(min(oddcount),min(evencount)))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# ABC111 C - /\/\/\/
import collections

n = int(input())
v = list(map(int, input().split()))
odd = []
even = []

for i in range(n):
    if i%2 == 0:
        odd.append(v[i])
    elif i%2 == i:
        even.append(v[i])
c_odd = collections.Counter(odd)
c_even = collections.Counter(even)

odd_ = 0
even_ = 0

odd_ = int(n//2)-c_odd.most_common()[0][1]
even_ = int(n//2)-c_even.most_common()[0][1]

if odd_ == 0:
    print(even_)
elif even_ == 0:
    print(odd_)
elif odd_ == 0 and even_ == 0:
    print(0)
else:
    print(min(int(n//2) - odd_,int(n//2) - even_))

Submission status: Wrong Answer

Solution code:
# ABC111 C - /\/\/\/
import collections

n = int(input())
v = list(map(int, input().split()))
odd = []
even = []

for i in range(n):
    if (i+1)%2 == 1:
        odd.append(v[i])
    elif (i+1)%2 == 0:
        even.append(v[i])
c_odd = collections.Counter(odd)
c_even = collections.Counter(even)

odd_ = 0
even_ = 0

odd_ = int(n//2)-c_odd.most_common()[0][1]
even_ = int(n//2)-c_even.most_common()[0][1]

if odd_ == 0:
    print(even_)
elif even_ == 0:
    print(odd_)
elif odd_ == 0 and even_ == 0:
    print(0)
else:
    print(min(int(n//2) - odd_,int(n//2) - even_))

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
V = list(map(int,input().split()))
V_odd = []
V_even = []
for i in range(n):
    if i % 2 == 0:
        V_odd += [V[i]]
    else:
        V_even += [V[i]]
V_odd = list(Counter(V_odd).most_common()) + [(-1,0)]
V_even = list(Counter(V_even).most_common()) + [(-2,0)]
print(V_odd,V_even)
if V_odd[0][0] != V_even[0][0]:
    print(len(V)-V_odd[0][1]-V_even[0][1],'a')
elif V_odd[1][1] >= V_even[1][1]:
    print(len(V)-V_odd[1][1]-V_even[0][1],'b')
else:
    print(len(V)-V_odd[0][1]-V_even[1][1],'c')

Submission status: Wrong Answer

Solution code:
import collections

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

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
V = list(map(int,input().split()))
V_odd = []
V_even = []
for i in range(n):
    if i % 2 == 0:
        V_odd += [V[i]]
    else:
        V_even += [V[i]]
V_odd = list(Counter(V_odd).most_common()) + [[-1,0]]
V_even = list(Counter(V_even).most_common()) + [[-2,0]]
if V_odd[0][0] != V_even[0][0]:
    print(len(V)-V_odd[0][1]-V_even[0][1])
elif V_odd[1][0] >= V_even[1][0]:
    print(len(V)-V_odd[1][1]-V_even[0][1])
else:
    print(len(V)-V_odd[0][1]-V_even[1][1])

Submission status: Wrong Answer

Solution code:
n = int(input())
dic1 = {}
dic2 = {}
lst = list(map(int, input().split()))
for i in range(n):
    if (i+1)%2 == 0:
        if lst[i] not in dic1:
            dic1[lst[i]] = 1
        else:
            dic1[lst[i]] += 1
    if i%2 == 0:
        if lst[i] not in dic2:
            dic2[lst[i]] = 1
        else:
            dic2[lst[i]] += 1
ans1 = sorted(dic1.values())       
ans2 = sorted(dic2.values())    

v1 = [k for k, v in dic1.items() if v == ans1[-1]]
v2 = [k for k, v in dic2.items() if v == ans2[-1]]
if v1 == v2:
    if ans1[-1] > ans2[-1]:
        if len(ans2) > 1:
            print(n - ans1[-1] - ans2[-2])
        else:
            print(n - ans1[-1])
    else:
        if len(ans2) > 1:
            print(n - ans1[-2] - ans2[-1])
        else:
            print(n - ans2[-1])
else:
    print(n - ans1[-1] - ans2[-1])

Submission status: Wrong Answer

Solution code:
# ABC111 C - /\/\/\/
import collections

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

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

Submission status: Wrong Answer

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

import heapq

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

A_even=[]
A_odd=[]
A_evenq = []
A_oddq = []
heapq.heapify(A_evenq)
heapq.heapify(A_oddq)

for i in range(N):
    if i%2==0:
        A_even.append(A[i])
    else:
        A_odd.append(A[i])

A_even.sort()
A_odd.sort()
i=0
max_even=0
i_even=0
while i < N//2:
    j = i
    count=0
    while j < N//2:
        if A_even[i] == A_even[j]:
            count+=1
            j+=1
        else:
            heapq.heappush(A_evenq,count)
            if max_even < count:
                max_even=count
                i_even = A_even[i]
            break
    i=j
heapq.heappush(A_evenq,-count)
if max_even < count:
    max_even=count
    i_even = A_even[i-1]

i=0
max_odd=0
i_odd=0
while i < N//2:
    j = i
    count=0
    while j < N//2:
        if A_odd[i] == A_odd[j]:
            count+=1
            j+=1
        else:
            heapq.heappush(A_oddq,-count)
            if max_odd < count:
                max_odd=count
                i_odd = A_odd[i]
            break
    i=j
heapq.heappush(A_oddq,count)
if max_odd < count:
    max_odd=count
    i_odd = A_odd[i-1]

ans=N-max_odd-max_even
if i_even == i_odd:
    if len(A_evenq) == 1 and len(A_oddq) == 1:
        ans = N//2
    else:
        ans=0
        heapq.heappop(A_oddq)
        odd2 = -heapq.heappop(A_oddq)
        heapq.heappop(A_evenq)
        even2 = -heapq.heappop(A_evenq)
        ans = min(N-even2-max_odd,N-odd2-max_even)
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter


n = int(input())
v = list(map(int, input().split()))
v_even = v[1::2]
v_odd = v[0::2]
v_even_cnt = Counter(v_even)
v_odd_cnt = Counter(v_odd)
if len(list(set(v))) == 1:
    print(len(v)//2)
else:
    print(-v_even_cnt.most_common(1)[0][1] + len(v_even) -\
          v_odd_cnt.most_common(1)[0][1] + len(v_odd))

Submission status: Wrong Answer

Solution code:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate
import sys



def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LIM(): return list(map(lambda x:int(x) - 1, sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def LIRM(n): return [LIM() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
mod = 1000000007


n = I()
num = LI()
even_cnt = Counter([num[i] for i in range(n) if i%2]).most_common()
odd_cnt = Counter([num[i] for i in range(n) if i%2==0]).most_common()
if len(even_cnt) == len(odd_cnt) == 1:
    print(n // 2)
elif len(even_cnt) == 1:
    print(odd_cnt[-2][1])
elif len(odd_cnt) == 1:
    print(even_cnt[-2][1])
elif len(odd_cnt) == 1:
    print(n - odd_cnt[-1][1] - even_cnt[-2][1])
elif even_cnt[-1][0] != odd_cnt[-1][0]:
    print(n - even_cnt[-1][1] - odd_cnt[-1][1])
else:
    print(min(n - even_cnt[-1][1] - odd_cnt[-2][1], n - even_cnt[-2][1] - odd_cnt[-1][1]))

Submission status: Wrong Answer

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

from collections import defaultdict

even = [[0,i] for i in range(10**5+1)]
odd = [[0,i] for i in range(10**5+1)]

for i in range(N//2):
    j = 2*i
    k = 2*i + 1
    even[v[j]][0] += 1
    odd[v[k]][0] += 1

even_sorted = sorted(even, key=lambda x:x[0], reverse = True)
odd_sorted = sorted(odd, key=lambda x:x[0], reverse = True)

if even_sorted[0][1] != odd_sorted[0][1]:
    print(N - even_sorted[0][0] - odd_sorted[0][0])
else:
    print(max(N - even_sorted[0][0] - odd_sorted[1][0], N - odd_sorted[0][0] - even_sorted[1][0]))

Submission status: Wrong Answer

Solution code:
import collections
N=int(input())
h=[int(i) for i in input().split()]

h_o_length = len(h[1::2])
h_e_length = len(h[::2])
h_o = collections.Counter(h[1::2])
h_e = collections.Counter(h[::2])
h_o = h_o.most_common()
h_e = h_e.most_common()

if h[1::2] == h[::2]:
    print(len(h)//2)
elif h_o[0][0]!= h_e[0][0]:
    h_o1 = h_o_length - h_o[0][1]
    h_e1 = h_e_length - h_e[0][1]
    print(h_o1 + h_e1)
elif h_o[0][0] == h_e[0][0]:
    a = min(len(h[1::2]) - h_o[1][1],len(h[::2]) - h_e[1][1]) + max(len(h[1::2]) - h_o[1][1],len(h[::2]) - h_e[1][1])
    print(a)

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    v = [int(i) for i in input().split()]
    v_even = v[::2]
    v_odd = v[1::2]
    from collections import Counter
    v_even_cnt = sorted(list(Counter(v_even).items()),key=lambda x:x[1],reverse=True)
    v_odd_cnt = sorted(list(Counter(v_odd).items()),key=lambda x:x[1],reverse=True)
    ans = 0
    print(v_even_cnt,v_odd_cnt)
    if v_even_cnt[0][0] != v_odd_cnt[0][0]:
        ans = len(v_even) - v_even_cnt[0][1] + len(v_odd) - v_odd_cnt[0][1]
    else:
        if len(v_even_cnt) == 1:
            ans = len(v_even)
        else:
            ans1 = len(v_even) - v_even_cnt[0][1] + len(v_odd) - v_odd_cnt[1][1]
            ans2 = len(v_even) - v_even_cnt[1][1] + len(v_odd) - v_odd_cnt[0][1]
            ans = min(ans1,ans2)
    print(ans)
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    v = [int(i) for i in input().split()]
    v_even = v[::2]
    v_odd = v[1::2]
    from collections import Counter
    v_even_cnt = sorted(list(Counter(v_even).items()),key=lambda x:x[1],reverse=True)
    v_odd_cnt = sorted(list(Counter(v_odd).items()),key=lambda x:x[1],reverse=True)
    ans = 0
    if v_even_cnt[0][0] != v_odd_cnt[0][0]:
        ans = len(v_even) - v_even_cnt[0][1] + len(v_odd) - v_odd_cnt[0][1]
    else:
        if len(v_even_cnt) == 1:
            ans = len(v_even)
        else:
            ans = len(v_even) - v_even_cnt[0][1] + len(v_odd) - v_odd_cnt[1][1]
    print(ans)
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    v = [int(i) for i in input().split()]
    v_even = v[::2]
    v_odd = v[1::2]
    from collections import Counter
    v_even_cnt = sorted(list(Counter(v_even).items()),key=lambda x:x[1],reverse=True)
    v_odd_cnt = sorted(list(Counter(v_odd).items()),key=lambda x:x[1],reverse=True)
    ans = -1
    if v_even_cnt[0][0] != v_odd_cnt[0][0]:
        ans = len(v_even) - v_even_cnt[0][1] + len(v_odd) - v_odd_cnt[0][1]
    else:
        if v_even_cnt[0][1] < v_odd_cnt[0][1]:
            if len(v_even_cnt) > 1:
                ans = len(v_even) - v_even_cnt[1][1] + len(v_odd) - v_odd_cnt[0][1]
            else:
                ans = len(v_even) - 0 + len(v_odd) - v_odd_cnt[0][1]
        elif v_even_cnt[0][1] > v_odd_cnt[0][1]:
            if len(v_odd_cnt) > 1:
                ans = len(v_even) - v_even_cnt[0][1] + len(v_odd) - v_odd_cnt[1][1]
            else:
                ans = len(v_even) - v_even_cnt[0][1] + len(v_odd) - 0
        else:
            if len(v_even_cnt) > 1 and len(v_odd_cnt) > 1:
                if v_even_cnt[1][1] > v_odd_cnt[1][1]:
                    ans = v_even_cnt[0][1] + v_odd_cnt[1][1]
                else:
                    ans = v_even_cnt[1][1] + v_odd_cnt[0][1]
            else:
                ans = len(v_even) - v_even_cnt[0][1] + len(v_odd) - 0
    print(ans)
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

dict_ai = {}
dict_bi = {}

for i in range(len(num_list)):
    if i % 2 == 0:
        if num_list[i] not in dict_ai:
            dict_ai[num_list[i]] = 1
        else:
            dict_ai[num_list[i]] += 1
    else:
        if num_list[i] not in dict_bi:
            dict_bi[num_list[i]] = 1
        else:
            dict_bi[num_list[i]] += 1
dict_ai = sorted(dict_ai.items())
dict_bi = sorted(dict_bi.items())

max_ai = dict_ai[0][0]
max_bi = dict_bi[0][0]

if max_ai == max_bi:
    if dict_ai[0][1] > dict_bi[0][1]:
        max_bi += 1
    else:
        max_ai += 1


count = 0
for i in range(len(num_list)):
    if i % 2 == 0:
        if num_list[i] != max_ai:
            count += 1
    else:
        if num_list[i] != max_bi:
            count += 1

print(count)

Submission status: Wrong Answer

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

dict_ai = {}
dict_bi = {}

for i in range(len(num_list)):
    if i % 2 == 0:
        if num_list[i] not in dict_ai:
            dict_ai[num_list[i]] = 1
        else:
            dict_ai[num_list[i]] += 1
    else:
        if num_list[i] not in dict_bi:
            dict_bi[num_list[i]] = 1
        else:
            dict_bi[num_list[i]] += 1
dict_ai = sorted(dict_ai.items())
dict_bi = sorted(dict_bi.items())

max_ai = dict_ai[0][0]
max_bi = dict_bi[0][0]

if max_ai == max_bi:
    max_bi += 1
count = 0
for i in range(len(num_list)):
    if i % 2 == 0:
        if num_list[i] != max_ai:
            count += 1
    else:
        if num_list[i] != max_bi:
            count += 1

print(count)

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    v = [int(i) for i in input().split()]
    v_even = v[::2]
    v_odd = v[1::2]
    from collections import Counter
    v_even_cnt = sorted(list(Counter(v_even).items()),key=lambda x:x[1],reverse=True)
    v_odd_cnt = sorted(list(Counter(v_odd).items()),key=lambda x:x[1],reverse=True)
    if v_even_cnt[0][0] != v_odd_cnt[0][0]:
        ans = len(v_even) - v_even_cnt[0][1] + len(v_odd) - v_odd_cnt[0][1]
    else:
        if v_even_cnt[0][1] < v_odd_cnt[0][1]:
            if len(v_even_cnt) > 1:
                ans = len(v_even) - v_even_cnt[1][1] + len(v_odd) - v_odd_cnt[0][1]
            else:
                ans = len(v_even) - 0 + len(v_odd) - v_odd_cnt[0][1]
        else:
            if len(v_odd_cnt) > 1:
                ans = len(v_even) - v_even_cnt[0][1] + len(v_odd) - v_odd_cnt[1][1]
            else:
                ans = len(v_even) - v_even_cnt[0][1] + len(v_odd) - 0
    print(ans)
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())
V = list(map(int, input().split()))
odd, even = {}, {}
for i in range(N):
    if i % 2 == 1:
        if V[i] not in even:
            even[V[i]] = 0
        even[V[i]] += 1
    else:
        if V[i] not in odd:
            odd[V[i]] = 0
        odd[V[i]] += 1

sorted_odd = sorted(odd.items(), key=lambda x: x[1])
sorted_even = sorted(even.items(), key=lambda x: x[1])
if sorted_odd[0][0] != sorted_even[0][0]:
    print(N - sorted_even[0][1] - sorted_odd[0][1])
else:
    if len(sorted_odd) == 1 or len(sorted_even) == 1:
        print(N // 2)
    else:
        print(N - max(sorted_even[0][1] + sorted_odd[1][1], sorted_even[1][1] + sorted_odd[0][1]))

Submission status: Wrong Answer

Solution code:
N = int(input())
V = list(map(int, input().split()))
odd, even = {}, {}
for i in range(N):
    if i % 2 == 1:
        if V[i] not in even:
            even[V[i]] = 0
        even[V[i]] += 1
    else:
        if V[i] not in odd:
            odd[V[i]] = 0
        odd[V[i]] += 1
if len(set(list(odd.keys()) + list(even.keys()))) == 1:
    key = list(odd.keys())[0]
    print(min(odd[key], even[key]))
    exit()

sorted_odd = sorted(odd.items(), key=lambda x: x[1])
sorted_even = sorted(even.items(), key=lambda x: x[1])
if len(sorted_odd) == 1:
    if len(sorted_even) == 1:
        print(0)
    else:
        print(min(sorted_even[0][1], sorted_even[1][1]))
elif len(sorted_even) == 1:
    print(min(sorted_odd[0][1], sorted_odd[1][1]))

Submission status: Wrong Answer

Solution code:
N = int(input())
v_even, v_odd = dict(), dict()
v_lst = list(map(int, input().split()))

for i in range(0, N, 2):
	if v_lst[i] in v_odd:
		v_odd[v_lst[i]] += 1
	else:
		v_odd[v_lst[i]] = 1
		
	if v_lst[i + 1] in v_even:
		v_even[v_lst[i + 1]] += 1
	else:
		v_even[v_lst[i + 1]] = 1
		
modify_num_even = int(N / 2) - max(v_even.values())
modify_num_odd = int(N / 2) - max(v_odd.values())

if [modify_num_even, modify_num_odd] == [0, 0] and max(v_even) == max(v_odd):
	print(int(N / 2))
else:
	print(modify_num_even + modify_num_odd)

Submission status: Wrong Answer

Solution code:
N = int(input())
v_even, v_odd = dict(), dict()
v_lst = list(map(int, input().split()))

for i in range(0, N, 2):
	if v_lst[i] in v_odd:
		v_odd[v_lst[i]] += 1
	else:
		v_odd[v_lst[i]] = 1
		
	if v_lst[i + 1] in v_even:
		v_even[v_lst[i + 1]] += 1
	else:
		v_even[v_lst[i + 1]] = 1
		
modify_num_even = int(N / 2) - max(v_even.values())
modify_num_odd = int(N / 2) - max(v_odd.values())

if [modify_num_even, modify_num_odd] == [0, 0]:
	print(int(N / 2))
else:
	print(modify_num_even + modify_num_odd)

Submission status: Wrong Answer

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

from collections import Counter

v1 = []
v2 = []
for i in range(0,n-1,2):
  v1.append(V[i])
for i in range(1,n,2):
  v2.append(V[i])
  
c1 = Counter(v1)
c2 = Counter(v2)

if list(c1.keys())[0] == list(c2.keys())[0]:
  a1 = sum(list(c1.values())[1:])+list(c2.values())[0]+sum(list(c2.values())[2:])
  a2 = sum(list(c2.values())[1:])+list(c1.values())[0]+sum(list(c1.values())[2:])
  ans = min(a1,a2)
  
else:
  ans = sum(list(c1.values())[1:])+sum(list(c2.values())[1:])

print(ans)

Submission status: Wrong Answer

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

from collections import Counter

v1 = []
v2 = []
for i in range(0,n,2):
  v1.append(V[i])
for i in range(1,n,2):
  v2.append(V[i])
  
c1 = Counter(v1)
c2 = Counter(v2)

if list(c1.keys())[0] == list(c2.keys())[0]:
  a1 = sum(list(c1.values())[1:])+list(c2.values())[0]+sum(list(c2.values())[2:])
  a2 = sum(list(c2.values())[1:])+list(c1.values())[0]+sum(list(c1.values())[2:])
           
  ans = min(a1,a2)
  
else:
  ans = sum(list(c1.values())[1:])+sum(list(c2.values())[1:])

print(ans)

Submission status: Wrong Answer

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

from collections import Counter

v1 = []
v2 = []
for i in range(0,n,2):
  v1.append(i)
for i in range(1,n,2):
  v2.append(i)
  
c1 = Counter(v1)
c2 = Counter(v2)

if list(c1.keys())[0] == list(c2.keys())[0]:
  a1 = sum(list(c1.values())[1:])+list(c2.values())[0]+sum(list(c2.values()[2:]))
  a2 = sum(list(c2.values())[1:])+list(c1.values())[0]+sum(list(c1.values()[2:]))
           
  ans = min(a1,a2)
  
else:
  ans = sum(list(c1.values())[1:])+sum(list(c2.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(0,n,2):
  v1.append(i)
for i in range(1,n,2):
  v2.append(i)
  
v1s = set(v1)
v2s = set(v2)
  
v1c = []
v2c = []
for i in list(v1s):
  v1c.append(v1.count(i))
for i in list(v2s):
  v2c.append(v2.count(i))

v1c.sort(reverse=True)
v2c.sort(reverse=True)

print(sum(v1c[1:])+sum(v2c[1:]))

Submission status: Wrong Answer

Solution code:
n = int(input())
v = [int(x) for x in input().split()]
dic0 = {}
dic1 = {}
for i in range(n):
  if i % 2 == 0:
    if v[i] in dic0:
      dic0[v[i]] += 1
    else:
      dic0[v[i]] = 1
  else:
    if v[i] in dic1:
      dic1[v[i]] += 1
    else:
      dic1[v[i]] = 1
list0 = sorted(dic0.items(), key = lambda x : x[1])
list1 = sorted(dic1.items(), key = lambda x : x[1])
l0 = len(list0) - 1
l1 = len(list1) - 1

if list0[l0][0] != list1[l1][0]:
  print(n - list0[l0][1] - list1[l1][1])
else:
  if l0 == 0 and l1 == 0:
    print(n // 2)
  elif l0 == 0:
    print(n - max(list0[0][1] + list1[l1 - 1][1], list1[l1][1]))
  elif l1 == 0:
    print(n - max(list0[l0 - 1][1] + list1[0][1], list0[l0][1]))
  else:
    print(n - max(list0[l0 - 1][1] + list1[l1][1], list0[l0][1] + list1[l1][1]))

Submission status: Wrong Answer

Solution code:
n = int(input())
v = [int(x) for x in input().split()]
dic0 = {}
dic1 = {}
for i in range(n):
  if i % 2 == 0:
    if v[i] in dic0:
      dic0[v[i]] += 1
    else:
      dic0[v[i]] = 1
  else:
    if v[i] in dic1:
      dic1[v[i]] += 1
    else:
      dic1[v[i]] = 1
list0 = sorted(dic0.items(), key = lambda x : x[1])
list1 = sorted(dic1.items(), key = lambda x : x[1])
l0 = len(list0) - 1
l1 = len(list1) - 1
while True:
  if list0[l0][0] != list1[l1][0]:
    print(n - list0[l0][1] - list1[l1][1])
    break
  else:
    if l0 < 0:
      print(n - list1[l1][1])
      break
    elif l1 < 0:
      print(n - list0[l0][1])
      break
    elif list0[l0][1] > list1[l1][1]:
      l1 -= 1
    else:
      l0 -= 1

Submission status: Wrong Answer

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

A = [[0] * (10**5+1) for i in range(2)]

for i in range(n):
    A[i%2][V[i]] += 1

C = [0] * (10**5+1)  # A[0][:i]の最大値
for i in range(1, len(C)):
    C[i] = max(C[i-1], A[0][i])

# print(A[0][:150])
# print(A[1][:150])
# print(C[:150])

ans = 0
for i in range(1, len(C)):
    ans = max(ans, C[i-1] + A[1][i])


print(n - ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
array = list(map(int,input().split()))
first = []
second = []
for i in range(n):
    if i % 2 == 0:
        first.append(array[i])
    else:
        second.append(array[i])
set1 = set(first)
set2 = set(second)
count1 = {}
count2 = {}
for i in set1:
    count1[i] = first.count(i)
for i in set2:
    count2[i] = second.count(i)

count1_sorted = sorted(count1.items(),key=lambda x : x[1])
count2_sorted = sorted(count2.items(),key=lambda x : x[1])


if  len(set1) == 1 and len(set2) == 1:
    if set1 != set2:
        print(0)
    else:
        print(len(first))
elif count1_sorted[len(count1_sorted)-1][1] != count2_sorted[len(count2_sorted)-1][1]:
    print(len(first) -count1_sorted[len(count1_sorted)-1][1] + len(second) -count2_sorted[len(count2_sorted)-1][1])
else:
    pass

Submission status: Wrong Answer

Solution code:
import sys
import math
from fractions import gcd
# import queue
from collections import Counter
# from itertools import accumulate
# from functools import reduce

def lcm(a, b):
    return a * b // gcd(a, b)

def combination_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def permutations_count(n, r):
    return math.factorial(n) // math.factorial(n - r)

big_prime = 1000000007

"""
# 標準入力取得
## 文字列
 =  sys.stdin.readline().rstrip()
 =  list(sys.stdin.readline().rstrip())

## 数値
 =  int(sys.stdin.readline())
 =  map(int, sys.stdin.readline().split())
 =  list(map(int, sys.stdin.readline().split()))
 =  [list(map(int,list(sys.stdin.readline().split()))) for i in range(N)]
"""

# 奇数側と偶数側でリストを分ける
# それぞれの最大値で置き換える
# 数値が一致してしまった時にどうするか
# 出現数順にソート、辞書を持つ
# 一致している場合とそうでない場合で分ける
# 療法試してmax取る


N =  int(sys.stdin.readline())
L =  list(map(int, sys.stdin.readline().split()))

E = L[::2]
O = L[1::2]

ce = Counter(E)
co = Counter(O)

cem = ce.most_common()
com = co.most_common()

if cem[0] != com[0]:
    print(N - cem[0][1] - com[0][1])
else:
    if len(cem) == 1 or len(com) == 1:
        print(N // 2)
    else:
        print(min(N - (len(E) - cem[0][1]) - (len(O) - cem[1][1]), N - (len(E) - cem[1][1]) - (len(O) - cem[0][1])))

Submission status: Wrong Answer

Solution code:
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n = ni()
vvv = na()
d = {}
for i in range(n):
    if vvv[i] not in d.keys():
        d[vvv[i]] = 1
    else:
        d[vvv[i]] += 1
if len(d.keys()) == 1:
    print(n // 2)
else:
    num1 = max(d, key=d.get)
    d.pop(num1)
    num2 = max(d, key=d.get)
    ct1 = 0
    ct2 = 0
    now1 = num1
    now2 = num2
    for i in range(n):
        if vvv[i] != now1:
            ct1 += 1
        if vvv[i] != now2:
            ct2 += 1
        now1, now2 = now2, now1
    print(min(ct1, ct2))

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
v = [int(i) for i in input().split()]
if len(list(set(v))) == 1:
	print(int(len(v)/2))
	exit()

vo = v[0::2]
ve = v[1::2]
cvo = collections.Counter(vo)
cve = collections.Counter(ve)
svo = sorted(cvo.items(),key=lambda x: x[1])
sve = sorted(cve.items(),key=lambda x: x[1])
ans  = sum([i[1] for i in svo[:-1]]) + sum([i[1] for i in sve[:-1]])
print(ans)

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
v = [int(i) for i in input().split()]
if len(list(set(v))) == 1:
	print(0)
	exit()

vo = v[0::2]
ve = v[1::2]
cvo = collections.Counter(vo)
cve = collections.Counter(ve)
svo = sorted(cvo.items(),key=lambda x: x[1])
sve = sorted(cve.items(),key=lambda x: x[1])
ans  = sum([i[1] for i in svo[:-1]]) + sum([i[1] for i in sve[:-1]])
print(ans)