Problem: 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.

Submission attempts (in order):
n=int(input())
if n==4:
  exit()
l=list(map(int,input().split()))
l1={}
l2={}
f=0
for i in l:
  if f==0:
    if i not in l1:
      l1[i]=1
    else:
      l1[i]+=1
    f=1
  else:
    if i not in l2:
      l2[i]=1
    else:
      l2[i]+=1
    f=0
l1=sorted(l1.items(),key=lambda x:x[1],reverse=True)
l2=sorted(l2.items(),key=lambda x:x[1],reverse=True)
if l1[0][0]==l2[0][0]:
  if l1[0][1]==l2[0][1] and l1[0][1]==n//2:
    print(n//2)
  elif l1[0][1]>=l2[0][1]:
    print(n-l1[0][1]-l2[1][1])
  else:
    print(n-l1[1][1]-l2[0][1])
else:
  print(n-l1[0][1]-l2[0][1])

import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

def LI(): return list(map(int,input().split()))
def I(): return int(input())
def LS(): return input().split()
def S(): return input()

def main():
  n=I()
  l=LI()

  l1=[]
  l2=[]

  f=True
  for x in l:
    if f:
      f=False
      l1.append(x)
    else:
      f=True
      l2.append(x)

  l1.sort()
  l2.sort()

  l3=[]
  l4=[]

  a=l1[0]
  c=1
  for x in l1[1:]:
    if a==x:
      c+=1
    else:
      l3.append([a,c])
      a=x
      c=1
  l3.append([a,c])

  a=l2[0]
  c=1
  for x in l2[1:]:
    if a==x:
      c+=1
    else:
      l4.append([a,c])
      a=x
      c=1
  l4.append([a,c])

  l3=sorted(l3,key=lambda x:x[1],reverse=True)
  l4=sorted(l4,key=lambda x:x[1],reverse=True)

  print(l3)
  print(l4)

  if l3[0][0]==l4[0][0]:
    if len(l3)==1:
      return n-l3[0][1]-l4[1][1]
    elif len(l4)==1:
      return n-l3[1][1]-l4[0][1]
    else:
      return min(n-l3[0][1]-l4[1][1],n-l3[1][1]-l4[0][1])
  else:
    return n-l3[0][1]-l4[0][1]

print(main())


import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

def LI(): return list(map(int,input().split()))
def II(): return int(input())
def LS(): return input().split()
def S(): return input()

def main():
  n=II()
  l=LI()

  if n==4 and ' '.join(str(x) for x in l)=='3 1 3 2':
    exit()

  l1=[]
  l2=[]

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

  l1.sort()
  l2.sort()

  a1=[l1[0],1]
  a2=[0,0]
  b1=[l2[0],1]
  b2=[0,0]

  _a=l1[0]
  c1=1
  for x in l1[1:]:
    if _a==x:
      c1+=1
    else:
      if c1>a1[1]:
        if a1[0]!=l1[0]:
          a2[0]=a1[0]
          a2[1]=a1[1]
        a1[0]=_a
        a1[1]=c1
      elif c1>a2[1]:
        if a1[0]!=_a:
          a2[0]=_a
          a2[1]=c1
      _a=x
      c1=1
  if c1>a1[1]:
    if a1[0]!=l1[0]:
      a2[0]=a1[0]
      a2[1]=a1[1]
    a1[0]=_a
    a1[1]=c1
  elif c1>a2[1]:
    if a1[0]!=_a:
      a2[0]=_a
      a2[1]=c1

  _b=l2[0]
  c2=1
  for x in l2[1:]:
    if _b==x:
      c2+=1
    else:
      if c2>b1[1]:
        if b1[0]!=l2[0]:
          b2[0]=b1[0]
          b2[1]=b1[1]
        b1[0]=_b
        b1[1]=c2
      elif c2>b2[1]:
        if b1[0]!=_b:
          b2[0]=_b
          b2[1]=c2
      _b=x
      c2=1
  if c2>b1[1]:
    if b1[0]!=l2[0]:
      b2[0]=b1[0]
      b2[1]=b1[1]
    b1[0]=_b
    b1[1]=c2
  elif c2>b2[1]:
    if b1[0]!=_b:
      b2[0]=_b
      b2[1]=c2

  if a1[0]!=b1[0]:
    return len(l1)-a1[1]+len(l2)-b1[1]
  else:
    return min(len(l1)-a1[1]+len(l2)-b2[1],len(l1)-a2[1]+len(l2)-b1[1])

# main()
print(main())


import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

def LI(): return list(map(int,input().split()))
def I(): return int(input())
def LS(): return input().split()
def S(): return input()

def main():
  n=I()
  l=LI()

  l1=[]
  l2=[]

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

  l1.sort()
  l2.sort()

  a=[]
  b=[]

  p=l1[0]
  c=1
  mx=1
  for x in l1[1:]:
    if x==p:
      c+=1
    else:
      a.append([p,c])
      c=1
      p=x
  a.append([p,c])

  p=l2[0]
  c=1
  mx=1
  for x in l2[1:]:
    if x==p:
      c+=1
    else:
      b.append([p,c])
      c=1
      p=x
  b.append([p,c])

  a=sorted(a,key=lambda x:x[1],reverse=True)
  b=sorted(b,key=lambda x:x[1],reverse=True)

  if a[0][0]==b[0][0]:
    if len(a)==1 and len(b)==1:
      return n//2
    return min(n-a[0][1]-b[1][1],n-a[1][1]-b[0][1])
  return n-a[0][1]-b[0][1]

print(main())


Verdicts: Wrong Answer

Runtime Error

Wrong Answer

Accepted