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:
a = int(input())
x = list(map(int, input().split()))
y=[]
z=[]
from collections import Counter
for i in range(a):
    if i%2==0:
        y.append(x[i])
    else:
        z.append(x[i])
y.append(0)
z.append(0)
c= Counter(y)
d = Counter(z)
c1=c.most_common()[0][1]
c2=c.most_common()[0][1]
d1=d.most_common()[0][1]
d2=d.most_common()[0][1]
if c.most_common()[0][0]== d.most_common()[0][0]:
    s = a-max(c1+d2,c2+d1)

else:s= a - c.most_common()[0][1] - d.most_common()[0][1]
print(s)

Submission status: Wrong Answer

Solution code:
import collections

n = int(input())
v_list = [int(x) for x in input().split()]
v_oddlist = v_list[::2]
v_evenlist = v_list[1::2]
c_odd = collections.Counter(v_oddlist)
c_even = collections.Counter(v_evenlist)
if c_odd.most_common()[0][0] != c_even.most_common()[0][0]:
    print(n - c_odd.most_common()[0][1] - c_even.most_common()[0][1])
elif len(c_odd.most_common()) == 1 and len(c_even.most_common()) == 1:
    print(n - c_odd.most_common()[0][1])
else:
    a = c_odd.most_common()[0][1] + c_even.most_common()[1][1]
    b = c_odd.most_common()[1][1] + c_even.most_common()[0][1]
    if a > b:
        print(n - b)
    else:
        print(n - a)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

a = Counter(v[::2]).most_common()
b = Counter(v[1::2]).most_common()

total = 0
if len(a) == 1 and len(b) == 1:
    total = n // 2
else:
    for i in range(1, len(a)):
        total += a[i][1]
    
    for i in range(1, len(b)):
        total += b[i][1]
print(total)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n=int(input())
v=list(map(int,input().split()))
E=[0]*(n//2)
O=[0]*(n//2)
for i in range(n):
    if i%2==0:
        O[i//2]=v[i]
    else:
        E[i//2]=v[i]
cntE=Counter(E)
cntO=Counter(O)
if cntE.most_common()[0][0]!=cntO.most_common()[0][0]:
    print(n-cntE.most_common()[0][1]-cntO.most_common()[0][1])
else:
    if len(cntE.most_common())==1 and len(cntO.most_common())==1:
        print(n//2)
    elif len(cntE.most_common())==1:
        print(n-cntE.most_common()[0][1]-cntO.most_common()[1][1])
    elif len(cntO.most_common())==1:
        print(n-cntE.most_common()[1][1]-cntO.most_common()[0][1])
    else:
        if cntE.most_common()[0][1]>=cntO.most_common()[0][1]:
            print(n-cntE.most_common()[0][1]-cntO.most_common()[1][1])
        else:
            print(n-cntE.most_common()[1][1]-cntO.most_common()[0][1])

Submission status: Wrong Answer

Solution code:
from collections import Counter
n=int(input())
v=list(map(int,input().split()))
E=[0]*(n//2)
O=[0]*(n//2)
for i in range(n):
    if i%2==0:
        E[i//2]=v[i]
    else:
        O[i//2]=v[i]
cntE=Counter(E)
cntO=Counter(O)
if cntE.most_common()[0][0]!=cntO.most_common()[0][0]:
    print(n-cntE.most_common()[0][1]-cntO.most_common()[0][1])
else:
    if len(cntE.most_common())==1 and len(cntO.most_common())==1:
        print(n//2)
    else:
        if cntE.most_common()[0][1]>=cntO.most_common()[0][1]:
            print(n-cntE.most_common()[0][1]-cntO.most_common()[1][1])
        else:
            print(n-cntE.most_common()[1][1]-cntO.most_common()[0][1])

Submission status: Wrong Answer

Solution code:
from collections import Counter
n=int(input())
v=list(map(int,input().split()))
E=[0]*(n//2)
O=[0]*(n//2)
for i in range(n):
    if i%2==0:
        E[i//2]=v[i]
    else:
        O[i//2]=v[i]
cntE=Counter(E)
cntO=Counter(O)
if cntE.most_common()[0][0]!=cntO.most_common()[0][0]:
    print(n-cntE.most_common()[0][1]-cntO.most_common()[0][1])
else:
    if len(cntE.most_common())==1 and len(cntO.most_common())==1:
        print(n//2)
    elif len(cntE.most_common())==1:
        print(n-cntE.most_common()[0][1]-cntO.most_common()[1][1])
    elif len(cntO.most_common())==1:
        print(n-cntE.most_common()[1][1]-cntO.most_common()[0][1])
    else:
        if cntE.most_common()[0][1]>=cntO.most_common()[0][1]:
            print(n-cntE.most_common()[0][1]-cntO.most_common()[1][1])
        else:
            print(n-cntE.most_common()[1][1]-cntO.most_common()[0][1])

Submission status: Wrong Answer

Solution code:
from collections import Counter
n=int(input())
v=list(map(int,input().split()))
E=[0]*(n//2)
O=[0]*(n//2)
for i in range(n):
    if i%2==0:
        E[i//2]=v[i]
    else:
        O[i//2]=v[i]
cntE=Counter(E)
cntO=Counter(O)
if cntE.most_common()[0][0]!=cntO.most_common()[0][0]:
    print(n-cntE.most_common()[0][1]-cntO.most_common()[0][1])
else:
    if len(cntE.most_common())==1 and len(cntO.most_common())==1:
        print(n//2)
    elif len(cntE.most_common())==1:
        print(n-cntE.most_common()[0][1]-cntO.most_common()[1][1])
    elif len(cntO.most_common())==1:
        print(n-cntE.most_common()[1][1]-cntO.most_common()[0][1])
    else:
        if cntE.most_common()[0][0]>=cntO.most_common()[0][0]:
            print(n-cntE.most_common()[0][1]-cntO.most_common()[1][1])
        else:
            print(n-cntE.most_common()[1][1]-cntO.most_common()[0][1])

Submission status: Wrong Answer

Solution code:
import collections

A = int(input())
A2 = list(map(int,input().split()))
B1 = []
B2 = []

for i in range(A):
    if(i % 2 == 0):
        B1.append(A2[i])
    else:
        B2.append(A2[i])

C1 = collections.Counter(B1)
C2 = collections.Counter(B2)


B1A = len(B1) - C1.most_common()[0][1]
B2A = len(B2) - C2.most_common()[0][1]

S = B1A + B2A

if(S == 0 and B1[0] == B2[0]):
    print(len(B1))
else:
    print(S)

Submission status: Wrong Answer

Solution code:
n = int(input())
v = [int(i) for i in input().split()] 
import collections
if len(set(v))  == 1:
    print(int(len(v) / 2))
else:
    a = collections.Counter(v[0::2]).most_common()
    b = collections.Counter(v[1::2]).most_common()
    if a == b:
        print(min((len(v[0::2]) - a[1][1] + len(v[1::2]) - b[0][1]),(len(v[0::2]) - a[0][1] + len(v[1::2]) - b[1][1])))
    else:
        print(len(v[0::2]) - a[0][1] + len(v[1::2]) - b[0][1])

Submission status: Wrong Answer

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

import collections
if len(set(v))  == 1:
    print(int(len(v) / 2))
else:
    print(len(v[0::2]) - collections.Counter(v[0::2]).most_common()[0][1] + len(v[1::2]) - collections.Counter(v[1::2]).most_common()[0][1])

Submission status: Wrong Answer

Solution code:
N = int(input())
V = list(map(int,input().split()))
ans = 0
check = {}
for i in range(N-2):
  if(V[i] not in check):
    check[V[i]] = 1
  else:
    check[V[i]] += 1
  if(V[i] != V[i+2]):
    ans += 1
if(len(check) == 1):
  print(int(N/2))
else:
  print(ans)

Submission status: Wrong Answer

Solution code:
import collections

n = int(input())
V = input().split()
V = list(map(lambda x: int(x), V))

flag = True
for i in range(len(V)):
  flag = flag and V[i] == V[0]

if flag:
  answer = n // 2
else:
  odd = []
  even = []
  for i in range(len(V)):
    if i % 2 == 1:
      odd.append(V[i])
    else:
      even.append(V[i])
  o_counter = collections.Counter(odd)
  e_counter = collections.Counter(even)
  o = o_counter.most_common()
  e = e_counter.most_common()
  o_num = 0
  e_num = 0
  if o[0][0] != e[0][0]:
    o_num = o[0][0]
    e_num = e[0][0]
  else:
    if o[1][0] > e[1][0]:
      o_num = o[1][0]
      e_num = e[0][0]
    elif o[1][0] <= e[1][0]:
      o_num = o[0][0]
      e_num = e[1][0]
  answer = n - o_counter[o_num] - e_counter[e_num]

print(answer)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
list =input().split(" ")
odd_list = []
even_list = []
for i in range(n):

    if i % 2 == 0:
        even_list.append(list[i])
    else:
        odd_list.append(list[i])
Count_even_list = Counter(even_list)
Count_odd_list = Counter(odd_list)


if len(set(list)) == 1:
    print(int(len(list) / 2))
else:
    print(len(even_list) - Count_even_list.most_common()[0][1] + len(odd_list) - Count_odd_list.most_common()[0][1])

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
list =input().split(" ")
odd_list = []
even_list = []
for i in range(n):

    if i % 2 == 0:
        even_list.append(list[i])
    else:
        odd_list.append(list[i])
Count_even_list = Counter(even_list)
Count_odd_list = Counter(odd_list)


if len(set(list)) == 1:
    print(2)
else:
    print(len(even_list) - Count_even_list.most_common()[0][1] + len(odd_list) - Count_odd_list.most_common()[0][1])

Submission status: Wrong Answer

Solution code:
def getMode(target:list):
    cache = {}
    for x in target:
        if x in cache:
            cache[x] = cache[x] + 1
        else:
            cache[x] = 1
    return sorted(cache.items(), key=lambda x: x[1], reverse=True)


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

guu = []
ki = []
for i, n in enumerate(v):
    if i % 2 == 0:
        guu.append(n)
    else:
        ki.append(n)

gMode = getMode(guu)
g = gMode[0][0]
kMode = getMode(ki)
k = kMode[0][0]

if g == k:
    if len(gMode) == 1:
        if len(kMode) == 1:
            k = g + 1
        else:
            k = kMode[1][0]
    elif len(kMode) == 1:
        g = gMode[1][0]
    else:
        if gMode[0][1] == kMode[0][1]:
            if gMode[1][1] < kMode[1][1]:
                k = kMode[1][0]
            else:
                g = gMode[1][0]
        if gMode[0][1] < kMode[0][1]:
            g = gMode[1][0]
        else:
            k = kMode[1][0]

result = 0
for n in guu:
    if n != g:
        result += 1

for n in ki:
    if n!= k:
        result += 1

print(result)

Submission status: Wrong Answer

Solution code:
def getMode(target:list):
    cache = {}
    for x in target:
        if x in cache:
            cache[x] = cache[x] + 1
        else:
            cache[x] = 1
    return sorted(cache.items(), key=lambda x: x[1], reverse=True)


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

guu = []
ki = []
for i, n in enumerate(v):
    if i % 2 == 0:
        guu.append(n)
    else:
        ki.append(n)

gMode = getMode(guu)
g = gMode[0][0]
kMode = getMode(ki)
k = kMode[0][0]

if g == k:
    if len(gMode) == 1:
        if len(kMode) == 1:
            k = g + 1
        else:
            k = kMode[1][0]
    elif len(kMode) == 1:
        g = gMode[1][0]
    else:
        if gMode[0][1] < kMode[0][1]:
            g = gMode[1][0]
        else:
            k = kMode[1][0]

result = 0
for n in guu:
    if n != g:
        result += 1

for n in ki:
    if n!= k:
        result += 1

print(result)

Submission status: Wrong Answer

Solution code:
def getMode(target:list):
    cache = {}
    for x in target:
        if x in cache:
            cache[x] = cache[x] + 1
        else:
            cache[x] = 1
    return sorted(cache.items(), key=lambda x: x[1], reverse=True)


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

guu = []
ki = []
for i, n in enumerate(v):
    if i % 2 == 0:
        guu.append(n)
    else:
        ki.append(n)

gMode = getMode(guu)
g = gMode[0][0]
kMode = getMode(ki)
k = kMode[0][0]

if g == k:
    if len(gMode) == 1:
        if len(kMode) == 1:
            k = g + 1
        else:
            k = kMode[1][0]
    else:
        if gMode[0][1] < kMode[0][1]:
            g = gMode[1][0]
        else:
            k = kMode[1][0]

result = 0
for n in guu:
    if n != g:
        result += 1

for n in ki:
    if n!= k:
        result += 1

print(result)

Submission status: Wrong Answer

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

listOddNumber=[]
listEvenNumber=[]

index=0
while index < n:
    if index%2==0:
        listEvenNumber.append(listV[index])
    else:
        listOddNumber.append(listV[index])
    index+=1

listEvenNumber.sort()
listOddNumber.sort()

#[count, numberitself]
EvenMaxN = [0, 0]
EvenMaxN2 = [0, 0]
evenBefore=0
evenCounter=0
index2=0
while index2 < len(listEvenNumber):
    if index2==0:
        evenBefore=listEvenNumber[index2]
        evenCounter=1
    elif listEvenNumber[index2]==evenBefore:
        evenCounter+=1
    else:
        if evenCounter > EvenMaxN[0]:
            EvenMaxN=[evenCounter, evenBefore]
        elif evenCounter > EvenMaxN2[0]:
            EvenMaxN2 = [evenCounter, evenBefore]
        evenBefore = listEvenNumber[index2]
        evenCounter=1
    index2+=1
if evenCounter > EvenMaxN[0]:
    EvenMaxN=[evenCounter, evenBefore]
elif evenCounter > EvenMaxN2[0]:
    EvenMaxN2 = [evenCounter, evenBefore]

#[count, numberItself]
OddMaxN = [0, 0]
OddMaxN2 = [0, 0]
oddBefore=0
oddCounter=0
index3=0
while index3 < len(listOddNumber):
    if index3==0:
        oddBefore=listOddNumber[index3]
        oddCounter=1
    elif listOddNumber[index3]==oddBefore:
        oddCounter+=1
    else:
        if oddCounter > OddMaxN[0]:
            OddMaxN=[oddCounter, oddBefore]
        elif oddCounter > OddMaxN2[0]:
            OddMaxN2 = [oddCounter, oddBefore]
        oddBefore = listOddNumber[index3]
        oddCounter=1
    index3+=1
if oddCounter > OddMaxN[0]:
    OddMaxN = [oddCounter, oddBefore]
elif oddCounter > OddMaxN2[0]:
    OddMaxN2 = [oddCounter, oddBefore]


if OddMaxN[1]!=EvenMaxN[1]:
    print(n-OddMaxN[0]-EvenMaxN[0])
else:
    if OddMaxN[0]+EvenMaxN2[0] > OddMaxN2[0]+EvenMaxN[0]:
        print(n-OddMaxN[0]-EvenMaxN2[0])
    else:
        print(n-OddMaxN2[0]-EvenMaxN[0])

Submission status: Wrong Answer

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

listOddNumber=[]
listOddCounter=[]
listEvenNumber=[]
listEvenCounter=[]

index=0
while index < n:
    if index%2==0:
        if listV[index] in listEvenNumber:
            targetI = listEvenNumber.index(listV[index])
            listEvenCounter[targetI]+=1
        else:
            listEvenNumber.append(listV[index])
            listEvenCounter.append(1)
    else:
        if listV[index] in listOddNumber:
            targetI = listOddNumber.index(listV[index])
            listOddCounter[targetI]+=1
        else:
            listOddNumber.append(listV[index])
            listOddCounter.append(1)
    index+=1

oddMaxIndex = listOddCounter.index(max(listOddCounter))
evenMaxIndex = listEvenCounter.index(max(listEvenCounter))

oddMaxNumber = listOddNumber[oddMaxIndex]
evenMaxNumer = listEvenNumber[evenMaxIndex]

if oddMaxNumber!=evenMaxNumer:
    print(n-max(listOddCounter)-max(listEvenCounter))
else:
    if max(listOddCounter)>max(listEvenCounter):
        del listEvenCounter[evenMaxIndex]
        del listEvenNumber[evenMaxIndex]
        if listEvenCounter == []:
            listEvenCounter.append(0)
    else:
        del listOddCounter[oddMaxIndex]
        del listOddNumber[oddMaxIndex]
        if listOddCounter == []:
            listOddCounter.append(0)
    print(n-max(listOddCounter)-max(listEvenCounter))

Submission status: Wrong Answer

Solution code:
a=[0]*100001
b=[0]*100001

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

for i in range(0,n,2):
  a[v[i]]+=1
for i in range(1,n,2):
  b[v[i]]+=1

if max(a)+max(b)==n and v[1]==v[0]:
  print(n//2)
elif a.index(max(a))==b.index(max(b)):
  a= sorted(a, reverse=True)
  b= sorted(b, reverse=True)
  print(min(n-a[1]+b[0],n-a[0]-b[1]))
else:
  print(n-max(a)-max(b))

Submission status: Wrong Answer

Solution code:
a=[0]*100001
b=[0]*100001

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

for i in range(0,n,2):
  a[v[i]]+=1
for i in range(1,n,2):
  b[v[i]]+=1

if max(a)+max(b)==n and v[1]==v[0]:
  print(n//2)
elif a.index(max(a))==b.index(max(b)):
  a= sorted(a)
  b= sorted(b)
  print(min(n-a[1]+b[0],n-a[0]-b[1]))
else:
  print(n-max(a)-max(b))

Submission status: Wrong Answer

Solution code:
a=[0]*100001
b=[0]*100001

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

for i in range(0,n,2):
  a[v[i]]+=1
for i in range(1,n,2):
  b[v[i]]+=1

if max(a)+max(b)==n and v[1]==v[0]:
  print(n//2)
elif a.index(max(a))==b.index(max(b)):
  a= sorted(a)
  b= sorted(b)
  print(min(n-a[2]+b[1],n-a[1]-b[2]))
else:
  print(n-max(a)-max(b))

Submission status: Wrong Answer

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


def m():
    first = V[0::2]
    second = V[1::2]
    fdic = {}
    sdic = {}
    for i in range(N//2):
        if fdic.get(first[i], 0) == 0:
            fdic[first[i]] = 1
        else:
            fdic[first[i]] +=1

        if sdic.get(second[i], 0) == 0:
            sdic[second[i]] = 1
        else:
            sdic[second[i]] +=1
    flist = list(fdic.items())
    slist = list(sdic.items())

    flist.sort(reverse=True, key=lambda x:x[1])
    slist.sort(reverse=True, key=lambda x:x[1])

    if flist[0][0] != slist[0][0] and len(flist) == 1 and len(slist) == 1:
        return 0


    if flist[0][0] != slist[0][0]:
        ans = 0
        for k, v in flist[1:]:
            ans += v
        for k, v in slist[1:]:
            ans += v
        return ans

    if flist[0][1] == slist[0][1]:
        return N//2

    if flist[0][1] > slist[0][1]:
        ans = 0
        for k, v in flist[1:]:
            ans += v
        for k, v in slist[2:]:
            ans += v
        ans += slist[0][0]
        return ans
    else:
        ans = 0
        for k, v in slist[1:]:
            ans += v
        for k, v in flist[2:]:
            ans += v
        ans += flist[0][0]
        return ans

print(m())

Submission status: Wrong Answer

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


def m():
    first = V[0::2]
    second = V[1::2]
    fdic = {}
    sdic = {}
    for i in range(N//2):
        if fdic.get(first[i], 0) == 0:
            fdic[first[i]] = 1
        else:
            fdic[first[i]] +=1

        if sdic.get(second[i], 0) == 0:
            sdic[second[i]] = 1
        else:
            sdic[second[i]] +=1
    flist = list(fdic.items())
    slist = list(sdic.items())

    flist.sort(reverse=True, key=lambda x:x[1])
    slist.sort(reverse=True, key=lambda x:x[1])

    if flist[0][0] != slist[0][0] and len(flist) == 1 and len(slist) == 1:
        return 0

    if flist[0][0] != slist[0][0]:
        ans = 0
        for k, v in flist[1:]:
            ans += v
        for k, v in slist[1:]:
            ans += v
        return ans

    if flist[0][1] > slist[0][1]:
        ans = 0
        for k, v in flist[1:]:
            ans += v
        for k, v in slist[2:]:
            ans += v
        ans += slist[0][0]
        return ans
    else:
        ans = 0
        for k, v in slist[1:]:
            ans += v
        for k, v in flist[2:]:
            ans += v
        ans += flist[0][0]
        return ans

print(m())

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    v = list(map(int, input().split()))
    e = [0 for _ in range(1, 10 ** 5 + 2)]
    o = [0 for _ in range(1, 10 ** 5 + 2)]
    for i in range(0, n, 2):
        e[v[i]] += 1
        o[v[i + 1]] += 1
    ans = 0
    if len(set(v)) == 1:
        ans = n // 2
    else:
        ans += n // 2 - max(e)
        ans += n // 2 - max(o)
    print(ans)


main()

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    v = list(map(int, input().split()))
    e = [0 for _ in range(1, 10 ** 5 + 2)]
    o = [0 for _ in range(1, 10 ** 5 + 2)]
    for i in range(0, n, 2):
        e[v[i]] += 1
        o[v[i + 1]] += 1
    ans = 0
    if len(set(v)) == 1:
        ans = n // 2
    else:
        if n // 2 > max(e):
            ans += n // 2 - max(e)
        if n // 2 > max(o):
            ans += n // 2 - max(o)
    print(ans)


main()

Submission status: Wrong Answer

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


def m():
    first = V[0::2]
    second = V[1::2]
    fdic = {}
    sdic = {}
    for i in range(N//2):
        if fdic.get(first[i], 0) == 0:
            fdic[first[i]] = 1
        else:
            fdic[first[i]] +=1

        if sdic.get(second[i], 0) == 0:
            sdic[second[i]] = 1
        else:
            sdic[second[i]] +=1
    flist = list(fdic.items())
    slist = list(sdic.items())

    flist.sort(reverse=True, key=lambda x:x[1])
    slist.sort(reverse=True, key=lambda x:x[1])

    if flist[0][0] != slist[0][0] and len(flist) == 1 and len(slist) == 1:
        return 0

    if flist[0][0] != slist[0][0]:
        ans = 0
        for i in range(1, len(flist)):
            ans += flist[i][1]
        for i in range(1, len(slist)):
            ans += slist[i][1]
        return ans
    else:
        ans = 0
        if flist[0][0] > slist[0][0]:
            for i in range(1, len(flist)):
                ans += flist[i][1]
            for i in range(2, len(slist)):
                ans += slist[i][1]
            ans += slist[0][1]
            return ans
        else:
            for i in range(1, len(slist)):
                ans += slist[i][1]
            for i in range(2, len(flist)):
                ans += flist[i][1]
            ans += flist[0][1]
            return ans

print(m())

Submission status: Wrong Answer

Solution code:
def count2(lst):
    ans = [["",0],0]
    def check():
        nonlocal ans
        if a > ans[0][1]:
            ans[1] = ans[0][1]
            ans[0][0] = last
            ans[0][1] = a
        elif a > ans[1]:
            ans[1] = a
    lst.sort()
    last =lst[0]
    a = 0
    for e in lst:
        if last == e:
            a +=1
        else:
            check()
            last = e
            a = 1
    check()
    return ans

def main(lst:list)->int:
    n = len(lst)
    ans1 =count2(lst[::2])
    ans2 =count2(lst[1::2])
    if ans1[0][0] == ans2[0][0]:
        if ans1[1] and ans2[1]:
            return n - max(ans1[0][1] + ans2[1],ans2[0][1] + ans1[1])
        else:
            return n//2
    else:
        return n - ans1[0][1] - ans2[0][1]

Submission status: Wrong Answer

Solution code:
def main(n:int,lst:list)->int:
    lst1 = lst[::2]
    lst2 = lst[1::2]
    ans1 =count2(lst1)
    ans2 =count2(lst2)
    if ans1[0][0] == ans2[0][0]:
        if ans1[1] and ans2[1]:
            return n - max(ans1[0][1] + ans2[1],ans2[0][1] + ans1[1])
        else:
            return n//2
    else:
        return n - ans1[0][1] - ans2[0][1]
def count2(lst):
    lst.sort()
    ans = [["",0],0]
    last =lst[0]
    a = 0
    for e in lst:
        if last == e:
            a +=1
        else:
            ans = check(a,e,ans)
            last = e
            a = 1
    return check(a,e,ans)
def check(a,e,ans):
    if a > ans[0][1]:
        ans[1] = ans[0][1]
        ans[0][0] = e
        ans[0][1] = a
    elif a > ans[1]:
        ans[1] = a
    return ans
n = int(input())
lst = input().split()
print(main(n,lst))

Submission status: Wrong Answer

Solution code:
def main(n:int,lst:list)->int:
    lst1 = lst[::2]
    lst2 = lst[1::2]
    lst1.sort()
    lst2.sort()
    c1 = [["",0],0]
    c2 = [["",0],0]
    last =lst1[0]
    a = 0
    for e in lst1:
        if last == e:
            a +=1
        else:
            if a > c1[0][1]:
                c1[1] = c1[0][1]
                c1[0][0] = e
                c1[0][1] = a
            elif a > c1[1]:
                c1[1] = a
            last = e
            a = 1
    if a > c1[0][1]:
        c1[1] = c1[0][1]
        c1[0][0] = e
        c1[0][1] = a
    elif a > c1[1]:
        c1[1] = a

    last =lst2[0]
    a = 0
    for e in lst2:
        if last == e:
            a +=1
        else:
            if a > c2[0][1]:
                c2[1] = c2[0][1]
                c2[0][0] = e
                c2[0][1] = a
            elif a > c2[1]:
                c2[1] = a
            last = e
            a = 1
    if a > c2[0][1]:
        c2[1] = c2[0][1]
        c2[0][0] = e
        c2[0][1] = a
    elif a > c2[1]:
        c2[1] = a

    if c1[0][0] == c2[0][0]:
        if c1[1] and c2[1]:
            return n - max(c1[0][1] + c2[1],c2[0][1] + c1[1])
        else:
            return n//2            
    else:
        return n - c1[0][1] - c2[0][1]

n = int(input())
lst = input().split()
print(main(n,lst))

Submission status: Wrong Answer

Solution code:
def main(n:int,lst:list)->int:
    lst1 = lst[::2]
    lst2 = lst[1::2]
    lst1.sort()
    lst2.sort()
    c1 = [["",0],0]
    c2 = [["",0],0]
    last =lst1[0]
    a = 0
    for e in lst1:
        if last == e:
            a +=1
        else:
            if a > c1[0][1]:
                c1[1] = c1[0][1]
                c1[0][0] = e
                c1[0][1] = a
            elif a > c1[1]:
                c1[1] = a
            last = e
            a = 1
    if a > c1[0][1]:
        c1[1] = c1[0][1]
        c1[0][0] = e
        c1[0][1] = a
    elif a > c1[1]:
        c1[1] = a

    last =lst2[0]
    a = 0
    for e in lst2:
        if last == e:
            a +=1
        else:
            if a > c2[0][1]:
                c2[1] = c2[0][1]
                c2[0][0] = e
                c2[0][1] = a
            elif a > c2[1]:
                c2[1] = a
            last = e
            a = 1
    if a > c2[0][1]:
        c2[1] = c2[0][1]
        c2[0][0] = e
        c2[0][1] = a
    elif a > c2[1]:
        c2[1] = a

    if c1[0][0] == c2[0][0]:
        if c1 and c2:
            return n//2
        else:
            return n - max(c1[0][1] + c2[1],c2[0][1] + c1[1])
    else:
        return n - c1[0][1] - c2[0][1]

n = int(input())
lst = input().split()
print(main(n,lst))

Submission status: Wrong Answer

Solution code:
def main(n:int,lst:list)->int:
    lst1 = lst[::2]
    lst2 = lst[1::2]
    lst1.sort()
    lst2.sort()
    c1 = [["",0],0]
    c2 = [["",0],0]
    last =lst1[0]
    a = 0
    for e in lst1:
        if last == e:
            a +=1
        else:
            if a >= c1[0][1]:
                c1[1] = c1[0][1]
                c1[0][0] = e
                c1[0][1] = a
            elif a > c1[1]:
                c1[1] = a
            last = e
            a = 1
    if a >= c1[0][1]:
        c1[1] = c1[0][1]
        c1[0][0] = e
        c1[0][1] = a
    elif a > c1[1]:
        c1[1] = a

    last =lst2[0]
    a = 0
    for e in lst2:
        if last == e:
            a +=1
        else:
            if a >= c2[0][1]:
                c2[1] = c2[0][1]
                c2[0][0] = e
                c2[0][1] = a
            elif a > c2[1]:
                c2[1] = a
            last = e
            a = 1
    if a >= c2[0][1]:
        c2[1] = c2[0][1]
        c2[0][0] = e
        c2[0][1] = a
    elif a > c2[1]:
        c2[1] = a

    if c1[0][0] == c2[0][0]:
        if c1[1]+c2[1]:
            return n - max(c1[0][1] + c2[1],c2[0][1] + c1[1])
        else:
            return n//2
    else:
        return n - c1[0][1] - c2[0][1]

n = int(input())
lst = input().split()
print(main(n,lst))

Submission status: Wrong Answer

Solution code:
def main(n:int,lst:list)->int:
    lst1 = lst[::2]
    lst2 = lst[1::2]
    lst1.sort()
    lst2.sort()
    c1 = [["",0],0]
    c2 = [["",0],0]
    last =lst1[0]
    a = 0
    for e in lst1:
        if last == e:
            a +=1
        else:
            if a >= c1[0][1]:
                c1[1] = c1[0][1]
                c1[0][0] = e
                c1[0][1] = a
            elif a > c1[1]:
                c1[1] = a
            last = e
            a = 1
    if a >= c1[0][1]:
        c1[1] = c1[0][1]
        c1[0][0] = e
        c1[0][1] = a
    elif a > c1[1]:
        c1[1] = a

    last =lst2[0]
    a = 0
    for e in lst2:
        if last == e:
            a +=1
        else:
            if a >= c2[0][1]:
                c2[1] = c2[0][1]
                c2[0][0] = e
                c2[0][1] = a
            elif a > c2[1]:
                c2[1] = a
            last = e
            a = 1
    if a >= c2[0][1]:
        c2[1] = c2[0][1]
        c2[0][0] = e
        c2[0][1] = a
    elif a > c2[1]:
        c2[1] = a

    if c1[0][0] == c2[0][0]:
        return n - max(c1[0][1] + c2[1],c2[0][1] + c1[1])
    else:
        return n - c1[0][1] - c2[0][1]

n = int(input())
lst = input().split()
print(main(n,lst))

Submission status: Wrong Answer

Solution code:
def main(n:int,lst:list)->int:
    b = True
    lst1 = []
    lst2 = []
    for e in lst:
        if b:
            lst1.append(e)
        else:
            lst2.append(e)
        b = not b
    lst1.sort()
    lst2.sort()
    c1 = [["",0],0]
    c2 = [["",0],0]
    last =lst1[0]
    a = 0
    for e in lst1:
        if last == e:
            a +=1
        else:
            if a >= c1[0][1]:
                c1[1] = c1[0][1]
                c1[0][0] = e
                c1[0][1] = a
            elif a > c1[1]:
                c1[1] = a
            last = e
            a = 1
    if a >= c1[0][1]:
        c1[1] = c1[0][1]
        c1[0][0] = e
        c1[0][1] = a
    elif a > c1[1]:
        c1[1] = a

    last =lst2[0]
    a = 0
    for e in lst2:
        if last == e:
            a +=1
        else:
            if a >= c2[0][1]:
                c2[1] = c2[0][1]
                c2[0][0] = e
                c2[0][1] = a
            elif a > c2[1]:
                c2[1] = a
            last = e
            a = 1
    if a >= c2[0][1]:
        c2[1] = c2[0][1]
        c2[0][0] = e
        c2[0][1] = a
    elif a > c2[1]:
        c2[1] = a

    if c1[0][0] == c2[0][0]:
        if c1[0][1] > c2[0][1] or(c1[0][1] == c2[0][1] and c2[1] > c1[1]):
            return n - c1[0][1] - c2[1]
        else:
            return n - c2[0][1] - c1[1]
    else:
        return n - c1[0][1] - c2[0][1]

n = int(input())
lst = input().split()
print(main(n,lst))