Problem:


Score : 300 points

Problem Statement

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

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

Exactly two different numbers appear in the sequence.

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

Constraints

2 \leq n \leq 10^5

n is even.

1 \leq v_i \leq 10^5

v_i is an integer.

Input

Input is given from Standard Input in the following format:

n
v_1 v_2 ... v_n

Output

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

Sample Input 1

4
3 1 3 2

Sample Output 1

1

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

Sample Input 2

6
105 119 105 119 105 119

Sample Output 2

0

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

Sample Input 3

4
1 1 1 1

Sample Output 3

2

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



Sample input:
4
3 1 3 2


Sample output:
1

Submission status: Wrong Answer

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

v1 = v[::2]
v2 = v[1::2]

counter_v1 = Counter(v1)
counter_v2 = Counter(v2)

most_common_v1 = counter_v1.most_common()
most_common_v2 = counter_v2.most_common()

count = 0
if len(counter_v1) == 1 and len(counter_v2) == 1:
  if most_common_v1[0][0] == most_common_v2[0][0]:
    count = n // 2
    
if len(counter_v1) > 1:
  values = list(counter_v1.values())
  count += len(v1) - values[0]
  
if len(counter_v2) > 1:
  values = list(counter_v2.values())
  if most_common_v1[0][0] == most_common_v2[0][0]:
    count += len(v2) - values[1]
  else:
    count += len(v2) - values[0]
print(count)

Submission status: Wrong Answer

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

v1 = v[::2]
v2 = v[1::2]

counter_v1 = Counter(v1)
counter_v2 = Counter(v2)

most_common_v1 = counter_v1.most_common()
most_common_v2 = counter_v2.most_common()
print(counter_v1)
print(counter_v2)

count = 0
if len(counter_v1) == 1 and len(counter_v2) == 1:
  if most_common_v1[0][0] == most_common_v2[0][0]:
    count = n // 2
    
if len(counter_v1) > 1:
  values = list(counter_v1.values())
  count += len(v1) - values[0]
  
if len(counter_v2) > 1:
  values = list(counter_v2.values())
  if most_common_v1[0][0] == most_common_v2[0][0]:
    count += len(v2) - values[1]
  else:
    count += len(v2) - values[0]
print(count)

Submission status: Wrong Answer

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

v1 = v[::2]
v2 = v[1::2]

counter_v1 = Counter(v1)
counter_v2 = Counter(v2)

most_common_v1 = counter_v1.most_common()
most_common_v2 = counter_v2.most_common()

count = 0
if len(counter_v1) == 1 and len(counter_v2) == 1:
  if most_common_v1[0][0] == most_common_v2[0][0]:
    count = n // 2
if len(counter_v1) > 1:
  values = counter_v1.values()
  for i, value in enumerate(values):
    if i == 0:
      continue
    count += value
if len(counter_v2) > 1:
  values = counter_v2.values()
  if most_common_v1[0][0] == most_common_v2[0][0]:
    for i, value in enumerate(values):
      if i == 1:
        continue
      count += value
  else:
    for i, value in enumerate(values):
      if i == 0:
        continue
      count += value
print(count)

Submission status: Wrong Answer

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

v1 = v[::2]
v2 = v[1::2]

counter_v1 = Counter(v1)
counter_v2 = Counter(v2)

most_common_v1 = counter_v1.most_common()
most_common_v2 = counter_v2.most_common()

count = 0
if len(counter_v1) == 1 and len(counter_v2) == 1:
  if most_common_v1[0][0] == most_common_v2[0][0]:
    count = n // 2
if len(counter_v1) > 1:
  values = counter_v1.values()
  for i, value in enumerate(values):
    if i == 0:
      continue
    count += value
if len(counter_v2) > 1:
  values = counter_v2.values()
  for i, value in enumerate(values):
    if i == 0:
      continue
    count += value
  
print(count)

Submission status: Wrong Answer

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

v1 = v[::2]
v2 = v[1::2]

counter_v1 = Counter(v1)
counter_v2 = Counter(v2)

most_common_v1 = counter_v1.most_common()
most_common_v2 = counter_v2.most_common()

count = 0
if len(counter_v1) == 1 and len(counter_v2) == 1:
  if most_common_v1[0][0] == most_common_v2[0][0]:
    count = n // 2
if len(counter_v1) > 1:
  count = count + len(counter_v1) - 1
if len(counter_v2) > 1:
  count = count + len(counter_v2) - 1
print(count)

Submission status: Wrong Answer

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

v1 = v[::2]
v2 = v[1::2]

counter_v1 = Counter(v1)
counter_v2 = Counter(v2)

count = 0
if len(counter_v1) == 1 and len(counter_v2) == 1:
  most_common_v1 = counter_v1.most_common()
  most_common_v2 = counter_v2.most_common()
  if most_common_v1[0][0] == most_common_v2[0][0]:
    count = n // 2
if len(counter_v1) > 1:
  count = count + len(counter_v1) - 1
if len(counter_v2) > 1:
  count = count + len(counter_v2) - 1
print(count)

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
list1 = list(map(int,input().split()))
list2n =list1[::2]
list2n_1 = list1[1::2]

dict2n = collections.Counter(list2n)
dict2n_1 = collections.Counter(list2n_1)

a = max(dict2n)
b = max(dict2n_1)

if not a == b:
    print(n - max(dict2n.values())-max(dict2n_1.values()))

else:
    c = list(dict2n.values())
    c.sort(reverse = True)
    d = list(dict2n_1.values())
    d.sort(reverse = True)
    if len(c) == 1:
        if len(d) == 1:
            print(int(n/2))
        else:
            print(n-c[0]-d[1])
    elif len(d) == 1:
        print(n-c[1]-d[0])
    
    else:
        if c[1] >= d[1]:
            print(n-c[1]-d[0])
        else:
            print(n-c[0]-d[1])

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
n=int(input())
w=list(map(int,input().split()))
ans=0
if len(set(w))==1:
    print(len(w)//2)
else:
    a=[]
    a1=[]
    for i in range(n):
        if i%2==0:
            a.append(w[i])
        else:
            a1.append(w[i])
    a.sort()
    a1.sort()
    ans=0
    t=a[0]
    cnt1=[]
    cnt=[]
    b=[]
    b1=[]
    for j in range(len(a)):
        if a[j]==t:
            ans+=1
        else:
            cnt.append([ans,t])
            t=a[j]
            ans=1
        if j==len(a)-1:
            cnt.append([ans,t])
    s=a1[0]
    ans=0
    for j in range(len(a)):
        if a1[j]==s:
            ans+=1
        else:
            cnt1.append([ans,s])
            s=a1[j]
            ans=1
        if j==len(a1)-1:
            cnt1.append([ans,s])
    cnt.sort(reverse=True)
    cnt1.sort(reverse=True)
    """
    print(a)
    print(a1)
    print(cnt)
    print(cnt1)
    """
    if cnt[0][1]!=cnt1[0][1]:
        print(n-cnt[0][0]-cnt1[0][0])
    else:
        if cnt[0][0]>cnt1[0][0]:
            print(n-cnt[0][0]-cnt1[1][0])
        elif cnt[0][0]<cnt1[0][0]:
            print(n-cnt1[0][0]-cnt[1][0])
        else:
            t=0
            s=0
            for i in range(1,min(len(cnt),len(cnt1))):
                if cnt[i][0]!=cnt1[i][0]:
                    if cnt[i][0]==max(cnt[i][0],cnt1[i][0]):
                        t=cnt[i][0]
                        s=cnt1[0][0]
                        break
                if cnt[i][0]!=cnt1[i][0]:
                    if cnt1[i][0]==max(cnt[i][0],cnt1[i][0]):
                        t=cnt1[i][0]
                        s=cnt[0][0]
                        break
            print(n-t-s)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
n=int(input())
w=list(map(int,input().split()))
ans=0
if len(set(w))==1:
    print(len(w)//2)
else:
    a=[]
    a1=[]
    for i in range(n):
        if i%2==0:
            a.append(w[i])
        else:
            a1.append(w[i])
    a.sort()
    a1.sort()
    ans=0
    t=a[0]
    cnt1=[]
    cnt=[]
    b=[]
    b1=[]
    for j in range(len(a)):
        if a[j]==t:
            ans+=1
        else:
            cnt.append([ans,t])
            t=a[j]
            ans=1
        if j==len(a)-1:
            cnt.append([ans,t])
    s=a1[0]
    ans=0
    for j in range(len(a)):
        if a1[j]==s:
            ans+=1
        else:
            cnt1.append([ans,s])
            s=a1[j]
            ans=1
        if j==len(a1)-1:
            cnt1.append([ans,s])
    cnt.sort(reverse=True)
    cnt1.sort(reverse=True)
    #print(cnt)
    #print(cnt1)
    if cnt[0][1]!=cnt1[0][1]:
        print(n-cnt[0][0]-cnt1[0][0])
    else:
        if cnt[0][0]>cnt1[0][0]:
            print(n-cnt[0][0]-cnt1[1][0])
        else:
            print(n-cnt1[0][0]-cnt[1][0])

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
v = list(map(int,input().split()))
odd = []
even = []
for i in range(n):
    if i % 2 == 0:
        even.append(v[i])
    else:
        odd.append(v[i])
cnt = 0
even_count = Counter(even)
odd_count = Counter(odd)
if len(even_count) != 1:
    work = even_count.values()
    cnt += sum(work) - max(work)
if len(odd_count) != 1:
    work = odd_count.values()
    cnt += sum(work) - max(work)
work1 = odd_count.keys()
work2 = even_count.keys()
if cnt == 0 and work1 == work2:
    print(n//2)
else:
    print(cnt)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
n=int(input())
w=list(map(int,input().split()))
ans=0
if len(set(w))==1:
    print(len(w)//2)
else:
    a=[]
    a1=[]
    for i in range(n):
        if i%2==0:
            a.append(w[i])
        else:
            a1.append(w[i])
    a.sort()
    a1.sort()
    ans=0
    t=a[0]
    cnt1=[]
    cnt=[]
    b=[]
    b1=[]
    for j in range(len(a)):
        if a[j]==t:
            ans+=1
        else:
            cnt.append([ans,t])
            t=a[j]
            ans=1
            continue
        if j==len(a)-1:
            cnt.append([ans,t])
    s=a1[0]
    ans=0
    for j in range(len(a)):
        if a1[j]==s:
            ans+=1
        else:
            cnt1.append([ans,s])
            s=a1[j]
            ans=1
            continue
        if j==len(a1)-1:
            cnt1.append([ans,s])
    cnt.sort(reverse=True)
    cnt1.sort(reverse=True)
    #print(cnt)
    #print(cnt1)
    if cnt[0][1]!=cnt1[0][1]:
        print(n-cnt[0][0]-cnt1[0][0])
    else:
        if cnt[0][0]>cnt1[0][0]:
            print(n//2-cnt1[1][0])
        else:
            print(n//2-cnt[1][0])

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
u = list(map(int, input().split()))
A = []
B = []
Af = [[i, -1] for i in range(100007)]
Bf = [[i, -1] for i in range(100007)]
for i in range(n):
    if i % 2 == 0:
        A.append(u[i])
        Af[u[i]][1] += 1
    else:
        B.append(u[i])
        Bf[u[i]][1] += 1

Af.sort(key=lambda x: -x[1])
Bf.sort(key=lambda x: -x[1])

Ae = 0
Be = 0
if Af[0][0] == Bf[0][0]:
  if Af[0][1] >= Bf[0][1]:
      Ae = Af[0][0]
      Be = Bf[1][0]
  else:
      Ae = Af[1][0]
      Be = Bf[0][0]
else:
    Ae = Af[0][0]
    Be = Bf[0][0]

ans = 0
for i in range(len(A)):
    if Ae != A[i]:
        ans += 1
for i in range(len(B)):
    if Be != B[i]:
        ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
u = list(map(int, input().split()))
A = []
B = []
Af = [[i, 0] for i in range(100007)]
Bf = [[i, 0] for i in range(100007)]
for i in range(n):
    if i % 2 == 0:
        A.append(u[i])
        Af[u[i]][1] += 1
    else:
        B.append(u[i])
        Bf[u[i]][1] += 1

Af.sort(key=lambda x: -x[1])
Bf.sort(key=lambda x: -x[1])

Ae = 0
Be = 0
if Af[0][0] == Bf[0][0]:
  if Af[0][1] >= Bf[0][1]:
      Ae = Af[0][0]
      Be = Bf[1][0]
  else:
      Ae = Af[1][0]
      Be = Bf[0][0]
else:
    Ae = Af[0][0]
    Be = Bf[0][0]

ans = 0
for i in range(len(A)):
    if Ae != A[i]:
        ans += 1
for i in range(len(B)):
    if Be != B[i]:
        ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
n=int(input())
w=list(map(int,input().split()))
ans=0
if len(set(w))==1:
    print(len(w)//2)
elif len(set(w))==2:
    w.sort()
    print(abs(w.count(w[0])-w.count(w[len(w)-1])))
else:
    cnt=[]
    ans=0
    w.sort()
    t=w[0]
    for j in range(n):
        if w[j]==t:
            ans+=1
        else:
            cnt.append(ans)
            t=w[j]
            ans=1
        if j==n-1:
            cnt.append(ans)
    print(cnt)
    cnt.sort(reverse=True)
    if cnt[0]+cnt[1]>n:
        print(cnt[0]+cnt[1]-n)
    elif cnt[0]+cnt[1]<n:
        if cnt[0]>=n//2:
            print(n//2-cnt[1])
        else:
            print(n-cnt[1]-cnt[0])
    else:
        print(cnt[0]-cnt[1])

Submission status: Wrong Answer

Solution code:
import sys
from collections import Counter
input = sys.stdin.readline

n = int(input())
vn = [int(x) for x in input().strip().split()]

v1 = [v for i, v in enumerate(vn) if i % 2 == 0]
v2 = [v for i, v in enumerate(vn) if i % 2 != 0]
v1cnt = Counter(v1)
v2cnt = Counter(v2)
maxv11 = 0
maxv12 = 0
maxv21 = 0
maxv22 = 0
c_ = 0
for v, c in v1cnt.items():
    if c > c_:
        maxv12 = c_
        c_ = c
        maxv1 = [v]
    elif c == c_:
        maxv1.append(v)

c_ = 0
for v, c in v2cnt.items():
    if c > c_:
        maxv22 = c_
        c_ = c
        maxv2 = [v]
    elif c == c_:
        maxv2.append(v)

if maxv1 != maxv2 or len(maxv1) > 1 or len(maxv2) > 1:
    print(len(v1) - max(v1cnt.values()) + len(v2) - max(v2cnt.values()))
else:
    print(min(len(v1) - max(v1cnt.values()) + len(v2) - maxv22, \
        len(v1) - maxv12 + len(v2) - max(v2cnt.values())))

Submission status: Wrong Answer

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

odev = [{}, {}]

for i in range(N):
  odev[i%2][v[i]] = odev[i%2].get(v[i],0) + 1

for i in range(2):
  odev[i] = sorted(odev[i].items(), key=lambda x: x[1], reverse=True)

odevM = [odev[0][0][1], odev[1][0][1]]
if(odev[0][0][0] == odev[1][0][0]):
  fInd = int(odevM[0] > odevM[1])
  odevM[fInd] = odev[fInd][1][1] if len(odev[fInd]) > 1 else 0
print(N - sum(odevM))

Submission status: Wrong Answer

Solution code:
def list_count(my_list,n,x):
    dic={} #辞書型の宣言
    for i in range(x,n,2):
        if my_list[i] in dic: #もしnumがkeyとして辞書にあれば
            dic[my_list[i]]+=1 #valueに+1
        else: #なければ
            dic[my_list[i]]=1 #dicにnumというkeyを追加し、対応するvalueを1とする
    return dic

n=int(input())
v=list(map(int,input().split()))
dic0=list_count(v,n,0)
dic1=list_count(v,n,1)
a=[[0,0],[0,0]]
b=[[0,0],[0,0]]
for i in dic0.keys():
    if a[0][1]<=dic0[i]:
        a[1][0]=a[0][0]
        a[1][1]=a[0][1]
        a[0][0]=i
        a[0][1]=dic0[i]
    elif a[1][1]<dic0[i]:
        a[1][0]=i
        a[1][1]=dic0[i]
for i in dic1.keys():
    if b[0][1]<=dic1[i]:
        b[1][0]=b[0][0]
        b[1][1]=b[0][1]
        b[0][0]=i
        b[0][1]=dic1[i]
    elif b[1][1]<dic1[i]:
        b[1][0]=i
        b[1][1]=dic1[i]
if a[0][0]==b[0][0]:
    print(n-min(a[0][1]+b[1][1],a[1][1]+b[0][1]))
else:
    print(n-a[0][1]-b[0][1])

Submission status: Wrong Answer

Solution code:
n=int(input())
v=list(map(int,input().split()))
v.insert(0,0)
check=0 #全部同じ数字か？0なら全部同じ数字
now=v[1]
for i in range(2,n):
    if now!=v[i]:
        check=1
        break
odd=[]
even=[]
for i in range(1,n+1):
    if i%2==1:
        odd.append(v[i])
    else:
        even.append(v[i])
ans=0
odd2=sorted(odd)
even2=sorted(even)
now_odd,now_even=odd2[0],even2[0]
rensa_odd,rensa_even=1,1
max_rensa_odd,max_rensa_even=1,1
half=n//2
for i in range(1,half):
    if odd2[i]==now_odd:
        rensa_odd+=1
    else:
        now_odd=odd2[i]
        if rensa_odd>max_rensa_odd:
            max_rensa_odd=rensa_odd
        rensa_odd=1
if rensa_odd>max_rensa_odd:
            max_rensa_odd=rensa_odd
for i in range(1,half):
    if even2[i]==now_even:
        rensa_even+=1
    else:
        now_even=even2[i]
        if rensa_even>max_rensa_even:
            max_rensa_even=rensa_even
        rensa_even=1
if rensa_even>max_rensa_even:
            max_rensa_even=rensa_even
print(n-max_rensa_odd-max_rensa_even if check==1 else half)

Submission status: Wrong Answer

Solution code:
n=int(input())
v=list(map(int,input().split()))
v.insert(0,0)
check=0 #全部同じ数字か？0なら全部同じ数字
now=v[0]
for i in range(1,n):
    if now!=v[i]:
        check=1
        break
odd=[]
even=[]
for i in range(1,n+1):
    if i%2==1:
        odd.append(v[i])
    else:
        even.append(v[i])
ans=0
odd2=sorted(odd)
even2=sorted(even)
now_odd,now_even=odd2[0],even2[0]
rensa_odd,rensa_even=1,1
max_rensa_odd,max_rensa_even=1,1
half=n//2
for i in range(1,half):
    if odd2[i]==now_odd:
        rensa_odd+=1
    else:
        now_odd=odd2[i]
        if rensa_odd>max_rensa_odd:
            max_rensa_odd=rensa_odd
        rensa_odd=1
if rensa_odd>max_rensa_odd:
            max_rensa_odd=rensa_odd
for i in range(1,half):
    if even2[i]==now_even:
        rensa_even+=1
    else:
        now_even=even2[i]
        if rensa_even>max_rensa_even:
            max_rensa_even=rensa_even
        rensa_even=1
if rensa_even>max_rensa_even:
            max_rensa_even=rensa_even
print(n-max_rensa_odd-max_rensa_even if check==0 else half)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

from collections import Counter
A = Counter(V[::2])
B = Counter(V[1::2])

ac = sorted(A.items(), key=lambda x: -x[1])
bc = sorted(B.items(), key=lambda x: -x[1])

if len(ac) == 1 and len(bc) == 1:
    print(h)
elif len(ac) == 1:
    print(h-bc[0][1])
elif len(bc) == 1:
    print(h-ac[0][1])
elif ac[0][0] == bc[0][0]:
    if ac[0][1]-ac[1][1] == bc[0][1]-bc[1][1]:
        if ac[0][1] >= bc[0][1]:
            print((h-ac[0][1]) + (h-bc[1][1]))
        else:
            print((h-ac[1][1]) + (h-bc[0][1]))
    elif ac[0][1]-ac[1][1] > bc[0][1]-bc[1][1]:
        print((h-ac[0][1]) + (h-bc[1][1]))
    else:
        print((h-ac[1][1]) + (h-bc[0][1]))
else:
    print((h-ac[0][1]) + (h-bc[0][1]))

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

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

if N == 2:
    if V[0] == V[1]:
        print(0)
    else:
        print(1)
    exit()

d_even = defaultdict(int)
d_odd = defaultdict(int)

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

if len(set(V)) == 1:
    print(N//2)
    exit()


l_even = sorted(d_even.items(), key=lambda x: -x[1])
l_odd = sorted(d_odd.items(), key=lambda x: -x[1])

if l_even[0][0] != l_odd[0][0]:
    print(N - l_even[0][1] - l_odd[0][1])
else:
    if l_even[0][1] > l_odd[0][1]:
        print(N - l_even[0][1] - l_odd[1][1])
    else:
        print(N - l_even[1][1] - l_odd[0][1])

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

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

d_even = defaultdict(int)
d_odd = defaultdict(int)

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

if len(set(V)) == 1:
    print(N//2)
    exit()

freq_even = sorted(d_even.values())[-1]
freq_odd = sorted(d_odd.values())[-1]

print(N - freq_even - freq_odd)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

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

d_even = defaultdict(int)
d_odd = defaultdict(int)

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

if d_even == d_odd:
    print(N//2)
    exit()
    
freq_even = sorted(d_even.values())[-1]
freq_odd = sorted(d_odd.values())[-1]

print(N - freq_even - freq_odd)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

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

d_even = defaultdict(int)
d_odd = defaultdict(int)

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

freq_even = sorted(d_even.values())[-1]
freq_odd = sorted(d_odd.values())[-1]

print(N - freq_even - freq_odd)

Submission status: Wrong Answer

Solution code:
from collections import Counter

n=int(input())
V=list(map(int,input().split()))
V_1=[(0,0)]+sorted(Counter([V[i] for i in range(n) if i%2==0]).items(), key=lambda x:x[1])
V_2=[(0,0)]+sorted(Counter([V[j] for j in range(n) if j%2==1]).items(), key=lambda x:x[1])

a,b=V_1[-1][0],V_2[-1][0]

if a==b:
    if V_1[-2][0]>V_2[-2][0]:a=V_1[-2][0]
    else:b=V_2[-2][0]

cnt=0
for i in range(n):
    if i%2==0:
        if V[i]!=a:cnt +=1
    else:
        if V[i]!=b:cnt +=1

print(cnt)

Submission status: Wrong Answer

Solution code:
from collections import Counter

n=int(input())
V=list(map(int,input().split()))
V_1=[(0,0)]+sorted(Counter([V[i] for i in range(n) if i%2==0]).items(), key=lambda x:x[1])
V_2=[(0,0)]+sorted(Counter([V[j] for j in range(n) if j%2==1]).items(), key=lambda x:x[1])

a,b=V_1[-1][0],V_2[-1][0]

if a==b:
    if V_1[-2][0]>V_2[-2][0]:
        a=V_1[-2][0]
    else:
        b=V_1[-2][0]

cnt=0
for i in range(n):
    if i%2==0:
        if V[i]!=a:cnt +=1
    else:
        if V[i]!=b:cnt +=1

print(cnt)

Submission status: Wrong Answer

Solution code:
from collections import Counter

n=int(input())
V=list(map(int,input().split()))
V_1=[(0,0)]+sorted(Counter([V[i] for i in range(n) if i%2==0]).items(), key=lambda x:x[1])
V_2=[(0,0)]+sorted(Counter([V[j] for j in range(n) if j%2==1]).items(), key=lambda x:x[1])

a,b=V_1[-1][0],V_2[-1][0]

if a==b:
    if V_1[-2]>V_2[-2]:
        a=V_1[-2]
    else:
        b=V_1[-2]

cnt=0
for i in range(n):
    if i%2==0:
        if V[i]!=a:cnt +=1
    else:
        if V[i]!=b:cnt +=1

print(cnt)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n=int(input())
V=list(map(int,input().split()))
V_1=[(0,0)]+sorted(Counter([V[i] for i in range(n) if i%2==0]).items(), key=lambda x:x[1])
V_2=[(0,0)]+sorted(Counter([V[j] for j in range(n) if j%2==1]).items(), key=lambda x:x[1])

a,b=V_1[-1][0],V_2[-1][0]
if a==b:b=V_2[-2][0]

cnt=0
for i in range(n):
    if i%2==0:
        if V[i]!=a:cnt +=1
    else:
        if V[i]!=b:cnt +=1

print(cnt)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n=int(input())
V=list(map(int,input().split()))
V_1=[(0,0)]+sorted(Counter([V[i] for i in range(n) if i%2==0]).items(), key=lambda x:x[1])
V_2=[(0,0)]+sorted(Counter([V[j] for j in range(n) if j%2==1]).items(), key=lambda x:x[1])

a,b=V_1[-1],V_2[-1]
if a==b:b=V_2[-2]

cnt=0
for i in range(n):
    if i%2==0:
        if V[i]!=a:cnt +=1
    else:
        if V[i]!=b:cnt +=1

print(cnt)

Submission status: Wrong Answer

Solution code:
n=int(input())
V=list(map(int,input().split()))
v_1,v_2=V[0],V[1]
if v_1==v_2:v_2=float("inf")
cnt=0
for i in range(n):
    if i%2==0:
        if V[i]!=v_1:cnt +=1
    else:
        if V[i]!=v_2:cnt +=1
print(cnt)

Submission status: Wrong Answer

Solution code:
from collections import Counter

N = int(input())
l = list(map(int, input().split(' ')))
l_odd = l[0::2]
l_even = l[1::2]
dict_odd = Counter(l_odd)
dict_even = Counter(l_even)
most_odd = dict_odd.most_common()[0][0]
most_even = dict_even.most_common()[0][0]

if dict_odd.most_common()[0][1] == dict_even.most_common()[0][1] == N / 2:
    if most_odd == most_even:
        ans = N / 2
    else:
        ans = 0

elif dict_odd.most_common()[0][1] == N / 2:
    ans = N / 2 - dict_even.most_common()[1][1]

elif dict_even.most_common()[0][1] == N / 2:
    ans = N / 2 - dict_odd.most_common()[1][1]

elif most_odd != most_even:
    ans = N - dict_odd.most_common()[0][1] - dict_even.most_common()[0][1]

else:
    ans = N - max(dict_odd.most_common()[0][1] + dict_even.most_common()[1][1], dict_even.most_common()[0][1] + dict_odd.most_common()[1][1])

print(int(ans))

Submission status: Wrong Answer

Solution code:
from collections import Counter

N = int(input())
l = list(map(int, input().split(' ')))
l_odd = l[0::2]
l_even = l[1::2]
dict_odd = Counter(l_odd)
dict_even = Counter(l_even)
most_odd = dict_odd.most_common()[0][0]
most_even = dict_even.most_common()[0][0]

if dict_odd.most_common()[0][1] == dict_even.most_common()[0][1] == N / 2:
    if most_odd == most_even:
        ans = N / 2
    else:
        ans = 0

elif dict_odd.most_common()[0][1] == N / 2:
    ans = N / 2 - dict_even.most_common()[1][1]

elif dict_even.most_common()[0][1] == N / 2:
    ans = N / 2 - dict_odd.most_common()[1][1]

elif most_odd != most_even:
    ans = N - dict_odd.most_common()[0][1] - dict_even.most_common()[0][1]

else:
    ans = N - max(dict_odd.most_common()[0][1] + dict_even.most_common()[1][1], dict_even.most_common()[0][1] + dict_odd.most_common()[1][1])

print(dict_odd, dict_even)
print(int(ans))

Submission status: Wrong Answer

Solution code:
from collections import Counter

N = int(input())
l = list(map(int, input().split(' ')))
l_odd = l[0::2]
l_even = l[1::2]
dict_odd = Counter(l_odd)
dict_even = Counter(l_even)
most_odd = dict_odd.most_common()[0][0]
most_even = dict_even.most_common()[0][0]

if dict_odd.most_common()[0][1] == dict_even.most_common()[0][1] == N / 2:
    if most_odd == most_even:
        ans = N / 2
    else:
        ans = 0

elif dict_odd.most_common()[0][1] == N / 2:
    ans = N / 2 - dict_even.most_common()[1][1]

elif dict_even.most_common()[0][1] == N / 2:
    ans = N / 2 - dict_odd.most_common()[1][1]

elif most_odd != most_even:
    ans = N - dict_odd.most_common()[0][1] - dict_even.most_common()[0][1]

else:
    ans = N - max(most_odd + dict_even.most_common()[1][0], most_even + dict_odd.most_common()[1][0])

print(int(ans))

Submission status: Wrong Answer

Solution code:
from collections import Counter

N = int(input())
l = list(map(int, input().split(' ')))
l_odd = l[0::2]
l_even = l[1::2]
dict_odd = Counter(l_odd)
dict_even = Counter(l_even)
most_odd = dict_odd.most_common()[0][0]
most_even = dict_even.most_common()[0][0]

if dict_odd.most_common()[0][1] == dict_even.most_common()[0][1] == N / 2:
    ans = N / 2

elif dict_odd.most_common()[0][1] == N / 2:
    ans = N / 2 - dict_even.most_common()[1][1]

elif dict_even.most_common()[0][1] == N / 2:
    ans = N / 2 - dict_odd.most_common()[1][1]

elif most_odd != most_even:
    ans = N - dict_odd.most_common()[0][1] - dict_even.most_common()[0][1]

else:
    ans = N - max(most_odd + dict_even.most_common()[1][0], most_even + dict_odd.most_common()[1][0])

print(int(ans))

Submission status: Wrong Answer

Solution code:
from collections import Counter

N = int(input())
l = list(map(int, input().split(' ')))
l_odd = l[0::2]
l_even = l[1::2]
dict_odd = Counter(l_odd)
dict_even = Counter(l_even)
most_odd = dict_odd.most_common()[0][0]
most_even = dict_even.most_common()[0][0]

if dict_odd.most_common()[0][1] == dict_even.most_common()[0][1] == N / 2:
    ans = N / 2

elif dict_odd.most_common()[0][1] == N / 2:
    ans = N / 2 - dict_even.most_common()[1][1]

elif dict_even.most_common()[0][1] == N / 2:
    ans = N / 2 - dict_odd.most_common()[1][1]

elif most_odd != most_even:
    ans = N - dict_odd.most_common()[0][1] - dict_even.most_common()[0][1]

else:
    ans = N - max(most_odd + dict_even.most_common()[1][0], most_even + dict_odd.most_common()[1][0])

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
v = list(map(int,input().split()))
v_odd = []
v_even = []
d_odd = {}
d_even = {}
o = []
e = []
for i in range(n//2):
    a = v[2*i]
    b = v[2*i+1]
    if a in d_odd:
        d_odd[a] += 1
    else:
        d_odd[a] = 1
        o.append(a)
    if b in d_even:
        d_even[b] += 1
    else:
        d_even[b] = 1
        e.append(b)
O = 0
s = 0
E = 0
t = 0
o_max = 0
e_max = 0
for i in o:
    x = d_odd[i]
    if x >= o_max:
        O = i
        s = o_max
        o_max = x
for i in e:
    y = d_even[i]
    if y >= e_max:
        E = i
        t = e_max
        e_max = y
if O == E:
    m = max(o_max+t,e_max+s)
else:
    m = o_max + e_max
print(n-m)

Submission status: Wrong Answer

Solution code:
import collections

n = int(input())
v = list(map(int, input().split()))
x = collections.Counter(v[::2])
y = collections.Counter(v[1::2])
a = (n // 2) - x.most_common()[0][1]
b = (n // 2) - y.most_common()[0][1]
if x.most_common()[0][0] == y.most_common()[0][0]:
    if len(set(v)) == 1:
        print(n // 2)
    else:
        min(a + (n // 2) - y.most_common()[1][1],
            b + (n // 2) - x.most_common()[1][1])
else:
    print(a + b)

Submission status: Wrong Answer

Solution code:
import collections

n = int(input())
v = list(map(int, input().split()))
x = collections.Counter(v[::2])
y = collections.Counter(v[1::2])
a = (n // 2) - x.most_common()[0][1]
b = (n // 2) - y.most_common()[0][1]
if x.most_common()[0][0] == y.most_common()[0][0]:
    if len(set(v)) == 1:
        print(n // 2)
    elif a < b:
        print(a + (n // 2) - y.most_common()[1][1])
    else:
        print(b + (n // 2) - x.most_common()[1][1])
else:
    print(a + b)

Submission status: Wrong Answer

Solution code:
# ABC111 C - \/\/\/\
from collections import Counter
si = lambda: input()
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))
N = ni()
V = nl()

O = []
E = []
ans = 0

for i in range(N):
    if i%2 == 0:
        O.append(V[i])
    else:
        E.append(V[i])
O_C = Counter(O)
O_E = Counter(E)

O_set = set(O)
E_set = set(E)
V_set = set(V)

if len(O_set)==1:
    O_First = O_C.most_common()[0][1]
    O_Second = 0
else:
    O_First = O_C.most_common()[0][1]
    O_Second = O_C.most_common()[1][1]

if len(E_set)==1:
    E_First = O_E.most_common()[0][1]
    E_Second = 0
else:
    E_First = O_E.most_common()[0][1]
    E_Second = O_E.most_common()[1][1]

if O_First == E_First:
    ans = min(len(E)-E_First+len(O)-O_Second,len(E)-E_Second+len(O)-O_First)
else:
    ans = len(O)-O_First+len(E)-E_First

if len(O_set)==1 and len(E_set)==1:
    if len(V_set)==1:
        ans = len(V)//2
    else:
        ans = 0

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
array = list(map(int,input().split()))
if len(set(array)) == 1:
    print(n//2)
    exit()
gu = []
ki = []
for i in range(n):
    if i % 2 == 0:
        gu.append(array[i])
    else:
        ki.append(array[i])
gu_c = Counter(gu)
ki_c = Counter(ki)
if gu_c.most_common()[0][0] != ki_c.most_common()[0][0]:
    print(n-(gu_c.most_common()[0][1]+ki_c.most_common()[0][1]))
elif gu_c.most_common()[0][1] < ki_c.most_common()[0][1]:
    print(n-(gu_c.most_common()[1][1]+ki_c.most_common()[0][1]))
else:
    print(n-(gu_c.most_common()[0][1]+ki_c.most_common()[1][1]))