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 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 a[0][1]<b[0][1]:
      return n-a[1][1]-b[0][1]
    else:
      if a[0][1]==n//2:
        return n//2
      return n-a[0][1]-b[1][1]
  else:
    return n-a[0][1]-b[0][1]

print(main())

Submission status: Wrong Answer

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

map_even_elem_dict = {}
map_odd_elem_dict = {}
for i,e in enumerate(v):
    if i % 2 == 0:
        if e in map_even_elem_dict:
            map_even_elem_dict[e] += 1
        else:
            map_even_elem_dict[e] = 1
    if i % 2 == 1:
        if e in map_odd_elem_dict:
            map_odd_elem_dict[e] += 1
        else:
            map_odd_elem_dict[e] = 1

even_dict_list = []
odd_dict_list = []

for k, v in map_even_elem_dict.items():
    even_dict_list.append((k, v))
    
for k, v in map_odd_elem_dict.items():
    odd_dict_list.append((k, v))
    
even_dict_list.sort()
odd_dict_list.sort()

max_even_elem, max_even_occurence = even_dict_list[-1]
max_odd_elem, max_odd_occurence = odd_dict_list[-1]

if max_even_elem != max_odd_elem:
    print(n // 2 - max_even_occurence + n // 2 - max_odd_occurence)
else:
    if max_even_occurence > max_odd_occurence:
        _, second_max_odd_occurence = odd_dict_list[-2]
        print(n // 2 - max_even_occurence + n // 2 - second_max_odd_occurence)
    elif max_even_occurence < max_odd_occurence:
        _, second_max_even_occurence = even_dict_list[-2]
        print(n // 2 - second_max_even_occurence + n // 2 - max_odd_occurence)
    else:
        if max_even_occurence == n // 2:
            print(n // 2)
        else:
            _, second_max_even_occurence = even_dict_list[-2]
            _, second_max_odd_occurence = odd_dict_list[-2]
            print(n // 2 - max_even_occurence + n // 2 - max(second_max_even_occurence, second_max_odd_occurence))

Submission status: Wrong Answer

Solution code:
def resolve():
    N = int(input())
    V = list(map(int, input().split(" ")))
    
    evens = V[::2]
    odds = V[1::2]

    import collections
    evenMosts = collections.Counter(evens).most_common()
    oddMosts = collections.Counter(odds).most_common()
    evenM = evenMosts[0]
    oddM = oddMosts[0]

    if len(evenMosts) == 1:
        if len(oddMosts) == 1:
            if evenM[0] != oddM[0]:
                print(0)
            else:
                print(evenM[1])
            return
        else:
            print(len(odds)-oddM[1])
            return
    else:
        if len(oddMosts) == 1:
            print(len(evens)-evenM[1])
            return
        else:
            # evensとoddsで最大カウント要素が同じ場合、どちらかを次点の数字のカウント数が大きい方に変更
            if evenM[0] == oddM[0]: 
                if (len(evens)-evenM[1]+len(odds)-oddM[0]) >= (len(evens)-evenM[0] + len(odds)-oddM[1]):
                    evenM = evenMosts[1]
                else:
                    oddM = oddMosts[1]
            print((len(evens)-evenM[1])+(len(odds)-oddM[1]))
            return
    


if '__main__' == __name__:
    resolve()

Submission status: Wrong Answer

Solution code:
def resolve():
    N = int(input())
    V = list(map(int, input().split(" ")))
    
    evens = V[::2]
    odds = V[1::2]

    import collections
    evenMosts = collections.Counter(evens).most_common()
    oddMosts = collections.Counter(odds).most_common()
    evenM = evenMosts[0]
    oddM = oddMosts[0]

    if len(evenMosts) == 1:
        if len(oddMosts) == 1:
            if evenM[0] != oddM[0]:
                print(0)
            else:
                print(evenM[1])
            return
        else:
            print(len(odds)-oddM[1])
            return
    else:
        if len(oddMosts) == 1:
            print(len(evens)-evenM[1])
            return
        else:
            # evensとoddsで最大カウント要素が同じ場合、どちらかを次点の数字のカウント数が大きい方に変更
            if evenM[0] == oddM[0]: 
                if evenM[1] >= oddM[1]:
                    evenM = evenMosts[1]
                else:
                    oddM = oddMosts[1]
            print((len(evens)-evenM[1])+(len(odds)-oddM[1]))
            return
    


if '__main__' == __name__:
    resolve()

Submission status: Wrong Answer

Solution code:
def resolve():
    N = int(input())
    V = list(map(int, input().split(" ")))
    
    evens = V[::2]
    odds = V[1::2]

    import collections
    evenMosts = collections.Counter(evens).most_common()
    oddMosts = collections.Counter(odds).most_common()
    evenM = evenMosts[0]
    oddM = oddMosts[0]

    if len(evenMosts) == 1:
        if len(oddMosts) == 1:
            if evenM[0] != oddM[0]:
                print(0)
            else:
                print(evenM[1])
            return
        else:
            print(len(odds)-oddM[1])
            return
    else:
        if len(oddMosts) == 1:
            print(len(evens)-evenM[1])
            return
        else:
            if evenM[0] == oddM[0]: # evensとoddsで最大カウント要素が同じ場合、カウント数が少ない方を一つずらす
                if evenM[1] >= oddM[1]:
                    oddM = oddMosts[1]
                else:
                    evenM = evenMosts[1]
            print((len(evens)-evenM[1])+(len(odds)-oddM[1]))
            return
    


if '__main__' == __name__:
    resolve()

Submission status: Wrong Answer

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

v1=Counter(v[::2])
v2=Counter(v[1::2])
lenv=len(v)
c1=v1.most_common()
c2=v2.most_common()

if c1[0][0]!=c2[0][0]:
    print(lenv-c1[0][1]-c2[0][1])
else:
    if c1[0][1]==c2[0][1]==len(v)//2:
        print(lenv//2)
    elif c1[0][1]>=c2[0][1]:
        print(lenv-c1[0][1]-c2[1][1])
    else:
        print(lenv-c1[1][1]-c2[0][1])

Submission status: Wrong Answer

Solution code:
n = int(input())
v = list(map(int,input().split()))
even = [v[i] for i in range(n) if i % 2 == 1]
odd = [v[i] for i in range(n) if i % 2 == 0]

import collections
c_test = collections.Counter(v)
c_even = collections.Counter(even)
c_odd = collections.Counter(odd)

c_test_len = len(list(c_test.keys()))
c_even_max = max(list(c_even.values()))
c_odd_max = max(list(c_odd.values()))

print(n - c_even_max - c_odd_max if c_test_len != 1 else n//2)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
v = [i for i in input().split()]
e,o = [],[]
e_cnt,o_cnt = 0,0
for i in range(n):
    if i%2 == 0:
        e.append(v[i])
        e_cnt += 1
    else:
        o.append(v[i])
        o_cnt += 1

if len(set(e))==len(set(o))==1 and e[0]!=o[0]:
    print(0)
    exit()
    
e,o = Counter(e),Counter(o)
ed = {k:v for k,v in e.items()}
od = {k:v for k,v in o.items()}
ed['0'] = 0
od['0'] = 0
e1,e2 = ed.pop(max(ed)),ed.pop(max(ed))
o1,o2 = od.pop(max(od)),od.pop(max(od))
print(min(e_cnt-e1+o_cnt-o2,e_cnt-e2+o_cnt-o1))

Submission status: Wrong Answer

Solution code:
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)

  # if l3[0][0]==l4[0][0]:
  #   if len(l3)==1 and len(l4)==1:
  #     return n//2
  #   elif 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]

  if l3[0][0]==l4[0][0]:
    if l3[0][1]>l4[0][1]:
      return n-l3[0][1]-l4[1][1]
    else:
      if len(l3)==1 and len(l4)==1:
        return n//2
      return n-l3[1][1]-l4[0][1]
  else:
    return n-l3[0][1]-l4[0][1]

print(main())

Submission status: Wrong Answer

Solution code:
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)

  if l3[0][0]==l4[0][0]:
    if l3[0][1]>l4[0][1]:
      if len(l4)==1:
        return n//2
      return n-l3[0][1]-l4[1][1]
    else:
      if len(l3)==1:
        return n//2
      return n-l3[1][1]-l4[0][1]
  else:
    return n-l3[0][1]-l4[0][1]

print(main())

Submission status: Wrong Answer

Solution code:
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)

  if l3[0][0]==l4[0][0]:
    if l3[0][1]>l4[0][1]:
      return n-l3[0][1]-l4[1][1]
    else:
      if len(l3)==1:
        return n//2
      return n-l3[1][1]-l4[0][1]
  else:
    return n-l3[0][1]-l4[0][1]

print(main())

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
v = [i for i in input().split()]
e,o = [],[]
e_cnt,o_cnt = 0,0
for i in range(n):
    if i%2 == 0:
        e.append(v[i])
        e_cnt += 1
    else:
        o.append(v[i])
        o_cnt += 1
#print(e,o)
e,o = Counter(e),Counter(o)
ed = {k:v for k,v in e.items()}
od = {k:v for k,v in o.items()}
if max(ed) == max(od):
    del od[max(od)]
try:
    print((e_cnt-ed[max(ed)])+(o_cnt-od[max(od)]))
except:
    print(o_cnt)

Submission status: Wrong Answer

Solution code:
import collections

def CountElements(l):
    collection = collections.Counter(l)    
    return max(collection.values())

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

veven = []
vodd = []

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

even = CountElements(veven)
odd = CountElements(vodd)

ans = len(veven) - even + len(vodd) - odd
print(ans)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
n = int(input())
v = list(map(int,input().split(" ")))
#print(v)


cnt = 0

#print(len(set(v)))

while True:
    #print(v)
    
    if len(set(v)) == 1:
        cnt = n//2 if n%2 == 0 else (n-1)//2
        break
    
    flag = True#条件check用
    for i in range(n-2):
        
        if v[i] != v[i+2]:
            v[i+2] = v[i]
            cnt += 1
            flag = False
            break
    if flag and len(set(v)) == 2:
        break
    
    cnt += 1
        
print(cnt)

Submission status: Wrong Answer

Solution code:

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


cnt = 0

#print(len(set(v)))

while True:
    #print(v)
    
    if len(set(v)) == 1:
        cnt = n//2 if n%2 == 0 else (n-1)//2
        break
    
    for i in range(n-2):
        if v[i] != v[i+2]:
            v[i+2] = v[i]
            cnt += 1
    
    
    
    #条件check
    if len(set(v)) == 2:
        flag = True
        for i in range(n-2):
            if v[i] != v[i+2]:
                flag = False
                break
            
        if flag:
            break
    
    cnt += 1
        
print(cnt)

Submission status: Wrong Answer

Solution code:
n = input()

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

eve = []
odd = []

for i in range(len(v)):

    if (i % 2 == 1):
        eve.append(v[i])
    else:
        odd.append(v[i])

dic_o = {}
dic_e = {}

dic_o[-1] = 0
dic_e[-1] = 0
#print (dic_o)

for i in odd:

    if ( i in dic_o.keys() ):
        dic_o[i] += 1
    else:
        dic_o[i] = 1


for i in eve:

    if ( i in dic_e.keys() ):
        dic_e[i] += 1
    else:
        dic_e[i] = 1

omax = -1
emax = -1
bul = True

while bul:

    for i in dic_o:
        
        if omax < 0:
            omax = i
        
        elif dic_o[i] > dic_o[omax] :
            omax = i

    for i in dic_e:

        if emax < 0:
            emax = i
        
        elif dic_e[i] > dic_e[emax] :
            emax = i

    if omax != emax :
        bul = False

    else:

        print(dic_o,dic_e)
        
        flag = True
        
        for i in dic_e:
            if dic_e[i] == dic_e[emax] and i != emax:
                emax = i
                flag = False

        if flag:
            for i in dic_o:
                if dic_o[i] == dic_o[emax] and i != omax:
                    omax = i
                    flag = False

        if flag:
        
            if dic_o[omax] > dic_e[emax]:
        
                dic_e.pop(emax)
                emax = -1

            else:

                dic_o.pop(omax)
                omax = -1

    
emax_n = dic_e[emax]
omax_n = dic_o[omax]

#print (dic_o,dic_e)
#print (omax,emax)
print ( (len(odd) - omax_n) + (len(eve) - emax_n))

Submission status: Wrong Answer

Solution code:

n = input()

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

eve = []
odd = []

for i in range(len(v)):

    if (i % 2 == 1):
        eve.append(v[i])
    else:
        odd.append(v[i])

dic_o = {}
dic_e = {}

dic_o[-1] = 0
dic_e[-1] = 0
#print (dic_o)

for i in odd:

    if ( i in dic_o.keys() ):
        dic_o[i] += 1
    else:
        dic_o[i] = 1


for i in eve:

    if ( i in dic_e.keys() ):
        dic_e[i] += 1
    else:
        dic_e[i] = 1

omax = 0
emax = 0
bul = True

while bul:

    omax = -1
    emax = -1

    for i in dic_o:
        
        if omax < 0:
            omax = i
        
        elif dic_o[i] > dic_o[omax] :
            omax = i

    for i in dic_e:

        if emax < 0:
            emax = i
        
        elif dic_e[i] > dic_e[emax] :
            emax = i

    if omax != emax :
        bul = False

    else:

        print(dic_o,dic_e)
        
        flag = True
        
        for i in dic_e:
            if dic_e[i] == dic_e[emax] and i != emax:
                emax = i
                flag = False
                bul = False

        if flag:
            for i in dic_o:
                if dic_o[i] == dic_o[emax] and i != omax:
                    omax = i
                    flag = False
                    bul = False

        if flag:
        
            if dic_o[omax] > dic_e[emax]:
        
                dic_e.pop(emax)

            else:

                dic_o.pop(omax)

    
emax_n = dic_e[emax]
omax_n = dic_o[omax]

#print (dic_o,dic_e)
#print (omax,emax)
print ( (len(odd) - omax_n) + (len(eve) - emax_n))

Submission status: Wrong Answer

Solution code:
n = input()

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

eve = []
odd = []

for i in range(len(v)):

    if (i % 2 == 1):
        eve.append(v[i])
    else:
        odd.append(v[i])

dic_o = {}
dic_e = {}

dic_o[-1] = 0
dic_e[-1] = 0
#print (dic_o)

for i in odd:

    if ( i in dic_o.keys() ):
        dic_o[i] += 1
    else:
        dic_o[i] = 1


for i in eve:

    if ( i in dic_e.keys() ):
        dic_e[i] += 1
    else:
        dic_e[i] = 1

omax = 0
emax = 0
bul = True

while bul:

    omax = -1
    emax = -1

    for i in dic_o:
        
        if omax < 0:
            omax = i
        
        if dic_o[i] > dic_o[omax] :
            omax = i

    for i in dic_e:

        if emax < 0:
            emax = i
        
        if dic_e[i] > dic_e[emax] :
            emax = i

    if omax != emax :
        bul = False

    elif dic_o[omax] > dic_e[emax]:
        
        dic_e.pop(emax)

    else:

        dic_o.pop(omax)

    
emax_n = dic_e[emax]
omax_n = dic_o[omax]

#print (dic_o,dic_e)
#print (omax,emax)
print ( (len(odd) - omax_n) + (len(eve) - emax_n))

Submission status: Wrong Answer

Solution code:

n = input()

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

eve = []
odd = []

for i in range(len(v)):

    if (i % 2 == 1):
        eve.append(v[i])
    else:
        odd.append(v[i])

dic_o = {}
dic_e = {}

dic_o[-1] = 0
dic_e[-1] = 0
#print (dic_o)

for i in odd:

    if ( i in dic_o.keys() ):
        dic_o[i] += 1
    else:
        dic_o[i] = 1


for i in eve:

    if ( i in dic_e.keys() ):
        dic_e[i] += 1
    else:
        dic_e[i] = 1

omax = 0
emax = 0
bul = True

while bul:

    omax = -1
    emax = -1

    for i in dic_o:
        if dic_o[i] > dic_o[omax] :
            omax = i

    for i in dic_e:
        if dic_e[i] > dic_e[emax] :
            emax = i

    if omax != emax :
        bul = False

    elif dic_o[omax] > dic_e[emax]:
        
        dic_e.pop(emax)

    else:

        dic_o.pop(omax)

    
emax_n = dic_e[emax]
omax_n = dic_o[omax]

#print (dic_o,dic_e)
#print (omax,emax)
print ( (len(odd) - omax_n) + (len(eve) - emax_n))

Submission status: Wrong Answer

Solution code:

n = input()

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

eve = []
odd = []

for i in range(len(v)):

    if (i % 2 == 1):
        eve.append(v[i])
    else:
        odd.append(v[i])

dic_o = {}
dic_e = {}

dic_o[-1] = 0
dic_e[-1] = 0
#print (dic_o)

for i in odd:

    if ( i in dic_o.keys() ):
        dic_o[i] += 1
    else:
        dic_o[i] = 1


for i in eve:

    if ( i in dic_e.keys() ):
        dic_e[i] += 1
    else:
        dic_e[i] = 1

omax = 0
emax = 0
bul = True

while bul:

    omax = -1
    emax = -1

    for i in dic_o:
        if dic_o[i] > omax :
            omax = i

    for i in dic_e:
        if dic_e[i] > emax :
            emax = i

    if omax != emax :
        bul = False

    elif dic_o[omax] > dic_e[emax]:
        
        dic_e.pop(emax)

    else:

        dic_o.pop(omax)

    
emax_n = dic_e[emax]
omax_n = dic_o[omax]

#print (dic_o,dic_e)
#print (omax,emax)
print ( (len(odd) - omax_n) + (len(eve) - emax_n))

Submission status: Wrong Answer

Solution code:
if __name__ == '__main__':
    N = int(input())
    v = list(map(int, input().split()))
    i_odd  = v[::2]
    i_even = v[1::2]
    #print(i_odd)
    #print(i_even)
    if set(i_even) == set(i_even):
        print(len(i_even))
        
    else:
        count = 0
        for i in (i_even, i_odd):
            tmp1 = 0
            for x in i:
                tmp2 = i.count(x)
                if tmp2 > tmp1:
                    tmp1 = tmp2
            count += tmp1
                
        print(N - count)

Submission status: Wrong Answer

Solution code:
if __name__ == '__main__':
    N = int(input())
    v = list(map(int, input().split()))
    i_odd  = v[::2]
    i_even = v[1::2]
    #print(i_odd)
    #print(i_even)
    if len(set(i_even)) == 1 and len(set(i_even)) == 1:
        print('0')
        
    else:
        count = 0
        for i in (i_even, i_odd):
            tmp1 = 0
            for x in i:
                tmp2 = i.count(x)
                if tmp2 > tmp1:
                    tmp1 = tmp2
            count += tmp1
            
        print(N - count)

Submission status: Wrong Answer

Solution code:
N = int(input())
v = [int(x) for x in input().split()]
cnt = 0
for i in range(N-2):
    if v[i] != v[i+2]:
        cnt+=1
        v[i+2] = v[i]
print(cnt)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import sys

input = sys.stdin.readline

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

    n = 1000000000
    emk = None
    ev1 = None
    ev2 = 0
    for ek, ev in even.items():
        if emk is None:
            emk = ek
            ev1 = ev
        elif ev > ev1:
            emk = ek
            ev1 = ev
        elif ev > ev2:
            ev2 = ev

    omk = None
    ov1 = None
    ov2 = 0
    for ok, ov in odd.items():
        if omk is None:
            omk = ok
            ov1 = ov
        elif ov > ov1:
            ov1 = ov
        elif ov > ov2:
            ov2 = ov

    if emk != omk:
        n = min(n, N - ev1 - ov1)
    else:
        n = min(n, N - ev1 - ov2, N - ev2 - ov1)

    print(n)

main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import sys

input = sys.stdin.readline

def main():
    N = int(input())
    S = list(map(int, input().split()))
    odd = {}
    even = {}
    for i in range(N):
        if i % 2 == 0:
            if S[i] not in even:
                even[S[i]] = 1
            else:
                even[S[i]] += 1
        else:
            if S[i] not in odd:
                odd[S[i]] = 1
            else:
                odd[S[i]] += 1
    even_max_key = None
    odd_max_key = None
    for k, v in even.items():
        if even_max_key is None:
            even_max_key = k
        elif v > even[even_max_key]:
            even_max_key = k
    for k, v in odd.items():
        if odd_max_key is None:
            odd_max_key = k
        elif v > odd[odd_max_key]:
            odd_max_key = k
    n = N - even[even_max_key] - odd[odd_max_key]
    if even_max_key == odd_max_key:
        n += min(even[even_max_key], odd[odd_max_key])
    print(n)

main()

Submission status: Wrong Answer

Solution code:
def sl_number(numbers):
    a = numbers[0::2]
    b = numbers[1::2]

    a_set = list(set(a))
    b_set = list(set(b))

    if len(a_set) != 1 and len(b_set) == 1:
        hist = []
        for a_sp in a_set:
            if (a_sp == b_set[0]): continue 
            hist.append(a.count(a_sp))

        hist.sort()
        return hist[::-1][1]

    if len(b_set) != 1 and len(a_set) == 1:
        hist = []
        for b_sp in b_set:
            if (b_sp == a_set[0]): continue 
            hist.append(b.count(b_sp))

        hist.sort()
        return hist[::-1][1]

    if a_set[0] != b_set[0]:
        return 0
    else:
        return len(a)


if __name__ == "__main__":
    _ = input()
    numbers = list(map(int, input().split()))

    print(sl_number(numbers))

Submission status: Wrong Answer

Solution code:
n=int(input())
even=[0]*(int(n/2))
odd=[0]*(int(n/2))
inp=list(map(int,input().split()))
for i in range(n):
    if i%2==0:
        even[int(i/2)]=inp[i]
    else:
        odd[int((i-1)/2)]=inp[i]
even.sort()
odd.sort()
def coeunt(lst):
    pre=tmpmax=mx=cnt=tmp=0
    for i in lst:
        if i==tmp:
            cnt+=1
        else:
            if cnt>mx:
                pre=mx; mx=cnt; tmpmax=i
            else:
                pre=max(pre,cnt)
            cnt=1; tmp=i
    if cnt>mx:
        tmpmax=tmp; pre=mx; mx=cnt
    return mx,pre,tmpmax
#maxはカウント、preは準max,tmpmaxは数字



def count(lst):
    tmp=cnt=maxcnt=maxi=precnt=0
    for i in lst:
        if tmp==i:
            cnt+=1
            if cnt>maxcnt:
                precnt=maxcnt; maxcnt=cnt; maxi=i;        
        else:
            cnt=1;tmp=i;maxcnt=max(cnt,maxcnt)
        
                
    return maxcnt,precnt,maxi
        
        
ev,od=count(even),count(odd)

if ev[2]!=od[2]:
    print(n-ev[0]-od[0])
else:
    a=n-ev[0]-od[1]
    b=n-od[0]-ev[1]
    print(min(a,b))

Submission status: Wrong Answer

Solution code:
n=int(input())
even=[0]*(int(n/2))
odd=[0]*(int(n/2))
inp=list(map(int,input().split()))
for i in range(n):
    if i%2==0:
        even[int(i/2)]=inp[i]
    else:
        odd[int((i-1)/2)]=inp[i]
even.sort()
odd.sort()
def count(lst):
    tmpmax=max=cnt=tmp=0
    for i in lst:
        if i==tmp:
            cnt+=1
        else:
            if cnt>max:
                pre=max; max=cnt
            cnt=1; tmp=i
    if cnt>max:
        tmpmax=tmp;pre=max; max=cnt
    return max,pre,tmpmax

ev,od=count(even),count(odd)

if ev[2]!=od[2]:
    print(n-ev[0]-od[0])
else:
    a=n-ev[0]-od[1]
    b=n-od[0]-ev[1]
    print(min(a,b))

Submission status: Wrong Answer

Solution code:
import collections as cl

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

odd_lst = [v_lst[i] for i in range(0, len(v_lst), 2)]
even_lst = [v_lst[i] for i in range(1, len(v_lst), 2)]

odd_value_dic = cl.Counter(odd_lst)
even_value_dic = cl.Counter(even_lst)

odd_value_tup_lst = sorted(odd_value_dic.items(), key=lambda x: x[1], reverse=True)
even_value_tup_lst = sorted(even_value_dic.items(), key=lambda x: x[1], reverse=True)


odds_first = odd_value_tup_lst[0][1]
evens_first = even_value_tup_lst[0][1]
ans = n - odds_first - evens_first

#print(odd_value_tup_lst)
#print(even_value_tup_lst)

if odd_value_tup_lst[0][0] == even_value_tup_lst[0][0]:
    if len(odd_value_tup_lst) == len(even_value_tup_lst) == 1:
        ans = odd_value_tup_lst[0][1]
    elif len(odd_value_tup_lst) == 1:
        evens_first = even_value_tup_lst[1][1]
        ans = n - evens_first
    elif len(even_value_tup_lst) == 1:
        odds_first = odd_value_tup_lst[1][1]
        ans = n - odds_first
    elif odds_first - odd_value_tup_lst[0][1] > evens_first - even_value_tup_lst[0][1]:
        evens_first = even_value_tup_lst[1][1]
        ans = n - odds_first - evens_first
    else:
        odds_first = odd_value_tup_lst[1][1]
        ans = n - odds_first - evens_first

print(ans)

Submission status: Wrong Answer

Solution code:
import collections as cl

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

odd_lst = [v_lst[i] for i in range(0, len(v_lst), 2)]
even_lst = [v_lst[i] for i in range(1, len(v_lst), 2)]

odd_value_dic = cl.Counter(odd_lst)
even_value_dic = cl.Counter(even_lst)

odd_value_tup_lst = sorted(odd_value_dic.items(), key=lambda x: x[1])
even_value_tup_lst = sorted(even_value_dic.items(), key=lambda x: x[1])


odds_first = odd_value_tup_lst[0][1]
evens_first = even_value_tup_lst[0][1]
ans = n - odds_first - evens_first

if odd_value_tup_lst[0][0] == even_value_tup_lst[0][0]:
    if len(odd_value_tup_lst) == len(even_value_tup_lst) == 1:
        ans = odd_value_tup_lst[0][1]
    elif len(odd_value_tup_lst) == 1:
        evens_first = even_value_tup_lst[1][1]
        ans = n - evens_first
    elif len(even_value_tup_lst) == 1:
        odds_first = odd_value_tup_lst[1][1]
        ans = n - odds_first
    elif odds_first - odd_value_tup_lst[0][1] > evens_first - even_value_tup_lst[0][1]:
        evens_first = even_value_tup_lst[1][1]
        ans = n - odds_first - evens_first
    else:
        odds_first = odd_value_tup_lst[1][1]
        ans = n - odds_first - evens_first

print(ans)

Submission status: Wrong Answer

Solution code:
import collections as cl

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

v_dic = cl.Counter(v_lst)

t = list(v_dic.values())
t.sort()
output = sum(t[:len(t)-2])
print(output)

Submission status: Wrong Answer

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

odd_l = []
even_l = []

if v.count(v[0]) == n:
    ans = n // 2
else:
    for i in range(0, n, 2):
        odd_l.append(v[i])
        even_l.append(v[i+1])

    import collections
    odd_c = collections.Counter(odd_l)
    even_c = collections.Counter(even_l)

    odd = odd_c.most_common()[0][1]
    even = even_c.most_common()[0][1]

    if odd != even:
        ans = n - (odd + even)
    else:
        for i in range(min(len(odd_c), len(even_c))):
            even = even_c.most_common()[0][1]
            odd = odd_c.most_common()[i][1]
            ans_change_odd = n - (odd + even)
            odd = odd_c.most_common()[0][1]
            even = even_c.most_common()[i][1]
            ans_change_even  = n - (odd + even)
            ans = min(ans_change_odd, ans_change_even)
            break

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n=int(input())
v=list(map(int,input().split()))
if len(set(v))==1:print(n//2)
else:
    v.extend([0,0])
    voc=Counter(v[::2]).most_common(2)
    vec=Counter(v[1::2]).most_common(2)
    if len(voc)==len(vec)==1:print(0)
    elif voc[0][0]==vec[1][0]:print(n-max(voc[0][1]+vec[1][1],voc[1][1]+vec[0][1]))
    else:print(n-voc[0][1]-vec[0][1])

Submission status: Wrong Answer

Solution code:
from collections import Counter
n=int(input())
v=list(map(int,input().split()))
if len(set(v))==1:print(n//2)
else:
    voc=Counter(v[::2]).most_common(2)
    vec=Counter(v[1::2]).most_common(2)
    if len(voc)==len(vec)==1:print(0)
    elif len(voc)==1:print(n-voc[0][1]-vec[1][1])
    elif len(vec)==1:print(n-voc[1][1]-vec[0][1])
    elif voc[0][0]==vec[1][0]:print(n-max(voc[0][1]+vec[1][1],voc[1][1]+vec[0][1]))
    else:print(n-voc[0][1]-vec[0][1])