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:
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],0]
    c2 = [[0,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 = list(map(int,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 = 1
    for e in lst1[1:]:
        if last == e:
            a +=1
        else:
            if a > c1[0][1]:
                c1[0][0] = e
                c1[0][1] = a

            elif a > c1[1][1]:
                c1[1][0] = e
                c1[1][1] = a
            last = e
            a = 1
    if a > c1[0][1]:
        c1[0][0] = e
        c1[0][1] = a

    elif a > c1[1][1]:
        c1[1][0] = e
        c1[1][1] = a

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

            elif a > c2[1][1]:
                c2[1][0] = e
                c2[1][1] = a
            last = e
            a = 1
    if a > c2[0][1]:
        c2[0][0] = e
        c2[0][1] = a

    elif a > c2[1][1]:
        c2[1][0] = e
        c2[1][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][1] > c1[1][1]):
            return n - c1[0][1] - c2[1][1]
        else:
            return n - c2[0][1] - c1[1][1]
    else:
        return n - c1[0][1] - c2[0][1]

n = int(input())
lst = list(map(int,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 = 1
    for e in lst1[1:]:
        if last == e:
            a +=1
        else:
            if a > c1[0][1]:
                c1[0][0] = e
                c1[0][1] = a

            elif a > c1[1][1]:
                c1[1][0] = e
                c1[1][1] = a
            last = e
            a = 1
    if a > c1[0][1]:
        c1[0][0] = e
        c1[0][1] = a

    elif a > c1[1][1]:
        c1[1][0] = e
        c1[1][1] = a

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

            elif a > c2[1][1]:
                c2[1][0] = e
                c2[1][1] = a
            last = e
            a = 1
    if a > c2[0][1]:
        c2[0][0] = e
        c2[0][1] = a

    elif a > c2[1][1]:
        c2[1][0] = e
        c2[1][1] = a
    if c1[0][0] == c2[0][0]:
        if c1[0][1] > c2[0][1]:
            return n - c1[0][1] - c2[1][1]
        else:
            return n - c2[0][1] - c1[1][1]
    else:
        return n - c1[0][1] - c2[0][1]

n = int(input())
lst = list(map(int,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 = 1
    for e in lst1[1:]:
        if last == e:
            a +=1
        else:
            if a > c1[0][1]:
                c1[0][0] = e
                c1[0][1] = a

            elif a > c1[1][1]:
                c1[1][0] = e
                c1[1][1] = a
            last = e
            a = 1
    if a > c1[0][1]:
        c1[0][0] = e
        c1[0][1] = a

    elif a > c1[1][1]:
        c1[1][0] = e
        c1[1][1] = a

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

            elif a > c2[1][1]:
                c2[1][0] = e
                c2[1][1] = a
            last = e
            a = 1
    if a > c2[0][1]:
        c2[0][0] = e
        c2[0][1] = a

    elif a > c2[1][1]:
        c2[1][0] = e
        c2[1][1] = a
    if c1[0][0] == c2[0][0]:
        if c1[0][1] > c2[0][1]:
            print(c1,c1)
            return n - c1[0][1] - c2[1][1]
        else:
            print(c1,c1)
            return n - c2[0][1] - c1[1][1]
    else:
        print(c1,c1)
        return n - c1[0][1] - c2[0][1]

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

Submission status: Wrong Answer

Solution code:
import collections
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
    c1 = collections.Counter(lst1).most_common()
    c2 = collections.Counter(lst2).most_common()
    if c1[0][0] == c2[0][0]:
        if c1[0][1] > c2[0][1]:
            if len(c2) == 1:
                return n - c1[0][1]
            else:
                return n - c1[0][1] - c2[1][1]
        else:
            if len(c1) == 1:
                return n - c2[0][1]
            else:
                return n - c2[0][1] - c1[1][1]
    else:
        return n - c1[0][1] - c2[0][1]

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

Submission status: Wrong Answer

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

v1,v2=[v[i] for i in range(n) if i%2==0],[v[i] for i in range(n) if not i%2==0]
v1c=Counter(v1).most_common()+[(0,0)]
v2c=Counter(v2).most_common()+[(0,0)]



if v1c[0][0]==v2c[0][0]:
    if v1c[0][1]<v2c[1][1]:
        print(n-v1c[0][1]-v2c[1][1])
    else:
        print(n-v1c[1][1]-v2c[0][1])
else:
    print(n-v1c[0][1]-v2c[0][1])

Submission status: Wrong Answer

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

v1,v2=[v[i] for i in range(n) if i%2==0],[v[i] for i in range(n) if not i%2==0]
v1c=Counter(v1).most_common()+[(0,0)]
v2c=Counter(v2).most_common()+[(0,0)]


print(v1c,v2c)
if v1c[0][0]==v2c[0][0]:
    if v1c[0][1]<v2c[1][1]:
        print(n-v1c[0][1]-v2c[1][1])
    else:
        print(n-v1c[1][1]-v2c[0][1])
else:
    print(n-v1c[0][1]-v2c[0][1])

Submission status: Wrong Answer

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

v1,v2=[v[i] for i in range(n) if i%2==0],[v[i] for i in range(n) if not i%2==0]
v1c=Counter(v1).most_common()
v2c=Counter(v2).most_common()
ans1=0
ans2=0


if n/2==v1c[0][1] and v1c==v2c:
    print(v2c[0][1])
    exit()


if v1c[ans1][0]==v2c[ans2][0]:

    if v1c[ans1][1]>=v2c[ans2][1]:

        ans2+=1
    else:

        ans1+=1


print(n-(v1c[ans1][1]+v2c[ans2][1]))

Submission status: Wrong Answer

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

v_odd = v[1::2]
v_even = v[::2]

v_odd_unique = list(set(v_odd))
v_even_unique = list(set(v_even))

v_odd_max = 0
v_even_max = 0
v_odd_max_num = 0
v_even_max_num = 0
v_odd_semi = -1
v_even_semi = -1
v_odd_semi_num = -1
v_even_semi_num = -1

for v_odd_num in v_odd_unique:
    v_odd_tmp = v_odd.count(v_odd_num)
    if v_odd_max < v_odd_tmp:
        v_odd_semi = v_odd_max
        v_odd_max = v_odd_tmp
        v_odd_semi_num = v_odd_max_num
        v_odd_max_num = v_odd_num

for v_even_num in v_even_unique:
    v_even_tmp = v_even.count(v_even_num)
    if v_even_max < v_even_tmp:
        v_even_semi = v_even_max
        v_even_max = v_even_tmp
        v_eve_semi_num = v_even_max_num
        v_even_max_num = v_even_num

if v_odd_max_num == v_even_max_num:
    print(max(len(v_odd)-v_odd_max+len(v_even)-v_even_semi,len(v_odd)-v_odd_semi+len(v_even)-v_even_max))
else:
    print(len(v_odd)-v_odd_max+len(v_even)-v_even_max)

Submission status: Wrong Answer

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

e = a[0::2]
o = a[1::2]
e = collections.Counter(e)
o = collections.Counter(o)

def E(i,j):
    return e.most_common()[i][j]
def O(i,j):
    return o.most_common()[i][j]


if E(0,0) != O(0,0):
    print(n-E(0,1) - O(0,1))
elif E(0,1) > O(0,1):
    if len(a[1::2]) == O(0,1):
        print(n-E(0,1))
    else:
        print(n-E(0,1)-O(1,1))
else:
    if len(a[0::2]) == E(0,1):
        print(n-O(0,1))
    else:
        print(n-O(0,1)-E(1,1))

Submission status: Wrong Answer

Solution code:
n = int(input())
x = list(int(i) for i in input().split())
a = []
b = []
for i in range(0, n):
    if i % 2 == 0:
        a.append(x[i])
    else:
        b.append(x[i])
cnta = [0] * (100002 + 1)
cntb = [0] * (100002 + 1)
vala = 0
vala1 = 0
maxCnta = 0
maxCnta1 = 0
for i in a:
    cnta[i] += 1
    if maxCnta < cnta[i]:
        vala = i
        maxCnta = cnta[i]
for i in a:
    if maxCnta1 < cnta[i] and vala != i:
        maxCnta1 = cnta[i]
        vala1 = i
#---------------------------
valb = 0
valb1 = 0
maxCntb = 0
maxCntb1 = 0
for i in b:
    cntb[i] += 1
    if maxCntb < cntb[i]:
        valb = i
        maxCnt = cntb[i]
for i in b:
    if maxCntb1 < cntb[i] and valb != i:
        maxCntb1 = cntb[i]
        valb1 = i

if 1:
    res = 0
    for i in a:
        if i != vala:
            res += 1
    for i in b:
        if i != valb:
            res += 1
    print(res)
else:
    resa = 0
    resb = 0
    resa1 = 0
    resb1 = 0
    for i in a:
        if i != vala:
            resa += 1
        if i != vala1:
            resa1 += 1
    for i in b:
        if i != valb:
            resb += 1
        if i != valb1:
            resb1 += 1
    print(min(resa + resb1, resa1 + resb))

Submission status: Wrong Answer

Solution code:
n = int(input())
x = list(int(i) for i in input().split())
a = []
b = []
for i in range(0, n):
    if i % 2 == 0:
        a.append(x[i])
    else:
        b.append(x[i])
cnta = [0] * (100002 + 1)
cntb = [0] * (100002 + 1)
vala = 0
vala1 = 0
maxCnta = 0
maxCnta1 = 0
for i in a:
    cnta[i] += 1
    if maxCnta < cnta[i]:
        vala = i
        maxCnta = cnta[i]
for i in a:
    if maxCnta1 < cnta[i] and vala != i:
        maxCnta1 = cnta[i]
        vala1 = i
#---------------------------
valb = 0
valb1 = 0
maxCntb = 0
maxCntb1 = 0
for i in b:
    cntb[i] += 1
    if maxCntb < cntb[i]:
        valb = i
        maxCnt = cntb[i]
for i in b:
    if maxCntb1 < cntb[i] and valb != i:
        maxCntb1 = cntb[i]
        valb1 = i

if valb != vala:
    res = 0
    for i in a:
        if i != vala:
            res += 1
    for i in b:
        if i != valb:
            res += 1
    print(res)
else:
    resa = 0
    resb = 0
    resa1 = 0
    resb1 = 0
    for i in a:
        if i != vala:
            resa += 1
        if i != vala1:
            resa1 += 1
    for i in b:
        if i != valb:
            resb += 1
        if i != valb1:
            resb1 += 1
    print(min(resa + resb1, resa1 + resb))

Submission status: Wrong Answer

Solution code:
n = int(input())
x = list(int(i) for i in input().split())
a = []
b = []
for i in range(0, n):
    if i % 2 == 0:
        a.append(x[i])
    else:
        b.append(x[i])
res = 0
#print(x, a, b)
cnta = [0] * (100002 + 1)
cntb = [0] * (100002 + 1)
vala = 0
vala1 = 0
maxCnta = 0
maxCnta1 = 0
for i in a:
    cnta[i] += 1
    if maxCnta < cnta[i]:
        vala = i
        maxCnta = cnta[i]
for i in a:
    if maxCnta1 < cnta[i] and vala != i:
        maxCnta1 = cnta[i]
        vala1 = i
#---------------------------
valb = 0
valb1 = 0
maxCntb = 0
maxCntb1 = 0
for i in b:
    cntb[i] += 1
    if maxCntb < cntb[i]:
        valb = i
        maxCnt = cntb[i]
for i in b:
    if maxCntb1 < cntb[i] and valb != i:
        maxCntb1 = cntb[i]
        valb1 = i

if valb != vala:
    res = 0
    for i in a:
        if i != vala:
            res += 1
    for i in b:
        if i != valb:
            res += 1
    print(res)
else:
    resa = 0
    resb = 0
    resa1 = 0
    resb1 = 0
    for i in a:
        if i != vala:
            resa += 1
        if i != vala1:
            resa1 += 1
    for i in b:
        if i != valb:
            resb += 1
        if i!= valb1:
            resb1 += 1
    print(min(resa + resb1, resa1 + resb))

Submission status: Wrong Answer

Solution code:
n = int(input())
x = list(int(i) for i in input().split())
a = []
b = []
for i in range(0, n):
    if i % 2 == 0:
        a.append(x[i])
    else:
        b.append(x[i])
res = 0
#print(x, a, b)
cnta = [0] * (100002 + 1)
cntb = [0] * (100002 + 1)
vala = 0
vala1 = 0
maxCnta = 0
maxCnta1 = 0
for i in a:
    cnta[i] += 1
    if maxCnta < cnta[i]:
        vala = i
        maxCnta = cnta[i]
for i in a:
    if maxCnta1 < cnta[i] and vala != i:
        maxCnta1 = cnta[i]
        vala1 = i
#---------------------------
valb = 0
valb1 = 0
maxCntb = 0
maxCntb1 = 0
for i in b:
    cntb[i] += 1
    if maxCntb < cntb[i]:
        valb = i
        maxCnt = cntb[i]
for i in b:
    if maxCntb1 < cntb[i] and valb != i:
        maxCntb1 = cntb[i]
        valb1 = i

if valb != vala:
    res = 0
    for i in a:
        if i != vala:
            res += 1
    for i in b:
        if i != valb:
            res += 1
    print(res)
else:
    resa = 0
    resb = 0
    resa1 = 0
    resb1 = 0
    for i in a:
        if i != vala:
            resa += 1
        if i != vala1:
            resa1 += 1
    for i in b:
        if i != valb:
            resb += 1
        if i!= valb1:
            resb1 += 1
    print(max(resa + resb1, resa1 + resb))

Submission status: Wrong Answer

Solution code:
n = int(input())
x = list(int(i) for i in input().split())
a = []
b = []
for i in range(0, n):
    if i % 2 == 0:
        a.append(x[i])
    else:
        b.append(x[i])
res = 0
#print(x, a, b)
cnta = [0] * (100002 + 1)
cntb = [0] * (100002 + 1)
vala = 0
maxCnt = 0
for i in a:
    cnta[i] += 1
    if maxCnt < cnta[i]:
        vala = i
        maxCnt = cnta[i]
for i in a:
    if i != vala:
        res += 1
valb = 0
maxCnt = 0
for i in b:
    cntb[i] += 1
    if maxCnt < cntb[i]:
        valb = i
        maxCnt = cntb[i]
for i in b:
    if i != valb:
        res += 1
print(res)

Submission status: Wrong Answer

Solution code:
N = int(input())
V = list(map(int,input().split()))
X = list(set(V))
nums = [V.count(x) for x in X if V.count(x) != int(N/2)]
if(len(nums) == 1):
  print(int(N/2))
else:
  print(int(len(nums)/2))

Submission status: Wrong Answer

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

even = []
odd = []
for i, v in enumerate(V):
	if i % 2 == 0: even.append(v)
	else: odd.append(v)

cnt_even = Counter(even).most_common(2)
cnt_odd = Counter(odd).most_common(2)

if cnt_even[0][0] != cnt_odd[0][0]:
	ans = len(V) - cnt_even[0][1] - cnt_odd[0][1]
else:
	if cnt_even[0][1] + cnt_odd[0][1] == len(V):
		ans = len(V) // 2

	elif len(cnt_odd) < 2 or len(cnt_even) < 2:
		ans = len(V) - cnt_even[0][1] - cnt_odd[0][1]
	else:
		ans1 = len(V) - cnt_even[0][1] - cnt_odd[1][1]
		ans2 = len(V) - cnt_even[1][1] - cnt_odd[0][1]
		ans = max(ans1, ans2)

print(ans)

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
A = list(input().split())
B = []
C = []
for i in range(n):
    if(i%2==0):
        B.append(int(A[i]))
    else:
        C.append(int(A[i]))

a = int(n/2 - max(dict(collections.Counter(B)).values()))
b = int(n/2 - max(dict(collections.Counter(C)).values()))

if(len(set(A)) == 1):
    print(int(n/2))
elif(len(set(B)) == 1 and len(set(C)) == 1):
    print(0)
else:
    print(a+b)

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
A = list(input().split())
B = []
C = []
for i in range(n):
    if(i%2==0):
        B.append(int(A[i]))
    else:
        C.append(int(A[i]))

a = int(n/2 - max(dict(collections.Counter(B)).values()))
b = int(n/2 - max(dict(collections.Counter(C)).values()))

if(len(set(A)) == 1):
    print(int(n/2))
else:
    print(a+b)

Submission status: Wrong Answer

Solution code:
N = int(input())
s = [l for l in input().split()]
o = s[1::2]
e = s[0::2]
od = {'0':0}
ed = {'0':0}
for i in o:
    if i not in od.keys():
        od[i] = 1
    else:
        od[i] += 1

for i in e:
    if i not in ed.keys():
        ed[i] = 1
    else:
        ed[i] += 1

od = sorted(od.items(),key = lambda x: x[1],reverse=True)
ed = sorted(ed.items(),key = lambda x: x[1],reverse=True)


if od[0][0] != ed[0][0]:
    print((len(o)-od[0][1])+(len(e)-ed[0][1]))
else:
    print(min(len(o)-od[0][1],len(e)-ed[0][1])+max(len(o)-od[1][1],len(e)-ed[1][1]))

Submission status: Wrong Answer

Solution code:
import collections

num = int(input())
values = [int(i) for i in input().split()]

odd = []  # kisuu
even = []  # gusu

for n, i in enumerate(values):
    if (n + 1) % 2 == 0:
        even.append(i)
    else:
        odd.append(i)

odd_counts = collections.Counter(odd)
even_counts = collections.Counter(even)

# print(odd_counts.most_common())
# print(even_counts.most_common())

odd_replace_num = int(num/2) - odd_counts.most_common()[0][1]
even_replace_num = int(num/2) - even_counts.most_common()[0][1]

print(odd_replace_num + even_replace_num)

Submission status: Wrong Answer

Solution code:
import collections

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

odd = []  # kisuu
even = []  # gusu

for n, i in enumerate(values):
    if (n + 1) % 2 == 0:
        even.append(i)
    else:
        odd.append(i)

odd_counts = collections.Counter(odd)
even_counts = collections.Counter(even)

odd_replace_num = n - odd_counts.most_common()[0][1]
even_replace_num = n - even_counts.most_common()[0][1]

print(odd_replace_num + even_replace_num)

Submission status: Wrong Answer

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

odd = []  # kisuu
even = []  # gusu

for n, i in enumerate(values):
    if (n + 1) % 2 == 0:
        even.append(i)
    else:
        odd.append(i)

odd_counts = []
for i in set(odd):
    odd_counts.append(odd.count(i))

even_counts = []
for i in set(even):
    even_counts.append(even.count(i))

# print(odd_counts)
# print(even_counts)

odd_replace_num = len(odd) - max(odd_counts)
even_replace_num = len(even) - max(even_counts)

print(odd_replace_num + even_replace_num)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

e = []
o = []
for i, x in enumerate(v):
	if i % 2 == 0: e.append(x)
	else: o.append(x)

ce = Counter(e)
co = Counter(o)
e1 = ce.most_common()[0][0]
if len(ce) >= 2: e2 = ce.most_common()[1][0]
else: e2 = e1
o1 = co.most_common()[0][0]
if len(co) >= 2: o2 = co.most_common()[1][0]
else: o2 = o1

def count(v, n):
	ret = 0
	for x in v:
		if x == n: continue
		else: ret += 1
	return ret

if e1 == o1:
	print(len(v)//2)
else:
	print(max(count(e, e1)+count(o, o2), count(e, e2)+count(o, o1)))

Submission status: Wrong Answer

Solution code:
import heapq

n=int(input())
ve=[0 for _ in range(100010)]
vo=[0 for _ in range(100010)]
v = list(map(int,input().split()))

for nn in range(n):
        vv = v[nn]
        if(nn%2==0):
                ve[vv]+=1
        else:
                vo[vv]+=1
hve = heapq.nlargest(2,range(len(ve)),key=ve.__getitem__)
hvo = heapq.nlargest(2,range(len(vo)),key=vo.__getitem__)

if hve[0]==hvo[0]:
        ans = min((n-ve[hve[0]]-vo[hvo[1]]),(n-ve[hve[1]]-vo[hvo[0]]))
else:
        ans = n-ve[hve[0]]-vo[hve[0]]

print(ans)

Submission status: Wrong Answer

Solution code:
import heapq

n=int(input())
ve=[0 for _ in range(100010)]
vo=[0 for _ in range(100010)]
v = list(map(int,input().split()))

for nn in range(n):
        vv = v[nn]
        if(nn%2==0):
                ve[vv]+=1
        else:
                vo[vv]+=1
hve = heapq.nlargest(2,range(len(ve)),key=ve.__getitem__)
hvo = heapq.nlargest(2,range(len(vo)),key=vo.__getitem__)

if ve[hve[0]]==vo[hvo[0]]:
        ans = min((n-ve[hve[0]]-vo[hvo[1]]),(n-ve[hve[1]]-vo[hvo[0]]))
else:
        ans = n-ve[hve[0]]-vo[hve[0]]

print(ans)

Submission status: Wrong Answer

Solution code:
import heapq

n=int(input())
ve=[0 for _ in range(100010)]
vo=[0 for _ in range(100010)]
v = list(map(int,input().split()))

for nn in range(n):
        vv = v[nn]
        if(nn%2==0):
                ve[vv]+=1
        else:
                vo[vv]+=1
hve = heapq.nlargest(2,range(len(ve)),key=ve.__getitem__)
hvo = heapq.nlargest(2,range(len(vo)),key=vo.__getitem__)

s = len(v)//2
ans = min((2*s-ve[hve[0]]-vo[hvo[1]]),(2*s-ve[hve[1]]-vo[hvo[0]]))

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
v = list(map(int, input().split()))
cnt0 = [0 for i in range(100001)]
cnt1 = [0 for i in range(100001)]
for i, elem in enumerate(v):
    if i%2==0:
        cnt0[elem] += 1
    else:
        cnt1[elem] += 1

max_first0 = -1
argmax_first0 = 0
max_second0 = -1
argmax_second0 = 0
for i, elem in enumerate(cnt0):
    if elem>=max_second0:
        max_second0 = elem
        argmax_second0 = i
    if elem>=max_first0:
        max_second0 = max_first0
        argmax_second0 = argmax_first0
        max_first0 = elem
        argmax_first0 = i
max_first1 = -1
argmax_first1 = 0
max_second1 = -1
argmax_second1 = 0
for i, elem in enumerate(cnt1):
    if elem>=max_second1:
        max_second1 = elem
        argmax_second1 = i
    if elem>=max_first1:
        max_second1 = max_first1
        argmax_second1 = argmax_first1
        max_first1 = elem
        argmax_first1 = i

if argmax_first0 != argmax_first1:
    ans = n//2-max_first0 + n//2-max_first1
else:
    ans = max(n-max_first0-max_second1, n-max_first1-max_second0)

print(ans)

Submission status: Wrong Answer

Solution code:
count = {}

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

for x in a:
    count[x] = count.get(x, 0) + 1

b = [(k, v) for k, v in count.items()]
b = sorted(b, key=lambda x: x[1], reverse=True)

if len(b) == 1:
    print(n//2)
else:
    x1 = b[0][0]
    x2 = b[1][0]

    ans = sum(map(lambda x: x != x1 and x != x2, a))
    print(ans)

Submission status: Wrong Answer

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

dummy = [(-1, 0)]
(av1, ak1), (av2, ak2) = (collections.Counter(v[::2]).most_common(2) + dummy)[:2]
(bv1, bk1), (bv2, bk2) = (collections.Counter(v[1::2]).most_common(2) + dummy)[:2]

if av1 != bv1:
    print(n-ak1-bk1)
elif ak1 < bk1:
    print(n-ak2-bk1)
else:
    print(n-ak1-bk2)

Submission status: Wrong Answer

Solution code:

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

a, b = dict(), dict()
for i in range(n):
    if i%2 == 0:
        a[v[i]] = a.get(v[i], 0) + 1
    else:
        b[v[i]] = b.get(v[i], 0) + 1
alst = sorted(list(a.items()), key=lambda x: x[1], reverse=True)
blst = sorted(list(b.items()), key=lambda x: x[1], reverse=True)

if alst[0][0] != blst[0][0]:
    print(n-alst[0][1]-blst[0][1])
elif len(alst) == 1 and len(blst) == 1:
    print(n-alst[0][1]-blst[0][1])    
elif len(alst) == 1:
    print(n-alst[0][1]-blst[1][1])
elif len(blst) == 1:
    print(n-alst[0][1]-blst[1][1])
elif blst[0][0]+alst[1][1] > alst[0][0]+blst[1][1]:
    print(n-alst[1][1]-blst[0][0])
else:
    print(n-alst[0][0]-blst[1][1])

Submission status: Wrong Answer

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

even = Counter(v[::2]).most_common()
odd = Counter(v[1::2]).most_common()

if len(even) == 1 and even == odd:
    print(n//2)
else:
    count = 0
    
    for i in even:
        count += i[1]
    for i in odd:
        count += i[1]
    count -= even[0][1] + odd[0][1]
    
    print(count)

Submission status: Wrong Answer

Solution code:
n = int(input())

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

v_g = [i for id, i in enumerate(v) if id%2 == 0] 

v_k = [i for id, i in enumerate(v) if id%2 == 1] 

def set_list(es):
    return len(list(set(es)))

print(int(set_list(v_g))+int(set_list(v_k))-2)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
import sys
import collections
N = int(input())
odd = []
even = []
lst = list(map(int,input().split()))
for i in range(0,N,2):
    #print(i)
    even.append(lst[i])
    
for i in range(1,N,2):
    #print(i)
    odd.append(lst[i])

odd_count = collections.Counter(odd)
even_count = collections.Counter(even)

even_list = list(even_count.items())
odd_list = list(odd_count.items())
#print(even_list ,odd_list )
    
if even_list[0][0] != odd_list[0][0]:
    print(N - even_list[0][1] - odd_list[0][1])
else:
    if len(even_list) > 1:
        tmp_even = N - even_list[1][1] - odd_list[0][1]
    else:
        tmp_even = N - odd_list[0][1]
    if len(odd_list) > 1:
        tmp_odd = N - odd_list[1][1] - even_list[0][1]
    else:
        tmp_odd = N - even_list[0][1]
    print(min(tmp_even,tmp_odd))

Submission status: Wrong Answer

Solution code:
import sys
import collections
N = int(input())
odd = []
even = []
lst = list(map(int,input().split()))
for i in range(0,N,2):
    #print(i)
    even.append(lst[i])
    
for i in range(1,N,2):
    #print(i)
    odd.append(lst[i])

odd_count = collections.Counter(odd)
even_count = collections.Counter(even)

even_list = list(even_count.items())
odd_list = list(odd_count.items())
#print(even_list ,odd_list )
    
if even_list[0][0] != odd_list[0][0]:
    print(N - even_list[0][1] - odd_list[0][1])
else:
    try:
        print(min(N - even_list[1][1] - odd_list[0][1],N - even_list[0][1] - odd_list[1][1]))
    except:
        print(N//2)

Submission status: Wrong Answer

Solution code:
from collections import Counter


def main():
    n = int(input())
    aa = list(map(int, input().split()))
    cs_a0 = Counter(a for i, a in enumerate(aa) if i % 2 == 0)
    cs_a1 = Counter(a for i, a in enumerate(aa) if i % 2 == 1)
    vs_a0 = sorted(((v, k) for k, v in cs_a0.items()), reverse=True)
    vs_a1 = sorted(((v, k) for k, v in cs_a1.items()), reverse=True)
    if vs_a0[0][1] != vs_a1[0][1]:
        print(n - vs_a0[0][0] - vs_a1[0][0])
    else:
        res = n // 2
        if len(vs_a0) > 1:
            res = min(res, n - vs_a0[1][0] - vs_a1[0][0])
        if len(vs_a1) > 1:
            res = min(res, n - vs_a0[0][0] - vs_a1[1][0])
        print(res)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from collections import Counter


def main():
    n = int(input())
    aa = list(map(int, input().split()))
    cs_a0 = Counter(a for i, a in enumerate(aa) if i % 2 == 0)
    cs_a1 = Counter(a for i, a in enumerate(aa) if i % 2 == 1)
    vs_a0 = sorted(((v, k) for k, v in cs_a0.items()), reverse=True)
    vs_a1 = sorted(((v, k) for k, v in cs_a1.items()), reverse=True)
    if vs_a0[0][1] != vs_a1[0][1]:
        print(n - vs_a0[0][0] - vs_a1[0][0])
    else:
        res = n // 2
        # if len(vs_a0) > 1:
        #     res = min(n - vs_a0[1][0] - vs_a1[0][0])
        # if len(vs_a1) > 1:
        #     res = min(n - vs_a0[0][0] - vs_a1[1][0])
        print(res)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from collections import Counter


def main():
    n = int(input())
    vs = list(map(int, input().split()))
    v0s = Counter(v for i, v in enumerate(vs) if i % 2 == 0)
    v1s = Counter(v for i, v in enumerate(vs) if i % 2 == 1)
    if len(v0s) == len(v1s) == 1 and list(v0s.keys())[0] == list(v1s.keys())[0]:
        print(n // 2)
    else:
        print(n - max(v0s.values()) - max(v1s.values()))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import collections

naked = input()
a = int(naked)
x = list(map(int,input().split()))
y = x[0:a:2]
z = x[1:a:2]
v = collections.Counter(y)
w = collections.Counter(z)
sv = 0
sw = 0

mvi = v.most_common()[0][0]
mwi = w.most_common()[0][0]
mvn = v.most_common()[0][1]
mwn = w.most_common()[0][1]
a2 =a//2

if a%2 ==0:
    sv = a2
    sw = a2
else:
    sv = a2+1
    sw = a2
if mvi == mwi:
    if mvn> mwn:
        mwi = w.most_common()[1][0]
        mwn = w.most_common()[1][1]
    else:
        if  sw == mwn:
            mwn = 0
        else:
            mvn = v.most_common()[1][0]
            mvn = v.most_common()[1][1]
#print(sv,sw,mvi,mwi,mvn,mwn)  
print(sv+sw-mvn-mwn)

Submission status: Wrong Answer

Solution code:
import collections

naked = input()
a = int(naked)
x = list(map(int,input().split()))
y = x[0:a:2]
z = x[1:a:2]
v = collections.Counter(y)
w = collections.Counter(z)
sv = 0
sw = 0

mvi = v.most_common()[0][0]
mwi = w.most_common()[0][0]
mvn = v.most_common()[0][1]
mwn = w.most_common()[0][1]
a2 =a//2

if a%2 ==0:
    sv = a2
    sw = a2
else:
    sv = a2+1
    sw = a2
if mvi == mwi:
    if mvi> mwi:
        mwi = w.most_common()[1][0]
        mwn = w.most_common()[1][1]
    else:
        if  sw == mwn:
            mwn = 0
        else:
            mvn = v.most_common()[1][0]
            mvn = v.most_common()[1][1]
#print(sv,sw,mvi,mwi,mvn,mwn)  
print(sv+sw-mvn-mwn)