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 = input().split()
vs = list(map(int, input().split()))

eve = {}
odd = {}

for i in range(len(vs)):
    if i % 2 == 0:
        if vs[i] in eve:
            eve[vs[i]] += 1
        else:
            eve[vs[i]] = 1
    else:
        if vs[i] in odd:
            odd[vs[i]] += 1
        else:
            odd[vs[i]] = 1

es = sorted(eve.items(), key=lambda x: -x[1])
os = sorted(odd.items(), key=lambda x: -x[1])

trans = 0

if es[0][0] == os[0][0]:
    if es[0][1] > os[0][1]:
        del es[0]
        if(len(os) > 1):
            del os[1]
    else:
        del os[0]
        if(len(es) > 1):
            del es[1]
else:
    for i in range(1, len(es)):
        trans += es[0][1]
    for i in range(1, len(os)):
        trans += os[0][1]

print(trans)

Submission status: Wrong Answer

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

eve = {}
odd = {}

for i in range(len(vs)):
    if i % 2 == 0:
        if vs[i] in eve:
            eve[vs[i]] += 1
        else:
            eve[vs[i]] = 1
    else:
        if vs[i] in eve:
            eve[vs[i]] += 1
        else:
            eve[vs[i]] = 1

es = sorted(eve.items(), key=lambda x: -x[1])
os = sorted(eve.items(), key=lambda x: -x[1])

trans = 0

if es[0][0] == os[0][0]:

    if es[0][1] > os[0][1]:
        del es[0]
        if(len(os) > 1):
            del os[1]
    else:
        del os[0]
        if(len(es) > 1):
            del es[1]
else:
    for i in range(1, len(es)):
        trans += es[0][1]
    for i in range(1, len(os)):
        trans += os[0][1]

print(trans)

Submission status: Wrong Answer

Solution code:
n = int(input())
l = list(map(int, input().split()))
l1 = [li for i, li in enumerate(l) if i % 2 == 0]
l2 = [li for i, li in enumerate(l) if i % 2 == 1]
def cnt(l):
    d = {}
    for li in l:
        if li in d:
            d[li] += 1
        else:
            d[li] = 1
    d = [(li, cnt) for li, cnt in d.items()]
    return sorted(d, key=lambda di: di[1], reverse=True)

k1 = cnt(l1)[:2]
k2 = cnt(l2)[:2]
ans = 10000000
if k1[0][0] != k2[0][0]:
    ans = n - k1[0][1] - k2[0][1]
if len(k1) == 2:
    ans = n - k1[1][1] - k2[0][1]
if len(k2) == 2:
    ans = min(ans, n - k1[0][1] - k2[0][1])
if ans == 10000000:
    ans = n - max(k1[0][1], k2[0][1])
print(ans)

Submission status: Wrong Answer

Solution code:
from sys import stdin
from collections import Counter

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

    if len(set(V)) == 1:
        print(N // 2)
        return

    even = [V[i] for i in range(N) if not i % 2]
    counter = Counter(even)
    top_e = counter.most_common()

    odd = [V[i] for i in range(N) if i % 2]
    counter = Counter(odd)
    top_o = counter.most_common()

    if top_e[0][1] > top_o[0][1]:
        a = [top_e[0][0]] * (N // 2)
        b = odd[:]
        cnt = (N // 2) - top_e[0][1]
        if top_e[0][0] == top_o[0][0]:
            n = top_o[1][0]
        else:
            n = top_o[0][0]
    else:
        a = [top_o[0][0]] * (N // 2)
        b = even[:]
        cnt = (N // 2) - top_o[0][1]
        if top_o[0][0] == top_e[0][0]:
            n = top_e[1][0]
        else:
            n = top_e[0][0]

    for i in b:
        if i != n:
            cnt += 1
    print(cnt)

input = lambda: stdin.readline()
main()

Submission status: Wrong Answer

Solution code:
n = int(input())
l = list(map(int, input().split()))
l1 = [li for i, li in enumerate(l) if i % 2 == 0]
l2 = [li for i, li in enumerate(l) if i % 2 == 1]
def cnt(l):
    d = {}
    for li in l:
        if li in d:
            d[li] += 1
        else:
            d[li] = 1
    d = [(li, cnt) for li, cnt in d.items()]
    return sorted(d, key=lambda di: di[1], reverse=True)

k1 = cnt(l1)[:2]
k2 = cnt(l2)[:2]
ans = 10000000
if k1[0][0] != k2[0][0]:
    ans = n - k1[0][1] - k2[0][1]
else:
    if len(k1) == 2:
        ans = n - k1[1][1] - k2[0][1]
    if len(k2) == 2:
        ans = min(ans, n - k1[0][1] - k2[0][1])
    if ans == 10000000:
        ans = n - max(k1[0][1], k2[0][1])
print(ans)

Submission status: Wrong Answer

Solution code:
import sys

def DistanceFromVV(seq, el):
    """Return the numbers of edits required to make seq into a VV sequences
    using el as the first and second element, respectively.
    """

    distA = 0
    distB = 0
    for i in range(0, len(seq), 2):
        if seq[i] != el:
            distA += 1
    for j in range(1, len(seq), 2):
        if seq[j] != el:
            distB += 1
    return (distA, distB)

def CountElements(seq):
    """Count the number of occurrences of each element of seq, returning the 
    result as a dictionary.
    """

    count = {}
    for el in seq:
        if el in count:
            count[el] += 1
        else:
            count[el] = 1
    return count

def MinChanges(seq):
    """Return the minimum number of changes which must be made to the given 
    sequence in order to make it "VV".
    """

    element_count = CountElements(seq)
    elements_descending = sorted(element_count, 
                                 key=lambda key: element_count[key], 
                                 reverse=True)

    if (len(elements_descending) == 1):
        return len(seq) // 2

    best = [len(seq) + 1, len(seq) + 1]
    second_best = [len(seq) + 1, len(seq) + 1]
    best_elements = [-1, -1]
    for el in elements_descending:
        bound = len(seq)//2 - element_count[el]
        if bound > best[0] and bound > best[1]:
            break

        changes = DistanceFromVV(seq, el)
        for i in (0,1):
            if changes[i] <= best[i]:
                second_best[i] = best[i]
                best[i] = changes[i]
                best_elements[i] = el
            elif changes[i] < second_best[i]:
                second_best[i] = changes[i]

        if best_elements[0] != best_elements[1]:
            if best[0] <= len(seq)//4 and best[1] <= len(seq)//4:
                break
        elif (best[0] <= len(seq)//4 and second_best[1] <= len(seq)//4) or (best[1] <= len(seq)//4 and second_best[0] <= len(seq)//4):
            break

    if best_elements[0] != best_elements[1]:
        return sum(best)
    else:
        return min(best[0] + second_best[1], best[1] + second_best[0])

lines = sys.stdin.read().split('\n')
n = int(lines[0])
entries = lines[1].split(' ')
v = []
for e in entries:
    v += [int(e)]

print(MinChanges(v))

Submission status: Wrong Answer

Solution code:
n = int(input())
l = list(map(int, input().split()))
l1 = [li for i, li in enumerate(l) if i % 2 == 0]
l2 = [li for i, li in enumerate(l) if i % 2 == 1]
def cnt(l):
    d = {}
    for li in l:
        if li in d:
            d[li] += 1
        else:
            d[li] = 1
    d = [(li, cnt) for li, cnt in d.items()]
    d = sorted(d, key=lambda di: di[0], reverse=True)
    return d

k1 = cnt(l1)[:2]
k2 = cnt(l2)[:2]

ans = 10000000
if k1[0][0] != k2[0][0]:
    ans = n - k1[0][1] - k2[0][1]
else:
    if len(k1) == 2:
        ans = n - k1[1][1] - k2[0][1]
    if len(k2) == 2:
        ans = min(ans, n - k1[0][1] - k2[0][1])
    if ans == 10000000:
        ans = n - max(k1[0][1], k2[0][1])
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
l = list(map(int, input().split()))
l1 = [li for i, li in enumerate(l) if i % 2 == 0]
l2 = [li for i, li in enumerate(l) if i % 2 == 1]

def cnt(l):
    d = {}
    for li in l:
        if li in d:
            d[li] += 1
        else:
            d[li] = 1
    d = [(li, cnt) for li, cnt in d.items()]
    d = sorted(d, key=lambda di: di[0])
    return d

k1 = cnt(l1)[:2]
k2 = cnt(l2)[:2]

ans = 10000000
if k1[0][0] != k2[0][0]:
    ans = n - k1[0][1] - k2[0][1]
else:
    if len(k1) == 2:
        ans = n - k1[1][1] - k2[0][1]
    if len(k2) == 2:
        ans = min(ans, n - k1[0][1] - k2[0][1])
    if ans == 10000000:
        ans = n - max(k1[0][1], k2[0][1])
print(ans)

Submission status: Wrong Answer

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

v_e_cnt = [0 for i in range(10**6)]
v_o_cnt = [0 for i in range(10**6)]
for x in range(n):
	if x % 2 == 0:
		v_e_cnt[v[x]] += 1
	else:
		v_o_cnt[v[x]] += 1

max_e = [(0,0),(0,0)]
max_o = [(0,0),(0,0)]
for i in range(10**5+1):
	if max_e[1][0] < v_e_cnt[i]:
		if max_e[0][0] < v_e_cnt[i]:
			max_e[1] = max_e[0]
			max_e[0] = (v_e_cnt[i], i)
		else:
			max_e[1] = (v_e_cnt[i], i)
	if max_o[1][0] < v_o_cnt[i]:
		if max_o[0][0] > v_o_cnt[i]:
			max_o[1] = max_o[0]
			max_o[0] = (v_o_cnt[i], i)
		else:
			max_o[1] = (v_o_cnt[i], i)

ans = n - max_e[0][0] - max_o[0][0]
if max_e[0][1] == max_o[0][1]:
	ans = n - max(max_e[0][0] + max_o[1][0], max_e[1][0] + max_o[0][0])

print(ans)

Submission status: Wrong Answer

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

v_e_cnt = [0 for i in range(10**6)]
v_o_cnt = [0 for i in range(10**6)]
for x in range(n):
	if x % 2 == 0:
		v_e_cnt[v[x]] += 1
	else:
		v_o_cnt[v[x]] += 1

max_e = [(0,0),(0,0)]
max_o = [(0,0),(0,0)]
for i in range(10**5+1):
	if max_e[1][0] < v_e_cnt[i]:
		if max_e[0][0] < v_e_cnt[i]:
			max_e[1] = max_e[0]
			max_e[0] = (v_e_cnt[i], i)
		else:
			max_e[1] = (v_e_cnt[i], i)
	if max_o[1][0] < v_o_cnt[i]:
		if max_o[0][0] > v_o_cnt[i]:
			max_o[1] = max_o[0]
			max_o[0] = (v_o_cnt[i], i)
		else:
			max_o[0] = (v_o_cnt[i], i)

ans = n - max_e[0][0] - max_o[0][0]
if max_e[0][1] == max_o[0][1]:
	ans = n - max(max_e[0][0] + max_o[1][0], max_e[1][0] + max_o[0][0])

print(ans)

Submission status: Wrong Answer

Solution code:
from sys import stdin
from collections import Counter

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

    if len(set(V)) == 1:
        print(N // 2)
        return

    even = [V[i] for i in range(N) if not i % 2]
    odd = [V[i] for i in range(N) if i % 2]
    d = []
    for i, j in zip(even, odd):
        d.append(i - j)

    counter = Counter(d)
    topn = counter.most_common()
    ans = 0
    for i in range(1, len(topn)):
        ans += topn[i][1]
    print(ans)

input = lambda: stdin.readline()
main()

Submission status: Wrong Answer

Solution code:
from collections import Counter
import numpy


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

even = a[0::2]
odd= a[1::2]
even_counter = Counter(even)
odd_counter = Counter(odd)
#print(len(even_counter.most_common()))
#print(odd_counter.most_common()[0][0])
c = even_counter.most_common()[0][0]
d = odd_counter.most_common()[0][0]

cnt = 0
if even_counter.most_common()[0][0] == odd_counter.most_common()[0][0]:
	if len(even_counter.most_common())==1 and len(odd_counter.most_common())==1:
		print(int(n/2))
		quit()
	elif len(even_counter.most_common())!=1 and len(odd_counter.most_common())==1:
		c = even_counter.most_common()[1][0]
	elif len(even_counter.most_common())==1 and len(odd_counter.most_common())!=1:
		d = odd_counter.most_common()[1][0]
	else:
		if len(even_counter.most_common())<len(odd_counter.most_common()):
			d  = odd_counter.most_common()[1][0]
		else:
			c = even_counter.most_common()[1][0]
    	
for i in range(int(n/2)):
	if a[i*2] != c:
		cnt = cnt+1
	if a[i*2+1] != d:
		cnt = cnt+1
#print(c)
print(cnt)

Submission status: Wrong Answer

Solution code:
import collections
n=int(input())
v = list(map(int,input().split()))
od=[]
ev=[]
k=n/2
cev=0
cod=0

for i in range(0,n,2):
  ev.append(v[i])
  od.append(v[i+1])

ev.sort()
od.sort()

c=collections.Counter(ev)
d=collections.Counter(od)
e=c.most_common()[0][1]
f=d.most_common()[0][1]

if c.most_common()[0][0]==d.most_common()[0][0]:
  e=int(k)
  f=0

print(n-e-f)

Submission status: Wrong Answer

Solution code:
from collections import Counter
import numpy


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

even = a[0::2]
odd= a[1::2]
even_counter = Counter(even)
odd_counter = Counter(odd)
#print(len(even_counter.most_common()))
#print(odd_counter.most_common()[0][0])
c = even_counter.most_common()[0][0]
d = odd_counter.most_common()[0][0]

cnt = 0
if even_counter.most_common()[0][0] == odd_counter.most_common()[0][0]:
	if len(even_counter.most_common())==1 and len(odd_counter.most_common())==1:
		print(int(n/2))
		quit()
	elif len(even_counter.most_common())!=1 and len(odd_counter.most_common())==1:
		c = even_counter.most_common()[1][0]
	elif len(even_counter.most_common())==1 and len(odd_counter.most_common())!=1:
		d = odd_counter.most_common()[1][0]

    	
for i in range(int(n/2)):
	if a[i*2] != c:
		cnt = cnt+1
	if a[i*2+1] != d:
		cnt = cnt+1
#print(c)
print(cnt)

Submission status: Wrong Answer

Solution code:
from sys import stdin

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

    if len(set(V)) == 1:
        print(N // 2)
        return

    ans = 0
    for i in range(0, N - 2, 4):
        if V[i] != V[i+2]:
            ans += 1
        if i + 3 < N:
            if V[i+1] != V[i+3]:
                ans += 1
    print(ans)

input = lambda: stdin.readline()
main()

Submission status: Wrong Answer

Solution code:
import os
import sys
import operator
def solve():
  n = int(input())
  s = {}
  k = {}
  for i, x in enumerate(list(map(int, input().split(' ')))):
    if i % 2 == 0:
      s[x] = s.get(x, 0) + 1
    else:
      k[x] = k.get(x, 0) + 1
  s = sorted(s.items(), key=operator.itemgetter(1), reverse=True)
  k = sorted(k.items(), key=operator.itemgetter(1), reverse=True)
  if s[0][0] != k[0][0]:
    return (n / 2 - s[0][1]) + (n / 2 - k[0][1])
  else:
    if s[0][1] == n / 2 and k[0][1] == n / 2:
      return n / 2
    if s[0][1] > k[0][1]:
      return (n / 2 - s[0][1]) + (n / 2 - k[1][1])
    else:
      return (n / 2 - s[1][1]) + (n / 2 - k[0][1])
print(int(solve()))

Submission status: Wrong Answer

Solution code:
from collections import Counter
import numpy


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

even = a[0::2]
odd= a[1::2]
even_counter = Counter(even)
odd_counter = Counter(odd)
#print(len(even_counter.most_common()))
#print(odd_counter.most_common()[0][0])
c = even_counter.most_common()[0][0]
d = odd_counter.most_common()[0][0]

cnt = 0
if even_counter.most_common()[0][0] == odd_counter.most_common()[0][0]:
	if len(even_counter.most_common())==1 and len(odd_counter.most_common())==1:
		print(int(n/2))
		quit()
	elif len(even_counter.most_common())!=1 and len(odd_counter.most_common())==1:
		c = even_counter.most_common()[0][1]
	elif len(even_counter.most_common())==1 and len(odd_counter.most_common())!=1:
		d = odd_counter.most_common()[0][1]

    	
for i in range(int(n/2)):
	if a[i*2] != c:
		cnt = cnt+1
	if a[i*2-1] != d:
		cnt = cnt+1
       
print(cnt)

Submission status: Wrong Answer

Solution code:
from collections import Counter

n = int(input())
V = [int(_) for _ in input().split()]


def main():
    A = V[::2]
    B = V[1::2]

    print(A)
    print(B)

    resA = Counter(A).most_common()
    resB = Counter(B).most_common()

    if resA[0][0] == resB[0][0]:

        if resA[0][1] > resB[0][1]:
            sumA = sum([num for x, num in resA[1:]])
            sumB = resB[0][1] + sum([num for x, num in resB[2:]])
            print(sumA + sumB)
        elif resA[0][1] < resA[0][1]:
            sumB = sum([num for x, num in resB[1:]])
            sumA = resA[0][1] + sum([num for x, num in resA[2:]])
            print(sumA + sumB)
        else:
            if len(resA) == 1 and len(resB) == 1:
                print(n // 2)
            else:
                if resA[1][1] > resB[1][1]:
                    sumB = sum([num for x, num in resB[1:]])
                    sumA = resA[0][1] + sum([num for x, num in resA[2:]])
                    print(sumA + sumB)
                else:
                    sumA = sum([num for x, num in resA[1:]])
                    sumB = resB[0][1] + sum([num for x, num in resB[2:]])
                    print(sumA + sumB)
    else:
        if len(resA) == 1 and len(resB) == 1:
            print(0)
        else:
            sumA = sum([num for x, num in resA[1:]])
            sumB = sum([num for x, num in resB[1:]])
            print(sumA + sumB)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
# 
import math
import sys
import itertools
import numpy as np


# いっこ入力
n =int(input())

# 空白区切りの数列をリストに代入
v = [int(i) for i in input().split()]

a = {v[0]:1}
b = {v[1]:1}
for i in range(2,n,2):
#    print(a)
    if v[i] in a:
        a[v[i]] += 1
    else:
        a[v[i]] = 1
    if v[i+1] in b:
        b[v[i+1]] += 1
    else:
        b[v[i+1]] = 1
    
#print(a,b)

max_a = max(a, key = a.get)
a1 = max(a.values())
max_b = max(b, key = b.get)
b1 = max(b.values())

if a1 == n // 2:
    a2=0
else:
    a[max_a]=0
    a2 = max(a.values())

if b1 == n // 2:
    b2=0
else:
    b[max_b]=0
    b2 = max(b.values())

c = a1+b2
d = a2+b1

#print(max_a,max_b,max_an,max_bn)
"""
if max_a == max_b:
    if a[max_a] > b[max_b]:
        b[max_b]= 0
        max_bn = max(b.values())
    else:
        a[max_a]= 0
        max_an = max(a.values())
"""
print(n-max(c,d))

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
# coding: utf-8
#

import collections

def main(n, a):

    if 0 == n%2:
        even_list = [a[2*i] for i in range(0, int(n/2))]
        odd_list = [a[2*i+1] for i in range(0, int(n/2))]
    else:
        even_list = [a[2*i] for i in range(0, int(n/2)+1)]
        odd_list = [a[2*i+1] for i in range(0, int(n/2))]
        
    if len(set(even_list)) == 1 and len(set(odd_list)) == 1:
        if even_list[0] == odd_list[0]:
            print(int(n/2))
        else:
            print(0)
        return
            
    # print(even_list)
    # print(odd_list)
    col_even = collections.Counter(even_list)
    col_odd = collections.Counter(odd_list)
    sort_col_even = sorted(col_even.items(), key = lambda x: -x[1])
    sort_col_odd  = sorted(col_odd.items(),  key = lambda x: -x[1])
    # print(sort_col_even)
    # print(sort_col_odd)
    
    if sort_col_even[0][0] != sort_col_odd[0][0]:
        retval = n - ( sort_col_even[0][1] + sort_col_odd[0][1])
        print(retval)
    else:
        if len(sort_col_even) != 1 and len(sort_col_odd) != 1:
            if sort_col_even[1][0] >= sort_col_odd[1][0]:
                retval = n - ( sort_col_even[0][1] + sort_col_odd[1][1])
            else:
                retval = n - ( sort_col_even[1][1] + sort_col_odd[0][1])
        else:
            if len(sort_col_even) == 1:
                retval = n - ( sort_col_even[0][1] + sort_col_odd[1][1])
            else:
                retval = n - ( sort_col_even[1][1] + sort_col_odd[0][1])
        print(retval)
        
            
if __name__ == '__main__':
    try:
        n = int(input().strip())
        a  = list(map(int,input().strip().split(' ')))
        main(n, a)
    except EOFError:
        pass

Submission status: Wrong Answer

Solution code:
from sys import stdin
from collections import Counter

input = lambda: stdin.readline()

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

    if set(V) == 1:
        print(N // 2)
        return

    d = []
    for i in range(N - 1):
        d.append(abs(V[i] - V[i+1]))
    counter = Counter(d)
    topn = counter.most_common()
    ans = 0
    for i in range(1, len(topn)):
        ans += topn[i][1]
    print(ans)

main()

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
# 
import math
import sys
import itertools
import numpy as np


# いっこ入力
n =int(input())

# 空白区切りの数列をリストに代入
v = [int(i) for i in input().split()]

a = {v[0]:1}
b = {v[1]:1}
for i in range(2,n,2):
#    print(a)
    if v[i] in a:
        a[v[i]] += 1
    else:
        a[v[i]] = 1
    if v[i+1] in b:
        b[v[i+1]] += 1
    else:
        b[v[i+1]] = 1
    
#print(a,b)

max_a = max(a, key = a.get)
max_an = max(a.values())
max_b = max(b, key = b.get)
max_bn = max(b.values())

#print(max_a,max_b,max_an,max_bn)
if max_a == max_b:
    if max_an == n // 2: # || max_bn == n // 2:
        print(n - max_bn)
        exit
    elif max_bn == n // 2:
        print(n - max_an)
        exit
    elif a[max_a] > b[max_b]:
        b[max_b]= 0
        max_bn = max(b.values())
    else:
        a[max_a]= 0
        max_an = max(a.values())

print(n - max_an - max_bn)

Submission status: Wrong Answer

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

v1 = {}
v2 = {}
for i in range(len(v)):
    if(i % 2 == 0):
        if((v[i] in v1) == True):
            v1[v[i]] += 1
        else:
            v1[v[i]] = 1
    else: 
        if((v[i] in v2) == True):
            v2[v[i]] += 1
        else:
            v2[v[i]] = 1

max_k1 = max(v1, key=v1.get)
max_k2 = max(v2, key=v2.get)

if(max_k1 == max_k2):
    if(v1[max_k1] > v2[max_k2]):
        v2[max_k2] = 0
        max_k2 = max(v2, key=v2.get)
    else:
        v1[max_k1] = 0
        max_k1 = max(v1, key=v1.get)

ans = n // 2 - v1[max_k1]
ans += n // 2 - v2[max_k2]

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

_ = input()
ns = list(map(int, input().split()))

# ns = [4, 1, 3, 2]

xs = ns[0::2]
ys = ns[1::2]

ans = 0
counts = defaultdict(int)
for x in xs:
    counts[x] += 1

max_numx = -1
max_x = -1
for key in counts.keys():
    if counts[key] > max_numx:
        max_numx = counts[key]
        max_x = key

del counts[max_x]
if counts:
    max_numx2 = max(counts.values())
else:
    max_numx2 = 0

counts = defaultdict(int)
for y in ys:
    counts[y] += 1
max_numy = -1
max_y = -1
for key in counts.keys():
    if counts[key] > max_numy:
        max_numy = counts[key]
        max_y = key

del counts[max_y]
if counts:
    max_numy2 = max(counts.values())
else:
    max_numy2 = 0

if max_x != max_y:
    print(len(ns) - max_numx - max_numy)
elif max_numx >= max_numy:
    print(len(ns) - max_numx - max_numy2)
else:
    print(len(ns) - max_numx2 - max_numy)

Submission status: Wrong Answer

Solution code:
from sys import stdin
il = lambda func=int: list(map(func, stdin.readline().rstrip().split()))
ils = lambda n, s="int(input())": [eval(s) for _ in range(n)]

n = int(input())
v = il()
a = dict()
b = dict()
for i in range(n):
    if i&1:
        if v[i] in a:
            a[v[i]] += 1
        else:
            a[v[i]] = 1
    else:
        if v[i] in b:
            b[v[i]] += 1
        else:
            b[v[i]] = 1
ans = 0
a = sorted(a.items(), key=lambda x:x[1])
b = sorted(b.items(), key=lambda x:x[1])
A, B = 0, 0
flag = 1
if a[-1][0] == b[-1][0]:
    if len(a) == 1 and len(b) == 1:
        ans += min(a[-1][1], b[-1][1])
        flag = 0
    elif len(a) == 1:
        B += 1
    elif len(b) == 1:
        A += 1
    else:
        if a[-2][1] > b[-2][1]:
            B += 1
        else:
            A += 1
if flag:
    if len(a) > 1:
        ans += n//2 - a[-1-A][1]
    if len(b) > 1:
        ans += n//2 - b[-1-B][1]
print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
# coding: utf-8
#

import collections

def main(n, a):

    if 0 == n%2:
        even_list = [a[2*i] for i in range(0, int(n/2))]
        odd_list = [a[2*i+1] for i in range(0, int(n/2))]
    else:
        even_list = [a[2*i] for i in range(0, int(n/2)+1)]
        odd_list = [a[2*i+1] for i in range(0, int(n/2))]
        
    if len(set(even_list)) == 1 and len(set(odd_list)) == 1:
        if even_list[0] == odd_list[0]:
            print(int(n/2))
        else:
            print(0)
        return
            
    # print(even_list)
    # print(odd_list)
    col_even = collections.Counter(even_list)
    col_odd = collections.Counter(odd_list)
    sort_col_even = sorted(col_even.items(), key = lambda x: -x[1])
    sort_col_odd  = sorted(col_odd.items(),  key = lambda x: -x[1])
    # print(sort_col_even)
    # print(sort_col_odd)
    
    if sort_col_even[0][0] != sort_col_odd[0][0]:
        retval = n - ( sort_col_even[0][1] + sort_col_odd[0][1])
        print(retval)
    else:
        if sort_col_even[1][0] >= sort_col_odd[1][0]:
            retval = n - ( sort_col_even[0][1] + sort_col_odd[1][1])
        else:
            retval = n - ( sort_col_even[1][1] + sort_col_odd[0][1])
        print(retval)
        
            
if __name__ == '__main__':
    try:
        n = int(input().strip())
        a  = list(map(int,input().strip().split(' ')))
        main(n, a)
    except EOFError:
        pass

Submission status: Wrong Answer

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

f = {}
b = {}

fcnt = 0
bcnt = 0
for v in vv:
    if fcnt == bcnt:
        if v in f:
            f[v] += 1
        else:
            f[v] = 1
        fcnt += 1
    else:
        if v in b:
            b[v] += 1
        else:
            b[v] = 1
        bcnt += 1


ff = sorted(list(map(lambda x: tuple(reversed(x)), f.items())), reverse = True)
bb = sorted(list(map(lambda x: tuple(reversed(x)), b.items())), reverse = True)

if ff[0][0] < bb[0][0]:
    ff, bb = bb, ff

if ff[0][1] != bb[0][1]:
    print(n - ff[0][0] - bb[0][0])
else:
    if len(bb) == 1:
        print(n - ff[0][0])
    else:
        print(n - ff[0][0] - bb[1][0])

Submission status: Wrong Answer

Solution code:
import numpy as np
n = int(input())
v = np.array(list(map(int,input().split())))
v1 = v.reshape(n//2,2)[:,0]
v2 = v.reshape(n//2,2)[:,1]
v1_unique = np.unique(v1)
v2_unique = np.unique(v2)
# 先に数字次に個数（新居まで）
maxs1 = [0,0,0,0]
ma = 0
for i in range(v1_unique.shape[0]):
    num = v1[v1 == v1_unique[i]].shape[0]
    if(num > maxs1[1]):
        maxs1[0] = v1_unique[i]
        maxs1[1] = num
    elif(num > maxs1[3]):
        maxs1[2] = v1_unique[i]
        maxs1[3] = num
maxs2 = [0,0,0,0]
for i in range(v2_unique.shape[0]):
    num = v2[v2 == v2_unique[i]].shape[0]
    if(num > maxs2[1]):
        maxs2[0] = v2_unique[i]
        maxs2[1] = num
    elif(num > maxs2[3]):
        maxs2[2] = v2_unique[i]
        maxs2[3] = num
if(maxs1[0] != maxs2[0]):
    ma = n - maxs1[1] - maxs2[1]
elif((maxs1[1] + maxs2[3]) > (maxs2[1]+ maxs1[3])):
    ma = n - maxs1[1] - maxs2[3]
else:
    ma = n - maxs2[1] - maxs1[3]
print(ma)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
# 
import math
import sys
import itertools
import numpy as np


# いっこ入力
n =int(input())

# 空白区切りの数列をリストに代入
v = [int(i) for i in input().split()]

a = {v[0]:1}
b = {v[1]:1}
for i in range(2,n,2):
#    print(a)
    if v[i] in a:
        a[v[i]] += 1
    else:
        a[v[i]] = 1
    if v[i+1] in b:
        b[v[i+1]] += 1
    else:
        b[v[i+1]] = 1
    
#print(a,b)

max_a = max(a, key = a.get)
max_an = max(a.values())
max_b = max(b, key = b.get)
max_bn = max(b.values())

#print(max_a,max_b,max_an,max_bn)
if max_a == max_b:
    if a[max_a] > b[max_b]:
        b[max_b]= 0
        max_bn = max(b.values())
    else:
        a[max_a]= 0
        max_an = max(a.values())

print(n - max_an - max_bn)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
# coding: utf-8
#

import collections

def main(n, a):
    
    even_list = [a[2*i] for i in range(0, int(n/2))]
    odd_list = [a[2*i+1] for i in range(0, int(n/2))]

    if len(set(even_list)) == 1 and len(set(odd_list)) == 1:
        if even_list[0] == odd_list[0]:
            print(int(n/2))
        else:
            print(0)
        return
            
    # print(even_list)
    # print(odd_list)
    col_even = collections.Counter(even_list)
    col_odd = collections.Counter(odd_list)
    sort_col_even = sorted(col_even.items(), key = lambda x: -x[1])
    sort_col_odd  = sorted(col_odd.items(),  key = lambda x: -x[1])
    # print(sort_col_even)
    # print(sort_col_odd)
    
    if sort_col_even[0][0] != sort_col_odd[0][0]:
        retval = n - ( sort_col_even[0][1] + sort_col_odd[0][1])
        print(retval)
    else:
        if sort_col_even[1][0] >= sort_col_odd[1][0]:
            retval = n - ( sort_col_even[0][1] + sort_col_odd[1][1])
        else:
            retval = n - ( sort_col_even[1][1] + sort_col_odd[0][1])
        print(retval)
        
            
if __name__ == '__main__':
    try:
        n = int(input().strip())
        a  = list(map(int,input().strip().split(' ')))
        main(n, a)
    except EOFError:
        pass

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
# coding: utf-8
#

import collections

def main(n, a):
    
    even_list = [a[2*i] for i in range(0, int(n/2))]
    odd_list = [a[2*i+1] for i in range(0, int(n/2))]

    if len(set(even_list)) == 1 and len(set(odd_list)) == 1:
        if even_list[0] == odd_list[0]:
            print(int(n/2))
        else:
            print(1)
        return
            
    # print(even_list)
    # print(odd_list)
    col_even = collections.Counter(even_list)
    col_odd = collections.Counter(odd_list)
    sort_col_even = sorted(col_even.items(), key = lambda x: -x[1])
    sort_col_odd  = sorted(col_odd.items(),  key = lambda x: -x[1])
    # print(sort_col_even)
    # print(sort_col_odd)
    
    if sort_col_even[0][0] != sort_col_odd[0][0]:
        retval = n - ( sort_col_even[0][1] + sort_col_odd[0][1])
        print(retval)
    else:
        if sort_col_even[1][0] >= sort_col_odd[1][0]:
            retval = n - ( sort_col_even[0][1] + sort_col_odd[1][1])
        else:
            retval = n - ( sort_col_even[1][1] + sort_col_odd[0][1])
        print(retval)
        
            
if __name__ == '__main__':
    try:
        n = int(input().strip())
        a  = list(map(int,input().strip().split(' ')))
        main(n, a)
    except EOFError:
        pass

Submission status: Wrong Answer

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

f = {}
b = {}

fcnt = 0
bcnt = 0
for v in vv:
    if fcnt == bcnt:
        if v in f:
            f[v] += 1
        else:
            f[v] = 1
        fcnt += 1
    else:
        if v in b:
            b[v] += 1
        else:
            b[v] = 1
        bcnt += 1


ff = sorted(list(map(lambda x: tuple(reversed(x)), f.items())), reverse = True)
bb = sorted(list(map(lambda x: tuple(reversed(x)), b.items())), reverse = True)

if ff[0][1] != bb[0][1]:
    print(n - ff[0][0] - bb[0][0])
else:
    print(n - max(ff[0][0], bb[0][0]))

Submission status: Wrong Answer

Solution code:
from sys import stdin

input = lambda: stdin.readline()

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

    d = set()
    for i in range(N - 1):
        d.add(abs(V[i] - V[i+1]))
    if len(d) == 1:
        if 0 in d:
            print(N // 2)
        else:
            print(0)
    else:
        print(len(d) - 1)

main()