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())) 

ve = v[0::2]
vo = v[1::2]

from collections import Counter
from operator import itemgetter

ve = Counter(ve).most_common(2)
vo = Counter(vo).most_common(2)

if ve[0][0] != vo[0][0]:
    ans = n - (ve[0][1] + vo[0][1])
elif ve == vo:
    ans = n//2
else:
    ans = n - (min(ve[0][1],vo[0][1]) + min(ve[1][1],vo[1][1]))

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from itertools import permutations, accumulate, combinations, combinations_with_replacement
from math import sqrt, ceil, floor, factorial
from bisect import bisect_left, bisect_right, insort_left, insort_right
from copy import deepcopy
from operator import itemgetter
from functools import reduce
from fractions import gcd
import sys
def input(): return sys.stdin.readline().rstrip()
def I(): return int(input())
def Is(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def TI(): return tuple(map(int, input().split()))
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def TIR(n): return [TI() for _ in range(n)]
def S(): return input()
def Ss(): return input().split()
def LS(): return list(input())
def SR(n): return [S() for _ in range(n)]
def SsR(n): return [Ss() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
sys.setrecursionlimit(10**6)
MOD = 10**9+7
INF = 10**18
# ----------------------------------------------------------- #

n = I()
V = LI()
odd = [V[i] for i in range(n) if i % 2 != 0]
even = [V[i] for i in range(n) if i % 2 == 0]
A = Counter(odd).most_common(2)
B = Counter(even).most_common(2)
ans = INF
for a in A:
    for b in B:
        if a[0] == b[0]:
            ans = min(ans, n//2)
        else:
            ans = min(ans, n-a[1]-b[1])
print(ans)

Submission status: Wrong Answer

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

odd_li = []
even_li = []
for i in range(n):
    if i%2==0:
        odd_li.append(v_input[i])
    else:
        even_li.append(v_input[i])
odd_count = sorted(Counter(odd_li).items(),key=lambda x:x[1])
even_count = sorted(Counter(even_li).items(),key=lambda x:x[1])

odd_max = odd_count[0][0]
even_max = even_count[0][0]

if odd_max==even_max and len(odd_count)==1:
    ans = odd_count[0][1]

elif odd_max==even_max:
    odd_next = odd_count[1][1]
    even_next = even_count[1][1]
    ans = n//2-odd_count[0][1] + n//2 - max(odd_next,even_next)
else:
    ans = n//2-odd_count[0][1] + n//2 - even_count[0][1]

print(ans)

Submission status: Wrong Answer

Solution code:
import math
import string
import collections
from collections import Counter


def readints():
    return list(map(int, input().split()))


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor


# coordinates
dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]

n = int(input())
v = readints()
cnt = 0
tmp = [0]*(10**5+1)
tmp2 = [0]*(10**5+1)
for i in range(n):
    if i % 2 == 0:
        tmp[v[i]] += 1
    else:
        tmp2[v[i]] += 1
tmp_max = 0
tmp2_max = 0
for i in range(len(tmp)):
    if tmp[tmp_max] < tmp[i]:
        tmp_max = i
for i in range(len(tmp2)):
    if tmp2[tmp2_max] < tmp2[i]:
        tmp2_max = i
if tmp_max != tmp2_max:
    cnt += (n//2)-tmp[tmp_max]
    cnt += (n//2)-tmp2[tmp2_max]
    print(cnt)
    exit()
tmp_max2 = 0
tmp2_max2 = 0
cnt2 = 0
cnt3 = 0
for i in range(len(tmp)):
    if i != tmp_max:
        if tmp[tmp_max] < tmp[i]:
            tmp_max2 = i
for i in range(len(tmp2)):
    if i != tmp2_max:
        if tmp2[tmp2_max] < tmp2[i]:
            tmp2_max2 = i
cnt2 = (n//2)-tmp[tmp_max]+(n//2)-tmp2[tmp2_max2]
cnt3 = (n//2)-tmp2[tmp2_max]+(n//2)-tmp[tmp_max2]
print(min(cnt2, cnt3))
# print(tmp_max)
# print(tmp2_max)
# print(tmp_max2)
# print(tmp2_max2)

Submission status: Wrong Answer

Solution code:
import math
import string
import collections
from collections import Counter


def readints():
    return list(map(int, input().split()))


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor


# coordinates
dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]

n = int(input())
v = readints()
cnt = 0
tmp = [0]*(10**5+10)
tmp2 = [0]*(10**5+10)
for i in range(n):
    if i % 2 == 0:
        tmp[v[i]] += 1
    else:
        tmp2[v[i]] += 1
tmp_max = 0
tmp2_max = 0
for i in range(len(tmp)):
    if tmp[tmp_max] < tmp[i]:
        tmp_max = i
for i in range(len(tmp2)):
    if tmp2[tmp2_max] < tmp2[i]:
        tmp2_max = i
if tmp_max != tmp2_max:
    cnt += (n//2)-tmp[tmp_max]
    cnt += (n//2)-tmp2[tmp2_max]
    print(cnt)
    exit()
tmp_max2 = 0
tmp2_max2 = 0
cnt2 = 0
cnt3 = 0
for i in range(len(tmp)):
    if i != tmp_max:
        if tmp[tmp_max] < tmp[i]:
            tmp_max2 = i
for i in range(len(tmp2)):
    if i != tmp2_max:
        if tmp2[tmp2_max] < tmp2[i]:
            tmp2_max2 = i
cnt2 = (n//2)-tmp[tmp_max]+(n//2)-tmp[tmp2_max2]
cnt3 = (n//2)-tmp2[tmp2_max]+(n//2)-tmp[tmp_max2]
print(min(cnt2, cnt3))
# print(tmp_max)
# print(tmp2_max)
# print(tmp_max2)
# print(tmp2_max2)

Submission status: Wrong Answer

Solution code:
import sys
from collections import Counter
input = sys.stdin.readline


def readstr():
    return input().strip()


def readint():
    return int(input())


def readnums():
    return map(int, input().split())


def readstrs():
    return input().split()


def main():
    n = readint()
    v = list(readnums())
    ve = [x for i, x in enumerate(v) if not i % 2]
    vo = [x for i, x in enumerate(v) if i % 2]
    cve = Counter(ve)
    cvo = Counter(vo)
    if cve.most_common()[0][0] == cvo.most_common()[0][0]:
        flag = 1 if len(ve) - cve.most_common()[0][1] >= len(vo) - cvo.most_common()[0][1] else 0
        if flag:
            if len(cve) == 1:
                print(n // 2)
            else:
                print(len(ve) - cve.most_common()[1][1] + len(vo) - cvo.most_common()[0][1])
        else:
            if len(cvo) == 1:
                print(n // 2)
            else:
                print(len(ve) - cve.most_common()[0][1] + len(vo) - cvo.most_common()[1][1])
    else:
        print(len(ve) - cve.most_common()[0][1] + len(vo) - cvo.most_common()[0][1])


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys
from collections import Counter
input = sys.stdin.readline


def readstr():
    return input().strip()


def readint():
    return int(input())


def readnums():
    return map(int, input().split())


def readstrs():
    return input().split()


def main():
    n = readint()
    v = list(readnums())
    ve = [x for i, x in enumerate(v) if not i % 2]
    vo = [x for i, x in enumerate(v) if i % 2]
    cve = Counter(ve)
    cvo = Counter(vo)
    if cve.most_common()[0][0] == cvo.most_common()[0][0]:
        flag = 1 if len(ve) - cve.most_common()[0][1] >= len(vo) - cvo.most_common()[0][1] else 0
        if flag:
            if len(cve) == 1:
                print(len(ve) + len(vo) - cvo.most_common()[0][1])
            else:
                print(len(ve) - cve.most_common()[1][1] + len(vo) - cvo.most_common()[0][1])
        else:
            if len(cvo) == 1:
                print(len(vo) + len(ve) - cve.most_common()[0][1])
            else:
                print(len(ve) - cve.most_common()[0][1] + len(vo) - cvo.most_common()[1][1])
    else:
        print(len(ve) - cve.most_common()[0][1] + len(vo) - cvo.most_common()[0][1])



if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
from collections import Counter


def main():
    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_count = Counter.most_common(Counter(a))
    # b_count = Counter.most_common(Counter(b))

    half_n = n // 2
    ac = Counter(v[::2]).most_common(2)
    bc = Counter(v[1::2]).most_common(2)

    if ac[0][0] != bc[0][0]:
        print(half_n - ac[0][1] - bc[0][1])
    else:
        if len(bc) == 1 or len(ac) == 1:
            print(half_n // 2)
        else:
            print(half_n - max(ac[0][1] + bc[1][1], ac[1][1] + bc[0][1]))

    # ans = 0

    # half_n = n // 2
    # eq = a_count[0][0] == b_count[0][0]
    # h_ac0 = half_n - a_count[0][1]
    # h_bc0 = half_n - b_count[0][1]

    # if len(a_count) == 1 and len(b_count) == 1:
    #     if eq:
    #         print(half_n)
    #         exit()
    #     else:
    #         print(ans)
    #         exit()

    # if a_count[0][1] > b_count[0][1]:
    #     ans += h_ac0
    #     if eq:
    #         ans += half_n - b_count[1][1]
    #     else:
    #         ans += h_bc0
    # elif a_count[0][1] < b_count[0][1]:
    #     ans += h_bc0
    #     if eq:
    #         ans += half_n - a_count[1][1]
    #     else:
    #         ans += h_ac0
    # else:
    #     if eq:
    #         ans += h_ac0
    #         ans += half_n - b_count[1][1]
    #     else:
    #         ans += h_ac0
    #         ans += h_bc0
    # print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from collections import Counter


def main():
    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_count = Counter.most_common(Counter(a))
    b_count = Counter.most_common(Counter(b))
    ans = 0

    half_n = n // 2
    eq = a_count[0][0] == b_count[0][0]
    h_ac0 = half_n - a_count[0][1]
    h_bc0 = half_n - b_count[0][1]

    if len(a_count) == 1 and len(b_count) == 1:
        if eq:
            print(half_n)
            exit()
        else:
            print(ans)
            exit()

    if a_count[0][1] > b_count[0][1]:
        ans += h_ac0
        if eq:
            ans += half_n - b_count[1][1]
        else:
            ans += h_bc0
    elif a_count[0][1] < b_count[0][1]:
        ans += h_bc0
        if eq:
            ans += half_n - a_count[1][1]
        else:
            ans += h_ac0
    else:
        if eq:
            ans += h_ac0
            ans += half_n - b_count[1][1]
        else:
            ans += h_ac0
            ans += h_bc0
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from collections import Counter


def main():
    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_count = Counter.most_common(Counter(a))
    b_count = Counter.most_common(Counter(b))
    ans = 0

    half_n = n // 2
    eq = a_count[0][0] == b_count[0][0]
    h_ac0 = half_n - a_count[0][1]
    h_bc0 = half_n - b_count[0][1]

    if len(a_count) == 1 and len(b_count) == 1:
        print(half_n)
        exit()

    if a_count[0][1] > b_count[0][1]:
        ans += h_ac0
        if eq:
            ans += half_n - b_count[1][1]
        else:
            ans += h_bc0
    elif a_count[0][1] < b_count[0][1]:
        ans += h_bc0
        if eq:
            ans += half_n - a_count[1][1]
        else:
            ans += h_ac0
    else:
        if eq:
            ans += h_ac0
            ans += half_n - b_count[1][1]
        else:
            ans += h_ac0
            ans += h_bc0
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
n = int(input())
v = list(map(int, input().split()))
count1 = defaultdict(int)
count2 = defaultdict(int)
for i in range(0, n, 2):
    count1[v[i]] += 1
for i in range(1, n, 2):
    count2[v[i]] += 1
ans = 0
for value in count1.values():
    ans += value
for value in count2.values():
    ans += value
ans = ans - max(count1.values()) - max(count2.values())
if len(count1.keys()) == 1 and len(count2.keys()) == 1:
    if v[0] == v[1]:
        print(n//2)
    else:
        print(ans)
else:
    print(ans)

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
v = list(map(int, input().split()))
odd = [k for i, k in enumerate(v) if i % 2 == 1]
even = [k for i, k in enumerate(v) if i % 2 == 0]

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

if odd.most_common()[0][0] == even.most_common()[0][0] and odd.most_common()[0][1] == even.most_common()[0][1] != 1:
    if odd.most_common()[0][1] > even.most_common()[0][1]:
        print(max(even.values()))
    else:
        print(max(odd.values()))
else:
    print(n - max(odd.values()) - max(even.values()))

Submission status: Wrong Answer

Solution code:
n = int(input())
v = list(map(int, input().split()))
freq_odd = [0] * (10 ** 5 + 1)
freq_even = [0] * (10 ** 5 + 1)
for i in range(n // 2):
    freq_odd[v[2 * i]] += 1
    freq_even[v[2 * i + 1]] += 1
# print(freq_odd[:10], freq_even[:10])
freq_even, id_even = zip(*sorted(zip(freq_even, range(10 ** 5 + 1))))
freq_odd, id_odd = zip(*sorted(zip(freq_odd, range(10 ** 5 + 1))))
# print(freq_odd[-2:], freq_even[-2:])
print(id_even[-1], id_odd[-1])
if id_even[-1] != id_odd[-1]:
    print(n - freq_even[-1] - freq_odd[-1])
else:
    print(min(n - freq_even[-2] - freq_odd[-1], n - freq_even[-1] - freq_odd[-2]))

Submission status: Wrong Answer

Solution code:
import sys
from collections import Counter

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


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

    even = []
    odd = []
    for i in range(n):
        odd.append(V[i]) if i % 2 == 0 else even.append(V[i])

    if set(even) == set(odd):
        print(n // 2)
        exit()

    D_even = Counter(even)
    D_odd = Counter(odd)

    even_cnt = []
    for k, v in D_even.items():
        even_cnt.append([k, v])

    odd_cnt = []
    for k, v in D_odd.items():
        odd_cnt.append([k, v])

    even_cnt = sorted(even_cnt, key=lambda x: x[1], reverse=True)
    odd_cnt = sorted(odd_cnt, key=lambda x: x[1], reverse=True)

    if even_cnt[0][0] != odd_cnt[0][0]:
        res = n - even_cnt[0][1] - odd_cnt[0][1]
        print(res)
    else:
        res = f_inf
        if len(even_cnt) > 1:
            res1 = n - even_cnt[1][1] - odd_cnt[0][1]
            res = min(res, res1)

        if len(odd_cnt) > 1:
            res2 = n - even_cnt[0][1] - odd_cnt[1][1]
            res = min(res, res2)

        print(res)


if __name__ == '__main__':
    resolve()

Submission status: Wrong Answer

Solution code:
n = int(input())
v = list(map(int, input().split()))
freq_odd = [0] * (10 ** 5 + 1)
freq_even = [0] * (10 ** 5 + 1)
for i in range(n // 2):
    freq_odd[v[2 * i]] += 1
    freq_even[v[2 * i + 1]] += 1
# print(freq_odd[:10], freq_even[:10])
freq_even, id_even = zip(*sorted(zip(freq_even, range(10 ** 5 + 1))))
freq_odd, id_odd = zip(*sorted(zip(freq_odd, range(10 ** 5 + 1))))
# print(freq_odd[-2:], freq_even[-2:])
if id_even[-1] != id_odd[-1]:
    print(n - freq_even[-1] - freq_odd[-1])
else:
    print(max(n - freq_even[-2] - freq_odd[-1], n - freq_even[-1] - freq_odd[-2]))

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

c1 = Counter(V[::2])
c2 = Counter(V[1::2])

c1 = dict(c1)
c2 = dict(c2)
c1[-1] = 0
c2[-2] = 0


MAX = 0
for i,(k,v) in enumerate(c1.items()):
    if i < 5:
        for j,(k2,v2) in enumerate(c2.items()):
            if j < 5:
                if k != k2:
                    MAX = max(v+v2,MAX)

print(N - MAX)

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
v = list(map(int, input().split()))
odd = [k for i, k in enumerate(v) if i % 2 == 1]
even = [k for i, k in enumerate(v) if i % 2 == 0]

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

if odd.most_common()[0][0] == even.most_common()[0][0] and odd.most_common()[0][1] == even.most_common()[0][1]:
    if odd.most_common()[0][1] > even.most_common()[0][1]:
        print(max(even.values()))
    else:
        print(max(odd.values()))
else:
    print(n - max(odd.values()) - max(even.values()))

Submission status: Wrong Answer

Solution code:
import collections

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

V_even = []
V_odd = []
for i in range(len(V)):
    if i % 2 == 0:
        V_even.append(V[i])
    else:
        V_odd.append(V[i])

V_even_count = sorted([(c, n) for c, n in collections.Counter(V_even).items()], key = lambda x: x[1])
V_odd_count = sorted([(c, n) for c, n in collections.Counter(V_odd).items()], key = lambda x: x[1])

ans = 0
if V_even_count[-1][0] != V_odd_count[-1][0]:
    for c, n in V_even_count[:-1]:
        ans += n
    for c, n in V_odd_count[:-1]:
        ans += n
else:
    if len(V_even_count) == len(V_odd_count) == 1:
        if V_even_count == V_odd_count:
            ans = V_even_count[0][1]
        else:
            ans = 0
    elif len(V_even_count) == 1:
        ans = n // 2 - V_odd_count[-1][1]
    elif len(V_odd_count) == 1:
        ans = n // 2 - V_even_count[-1][1]
    else:
        odd_max_num = V_odd_count[-1][1]
        odd_second_max_num = V_odd_count[-2][1]
        even_max_num = V_even_count[-1][1]
        even_second_max_num = V_even_count[-1][1]
        ans = min((n//2 - odd_second_max_num) + (n//2 - even_max_num), (n//2 - even_second_max_num) + (n//2 - odd_max_num))

print(ans)

Submission status: Wrong Answer

Solution code:
import collections

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

V_even = []
V_odd = []
for i in range(len(V)):
    if i % 2 == 0:
        V_even.append(V[i])
    else:
        V_odd.append(V[i])

V_even_count = sorted([(c, n) for c, n in collections.Counter(V_even).items()], key = lambda x: x[1])
V_odd_count = sorted([(c, n) for c, n in collections.Counter(V_odd).items()], key = lambda x: x[1])

ans = 0
if V_even_count[-1][0] != V_odd_count[-1][0]:
    for c, n in V_even_count[:-1]:
        ans += n
    for c, n in V_odd_count[:-1]:
        ans += n
else:
    if len(V_even_count) == len(V_odd_count) == 1:
        if V_even_count == V_odd_count:
            ans = V_even_count[0][1]
        else:
            ans = 0
    elif len(V_even_count) == 1:
        ans = V_odd_count[0][1]
    elif len(V_odd_count) == 1:
        ans = V_even_count[0][1]
    else:
        odd_max_num = V_odd_count[-1][1]
        odd_second_max_num = V_odd_count[-2][1]
        even_max_num = V_even_count[-1][1]
        even_second_max_num = V_even_count[-1][1]
        ans = min((n//2 - odd_second_max_num) + (n//2 - even_max_num), (n//2 - even_second_max_num) + (n//2 - odd_max_num))

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter


def main():
    n = int(input())
    v = list(map(int, input().split()))
    max_count = Counter.most_common(Counter(v))
    if len(max_count) == 1:
        print(n // 2)
    else:
        a = n // 2 - (max_count[0][1])
        b = n // 2 - (max_count[1][1])
        if a < 0:
            print(b)
        else:
            print(a+b)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from collections import Counter


def main():
    n = int(input())
    v = list(map(int, input().split()))
    max_count = Counter.most_common(Counter(v))
    if len(max_count) == 1:
        print(n // 2)
    else:
        a = abs(n // 2 - (max_count[0][1]))
        b = abs(n // 2 - (max_count[1][1]))
        print(a+b)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

c1 = Counter(V[::2])
c2 = Counter(V[1::2])

c1 = dict(c1)
c2 = dict(c2)
c1[-1] = 0
c2[-2] = 0


MAX = 0
for i,(k,v) in enumerate(c1.items()):
    if i < 2:
        for j,(k2,v2) in enumerate(c2.items()):
            if j < 2:
                if k != k2:
                    MAX = max(v+v2,MAX)

print(N - MAX)

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
v = list(map(int, input().split()))
odd = [k for i, k in enumerate(v) if i % 2 == 1]
even = [k for i, k in enumerate(v) if i % 2 == 0]

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

if odd.most_common()[0][0] == even.most_common()[0][0]:
    if odd.most_common()[0][1] > even.most_common()[0][1]:
        print(max(even.values()))
    else:
        print(max(odd.values()))
else:
    print(n - max(odd.values()) - max(even.values()))

Submission status: Wrong Answer

Solution code:
import sys
from itertools import product
import statistics

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


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

    even = []
    odd = []
    for i in range(n):
        odd.append(V[i]) if i % 2 == 0 else even.append(V[i])

    even_med = statistics.median(even)
    odd_med = statistics.median(odd)

    cnt = 0
    if even_med != odd_med:
        for i in range(n // 2):
            cnt += abs(even[i] - even_med) + abs(odd[i] - odd_med)
        print(int(cnt))
    else:
        res = f_inf
        for de, do in product([0, 1, - 1], repeat=2):
            if de == do:
                continue
            for i in range(n // 2):
                cnt += abs(even[i] - even_med + de) + abs(odd[i] - odd_med + do)
            res = min(res, cnt)

        print(int(res))


if __name__ == '__main__':
    resolve()

Submission status: Wrong Answer

Solution code:
from collections import Counter


def main():
    n = int(input())
    v = list(map(int, input().split()))
    max_count = Counter.most_common(Counter(v))
    if len(max_count) == 1:
        print(n // 2)
    else:
        print(n // 2 - max_count[1][1])


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
from itertools import product

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


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

    even = []
    odd = []
    for i in range(n):
        odd.append(V[i]) if i % 2 == 0 else even.append(V[i])

    odd.sort()
    even.sort()

    even_med = even[len(even) // 2]
    odd_med = V[len(odd) // 2 + 1]

    cnt = 0
    if even_med != odd_med:
        for i in range(n // 2):
            cnt += abs(even[i] - even_med) + abs(odd[i] - odd_med)
        print(cnt)
    else:
        res = f_inf
        for de, do in product([0, 1, - 1], repeat=2):
            if de == do:
                continue
            for i in range(n // 2):
                cnt += abs(even[i] - even_med + de) + abs(odd[i] - odd_med + do)
            res = min(res, cnt)

        print(res)

if __name__ == '__main__':
    resolve()

Submission status: Wrong Answer

Solution code:
from collections import Counter


def main():
    n = int(input())
    v = list(map(int, input().split()))
    max_count = Counter.most_common(Counter(v))
    if len(max_count) == 1:
        print(n // 2)
    else:
        ans = max_count[0][1] - max_count[1][1]
        print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

c1 = Counter(V[::2])
c2 = Counter(V[1::2])
a = c1.most_common()
b = c2.most_common()

if a[0][0] != b[0][0]:
    print(N-a[0][1]-b[0][1])
else:
    if len(a) == 1 and len(b) == 1:
        print(b[0][1])
    elif len(a)== 1 and len(b) > 1:
        print(a[0][0] + b[0][1])
    elif len(b) == 1 and len(a) > 1:
        print(a[0][1] + b[0][0])
    else:
        ans = min(a[0][1]+b[1][1],b[0][1]+a[1][1])
        print(ans)

Submission status: Wrong Answer

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

odd = [v[i] for i in range(n) if i % 2 == 0]
even = [v[i] for i in range(n) if i % 2 == 1]

t = collections.defaultdict(int)
t2 = collections.defaultdict(int)
for x in odd:
    t[x] += 1
for x in even:
    t2[x] += 1

t = list(t.items())
t.sort(reverse=True)

t2 = list(t2.items())
t2.sort(reverse=True)


t.append([0, 0])
t2.append([0, 0])
ans = t[0][1] + t2[0][1]
if t[0][0] == t2[0][0]:
    ans = max(t[0][1] + t2[1][1], t[1][1]+t2[0][1])
print(n - ans)

Submission status: Wrong Answer

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

from collections import Counter
c1 = Counter(V[::2])
c2 = Counter(V[1::2])
m1 = c1.most_common()
m2 = c2.most_common()

if m1[0][0] != m2[0][0]:
    ans = N - m1[0][1] - m2[0][1]
    print(ans)
    exit()

ans = N
if len(m1) > 1 and m1[1][0] != m2[0][0]:
    ans = min(ans, N - m1[1][1] - m2[0][1])
if len(m2) > 1 and m1[0][0] != m2[1][0]:
    ans = min(ans, N - m1[0][1] - m2[1][1])
if len(m1) > 1 and len(m2) > 1 and m1[1][0] != m2[1][0]:
    ans = min(ans, N - m1[1][1] - m2[1][1])
print(ans)

Submission status: Wrong Answer

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

from collections import Counter
c1 = Counter(V[::2])
c2 = Counter(V[1::2])
m1 = c1.most_common()
m2 = c2.most_common()

if m1[0][0] != m2[0][0]:
    ans = N - m1[0][1] - m2[0][1]
    print(ans)
    exit()

ans = N//2
if len(m1) > 1 and m1[1][0] != m2[0][0]:
    ans = min(ans, N - m1[1][1] - m2[0][1])
if len(m2) > 1 and m1[0][0] != m2[1][0]:
    ans = min(ans, N - m1[0][1] - m2[1][1])
if len(m1) > 1 and len(m2) > 1 and m1[1][0] != m2[1][0]:
    ans = min(ans, N - m1[1][1] - m2[1][1])
print(ans)

Submission status: Wrong Answer

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

from collections import Counter
c1 = Counter(V[::2])
c2 = Counter(V[1::2])
m1 = c1.most_common()
m2 = c2.most_common()

if m1[0][0] != m2[0][0]:
    ans = N - m1[0][1] - m2[0][1]
    print(ans)
    exit()

ans = N//2
if len(m1) > 1:
    ans = min(ans, N - m1[1][1] - m2[0][1])
if len(m2) > 1:
    ans = min(ans, N - m1[0][1] - m2[1][1])
if len(m1) > 1 and len(m2) > 1:
    ans = min(ans, N - m1[1][1] - m2[1][1])
print(ans)

Submission status: Wrong Answer

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

from collections import Counter
c1 = Counter(V[::2])
c2 = Counter(V[1::2])
m1 = c1.most_common()
m2 = c2.most_common()

if m1[0][0] != m2[0][0]:
    ans = N - m1[0][1] - m2[0][1]
    print(ans)
    exit()

ans = N//2
if len(m1) > 1:
    ans = min(ans, N - m1[1][1] - m2[0][1])
if len(m2) > 1:
    ans = min(ans, N - m1[0][1] - m2[1][1])
print(ans)

Submission status: Wrong Answer

Solution code:
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


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

    even_sum = 0
    odd_sum = 0
    for i in range(n):
        if i % 2 == 0:
            odd_sum += V[i]
        else:
            even_sum += V[i]

    even_ave = even_sum // (n // 2)
    odd_ave = odd_sum // (n // 2)

    cnt = 0
    for i in range(n):
        if i % 2 == 0:
            cnt += abs(V[i] - odd_ave)
        else:
            cnt += abs(V[i] - even_ave)

    print(cnt)


if __name__ == '__main__':
    resolve()

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
v = list(map(int, input().split()))
l = []
r = []
for i in range(n):
    if i % 2 == 0:
        r.append(v[i])
    else:
        l.append(v[i])
data_l = Counter(l)
data_r = Counter(r)
ans = 0
TF = False
ck = 0
if set(data_r) == set(data_l):
    ans = min(data_l.most_common()[0][1], data_r.most_common()[0][1])
if len(data_r) > 1:
    values_r, counts_r = zip(*data_r.most_common())
    ck = max(counts_r)
    bl = True
    for c in counts_r:
        if ck != c:
            ans += c
            bl = False
    if bl:
       ans += (len(data_r) - 1) * ck
if len(data_l) > 1:
    values_l, counts_l = zip(*data_l.most_common())
    if ck == max(counts_l):
        TF = True
    if TF:
        ck = sorted(counts_l)[-2]
    else:
        ck = max(counts_l)
    bl = True
    for c in counts_l:
        if ck != c:
            ans += c
            bl = False
    if bl:
       ans += (len(data_l) - 1) * ck
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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


o = Counter(l[::2]).most_common()
e = Counter(l[1::2]).most_common()

if o[0][0] == e[0][0]:
    res = 0
    other = 0
    if o[0][1]> e[0][1]:
        res += (N/2 - o[0][1])
        ms = o[0][0]
        for ee in e:
            if ee[0] != ms:
                res += (N/2 - ee[1])
                other = 1
                break

    else:
        res += (N/2 - e[0][1])
        ms = e[0][0]
        for oo in o:
            if oo[0] != ms:
                res += (N/2 - oo[1])
                other = 1
                break

    if not other:
        res = N/2

    print(int(res))
else:
    print(N - o[0][1] - e[0][1])

Submission status: Wrong Answer

Solution code:
from collections import Counter

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


o = Counter(l[::2]).most_common(1)[0]
e = Counter(l[1::2]).most_common(1)[0]

if o[0] == e[0]:
    smaller = max(o[1], e[1])
    print(N - smaller)
else:
    print(N - o[1] - e[1])

Submission status: Wrong Answer

Solution code:
import collections
def main():
    n=int(input())
    v=list(map(int,input().split()))
    ve=[]
    vo=[]
    for i in range(n//2):
        ve.append(v[2*i])
        vo.append(v[2*i+1])
    ce=collections.Counter(ve)
    co=collections.Counter(vo)
    eMax=ce.most_common()[0][1]
    oMax=co.most_common()[0][1]
    if ce.most_common()[0][0]==co.most_common()[0][0]:
        if ce.most_common()[0][1]<=co.most_common()[0][1]:
            if len(ce)==1:
                eMax=0
            else:
                eMax=ce.most_common()[1][1]
        else:
            if len(co)==1:
                oMax=0
            else:
                oMax=co.most_common()[1][1]
    print(n-eMax-oMax)
if __name__=="__main__":
    main()