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())
l = input().split()
v = [sorted([int(l[2 * i]) for i in range(n // 2)]), \
sorted([int(l[2 * i + 1]) for i in range(n // 2)])]

cnt = [1, 1]
m = [[1, 0], [1, 0]]
num = [0, 0]
for i in range(n // 2 - 1):
    for j in range(2):
        if (v[j][i] == v[j][i + 1]):
            cnt[j] += 1
        else:
            if (m[j][0] < cnt[j]):
                m[j][1] = m[j][0]
                m[j][0] = cnt[j]
                num[j] = v[j][i]
            cnt[j] = 1

for j in range(2):
    if (m[j][0] < cnt[j]):
        m[j][1] = m[j][0]
        m[j][0] = cnt[j]
        num[j] = v[j][i]

out = n - (m[0][0] + m[1][0])
if (num[0] == num[1]):
    out += min(m[0][0] - m[0][1], m[1][0] - m[1][1])
print(out)

Submission status: Wrong Answer

Solution code:
from collections import OrderedDict
n = int(input())

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

odd = OrderedDict()
even = OrderedDict()

for i in range(len(v)):
    if (i % 2 == 1):
        odd.setdefault(v[i],0)
        odd[v[i]] += 1
    else:
        even.setdefault(v[i],0)
        even[v[i]] += 1


oddl = OrderedDict(sorted(odd.items(),key = lambda x: x[1],reverse=True))
evenl = OrderedDict(sorted(even.items(),key = lambda x: x[1],reverse=True))


ok = [x for x in oddl.keys()]
ov  = [x for x in oddl.values()]
ek = [x for x in evenl.keys()]
ev = [x for x in evenl.values()]


if ok[0] != ek[0]:
    if(len(ev) == 1): ev.append(0)
    if(len(ov) == 1):ov.append(0)
    res1 = n - ov[0] - ev[1]
    res2 = n - ov[1] - ev[0]
    if res1 >= res2 :
        res = res2
    else:
        res = res1
else:
    res = n-ov[0]-ev[0]

print(res)

Submission status: Wrong Answer

Solution code:
from collections import OrderedDict
n = int(input())

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

odd = OrderedDict()
even = OrderedDict()

for i in range(len(v)):
    if (i % 2 == 1):
        odd.setdefault(v[i],0)
        odd[v[i]] += 1
    else:
        even.setdefault(v[i],0)
        even[v[i]] += 1


oddl = OrderedDict(sorted(odd.items(),key = lambda x: x[1],reverse=True))
evenl = OrderedDict(sorted(even.items(),key = lambda x: x[1],reverse=True))


ok = [x for x in oddl.keys()]
ov  = [x for x in oddl.values()]
ek = [x for x in evenl.keys()]
ev = [x for x in evenl.values()]


if ok[0] != ek[0]:
    print(n - ov[0] - ev[0])
elif ov[0] > ev[0]:
    if (len(ov) == 1 and len(ev) != 1):
        print(int(n - n / 2 - ev[0]))
    elif (len(ev) == 1 and len(ov) != 1):
        print(int(n - (n / 2) - ov[0]))
    elif (len(ov) == 1 and len(ev) == 1):
        print(int(n - n / 2))
else:
    if (len(ov) == 1 and len(ev) != 1):
        print(int(n - n / 2 - ev[0]))
    elif (len(ev) == 1 and len(ov) != 1):
        print(int(n - (n / 2) - ov[0]))
    elif (len(ov) == 1 and len(ev) == 1):
        print(int(n - n / 2))

Submission status: Wrong Answer

Solution code:
from collections import OrderedDict
n = int(input())

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

odd = OrderedDict()
even = OrderedDict()

for i in range(len(v)):
    if (i % 2 == 1):
        odd.setdefault(v[i],0)
        odd[v[i]] += 1
    else:
        even.setdefault(v[i],0)
        even[v[i]] += 1


oddl = OrderedDict(sorted(odd.items(),key = lambda x: x[1],reverse=True))
evenl = OrderedDict(sorted(even.items(),key = lambda x: x[1],reverse=True))


ok = [x for x in oddl.keys()]
ov  = [x for x in oddl.values()]
ek = [x for x in evenl.keys()]
ev = [x for x in evenl.values()]

if(len(ov) == 1 and len(ev) != 1):
    print(int(n - n/2 - ev[0]))
elif(len(ev) == 1 and len(ov) != 1):
    print(int(n-(n/2) - ov[0]))
elif(len(ov) == 1 and len(ev) == 1):
    print(int(n-n/2))
elif ok[0] != ek[0]:
    print(n - ov[0] - ev[0])
elif ov[0] > ev[0]:
    print(n-ov[0]-ev[1])
else:
    print(n-ov[1]-ev[0])

Submission status: Wrong Answer

Solution code:
from collections import OrderedDict
n = int(input())

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

odd = OrderedDict()
even = OrderedDict()

for i in range(len(v)):
    if (i % 2 == 1):
        odd.setdefault(v[i],0)
        odd[v[i]] += 1
    else:
        even.setdefault(v[i],0)
        even[v[i]] += 1


oddl = OrderedDict(sorted(odd.items(),key = lambda x: x[1],reverse=True))
evenl = OrderedDict(sorted(even.items(),key = lambda x: x[1],reverse=True))


ok = [x for x in oddl.keys()]
ov  = [x for x in oddl.values()]
ek = [x for x in evenl.keys()]
ev = [x for x in evenl.values()]

if(len(ov) == 1 and len(ev) != 1):
    print(int(n - n/2 - ev[0]))
elif(len(ev) == 1 and len(ov) != 1):
    print(n-int(n/2) - ov[0])
elif(len(ov) == 1 and len(ev) == 1):
    print(n-int(n/2))
elif ok[0] != ek[0]:
    print(n - ov[0] - ev[0])
elif ov[0] > ev[0]:
    print(n-ov[0]-ev[1])
else:
    print(n-ov[1]-ev[0])

Submission status: Wrong Answer

Solution code:
from collections import OrderedDict
n = int(input())

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

odd = OrderedDict()
even = OrderedDict()

for i in range(len(v)):
    if (i % 2 == 1):
        odd.setdefault(i,0)
        odd[i] += 1
    else:
        even.setdefault(i,0)
        even[i] += 1


oddl = OrderedDict(sorted(odd.items(),key = lambda x: x[1],reverse=True))
evenl = OrderedDict(sorted(even.items(),key = lambda x: x[1],reverse=True))


ok = [x for x in oddl.keys()]
ov  = [x for x in oddl.values()]
ek = [x for x in evenl.keys()]
ev = [x for x in evenl.values()]
if ok[0] != ek[0]:
    print(n - ov[0] - ev[0])
elif ov[0] > ev[0]:
    print(n-ov[0]-ev[1])
else:
    print(n-ov[1]-ev[0])

Submission status: Wrong Answer

Solution code:
from collections import OrderedDict
n = int(input())

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

odd = OrderedDict()
even = OrderedDict()

for i in range(len(v)):
    if (i % 2 == 1):
        odd.setdefault(i,0)
        odd[i] += 1
    else:
        even.setdefault(i,0)
        even[i] += 1


oddlv = [v for k,v in sorted(odd.items(),key = lambda x: x[1])]
oddlk = [k for k,v in sorted(odd.items(),key = lambda x: x[1])]
evenlv = [v for k,v in sorted(even.items(),key = lambda x: x[1])]
evenlk = [k for k,v in sorted(odd.items(),key = lambda x: x[1])]


if oddlk[0] != evenlk[0]:
    print(n - oddlv[0] - evenlv[0])
elif oddlv[0] > evenlv[0]:
    print(n-oddlv[0]-evenlv[1])
else:
    print(n-oddlv[1]-evenlv[0])

Submission status: Wrong Answer

Solution code:
from collections import OrderedDict
n = int(input())

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

odd = OrderedDict()
even = OrderedDict()

for i in range(len(v)):
    if (i % 2 == 1):
        odd.setdefault(i,0)
        odd[i] += 1
    else:
        even.setdefault(i,0)
        even[i] += 1

oddl = [v for k,v in sorted(odd.items())]
evenl = [v for k,v in sorted(even.items())]
print(oddl[0],evenl[0])
if oddl[0] != evenl[0]:
    print(n - oddl[0] - evenl[0])
elif oddl[0] > evenl[0]:
    print(n-oddl[0]-evenl[1])
else:
    print(n-oddl[1]-evenl[0])

Submission status: Wrong Answer

Solution code:
from collections import OrderedDict
n = int(input())

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

odd = OrderedDict()
even = OrderedDict()

for i in range(len(v)):
    if (i % 2 == 1):
        odd.setdefault(i,0)
        odd[i] += 1
    else:
        even.setdefault(i,0)
        even[i] += 1

oddl = [v for k,v in sorted(odd.items())]
evenl = [v for k,v in sorted(even.items())]

if oddl[0] != evenl[0]:
    print(n - oddl[0] - evenl[0])
elif oddl[0] > evenl[0]:
    print(n-oddl[0]-evenl[1])
else:
    print(n-oddl[1]-evenl[0])

Submission status: Wrong Answer

Solution code:
from collections import OrderedDict
n = int(input())

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

odd = OrderedDict()
even = OrderedDict()

for i in range(len(v)):
    if (i % 2 == 1):
        odd.setdefault(i,0)
        odd[i] += 1
    else:
        even.setdefault(i,0)
        even[i] += 1

oddl = [v for k,v in sorted(odd.items())]
evenl = [v for k,v in sorted(even.items())]

if oddl[0] != evenl[0]:
    print(n - odd[0] - evenl[0])
elif oddl[0] > evenl[0]:
    print(n-oddl[0]-evenl[1])
else:
    print(n-oddl[1]-evenl[0])

Submission status: Wrong Answer

Solution code:
import numpy as np
import sys

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

vodd = v[::2]
veven = v[1::2]
flag = False

if v.count(v[0]) == len(v):
    print(n // 2)
    sys.exit()

vodd_duplicate = np.array(
    [[x, vodd.count(x)] for x in set(vodd) if vodd.count(x) > 1])
if vodd_duplicate.size == 0:
    vodd_sort = np.array([[0, 1]])
    flag = True
else:
    vodd_sort = vodd_duplicate[np.argsort(vodd_duplicate[:, 1])]

veven_duplicate = np.array(
    [[x, veven.count(x)] for x in set(veven) if veven.count(x) > 1])
if veven_duplicate.size == 0:
    veven_sort = np.array([[0, 1]])
    flag = True
else:
    veven_sort = veven_duplicate[np.argsort(veven_duplicate[:, 1])]

if flag:
    print(n - (vodd_sort[0][1] + veven_sort[0][1]))
else:
    if not vodd_sort[0][0] == veven_sort[0][0]:
        print(n - (vodd_sort[0][1] + veven_sort[0][1]))
    else:
        print(n - max(vodd_sort[0][1] + veven_sort[1][1], vodd_sort[1][1] +
                      veven_sort[0][1]))

Submission status: Wrong Answer

Solution code:
N = int(input())
li=[int(it) for it in input().split()]
lia=li[::2]
lib=li[1::2]

import collections
ca = list(collections.Counter(lia).items())
cb = list(collections.Counter(lib).items())
na = len(lia)
nb = len(lib)
ca.sort(key=lambda x:-x[1])
cb.sort(key=lambda x:-x[1])
s = 0
if ( ca[0][0] != cb[0][0] ):
  s += na - ca[0][1]
  s += nb - cb[0][1]
else:
  if ( ca[0][1] > cb[0][1]   ):
    s += na - ca[0][1]
    if ( len(cb)>1 ):
      s += nb - cb[1][1]
    else:
      s += nb
  else:
    s += nb - cb[0][1]
    if ( len(ca)>1 ):
      s += na - ca[1][1]
    else:
      s += na
print (s)

Submission status: Wrong Answer

Solution code:
N = int(input())
li=[int(it) for it in input().split()]
lia=li[::2]
lib=li[1::2]

import collections
ca = list(collections.Counter(lia).items())
cb = list(collections.Counter(lib).items())
na = len(lia)
nb = len(lib)
ca.sort(key=lambda x:-x[1])
cb.sort(key=lambda x:-x[1])
s = 0
if ( ca[0][0] != cb[0][0] ):
  s += na - ca[0][1]
  s += nb - cb[0][1]
else:
  if ( ca[0][1] > cb[0][1]   ):
    s += na - ca[0][1]
    if ( len(cb)>1 ):
      s += nb - cb[1][1]
    else:
      s += nb
  else:
    s += nb - cb[0][1]
    if ( len(ca)>1 ):
      s += na - ca[1][1]
    else:
      s += na
print (s)

Submission status: Wrong Answer

Solution code:
def basket_count(arr):
    basket = []
    tmp = arr[0]
    cnt_ele = 0
    for ele in arr:
        if ele == tmp:
            cnt_ele += 1
        else:
            basket.append([tmp, cnt_ele])
            # reset count for basket
            tmp = ele
            cnt_ele = 0
    basket.append([tmp, cnt_ele])
    return basket

def solve():
    n = int(raw_input())
    v = [int(_) for _ in raw_input().split()]
    v0 = []
    v1 = []
    for i in range(n):
        if i % 2 == 0:
            v0.append(v[i])
        else:
            v1.append(v[i])
    v0.sort()
    v1.sort()
    bask_v0 = basket_count(v0)
    bask_v0.sort(reverse = True, key = lambda x: x[1])
    bask_v1 = basket_count(v1)
    bask_v1.sort(reverse = True, key = lambda x: x[1])
    if bask_v0[0][0] != bask_v1[0][0]:
        ret = n - (bask_v0[0][1] + bask_v1[0][1])
    elif len(bask_v1) <= 1:
        if len(bask_v0) > 1:
            ret = n - (bask_v0[1][1] + bask_v1[0][1])
        else:
            ret = n - bask_v0[0][1]
    else: # len(bask_v1) > 1
        if len(bask_v0) <= 1:
            ret = n - (bask_v0[0][1] + bask_v1[1][1])
        else:
            ret = n - max(bask_v0[0][1] + bask_v1[1][1], \
                          bask_v0[1][1] + bask_v0[0][1])
    print str(ret)

if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

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

v_dict = [{} for _ in range(2)]
for i in range(n):
    if i % 2 == 0:
        if v[i] in v_dict[0]:
            v_dict[0][v[i]] += 1
        else:
            v_dict[0][v[i]] = 1
    else:
        if v[i] in v_dict[1]:
            v_dict[1][v[i]] += 1
        else:
            v_dict[1][v[i]] = 1

evens = sorted([(key, val) for key, val in v_dict[0].items()], key=lambda comb: comb[1])
odds = sorted([(key, val) for key, val in v_dict[1].items()], key=lambda comb: comb[1])

ans = 0
for _, val in evens[:-1]:
    ans += val
for _, val in odds[:-1]:
    ans += val
if evens[-1][0] == odds[-1][0]:
    if len(evens) > 1:
        if evens[-2][1] < odds[-2][1]:
            ans += odds[-2][1] - odds[-2][1]
        else:
            ans += evens[-2][1] - evens[-2][1]
    else:
        ans = n // 2

print(ans)

Submission status: Wrong Answer

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

v_dict = [{} for _ in range(2)]
for i in range(n):
    if i % 2 == 0:
        if v[i] in v_dict[0]:
            v_dict[0][v[i]] += 1
        else:
            v_dict[0][v[i]] = 1
    else:
        if v[i] in v_dict[1]:
            v_dict[1][v[i]] += 1
        else:
            v_dict[1][v[i]] = 1

even_v = sorted(v_dict[0].values())
odd_v = sorted(v_dict[1].values())

ans = 0
for ev in even_v[:-1]:
    ans += ev
for ov in odd_v[:-1]:
    ans += ov
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
a1 = {'emp':0}
a2 = {'emp':0}

for i in range(0,n//2+2,2):
    # print(i)
    if str(a[i]) in a1.keys():
        a1[str(a[i])] += 1
    else :
        a1[str(a[i])] = 1
    if str(a[i+1]) in a2.keys():
        a2[str(a[i+1])] += 1
    else :
        a2[str(a[i+1])] = 1
# print(a1,a2)

a1 = sorted(a1.items(), key=lambda x: -x[1])
a2 = sorted(a2.items(), key=lambda x: -x[1])

if a1[0][0] == a2[0][0]:
    print(n-max(a1[0][1]+a2[1][1],a1[1][1]+a2[0][1]))
else :
    print(n-a1[0][1]-a2[0][1])

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
a1 = {'emp':0}
a2 = {'emp':0}

for i in range(0,n//2+1,2):
    if str(a[i]) in a1.keys():
        a1[str(a[i])] += 1
    else :
        a1[str(a[i])] = 1
    if str(a[i+1]) in a2.keys():
        a2[str(a[i+1])] += 1
    else :
        a2[str(a[i+1])] = 1

a1 = sorted(a1.items(), key=lambda x: -x[1])
a2 = sorted(a2.items(), key=lambda x: -x[1])

if a1[0][0] == a2[0][0]:
    print(n-max(a1[0][1]+a2[1][1],a1[1][1]+a2[0][1]))
else :
    print(n-a1[0][1]-a2[0][1])

Submission status: Wrong Answer

Solution code:
n = int(input())
v = input().split()
count1 = {}
count2 = {}
for loop_count,i in enumerate(v):
    if loop_count % 2 == 0:
        count1[i] = count1.get(i,0) + 1
    else:
        count2[i] = count2.get(i,0) + 1

sort_1 = sorted(count1.items(), key = lambda x : x[1])
sort_2 = sorted(count2.items(), key = lambda x : x[1])
if sort_1[0][0] != sort_2[0][0]:
    print(n - sort_1[0][1] - sort_2[0][1])
elif len(sort_1) > 1 and len(sort_2) > 1:
    print(min([n - sort_1[1][1] - sort_2[0][1] , n - sort_1[0][1] - sort_2[1][1]]))
else:
    print(n//2)

Submission status: Wrong Answer

Solution code:
n = int(input())
v = input().split()
count1 = {}
count2 = {}
for loop_count,i in enumerate(v):
    if loop_count % 2 == 0:
        count1[i] = count1.get(i,0) + 1
    else:
        count2[i] = count2.get(i,0) + 1
print(n - max(count1.values()) - max(count2.values()))

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
from collections import Counter
INF = float("inf")


def solve(n: int, v: "List[int]"):
    c0 = Counter(v[0::2])
    c1 = Counter(v[1::2])

    c0[0] = 0
    c1[0] = 0

    mc0 = c0.most_common(2)
    mc1 = c1.most_common(2)

    v0, v1 = -INF, -INF

    if mc0[0][0] == mc1[0][0]:
        if mc0[0][1] + mc1[1][1] > mc0[1][1] + mc1[0][1]:
            v0 = mc0[1][1]
            v1 = mc1[0][1]
        else:
            v0 = mc0[0][1]
            v1 = mc1[1][1]
    else:
        v0 = mc0[0][1]
        v1 = mc1[0][1]

    print(n - v0-v1)

    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    n = int(next(tokens))  # type: int
    v = [int(next(tokens)) for _ in range(n)]  # type: "List[int]"
    solve(n, v)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
from collections import Counter
INF = float("inf")


def solve(n: int, v: "List[int]"):
    c0 = Counter(v[0::2])
    c1 = Counter(v[1::2])

    c0[0] = 0
    c1[0] = 0

    mc0 = c0.most_common(2)
    mc1 = c1.most_common(2)

    v0, v1 = -INF, -INF

    if mc0[0][0] == mc1[0][0]:
        if mc0[0][1] < mc1[0][1]:
            v0 = mc0[1][1]
            v1 = mc1[0][1]
        else:
            v0 = mc0[0][1]
            v1 = mc1[1][1]
    else:
        v0 = mc0[0][1]
        v1 = mc1[0][1]

    print(n - v0-v1)

    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    n = int(next(tokens))  # type: int
    v = [int(next(tokens)) for _ in range(n)]  # type: "List[int]"
    solve(n, v)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
from collections import Counter
INF = float("inf")


def solve(n: int, v: "List[int]"):
    c0 = Counter(v[0::2])
    c1 = Counter(v[1::2])

    c0[0] = 0
    c1[0] = 0

    mc0 = c0.most_common(1)[0]
    mc1 = c1.most_common(1)[0]
    if mc0[0] == mc1[0]:
        if mc0[1] >= mc1[1]:
            del c1[mc1[0]]
            mc1 = c1.most_common(1)[0]
        else:
            del c0[mc0[0]]
            mc0 = c0.most_common(1)[0]
    print(n - mc0[1] - mc1[1])

    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    n = int(next(tokens))  # type: int
    v = [int(next(tokens)) for _ in range(n)]  # type: "List[int]"
    solve(n, v)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

v1, v2 = defaultdict(int), defaultdict(int)
for i, vv in enumerate(v):
    if i%2 == 0:
        v1[vv] += 1
    else:
        v2[vv] += 1
v1 = sorted([(c, vv) for vv, c in v1.items()], reverse = True)
v2 = sorted([(c, vv) for vv, c in v2.items()], reverse = True)

if v1[0][1] == v2[0][1]:
    if len(v1) == len(v2):
        ans = n//2
    elif v1[1][0] > v2[1][0]:
        ans = n - v1[1][0] - v2[0][0]
    else:
        ans = n - v1[0][0] - v2[1][0]
else:
    ans = n - v1[0][0] - v2[0][0]
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
v = list(map(int, input().split()))
import collections
a = v[::2]
b = v[1::2]
a,b = collections.Counter(a),collections.Counter(b)
s = a[max(a)] + b[max(b)]
print(len(v)-s)

Submission status: Wrong Answer

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

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


def search_mode(list):
    dict = {}
    mode = 0
    for l in list:
        if l in dict.keys():
            dict[l] += 1
            if mode < dict[l]:
                mode = dict[l]
        else:
            dict[l] = 1
    dict = sorted(dict.items(), key=lambda x: -x[1])
    return dict


even_dict = search_mode(even)
odd_dict = search_mode(odd)

if len(even_dict) == 1 and len(odd_dict) == 1:
    print(n // 2)
elif len(even_dict) == 1:
    if even_dict[0][0] == odd_dict[0][0]:
        print(len(odd) - odd_dict[1][1])
    else:
        print(len(odd) - odd_dict[0][1])
elif len(odd_dict) == 1:
    if odd_dict[0][0] == even_dict[0][0]:
        print(len(even) - even_dict[1][1])
    else:
        print(len(even) - even_dict[0][1])
elif even_dict[0][0] == odd_dict[0][0]:
    eo01 = n - even_dict[0][1] - odd_dict[1][1]
    eo10 = n - even_dict[1][1] - odd_dict[0][1]
    max_count = min(eo01, eo10)
    print(max_count)
else:
    print(n - even_dict[0][1] - odd_dict[0][1])

Submission status: Wrong Answer

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

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


def search_mode(list):
    dict = {}
    mode = 0
    for l in list:
        if l in dict.keys():
            dict[l] += 1
            if mode < dict[l]:
                mode = dict[l]
        else:
            dict[l] = 1
    dict = sorted(dict.items(), key=lambda x: -x[1])
    return dict


even_dict = search_mode(even)
odd_dict = search_mode(odd)

if len(even_dict) == 1 and len(odd_dict) == 1:
    print(n // 2)
elif len(even_dict) == 1:
    if even_dict[0][0] == odd_dict[0][0]:
        print(len(odd) - odd_dict[1][1])
    else:
        print(len(odd) - odd_dict[0][1])
elif len(odd_dict) == 1:
    if odd_dict[0][0] == even_dict[0][0]:
        print(len(even) - even_dict[1][1])
    else:
        print(len(even) - even_dict[0][1])
elif even_dict[0][0] == odd_dict[0][0]:
    eo01 = n - even_dict[0][1] - odd_dict[1][1]
    eo10 = n - even_dict[1][1] - odd_dict[0][1]
    max_count = max(eo01, eo10)
    print(max_count)
else:
    print(n - even_dict[0][1] - odd_dict[0][1])

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
v = [int(i) for i in input().split()]
v_even = [v[2*i] for i in range(int(n/2))]
v_odd = [v[2*i-1] for i in range(int(n/2))]
c_even = collections.Counter(v_even)
c_odd = collections.Counter(v_odd)
if(c_even.most_common()[0][0]!=c_odd.most_common()[0][0]):
    print(n - c_even.most_common()[0][1] - c_odd.most_common()[0][1])
elif(len(collections.Counter(v))==1):
    print(int(n/2))
else:
    if(c_even.most_common()[0][1]>c_odd.most_common()[0][1]):
        print(n-c_even.most_common()[0][1] - c_odd.most_common()[1][1])
    else:
        print(n - c_odd.most_common()[0][1] - c_even.most_common()[1][1])

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
v = [int(i) for i in input().split()]
v_even = [v[2*i] for i in range(int(n/2))]
v_odd = [v[2*i-1] for i in range(int(n/2))]
c_even = collections.Counter(v_even)
c_odd = collections.Counter(v_odd)
if(c_even.most_common()[0][0]!=c_odd.most_common()[0][0]):
    print(n - c_even.most_common()[0][1] - c_odd.most_common()[0][1])
elif(len(collections.Counter(v))==1):
    print(int(n/2))
else:
    print(n - max(c_even.most_common()[0][1],c_odd.most_common()[0][1])- min(c_even.most_common()[0][1],c_odd.most_common()[0][1]))

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
v = [int(i) for i in input().split()]
v_even = [v[2*i] for i in range(int(n/2))]
v_odd = [v[2*i-1] for i in range(int(n/2))]
c_even = collections.Counter(v_even)
c_odd = collections.Counter(v_odd)
if(c_even.most_common()[0][0]!=c_odd.most_common()[0][0]):
    print(n - c_even.most_common()[0][1] - c_odd.most_common()[0][1])
elif(len(collections.Counter(v))==1):
    print(int(n/2))
else:
    print(n - max(c_even.most_common()[0][1],c_odd.most_common()[0][1])- (int(n/2) - min(c_even.most_common()[0][1],c_odd.most_common()[0][1])))

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
v = [int(i) for i in input().split()]
v_even = [v[2*i] for i in range(int(n/2))]
v_odd = [v[2*i-1] for i in range(int(n/2))]
c_even = collections.Counter(v_even)
c_odd = collections.Counter(v_odd)
if(c_even.most_common()[0][0]!=c_odd.most_common()[0][0]):
    print(n - c_even.most_common()[0][1] - c_odd.most_common()[0][1])
elif(len(collections.Counter(v))==1):
    print(int(n/2))
else:
    print(n - collections.Counter(v).most_common()[0][1])

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
v = [int(i) for i in input().split()]
v_even = [v[2*i] for i in range(int(n/2))]
v_odd = [v[2*i-1] for i in range(int(n/2))]
c_even = collections.Counter(v_even)
c_odd = collections.Counter(v_odd)
if(c_even.most_common()[0][0]!=c_odd.most_common()[0][0]):
    print(n - c_even.most_common()[0][1] - c_odd.most_common()[0][1])
else:
    if(len(c_odd.most_common())==1):
        print(n-c_even.most_common()[0][1])
    else:
        print(n - c_even.most_common()[0][1] - c_odd.most_common()[1][1])

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())


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

    a_dict = {}
    b_dict = {}

    for i in range(n//2):
        a = v[2*i]
        b = v[2*i+1]
        if not a in a_dict.keys():
            a_dict[a] = 0
        if not b in b_dict.keys():
            b_dict[b] = 0

        a_dict[a] +=1
        b_dict[b] +=1

    if len(a_dict) == 1 and len(b_dict) ==1 and list(a_dict.keys()) != list(b_dict.keys()):
        print(0)
        return


    a_val= sorted(a_dict.items(), key=lambda x:x[1], reverse=True)
    b_val = sorted(b_dict.items(), key=lambda x:x[1], reverse=True)

    def sum_val(val):
        ret =0
        if len(val) >= 1:
            for it in val:
                ret += it[1]
        return ret

    ret = 0
    if a_val[0][0] != b_val[0][0]:
        ret += sum_val(a_val[1:])
        ret += sum_val(b_val[1:])
        print(ret)
    elif a_val[0][1] > b_val[0][1]:
        ret += sum_val(a_val[1:])
        ret += sum_val(b_val[:1])
        ret += sum_val(b_val[2:])
        print(ret)
    return
main()

Submission status: Wrong Answer

Solution code:
from collections import Counter
n=int(input())
l=input().split()
m=[Counter(l[i::2]).most_common()[0][0] for i in range(2)]
print(n-l[0::2].count(m[0])-l[1::2].count(m[1]) if len(set(l))!=1 else n//2)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n=int(input())
l=input().split()
print(n-Counter(l[0::2]).most_common()[0][1]-Counter(l[1::2]).most_common()[0][1] if l[0]!=l[1] else n//2)

Submission status: Wrong Answer

Solution code:
n = int(input())
v = [int(_) for _ in input().split()]
oddv = v[::2]
evenv = v[1::2]
oddcnt = [0]*(10**5+1)
evencnt = [0]*(10**5+1)

for i, j in zip(oddv, evenv):
    oddcnt[i] += 1
    evencnt[j] += 1

for i, j in enumerate(oddcnt):
    oddcnt[i] = [i, j]

for i, j in enumerate(evencnt):
    evencnt[i] = [i, j]

oddcnt = sorted(oddcnt, key=lambda x: -x[1])
evencnt = sorted(evencnt, key=lambda x: -x[1])

if oddcnt[0][0] != evencnt[0][0]:
    oddmax = oddcnt[0][1]
    evenmax = evencnt[0][1]
elif oddcnt[0][1] > evencnt[0][1]:
    oddmax = oddcnt[0][1]
    evenmax = evencnt[1][1]
else:
    oddmax = oddcnt[1][1]
    evenmax = evencnt[0][1]

print(n - oddmax - evenmax)

Submission status: Wrong Answer

Solution code:
#coding: utf-8
from collections import Counter
N = int(input())
l = list(map(int,input().split()))
if len(set(l)) > 1:
  o, e = [], []
  for i in range(N):
    if i % 2==0:
      e.append(l[i])
    else:
      o.append(l[i])
  oc, oe = Counter(o).most_common(2), Counter(e).most_common(2)
  print(len(l) - oc[0][1] - oe[0][1] if oc != oe else len(l) - max(oc[0][1] + oe[1][1], oc[1][1] + oe[0][1]))

else:
  print(len(l) // 2)

Submission status: Wrong Answer

Solution code:
#coding: utf-8
from collections import Counter
N = int(input())
l = list(map(int,input().split()))
if len(set(l)) > 1:
  o, e = [], []
  for i in range(N):
    if i % 2==0:
      e.append(l[i])
    else:
      o.append(l[i])
  oc, oe = Counter(o).most_common(), Counter(e).most_common()
  print(len(l) - oc[0][1] - oe[0][1] if oc != oe else len(l) - oc[0][1] - oe[1][1])

else:
  print(len(l) // 2)

Submission status: Wrong Answer

Solution code:
#coding: utf-8
from collections import Counter
N = int(input())
l = list(map(int,input().split()))
if len(set(l)) > 1:
  o, e = [], []
  for i in range(N):
    if i % 2==0:
      e.append(l[i])
    else:
      o.append(l[i])
  oc, oe = max(Counter(o).values()), max(Counter(e).values())
  print(len(l) - oc - oe)

else:
  print(len(l) // 2)

Submission status: Wrong Answer

Solution code:
from collections import Counter
N= int(input())
l = list(map(int,input().split()))
if len(set(l))>1:
  o, e = [],[]
  for i in range(N):
    if i %2==0:
      e.append(l[i])
    else:
      o.append(l[i])
  oc = Counter(o)
  oe = Counter(e)
  oo = max(oc.values())
  ee = max(oe.values())
  print(len(o)-oo+len(e)-ee)
else:
  print(len(l)//2)

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
v = list(map(int,input().split()))
od = [0]
ev = [0]
for i in range(n):
    if i % 2 == 0:
        od.append(v[i])
    else:
        ev.append(v[i])

o1, o2 = collections.Counter(od).most_common(2)
e1, e2 = collections.Counter(ev).most_common(2)
if o1[0] == e1[0]:
    print(n - max(o1[1] + e2[1], o2[1] + e1[1]))
else:
    print(n - (o1[1] + e1[1]))

Submission status: Wrong Answer

Solution code:
n = int(input())
v = list(map(int,input().split()))
if len(set(v)) == 1:
    print(n//2)
    exit()
    
od = {}
ev = {}
for i in range(n):
    if i % 2 == 0:
        if v[i] in od:
            od[v[i]] += 1
        else:
            od[v[i]] = 1
    else:
        if v[i] in ev:
            ev[v[i]] += 1
        else:
            ev[v[i]] = 1
print(n - max(od.values()) - max(ev.values()))

Submission status: Wrong Answer

Solution code:
n=int(input())
m=list(map(int,input().split()))
a=m[::2]
b=m[1::2]
aa={}
bb={}
for i in range(n//2):
  if not a[i] in aa:
    aa[a[i]]=0
  aa[a[i]]+=1
  if not b[i] in bb:
    bb[b[i]]=0
  bb[b[i]]+=1
aaa=list(aa.values())
aaa.sort(reverse=True)
bbb=list(bb.values())
bbb.sort(reverse=True)
if not max(aa)==max(bb):
  print(n-aaa[0]-bbb[0])
else:
  if len(aaa)>1 and len(bbb)>1:
    print(min(n-aaa[1]-bbb[0],n-aaa[0]-bbb[1]))
  elif len(aaa)>1 and len(bbb)==1:
    print(n-aaa[1]-bbb[0])
  elif len(aaa)==1 and len(bbb)>1:
    print(n-aaa[0]-bbb[1])
  else:
    print(n//2)

Submission status: Wrong Answer

Solution code:
n=int(input())
m=list(map(int,input().split()))
a=m[::2]
b=m[1::2]
aa={}
bb={}
for i in range(n//2):
  if not a[i] in aa:
    aa[a[i]]=0
  aa[a[i]]+=1
  if not b[i] in bb:
    bb[b[i]]=0
  bb[b[i]]+=1
print(n-max(aa.values())-max(bb.values()))

Submission status: Wrong Answer

Solution code:
n=int(input())
m=list(map(int,input().split()))
a=m[::2]
b=m[1::2]
a1=10**18
b1=10**18
for i in range(n//2):
  a1=min(a1,n//2-a.count(a[i]))
  b1=min(b1,n//2-b.count(b[i]))
print(a1+b1)