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:
# ABC111 C - \/\/\/\
from collections import Counter
si = lambda: input()
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))
N = ni()
V = nl()

O = []
E = []
ans = 0

for i in range(N):
    if i%2 == 0:
        O.append(V[i])
    else:
        E.append(V[i])
O_C = Counter(O)
O_E = Counter(E)

O_set = set(O)
E_set = set(E)
V_set = set(V)

if len(O_set)==1:
    O_First = O_C.most_common()[0][1]
    O_Second = 0
else:
    O_First = O_C.most_common()[0][1]
    O_Second = O_C.most_common()[1][1]

if len(E_set)==1:
    E_First = O_E.most_common()[0][1]
    E_Second = 0
else:
    E_First = O_E.most_common()[0][1]
    E_Second = O_E.most_common()[1][1]

if O_First == E_First:
    ans = min(len(E)-E_First+len(O)-O_Second,len(E)-E_Second+len(O)-O_First)
else:
    ans = len(O)-O_First+len(E)-E_First

if len(O_set)==1 and len(E_set)==1:
    if len(V_set)!=1:
        ans = 0

print(ans)

Submission status: Wrong Answer

Solution code:
import collections
N=int(input())
V=list(map(int,input().split()))
a=[V[i] for i in range(N) if i%2==0]
b=[V[i] for i in range(N) if i%2==1]

a=collections.Counter(a)
b=collections.Counter(b)
a=a.most_common()
b=b.most_common()
if len(a)==len(b)==1:
    if a[0][0]==b[0][0]:
        print(int(N/2))
    else:
        print(0)
if len(a)==1 and len(b)>=2:
    print(N-(b[0][1] if a[0][0]!=b[0][0] else b[1][1])-a[0][1])
if len(a)>=2 and len(b)==1:
    print(N-(a[0][1] if a[0][0]!=b[0][0] else a[1][1])-b[0][1])
if len(a)>=2 and len(a)>=2:
    print(min(N-(b[0][1] if a[0][0]!=b[0][0] else b[1][1])-a[0][1],N-(a[0][1] if a[0][0]!=b[0][0] else a[1][1])-b[0][1]))

Submission status: Wrong Answer

Solution code:
import collections
N=int(input())
V=list(map(int,input().split()))
a=[V[i] for i in range(N) if i%2==0]
b=[V[i] for i in range(N) if i%2==1]

a=collections.Counter(a)
b=collections.Counter(b)
a=a.most_common()
b=b.most_common()
print(a)
print(b)
if len(a)==len(b)==1:
    if a[0][0]==b[0][0]:
        print(int(N/2))
    else:
        print(0)
elif len(a)==1 and len(b)>=2:
    print(N-(b[0][1] if a[0][0]!=b[0][0] else b[1][1])-a[0][1])
elif len(a)>=2 and len(b)==1:
    print(N-(a[0][1] if a[0][0]!=b[0][0] else a[1][1])-b[0][1])
elif len(a)>=2 and len(a)>=2:
    print(min(N-(b[0][1] if a[0][0]!=b[0][0] else b[1][1])-a[0][1],N-(a[0][1] if a[0][0]!=b[0][0] else a[1][1])-b[0][1]))

Submission status: Wrong Answer

Solution code:
import collections
N=int(input())
V=list(map(int,input().split()))
a=[V[i] for i in range(N) if i%2==0]
b=[V[i] for i in range(N) if i%2==1]

a=collections.Counter(a)
b=collections.Counter(b)
a=a.most_common()
b=b.most_common()

if len(a)==len(b)==1:
    if a[0][0]==b[0][0]:
        print(int(N/2))
    else:
        print(0)
if len(a)==1 and len(b)>=2:
    print(N-(b[0][1] if a[0][0]!=b[0][0] else b[1][1])-a[0][1])
if len(a)>=2 and len(b)==1:
    print(N-(a[0][1] if a[0][0]!=b[0][0] else a[1][1])-b[0][1])
if len(a)>=2 and len(a)>=2:
    print(min(N-(b[0][1] if a[0][0]!=b[0][0] else b[1][1])-a[0][1],N-(a[0][1] if a[0][0]!=b[0][0] else a[1][1])-b[0][1]))

Submission status: Wrong Answer

Solution code:
import collections
N=int(input())
V=list(map(int,input().split()))
a=[V[i] for i in range(N) if i%2==0]
b=[V[i] for i in range(N) if i%2==1]

a=collections.Counter(a)
b=collections.Counter(b)
a=a.most_common()
b=b.most_common()

if len(a)==len(b)==1:
    if a[0][0]==b[0][0]:
        print(int(N/2))
    else:
        print(0)
if len(a)==1 and len(b)>=2:
    print(N-(b[0][1] if a[0][0]!=b[0][0] else b[1][1])-a[0][1])
if len(a)>=2 and len(b)==1:
    print(N-(a[0][1] if a[0][0]!=b[0][0] else a[1][1])-b[0][1])
if len(a)>=2 and len(a)==2:
    print(min(N-(b[0][1] if a[0][0]!=b[0][0] else b[1][1])-a[0][1],N-(a[0][1] if a[0][0]!=b[0][0] else a[1][1])-b[0][1]))

Submission status: Wrong Answer

Solution code:
from collections import Counter
n=int(input())
V=list(map(int,input().split()))
lenV=len(V)
V=Counter(V)
value=0
Flag=0
for i,v in enumerate(sorted([V[v] for v in V],reverse=True)):
    if i>=2:break
    if i==1:Flag=1
    value+=v
print(lenV-value if Flag else 2)
#for i in range(2):

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
v = list(map(int,input().split()))
ve = [v[2*i] for i in range(n//2)]
vo = [v[2*i + 1] for i in range(n//2)]
Cve = collections.Counter(ve)
Cvo = collections.Counter(vo)
Cve1 = Cve.most_common()[0]
Cvo1 = Cvo.most_common()[0]
if len(Cve) == 1 and len(Cvo) == 1: #eo両方1種類
    if Cve1[0] == Cvo1[0]: ans = n//2 #eo top同じ
    else: ans = 0 #eo異なる
elif len(Cve) == 1 and len(Cvo) > 1: #eのみ1種類
    Cvo2 = Cvo.most_common()[1]
    if Cve1[0] == Cvo1[0]: ans = n//2 - Cvo2[1] #eo top同じ
    else: ans = n//2 - Cvo1[1] #eo top異なる
elif len(Cve) > 1 and len(Cvo) == 1: #oのみ1種類
    Cve2 = Cve.most_common()[1]
    if Cve1[0] == Cvo1[0]: ans = n//2 - Cve2[1] #eo top同じ
    else: ans = n//2 - Cve1[1] #eo top異なる
else:
    Cve2 = Cve.most_common()[1]
    Cvo2 = Cvo.most_common()[1]
    if Cve1[0] != Cvo1[0]: ans = n - Cve2[1] - Cvo2[1] #top異なる
    if Cve1[0] == Cvo1[0]:
        if Cve1[1] < Cvo1[1]: ans = n - Cve2[1] - Cvo1[1]
        elif Cve2[1] > Cvo2[1] : ans = n - Cve2[1] - Cvo1[1]
        else: ans = n - Cve1[1] - Cvo2[1]
print(ans)

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
v = list(map(int,input().split()))
ve = [v[2*i] for i in range(n//2)]
vo = [v[2*i + 1] for i in range(n//2)]
Cve = collections.Counter(ve)
Cvo = collections.Counter(vo)
Cve1 = Cve.most_common()[0]
Cvo1 = Cvo.most_common()[0]
if len(Cve) == 1 and len(Cvo) == 1: #eo両方1種類
    if Cve1[0] == Cvo1[0]: ans = n//2 #eo top同じ
    else: ans = 0 #eo異なる
elif len(Cve) == 1 and len(Cvo) > 1: #eのみ1種類
    Cvo2 = Cvo.most_common()[1]
    if Cve1[0] == Cvo1[0]: ans = n//2 - Cvo2[1] #eo top同じ
    else: ans = n//2 - Cvo1[1] #eo top異なる
elif len(Cve) > 1 and len(Cvo) == 1: #oのみ1種類
    Cve2 = Cve.most_common()[1]
    if Cve1[0] == Cvo1[0]: ans = n//2 - Cve2[1] #eo top同じ
    else: ans = n//2 - Cve1[1] #eo top異なる
else:
    Cve2 = Cve.most_common()[1]
    Cvo2 = Cvo.most_common()[1]
    if Cve1[0] != Cvo1[0]: ans = n - Cve2[1] - Cvo2[1] #top異なる
    if Cve1[0] == Cvo1[0]:
        if Cve1[1] > Cvo1[1]: ans = n - Cvo1[1] - Cve2[1]
        else: ans = n - Cve2[1] - Cvo1[1]
print(ans)

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
v = list(map(int,input().split()))
ve = [v[2*i] for i in range(n//2)]
vo = [v[2*i + 1] for i in range(n//2)]
Cve = collections.Counter(ve)
Cvo = collections.Counter(vo)
Cve1 = Cve.most_common()[0]
Cvo1 = Cvo.most_common()[0]
if len(Cve) == 1 and len(Cvo) == 1: #eo両方1種類
    if Cve1[0] == Cvo1[0]: ans = n//2 #eo top同じ
    else: ans = 0 #eo異なる
elif len(Cve) == 1 and len(Cvo) > 1: #eのみ1種類
    Cvo2 = Cvo.most_common()[1]
    if Cve1[0] == Cvo1[0]: ans = n//2 - Cvo2[1] #eo top同じ
    else: ans = n//2 - Cvo1[1] #eo top異なる
elif len(Cve) > 1 and len(Cvo) == 1: #oのみ1種類
    Cve2 = Cve.most_common()[1]
    if Cve1[0] == Cvo1[0]: ans = n//2 - Cve2[1] #eo top同じ
    else: ans = n//2 - Cve1[1] #eo top異なる
else:
    Cve2 = Cve.most_common()[1]
    Cvo2 = Cvo.most_common()[1]
    if Cve1[0] != Cvo1[0]: ans = n - Cve2[1] - Cvo2[1] #top異なる
    if Cve1[0] == Cvo1[0]:
        if Cve1[1] > Cvo1[1]: ans = n - Cve1[1] - Cvo2[1]
        else: ans = n - Cve2[1] - Cvo1[1]
print(ans)

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
v = list(map(int,input().split()))
ve = [v[2*i] for i in range(n//2)]
vo = [v[2*i + 1] for i in range(n//2)]
Cve = collections.Counter(ve)
Cvo = collections.Counter(vo)
Cve1 = Cve.most_common()[0]
Cvo1 = Cvo.most_common()[0]
if len(Cve) == 1 and len(Cvo) == 1: #eo両方1種類
    if Cve1[0] == Cvo1[0]: ans = n//2 #eo top同じ
    else: ans = 0 #eo異なる
elif len(Cve) == 1 and len(Cvo) > 1: #eのみ1種類
    Cvo2 = Cvo.most_common()[1]
    if Cve1[0] == Cvo1[0]: ans = n//2 - Cvo2[1] #eo top同じ
    else: ans = n//2 - Cvo1[1] #eo top異なる
elif len(Cve) > 1 and len(Cvo) == 1: #oのみ1種類
    Cve2 = Cve.most_common()[1]
    if Cve1[0] == Cvo1[0]: ans = n//2 - Cve2[1] #eo top同じ
    else: ans = n//2 - Cve1[1] #eo top異なる
else:
    Cve2 = Cve.most_common()[1]
    Cvo2 = Cvo.most_common()[1]
    if Cve1[0] != Cvo1[0]: ans = n - Cve1[1] - Cvo1[1] #top異なる
    if Cve1[0] == Cvo1[0]:
        if Cve2[0] == Cve2[0]:
            ans = n//2
        elif Cve1[1] > Cvo1[1]: ans = n - Cve1[1] - Cvo2[1]
        else: ans = n - Cve2[1] - Cvo1[1]
print(ans)

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
v = list(map(int,input().split()))
ve = [v[2*i] for i in range(n//2)]
vo = [v[2*i + 1] for i in range(n//2)]
Cve = collections.Counter(ve)
Cvo = collections.Counter(vo)
Cve1 = Cve.most_common()[0]
Cvo1 = Cvo.most_common()[0]
if len(Cve) == 1 and len(Cvo) == 1: #eo両方1種類
    if Cve1[0] == Cvo1[0]: ans = n//2 #eo top同じ
    else: ans = 0 #eo異なる
elif len(Cve) == 1 and len(Cvo) > 1: #eのみ1種類
    Cvo2 = Cvo.most_common()[1]
    if Cve1[0] == Cvo1[0]: ans = n//2 - Cvo2[1] #eo top同じ
    else: ans = n//2 - Cvo1[1] #eo top異なる
elif len(Cve) > 1 and len(Cvo) == 1: #oのみ1種類
    Cve2 = Cve.most_common()[1]
    if Cve1[0] == Cvo1[0]: ans = n//2 - Cve2[1] #eo top同じ
    else: ans = n//2 - Cve1[1] #eo top異なる
else:
    Cve2 = Cve.most_common()[1]
    Cvo2 = Cvo.most_common()[1]
    if Cve1[0] != Cvo1[0]: ans = n - Cve1[1] - Cvo1[1] 
    if Cve1[0] == Cvo1[0]:
        if Cve1[1] > Cvo1[1]: ans = n - Cve1[1] - Cvo2[1]
        else: ans = n - Cve2[1] - Cvo1[1]
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
v = [x for x in input().split()]
v_even_mc = Counter(v[::2]).most_common()
v_odd_mc = Counter(v[1::2]).most_common()
if v_even_mc[0] == v_odd_mc[0]:
  ans = min(v_even_mc[0][1], v_odd_mc[0][1])
else:
  ans = abs(v_even_mc[0][1] - v_odd_mc[0][1])
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
v = input().split()
o = {"":0}
e = {"":0}
for s in v[::2]:
    if s in o:
        o[s] += 1
    else:
        o[s] = 1

for s in v[1::2]:
    if s in e:
        e[s] += 1
    else:
        e[s] = 1

o = sorted(o.items(), key=lambda x:x[1])
e = sorted(e.items(), key=lambda x:x[1])

if o[0][0] != e[0][0]:
    print(n-o[0][1]-e[0][1])
else:
    print(n - max(o[0][1]+e[1][1], o[1][1]+e[0][1]))

Submission status: Wrong Answer

Solution code:
from sys import stdin
from itertools import groupby

n = int(stdin.readline().rstrip())

li = list(map(int,stdin.readline().rstrip().split()))

li1 = []
li2 = []

for i in range(n):
    if i % 2 == 0:
        li1.append(li[i])
    else:
        li2.append(li[i])

li1.sort()
li2.sort()

lin = []
lin2 = []

for key, value in groupby(li1):
    lin.append((key,len(list(value))))
for key, value in groupby(li2):
    lin2.append((key,len(list(value))))

lin.sort(key=lambda x:(x[1]))
lin2.sort(key=lambda x:(x[1]))

point = 0

if lin[-1][0] == lin2[-1][0] and lin[-1][1] == lin2[-1][1]:
    if len(lin) == 1:
        print(n//2)
    else:
        if lin[-2][1] >= lin2[-2][1]:
            print(n-lin[-1][1]-lin2[-2][1]-1)
        else:
            print(n-lin[-2][1]-lin2[-1][1]-1)

elif lin[-1][0] == lin2[-1][0]:
    if len(lin) == 1:
        print(n//2-lin2[-2][1])
    elif len(lin2) == 1:
        print(n//2-lin[-2][1])
    else:
        if lin[-2][1] >= lin2[-2][1]:
            print(n-lin[-1][1]-lin2[-2][1])
        else:
            print(n-lin[-2][1]-lin2[-1][1])
else:
    print(n-lin[-1][1]-lin2[-1][1])

Submission status: Wrong Answer

Solution code:
from sys import stdin
from itertools import groupby

n = int(stdin.readline().rstrip())

li = list(map(int,stdin.readline().rstrip().split()))

li1 = []
li2 = []

for i in range(n):
    if i % 2 == 0:
        li1.append(li[i])
    else:
        li2.append(li[i])

li1.sort()
li2.sort()

lin = []
lin2 = []

for key, value in groupby(li1):
    lin.append((key,len(list(value))))
for key, value in groupby(li2):
    lin2.append((key,len(list(value))))

lin.sort(key=lambda x:(x[1]))
lin2.sort(key=lambda x:(x[1]))

point = 0

if lin[-1][0] == lin2[-1][0] and lin[-1][1] == lin2[-1][1]:
    if len(lin) == 1:
        print(n//2)
    else:
        if lin[-2][1] >= lin2[-2][1]:
            print(n-lin[-1][1]-lin2[-2][1])
        else:
            print(n-lin[-2][1]-lin2[-1][1])

elif lin[-1][0] == lin2[-1][0]:
    if len(lin) == 1:
        print(n//2-lin2[-2][1])
    elif len(lin2) == 1:
        print(n//2-lin[-2][1])
    else:
        if lin[-2][1] >= lin2[-2][1]:
            print(n-lin[-1][1]-lin2[-2][1]-1)
        else:
            print(n-lin[-2][1]-lin2[-1][1]-1)
else:
    print(n-lin[-1][1]-lin2[-1][1])

Submission status: Wrong Answer

Solution code:
from sys import stdin
from itertools import groupby

n = int(stdin.readline().rstrip())

li = list(map(int,stdin.readline().rstrip().split()))

li1 = []
li2 = []

for i in range(n):
    if i % 2 == 0:
        li1.append(li[i])
    else:
        li2.append(li[i])

li1.sort()
li2.sort()

lin = []
lin2 = []

for key, value in groupby(li1):
    lin.append((key,len(list(value))))
for key, value in groupby(li2):
    lin2.append((key,len(list(value))))

lin.sort(key=lambda x:(x[1]))
lin2.sort(key=lambda x:(x[1]))

point = 0

if lin[-1][0] == lin2[-1][0] and lin[-1][1] == lin2[-1][1]:
    if len(lin) == 1:
        print(n//2)
    else:
        if lin[-2][1] >= lin2[-2][1]:
            print(n-lin[-1][1]-lin2[-2][1])
        else:
            print(n-lin[-2][1]-lin2[-1][1])
elif lin[-1][0] == lin2[-1][0]:
    if len(lin) == 1:
        print(n//2-lin2[-2][1])
    elif len(lin2) == 1:
        print(n//2-lin[-2][1])
    else:
        if lin[-2][1] >= lin2[-2][1]:
            print(n-lin[-1][1]-lin2[-2][1])
        else:
            print(n-lin[-2][1]-lin2[-1][1])
else:
    print(n-lin[-1][1]-lin2[-1][1])

Submission status: Wrong Answer

Solution code:
n = int(input())
v = list(map(int, input().split()))
w = [0]*(10**5+1)
for x in v: w[x]+=1
print(n-sum(sorted(w,reverse=True)[:2]))

Submission status: Wrong Answer

Solution code:
n = int(input())
v = list(map(int, input().split()))
w = [0]*(10**5+1)
for x in v: w[x]+=1
print(n-sum(sorted(w)[:2]))

Submission status: Wrong Answer

Solution code:
from collections import Counter
N = int(input())
v = list(map(int, input().split()))
v1 = Counter(v[::2])
v2 = Counter(v[::-2])
if len(Counter(v))==1:
    print(N//2)
elif (len(v1)==1) and (len(v2)==1):
    print(0)
elif (len(v1)==1):
    k,v = zip(*v2.most_common())
    print(sum(v[1:]))
elif (len(v2)==1):
    k,v = zip(*v1.most_common())
    print(sum(v[1:]))
else:
    k1,v1 = zip(*v1.most_common())
    k2,v2 = zip(*v2.most_common())
    if k1[0]==k2[0]:
        if k1[0] >= k2[0]:
            print(sum(v1[1:])+v2[0]+(sum(v2[2:]) if len(v2)>2 else 0))
        else:
            print(sum(v2[1:])+v1[0]+(sum(v1[2:]) if len(v1)>2 else 0))
    else:
        print(sum(v1[1:])+sum(v2[1:]))

Submission status: Wrong Answer

Solution code:
import collections
def count(l):
    n = 0
    c = collections.Counter(l)
    c = list(c.values())
    if len(c) == 1: return 0
    else:
        c.sort(reverse=True)
        for i in c[1:]:
            n += i
        return n
n = int(input())
v = [int(i) for i in input().split()]
v1 = [v[i] for i in range(0, n, 2)]
v2 = [v[j] for j in range(1, n, 2)]
cnt = count(v1) + count(v2)
if cnt == 0 and v1[0] == v2[0]: cnt = int(n/2)
print(cnt)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

v1 = Counter(v[::2])
v2 = Counter(v[1::2])
v1 = v1.most_common()
v2 = v2.most_common()

no_change = 0

if v1[0][1] >= v2[0][1]:
    no_change += v1[0][1]
    for i in v2:
        if i[0] != v1[0][0]:
            no_change += i[1]
            break
else:
    no_change += v2[0][1]
    for i in v1:
        if i[0] != v2[0][0]:
            no_change += i[1]
            break

print(n-no_change)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

v1 = Counter(v[::2])
v2 = Counter(v[1::2])
v1.most_common()
v2.most_common()

no_change = 0
if list(v1.values())[0] >= list(v2.values())[0]:
    no_change += list(v1.values())[0]
    for k, val in v2.items():
        if k != list(v1.keys())[0]:
            no_change += val
            break
else:
    no_change += list(v2.values())[0]
    for k, val in v1.items():
        if k != list(v2.keys())[0]:
            no_change += val
            break

print(n-no_change)

Submission status: Wrong Answer

Solution code:
import heapq

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

one = V[::2]
two = V[1:][::2]

one_count={}
one_len=len(one)
for o in one:
    if o in one_count:
        one_count[o] += 1
    else:
        one_count[o] = 1

one_count[10**6]=one_len
for k,v in one_count.items():
    one_count[k] = one_len-v
    
two_len=len(two)
two_count={}

for t in two:
    if t in two_count:
        two_count[t] += 1
    else:
        two_count[t] = 1

two_count[10**6]=two_len
for k,v in two_count.items():
    two_count[k] = two_len-v


mins = 1000000

for one_key, one_value in one_count.items():
    for two_key, two_value in two_count.items():
        if one_key != two_key:
            if (one_value + two_value) < mins:
                mins = one_value + two_value
print(mins)

Submission status: Wrong Answer

Solution code:
import heapq

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

one = V[::2]
two = V[1:][::2]

one_count={}
one_len=len(one)
for o in one:
    if o in one_count:
        one_count[o] += 1
    else:
        one_count[o] = 1

one_count[10**6]=one_len
for k,v in one_count.items():
    one_count[k] = one_len-v


    
two_len=len(two)
two_count={}

for t in two:
    if t in two_count:
        two_count[t] += 1
    else:
        two_count[t] = 1

two_count[10**6]=two_len
for k,v in two_count.items():
    two_count[k] = two_len-v


mins = 1000

for one_key, one_value in one_count.items():
    for two_key, two_value in two_count.items():
        if one_key != two_key:
            if (one_value + two_value) < mins:
                mins = one_value + two_value
print(mins)

Submission status: Wrong Answer

Solution code:
import heapq

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

one = V[::2]
two = V[1:][::2]

one_count={}
one_len=len(one)
values={}
for o in one:
    if o in values:
        values[o] += 1
    else:
        values[o] = 1

one_count[10**6]=one_len
for k,v in values.items():
    one_count[k] = one_len-v


    
two_len=len(two)
two_count={}
values={}

for t in two:
    if t in values:
        values[t] += 1
    else:
        values[t] = 1

two_count[10**6]=two_len
for k,v in values.items():
    two_count[k] = two_len-v




keys = list(set(V))
mins = 1000

for one_key, one_value in one_count.items():
    for two_key, two_value in two_count.items():
        if one_key != two_key:
            if one_value + two_value < mins:
                mins = one_value + two_value
print(mins)

Submission status: Wrong Answer

Solution code:
import heapq



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

one = V[::2]
two = V[1:][::2]

one_count={}
one_len=len(one)
# values=[]
# for i,o in enumerate(set(one)):
#     values.append([ o, one_len - one.count(o)] )
values=[[ o, one_len - one.count(o)] for i,o in enumerate(set(one))]

one_count[10**6]=one_len
# values = heapq.heapify(values)
for temp in heapq.nsmallest(3, values, key=lambda x:x[1]):
    one_count[temp[0]] = temp[1]
    
two_len=len(two)
two_count={}
values=[]
# for i,t in enumerate(set(two)):
#     values.append([ t, two_len - two.count(t)] )
values=[[ t, two_len - two.count(t)] for i,t in enumerate(set(two))]

two_count[10**6]=two_len
for temp in heapq.nsmallest(3, values, key=lambda x:x[1]):
    two_count[temp[0]] = temp[1]


keys = list(set(V))
mins = 1000

# for one_key, one_value in one_count.items():
#     for two_key, two_value in two_count.items():
#         if one_key != two_key:
#             if one_value + two_value < mins:
#                 mins = one_value + two_value
print(mins)

Submission status: Wrong Answer

Solution code:
import heapq



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

one = V[::2]
two = V[1:][::2]

one_count={}
one_len=len(one)
# values=[]
# for i,o in enumerate(set(one)):
#     values.append([ o, one_len - one.count(o)] )
values=[[ o, one_len - one.count(o)] for i,o in enumerate(set(one))]

one_count[10**6]=one_len
# values = heapq.heapify(values)
for temp in heapq.nsmallest(3, values, key=lambda x:x[1]):
    one_count[temp[0]] = temp[1]
    
two_len=len(two)
two_count={}
values=[]
# for i,t in enumerate(set(two)):
#     values.append([ t, two_len - two.count(t)] )
values=[[ t, two_len - two.count(t)] for i,t in enumerate(set(two))]

two_count[10**6]=two_len
for temp in heapq.nsmallest(3, values, key=lambda x:x[1]):
    two_count[temp[0]] = temp[1]


keys = list(set(V))
mins = 1000

for one_key, one_value in one_count.items():
    for two_key, two_value in two_count.items():
        if one_key != two_key:
            if one_value + two_value < mins:
                mins = one_value + two_value
print(mins)

Submission status: Wrong Answer

Solution code:
import heapq



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

one = V[::2]
two = V[1:][::2]

one_count={}
one_len=len(one)
values=[]
for i,o in enumerate(set(one)):
    values.append([ o, one_len - one.count(o)] )

one_count[10**6]=one_len
# values = heapq.heapify(values)
for temp in heapq.nsmallest(3, values, key=lambda x:x[1]):
    one_count[temp[0]] = temp[1]
    
two_len=len(two)
two_count={}
values=[]
for i,t in enumerate(set(two)):
    values.append([ t, two_len - two.count(t)] )

two_count[10**6]=two_len
for temp in heapq.nsmallest(3, values, key=lambda x:x[1]):
    two_count[temp[0]] = temp[1]


keys = list(set(V))
mins = 1000

for one_key, one_value in one_count.items():
    for two_key, two_value in two_count.items():
        if one_key != two_key:
            if one_value + two_value < mins:
                mins = one_value + two_value
print(mins)

Submission status: Wrong Answer

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

one = V[::2]
two = V[1:][::2]

one_count={}
one_len=len(one)
values=[]
for i,o in enumerate(set(one)):
    values.append([ o, one_len - one.count(o)] )

one_count[10**6]=one_len
for temp in sorted(values, key=lambda x: x[1])[:3]:
    one_count[temp[0]] = temp[1]
    
two_len=len(two)
two_count={}
values=[]
for i,t in enumerate(set(two)):
    values.append([ t, two_len - two.count(t)] )

two_count[10**6]=two_len
for temp in sorted(values, key=lambda x: x[1])[:3]:
    two_count[temp[0]] = temp[1]


keys = list(set(V))
mins = 1000

for one_key, one_value in one_count.items():
    for two_key, two_value in two_count.items():
        if one_key != two_key:
            if one_value + two_value < mins:
                mins = one_value + two_value
print(mins)

Submission status: Wrong Answer

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

one = V[::2]
two = V[1:][::2]

one_count={}
one_len=len(one)
values=[]
for i,o in enumerate(set(one)):
    values.append([ o, one_len - one.count(o)] )

one_count[10**6]=one_len
for temp in sorted(values, key=lambda x: x[1])[:3]:
    one_count[temp[0]] = temp[1]
    
two_len=len(two)
two_count={}
values_dict={}
for i,t in enumerate(set(two)):
    values.append([ t, two_len - two.count(t)] )

two_count[10**6]=two_len
for temp in sorted(values, key=lambda x: x[1])[:3]:
    two_count[temp[0]] = temp[1]


keys = list(set(V))
mins = 1000

for one_key, one_value in one_count.items():
    for two_key, two_value in two_count.items():
        if one_key != two_key:
            if one_value + two_value < mins:
                mins = one_value + two_value
print(mins)

Submission status: Wrong Answer

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

one = V[::2]
two = V[1:][::2]

one_count={}
one_len=len(one)
values_dict={}
for i,o in enumerate(set(one)):
    temp = one_len - one.count(o)
    
    if temp in values_dict:
        if values_dict[temp] >= 2:
            one_count[o] = one_len - one.count(o)
        else:
            values_dict[temp]+=1
    else:
        one_count[o] = one_len - one.count(o)
        values_dict[temp]=1
        
one_count[10**6]=one_len
    
two_len=len(two)
two_count={}
values_dict={}
for i,t in enumerate(set(two)):
    temp = two_len - two.count(t)
    
    if temp in values_dict:
        if values_dict[temp] >= 2:
            two_count[t] = two_len - two.count(t)
        else:
            values_dict[temp]+=1
    else:
        two_count[t] = two_len - two.count(t)
        values_dict[temp]=1
        
two_count[10**6]=two_len

keys = list(set(V))
mins = 1000

for one_key, one_value in one_count.items():
    for two_key, two_value in two_count.items():
        if one_key != two_key:
            if one_value + two_value < mins:
                mins = one_value + two_value
print(mins)

Submission status: Wrong Answer

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

one = V[::2]
two = V[1:][::2]

#one
one_count={}
one_len=len(one)
for i,o in enumerate(set(one)):
    one_count[o] = one_len - one.count(o)
one_count[10**6]=one_len
    
two_len=len(two)
two_count={}
for i,t in enumerate(set(two)):
    two_count[t] = two_len - two.count(t)
two_count[10**6]=two_len

keys = list(set(V))
mins = 1000

for one_key, one_value in one_count.items():
    for two_key, two_value in two_count.items():
        if one_key != two_key:
            if one_value + two_value < mins:
                mins = one_value + two_value
print(mins)

Submission status: Wrong Answer

Solution code:
n = int(input())
v = input().split()
x = {}
for w in v:
    if w in x:
        x[w] += 1
    else:
        x[w] = 1
y = list(x.values())
y.sort()
if len(y) == 1:
    print(n//2)
else:
    print(max(n//2-y[-1], 0) + n//2-y[-2])

Submission status: Wrong Answer

Solution code:
n = int(input())
v = input().split()
x = {}
for w in v:
    if w in x:
        x[w] += 1
    else:
        x[w] = 1
y = list(x.values())
y.sort()
if len(y) == 1:
    print(n//2)
else:
    print(abs(n//2-y[-1]) + abs(n//2-y[-2]))

Submission status: Wrong Answer

Solution code:
n = int(input())
vl = list(map(int,input().split()))
v1 = vl[::2]
v2 = vl[1::2]

def count(a):
  d = dict()
  for i in a:
    if i not in d:
      d[i] = 1
    else:
      d[i] += 1
  l = []
  for i in d:
    l.append([d[i],i])
  l.append([0,0])
  l.sort(reverse=1)
  return l

v1 = count(v1)
v2 = count(v2)
if v1[0][0] == v1[1][0] or v2[0][0] ==v2[1][0]:
  print(n-v1[0][0]-v2[0][0])
elif v1[0][1] != v2[0][1]:
  print(n-v1[0][0]-v2[0][0])
elif v1[1][0]+v2[0][0] > v1[0][0]+v2[1][0]:
  print(n-v1[1][0]+v2[0][0])
else:
  print(v1[0][0]+v2[1][0])

Submission status: Wrong Answer

Solution code:
n = int(input())
vl = list(map(int,input().split()))
v1 = vl[::2]
v2 = vl[1::2]

def count(a):
  d = dict()
  for i in a:
    if i not in d:
      d[i] = 1
    else:
      d[i] += 1
  m = [[0],[0]]
  for i in d:
    if d[i] >= m[0][0]:
      m = [(d[i],i),m[0]]
    elif d[i] >= m[1][0]:
      m = [m[0],(d[i],i)]
  return m

v1 = count(v1)
v2 = count(v2)
if v1[0][1] != v2[0][1]:
  print(n-v1[0][0]-v2[0][0])
elif v1[1][0]+v2[0][0] > v1[0][0]+v2[1][0]:
  print(n-v1[1][0]+v2[0][0])
else:
  print(v1[0][0]+v2[1][0])

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

odd = []
even = []

for m in range(0,n, 2):
    odd.append(V[m])
for m in range(1,n, 2):
    even.append(V[m])

odd_c = Counter(odd)
even_c = Counter(even)

odd_c_sort = sorted(odd_c.items(), key = lambda x:x[1])
even_c_sort = sorted(even_c.items(), key = lambda x:x[1])

if len(odd_c_sort) == len(even_c_sort) == 1:
    if odd_c_sort[0][0] == even_c_sort[0][0]:
        ans = n/2
    else:
        ans = 0
elif len(odd_c_sort) == 1:
    if odd_c_sort[0][0] == even_c_sort[0][0]:
        ans = n/2 - even_c_sort[1][1]
    else:
        ans = n/2 - even_c_sort[0][1]
elif len(even_c_sort) == 1:
    if even_c_sort[0][0] == odd_c_sort[0][0]:
        ans = n/2 - odd_c_sort[1][1]
    else:
        ans = n/2 - odd_c_sort[0][1]
else:
    if odd_c_sort[0][0] != even_c_sort[0][0]:
        ans = n - odd_c_sort[0][1] - even_c_sort[0][1]
    else:
        ans = min((n - odd_c_sort[0][1] - even_c_sort[1][1]), (n - odd_c_sort[1][1] - even_c_sort[0][1]))

print(int(ans))

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

odd = []
even = []

for m in range(0,n, 2):
    odd.append(V[m])
for m in range(1,n, 2):
    even.append(V[m])

odd_c = Counter(odd)
even_c = Counter(even)

odd_c_sort = sorted(odd_c.items(), key = lambda x:x[1])
even_c_sort = sorted(even_c.items(), key = lambda x:x[1])

if len(odd_c_sort) == len(even_c_sort) == 1:
    if odd_c_sort[0][0] == even_c_sort[0][0]:
        ans = n/2
    else:
        ans = 0
elif len(odd_c_sort) == 1:
    if odd_c_sort[0][0] == even_c_sort[0][0]:
        ans = n/2 - even_c_sort[1][1]
    else:
        ans = n/2 - even_c_sort[0][1]
elif len(even_c_sort) == 1:
    if even_c_sort[0][0] == odd_c_sort[0][0]:
        ans = n/2 - odd_c_sort[1][1]
    else:
        ans = n/2 - odd_c_sort[0][1]
else:
    if odd_c_sort[0][0] == even_c_sort[0][0]:
        if odd_c_sort[0][1] >= even_c_sort[0][1]:
            ans = n - odd_c_sort[0][1] - even_c_sort[1][1]
        else:
            ans = n - odd_c_sort[1][1] - even_c_sort[0][1]
    else:
        ans = n - odd_c_sort[0][1] - even_c_sort[0][1]

print(int(ans))

Submission status: Wrong Answer

Solution code:
n = int(input())
v = list(map(int, input().split()))
v1 = []
v2 = []
for i in range(n):
	if i%2 == 0:
		v1.append(v[i])
	else:
		v2.append(v[i])
v1.sort()
v2.sort()

cnt1 = []
cnt2 = []
now = v1[0]
con = 1
for i in range(1, len(v1)):
	if now == v1[i]:
		con += 1
	else:
		cnt1.append([con, now])
		now = v1[i]
		con = 1
cnt1.append([con, now])
now = v2[0]
con = 1
for i in range(1, len(v2)):
	if now == v2[i]:
		con += 1
	else:
		cnt2.append([con, now])
		now = v2[i]
		con = 1
cnt2.append([con, now])

cnt1.sort()
cnt2.sort()
if cnt1[len(cnt1)-1][1] != cnt2[len(cnt2)-1][1]:
	p1 = [cnt1[i][0] for i in range(len(cnt1))]
	p2 = [cnt2[i][0] for i in range(len(cnt2))]
	print(sum(p1[:len(p1)-1])+sum(p2[:len(p2)-1]))
else:
	p1 = [cnt1[i][0] for i in range(len(cnt1))]
	p2 = [cnt2[i][0] for i in range(len(cnt2))]
	ans = max(sum(p1[:len(p1)-2])+p1[len(p1)-1]+sum(p2[:len(p2)-1]), sum(p1[:len(p1)-1])+p2[len(p2)-1]+sum(p2[:len(p2)-2]))
	print(ans)