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:
#!/usr/bin/env python3
import sys
import statistics
import collections

def solve(n: int, v: "List[int]"):
    half_length = len(v) // 2
    O = [v[i] for i in range(1, n, 2)]
    E = [v[i] for i in range(0, n, 2)]

    co = list(collections.Counter(O).most_common())
    ce = list(collections.Counter(E).most_common())
    o1 = co[0][0]
    e1 = ce[0][0]

    O_ = list(filter(lambda o: o != o1, O))
    E_ = list(filter(lambda e: e != e1, E))
    num_o_1 = len(O_) 
    num_e_1 = len(E_)

    if e1 != o1:
        num = num_o_1 + num_e_1
    else:
        if True:
            num = half_length
        elif len(co) == 1:
            e2 = ce[1][0]
            num_e_2 = len(list(filter(lambda e: e != e2, E)))
            num = num_o_1 + num_e_2
        elif len(ce) == 1:
            o2 = co[1][0]
            num_o_2 = len(list(filter(lambda o: o != o2, O)))
            num = num_o_2 + num_e_1
        else:
            e2 = ce[1][0]
            o2 = co[1][0]
            num = min(num_o_1 + num_e_2, num_o_2 + num_e_1)
    num = 0
    print(num)
    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
import statistics
import collections

def solve(n: int, v: "List[int]"):
    half_length = len(v) // 2
    O = [v[i] for i in range(1, n, 2)]
    E = [v[i] for i in range(0, n, 2)]

    co = list(collections.Counter(O).most_common())
    ce = list(collections.Counter(E).most_common())
    o1 = co[0][0]
    e1 = ce[0][0]

    O_ = list(filter(lambda o: o != o1, O))
    E_ = list(filter(lambda e: e != e1, E))
    num_o_1 = len(O_) 
    num_e_1 = len(E_)

    print(0)
    return

    if e1 != o1:
        num = num_o_1 + num_e_1
    else:
        if len(co) == 1 and len(ce) == 1:
            num = half_length
        elif len(co) == 1:
            e2 = ce[1][0]
            num_e_2 = len(list(filter(lambda e: e != e2, E)))
            num = num_o_1 + num_e_2
        elif len(ce) == 1:
            o2 = co[1][0]
            num_o_2 = len(list(filter(lambda o: o != o2, O)))
            num = num_o_2 + num_e_1
        else:
            e2 = ce[1][0]
            o2 = co[1][0]
            num = min(num_o_1 + num_e_2, num_o_2 + num_e_1)
    print(num)
    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:
import collections

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

#print(even)
#print(odd)

if v[0::2] == v[1::2]:
    print(len(v[0::2]),end='')
else:
    e = 0
    o = 0
    count = 1
    while(1):
        if count != 1 and count % 2 == 0:
            e += 1
        elif count != 1:
            o += 1
        
        #print(even.most_common()[e][0])
        #print(odd.most_common()[o][0])
        
        if even.most_common()[e][0] != odd.most_common()[o][0]:
            ans1 = len(v)/2 - even.most_common()[e][1]
            ans2 = len(v)/2 - odd.most_common()[o][1]
            break
        count += 1
        
    print(int(ans1 + ans2),end='')

Submission status: Wrong Answer

Solution code:
import collections

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

ans1 = len(v)/2 - even.most_common()[0][1]
ans2 = len(v)/2 - odd.most_common()[0][1]

if v[0::2] == v[1::2]:
    print(len(v[0::2]),end='')
else:
    print(int(ans1 + ans2),end='')

Submission status: Wrong Answer

Solution code:
import collections

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

ans1 = int((len(v)/2)) - even.most_common()[0][1]
ans2 = int((len(v)/2)) - odd.most_common()[0][1]

if v[0::2] == v[1::2]:
    print(len(v[0::2]),end='')
else:
    print(ans1 + ans2,end='')

Submission status: Wrong Answer

Solution code:
import collections

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

ans1 = int((len(v)/2)) - even.most_common()[0][1]
ans2 = int((len(v)/2)) - odd.most_common()[0][1]

if v[0::2] == v[1::2]:
    print(2,end='')
else:
    print(ans1 + ans2,end='')

Submission status: Wrong Answer

Solution code:
n = int(input())
v = list(map(int,input().split()))
even = v[0::2]
se =  list(set(even))
odd = v[1::2]
oe = list(set(odd))
enum = 0
onum = 0

for item in se:
    if enum < even.count(item):
        enum = even.count(item)
ans1 = len(even) - enum

for item in oe:
    if onum < odd.count(item):
        onum = odd.count(item)
ans2 = len(odd) - onum

if even == odd:
    print(2,end='')
else:
    print(ans1 + ans2,end='')

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int,input().split()))
d0={}
for a in A[::2]:d0[a]=d0.get(a,0)+1
d0=sorted([(k,v) for k,v in d0.items()],key=lambda x:-x[1])
d1={}
for a in A[1::2]:d1[a]=d1.get(a,0)+1
d1=sorted([(k,v) for k,v in d1.items()],key=lambda x:-x[1])
if d0[0][0]!=d1[0][0]:print(N-d0[0][1]-d1[0][1]);exit()
m=[N//2]
if len(d0)>1:m+=[N//2-d0[1][1]]
if len(d1)>1:m+=[N//2-d1[1][1]]
print(min(m))

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int,input().split()))
d0={}
for a in A[::2]:d0[a]=d0.get(a,0)+1
d0=sorted([(k,v) for k,v in d0.items()],key=lambda x:-x[1])
d1={}
for a in A[1::2]:d1[a]=d1.get(a,0)+1
d1=sorted([(k,v) for k,v in d1.items()],key=lambda x:-x[1])
m=[N//2]
if d0[0][0]!=d1[0][0]:m+=[N-d0[0][1]-d1[0][1]]
if len(d0)>1:m+=[N//2-d0[1][1]]
if len(d1)>1:m+=[N//2-d1[1][1]]
print(min(m))

Submission status: Wrong Answer

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

even = []
odd = []

for i in range(n//2):
    even.append(v[2*i])
    odd.append(v[2*i+1])

def count(list):
    list.sort()
    keepcount = 0
    count = 0
    maxcount = 0
    for i in list:
        if maxcount == 0:
            keepcount = i
            count = 1
            maxcount = 1
        elif keepcount == i:
            count += 1
            maxcount = max(maxcount,count)
        else:
            keepcount = i
            count = 1
            maxcount = max(maxcount,count)
    return maxcount

if len(set(v)) != 1:
    print(len(v) - count(even) - count(odd))
else:
    print(len(v)//2)

Submission status: Wrong Answer

Solution code:
n = int(input())

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

odd = [data[i] for i in range(0,n,2)]
even = [data[i] for i in range(1,n,2)]

odd_dict = dict({})
even_dict = dict({})

for i in range(n//2):
    if odd_dict.__contains__(odd[i]):
        odd_dict[odd[i]]+=1
    else:
        odd_dict[odd[i]] = 1
    if even_dict.__contains__(even[i]):
        even_dict[even[i]]+=1
    else:
        even_dict[even[i]] = 1

odd = sorted(odd_dict.items(), key=lambda d:d[1])
even = sorted(even_dict.items(), key=lambda d:d[1])

odd.append((0,0))
even.append((0,0))
if odd[0][0] == even[0][0]:
    print(min(n-odd[0][1]-even[1][1],n-odd[1][1]-even[0][1]))
else:
    print(n-odd[0][1]-even[0][1])

Submission status: Wrong Answer

Solution code:
n = int(input())

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

odd = [data[i] for i in range(0,n,2)]
even = [data[i] for i in range(1,n,2)]

odd_dict = dict({})
even_dict = dict({})

for i in range(n//2):
    if odd_dict.__contains__(odd[i]):
        odd_dict[odd[i]]+=1
    else:
        odd_dict[odd[i]] = 1
    if even_dict.__contains__(even[i]):
        even_dict[even[i]]+=1
    else:
        even_dict[even[i]] = 1

odd = sorted(odd_dict.items(), key=lambda d:d[1])
even = sorted(even_dict.items(), key=lambda d:d[1])

if odd[0][0] == even[0][0]:
    if odd[0][1] == n//2:
        print(n//2)
    else:
        print(min(n-odd[0][1]-even[1][1],n-odd[1][1]-even[0][1]))
else:
    print(n-odd[0][1]-even[0][1])

Submission status: Wrong Answer

Solution code:
n = int(input())

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

odd = [data[i] for i in range(0,n,2)]
even = [data[i] for i in range(1,n,2)]

odd_dict = dict({})
even_dict = dict({})

for i in range(n//2):
    if odd_dict.__contains__(odd[i]):
        odd_dict[odd[i]]+=1
    else:
        odd_dict[odd[i]] = 1
    if even_dict.__contains__(even[i]):
        even_dict[even[i]]+=1
    else:
        even_dict[even[i]] = 1

odd = sorted(odd_dict.items(), key=lambda d:d[1])
even = sorted(even_dict.items(), key=lambda d:d[1])

if odd[0][0] == even[0][0]:
    if odd[0][1] > even[0][1]:
        # find next
        print(n-odd[0][1]-even[1][1])
    elif odd[0][1] == even[0][1]:
        if odd[0][1] == n//2:
            print(n-odd[0][1])
        else:
            print(n-odd[0][1]-even[1][1])
    else:
        print(n-odd[1][1]-even[0][1])
else:
    print(n-odd[0][1]-even[0][1])

Submission status: Wrong Answer

Solution code:
n = int(input())

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

odd = [data[i] for i in range(0,n,2)]
even = [data[i] for i in range(1,n,2)]

odd_dict = dict({})
even_dict = dict({})

for i in range(n//2):
    if odd_dict.__contains__(odd[i]):
        odd_dict[odd[i]]+=1
    else:
        odd_dict[odd[i]] = 1
    if even_dict.__contains__(even[i]):
        even_dict[even[i]]+=1
    else:
        even_dict[even[i]] = 1

odd = sorted(odd_dict.items(), key=lambda d:d[1])
even = sorted(even_dict.items(), key=lambda d:d[1])

print(n-odd[0][1]-even[0][1])

Submission status: Wrong Answer

Solution code:
# https://atcoder.jp/contests/abc111/tasks/arc103_a

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

f_l = v[::2]
s_l = v[1::2]

f_dict = {}
for f in f_l:
    if f not in f_dict:
        f_dict[f] = 1
    else:
        f_dict[f] += 1


s_dict = {}
for s in s_l:
    if s not in s_dict:
        s_dict[s] = 1
    else:
        s_dict[s] += 1

f_sorted = sorted(f_dict.items(), key=lambda x: -x[1])
s_sorted = sorted(s_dict.items(), key=lambda x: -x[1])


i = f_sorted[0]
j = s_sorted[0]
# print(f_sorted)
# print(s_sorted)

i = 0
j = 0

while i < len(f_sorted) and j < len(s_sorted):
    if f_sorted[i][0] == s_sorted[j][0]:  # 同じ値だったら使えない
        if f_sorted[i][1] > s_sorted[j][1]:
            j += 1
        else:
            i += 1
    else:
        break

if i == len(f_sorted):
    print(n - s_sorted[j][1])
elif j == len(s_sorted):
    print(n - f_sorted[i][1])
else:
    print(n - f_sorted[i][1] - s_sorted[j][1])

Submission status: Wrong Answer

Solution code:
import collections

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

nod = collections.Counter(l[0::2]).most_common()
even = collections.Counter(l[1::2]).most_common()

if len(set(l)) == 1:
    ans = n // 2
else:
    if nod[0][0] == even[0][0]:
        ans = n - max(nod[0][1], nod[1][1], even[0][1], even[1][1])
    else:
        ans = n - nod[0][1] - even[0][1]

print(ans)

Submission status: Wrong Answer

Solution code:
import collections

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

nod = collections.Counter(l[0::2])
even = collections.Counter(l[1::2])

if nod.most_common()[0][0] == even.most_common()[0][0]:
    if len(nod) == 1 and len(even) == 1:
        ans = int(len(l) / 2)
    elif nod.most_common()[0][1] > even.most_common()[0][1]:
        ans = len(l)- nod.most_common()[0][1] - even.most_common()[1][1]
    else:
        ans = len(l)- nod.most_common()[1][1] - even.most_common()[0][1]
else:
    ans = len(l)- nod.most_common()[0][1] - even.most_common()[0][1]

print(ans)

Submission status: Wrong Answer

Solution code:
import collections

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

nod = collections.Counter(l[0::2])
even = collections.Counter(l[1::2])

print(nod.most_common()[0][0])
print(even.most_common()[0][0] )

if nod.most_common()[0][0] == even.most_common()[0][0]:
    if len(nod) == 1 and len(even) == 1:
        ans = int(len(l) / 2)
    elif nod.most_common()[0][1] > even.most_common()[0][1]:
        ans = len(l)- nod.most_common()[0][1] - even.most_common()[1][1]
    else:
        ans = len(l)- nod.most_common()[1][1] - even.most_common()[0][1]
else:
    ans = len(l)- nod.most_common()[0][1] - even.most_common()[0][1]

print(ans)

Submission status: Wrong Answer

Solution code:
import collections

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

nod = collections.Counter(l[0::2])
even = collections.Counter(l[1::2])

ans = len(l)- nod.most_common()[0][1] - even.most_common()[0][1]

if ans == 0 and len(nod) == 1 and len(even) ==1:
    ans = int(len(l) / 2)

print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
n=N//2
L=list(map(int,input().split()))
A=0
B=0

def proj_to_ntimes(x):
  if x%n==0:
    return x
  else:
    if x%n<=(n-x%n):
    	return x - (x%n)
    else:
      return x+n-x%n
  

for i in range(n):
  A+=L[2*i]
  B+=L[2*i+1]

a=[A%n,n-A%n]
b=[B%n,n-B%n]

if proj_to_ntimes(A)!=proj_to_ntimes(B):
  print(min(a)+min(b))
else:
  print(min(min(a)+max(b),max(a)+min(b)))

Submission status: Wrong Answer

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

import math
import sys
import heapq
from operator import itemgetter
import itertools
input = sys.stdin.readline

# a = int(input().rstrip())
# a, b = map(int, input().rstrip().split())
# D = list(map(int, input().rstrip().split()))
# H = [int(input().rstrip()) for _ in range(L)]
# DD = [[0 for j in range(100)] for i in range(200)]
# dict = {} ## dictionary

# a = sorted(a, key=lambda x: x[1]))
# if __name__ == '__main__':

n = int(input().rstrip())
v = list(map(int, input().rstrip().split()))
v_even = dict()
v_odd = dict()

def solve(d1, d2):
	d1_max, d2_max = [0, 0], [0, 0]
	d1_max_nxt, d2_max_nxt = 0, 0

	for i in d1:
		if d1[i] >= d1_max[1]:
			d1_max_nxt = d1_max[1]
			d1_max = [i, d1[i]]
	for i in d2:
		if d2[i] >= d2_max[1]:
			d2_max_nxt = d2_max[1]
			d2_max = [i, d2[i]]

	if (d1_max[0] != d2_max[0]):
		return(n - d1_max[1] - d2_max[1])
	else:
		return(min(n - d1_max[1] - d2_max_nxt, n - d2_max[1] - d1_max_nxt))
	

for i in range(len(v)):
	if i % 2 == 0:
		if v[i] not in v_even:
			v_even[v[i]] = 1
		else:
			v_even[v[i]] += 1
	else:
		if v[i] not in v_odd:
			v_odd[v[i]] = 1
		else:
			v_odd[v[i]] += 1
	
print(solve(v_even, v_odd))

Submission status: Wrong Answer

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

import math
import sys
import heapq
from operator import itemgetter
import itertools
input = sys.stdin.readline

# a = int(input().rstrip())
# a, b = map(int, input().rstrip().split())
# D = list(map(int, input().rstrip().split()))
# H = [int(input().rstrip()) for _ in range(L)]
# DD = [[0 for j in range(100)] for i in range(200)]
# dict = {} ## dictionary

# a = sorted(a, key=lambda x: x[1]))
# if __name__ == '__main__':

n = int(input().rstrip())
v = list(map(int, input().rstrip().split()))
v_even = dict()
v_odd = dict()

def solve(d1, d2):
	d1_max = [[0, 0], [0, 0]]
	d2_max = [[0, 0], [0, 0]]
	for i in d1:
		if d1_max[0][1] <= d1[i]:
			d1_max[1] = d1_max[0]
			d1_max[0] = [i, d1[i]]
	for i in d2:
		if d2_max[0][1] <= d2[i]:
			d2_max[1] = d2_max[0]
			d2_max[0] = [i, d2[i]]

	print(d1_max)
	print(d2_max)

	if d1_max[0][0] != d2_max[0][0]:
		return(n - d1_max[0][1]- d2_max[0][1])
	else:
		return(min(n - d1_max[1][1]- d2_max[0][1], n - d1_max[0][1]- d2_max[1][1]))

for i in range(len(v)):
	if i % 2 == 0:
		if v[i] not in v_even:
			v_even[v[i]] = 1
		else:
			v_even[v[i]] += 1
	else:
		if v[i] not in v_odd:
			v_odd[v[i]] = 1
		else:
			v_odd[v[i]] += 1
	
print(solve(v_even, v_odd))

Submission status: Wrong Answer

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

import math
import sys
import heapq
from operator import itemgetter
import itertools
input = sys.stdin.readline

# a = int(input().rstrip())
# a, b = map(int, input().rstrip().split())
# D = list(map(int, input().rstrip().split()))
# H = [int(input().rstrip()) for _ in range(L)]
# DD = [[0 for j in range(100)] for i in range(200)]
# dict = {} ## dictionary

# a = sorted(a, key=lambda x: x[1]))
# if __name__ == '__main__':

n = int(input().rstrip())
v = list(map(int, input().rstrip().split()))
v_even = dict()
v_odd = dict()

def solve(d1, d2):
	d1_max = [[0, 0], [0, 0]]
	d2_max = [[0, 0], [0, 0]]
	for i in d1:
		if d1_max[0][1] < d1[i]:
			d1_max[1] = d1_max[0]
			d1_max[0] = [i, d1[i]]
	for i in d2:
		if d2_max[0][1] < d2[i]:
			d2_max[1] = d2_max[0]
			d2_max[0] = [i, d2[i]]

	if d1_max[0][0] != d2_max[0][0]:
		return(n - d1_max[0][1]- d2_max[0][1])
	else:
		return(min(n - d1_max[1][1]- d2_max[0][1], n - d1_max[0][1]- d2_max[1][1]))

for i in range(len(v)):
	if i % 2 == 0:
		if v[i] not in v_even:
			v_even[v[i]] = 1
		else:
			v_even[v[i]] += 1
	else:
		if v[i] not in v_odd:
			v_odd[v[i]] = 1
		else:
			v_odd[v[i]] += 1
	
print(solve(v_even, v_odd))

Submission status: Wrong Answer

Solution code:
N = int(input())
L = list(map(int, input().split()))
odd = {}
even = {}
for i, l in enumerate(L):
    if i % 2 == 0:
        odd.setdefault(l, 0)
        odd[l] += 1
    else:
        even.setdefault(l, 0)
        even[l] += 1
sorted(odd.items(), key = lambda x: x[1], reverse=True)
sorted(even.items(), key = lambda x: x[1], reverse=True)
cnt = 0
for i, key in enumerate(odd.keys()):
    if i == 0:
        maxK = key
        continue
    else:
        cnt += odd[key]
keyE1 = 0
valE1 = 0
keyE2 = 0
valE2 = 0
for i , key in enumerate(even.keys()):
    if i == 0:
        keyE1 = key
        valE1 = even[key]
    elif i == 1:
        keyE2 = key
        valE2 = even[key]
    else:
        cnt += even[key]
if maxK == keyE1:
    cnt += valE1
else:
    cnt += valE2
print(cnt)

Submission status: Wrong Answer

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

d0, d1 = {}, {}
for i in range(n//2):
    v = V[2*i]
    if v in d0:
        d0[v] += 1
    else:
        d0[v] = 1

    v = V[2*i+1]
    if v in d1:
        d1[v] += 1
    else:
        d1[v] = 1

s0 = sorted(d0.items(), key=lambda x: -x[1])
k0_0, v0_0 = s0[0]
s1 = sorted(d1.items(), key=lambda x: -x[1])
k1_0, v1_0 = s1[0]

if k0_0 != k1_0:
    print(n - v0_0 - v1_0)
else:
    k0_1, v0_1 = s0[1] if len(s0)>1 else ('0',0)
    k1_1, v1_1 = s1[1] if len(s1)>1 else ('0',0)
    if v0_0 <= v1_0:
        print(n - v1_0 - v0_1)
    else:
        print(n - v0_0 - v1_1)

Submission status: Wrong Answer

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

li_ki = li_input[0::2]
li_gu = li_input[1::2]


li_ki_counter = sorted([(i, li_ki.count(i)) for i in set(li_ki)], key=lambda x: x[1])
li_gu_counter = sorted([(i, li_gu.count(i)) for i in set(li_gu)], key=lambda x: x[1])


ki_1st = li_ki_counter[0][0]
gu_1st = li_gu_counter[0][0]

if ki_1st == gu_1st:
    # 最頻値が同じ値の場合、2番目に多い要素を使う

    if len(li_ki_counter) == 1:
        ki_2nd = -1
    else:
        ki_2nd = li_ki_counter[1][0]

    if len(li_gu_counter) == 1:
        gu_2nd = -1
    else:
        gu_2nd = li_gu_counter[1][0]

    ptn1 = len(list(filter(lambda x: x != ki_1st, li_ki))) + len(list(filter(lambda x: x != gu_2nd, li_gu)))
    ptn2 = len(list(filter(lambda x: x != ki_2nd, li_ki))) + len(list(filter(lambda x: x != gu_1st, li_gu)))

    if ptn1 >= ptn2:
        print(ptn2)
    else:
        print(ptn1)

else:
    # 最頻値が異なる場合
    print(
        len(list(filter(lambda x: x != ki_1st, li_ki))) +
        len(list(filter(lambda x: x != gu_1st, li_gu)))
    )

Submission status: Wrong Answer

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

d0, d1 = {}, {}
for i in range(n//2):
    v = V[2*i]
    if v in d0:
        d0[v] += 1
    else:
        d0[v] = 1

    v = V[2*i+1]
    if v in d1:
        d1[v] += 1
    else:
        d1[v] = 1

s0 = sorted(d0.items(), key=lambda x: -x[1])
k0_0, v0_0 = s0[0]
s1 = sorted(d1.items(), key=lambda x: -x[1])
k1_0, v1_0 = s1[0]

if k0_0 != k1_0:
    a0 = n//2 - v0_0
    a1 = n//2 - v1_0
    print(a0 + a1)
else:

    k0_1, v0_1 = s0[1] if len(s0)>1 else [0,0]
    k1_1, v1_1 = s1[1] if len(s1)>1 else [0,0]
    if v0_0 <= v1_0:
        a0 = n//2 - v0_1
        a1 = n//2 - v1_0
    else:
        a0 = n//2 - v0_0
        a1 = n//2 - v1_1
    print(a0 + a1)

Submission status: Wrong Answer

Solution code:
import collections as col
from functools import reduce
from operator import add
n = int(input())

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

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

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

co = col.Counter(odd)
coli = list(co.values())
ce = col.Counter(even)
celi = list(ce.values())

cov = list(co.keys())
cev = list(ce.keys())

if cov[0] != cev[0]:
    a = reduce(add, coli[1:], 0)
    b = reduce(add, celi[1:], 0)
    print(a + b)
    print(n - coli[0] - coli[0])
else:
    # a1 = reduce(add, coli[1:], 0)
    # b1 = reduce(add, celi[2:], 0)
    # b1 = celi[0] + b1

    # a2 = reduce(add, coli[2:], 0)
    # b2 = reduce(add, celi[1:], 0)
    # a2 = a2 + coli[0]
    if len(coli) <= 1:
        coli.append(0)
    if len(celi) <= 1:
        celi.append(0)

    ans1 = n - coli[1] - celi[0]
    ans2 = n - coli[0] - celi[1]

    print(min(ans1, ans2))

Submission status: Wrong Answer

Solution code:
import collections as col
from functools import reduce
from operator import add
n = int(input())

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

# if len(set(v)) == 1:
#     print(int(n / 2))
#     exit()

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

co = col.Counter(odd)
coli = list(co.values())
ce = col.Counter(even)
celi = list(ce.values())

cov = list(co.keys())
cev = list(ce.keys())

if cov[0] != cev[0]:
    a = reduce(add, coli[1:], 0)
    b = reduce(add, celi[1:], 0)
    print(a + b)
else:
    a1 = reduce(add, coli[1:], 0)
    b1 = reduce(add, celi[2:], 0)
    b1 = celi[0] + b1

    a2 = reduce(add, coli[2:], 0)
    b2 = reduce(add, celi[1:], 0)
    a2 = a2 + coli[0]

    print(min(a1+b1,a2+b2))

Submission status: Wrong Answer

Solution code:
import collections as col
from functools import reduce
from operator import add
n = int(input())

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

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

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

co = col.Counter(odd)
coli = list(co.values())
ce = col.Counter(even)
celi = list(ce.values())

cov = list(co.keys())
cev = list(ce.keys())

if cov[0] != cev[0]:
    a = reduce(add, coli[1:], 0)
    b = reduce(add, celi[1:], 0)
    print(a + b)
else:
    a1 = reduce(add, coli[1:], 0)
    b1 = reduce(add, celi[2:], 0)
    b1 = celi[0] + b1

    a2 = reduce(add, coli[2:], 0)
    b2 = reduce(add, celi[1:], 0)
    a2 = a2 + coli[0]

    print(min(a1+b1,a2+b2))

Submission status: Wrong Answer

Solution code:
import collections as col
from functools import reduce
from operator import add
n = int(input())

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

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

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

co = col.Counter(odd)
coli = list(co.values())
ce = col.Counter(even)
celi = list(ce.values())

cov = list(co.keys())
cev = list(ce.keys())

if cov[0] != cev[0]:
    a = reduce(add, coli[1:], 0)
    b = reduce(add, celi[1:], 0)
    print(a + b)
else:
    a1 = reduce(add, coli[1:], 0)
    b1 = reduce(add, celi[2:])
    b1 = coli[0] + b1

    a2 = reduce(add, coli[2:], 0)
    b2 = reduce(add, celi[1:])
    a2 = a2 + coli[0]

    print(min(a1+b1,a2+b2))

Submission status: Wrong Answer

Solution code:
import collections as col
from functools import reduce
from operator import add
n = int(input())

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

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

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

co = col.Counter(odd)
co = list(co.values())[1:]
ce = col.Counter(even)
ce = list(ce.values())[1:]

a = reduce(add, co, 0)
b = reduce(add, ce, 0)

print(a + b)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
cnt = 0
for i in range(N):
  if i + 2 >= N:
    break
  if A[i] != A[i+2]:
    cnt += 1
if cnt > 0:
  print(cnt)
  exit()
if len(set(A)) == 1:
  print(N // 2)
  exit()
print(cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
cnt = 0
for i in range(N):
  if i + 2 >= N:
    break
  if A[i] != A[i+2]:
    cnt += 1
if cnt > 0:
  print(cnt)
  exit()
print(N // 2)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
cnt = 0
for i in range(N):
  if i + 2 >= N:
    break
  if A[i] != A[i+2] or A[i] == A[i+1]:
    cnt += 1
print(cnt)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

L1 = [L[i] for i in range(0,N-1,2)]
L2 = [L[i] for i in range(1,N,2)]

if max(Counter(L1)) == max(Counter(L2)) :
    ans = N//2
else :
    a = N//2 - max(Counter(L1).values())
    b = N//2 - max(Counter(L2).values())
    ans = a+b
print(ans)

Submission status: Wrong Answer

Solution code:
import collections

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

for i in range(len(v)):
    if i % 2 == 1:
        odd.append(v[i])
    elif i % 2 == 0:
        even.append(v[i])
        
if odd == even:
    print(int(n/2))
else:
    c = collections.Counter(odd)
    c_common = c.most_common()[0][1]
    d = collections.Counter(even)
    d_common = d.most_common()[0][1]
    
    if c.most_common()[0][0] == d.most_common()[0][0]:
        c_second = c.most_common()[1][1]
        d_second = d.most_common()[1][1]
        min_count = min(len(odd) - c_common + len(even) - d_second, len(odd) - c_second + len(even) - d_common)
        print(min_count)
    else:
        print(len(odd) - c_common + len(even) - d_common)

Submission status: Wrong Answer

Solution code:
import collections

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

for i in range(len(v)):
    if i % 2 == 1:
        odd.append(v[i])
    elif i % 2 == 0:
        even.append(v[i])
        
if odd == even:
    print(int(n/2))
else:
    c = collections.Counter(odd)
    odd_num = len(odd) - c.most_common()[0][1]

    d = collections.Counter(even)
    even_num = len(even) - d.most_common()[0][1]
         
    print(odd_num + even_num)

Submission status: Wrong Answer

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

for i in range(len(v)):
    if i % 2 == 1:
        odd.append(v[i])
    elif i % 2 == 0:
        even.append(v[i])
        
c = collections.Counter(odd)
odd_num = len(odd) - c.most_common()[0][1]

d = collections.Counter(even)
even_num = len(even) - d.most_common()[0][1]
           
print(odd_num + even_num)

Submission status: Wrong Answer

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

for i in range(len(v)-2):
    if v[i+2] != v[i]:
        v[i+2] = v[i]
        counter += 1
    
print(counter)

Submission status: Wrong Answer

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

for i in range(len(v)-2):
    v[i+2] = v[i]
    
for i in v:
    print(i,end=" ")

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
n = int(input())
A = defaultdict(int)
B = defaultdict(int)
tmp = list(map(int,input().split()))
for i in range(n):
    if i % 2 == 0: A[tmp[i]] += 1
    else: B[tmp[i]] += 1

A = sorted(A.items(), key=lambda x:x[1],reverse=True)
B = sorted(B.items(), key=lambda x:x[1],reverse=True)

ans = 0
a = A.pop()
b = B.pop()
if a == b and len(A)+len(B)==0:
    ans = n // 2
elif a[0] == b[0]:
    if a[1] >= b[1]:
        ans += b[1]
        B.pop()
    else:
        ans += a[1]
        A.pop()
while A: ans += A.pop()[1]
while B: ans += B.pop()[1]

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
n = int(input())
A = defaultdict(int)
B = defaultdict(int)
tmp = list(map(int,input().split()))
for i in range(n):
    if i % 2 == 0: A[tmp[i]] += 1
    else: B[tmp[i]] += 1

A = sorted(A.items(), key=lambda x:x[1],reverse=True)
B = sorted(B.items(), key=lambda x:x[1],reverse=True)

ans = 0
a = A.pop()
b = B.pop()
if a == b:
    ans = n // 2
elif a[0] == b[0]:
    if a[1] >= b[1]:
        ans += b[1]
        B.pop()
    else:
        ans += a[1]
        A.pop()
while A: ans += A.pop()[1]
while B: ans += B.pop()[1]

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

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

odd = defaultdict(lambda: 0)
even = defaultdict(lambda: 0)
odd[None] = 0
even[None] = 0
for i in v[0::2]:
    odd[i] += 1
for i in v[1::2]:
    even[i] += 1

odd = sorted(odd.items(), key=lambda x: x[1], reverse=True)
even = sorted(even.items(), key=lambda x: x[1], reverse=True)
if odd[0][0] != even[0][0]:
    count = n - odd[0][1] - even[0][1]
elif odd[0][1] >= even[0][1]:
    count = n - odd[0][1] - even[1][1]
elif odd[0][1] < even[0][1]:
    count = n - odd[1][1] - even[0][1]

print(count)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

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

if len(set(v)) == 1:
    print(n//2)
else:
    odd = defaultdict(lambda: 0)
    even = defaultdict(lambda: 0)
    for i in v[0::2]:
        odd[i] += 1
    for i in v[1::2]:
        even[i] += 1
    print(n - max(odd.values()) - max(even.values()))

Submission status: Wrong Answer

Solution code:
from collections import Counter
input()
V = list(map(int, input().split()))
odd = Counter(V[::2])
even = Counter(V[1::2])
odd_max = max(odd.items(), key=lambda x: x[1])
even_max = max(even.items(), key=lambda x: x[1])
if odd_max[0] != even_max[0]:
    print(len(V) - odd_max[1] - even_max[1])
    exit()
if odd_max[1] >= even_max[1]:
    first = odd_max[1]
    second = even.most_common(2)
else:
    first = even_max[1]
    second = odd.most_common(2)
if len(second) >= 2:
    second = second[1][1]
else:
    second = 0
print(len(V) - first - second)

Submission status: Wrong Answer

Solution code:
n=int(input())
a = list(map(int, input().split()))
b=set(a[0::2])
c=set(a[1::2])
if len(set(a)) == 1:
      print(int(len(a)/2))
else:
      print(len(b)+len(c)-2)

Submission status: Wrong Answer

Solution code:
# C
import numpy as np
n = int(input())
v = [int(i) for i in input().split()]
solo_check = len(list(set(v)))
average = round(np.mean(v)*2)/2
if solo_check == 1:
    print(int(n/2))
else:
    diff_list = [x - average for x in v]
    print(int(sum(diff_list)))