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:
from collections import Counter

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

V1 = [V[i] for i in range(0, len(V), 2)]
V2 = [V[i] for i in range(1, len(V), 2)]

x = Counter(V1).most_common(2)
y = Counter(V2).most_common(2)
x, y = (x, y) if x[0][1] > y[0][1] else (y, x)

l = int(N / 2)
res = l - x[0][1]
if y[0][0] == x[0][0]:
    res += l - (y[1][1] if len(y) > 1 else 0)
else:
    res += l - y[0][1]

print(res)

Submission status: Wrong Answer

Solution code:
def get_first(even,even_max_ind,even_second_ind):
    even_max=0
    for i in range(1,10**5+1):
        if(even[i]==0):
            continue
        if(even_max<even[i]):
            even_second_ind[0]=even_max_ind.pop()
            even_max_ind.clear()
            even_max_ind.append(i)
            even_max=even[i]
        elif(even_max==even[i]):
            even_max_ind.append(i)


n=int(input())
e_max=0
o_max=0
even=[0]*(10**5+1)
odd=[0]*(10**5+1)
retu=list(map(int,input().split()))
for i in range(n):
    if(i%2==0):
        even[retu[i]]+=1
    else:
        odd[retu[i]]+=1

even_max_ind=[0]
even_second_ind=[0]
odd_max_ind=[0]
odd_second_ind=[0]

get_first(even,even_max_ind,even_second_ind)
get_first(odd,odd_max_ind,odd_second_ind)

if(len(even_max_ind)>=2 or len(odd_max_ind)>=2 or even_max_ind[0]!=odd_max_ind[0]):
    print(n-even[even_max_ind[0]] - odd[odd_max_ind[0]])
else:
    print(n-max([even[even_second_ind[0]] + odd[odd_max_ind[0]],even[even_max_ind[0]] + odd[odd_second_ind[0]]]))

Submission status: Wrong Answer

Solution code:
vvv_num = int(input())
vvv_num_list_str = input()
vvv_num_list = vvv_num_list_str.split()

vvv_num_uniq = list( set( vvv_num_list ) )
uniq_num = len(vvv_num_uniq)

if uniq_num == 2:
    print(0)
elif uniq_num == 1:
    print(int(vvv_num/2))
else:
    print(uniq_num-2)

Submission status: Wrong Answer

Solution code:
import collections

n = int(input())
V = [int(x) for x in input().split()]
V_even = collections.Counter([V[i] for i in range(len(V)) if i % 2 == 1])
V_odd = collections.Counter([V[i] for i in range(len(V)) if i % 2 == 0])
even_most = V_even.most_common()
odd_most = V_odd.most_common()
if len(even_most) == 1 and len(odd_most) == 1 and even_most[0][0] == odd_most[0][0]:
    ans = n/2
    print(int(ans))
elif even_most[0][0] is not odd_most[0][0]:
    ans = n/2 - V_even[even_most[0][0]] + n/2 - V_odd[odd_most[0][0]]
    print(int(ans))
elif len(even_most) == 1:
    ans = n/2 - V_even[even_most[0][0]] + n/2 - V_odd[odd_most[1][0]]
    print(int(ans))
elif len(odd_most) == 1:
    ans = n/2 - V_even[even_most[1][0]] + n/2 - V_odd[odd_most[0][0]]
    print(int(ans))
else:
    ans1 = n/2 - V_even[even_most[0][0]] + n/2 - V_odd[odd_most[1][0]]
    ans2 = n/2 - V_even[even_most[1][0]] + n/2 - V_odd[odd_most[0][0]]
    print(int(min(ans1, ans2)))

Submission status: Wrong Answer

Solution code:
import collections

n = int(input())
V = [int(x) for x in input().split()]
V_even = collections.Counter([V[i] for i in range(len(V)) if i % 2 == 1])
V_odd = collections.Counter([V[i] for i in range(len(V)) if i % 2 == 0])
even_most = V_even.most_common()
odd_most = V_odd.most_common()
if len(even_most) == 1 and len(odd_most) == 1 and even_most[0][0] == odd_most[0][0]:
    ans = n/2
    print(int(ans))
elif even_most[0][0] is not odd_most[0][0]:
    ans = n/2 - V_even[even_most[0][0]] + n/2 - V_odd[odd_most[0][0]]
    print(int(ans))
else:
    ans1 = n/2 - V_even[even_most[0][0]] + n/2 - V_odd[odd_most[1][0]]
    ans2 = n/2 - V_even[even_most[1][0]] + n/2 - V_odd[odd_most[0][0]]
    print(int(min(ans1, ans2)))

Submission status: Wrong Answer

Solution code:
import collections

n = int(input())
V = [int(x) for x in input().split()]
V_even = collections.Counter([V[i] for i in range(len(V)) if i % 2 == 0])
V_odd = collections.Counter([V[i] for i in range(len(V)) if i % 2 == 1])
even_most = V_even.most_common()
odd_most = V_odd.most_common()
if len(even_most) == 1 and len(odd_most) == 1:
    ans = n/2
    print(int(ans))
elif even_most[0][0] is not odd_most[0][0]:
    ans = n/2 - V_even[even_most[0][0]] + n/2 - V_odd[odd_most[0][0]]
    print(int(ans))
else:
    ans1 = n/2 - V_even[even_most[0][0]] + n/2 - V_odd[odd_most[1][0]]
    ans2 = n/2 - V_even[even_most[1][0]] + n/2 - V_odd[odd_most[0][0]]
    ans3 = n/2 - V_even[even_most[0][0]] + n/2 - V_odd[odd_most[2][0]]
    ans4 = n/2 - V_even[even_most[2][0]] + n/2 - V_odd[odd_most[0][0]]
    print(int(min(ans1, ans2, ans3, ans4)))

Submission status: Wrong Answer

Solution code:
N = int(input())
v_list = [int(x) for x in input().split()]
v_odd = [x for x in v_list if v_list.index(x) % 2 == 1]
v_even = [x for x in v_list if v_list.index(x) % 2 == 0]

print(v_odd, v_even)
if len(list(set(v_list))) > 1:

        odd_max1 = list(set(v_odd))[-1]
        
        even_max1 = list(set(v_even))[-1]
        
        
        if odd_max1 == even_max1:
                odd_max2 = list(set(v_odd))[-2]
                even_max2 = list(set(v_even))[-2]

                p = N -v_odd.count(odd_max1) - v_even.count(even_max2)
                q = N -v_odd.count(odd_max2) - v_even.count(even_max1)

                if p > q:
                        n = p
                else:
                        n = q
        else:
                n = N -v_odd.count(odd_max1) - v_even.count(even_max1)

else:
        n = int(N / 2)



print(n)

Submission status: Wrong Answer

Solution code:
import collections

n = int(input())
V = [int(x) for x in input().split()]
V_even = collections.Counter([V[i] for i in range(len(V)) if i % 2 == 0])
V_odd = collections.Counter([V[i] for i in range(len(V)) if i % 2 == 1])
even_most = V_even.most_common()
odd_most = V_odd.most_common()
if len(even_most) == 1 and len(odd_most) == 1:
    ans = n/2
    print(int(ans))
elif even_most[0][0] is not odd_most[0][0]:
    ans = n/2 - V_even[even_most[0][0]] + n/2 - V_odd[odd_most[0][0]]
    print(int(ans))
else:
    ans1 = n/2 - V_even[even_most[0][0]] + n/2 - V_odd[odd_most[1][0]]
    ans2 = n/2 - V_even[even_most[1][0]] + n/2 - V_odd[odd_most[0][0]]
    print(int(min(ans1, ans2)))

Submission status: Wrong Answer

Solution code:
import collections

n = int(input())
V = [int(x) for x in input().split()]
V_even = collections.Counter([V[i] for i in range(len(V)) if i % 2 == 0])
V_odd = collections.Counter([V[i] for i in range(len(V)) if i % 2 == 1])
even_most = V_even.most_common()
odd_most = V_odd.most_common()
if even_most[0][0] is not odd_most[0][0]:
    ans = n/2 - V_even[even_most[0][0]] + n/2 - V_odd[odd_most[0][0]]
    print(int(ans))
elif len(even_most) == 1 and len(odd_most) == 1:
    ans = n/2
    print(int(ans))
else:
    ans1 = n/2 - V_even[even_most[0][0]] + n/2 - V_odd[odd_most[1][0]]
    ans2 = n/2 - V_even[even_most[1][0]] + n/2 - V_odd[odd_most[0][0]]
    #ans3 = n/2 - V_even[even_most[1][0]] + n/2 - V_odd[odd_most[0][0]]
    #ans4 = n/2 - V_even[even_most[1][0]] + n/2 - V_odd[odd_most[0][0]]
    print(int(min(ans1, ans2)))

Submission status: Wrong Answer

Solution code:
import collections

n = int(input())
V = [int(x) for x in input().split()]
V_even = collections.Counter([V[i] for i in range(len(V)) if i % 2 == 0])
V_odd = collections.Counter([V[i] for i in range(len(V)) if i % 2 == 1])
even_most = V_even.most_common()
odd_most = V_odd.most_common()
if even_most[0][0] is not odd_most[0][0]:
    ans = n/2 - V_even[even_most[0][0]] + n/2 - V_odd[odd_most[0][0]]
    print(int(ans))
elif len(even_most) == 1 and len(odd_most) == 1:
    ans = n/2
    print(int(ans))
else:
    if even_most[0][1] >= odd_most[0][1]:
        ans = n/2 - V_even[even_most[0][0]] + n/2 - V_odd[odd_most[1][0]]
    else:
        ans = n/2 - V_even[even_most[1][0]] + n/2 - V_odd[odd_most[0][0]]
    print(int(ans))

Submission status: Wrong Answer

Solution code:
N = int(input())
V = list(map(int, input().split()))
M = 10 ** 5 + 1
V0, V1 = [0] * M, [0] * M
ma01, ma02 = 0, 0
ma11, ma12 = 0, 0
ind0, ind1 = 0, 0
for i in range(N):
    if i % 2 == 0:
        V0[V[i]] += 1
        if ma01 <= V0[V[i]]:
            ma01 = V0[V[i]]
            ma02 = ma01
            ind0 = V[i]
    else:
        V1[V[i]] += 1
        if ma11 <= V1[V[i]]:
            ma11 = V1[V[i]]
            ma12 = ma11
            ind1 = V[i]

if ind0 != ind1:
    print(N - ma01 - ma11)
else:
    print(min(N + ma01 - ma02 - ma11, N - ma01 + ma11 - ma12))

Submission status: Wrong Answer

Solution code:
import heapq
n=int(input().strip())
nu=list(map(int, input().strip().split()))
nu1=[]
nu2=[]
nu1memo=[0]*100001
nu2memo=[0]*100001
for i in range(0,n//2):
    nu1.append(nu[2*i])
    nu2.append(nu[2*i+1])
    nu1memo[nu[2*i]]+=1
    nu2memo[nu[2*i+1]]+=1
    
#mi1=max(zip(nu1memo, range(len(nu1memo))))[1]
mi1=heapq.nlargest(2, range(len(nu1memo)), key=nu1memo.__getitem__)
#mi2=max(zip(nu2memo, range(len(nu2memo))))[1]
mi2=heapq.nlargest(2, range(len(nu2memo)), key=nu2memo.__getitem__)
ans=0
if mi1[0]!=mi2[0]:
    ans=n-nu1memo[mi1[0]]-nu2memo[mi2[0]]
elif mi1[0]==mi2[0]:
    if mi1[1]<mi2[1]:
        ans=n-nu1memo[mi1[0]]-nu2memo[mi2[1]]
    else:
        ans=n-nu1memo[mi1[1]]-nu2memo[mi2[0]]
    
print(ans)

Submission status: Wrong Answer

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

x = []
y = []

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

x.sort()
y.sort()

q = []
r = []
s = []
t = []
countx = 1
county = 1

for j in range(int(n / 2)):
    if x[j - 1] == x[j] and j != 0:
        countx += 1
    if j == n / 2 - 1:
        s.append(countx)
        q.append(x[j - 1])
        countx = 1
    elif x[j - 1] != x[j] and j != 0:
        s.append(countx)
        q.append(x[j - 1])
        countx = 1


for k in range(int(n / 2)):
    if y[k - 1] == y[k] and k != 0:
        county += 1
    if k == n / 2 - 1:
        t.append(county)
        r.append(y[k - 1])
        county = 1
    elif y[k - 1] != y[k] and k != 0:
        t.append(county)
        r.append(y[k - 1])
        county = 1
s2 = s
t2 = t
#a = [int(m) for m in a]
s2.sort(reverse=True)
t2.sort(reverse=True)
sc = -1
tc = -1
sk = 0
tk = 0

for i in s2:
    if sc == -1:
        sk = i
    elif i != sk and sc > -1:
        sk = i
        break
    sc += 1
if sc == 0:
    sk = 0

for i in t2:
    if tc == -1:
        tk = i
    elif i != tk and tc > -1:
        tk = i
        break
    tc += 1
if tc == 0:
    tk = 0

if q[s.index(max(s))] != r[t.index(max(t))]:
    print(n - max(s) - max(t))
else:
    if sk >= tk:
        print(n - sk - max(t))
    else:
        print(n - max(s) - tk)

Submission status: Wrong Answer

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

x = []
y = []

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

x.sort()
y.sort()

q = []
r = []
s = []
t = []
countx = 1
county = 1

for j in range(int(n / 2)):
    if x[j - 1] == x[j] and j != 0:
        countx += 1
    if j == n / 2 - 1:
        s.append(countx)
        q.append(x[j - 1])
        countx = 1
    elif x[j - 1] != x[j] and j != 0:
        s.append(countx)
        q.append(x[j - 1])
        countx = 1


for k in range(int(n / 2)):
    if y[k - 1] == y[k] and k != 0:
        county += 1
    if k == n / 2 - 1:
        t.append(county)
        r.append(y[k - 1])
        county = 1
    elif y[k - 1] != y[k] and k != 0:
        t.append(county)
        r.append(y[k - 1])
        county = 1
s2 = s
t2 = t
#a = [int(m) for m in a]
s2.sort(reverse=True)
t2.sort(reverse=True)
sc = -1
tc = -1
sk = 0
tk = 0
ssymbol = 0
tsymbol = 0
for i in s2:
    if sc == -1:
        sk = i
    elif i != sk and sc > -1:
        sk = i
        ssymbol = 1
        break
    sc += 1
if ssymbol == 0:
    sk = 0
for i in t2:
    if tc == -1:
        tk = i
    elif i != tk and tc > -1:
        tk = i
        break
    tc += 1
if tsymbol == 0:
    tk = 0

if q[s.index(max(s))] != r[t.index(max(t))]:
    print(n - max(s) - max(t))
else:
    if sk >= tk:
        print(n - sk - max(t))
    else:
        print(n - max(s) - tk)

Submission status: Wrong Answer

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

x = []
y = []

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

x.sort()
y.sort()

q = []
r = []
s = []
t = []
countx = 1
county = 1

for j in range(int(n / 2)):
    if x[j - 1] == x[j] and j != 0:
        countx += 1
    if j == n / 2 - 1:
        s.append(countx)
        q.append(x[j - 1])
        countx = 1
    elif x[j - 1] != x[j] and j != 0:
        s.append(countx)
        q.append(x[j - 1])
        countx = 1


for k in range(int(n / 2)):
    if y[k - 1] == y[k] and k != 0:
        county += 1
    if k == n / 2 - 1:
        t.append(county)
        r.append(y[k - 1])
        county = 1
    elif y[k - 1] != y[k] and k != 0:
        t.append(county)
        r.append(y[k - 1])
        county = 1
s2 = s
t2 = t
#a = [int(m) for m in a]
s2.sort(reverse=True)
t2.sort(reverse=True)
sc = -1
tc = -1
sk = 0
tk = 0

for i in s2:
    if sc == -1:
        sk = i
    elif i != sk and sc > -1:
        sk = i
        break
    sc += 1

for i in t2:
    if tc == -1:
        sk = i
    elif i != tk and tc > -1:
        tk = i
        break
    tc += 1

if q[s.index(max(s))] != r[t.index(max(t))]:
    print(n - max(s) - max(t))
else:
    if sk >= tk:
        print(n - sk - max(t))
    else:
        print(n - max(s) - tk)

Submission status: Wrong Answer

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

x = []
y = []

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

x.sort()
y.sort()

q = []
r = []
s = []
t = []
countx = 1
county = 1

for j in range(int(n / 2)):
    if x[j - 1] == x[j] and j != 0:
        countx += 1
    if j == n / 2 - 1:
        s.append(countx)
        q.append(x[j - 1])
        countx = 1
    elif x[j - 1] != x[j] and j != 0:
        s.append(countx)
        q.append(x[j - 1])
        countx = 1


for k in range(int(n / 2)):
    if y[k - 1] == y[k] and k != 0:
        county += 1
    if k == n / 2 - 1:
        t.append(county)
        r.append(y[k - 1])
        county = 1
    elif y[k - 1] != y[k] and k != 0:
        t.append(county)
        r.append(y[k - 1])
        county = 1
s2 = s
t2 = t
#a = [int(m) for m in a]
s2.sort(reverse=True)
t2.sort(reverse=True)
sc = -1
tc = -1
sk = 0
tk = 0

for i in s2:
    if sc == -1:
        sk == i
    elif i != sk and sc > -1:
        sk = i
        break
    sc += 1

for i in t2:
    if tc == -1:
        sk == i
    elif i != tk and tc > -1:
        tk = i
        break
    tc += 1

if q[s.index(max(s))] != r[t.index(max(t))]:
    print(n - max(s) - max(t))
else:
    if sk >= tk:
        print(n - sk - max(t))
    else:
        print(n - max(s) - tk)

Submission status: Wrong Answer

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

x = []
y = []

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

x.sort()
y.sort()

q = []
r = []
s = []
t = []
countx = 1
county = 1

for j in range(int(n / 2)):
    if x[j - 1] == x[j] and j != 0:
        countx += 1
    if j == n / 2 - 1:
        s.append(countx)
        q.append(x[j - 1])
        countx == 1
    elif x[j - 1] != x[j] and j != 0:
        s.append(countx)
        q.append(x[j - 1])
        countx == 1


for k in range(int(n / 2)):
    if y[k - 1] == y[k] and k != 0:
        county += 1
    if k == n / 2 - 1:
        t.append(county)
        r.append(y[k - 1])
        county == 1
    elif y[k - 1] != y[k] and k != 0:
        t.append(county)
        r.append(y[k - 1])
        county == 1
s2 = s
t2 = t
#a = [int(m) for m in a]
s2.sort(reverse=True)
t2.sort(reverse=True)
sc = -1
tc = -1
sk = 0
tk = 0

for i in s2:
    if sc == -1:
        sk == i
    elif i != sk and sc > -1:
        sk = i
        break
    sc += 1

for i in t2:
    if tc == -1:
        sk == i
    elif i != tk and tc > -1:
        tk = i
        break
    tc += 1

if q[s.index(max(s))] != r[t.index(max(t))]:
    print(n - max(s) - max(t))
else:
    if sk >= tk:
        print(n - sk - max(t))
    else:
        print(n - max(s) - tk)

Submission status: Wrong Answer

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

x = []
y = []

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

x.sort()
y.sort()

q = []
r = []
s = []
t = []
countx = 1
county = 1

for j in range(int(n / 2)):
    if x[j - 1] == x[j] and j != 0:
        countx += 1
    if j == n / 2 - 1:
        s.append(countx)
        q.append(x[j - 1])
        countx == 1
    elif x[j - 1] == x[j] and j != 0:
        s.append(countx)
        q.append(x[j - 1])
        countx == 1


for k in range(int(n / 2)):
    if y[k - 1] == y[k] and k != 0:
        county += 1
    if k == n / 2 - 1:
        t.append(county)
        r.append(y[k - 1])
        county == 1
    elif y[k - 1] == y[k] and k != 0:
        t.append(county)
        r.append(y[k - 1])
        county == 1
s2 = s
t2 = t
#a = [int(m) for m in a]
s2.sort(reverse=True)
t2.sort(reverse=True)
sc = -1
tc = -1
sk = 0
tk = 0

for i in s2:
    if sc == -1:
        sk == i
    elif i != sk and sc > -1:
        sk = i
        break
    sc += 1

for i in t2:
    if tc == -1:
        sk == i
    elif i != tk and tc > -1:
        tk = i
        break
    tc += 1

if q[s.index(max(s))] != r[t.index(max(t))]:
    print(n - max(s) - max(t))
else:
    if sk >= tk:
        print(n - sk - max(t))
    else:
        print(n - max(s) - tk)

Submission status: Wrong Answer

Solution code:
import collections

N = int(input())
a = list(int(i) for i in input().split())

b = a[::2]
c = a[1::2]

b_ =collections.Counter(b)
c_ =collections.Counter(c)

baa = b_.most_common()
caa = c_.most_common()

baa.append([0,0])
caa.append([0,0])

if baa[0][0] != caa[0][0]:
    print(N - baa[0][1] - caa[0][1])
else:
    print(max(N - baa[0][1] - caa[1][1],N - caa[0][1] - baa[1][1]))

Submission status: Wrong Answer

Solution code:
# coding: UTF-8
import sys
#sys.setrecursionlimit(n)
import heapq
import re
import bisect
import random
import math
import itertools
from collections import defaultdict, deque
from copy import deepcopy
from decimal import *

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

nn = n // 2
for i in range(nn):
    a[v[i * 2]] += 1
    b[v[i * 2 + 1]] += 1

ma1 = max(a, key=a.get)
mb1 = max(b, key=b.get)
mva1 = a[ma1]
mvb1 = b[mb1]
a[ma1] = 0
b[mb1] = 0
ma2 = max(a, key=a.get)
mb2 = max(b, key=b.get)
mva2 = a[ma2]
mvb2 = b[mb2]
a[ma2] = 0
b[mb2] = 0

ma = [(ma1, mva1), (ma2, mva2)]
mb = [(mb1, mvb1), (mb2, mvb2)]
mx = 0xFFFFFFFF
for i in ma:
    for j in mb:
        if i[0] == j[0]:
            pass
        else:
            mx = min(sum(a.values()) + i[1] + sum(b.values()) + j[1], mx)
if mx == 0xFFFFFFFF:
    print(0)
else:
    print(mx)

Submission status: Wrong Answer

Solution code:
# coding: UTF-8
import sys
#sys.setrecursionlimit(n)
import heapq
import re
import bisect
import random
import math
import itertools
from collections import defaultdict, deque
from copy import deepcopy
from decimal import *

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

nn = n // 2
for i in range(nn):
    a[v[i * 2]] += 1
    b[v[i * 2 + 1]] += 1

ma1 = max(a, key=a.get)
mb1 = max(b, key=b.get)
mva1 = a[ma1]
mvb1 = b[mb1]
a[ma1] = 0
b[mb1] = 0
ma2 = max(a, key=a.get)
mb2 = max(b, key=b.get)
mva2 = a[ma2]
mvb2 = b[mb2]
a[ma2] = 0
b[mb2] = 0

ma = [(ma1, mva1), (ma2, mva2)]
mb = [(mb1, mvb1), (mb2, mvb2)]
mx = 0xFFFFFFFF
for i in ma:
    for j in mb:
        if i[0] == j[0]:
            mx = min(mx, nn)
        else:
            mx = min(sum(a.values()) + i[1] + sum(b.values()) + j[1], mx)
if mx == 0xFFFFFFFF:
    print(0)
else:
    print(mx)

Submission status: Wrong Answer

Solution code:
# coding: UTF-8
import sys
#sys.setrecursionlimit(n)
import heapq
import re
import bisect
import random
import math
import itertools
from collections import defaultdict, deque
from copy import deepcopy
from decimal import *

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

nn = n // 2
for i in range(nn):
    a[v[i * 2]] += 1
    b[v[i * 2 + 1]] += 1

ma1 = max(a, key=a.get)
mb1 = max(b, key=b.get)
mva1 = a[ma1]
mvb1 = b[mb1]
a[ma1] = 0
b[mb1] = 0
ma2 = max(a, key=a.get)
mb2 = max(b, key=b.get)
mva2 = a[ma2]
mvb2 = b[mb2]
a[ma2] = 0
b[mb2] = 0

ma = [mva1, mva2]
mb = [mvb1, mvb2]
mx = 0xFFFFFFFF
for i in ma:
    for j in mb:
        if i == 0 and j == 0:
            pass
        else:
            mx = min(sum(a.values()) + i + sum(b.values()) + j, mx)
if mx == 0xFFFFFFFF:
    print(0)
else:
    print(mx)

Submission status: Wrong Answer

Solution code:
# coding: UTF-8
import sys
#sys.setrecursionlimit(n)
import heapq
import re
import bisect
import random
import math
import itertools
from collections import defaultdict, deque
from copy import deepcopy
from decimal import *

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

nn = n // 2
for i in range(nn):
    a[v[i * 2]] += 1
    b[v[i * 2 + 1]] += 1

ma1 = max(a, key=a.get)
mb1 = max(b, key=b.get)
a[ma1] = 0
b[mb1] = 0
ma2 = max(a, key=a.get)
mb2 = max(b, key=b.get)
a[ma2] = 0
b[mb2] = 0

ma = [ma1, ma2]
mb = [mb1, mb2]
mx = 0xFFFFFFFF
for i in ma:
    for j in mb:
        mx = min(sum(a.values()) + i + sum(b.values()) + j, mx)
        
print(mx)

Submission status: Wrong Answer

Solution code:
# coding: UTF-8
import sys
#sys.setrecursionlimit(n)
import heapq
import re
import bisect
import random
import math
import itertools
from collections import defaultdict, deque
from copy import deepcopy
from decimal import *

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

nn = n // 2
for i in range(nn):
    a[v[i * 2]] += 1
    b[v[i * 2 + 1]] += 1

c = max(a, key=a.get)
d = max(b, key=b.get)
tmpc = a[c]
tmpd = b[d]
a[c] = 0
b[d] = 0

if c == d and tmpc == tmpd:
    print(tmpc)
else:
    if c == d:
        if tmpc > tmpd:
            d2 = max(b, key=b.get)
            b[d] = tmpd
            b[d2] = 0
        else:
            c2 = max(a, key=a.get)
            a[c] = tmpc
            a[c2] = 0
    print(sum(a.values()) + sum(b.values()))

Submission status: Wrong Answer

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

a = [arr[i] for i in range(0,n,2)]
b = [arr[y] for y in range(1,n,2)]

import collections
acnt = collections.Counter(a)
bcnt = collections.Counter(b)

lsacnt = sorted(acnt.items(), key=lambda x: x[1],reverse=True)
lsbcnt = sorted(bcnt.items(), key=lambda j: j[1],reverse=True)

def val(abcnt, ablscnt):
	if len(list(abcnt)) < 2:
		return 0
	else:
		return ablscnt[1][1]

if lsacnt[0][0] != lsbcnt[0][0]:
	ans = n - lsacnt[0][1] - lsbcnt[0][1]
elif lsacnt[0][0] == lsbcnt[0][0]:
	if lsacnt[0][1] >= lsbcnt[0][1]:
		ans = n - lsacnt[0][1] - val(bcnt,lsbcnt)
	else:
		ans = n - val(acnt,lsacnt) - lsbcnt[0][1]

print(ans)

Submission status: Wrong Answer

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

a = [arr[i] for i in range(0,n,2)]
b = [arr[y] for y in range(1,n,2)]

import collections
acnt = collections.Counter(a)
bcnt = collections.Counter(b)

lsacnt = sorted(acnt.items(), key=lambda x: x[1])
lsbcnt = sorted(bcnt.items(), key=lambda j: j[1])

def val(abcnt, ablscnt):
	if len(list(abcnt)) < 2:
		return 0
	else:
		return ablscnt[1][1]

if lsacnt[0][0] != lsbcnt[0][0]:
	ans = n - lsacnt[0][1] - lsbcnt[0][1]
elif lsacnt[0][0] == lsbcnt[0][0]:
	if lsacnt[0][1] >= lsbcnt[0][1]:
		ans = n - lsacnt[0][1] - val(bcnt,lsbcnt)
	else:
		ans = n - val(acnt,lsacnt) - lsbcnt[0][1]

print(ans)

Submission status: Wrong Answer

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

a = [arr[i] for i in range(0,n,2)]
b = [arr[y] for y in range(1,n,2)]

import collections
acnt = collections.Counter(a)
bcnt = collections.Counter(b)

lsacnt = sorted(acnt.items(), key=lambda x: x[1])
lsbcnt = sorted(bcnt.items(), key=lambda y: y[1])

def val(abcnt, ablscnt):
	if len(list(abcnt)) < 2:
		return 0
	else:
		return ablscnt[1][1]

if lsacnt[0][0] != lsbcnt[0][0]:
	ans = n - lsacnt[0][1] - lsbcnt[0][1]
elif lsacnt[0][0] == lsbcnt[0][0]:
	if lsacnt[0][1] >= lsbcnt[0][1]:
		ans = n - lsacnt[0][1] - val(bcnt,lsbcnt)
	else:
		ans = n - val(acnt,lsbcnt) - lsbcnt[0][1]

print(ans)

Submission status: Wrong Answer

Solution code:
import sys

def solve(N, ls_v):
    # Uncomment the following if you want to check the input.
    #print('N =', N)
    #print('ls_v =', ls_v)
    inc=[]
    incc={}
    count=0
    for i in ls_v:
        if i not in incc:
            incc[i] = 1
        else:
            incc[i] += 1
    cl =[i for i in incc.values()]
    cls =[i for i in incc.keys()]
    a = max(cl)
    a = cl.index(a)
    a = cls[a]
    counter = 0
    counter2 = 0
    reco = 0
    counter3 = 0
    ckk = ""
    ck = ""
    rk = ""
    samecount= 0
    samelist=[]
    for key,value in incc.items():
        #print(key,value)
        if key == a:
            ckk,counter2 = key,value
        elif key != a and counter < value:
            counter,ck = value,key
        if (key != a and key != ck) and reco <= value:
            rk,reco = key,value
            #print("c")
        else:
            counter3 += 1
    #print("1",reco,rk)
    corli = []
    corli1 = []
    corli2 = []
    corli3 = []
    corli4 = []
    corli5 = []
    i = 10
    for line in ls_v:
        if i%2 == 0:
            corli.append(ckk)
            corli1.append(ck)
            corli2.append(rk)
            corli3.append(ck)
            corli4.append(rk)
            corli5.append(ckk)
        elif i%2 != 0:
            corli.append(ck)
            corli1.append(ckk)
            corli2.append(ck)
            corli3.append(rk)
            corli4.append(ckk)
            corli5.append(rk)
        i += 1
    #print(corli2)
    cc,c1,c2,c3,c4 = 0,0,0,0,0
    c = 0
    for (line1,line2) in zip(ls_v,corli):
        if line1 != line2:
            c += 1
    for (line1,line2) in zip(ls_v,corli1):
        if line1 != line2:
            cc += 1
    for (line1,line2) in zip(ls_v,corli2):
        #print(line1,line2)
        if line1 != line2:
            c1 += 1
    for (line1,line2) in zip(ls_v,corli3):
        if line1 != line2:
            c2 += 1
    for (line1,line2) in zip(ls_v,corli4):
        if line1 != line2:
            c3 += 1
    for (line1,line2) in zip(ls_v,corli5):
        if line1 != line2:
            c4 += 1
    for item in ls_v:
        if item == ls_v[0]:
            samecount += 1
    if samecount==N:
        return N//2
    else:
    #print(c,cc,c1,c2,c3,c4)
        if cc == 0:
            return 0
        else:
            return min(c,cc,c1,c2,c3,c4)
        #print(corli,corli1,corli3,corli4,corli5)
        print(samecount)

def readQuestion():
    ws = sys.stdin.readline().strip().split()
    N = int(ws[0])
    ws = sys.stdin.readline().strip().split()
    ls_v = list(map(int, ws))
    return (N, ls_v)

def main():
    print(solve(*readQuestion()))

main()

Submission status: Wrong Answer

Solution code:
import sys

def solve(N, ls_v):
    # Uncomment the following if you want to check the input.
    #print('N =', N)
    #print('ls_v =', ls_v)
    inc=[]
    incc={}
    count=0
    for i in ls_v:
        if i not in incc:
            incc[i] = 1
        else:
            incc[i] += 1
    cl =[i for i in incc.values()]
    cls =[i for i in incc.keys()]
    a = max(cl)
    a = cl.index(a)
    a = cls[a]
    counter = 0
    counter2 = 0
    reco = 0
    counter3 = 0
    ckk = ""
    ck = ""
    rk = ""
    samecount= 0
    samelist=ls_v
    for key,value in incc.items():
        #print(key,value)
        if key == a:
            ckk,counter2 = key,value
        elif key != a and counter < value:
            counter,ck = value,key
        if (key != a and key != ck) and reco <= value:
            rk,reco = key,value
            #print("c")
        else:
            counter3 += 1
    #print("1",reco,rk)
    corli = []
    corli1 = []
    corli2 = []
    corli3 = []
    corli4 = []
    corli5 = []
    i = 10
    for line in ls_v:
        if i%2 == 0:
            corli.append(ckk)
            corli1.append(ck)
            corli2.append(rk)
            corli3.append(ck)
            corli4.append(rk)
            corli5.append(ckk)
        elif i%2 != 0:
            corli.append(ck)
            corli1.append(ckk)
            corli2.append(ck)
            corli3.append(rk)
            corli4.append(ckk)
            corli5.append(rk)
        i += 1
    #print(corli2)
    cc,c1,c2,c3,c4 = 0,0,0,0,0
    c = 0
    for (line1,line2) in zip(ls_v,corli):
        if line1 != line2:
            c += 1
    for (line1,line2) in zip(ls_v,corli1):
        if line1 != line2:
            cc += 1
    for (line1,line2) in zip(ls_v,corli2):
        #print(line1,line2)
        if line1 != line2:
            c1 += 1
    for (line1,line2) in zip(ls_v,corli3):
        if line1 != line2:
            c2 += 1
    for (line1,line2) in zip(ls_v,corli4):
        if line1 != line2:
            c3 += 1
    for (line1,line2) in zip(ls_v,corli5):
        if line1 != line2:
            c4 += 1
    for item in ls_v:
        if item in samelist:
            samecount += 1
    if samecount==N:
        return N//2
    else:
    #print(c,cc,c1,c2,c3,c4)
        if cc == 0:
            return 0
        else:
            return min(c,cc,c1,c2,c3,c4)
        #print(corli,corli1,corli3,corli4,corli5)

def readQuestion():
    ws = sys.stdin.readline().strip().split()
    N = int(ws[0])
    ws = sys.stdin.readline().strip().split()
    ls_v = list(map(int, ws))
    return (N, ls_v)

def main():
    print(solve(*readQuestion()))

main()