Problem:


Score : 300 points

Problem Statement

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

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

Exactly two different numbers appear in the sequence.

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

Constraints

2 \leq n \leq 10^5

n is even.

1 \leq v_i \leq 10^5

v_i is an integer.

Input

Input is given from Standard Input in the following format:

n
v_1 v_2 ... v_n

Output

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

Sample Input 1

4
3 1 3 2

Sample Output 1

1

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

Sample Input 2

6
105 119 105 119 105 119

Sample Output 2

0

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

Sample Input 3

4
1 1 1 1

Sample Output 3

2

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



Sample input:
4
3 1 3 2


Sample output:
1

Submission status: Wrong Answer

Solution code:
n=int(input())
v_list = list(map(int,input().split()))
odd_list = []
even_list = []

for i in range(n):
    if i % 2 == 0:
        odd_list.append(v_list[i]) 
    else:
        even_list.append(v_list[i])

import collections

odd_list_c = collections.Counter(odd_list)
even_list_c = collections.Counter(even_list)

if odd_list_c.most_common()[0][0] != even_list_c.most_common()[0][0]:
    ans = n - odd_list_c.most_common()[0][1] - even_list_c.most_common()[0][1]
else:
    if len(even_list_c) == 1:
        ans = n // 2
    else: 
        if odd_list_c.most_common()[0][1] >= even_list_c.most_common()[0][1]:
            ans = n - odd_list_c.most_common()[0][1] - even_list_c.most_common()[1][1]
        elif odd_list_c.most_common()[0][1] < even_list_c.most_common()[0][1]:
            ans = n - odd_list_c.most_common()[1][1] - even_list_c.most_common()[0][1]

print(ans)

Submission status: Wrong Answer

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

set_v = list(set(v))
cnt_v = [0] * len(set_v)
for i in range(len(set_v)):
    cnt_v[i] = v.count(set_v[i])
cnt_v.sort(reverse=True)

if len(cnt_v) == 1:
    print(int(n/2))
else:
    ans = ((n/2)-cnt_v[0]) + ((n/2)-cnt_v[1])
    print(int(ans))

Submission status: Wrong Answer

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

count = 0
j=0

if max(v) == min(v):
    print(int(n/2))
else:
    for i in range(int(n/2)-1):
        if v[0] != v[j+2]:
            count += 1
        if v[1] != v[j+3]:
            count =+ 1
        j = j+2
    print(count)

Submission status: Wrong Answer

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

count = 0

if max(v) == min(v):
    print(int(n/2))
else:
    for i in range(int(n/2)):
        if v[i] != v[i+2]:
            count += 1
    print(count)

Submission status: Wrong Answer

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

count = 0

for i in range(int(n/2)):
    if v[i] != v[i+2]:
        count += 1
        
print(count)

Submission status: Wrong Answer

Solution code:
n = int(input())
v = list(map(int, input().split()))
ans = 0
dic_1 = {}
dic_2 = {}
for i in range(n):
  if  i%2 == 0:
    if v[i] in dic_1:
      dic_1[v[i]] += 1
    else:
      dic_1[v[i]] = 1
  elif  i%2 != 0:
    if v[i] in dic_2:
      dic_2[v[i]] += 1
    else:
      dic_2[v[i]] = 1
    
temp_1 = max(dic_1.items(), key = lambda x:x[1])[0]
temp_2 = max(dic_2.items(), key = lambda x:x[1])[0]
    

for i in range(n-2):
  if len(set(v)) >= 2:
    if i%2 == 0:
      if v[i] != temp_1:
        v[i] != temp_1
        ans += 1
    else:
      if v[i] != temp_2:
        v[i] != temp_2
        ans += 1
  else:
    ans = n//2
print(ans)

Submission status: Wrong Answer

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

vo=v[0::2]
ve=v[1::2]

voc=collections.Counter(vo).most_common()
vec=collections.Counter(ve).most_common()

mvo=voc[0][0]
mve=vec[0][0]

if mvo!=mve:
  print(N-voc[0][1]-vec[0][1])
elif len(voc)==len(vec) and mvo==mve:
  print(N//2)
else:
  print(min(N-voc[0][1]-vec[1][1],N-voc[1][1]-vec[0][1]))

Submission status: Wrong Answer

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

a = li[0]
b = li[1]

for i in range(n // 2):
  print(i)

Submission status: Wrong Answer

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

mO = [0,] * 100010
mE = [0,] * 100010

for a in vA[0::2]:
  mO[a] += 1
for a in vA[1::2]:
  mE[a] += 1

modeO = mO.index(max(mO))
modeE = mE.index(max(mE))
if modeO == modeE:
  if max(mO) <= max(mE):
    mO.pop(modeO)
  else:
    mE.pop(modeE)
print(N - max(mO) - max(mE))

Submission status: Wrong Answer

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

mO = [0,] * 100010
mE = [0,] * 100010

for a in vA[0::2]:
  mO[a] += 1
for a in vA[1::2]:
  mE[a] += 1

modeO = mO.index(max(mO))
modeE = mE.index(max(mE))
if modeO == modeE:
  if max(mO) >= max(mE):
    mO.pop(modeO)
  else:
    mE.pop(modeE)
print(N - max(mO) - max(mE))

Submission status: Wrong Answer

Solution code:
import collections

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

emax=e.most_common()[0][0]
omax=o.most_common()[0][0]
for i in range(n//2):
    if ve[i]!=emax:
        count+=1
for i in range(n//2):
    if vo[i]!=omax:
        count+=1
if emax==omax:
    print(n//2)
else:
    print(count)

Submission status: Wrong Answer

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

mO = [0,] * 100010
mE = [0,] * 100010

for a in vA[0::2]:
  mO[a] += 1
for a in vA[1::2]:
  mE[a] += 1

modeO = mO.index(max(mO))
modeE = mE.index(max(mE))
if modeO == modeE:
  if max(mO) != N//2:
    mO.pop(modeO)
  else:
    mE.pop(modeE)
print(N - max(mO) - max(mE))

Submission status: Wrong Answer

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

mO = [0,] * 100010
mE = [0,] * 100010

for a in vA[0::2]:
  mO[a] += 1
for a in vA[1::2]:
  mE[a] += 1

modeO = mO.index(max(mO))
modeE = mE.index(max(mE))
if modeO == modeE:
  mO.pop(modeO)
print(N - max(mO) - max(mE))

Submission status: Wrong Answer

Solution code:
def slove():
    import sys
    import collections
    input = sys.stdin.readline
    do = collections.defaultdict(int)
    de = collections.defaultdict(int)
    n = int(input().rstrip('\n'))
    v = list(map(int, input().rstrip('\n').split()))
    for i, vv in enumerate(v):
        if i % 2 == 0:
            de[vv] += 1
        else:
            do[vv] += 1
    do = sorted(do.items(), key=lambda x: x[1], reverse=True)
    de = sorted(de.items(), key=lambda x: x[1], reverse=True)
    if do[0][0] == de[0][0]:
        if len(do) == len(de) == 1:
            print(min(de[0][1], do[0][1]))
        else:
            m = 10 ** 20
            m = min(m, n // 2 - do[0][1] + n // 2 - de[0][1])
            if len(do) != 1:
                m = min(m, n // 2 - do[1][1] + n // 2 - de[0][1])
            if len(de) != 1:
                m = min(m, n // 2 - do[0][1] + n // 2 - de[1][1])
            print(m)
    else:
        print(n // 2 - do[0][1] + n // 2 - de[0][1])


if __name__ == '__main__':
    slove()

Submission status: Wrong Answer

Solution code:
def slove():
    import sys
    import collections
    input = sys.stdin.readline
    do = collections.defaultdict(int)
    de = collections.defaultdict(int)
    n = int(input().rstrip('\n'))
    v = list(map(int, input().rstrip('\n').split()))
    for i, vv in enumerate(v):
        if i % 2 == 0:
            de[vv] += 1
        else:
            do[vv] += 1
    do = sorted(do.items(), key=lambda x: x[1], reverse=True)
    de = sorted(de.items(), key=lambda x: x[1], reverse=True)
    if do[0][0] == de[0][0]:
        if len(do) == len(de) == 1:
            print(de[0][1])
        else:
            m = 10 ** 20
            m = min(m, n // 2 - do[0][1] + n // 2 - de[0][1])
            if len(do) != 1:
                m = min(m, n // 2 - do[1][1] + n // 2 - de[0][1])
            if len(de) != 1:
                m = min(m, n // 2 - do[0][1] + n // 2 - de[1][1])
            print(m)
    else:
        print(n // 2 - do[0][1] + n // 2 - de[0][1])


if __name__ == '__main__':
    slove()

Submission status: Wrong Answer

Solution code:
#gcdは3.4.3だとfractionsにある
from fractions import gcd

from math import factorial as f

from math import ceil,floor,sqrt

from sys import exit

from copy import deepcopy
import numpy as np

import bisect
import re


ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))



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

    odd = v[::2]
    even = v[1::2]

    ocount = [0 for i in range(100005)]
    ecount = [0 for i in range(100005)]

    for i in odd:
        ocount[i] += 1
    for i in even:
        ecount[i] += 1

    om = np.argmax(ocount)
    em = np.argmax(ecount)

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

    if not om == em:
        print(n-(ocount[om]+ecount[em]))
        exit()

    if ocount[om] > ecount[em]:
        ecount[em] = 0
        em = np.argmax(ecount)
        print(n-(ocount[om]+ecount[em]))
    elif ecount[em] > ocount[om]:
        ocount[em] = 0
        om = np.argmax(ocount)
        print(n-(ocount[om]+ecount[em]))
    else:
        oc = ocount[om]
        ecount[em] = 0
        em = np.max(ecount)
        ocount[em] = 0
        om = np.max(ocount)

        print(n-(oc + max(om,em)))








main()

Submission status: Wrong Answer

Solution code:
#gcdは3.4.3だとfractionsにある
from fractions import gcd

from math import factorial as f

from math import ceil,floor,sqrt

from sys import exit

from copy import deepcopy
import numpy as np

import bisect
import re


ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))



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

    odd = v[::2]
    even = v[1::2]

    ocount = [0 for i in range(100005)]
    ecount = [0 for i in range(100005)]

    for i in odd:
        ocount[i] += 1
    for i in even:
        ecount[i] += 1

    om = np.argmax(ocount)
    em = np.argmax(ecount)

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

    if not om == em:
        print(n-(ocount[om]+ecount[em]))
        exit()

    if ocount[om] > ecount[em]:
        ecount[em] = 0
        em = np.argmax(ecount)
        print(n-(ocount[om]+ecount[em]))
    elif ecount[em] > ocount[om]:
        ocount[em] = 0
        om = np.argmax(ocount)
        print(n-(ocount[om]+ecount[em]))
    else:
        oc = ocount[om]
        ecount[em] = 0
        em = np.max(ecount)
        ocount[em] = 0
        om = np.max(ocount)

        print(n-(oc + max(om,em)))

Submission status: Wrong Answer

Solution code:
n = int(input())
v = [int(x) for x in input().split()]
a=[]
b=[]

for i in range(n):
  if i%2==0:
    a.append(v[i])
  else:
    b.append(v[i])
if a == b:
  print(n//2)
elif len(set(a)) ==1 and len(set(b)) ==1:
  print(0)
else:
  print( (len(set(a)))+len(set(b))-2)

Submission status: Wrong Answer

Solution code:
import collections
import sys

input = sys.stdin.readline

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

v_e = []
v_o = []

for i in range(0,n,2):
    v_e.append(v[i])
for j in range(1,n,2):
    v_o.append(v[j])

if len(collections.Counter(v)) == 1:
    print (n//2)
else:
    v_e_1 = collections.Counter(v_e)
    v_o_1 = collections.Counter(v_o)

    V_E = v_e_1.most_common()
    V_O = v_o_1.most_common()

    if V_E[0][0] != V_O[0][0]:
        print(len(v_e)-V_E[0][1]+len(v_o)-V_O[0][1])
    else:
        print(min([len(v_e)-V_E[1][1]+len(v_o)-V_O[0][1],len(V_E)-V_E[1][1]+len(V_O)-V_O[0][1]]))

Submission status: Wrong Answer

Solution code:
import collections
import sys

input = sys.stdin.readline

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

v_e = []
v_o = []

for i in range(0,n,2):
    v_e.append(v[i])
for j in range(1,n,2):
    v_o.append(v[j])

if len(collections.Counter(v)) == 1:
    print (n//2)
else:
    v_e_1 = collections.Counter(v_e)
    v_o_1 = collections.Counter(v_o)

    V_E = v_e_1.most_common()
    V_O = v_o_1.most_common()

    if V_E[0][0] != V_O[0][0]:
        print(len(v_e)-V_E[0][1]+len(v_o)-V_O[0][1])
    else:
        print(max([len(v_e)-V_E[1][1]+len(v_o)-V_O[0][1],len(V_E)-V_E[1][1]+len(V_O)-V_O[0][1]]))

Submission status: Wrong Answer

Solution code:
import collections
import sys

input = sys.stdin.readline

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

v_e = []
v_o = []

for i in range(0,n,2):
    v_e.append(v[i])
for j in range(1,n,2):
    v_o.append(v[j])

v_e_1 = collections.Counter(v_e)
v_o_1 = collections.Counter(v_o)

V_E = v_e_1.most_common(2)
V_O = v_o_1.most_common(2)

if V_E[0][0] != V_O[0][0]:
    print(len(v_e)-V_E[0][1]+len(v_o)-V_O[0][1])
elif len(V_E) > 1 and len(V_O) > 1:
    print(max([len(v_e)-V_E[1][1]+len(v_o)-V_O[0][1],len(V_E)-V_E[1][1]+len(V_O)-V_O[0][1]]))
elif len(V_E) > 1:
    print(max([len(v_e)-V_E[1][1]+len(v_o),len(v_o)-V_O[1][1]]))
elif len(V_O) > 1:
    print(max([len(v_o)-V_O[1][1]+len(v_e),len(v_e)-V_E[1][1]]))
else:
    print(len(v_e))

Submission status: Wrong Answer

Solution code:
import collections
import sys

input = sys.stdin.readline

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

v_e = []
v_o = []

for i in range(0,n,2):
    v_e.append(v[i])
for j in range(1,n,2):
    v_o.append(v[j])

v_e_1 = collections.Counter(v_e)
v_o_1 = collections.Counter(v_o)

V_E = v_e_1.most_common(2)
V_O = v_o_1.most_common(2)

if V_E[0][0] != V_O[0][0]:
    print(len(v_e)-V_E[0][1]+len(v_o)-V_O[0][1])
elif len(V_E) > 1 and len(V_O) > 1:
    print(max([len(v_e)-V_E[1][1]+len(v_o)-V_O[0][1],len(V_E)-V_E[1][1]+len(V_O)-V_O[0][1]]))
elif len(V_E) > 1:
    print(len(v_e)-V_E[1][1]+len(v_o))
elif len(V_O) > 1:
    print(len(v_o)-V_O[1][1]+len(v_e))
else:
    print(len(v_e))

Submission status: Wrong Answer

Solution code:
import collections
import sys

input = sys.stdin.readline

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

v_e = []
v_o = []

for i in range(0,n,2):
    v_e.append(v[i])
for j in range(1,n,2):
    v_o.append(v[j])

v_e_1 = collections.Counter(v_e)
v_o_1 = collections.Counter(v_o)

V_E = v_e_1.most_common(2)
V_O = v_o_1.most_common(2)

if V_E[0][0] != V_O[0][0]:
    print(len(v_e)-V_E[0][1]+len(v_o)-V_O[0][1])
elif len(V_E) > 1 and len(V_O) > 1:
    print(max([len(v_e)-V_E[1][1]+len(v_o)-V_O[1][1],len(V_E)-V_E[1][1]+len(V_O)-V_O[0][1]]))
elif len(V_E) > 1:
    print(len(v_e)-V_E[1][1]+len(v_o))
elif len(V_O) > 1:
    print(len(v_o)-V_O[1][1]+len(v_e))
else:
    print(len(v_e))

Submission status: Wrong Answer

Solution code:
from collections import Counter
n=int(input())
v=list(map(int,input().split()))
v1=v[::2]
v2=v[1::2]
c1=Counter(v1)
c2=Counter(v2)
c1[0]=0
c2[0]=0
c10,c11=c1.most_common(2)
c20,c21=c2.most_common(2)
if c10[0]!=c20[0]:
    print(n-(c10[1]+c20[1]))
else:
    print(n-min(c10[1]+c21[1],c11[1]+c20[1]))

Submission status: Wrong Answer

Solution code:
from collections import Counter
n=int(input())
v=list(map(int,input().split()))
v1=v[::2]
v2=v[1::2]
tmp1=Counter(v1)
tmp2=Counter(v2)
tmp1[0]=0
tmp2[0]=0
c10,c11=tmp1.most_common(2)
c20,c21=tmp2.most_common(2)
if c10[0]==c20[0]:
    print(n-min(c10[1]+c21[1],c11[1]+c20[1]))
else:
    print(n-(c10[1]+c20[1]))

Submission status: Wrong Answer

Solution code:
from collections import Counter
n=int(input())
v=list(map(int,input().split()))
v1=v[0::2]
v2=v[1::2]
tmp1=Counter(v1)
tmp2=Counter(v2)
tmp1[0]=0
tmp2[0]=0
c10,c11=tmp1.most_common(2)
c20,c21=tmp2.most_common(2)
if c10[0]==c20[0]:
    print(n-min(c10[1]+c21[1],c11[1]+c20[1]))
else:
    print(n-c10[1]-c20[1])

Submission status: Wrong Answer

Solution code:
from collections import Counter
n=int(input())
v=list(map(int,input().split()))
v1=v[0::2]
v2=v[1::2]
tmp1=Counter(v1)
tmp2=Counter(v2)
tmp1[0]=0
tmp2[0]=0
c1=tmp1.most_common(2)
c2=tmp2.most_common(2)
if c1[0][0]==c2[0][0]:
    print(n-max(c1[0][1]-c2[1][1],c1[1][1]-c2[0][1]))
else:
    print(n-c1[0][1]-c2[0][1])

Submission status: Wrong Answer

Solution code:
from collections import Counter
n=int(input())
v=list(map(int,input().split()))
v1=v[0::2]
v2=v[1::2]
tmp1=Counter(v1)
tmp2=Counter(v2)
tmp1[0]=0
tmp2[0]=0
c1=tmp1.most_common()
c2=tmp2.most_common()
if c1[0][0]==c2[0][0]:
    print(n-max(c1[0][1]-c2[1][1],c1[1][1]-c2[0][1]))
else:
    print(n-c1[0][1]-c2[0][1])

Submission status: Wrong Answer

Solution code:
from collections import Counter
n=int(input())
v=list(map(int,input().split()))
v1=v[0::2]
v2=v[1::2]
c1=Counter(v1).most_common()
c2=Counter(v2).most_common()
if len(set(v))==1:
    print(len(v)//2)
    exit(0)
if c1[0][0]==c2[0][0]:
    print(n-max(c1[0][1]-c2[1][1],c1[1][1]-c2[0][1]))
else:
    print(n-c1[0][1]-c2[0][1])

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import collections

def inverse_lookup(d, x):
    for k,v in d.items():
        if x == v:
            return k

n = int(input())
v_list = list(map(int, input().split()))
v_0_list = v_list[::2]
v_1_list = v_list[1::2]

v_0_count_dict = collections.Counter(v_0_list)
v_0_count_list = list(v_0_count_dict.values())
v_0_count_list.sort()
v_0_max_count = v_0_count_list[-1]
v_0_max = inverse_lookup(v_0_count_dict, v_0_max_count)

v_1_count_dict = collections.Counter(v_1_list)
v_1_count_list = list(v_1_count_dict.values())
v_1_count_list.sort()
v_1_max_count = v_1_count_list[-1]
v_1_max = inverse_lookup(v_1_count_dict, v_1_max_count)

ans = 0
if v_0_max == v_1_max:
    if v_0_max_count < v_1_max_count:
        v_0_max_count = v_0_count_list[-2]
    elif v_0_max_count > v_1_max_count:
        v_1_max_count = v_1_count_list[-2]
    elif v_0_max_count == v_1_max_count:
        if len(v_0_count_list) == 1:
            if len(v_1_count_list) == 1:
                v_0_max_count = 0
                v_1_max_count = len(v_1_list)
            else:
                v_1_max_count = v_1_count_list[-2]
        else:
            v_0_max_count = v_0_count_list[-2]
    ans += len(v_0_list) - v_0_max_count
    ans += len(v_1_list) - v_1_max_count
else:
    ans += len(v_0_list) - v_0_max_count
    ans += len(v_1_list) - v_1_max_count

print(ans)

Submission status: Wrong Answer

Solution code:
import collections

def inverse_lookup(d, x):
    for k,v in d.items():
        if x == v:
            return k

n = int(input())
v_list = list(map(int, input().split()))
v_0_list = v_list[::2]
v_1_list = v_list[1::2]

v_0_count_dict = collections.Counter(v_0_list)
v_0_count_list = list(v_0_count_dict.values())
v_0_count_list.sort()
v_0_max_count = v_0_count_list[-1]
v_0_max = inverse_lookup(v_0_count_dict, v_0_max_count)

v_1_count_dict = collections.Counter(v_1_list)
v_1_count_list = list(v_1_count_dict.values())
v_1_count_list.sort()
v_1_max_count = v_1_count_list[-1]
v_1_max = inverse_lookup(v_1_count_dict, v_1_max_count)

ans = 0
if v_0_max == v_1_max:
    if v_0_max_count < v_1_max_count:
        v_0_max_count = v_0_count_list[-2]
    elif v_0_max_count > v_1_max_count:
        v_1_max_count = v_1_count_list[-2]
    elif v_0_max_count == v_1_max_count:
        if len(v_0_count_list) == 1:
            if len(v_1_count_list) == 1:
                v_0_max_count = 0
                v_1_max_count = n//2
            else:
                v_1_max_count = v_1_count_list[-2]
        else:
            v_0_max_count = v_0_count_list[-2]
    ans += len(v_0_list) - v_0_max_count
    ans += len(v_1_list) - v_1_max_count
else:
    ans += len(v_0_list) - v_0_max_count
    ans += len(v_1_list) - v_1_max_count

print(ans)

Submission status: Wrong Answer

Solution code:
import collections

def inverse_lookup(d, x):
    for k,v in d.items():
        if x == v:
            return k

n = int(input())
v_list = list(map(int, input().split()))
v_0_list = v_list[::2]
v_1_list = v_list[1::2]

v_0_count_dict = collections.Counter(v_0_list)
v_0_count_list = list(v_0_count_dict.values())
v_0_count_list.sort()
v_0_max_count = v_0_count_list[-1]
v_0_max = inverse_lookup(v_0_count_dict, v_0_max_count)

v_1_count_dict = collections.Counter(v_1_list)
v_1_count_list = list(v_1_count_dict.values())
v_1_count_list.sort()
v_1_max_count = v_1_count_list[-1]
v_1_max = inverse_lookup(v_1_count_dict, v_1_max_count)

ans = 0
if v_0_max == v_1_max:
    if len(v_0_count_list) == 1:
        ans += n//2
    else:
        if v_0_max_count < v_1_max_count:
            v_0_max_count = v_0_count_list[-2]
        elif v_0_max_count >= v_1_max_count:
            v_1_max_count = v_1_count_list[-2]
        ans += len(v_0_list) - v_0_max_count
        ans += len(v_1_list) - v_1_max_count
else:
    ans += len(v_0_list) - v_0_max_count
    ans += len(v_1_list) - v_1_max_count

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
N = int (input())
List = list(map(int, input().split()))
List_even = List[0::2]
List_odd = List[1::2]

mode_even = Counter(List_even).most_common()
mode_odd = Counter(List_odd).most_common()
if List_odd == List_even:
    print (len(List_odd))
else:
    if mode_even[0][0] != mode_odd[0][0]:
        count_even = (N/2) - mode_even[0][1]
        count_odd =  (N/2) - mode_odd[0][1]
        print (int(count_even + count_odd))
    else:
        count1 = N - mode_even[0][1] - mode_odd[1][1]
        count2 = N - mode_even[1][1] - mode_odd[0][1]
        print (max(count1, count2))

Submission status: Wrong Answer

Solution code:
from collections import Counter
N = int (input())
List = list(map(int, input().split()))
List_even = List[0::2]
List_odd = List[1::2]

mode_even = Counter(List_even).most_common()
mode_odd = Counter(List_odd).most_common()
if List_odd == List_even:
    print (len(List_odd))
else:
    if mode_even[0][0] != mode_odd[0][0]:
        count_even = (N/2) - mode_even[0][1]
        count_odd =  (N/2) - mode_odd[0][1]
        print (int(count_even + count_odd))
    else:
        if mode_even[0][1] > mode_odd[0][1]:
            count_even = (N/2) - mode_even[0][1]
            count_odd  = (N/2) - mode_odd[1][1]
            print (int(count_even + count_odd))
        elif mode_even[0][1] < mode_odd[0][1]:
            count_even = (N/2) - mode_even[1][1]
            count_odd  = (N/2) - mode_odd[0][1]
            print (int(count_even + count_odd))
        else:
            if mode_even[1][1] > mode_odd[1][1]:
                count_even = (N/2) - mode_even[1][1]
                count_odd  = (N/2) - mode_odd[0][1]
                print (int(count_even + count_odd))
            else:
                count_even = (N/2) - mode_even[0][1]
                count_odd  = (N/2) - mode_odd[1][1]
                print (int(count_even + count_odd))

Submission status: Wrong Answer

Solution code:
from collections import Counter
N = int (input())
List = list(map(int, input().split()))
List_even = List[0::2]
List_odd = List[1::2]

mode_even = Counter(List_even).most_common()
mode_odd = Counter(List_odd).most_common()
if List_odd == List_even:
    print (len(List_odd))
else:
    if mode_even[0][0] != mode_odd[0][0]:
        count_even = (N/2) - mode_even[0][1]
        count_odd =  (N/2) - mode_odd[0][1]
        print (int(count_even + count_odd))
    else:
        if mode_even[0][1] >= mode_odd[0][1]:
            count_even = (N/2) - mode_even[0][1]
            count_odd  = (N/2) - mode_odd[1][1]
            print (int(count_even + count_odd))
        elif mode_even[0][1] < mode_odd[0][1]:
            count_even = (N/2) - mode_even[1][1]
            count_odd  = (N/2) - mode_odd[0][1]
            print (int(count_even + count_odd))

Submission status: Wrong Answer

Solution code:
from collections import Counter
N = int (input())
List = list(map(int, input().split()))
List_even = List[0::2]
List_odd = List[1::2]

mode_even = Counter(List_even).most_common()
mode_odd = Counter(List_odd).most_common()
if List_odd == List_even:
    print (len(List_odd))
else:
    if mode_even[0][0] != mode_odd[0][0]:
        count_even = (N/2) - mode_even[0][1]
        count_odd =  (N/2) - mode_odd[0][1]
        print (count_even + count_odd)
    else:
        if mode_even[0][1] >= mode_odd[0][1]:
            count_even = (N/2) - mode_even[0][1]
            count_odd  = (N/2) - mode_odd[1][1]
            print (count_even + count_odd)
        elif mode_even[0][1] < mode_odd[0][1]:
            count_even = (N/2) - mode_even[1][1]
            count_odd  = (N/2) - mode_odd[0][1]
            print (count_even + count_odd)
    print (count_even)
    print (count_odd)

Submission status: Wrong Answer

Solution code:
n=int(input())
v=list(map(int,input().split()))
v_odd={}
v_even={}
for i,x in enumerate(v):
  if i%2==0:
    if x in v_odd:#none [x] in v_??
      v_odd[x]+=1
    else:
      v_odd[x]=1
  else:
    if x in v_even:#none [x] in v_??
      v_even[x]+=1
    else:
      v_even[x]=1

v_odd_top = sorted(v_odd.items(), key=lambda x:x[1],reverse=True)[:2]
v_even_top = sorted(v_even.items(), key=lambda x:x[1],reverse=True)[:2]

if v_odd_top[0][0]!=v_even_top[0][0]:
  v_odd_ans=v_odd_top[0][1]
  v_even_ans=v_even_top[0][1]
else:
  if len(v_odd_top)>1 and len(v_even_top)>1:
    if v_odd_top[1][1]>v_even_top[1][1]:
      v_odd_ans=v_odd_top[0][1]
      v_even_ans=v_even_top[1][1]
    else:
      v_odd_ans=v_odd_top[1][1]
      v_even_ans=v_even_top[0][1]
  elif len(v_odd_top)==1 and len(v_even_top)>1:
    v_odd_ans=0
    v_even_ans=v_even_top[1][1]
  elif len(v_odd_top)>1 and len(v_even_top)==1:
    v_odd_ans=v_odd_top[1][1]
    v_even_ans=0
  elif len(v_odd_top)==1 and len(v_even_top)==1:
    v_odd_ans=v_odd_top[0][1]
    v_even_ans=0
            
sum_freq = sum(v_odd.values())+sum(v_even.values())
ans=sum_freq - ( v_odd_ans + v_even_ans )
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

tmp = n // 2

tmp1 = []
tmp2 = []

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

tmp1 = Counter(tmp1)
tmp2 = Counter(tmp2)

ans = (tmp - tmp1.most_common()[0][1]) + (tmp - tmp2.most_common()[0][1])
if ans == 0 and len(Counter(v)) == 1:
    print(tmp)
else:
    print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

tmp = n // 2

tmp1 = []
tmp2 = []

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

tmp1 = Counter(tmp1)
tmp2 = Counter(tmp2)

ans = (tmp - tmp1.most_common()[0][1]) + (tmp - tmp2.most_common()[0][1])
if ans == 0 and len(Counter(v)) == 1:
    print(1)
else:
    print(ans)

Submission status: Wrong Answer

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

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

for i in range(n):
    if i%2==0:
        v_even[v[i]][1] +=1
    else:
        v_odd[v[i]][1] +=1

v_even_s=sorted(v_even,key=lambda x:x[1],reverse=True)
v_odd_s=sorted(v_odd,key=lambda x:x[1],reverse=True)

sum1=0
sum2=0

i=0
f=True

while f:
    if v_even_s[i][0]!=v_odd_s[i][0]:
        if v_even_s[i][1]>v_odd_s[i][1]:
            v_even_s.pop(i)
            v_odd_s.pop(0)
        else:
            v_even_s.pop(0)
            v_odd_s.pop(i)
        f=False
    else:
        i+=1
        if i==n//2:
            print(n//2)
            exit()

for i in range(n-1):
    sum1+=v_even_s[i][1]
    sum2+=v_odd_s[i][1]
ans=sum1+sum2
print(ans)

Submission status: Wrong Answer

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

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

for i in range(n):
    if i%2==0:
        v_even[v[i]][1] +=1
    else:
        v_odd[v[i]][1] +=1

v_even_s=sorted(v_even,key=lambda x:x[1],reverse=True)
v_odd_s=sorted(v_odd,key=lambda x:x[1],reverse=True)

sum1=0
sum2=0

i=0
f=True

while f:
    if v_even_s[i][0]!=v_odd_s[i][0]:
        v_even_s.pop(i)
        v_odd_s.pop(i)
        f=False
    else:
        i+=1
        if i==n//2:
            print(n//2)
            exit()

for i in range(n-1):
    sum1+=v_even_s[i][1]
    sum2+=v_odd_s[i][1]
ans=sum1+sum2
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
l=list(map(int,input().split()))
sl=set(l)
if len(sl)==1:
  print(n//2)
elif len(sl)>2:
  ans=n//2
  lsl=list(sl)
  d=len(sl)
  for a in range(d)[1:]:
    for b in range(d)[:a]:
      y,x=lsl[a],lsl[b]
      g,h=0,0
      for rt in [jk for jk in range(n) if jk%2==0]:
        if l[rt] != y:
          g+=1
        if l[rt] != x:
          h+=1
      for ef in [jc for jc in range(n) if jc%2==1]:
        if l[ef]!=x:
          g+=1
        if l[ef]!=y:
          h+=1
      ans=min([g,h,ans])
  print(ans)
else:
  a,b=list(sl)[0],list(sl)[1]
  s,d=0,0
  for i in [_ for _ in range(n) if _%2==0]:
    if l[i]!=a:
      s+=1
    else:
      d+=1
  for jg in [lk for lk in range(n) if lk%2==1]:
    if l[jg]!=a:
      d+=1
    else:
      s+=1
  print(min([s,d]))

Submission status: Wrong Answer

Solution code:
# 2125
n = int(input())
get_inf = list(map(int, input().split(' ')))
a = get_inf[::2]
b = get_inf[1::2]

def count_unique(lis):
    r = []
    s = []
    i = 0
    while i < len(lis):
        count = 1
        k = i + 1
        if lis[i] > 0:
            while k < len(lis):
                if lis[i] == lis[k] and lis[k] > 0:
                    count += 1
                    lis[k] *= -1
                k += 1
            r.append(count)
            s.append(lis[i])
            lis[i] *= -1
            i += 1
        else:
            i += 1
    return r, s

x = []
x_1 = []
y = []
y_1= []
x, x_1 = count_unique(a)
y, y_1 = count_unique(b)
x.append(0)
y.append(0)

if x_1[x.index(max(x))] != y_1[y.index(max(y))]:
    print(n-max(x)-max(y))
else:
    print('x')
    p = max(x)
    q = max(y)
    x[x.index(max(x))] *= -1
    y[y.index(max(y))] *= -1
    print(min([n-p-max(y), n-q-max(x)]))