Problem:


Score : 300 points

Problem Statement

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

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

Exactly two different numbers appear in the sequence.

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

Constraints

2 \leq n \leq 10^5

n is even.

1 \leq v_i \leq 10^5

v_i is an integer.

Input

Input is given from Standard Input in the following format:

n
v_1 v_2 ... v_n

Output

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

Sample Input 1

4
3 1 3 2

Sample Output 1

1

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

Sample Input 2

6
105 119 105 119 105 119

Sample Output 2

0

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

Sample Input 3

4
1 1 1 1

Sample Output 3

2

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



Sample input:
4
3 1 3 2


Sample output:
1

Submission status: Wrong Answer

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

v1,v2 = v[::2],v[1::2]

v1.sort()
v2.sort()
max1 = 0
max2 = 0
semi1 = 0
semi2 = 0
for i in range(n//2):
    if v1[i] != max1:
        semi1 = max1
        max1 = v1[i]
        count1 = 1
    else:
        count1 += 1
    if v2[i] != max2:
        semi2 = max2
        max2 = v2[i]
        count2 = 1
    else:
        count2 += 1

if max1 == max2:
    if semi1 == count2:
        print(n-count1-semi2)
    elif semi2 == count1:
        print(n-count2-semi1)
    else:
        print(min(n -semi1 - count2,n-count1-semi2))
else:
    print(n-count1-count2)

Submission status: Wrong Answer

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

v1,v2 = v[::2],v[1::2]

v1.sort()
v2.sort()
max1 = 0
max2 = 0
semi1 = 0
semi2 = 0
for i in range(n//2):
    if v1[i] != max1:
        semi1 = max1
        max1 = v1[i]
        count1 = 1
    else:
        count1 += 1
    if v2[i] != max2:
        semi2 = max2
        max2 = v2[i]
        count2 = 1
    else:
        count2 += 1

if max1 == max2:
    print(min(n -semi1 - count2,n-count1-semi2))
else:
    print(n-count1-count2)

Submission status: Wrong Answer

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

v1,v2 = v[::2],v[1::2]

v1.sort()
v2.sort()
max1 = 0
max2 = 0
semi1 = 0
semi2 = 0
for i in range(n//2):
    if v1[i] != max1:
        if max1 != 0:
            semi1 = max1
        max1 = v1[i]
        count1 = 1
    else:
        count1 += 1
    if v2[i] != max2:
        if max2 != 0:
            semi2 = max2
        max2 = v2[i]
        count2 = 1
    else:
        count2 += 1

if max1 == max2:
    if count1 - semi1 < count2 - semi2:
        print(n- count1 - semi2)
    else:
        print(n -semi1 - count2)
else:
    print(n-count1-count2)

Submission status: Wrong Answer

Solution code:
n = int(input())
v = list(map(int,input().split()))
max1 = 0
max2 = 0
semi_max1 = 0
semi_max2 = 0
max_1 = -1
max_2 = 0
v1,v2 = v[::2],v[1::2]
for i in range(n//2):
    a = max1
    b = max2
    max1 = max(max1,v1.count(v1[i]))
    max2 = max(max2,v2.count(v2[i]))
    if v1[i] != a and a < v1.count(v1[i]):
        semi_max1 = a
        max_1 = v[i]
    if v2[i] != b and b < v1.count(v1[i]):
        semi_max2 = b
        max_2 = v[i]
print(max_1, max_2,semi_max1,semi_max2,max1,max2) 
if max_1 == max_2:
    if (max1 - semi_max1) < (max2 -semi_max2 ):
        print((n//2-semi_max1)+(n//2-max2))
    else:
        print((n//2-semi_max1)+(n//2-max2))
else:
    print((n//2-max1)+(n//2-max2))

Submission status: Wrong Answer

Solution code:
# ABC111C
import collections

n = int(input())
v = list(map(int, input().split()))
if len(set(v)) == 1:
    print(n//2)
    exit()

v_odd = [0] * (n // 2)
v_even = [0] * (n // 2)
for i in range(n):
    if (i+1)%2 == 1:
        v_odd[i//2] = v[i]
    else:
        v_even[i//2] = v[i]
c_v_odd = collections.Counter(v_odd)
c_v_even = collections.Counter(v_even)

if c_v_odd.most_common()[0][0] == c_v_even.most_common()[0][0]:
    if c_v_odd.most_common()[0][1] > c_v_even.most_common()[0][1]:
        odd_count = n//2 - c_v_odd.most_common()[0][1]
        even_count = n//2 - c_v_even.most_common()[1][1]
        ans = odd_count + even_count
    else:
        odd_count = n//2 - c_v_odd.most_common()[1][1]
        even_count = n//2 - c_v_even.most_common()[0][1]
        ans = odd_count + even_count
else:
    odd_count = n//2 -  c_v_odd.most_common()[0][1]
    even_count = n//2 -  c_v_even.most_common()[0][1]
    ans = odd_count + even_count
print(ans)

Submission status: Wrong Answer

Solution code:
# ABC111C
import collections

n = int(input())
v = list(map(int, input().split()))
if len(set(v)) == 1:
    print(n//2)
    exit()
v_odd = [0] * (n // 2)
v_even = [0] * (n // 2)
for i in range(n):
    if (i+1)%2 == 1:
        v_odd[i//2] = v[i]
    else:
        v_even[i//2] = v[i]
c_v_odd = collections.Counter(v_odd)
c_v_even = collections.Counter(v_even)

odd_count = n//2 -  c_v_odd.most_common()[0][1]
even_count = n//2 -  c_v_even.most_common()[0][1]

print(odd_count + even_count)

Submission status: Wrong Answer

Solution code:
n = int(input())
l = list(map(int, input().split()))
allset=list((set(l)))
g=[]
k=[]
for i in range(0,n,2):
    g.append(l[i])
    k.append(l[i+1])

if len(allset)==1 and len(set(g))==1 and len(set(k))==1:
    print(n//2)
elif len(set(g))==1 and len(set(k))==1:
    print(0)
else:
    print((len(set(g))-1)+(len(set(k))-1))

Submission status: Wrong Answer

Solution code:
import collections
N=int(input())
h=[int(i) for i in input().split()]

h_o_l = len(h[1::2])
h_e_l = len(h[::2])

h_o = collections.Counter(h[1::2])
h_e = collections.Counter(h[::2])

o_ = h_o.most_common()
e_ = h_e.most_common()
o_.append((0,0))
e_.append((0,0))

if o_[0][0] != e_[0][0]:
    print(N-o_[1][1]-e_[1][1])
elif o_[0][0] == e_[0][0]:
    a =min(N-o_[0][1]-e_[1][1],N-e_[0][1]-o_[1][1])
    print(a)

Submission status: Wrong Answer

Solution code:
import collections
N=int(input())
h=[int(i) for i in input().split()]

h_o_l = len(h[1::2])
h_e_l = len(h[::2])

h_o = collections.Counter(h[1::2])
h_e = collections.Counter(h[::2])

o_ = h_o.most_common()
e_ = h_e.most_common()
o_.append((0,0))
e_.append((0,0))

if o_[0][0] != e_[0][0]:
    print(o_[1][1]+e_[1][1])
elif o_[0][0] == e_[0][0]:
    a =min(N-o_[0][1]-e_[1][1],N-e_[0][1]-o_[1][1])
    print(a)

Submission status: Wrong Answer

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

Odd, Evn = [], []
for i in range(n):
    Evn.append(V[i]) if i%2 == 0 else Odd.append(V[i])
Evn = sorted( dict(Counter(Evn)).items(), key = lambda x:x[1])
Odd = sorted( dict(Counter(Odd)).items(), key = lambda x:x[1])

cnt = -1
for evn in Evn[0:2]:
    for odd in Odd[0:2]:
        if evn[0] != odd[0]:
            cnt = max(cnt, evn[1]+odd[1])
print(n-cnt) if cnt > 0 else print(n//2)

Submission status: Wrong Answer

Solution code:
n = int(input())
v = list(map(int,input().split()))
#print(n)
m=0
o=0
j=0
k=0
count_1= 1
count_2= 1
list_1=[0]*(n//2)
list_2=[0]*(n//2)
list_1c=[0]*(n//2)
list_2c=[0]*(n//2)

for l in range (n):
	if l%2 == 0:
		list_1[m] = v[l]
		m += 1
	else:
		list_2[o] = v[l]
		o += 1
#print(list_1 ,end = " ")
#print(list_2)

for i in range(n-2):
	if v[i] == v[i+2]:
		if i%2 == 0:
			count_1 += 1
		else:
			count_2 += 1
	else:
		if i%2 == 0:
			list_1c[j] = count_1
			count_1 = 1
			j += 1
		else:
			list_2c[k] = count_2
			count_2 = 1
			k += 1
list_1c[j] = count_1
list_2c[k] = count_2
#print("count" ,end = " ")
list_new1=sorted(list_1c)
list_new2=sorted(list_2c)
#print(list_new1 ,end = " ")
#print(list_new2)
N = n//2
ans = int(n-int(list_new1[N-1])-int(list_new2[N-1]))
if v[1] == v[0]:
	print(N)
else:
	print(ans)

Submission status: Wrong Answer

Solution code:
import math
import itertools
import fractions
import heapq
import collections
import bisect
import sys

sys.setrecursionlimit(10**7)
mod = 10**9+7
inf = 10**20

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()

def counter_top(c,exclude):
    for a in c.most_common():
        if a[0]!=exclude:
            return a
    return (object(),0)

def conv_seq(seq,exclude = None):
    c = collections.Counter(seq)
    mc = counter_top(c,exclude)
    return sum(c.values()) - mc[1],mc[0]

N = I()
V = LI()

l = [V[i] for  i in range(0,N,2)]
r = [V[i] for i in range(1,N,2)]

s1,a = conv_seq(V[::2])
s2,b = conv_seq(V[1::2])

if s1!=s2:
    print(a+b)
else:
    s1_new,_ = conv_seq(V[::2],exclude=b)
    s2_new,_ = conv_seq(V[1::2],exclude=a)
    print(min(s1_new+s2,s1+s2_new))

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
v = list(map(int, input().split()))
even = []
odd = []
for i in range(n):
    if i % 2 == 0:
        even += [v[i]]
    else:
        odd += [v[i]]
even_dict = collections.Counter(even)
odd_dict = collections.Counter(odd)
max_even = max(even_dict.items(), key = lambda x:x[1])
max_odd = max(odd_dict.items(), key = lambda x:x[1])
#最高の値が同じでない
if max_even[0] != max_odd[0]:
    print(len(even) - max_even[1] + len(odd) - max_odd[1])
else:
    #同じだった場合
    if max_even[1] == len(even) and max_odd[1] == len(odd):
        second_even = (-1,0)
        second_odd = (-1,0)
    elif max_even[1] == len(even):
        second_even = (-1,0)
        second_odd = max([i for i in odd_dict.items() if i != max_odd], key = lambda x:x[1])
    elif max_odd[1] == len(odd):
        second_even = max([i for i in even_dict.items() if i != max_even], key = lambda x:x[1])
        second_odd = (-1,0)
    else:
        second_even = max([i for i in even_dict.items() if i != max_even], key = lambda x:x[1])
        second_odd = max([i for i in odd_dict.items() if i != max_odd], key = lambda x:x[1])
    #二つ目に大きいやつも同じかどうか
    if second_even[1] > second_odd[1]:
        print(len(even) - second_even[1] + len(odd) - max_even[1])
    else:
        print(len(even) - max_even[1] + len(odd) - second_even[1])

Submission status: Wrong Answer

Solution code:
import sys, math
def input():
    return sys.stdin.readline()[:-1]
from itertools import permutations, combinations
from collections import defaultdict, Counter

sys.setrecursionlimit(10**7)
n = int(input())
v = list(map(int, input().split()))

v1 = v[0::2]
v2 = v[1::2]

c1 = Counter(v1).most_common()
c2 = Counter(v2).most_common()

cnt1 = c1[0][1]
cnt2 = c2[0][1]

if c1[0][0] != c2[0][0]:
    print(n-cnt1-cnt2)
else:
    if len(c1)==1 or len(c2)==2:
        print(n//2)
    else:
        cnt11 = c1[1][1]
        cnt22 = c2[1][1]
        print(min(cnt11, cnt22))

Submission status: Wrong Answer

Solution code:
import sys, math
def input():
    return sys.stdin.readline()[:-1]
from itertools import permutations, combinations
from collections import defaultdict, Counter

sys.setrecursionlimit(10**7)
n = int(input())
v = list(map(int, input().split()))

v1 = [vi for i, vi in enumerate(v) if i%2]
v2 = [vi for i, vi in enumerate(v) if not i%2]

c1 = Counter(v1)
c2 = Counter(v2)

cnt1 = c1.most_common()[0][1]
cnt2 = c2.most_common()[0][1]

if c1.most_common()[0][0] != c2.most_common()[0][0]:
    print(len(v1)+len(v2)-cnt1-cnt2)

else:
    if cnt1 < cnt2:
        if len(c1.keys()) > 1:
            cnt1 = c1.most_common()[1][1]
            print(len(v1)+len(v2)-cnt1-cnt2)
        elif len(c2.keys()) > 1:
            cnt2 = c2.most_common()[1][1]
            print(len(v1)+len(v2)-cnt1-cnt2)
        else:
            print(len(v1)+len(v2)-cnt2)
    else:
        if len(c2.keys()) > 1:
            cnt2 = c2.most_common()[1][1]
            print(len(v1)+len(v2)-cnt1-cnt2)
        elif len(c1.keys()) > 1:
            cnt1 = c1.most_common()[1][1]
            print(len(v1)+len(v2)-cnt1-cnt2)
        else:
            print(len(v1)+len(v2)-cnt1)

Submission status: Wrong Answer

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

L1 = Counter(V[::2])
L2 = Counter(V[1::2])
# print(L1)
# print(L2)

if L1.most_common()[0][0] != L2.most_common()[0][0]:
    print(n - L1.most_common()[0][1] - L2.most_common()[0][1])
elif L1 == L2:
    print(n // 2)
else:
    l10 = L1.most_common()[0][1]
    l20 = L2.most_common()[0][1]
    l11 = L1.most_common()[1][1]
    l21 = L2.most_common()[1][1]
    if l10 > l20:
        print(n - l10 - l21)
    elif l10 < l20:
        print(n - l11 - l20)
    else:
        print(n - l10 - max(l11, l21))

Submission status: Wrong Answer

Solution code:
n = int(input())

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

B = []
C = []

for i in range(n):
    if i % 2 == 0:
        B.append(A[i])
    else:
        C.append(A[i])

if len(set(B)) == 1 and len(set(C)) == 1 and B[0] != C[0]:
    print(0)
elif len(set(B)) == 1 and len(set(C)) == 1 and B[0] == C[0]:
    print(len(B))
elif len(set(B)) == 1:
    temp = 0
    cou = 0
    for j in set(C):
        if j != B[0]:
            num = C.count(j)
            if cou < num:
                cou = num
                temp = j
    print(len(C) - cou)
elif len(set(C)) == 1:
    temp = 0
    cou = 0
    for j in set(B):
        if j != C[0]:
            num = B.count(j)
            if cou < num:
                cou = num
                temp = j
    print(len(B) - cou)
else:
    first = 0
    second = 0
    f_count = 0
    s_count = 0
    for i in set(B):
        temp = B.count(i)
        if f_count < temp:
            s_count = f_count
            f_count = temp
            second = first
            first = i
        elif s_count < temp < f_count:
            s_count = temp
            second = i
        
    first_ = 0
    second_ = 0
    f_count_ = 0
    s_count_ = 0
    for i in set(B):
        temp_ = B.count(i)
        if f_count_ < temp_:
            s_count_ = f_count_
            f_count_ = temp_
            second_ = first_
            first_ = i
        elif s_count_ < temp_ < f_count_:
            s_count_ = temp_
            second_ = i
    
    if first == first_:
        if f_count < f_count_:
            print(len(B) - s_count + len(C) - f_count_)
        else:
            print(len(B) - f_count + len(C) - s_count_)
    else:
        print(len(B) - f_count + len(C) - f_count_)

Submission status: Wrong Answer

Solution code:
import math
import numpy as np
from fractions import gcd
import fractions
import collections

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

odd = []
even = []
for i in range(N):
    if (i%2 != 0):
        odd.append(A[i])
    else:
        even.append(A[i])

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

odd_sorted = dict(sorted(odd_c.items(), key=lambda x:x[1], reverse=True))
even_sorted = dict(sorted(even_c.items(), key=lambda x:x[1], reverse=True))

odd_keys = list(odd_sorted.keys())
even_keys = list(even_sorted.keys())

ans = 0
if (even_keys[0] != odd_keys[0]):
    for i in range(N):
        if (i%2 != 0 and A[i] != odd_keys[0]):
            ans += 1
        elif (i%2 == 0 and A[i] != even_keys[0]):
            ans += 1
elif(len(even_keys) >= 2 and len(odd_keys) >=2):
    tmp1 = 0
    tmp2 = 0
    for i in range(N):
        if (i%2 != 0 and A[i] != odd_keys[0]):
            tmp1 += 1
        elif (i%2 == 0 and A[i] != even_keys[1]):
            tmp1 += 1
    for i in range(N):
        if (i%2 != 0 and A[i] != odd_keys[1]):
            tmp2 += 1
        elif (i%2 == 0 and A[i] != even_keys[0]):
            tmp2 += 1
    ans = min(tmp1,tmp2)
elif(len(even_keys) == 1 and len(odd_keys) ==1):
    ans = N//2
else:
    ans = min(even_keys[-1], odd_keys[-1])
print(ans)

Submission status: Wrong Answer

Solution code:
import math
import numpy as np
from fractions import gcd
import fractions
import collections

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

C = collections.Counter(A)
c_sorted = dict(sorted(C.items(), key=lambda x:x[1], reverse=True))

val = list(c_sorted.values())
if (len(val) == 1):
    print(val[0]//2)
else:
    print(sum(val[2:]))

Submission status: Wrong Answer

Solution code:

n = int(input())
V = list(map(int, input().split()))
A = [] # 偶数
B = [] # 奇数

inf = 999999999999999999999

import collections

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

A = collections.Counter(A).most_common()
B = collections.Counter(B).most_common()

count = 0

if A[0][0] == B[0][0]:
  count += min(A[0][1], B[0][1])

A.pop(0)
B.pop(0)

for key, value in A:
  count += value

for  key, value in B:
  count += value

print(count)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

if sum(V)/N == V[0] and sum(V)/N == V[N-1]:
  print(N//2)
  exit()

def get_most_common(lis):
  c = Counter(lis)
  m = c.most_common()
  return m

odds = V[0::2]
evens = V[1::2]

m_odds = get_most_common(odds)
m_evens = get_most_common(evens)

if m_odds[0][0] == m_evens[0][0]:
  if m_odds[0][1] > m_evens[0][1]:
    idx_odds = 0
    idx_evens = 1
  else:
    idx_odds = 1
    idx_evens = 0
else:
  idx_odds = 0
  idx_evens = 0
  
print(N - m_odds[idx_odds][1] - m_evens[idx_evens][1])

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

if sum(V)/N == V[0] and sum(V)/N == V[N-1]:
  print(N//2)
  exit()

def get_most_common(lis):
  c = Counter(lis)
  m = c.most_common()
  return m

odds = V[0::2]
evens = V[1::2]

m_odds = get_most_common(odds)
m_evens = get_most_common(evens)

if m_odds[0][0] == m_evens[0][0]:
  idx_evens = 1
else:
  idx_evens = 0
  
print(N - m_odds[0][1] - m_evens[idx_evens][1])

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

if sum(V)/N == V[0] and sum(V)/N == V[N-1]:
  print(N//2)
  exit()

def get_maxfreq_count(lis):
  c = Counter(lis)
  m = c.most_common()[0]
  return m[1]

odds = V[0::2]
evens = V[1::2]

print(N - (get_maxfreq_count(odds) + get_maxfreq_count(evens)))

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

n = int(input())
v = list(map(int, input().split()))
v1 = [v[i] for i in range(0, n, 2)]
v2 = [v[i] for i in range(1, n, 2)]

cnt1 = defaultdict(int)
cnt2 = defaultdict(int)
for x in v1:
  cnt1[x] += 1
for x in v2:
  cnt2[x] += 1
vc1 = []
vc2 = []
for k, v in cnt1.items():
  vc1.append((v, k))
for k, v in cnt2.items():
  vc2.append((v, k))
vc1.sort()
vc1.reverse()
vc2.sort()
vc2.reverse()

vc1.append((0, vc1[0][0] + 1))
vc2.append((0, vc2[0][0] + 1))

ans = n
for _, x1 in vc1[:2]:
  for _, x2 in vc2[:2]:
    s = 0
    for x in v1:
      if x != x1: s += 1
    for x in v2:
      if x != x2: s += 1
    ans = min(ans, s)
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
v = list(map(int, input().split()))
v1 = [v[i] for i in range(0, n, 2)]
v2 = [v[i] for i in range(1, n, 2)]

v1a = sum(v1) // len(v1)
v2a = sum(v2) // len(v2)

ans = 100000000000000000000000
for x1 in range(v1a - 1, v1a + 2):
  for x2 in range(v2a - 1, v2a + 2):
    if x1 == x2: continue
    s = 0
    for x in v1:
      if x != x1: s += 1
    for x in v2:
      if x != x2: s += 1
    ans = min(ans, s)
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
v = list(map(int, input().split()))
v1 = [v[i] for i in range(0, n, 2)]
v2 = [v[i] for i in range(1, n, 2)]

v1a = sum(v1) // len(v1)
v2a = sum(v2) // len(v2)

ans = 100000000000000000000000
for x1 in range(v1a - 1, v1a + 2):
  for x2 in range(v2a - 1, v2a + 2):
    if x1 == x2: continue
    s = 0
    for x in v1:
      s += abs(x - x1)
    for x in v2:
      s += abs(x - x2)
    ans = min(ans, s)
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
v=list(map(int,input().split()))
w=[]
for i in range(n//2):
    w.append(v.pop(i))
print(v)
print(w)
import collections
cv = collections.Counter(v)
cw = collections.Counter(w)
scv = sorted(cv.items(), key=lambda x:-x[1])
scw = sorted(cw.items(), key=lambda x:-x[1])

v1=scv[0][0]
w1=scw[0][0]

if v1==w1:
    if len(scv)==1:
        v2=0
    else:
        v2=scv[1][1]
    if len(scw)==1:
        w2=0
    else:
        w2=scw[1][1]
        
    print(min(n-scv[0][1]-w2, n-scw[0][1]-v2))
        
else:
    print(n-scv[0][1]-scw[0][1])

Submission status: Wrong Answer

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

odd = sorted(v[0::2])
even = sorted(v[1::2])
odd.append(-1)
even.append(-1)

ans = 0

ml = []
current = 0
for i in range(len(odd)):
    if odd[current] != odd[i]:
        ml.append(i-current)
        current = i

ans += sum(ml) - max(ml)

ml = []
current = 0
for i in range(len(even)):
    if even[current] != even[i]:
        ml.append(i-current)
        current = i

ans += sum(ml) - max(ml)

print(n//2 if ans == 0 and odd == even else ans)

Submission status: Wrong Answer

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

odd = sorted(v[0::2])
even = sorted(v[1::2])
odd.append(-1)
even.append(-1)

ans = 0

ml = []
current = 0
for i in range(len(odd)):
    if odd[current] != odd[i]:
        ml.append(i-current)
        current = i

ans += sum(ml) - max(ml)

ml = []
current = 0
for i in range(len(even)):
    if even[current] != even[i]:
        ml.append(i-current)
        current = i

ans += sum(ml) - max(ml)

print(n//2 if odd == even else ans)

Submission status: Wrong Answer

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

odd = sorted(v[0::2])
even = sorted(v[1::2])
odd.append(-1)
even.append(-1)

ans = 0

ma = 0
current = 0
for i in range(len(odd)):
    if odd[current] != odd[i]:
        ma = max(ma, i-current)
        current = i

ans += ma

ma = 0
current = 0
for i in range(len(even)):
    if even[current] != even[i]:
        ma = max(ma, i-current)
        current = i

ans += ma

print(n//2 if odd == even else n - ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
from collections import Counter

def solve(n: int, v: "List[int]"):
    v1 = v[0::2]
    v2 = v[1::2]

    counter1 = Counter(v1).most_common()
    counter2 = Counter(v2).most_common(2)

    key1,value1 = counter1[0]
    key2,value2 = counter2[0]

    if key1 == key2:
        if len(counter2) >=2:
            _,value2 = counter2[1]
        else:
            value2 = 0

    print(len(v1)-value1+len(v2)-value2)

    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:
n=int(input())
v=list(map(int,input().split()))
cnt=0
for i in range(n-2):
    if v[i]!=v[i+2]:
        cnt+=1
    elif v[i]==v[i+1]:
        cnt+=1
print(cnt)

Submission status: Wrong Answer

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

#print(v)

# 同じ文字の場合の処理
if len(set(v)) == 1:
    print(int(n/2))
    exit()

eval,odd = [],[]

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

eval = len(set(eval)) - 1
odd = len(set(odd)) - 1

print(odd + eval)

Submission status: Wrong Answer

Solution code:
n = int(input())
v = list(map(int, input().split()))
v1 = [v[i] for i in range(n) if i % 2 == 0]
v2 = [v[i] for i in range(n) if i % 2 == 1]
v1.sort()
v2.sort()
num1 = 0
num2 = 0
num11 = 0
num22 = 0
check1 = 1
check2 = 1
p = 0
for i in range(len(v1)-1):
    if v1[i] != v1[i+1]:
        if check1 > num1:
            num1 = check1
            p = v1[i]
        check1 = 1
    else:
        check1 += 1
        if check1 > num1:
            num1 = check1
            p = v1[i]

for i in range(len(v2)-1):
    if v2[i] != v2[i+1]:
        if check2 > num2 and v2[i] != p:
            num2 = check2
        check2 = 1
    else:
        check2 += 1
    if check2 > num2 and v2[i] != p:
        num2 = check2

check1 = check2 = 1
for i in range(len(v2)-1):
    if v2[i] != v2[i+1]:
        if check2 > num22:
            num22 = check2
            p = v2[i]
        check2 = 1
    else:
        check2 += 1
    if check2 > num22:
        num22 = check2

for i in range(len(v1)-1):
    if v1[i] != v1[i+1]:
        if check1 > num11 and v1[i] != p:
            num11 = check1
        check1 = 1
    else:
        check1 += 1
        if check1 > num11 and v1[i] != p:
            num11 = check1

print(min(n-num1-num2, n-num11-num22))

Submission status: Wrong Answer

Solution code:
n = int(input())
v = list(map(int,input().split()))
v1 = [v[i] for i in range(n) if i%2 == 0]
v2 = [v[i] for i in range(n) if i%2 == 1]
v1.sort()
v2.sort()
num1 = 0
num2 = 0
check1 = 1
check2 = 1
p = 0
for i in range(len(v1)-1):
    if v1[i] != v1[i+1]:
        if check1 > num1:
            num1 = check1
            p = v1[i]
        check1 = 1
    else:
        check1 += 1
        if check1 > num1:
            num1 = check1
            p = v1[i]
for i in range(len(v2)-1):
    if v2[i] != v2[i+1]:
        if check2 > num2 and v2[i] != p:
            num2 = check2
        check2 = 1
    else:
        check2 += 1
    if check2 > num2 and v2[i] != p:
        num2 = check2
print(n-num1-num2)

Submission status: Wrong Answer

Solution code:
import collections

n = int(input())
V = list(map(int, input().split()))
kisuu = []
gusuu = []
for idx, v in enumerate(V):
    if idx % 2 == 0:
        gusuu.append(v)
    else:
        kisuu.append(v)
gusuu_c = collections.Counter(gusuu)
gusuu_c_sorted = sorted(gusuu_c.items(), key=lambda x: x[1])
kisuu_c = collections.Counter(kisuu)
kisuu_c_sorted = sorted(kisuu_c.items(), key=lambda x: x[1])
# print(gusuu_c_sorted)
# print(kisuu_c_sorted)

# if gusuu_c_sorted[0][0] == kisuu_c_sorted[0][0]:
#     if len(gusuu_c_sorted) == 1 and len(kisuu_c_sorted) == 1:
#         print(min(len(gusuu), len(kisuu)))
#     elif len(gusuu_c_sorted) == 1:
#         print(len(kisuu_c_sorted) - kisuu_c_sorted[1][1])
#     elif len(kisuu_c_sorted) == 1:
#         print(len(gusuu_c_sorted) - gusuu_c_sorted[1][1])
#     else:
#         print(min(len(kisuu_c_sorted) - kisuu_c_sorted[1][1] +  len(gusuu_c_sorted) - gusuu_c_sorted[0][1],len(kisuu_c_sorted) - kisuu_c_sorted[0][1] +  len(gusuu_c_sorted) - gusuu_c_sorted[1][1] ))
# else:
#     if len(gusuu_c_sorted) == 1 and len(kisuu_c_sorted) == 1:
#         print(0)
#     elif len(gusuu_c_sorted) == 1:
#         print(len(kisuu_c_sorted) - kisuu_c_sorted[0][1])
#     elif len(kisuu_c_sorted) == 1:
#         print(len(gusuu_c_sorted) - gusuu_c_sorted[0][1])
#     else:
#         print(len(kisuu_c_sorted) - kisuu_c_sorted[0][1] +  len(gusuu_c_sorted) - gusuu_c_sorted[0][1])

if gusuu_c_sorted[0][0] != kisuu_c_sorted[0][0]:
    print(
        len(kisuu) - kisuu_c_sorted[0][1] + len(gusuu) - gusuu_c_sorted[0][1])
else:
    if len(gusuu_c_sorted) == 1 and len(kisuu_c_sorted) == 1:
        print(min(len(gusuu), len(kisuu)))
    elif len(gusuu_c_sorted) == 1:
        print(len(kisuu) - kisuu_c_sorted[1][1])
    elif len(kisuu_c_sorted) == 1:
        print(len(gusuu) - gusuu_c_sorted[1][1])
    else:
        print(min(len(kisuu) - kisuu_c_sorted[1][1] + len(gusuu) - gusuu_c_sorted[0][1],
                  len(kisuu) - kisuu_c_sorted[0][1] + len(gusuu) - gusuu_c_sorted[1][1]))

Submission status: Wrong Answer

Solution code:
import collections

n = int(input())
V = list(map(int, input().split()))
kisuu = []
gusuu = []
for idx, v in enumerate(V):
    if idx % 2 == 0:
        gusuu.append(v)
    else:
        kisuu.append(v)
gusuu_c = collections.Counter(gusuu)
gusuu_c_sorted = sorted(gusuu_c.items(), key=lambda x: x[1])
kisuu_c = collections.Counter(kisuu)
kisuu_c_sorted = sorted(kisuu_c.items(), key=lambda x: x[1])
# print(gusuu_c_sorted)
# print(kisuu_c_sorted)

if gusuu_c_sorted[0][0] == kisuu_c_sorted[0][0]:
    if len(gusuu_c_sorted) == 1 and len(kisuu_c_sorted) == 1:
        print(min(len(gusuu), len(kisuu)))
    elif len(gusuu_c_sorted) == 1:
        print(len(kisuu) - kisuu_c_sorted[1][1])
    elif len(kisuu_c_sorted) == 1:
        print(len(gusuu) - gusuu_c_sorted[1][1])
    else:
        print(min(len(kisuu_c_sorted) - kisuu_c_sorted[1][1] +  len(gusuu_c_sorted) - gusuu_c_sorted[0][1],len(kisuu_c_sorted) - kisuu_c_sorted[0][1] +  len(gusuu_c_sorted) - gusuu_c_sorted[1][1] ))
else:
    if len(gusuu_c_sorted) == 1 and len(kisuu_c_sorted) == 1:
        print(0)
    elif len(gusuu_c_sorted) == 1:
        print(len(kisuu) - kisuu_c_sorted[0][1])
    elif len(kisuu_c_sorted) == 1:
        print(len(gusuu) - gusuu_c_sorted[0][1])
    else:
        print(len(kisuu) - kisuu_c_sorted[0][1] +  len(gusuu) - gusuu_c_sorted[0][1])

Submission status: Wrong Answer

Solution code:
import collections

n = int(input())
V = list(map(int, input().split()))
kisuu = []
gusuu = []
for idx, v in enumerate(V):
    if idx % 2 == 0:
        gusuu.append(v)
    else:
        kisuu.append(v)
gusuu_c = collections.Counter(gusuu)
gusuu_c_sorted = sorted(gusuu_c.items(), key=lambda x: x[1])
kisuu_c = collections.Counter(kisuu)
kisuu_c_sorted = sorted(kisuu_c.items(), key=lambda x: x[1])
# print(gusuu_c_sorted)
# print(kisuu_c_sorted)

if gusuu_c_sorted[0][0] == kisuu_c_sorted[0][0]:
    if len(gusuu_c_sorted) == 1 and len(kisuu_c_sorted) == 1:
        print(min(len(gusuu), len(kisuu)))
    elif len(gusuu_c_sorted) == 1:
        print(len(kisuu_c_sorted) - kisuu_c_sorted[1][1])
    elif len(kisuu_c_sorted) == 1:
        print(len(gusuu_c_sorted) - gusuu_c_sorted[1][1])
    else:
        print(min(len(kisuu_c_sorted) - kisuu_c_sorted[1][1] +  len(gusuu_c_sorted) - gusuu_c_sorted[0][1],len(kisuu_c_sorted) - kisuu_c_sorted[0][1] +  len(gusuu_c_sorted) - gusuu_c_sorted[1][1] ))
else:
    if len(gusuu_c_sorted) == 1 and len(kisuu_c_sorted) == 1:
        print(0)
    elif len(gusuu_c_sorted) == 1:
        print(len(kisuu_c_sorted) - kisuu_c_sorted[0][1])
    elif len(kisuu_c_sorted) == 1:
        print(len(gusuu_c_sorted) - gusuu_c_sorted[0][1])
    else:
        print(len(kisuu_c_sorted) - kisuu_c_sorted[0][1] +  len(gusuu_c_sorted) - gusuu_c_sorted[0][1])

Submission status: Wrong Answer

Solution code:
import itertools
from collections import Counter
N = int(input())
V = list(map(int,input().split()))
even_counter = Counter(V[::2])
odd_counter = Counter(V[1::2])
even_counter[-1] = 0
odd_counter[-1] = 0
even = even_counter.most_common(2)
odd = odd_counter.most_common(2)
print(even,odd)
ans = N
for (k1,v1),(k2,v2) in itertools.product(even,odd):
  if k1 == k2:
    continue
  ans = min(ans,N - v1 - v2)
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
V = [int(i) for i in input().split()]
a = []
b = []
for i in range(n):
  if i%2==0:
    a.append(V[i])
  else:
    b.append(V[i])
if a == b:
  print(n//2)
else:
  print(len(set(a))+len(set(b))-2)