Problem:


Score : 300 points

Problem Statement

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

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

Exactly two different numbers appear in the sequence.

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

Constraints

2 \leq n \leq 10^5

n is even.

1 \leq v_i \leq 10^5

v_i is an integer.

Input

Input is given from Standard Input in the following format:

n
v_1 v_2 ... v_n

Output

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

Sample Input 1

4
3 1 3 2

Sample Output 1

1

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

Sample Input 2

6
105 119 105 119 105 119

Sample Output 2

0

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

Sample Input 3

4
1 1 1 1

Sample Output 3

2

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



Sample input:
4
3 1 3 2


Sample output:
1

Submission status: Wrong Answer

Solution code:
n = int(input())
v = list(map(int,input().split()))
m1 = []
m2 = []
for i in range(10**5+1):
    m1.append(0)
    m2.append(0)
for i in range(n):
    if i%2 == 0:
        m1[v[i]] += 1
    elif i%2 == 1:
        m2[v[i]] += 1
if v.count(v[0]) == n:
    print(int(n/2))
else:
    print(n-max(m1)-max(m2))

Submission status: Wrong Answer

Solution code:
from collections import Counter


def main():
    n = int(input())
    lines = [int(x) for x in input().split()]
    g = lines[::2]
    k = lines[1::2]
    sub = 0
    j = False
    if len(set(g)) is not 1:
        sub += len(g) - Counter(g).most_common()[0][1]
        j = True
    if len(set(k)) is not 1:
        sub += len(k) - Counter(k).most_common()[0][1]
        j = True
    if len(set(lines)) == 1:
        result = int(n / 2)
    elif len(set(g)) is len(set(k)) is 1:
        result = 0
    elif j is True:
        result = int(sub)
    else:
        result = n - 2
    print(result)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#coding: utf-8
import collections

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

c = 0
even, odd = [],[]

even = V[0::2]
odd = V[1::2]

ce = collections.Counter(even)
co = collections.Counter(odd)
cV = collections.Counter(V)

if len(ce.keys()) == 1 and len(co.keys()) == 1:
    c = 0
else:
    c = len(V) - ce.most_common()[0][1] - co.most_common()[0][1]

print(c)

Submission status: Wrong Answer

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

a = set()
b = set()

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

Submission status: Wrong Answer

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

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


if B1.most_common(2)[0][1]==B2.most_common(2)[0][1] and B1.most_common(2)[0][1]==int(N/2):
    print(int(N/2))
else:
    
    if B1.most_common(1)==B2.most_common(1):
        if B1.most_common(2)[1][1]>=B2.most_common(2)[1][1]:
            ans=N-B1.most_common(2)[1][1]-B2.most_common(2)[0][1]
        else:
            ans=N-B2.most_common(2)[1][1]-B1.most_common(2)[0][1]
    elif B1.most_common(2)[0][0]==B2.most_common(2)[0][0]:
        if B1.most_common(2)[0][1]>=B2.most_common(2)[0][1]:
            ans=N-B1.most_common(2)[0][1]-B2.most_common(2)[1][1]
        else:
            ans=N-B2.most_common(2)[0][1]-B1.most_common(2)[1][1]
    else:
        ans=N-B1.most_common(2)[0][1]-B2.most_common(2)[0][1]
    print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
v = list(map(int, input().split()))
li = len(set(v))
if li == 1:
    print(2)
elif li == 2:
    print(0)
else:
    print(1)

Submission status: Wrong Answer

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

o=[]
e=[]


for i in range(n):
    if i%2==1:
        o.append(a[i])
    else:
        e.append(a[i])

oc = Counter(o)
ec = Counter(e)

ok=[]
ek=[]
ol=[]
el=[]
for word, cnt in oc.most_common():
    ok.append(cnt)
    ol.append(word)
for word, cnt in ec.most_common():
    ek.append(cnt)
    el.append(word)

if len(ok)==1:
    ok.append(2//n)
if len(ek)==1:
    ek.append(2//n)
if el[0]!=ol[0]:
    print(n-ok[0]-ek[0])
else:
    m=max(ok[0],ek[0])
    if m==ok[0]:
        print(n-m-ek[1])
    else:
        print(n-m-ok[1])

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import collections

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

odd = V[::2]
even = V[1:N:2]

odd_d = collections.Counter(odd)
even_d = collections.Counter(even)

if odd == even and len(odd_d) == 1 and len(even_d) == 1:
    ans = len(odd)

elif len(odd_d) == 1 and len(even_d) == 1:
    ans = 0

else:
    for i,n in enumerate(odd_d.keys()):
        if i == 0:
            odd_ind = n
        elif i == 1:
            odd_ind2 = n
        else:
            break
    for i, n in enumerate(even_d.keys()):
        if i == 0:
            even_ind = n
        elif i == 1:
            even_ind2 = n
        else:
            break

    if odd_ind != even_ind:
        ans = (N//2 - odd_d[odd_ind]) + (N//2 - even_d[even_ind])
    else:
        if odd_d[odd_ind] >= even_d[even_ind]:
            ans = (N//2 - odd_d[odd_ind]) + (N//2 - even_d[even_ind2])
        else:
            ans = (N//2 - odd_d[odd_ind2]) + (N//2 - even_d[even_ind])
print(ans)

Submission status: Wrong Answer

Solution code:
import collections

n = int(raw_input())
v = map(int, raw_input().split())

even = [vi for i,vi in enumerate(v) if i % 2 == 0]
odd  = [vi for i,vi in enumerate(v) if i % 2 == 1]

evenc = collections.Counter(even)
oddc = collections.Counter(odd)

evenc_most_common = evenc.most_common(len(set(even)))
oddc_most_common = oddc.most_common(len(set(odd)))

if evenc_most_common[0][0] != oddc_most_common[0][0]:
    res = len(set(even)) + len(set(odd)) - 2
    print(res)
else:
    if evenc_most_common[0][1] >= oddc_most_common[0][1]:
        a = len(even) - evenc_most_common[0][1]
        b = len(odd)
        if len(oddc_most_common) > 1:
            b = len(odd) - oddc_most_common[1][1]
        print(a+b)
    elif evenc_most_common[0][1] < oddc_most_common[0][1]:
        a = len(odd) - oddc_most_common()[0][1]
        b = len(even)
        if len(evenc_most_common) > 1:
            b = len(even) - evenc_most_common[1][1]
        print(a+b)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
cnt = 0
if len(set(a)) == 1:
    print(n//2)
    exit()
for i in range(2,n-1):
    if a[i] != a[0] or a[i] != a[1] :
        cnt += 1
print(cnt)

Submission status: Wrong Answer

Solution code:
n = int(input())
v = [int(i) for i in input().split()]
v1 = v[::2]
v2 = v[1::2]
v1_a = list(set(v1))
v2_a = list(set(v2))
v_a = list(set(v))

v1_1st = 0
v1_2nd = 0
v2_1st = 0
v2_2nd = 0

for i in range(len(v1_a)):
    if i == 0:
        v1_1st = v1_a[i]
        continue
    if i == 1:
        if v1.count(v1_1st) < v1.count(v1_a[i]):
            v1_2nd = v1_1st
            v1_1st = v1_a[i]
        else:
            v1_2nd = v1_a[i]
        continue
    if v1.count(v1_1st) < v1.count(v1_a[i]):
        v1_2nd = v1_1st
        v1_1st = v1_a[i]
    else:
        if v1.count(v1_2nd) < v1.count(v1_a[i]):
            v1_2nd = v1_a[i]

for i in range(len(v2_a)):
    if i == 0:
        v2_1st = v2_a[i]
        continue
    if i == 1:
        if v2.count(v2_1st) < v2.count(v2_a[i]):
            v2_2nd = v2_1st
            v2_1st = v2_a[i]
        else:
            v2_2nd = v2_a[i]
        continue
    if v2.count(v2_1st) < v2.count(v2_a[i]):
        v2_2nd = v2_1st
        v2_1st = v2_a[i]
    else:
        if v2.count(v2_2nd) < v1.count(v2_a[i]):
            v2_2nd = v2_a[i]

if v1_1st == v2_1st:
    print(min(v1.count(v1_1st) + len(v2) - v2.count(v2_1st) ,v2.count(v2_1st) + len(v1) - v1.count(v1_1st)))
else:
    if v1_2nd == 0 :
        if v2_2nd == 0:
            print(0)
        else:
            print(len(v2) - v2.count(v2_1st))
    else:
        if v2_2nd == 0:
            print(len(v1) - v1.count(v1_1st))
        else:
            print(len(v1) - v1.count(v1_1st) + len(v2) - v2.count(v2_1st))

Submission status: Wrong Answer

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

kisu = [str(v) for i,v in enumerate(V) if i % 2 == 1]
gusu = [str(v) for i,v in enumerate(V) if i % 2 == 0]

from collections import Counter

kisu_c = Counter(kisu).most_common()
gusu_c = Counter(gusu).most_common()

ans = 0


if len(kisu_c) == 1 and len(gusu_c) == 1:
    if kisu_c[0][0] == gusu_c[0][0]:
        print(kisu_c[0][1])
    else:
        print(0)
    exit()
elif len(kisu_c) == 1:
    gusu_c.pop(1)

    for i in gusu_c:
        ans += i[1]
    print(ans)
    exit()
elif len(gusu_c) == 1:
    kisu_c.pop(1)

    for i in kisu_c:
        ans += i[1]
    print(ans)
    exit()



if kisu_c[0][0] == gusu_c[0][0]:
    if kisu_c[0][1] < gusu_c[0][1]:
        gusu_c.pop(0)
        kisu_c.pop(1)
    elif kisu_c[0][1] > gusu_c[0][1]:
        gusu_c.pop(1)
        kisu_c.pop(0)
    else:
        if kisu_c[1][1] > gusu_c[1][1]:
            kisu_c.pop(1)
            gusu_c.pop(0)
        else:
            kisu_c.pop(0)
            gusu_c.pop(1)

else:
    kisu_c.pop(0)
    gusu_c.pop(0)


for i in kisu_c:
    ans += i[1]
for i in gusu_c:
    ans += i[1]

print(ans)

Submission status: Wrong Answer

Solution code:

import collections

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

evel = collections.Counter()
odd = collections.Counter()
for index, v in enumerate(V):
    if index % 2 == 0:
        evel[v] += 1
    else:
        odd[v] += 1

if evel == odd:
    print(int(n / 2))
else:
    el = evel.most_common()
    ol = odd.most_common()
    max_val = 0
    for index_e, num_e in el:
        for index_o, num_o in ol:
            if index_e != index_o:
                max_val = max(max_val, num_e + num_o)
    ans = n - max_val
    print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
v = list(map(int,input().split()))
m1 = []
m2 = []
for i in range(10**5+1):
    m1.append(0)
    m2.append(0)
for i in range(n):
    if i%2 == 0:
        m1[v[i]] += 1
    elif i%2 == 1:
        m2[v[i]] += 1
print(n-max(m1)-max(m2))

Submission status: Wrong Answer

Solution code:

import collections

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

evel = collections.Counter()
odd = collections.Counter()
for index, v in enumerate(V):
    if index % 2 == 0:
        evel[v] += 1
    else:
        odd[v] += 1
print(evel, odd)
if evel == odd:
    print(int(n / 2))
else:
    el = evel.most_common()
    ol = odd.most_common()
    max_val = 0
    for index_e, num_e in el:
        for index_o, num_o in ol:
            if index_e != index_o:
                max_val = max(max_val, num_e + num_o)
    ans = n - max_val
    print(ans)

Submission status: Wrong Answer

Solution code:
import collections

n = int(input())
vs = [int(i) for i in input().split()]
evens = []
odds = []
for i,num in enumerate(vs):
    if i % 2 == 0:
        evens.append(num)
    elif i % 2 == 1:
        odds.append(num)

def plana():
    if (len(set(vs)) == 2) and (len(set(evens)) == 1) and (len(set(odds)) == 1):
        return 0
    elif (len(set(vs)) == 1):
        return len(evens)
    ec = collections.Counter(evens)
    oc = collections.Counter(odds)

    count = 0
    count += (len(evens) - ec.most_common()[0][1])
    count += (len(odds) - oc.most_common()[0][1])
    return count

# if len(set(vs)) == 1:
#     print(int(len(vs)/2))
# elif (len(set(evens)) == 1) and (len(set(odds)) == 1):
#     print(0)
# else:
print(int(plana()))

Submission status: Wrong Answer

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

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


if B1.most_common(2)[0][1]==B2.most_common(2)[0][1] and B1.most_common(2)[0][1]==int(N/2):
    print(int(N/2))
else:
    
    if B1.most_common(1)==B2.most_common(1):
        if B1.most_common(2)[1][1]>=B2.most_common(2)[1][1]:
            ans=N-B1.most_common(2)[1][1]-B2.most_common(2)[0][1]
        else:
            ans=N-B2.most_common(2)[1][1]-B1.most_common(2)[0][1]
    elif B1.most_common(2)[0][0]==B2.most_common(2)[0][0]:
        if B1.most_common(2)[0][1]>=B1.most_common(2)[0][1]:
            ans=N-B1.most_common(2)[0][1]-B2.most_common(2)[1][1]
        else:
            ans=N-B2.most_common(2)[0][1]-B1.most_common(2)[1][1]
    else:
        ans=N-B1.most_common(2)[0][1]-B2.most_common(2)[0][1]
    print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-


def main():
    from collections import Counter

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

    if len(set(v)) == 1:
        print(half)
        exit()
    else:
        ans1 = 0
        ans2 = 0
        v1 = v[0]
        v2 = v[1]
        c = Counter(v).most_common(2)
        c1 = c[0][0]
        c2 = c[1][0]

        for i in range(2, n):
            if i % 2 == 0:
                if v[i] != v1:
                    ans1 += 1
            else:
                if v[i] != v2:
                    ans1 += 1

        for i in range(2, n):
            if i % 2 == 0:
                if v[i] != c1:
                    ans2 += 1
            else:
                if v[i] != c2:
                    ans2 += 1

        print(min(ans1, ans2))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

a = set()
b = set()

for i in range(n):
    if i % 2 == 1:
        a.add(v[i])
for j in range(n):
    if j % 2 == 0:
        b.add(v[j])

if (len(a) == 1) and (len(b) == 1) and (a == b) and (n != 2):
    print(n//2)
else:
    print(len(a) + len(b) -2)
print(a)
print(b)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/python3
# -*- coding: utf-8 -*-

n = int(input())
v = [int(i) for i in input().split()]
INF = 10 ** 6

vd = {}
for vi in v:
    if vi in vd:
        vd[vi] += 1
    else:
        vd[vi] = 1

vl = sorted(vd.values())
if len(vl) == 1:
    print(n // 2)
else:
    m = INF
    for i, j in zip(vl, vl[1:]):
        di = n // 2 - i
        dj = n // 2 - j
        if dj < 0 <= di:
            k = min(di, -dj) + abs(di + dj)
        else:
            k = abs(di + dj)
        if m > k:
            m = k

    print(m)

Submission status: Wrong Answer

Solution code:
n = int(input())
v = list(map(int,input().split()))
m1 = []
m2 = []
for i in range(10**5+1):
    m1.append(0)
    m2.append(0)
for i in range(n):
    if i%2 == 0:
        m1[i] += 1
    elif i%2 == 1:
        m2[i] += 1
print(n-max(m1)-max(m2))

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
v = list(map(int, input().split()))
v_odd = v[::2]
v_even = v[1::2]
v_odd = collections.Counter(v_odd)
v_even = collections.Counter(v_even)
v_odd = v_odd.most_common()
v_even = v_even.most_common()
if v_odd[0][0] == v_even[0][0]:
  if len(v_odd) == len(v_even) == 1:
    print(int(n/2))
  elif v_odd[0][1] >= v_even[0][1]:
    print(n - v_odd[0][1] -v_even[1][1])
  else:
    print(n - v_odd[1][1] -v_even[0][1])
else:
  print(n - v_odd[0][1] -v_even[0][1])

Submission status: Wrong Answer

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

min_num = 0

even = {}
odd = {}

for i, v in enumerate(v_list):
    if i % 2 == 0:
        if v in even:
            even[v] += 1
        else:
            even[v] = 1
    else:
        if v in odd:
            odd[v] += 1
        else:
            odd[v] = 1

even_max = sorted(even.items(), key=lambda x: -x[1])
odd_max = sorted(odd.items(), key=lambda x: -x[1])

even_num = even_max[0][0]
odd_num = odd_max[0][0]


if odd_num == even_num:
    if len(odd_max) == 1 and len(even_max) == 1:
        odd_num = 10 ** 5 + 1
    elif len(odd_max) == 1:
        even_num = even_max[1][0]
    elif len(even_max) == 1:
        odd_num = odd_max[1][0]
    else:
        second_e = even_max[1][1]
        second_d = even_max[1][1]
        if second_e >= second_d:
            even_num = even_max[1][0]
        else:
            odd_num = odd_max[1][0]

for i, v in enumerate(v_list):
    if i % 2 == 0:
        if v != even_num:
            min_num += 1
    else:
        if v != odd_num:
            min_num += 1
print(min_num)

Submission status: Wrong Answer

Solution code:
n = int(input())

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

v1 = {}

v2 = {}

for i in range(n//2):
    if  v[2 *i +1] in v1.keys():
        v1[v[2 * i +1]] += 1
    else:
        v1[v[2 * i + 1]] = 1

    if v[2 * i] in v2.keys():
        v2[v[2 * i]] += 1
    else:
        v2[v[2 * i]] = 1


v1 = sorted(v1.items(),key=lambda x: - x[0])
v2 = sorted(v2.items(),key=lambda x: - x[0])
v1.reverse()
v2.reverse()
v1.append((None,0))
v2.append((None,0))
# print(v1)
ans = 0
if v1[0][0] == v2[0][0]:
    ans = max(v1[0][1]+v2[1][1] , v1[1][1] + v2[0][1])
else:
    ans = v1[0][1] + v2[0][1]

print(n - ans)

Submission status: Wrong Answer

Solution code:
import collections

n = input()
nums = list(map(int, input().split()))
odd = nums[0::2]
even = nums[1::2]
odd_c = collections.Counter(odd)
even_c = collections.Counter(even)

if odd_c.most_common(1)[0][0] == even_c.most_common(1)[0][0]:
    odd_next_most = 0
    even_next_most = 0
    if len(odd_c) >= 2:
        odd_next_most = odd_c.most_common(2)[1][1]
    if len(even_c) >= 2:
        even_next_most = even_c.most_common(2)[1][1]
    if odd_next_most > even_next_most:
        print(len(odd) - odd_next_most)
    else:
        print(len(even) - even_next_most)
else:
    odd_change = len(odd) - odd_c.most_common(1)[0][1]
    even_change = len(even) - even_c.most_common(1)[0][1]
    if odd_change + even_change == 0:
        if odd_c.most_common(1)[0][0] == even_c.most_common(1)[0][0]:
            print(len(even))
            exit()
    print(odd_change + even_change)

Submission status: Wrong Answer

Solution code:
import collections
n=input()
N=list(map(int,input().split(" ")))
list_odd=N[::2]
list_even=N[1::2]
c_odd = collections.Counter(list_odd)
c_even = collections.Counter(list_even)
most_odd=c_odd.most_common()[0][1]
most_even=c_even.most_common()[0][1]
if(c_odd.most_common()[0][0]==c_even.most_common()[0][0]):
    print(most_odd)
else:
    print(len(list_even)+len(list_odd)-most_even-most_odd)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
v = list(map(int,input().split()))
o = v[0::2]
e = v[1::2]
o_mode = Counter(o).most_common(1)
e_mode = Counter(e).most_common(1)
if o == e:
  print(int(n/2))
else:
  print(n-o_mode[0][1]-e_mode[0][1])

Submission status: Wrong Answer

Solution code:
n = int(input())

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

v1 = {}

v2 = {}

for i in range(n//2):
    if  v[2 *i +1] in v1.keys():
        v1[v[2 * i +1]] += 1
    else:
        v1[v[2 * i - 1]] = 1

    if v[2 * i] in v2.keys():
        v2[v[2 * i]] += 1
    else:
        v2[v[2 * i]] = 1


v1 = sorted(v1.items(),key=lambda x: - x[0])
v2 = sorted(v2.items(),key=lambda x: - x[0])
v1.reverse()
v2.reverse()
v1.append((None,0))
v2.append((None,0))
# print(v1)
ans = 0
if v1[0][0] == v2[0][0]:
    ans = max(v1[0][1]+v2[1][1] , v1[1][1] + v2[0][1])
else:
    ans = v1[0][1] + v2[0][1]

print(n - ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
N=list(map(int,input().split()))
even=[]
odd=[]
for i in range(len(N)):
    if i%2==0:
        even.append(N[i])
    if i%2==1:
        odd.append(N[i])
import collections
c = collections.Counter(even)
x=c.most_common()[0][0]
o=even.count(x)
d= collections.Counter(odd)
y=d.most_common()[0][0]
p=odd.count(y)
s=len(even)-even.count(x)
t=len(odd)-odd.count(y)
if x!=y and o==len(even) and p==len(odd):
    print(0)
elif x!=y:
    print(s+t)
elif x==y and o==len(even) and p==len(odd):
    print(n/2)
elif x==y and (o!=len(even) or p!=len(odd)):
    if o>p:
        y=d.most_common()[1][0]
        s=len(even)-even.count(x)
        t=len(odd)-odd.count(y)
        print(s+t)
    else:
        x=d.most_common()[1][0]
        s=len(even)-even.count(x)
        t=len(odd)-odd.count(y)
        print(s+t)

Submission status: Wrong Answer

Solution code:
import collections

n=int(input())
v=list(input().split())
k=v[0::2]
g=v[1::2]

c1 = collections.Counter(k)
c2 = collections.Counter(g)

res1 = n/2 - c1.most_common()[0][1]
res2 = n/2 - c2.most_common()[0][1]

if c1.most_common()[0][0] == c2.most_common()[0][0]:
    if(c1.most_common()[0][1] > c2.most_common()[0][1]):
        res2 = n/2 - c2.most_common()[1][1]
    elif(c1.most_common()[0][1] < c2.most_common()[0][1]):
        res1 = n/2 - c1.most_common()[1][1]
    else:
        if(res1 > 0):
            res1 = n/2 - c1.most_common()[1][1]
        else:
            res1 = n/2
            res2 = 0
            
print(int(res1+res2))

Submission status: Wrong Answer

Solution code:
from collections import Counter
from collections import deque

if __name__ == '__main__':
    n = int(input())
    vs0 = []
    vs1 = []
    for i,v in enumerate(map(int, input().split())):
        if i % 2 == 0:
            vs0.append(v)
        else:
            vs1.append(v)
    vs0 = deque(sorted(Counter(vs0).items(), key=lambda t: t[0]))
    vs1 = deque(sorted(Counter(vs1).items(), key=lambda t: t[0]))
    t0 = vs0.pop()
    t1 = vs1.pop()
    if t0[0] != t1[0]:
        vs0 = (t[1] for t in vs0)
        vs1 = (t[1] for t in vs1)
        print(sum(vs0) + sum(vs1))
    else:
        if len(vs1) == 0:
            if len(vs0) == 0:
                print(t1[1])
            else:
                vs0 = (t[1] for t in vs0)
                print(sum(vs0))
        elif len(vs0) == 0:
            vs1 = (t[1] for t in vs1)
            print(sum(vs1))
        else:
            t00 = vs0.pop()
            t11 = vs1.pop()
            a = t00[1] + t1[1]
            b = t11[1] + t0[1]
            vs0 = (t[1] for t in vs0)
            vs1 = (t[1] for t in vs1)
            print(sum(vs0) + sum(vs1) + (a if a < b else b))

Submission status: Wrong Answer

Solution code:
a = int(input())

b = list(map(int,input().split()))
d = max(b)
c = [0 for i in range(pow(10,5))]
cc = [0 for i in range(pow(10,5))]
for i in range(a):
    if i % 2 == 0:
        c[b[i]-1] += 1
    else:
        cc[b[i]-1] += 1

one = 0
onee = 0
two = 0
twoo = 0
p = 0
pp = 0
for i in range(d):
    if one <= c[i]:
        onee = one
        one = c[i]
        p += 1
    if two <= cc[i]:
        twoo = two
        two = cc[i]
        p += 1
    if p == 2:
        pp = 1
    else:
        pp = 0
    p = 0

t = max(one+twoo,onee+two)

if pp == 0:
    print(a-one-two)
else:
    print(a-t)

Submission status: Wrong Answer

Solution code:
import sys
a=int(input())
b=input()
c=b.split(" ")
map(int,c)
c.sort()
d=c[:a//2]
e=c[a//2:]
min1=0
min2=0

temp1=len(d)
temp2=len(e)
temp3=len(set(d))
temp4=len(set(e))


if temp3==1 and set(d)!=set(e):
    min1=0
elif temp1==temp3:
    min1=temp1-1
elif temp3==1 and set(d)==set(e):
    print(temp1)
    sys.exit()
else:
    min1=temp3-1


if temp4==1 and set(d)!=set(e):
    min2=0
elif temp2==temp4:
    min2=temp2-1
else:
    min2=temp4-1

print(min1+min2)

Submission status: Wrong Answer

Solution code:
n = int(input())

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

v1 = {}

v2 = {}

for i in range(n//2):
    if  v[2 *i +1] in v1.keys():
        v1[v[2 * i +1]] += 1
    else:
        v1[v[2 * i - 1]] = 1

    if v[2 * i] in v2.keys():
        v2[v[2 * i]] += 1
    else:
        v2[v[2 * i]] = 1


v1 = sorted(v1.items(),key=lambda x: - x[0])
v2 = sorted(v2.items(),key=lambda x: - x[0])
v1.reverse()
v2.reverse()
v1.append((None,0))
v2.append((None,0))
print(v1)
ans = 0
if v1[0][0] == v2[0][0]:
    ans = max(v1[0][1]+v2[1][1] , v1[1][1] + v2[0][1])
else:
    ans = v1[0][1] + v2[0][1]

print(n - ans)

Submission status: Wrong Answer

Solution code:
import collections
 
def main():
    n = input()
    a = map(int, raw_input().split())
    odd = [a[2 * i] for i in range(n/2)]
    even = [a[2*i + 1] for i in range(n/2)]
    codd = collections.Counter(odd)
    ceven = collections.Counter(even)
    coddmostitem = codd.most_common()[0][0]
    coddmosttimes = codd.most_common()[0][1]
    cevenmostitem = ceven.most_common()[0][0]
    cevenmosttimes = ceven.most_common()[0][1]
    if coddmostitem == cevenmostitem:
        if coddmosttimes >= cevenmosttimes:
            if len(ceven) == 1:
                cevennoreplace = 0
            else:
                cevennoreplace = ceven.most_common()[1][1]
            coddnoreplace = codd.most_common()[0][1]
        if coddmosttimes < cevenmosttimes:
            if len(codd) == 1:
                coddnoreplace = 0
            else:
                coddnoreplace = codd.most_common()[1][1]
            cevennoreplace = ceven.most_common()[0][1]
    else:
        coddnoreplace = codd.most_common()[0][1]
        cevennoreplace = ceven.most_common()[0][1]
    coddreplace = n/2 - coddnoreplace
    cevenreplace = n/2 - cevennoreplace
    print(coddreplace+cevenreplace)
 
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
v = list(map(int, input().split()))
v_odd = v[::2]
v_even = v[1::2]
v_odd = collections.Counter(v_odd)
v_even = collections.Counter(v_even)
v_odd = v_odd.most_common()
v_even = v_even.most_common()
if v_odd[0][0] == v_even[0][0]:
  if len(v_odd) == 1:
    print(n/2)
  elif v_odd[0][1] >= v_even[0][1]:
    print(n - v_odd[0][1] -v_even[1][1])
  else:
    print(n - v_odd[1][1] -v_even[0][1])
else:
  print(n - v_odd[0][1] -v_even[0][1])

Submission status: Wrong Answer

Solution code:
from collections import Counter


def main():
    n = int(input())
    lines = [int(x) for x in input().split()]
    g = lines[::2]
    k = lines[1::2]
    sub = 0
    j = False
    if len(set(g)) is not 1:
        sub += n / 2 - Counter(g).most_common()[0][1]
        j = True
    if len(set(k)) is not 1:
        sub += n / 2 - Counter(k).most_common()[0][1]
        j = True
    if len(set(lines)) == 1:
        result = int(n / 2)
    elif len(set(g)) is len(set(k)) is 1:
        result = 0
    elif j is True:
        result = int(sub)
    else:
        result = n - 2
    print(result)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

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


if B1.most_common(2)[0][1]==B2.most_common(2)[0][1] and B1.most_common(2)[0][1]==int(N/2):
    print(int(N/2))
else:
    
    if B1.most_common(1)==B2.most_common(1):
        if B1.most_common(2)[1][1]>=B2.most_common(2)[1][1]:
            ans=N-B1.most_common(2)[1][1]-B2.most_common(2)[0][1]
        else:
            ans=N-B2.most_common(2)[1][1]+B1.most_common(2)[0][1]
    elif B1.most_common(2)[0][0]==B2.most_common(2)[0][0]:
        if B1.most_common(2)[0][1]>=B1.most_common(2)[0][1]:
            ans=N-B1.most_common(2)[0][1]-B2.most_common(2)[1][1]
        else:
            ans=N-B2.most_common(2)[0][1]-B1.most_common(2)[1][1]
    else:
        ans=N-B1.most_common(2)[0][1]-B2.most_common(2)[0][1]
    print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import collections
n = int(input())
half_n = n // 2
v = input().split()
v1 = []
v2 = []
ans = 0

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

for i,j in enumerate(v):
    if i % 2 == 0:
        v1.append(j)
    else:
        v2.append(j)

i = collections.Counter(v1)
j = collections.Counter(v2)
if i.most_common()[0][0] == j.most_common()[0][0]:
    if i.most_common()[0][1] >= j.most_common()[0][1]:
        ans += half_n - i.most_common()[0][1]
        ans += half_n - j.most_common()[1][1]
    else:
        ans += half_n - j.most_common()[0][1]
        ans += half_n - i.most_common()[1][1]
else:
    ans += half_n - i.most_common()[0][1]
    ans += half_n - j.most_common()[0][1]

print(ans)

Submission status: Wrong Answer

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

d = defaultdict(int)
rd = defaultdict(int)
d[0] = 0
rd[0] = 0

ll = (n) // 2
rr = (n) // 2

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

d = list(reversed(sorted(d.items(), key=lambda x: x[1])))
rd= list(reversed(sorted(rd.items(), key=lambda x: x[1])))

i, j = 0, 0

while d[i][0] == rd[j][0] and i < len(d) and j < len(rd):
    if (ll - d[i][1] < rr - rd[j][1]):
        j += 1
    else:
        i += 1


print(ll - d[i][1] + rr - rd[j][1])

Submission status: Wrong Answer

Solution code:
#!/usr/bin/python3
# -*- coding: utf-8 -*-

n = int(input())
v = [int(i) for i in input().split()]
INF = 10 ** 6

vd = {}
for vi in v:
    if vi in vd:
        vd[vi] += 1
    else:
        vd[vi] = 1

vl = sorted(vd.values())
if len(vl) == 1:
    print(n // 2)
else:
    m = INF
    for i, j in zip(vl, vl[1:]):
        di = n // 2 - i
        dj = n // 2 - j
        if dj < 0 <= di:
            k = abs(dj) + abs(di + dj)
        else:
            k = abs(di + dj)
        if m > k:
            m = k

    print(m)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
vn = list(map(int,input().split()))
v0 = [0]*(n//2)
v1 = [0]*(n//2)
for i in range(n//2):
  v0[i] = vn[i*2+0]
  v1[i] = vn[i*2+1]
v0 = Counter(v0)
v1 = Counter(v1)
v0c0 = v0.most_common()[0]
v1c0 = v1.most_common()[0]
v0c1 = [0,0] if (len(v0.most_common()) == 1) else v0.most_common()[1]
v1c1 = [0,0] if (len(v1.most_common()) == 1) else v1.most_common()[1]

if v0c0[0] != v1c0[0]:
  print(n-v0c0[1]-v1c0[1])
elif v0c0[1] < v1c0[1]:
  print(n-v0c1[1]-v1c0[1])
elif v0c0[1] > v1c0[1]:
  print(n-v0c0[1]-v1c1[1])
elif v0c1[1] < v1c1[1]:
  print(n-v0c1[1]-v1c0[1])
elif v0c1[1] > v1c1[1]:
  print(n-v0c0[1]-v1c1[1])
else:
  print(n-v0c0[1]-v1c1[1])

Submission status: Wrong Answer

Solution code:
a=int(input())
b=input()
c=b.split(" ")
map(int,c)
c.sort()
d=c[:a//2]
e=c[a//2:]
min1=0
min2=0

temp1=len(d)
temp2=len(e)
temp3=len(set(d))
temp4=len(set(e))


if temp3==1 and set(d)!=set(e):
    min1=0
elif temp1==temp3:
    min1=temp1-1
elif temp3==1 and set(d)==set(e):
    min1=temp1/2
else:
    min1=temp3-1


if temp4==1 and set(d)!=set(e):
    min2=0
elif temp2==temp4:
    min2=temp2-1
elif temp4==1 and set(d)==set(e):
    min2=temp2/2
else:
    min2=temp4-1

print("%.0d" % (min1+min2))

Submission status: Wrong Answer

Solution code:
n = int(input())
nums = list(map(int, input().split()))
a = nums[0]
b = 0
ct = 0
for i in range(0, len(nums)):
    if nums[i] % 2 != 0:
        if a != nums[i]:
            b = nums[i]

for i in range(0, len(nums)):
    if i % 2 == 0:
        if nums[i] != a:
            ct += 1
    else:
        if nums[i] != b:
            ct += 1

print(ct)