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:
# 2125
n = int(input())
get_inf = list(map(int, input().split(' ')))
a = get_inf[::2]
b = get_inf[1::2]

def count_unique(lis):
    r = []
    i = 0
    while i < len(lis):
        count = 1
        k = i + 1
        if lis[i] > 0:
            while k < len(lis):
                if lis[i] == lis[k] and lis[k] > 0:
                    count += 1
                    lis[k] *= -1
                k += 1
            r.append([count, lis[i]])
            lis[i] *= -1
            i += 1
        else:
            i += 1
    return r

x = []
y = []
x = count_unique(a)
y = count_unique(b)

x.sort()
y.sort()

result = []
i = 0
s = 0
counter = 0
while i < len(x) and counter < 5:
    counter_2 = 0
    while s < len(y) and counter_2 < 5:
        if x[i][1] != y[s][1]:
            r = n-x[i][0]-y[s][0]
            result.append(r)
            s += 1
            counter_2 += 1
        else:
            s += 1
            counter_2 += 1
    i += 1
    counter += 1
if len(result) != 0:
    print(min(result))
else:
    print(int(n/2))

Submission status: Wrong Answer

Solution code:
# 2125
n = int(input())
get_inf = list(map(int, input().split(' ')))
a = get_inf[::2]
b = get_inf[1::2]

def count_unique(lis):
    r = []
    i = 0
    while i < len(lis):
        count = 1
        k = i + 1
        if lis[i] > 0:
            while k < len(lis):
                if lis[i] == lis[k] and lis[k] > 0:
                    count += 1
                    lis[k] *= -1
                k += 1
            r.append([count, lis[i]])
            lis[i] *= -1
            i += 1
        else:
            i += 1
    return r

x = []
y = []
x = count_unique(a)
y = count_unique(b)

x.sort()
y.sort()

result = []
i = 0
s = 0
counter = 1
while i < len(x) and counter < 100:
    counter_2 = 0
    while s < len(y) and counter_2 < 100:
        if x[i][1] != y[s][1]:
            r = n-x[i][0]-y[s][0]
            result.append(r)
            s += 1
            counter_2 += 1
        else:
            s += 1
            counter_2 += 1
    i += 1
if len(result) != 0:
    print(min(result))
else:
    print(int(n/2))

Submission status: Wrong Answer

Solution code:
n = int(input())
v = list(map(int, input().split()))
e = [i for idx,i in enumerate(v) if idx%2==0]
o = [i for idx,i in enumerate(v) if idx%2==1]

import statistics

if e==o:
  print(len(e))
else:
  try:
    e = e.count(statistics.mode(e))
  except:
    e = 1

  try:
    o = o.count(statistics.mode(o))
  except:
    o = 1
  print(n-e-o)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
v = list(map(int, input().split()))
a = Counter(v[::2])
b = Counter(v[1::2])
count = a.most_common()[0][1]
count1 = b.most_common()[0][1]
print(n//2 if len(set(v)) == 1 else n-count-count1)

Submission status: Wrong Answer

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

a = []
b = []
for i in range(N//2):
	a.append(int(A[i*2]))
	b.append(int(A[i*2+1]))

a = collections.Counter(a)
b = collections.Counter(b)

if a.most_common()[0][0] == b.most_common()[0][0] 	:
	if len(a) == 1:
		print(N//2)
	elif a.most_common()[0][1] > b.most_common()[0][1]:
		print(N - a.most_common()[0][1]  - b.most_common()[1][1]) 
	else:
		print(N - a.most_common()[1][1]  - b.most_common()[0][1])
else:
	print(N - a.most_common()[0][1]  - b.most_common()[0][1])

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(map(int,input().split()))
cnt = 0
same = True
for i in range(n-2):
    if s[i] != s[i+2]:
        cnt += 1
    if s[i] != s[i+1]:
        same = False
if same:
    print(int(n/2))
else:
    print(cnt)

Submission status: Wrong Answer

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

Onum = {}
Enum = {}

for i in range(n):
    if i%2 == 1:
        if v[i] in Onum:
            Onum[v[i]] += 1
        else:
            Onum[v[i]] = 1
    else:
        if v[i] in Enum:
            Enum[v[i]] += 1
        else:
            Enum[v[i]] = 1

sumO = sum(Onum.values())
sumE = sum(Enum.values())
Onum = sorted(Onum.items(), key = lambda x:-x[1])
Enum = sorted(Enum.items(), key = lambda x:-x[1])

if len(Onum) == 1 and len(Enum) == 1 and Onum[0][0] != Enum[0][0]:
    ans = 0
elif len(Onum) == 1 and len(Enum) == 1:
    ans = n // 2
elif len(Enum) == 1:
    ans = sumO - Onum[1][1]
elif len(Onum) == 1:
    ans = sumE - Enum[1][1]
elif Onum[0][0] != Enum[0][0]:
    ans = sumO + sumE - (Onum[0][1] + Enum[0][1])
else:
    ans = sumO + sumE - max(Onum[0][1]+Enum[1][1], Onum[1][1]+Enum[0][1])

print(ans)

Submission status: Wrong Answer

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

Onum = {}
Enum = {}

for i in range(n):
    if i%2 == 1:
        if v[i] in Onum:
            Onum[v[i]] += 1
        else:
            Onum[v[i]] = 1
    else:
        if v[i] in Enum:
            Enum[v[i]] += 1
        else:
            Enum[v[i]] = 1

sumO = sum(Onum.values())
sumE = sum(Enum.values())
Onum = sorted(Onum.items(), key = lambda x:x[1])
Enum = sorted(Enum.items(), key = lambda x:x[1])

if len(Onum) == 1 and len(Enum) == 1 and Onum[0][0] != Enum[0][0]:
    ans = 0
elif len(Onum) == 1 and len(Enum) == 1:
    ans = n // 2
elif len(Enum) == 1:
    ans = sumO - Onum[1][1]
elif len(Onum) == 1:
    ans = sumE - Enum[1][1]
elif Onum[0][0] != Enum[0][0]:
    ans = sumO + sumE - (Onum[0][1] + Enum[0][1])
else:
    ans = sumO + sumE - max(Onum[0][1]+Enum[1][1], Onum[1][1]+Enum[0][1])

print(ans)

Submission status: Wrong Answer

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

Onum = {}
Enum = {}

for i in range(n):
    if i%2:
        if v[i] in Onum:
            Onum[v[i]] += 1
        else:
            Onum[v[i]] = 1
    else:
        if v[i] in Enum:
            Enum[v[i]] += 1
        else:
            Enum[v[i]] = 1

#print(min(Onum.values()))
#print(min(Enum.values()))
ans = sum(Onum.values()) + sum(Enum.values())
Onum = sorted(Onum.items(), key = lambda x:x[1])
Enum = sorted(Enum.items(), key = lambda x:x[1])

if len(Onum) == 1 and len(Enum) == 1 and Onum[0][0] != Enum[0][0]:
    ans = 0
elif len(Onum) == 1 and len(Enum) == 1:
    ans = n // 2
elif len(Enum) == 1:
    ans = ans - (Onum[1][1] + Enum[0][1])
elif len(Onum) == 1:
    ans = ans - (Onum[0][1] + Enum[1][1])
elif Onum[0][0] != Enum[0][0]:
    ans = ans - (Onum[0][1] + Enum[0][1])
else:
    ans = ans - max(Onum[0][1]+Enum[1][1], Onum[1][1]+Enum[0][1])

print(ans)

Submission status: Wrong Answer

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

Onum = {}
Enum = {}

for i in range(n):
    if i%2:
        if v[i] in Onum:
            Onum[v[i]] += 1
        else:
            Onum[v[i]] = 1
    else:
        if v[i] in Enum:
            Enum[v[i]] += 1
        else:
            Enum[v[i]] = 1

#print(min(Onum.values()))
#print(min(Enum.values()))
ans = sum(Onum.values()) + sum(Enum.values())
Onum = sorted(Onum.items(), key = lambda x:x[1])
Enum = sorted(Enum.items(), key = lambda x:x[1])

if len(Onum) == 1 and len(Enum) == 1 and Onum[0][0] != Enum[0][0]:
    ans = 0
elif len(Onum) == 1 and len(Enum) == 1:
    ans = n // 2
elif len(Enum) == 1:
    ans = ans - (Onum[1][1] + Enum[0][1])
elif len(Onum) == 1:
    ans = ans - (Onum[0][1] + Enum[1][1])
elif Onum[0][0] != Enum[0][0]:
    ans = ans - (Onum[0][1] + Enum[0][1])
else:
    ans = ans - min(Onum[0][1]+Enum[1][1], Onum[1][1]+Enum[0][1])

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
from functools import reduce
n = int(input())
v = list(map(int, input().split()))
r1 = [v[i] for i in range(0, len(v), 2)]
r2 = [v[i] for i in range(1, len(v), 2)]
c1 = Counter(r1).most_common(1)[0][0]
c2 = Counter(r2).most_common(2)
if len(c2) == 1 and c2[0][0] == c1:
    c2 = -1
else:
    c2 = c2[0][0] if c2[0][0] != c1 else c2[1][0]
f = lambda e, v: 1 if e != v else 0
c = reduce(lambda x, y: x + f(y, c1), r1, 0)
c += reduce(lambda x, y: x + f(y, c2), r2, 0)
print(c)

Submission status: Wrong Answer

Solution code:
from collections import Counter
from functools import reduce
n = int(input())
v = list(map(int, input().split()))
r1 = [v[i] for i in range(0, len(v), 2)]
r2 = [v[i] for i in range(1, len(v), 2)]
c1 = Counter(r1).most_common(1)[0][0]
c2 = Counter(r2).most_common(2)
if len(c2) > 1:
    c2 = c2[0][0] if c2[0][0] != c1 else c2[1][0]
else:
    c2 = -1
f = lambda e, v: 1 if e != v else 0
c = reduce(lambda x, y: x + f(y, c1), r1, 0)
c += reduce(lambda x, y: x + f(y, c2), r2, 0)
print(c)

Submission status: Wrong Answer

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

dic = defaultdict(int)
for v in V:
    dic[v] += 1

len_d = len(dic)
if len_d == 1:
    print(N//2)
else:
    ans = 0
    for i in range(N-2):
        if V[i] != V[i+2]:
            ans += 1
    print(ans)

Submission status: Wrong Answer

Solution code:
#%%
import collections

n = int(input())
v = list(input().split())
v1 = v[0::2]
v2 = v[1::2]

#print(v1)
#print(v2)


l1 = list(collections.Counter(v1).items())
l2 = list(collections.Counter(v2).items())


l1.sort()
l2.sort()


if l1[0][0] != l2[0][0]:
    tmp = l1[0][1] + l2[0][1]
else:
    if len(l1) > 1 and len(l2) > 1: 
        tmp = max(l1[1][1] + l2[0][1], l1[0][1] + l2[1][1])
    elif len(l1) == 1 and len(l2) > 1:
        tmp = max(l2[0][1], l1[0][1] + l2[1][1])
    elif len(l2) == 1 and len(l1) > 1:
        tmp = max(l1[1][1] + l2[0][1], l1[0][1])
    else:
        tmp = max(l2[0][1], l1[0][1])

ans = n - tmp
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

V1=V[0::2]
V2=V[1::2]

V1c=Counter(V1).most_common()
V2c=Counter(V2).most_common()
print(V1c)
print(V2c)


if V1c[0][0]==V2c[0][0]:
  if len(V1c)==1 and len(V2c)==1:
    print(n//2)
  elif len(V1c)==1:
    print(V2c[0][1])
  elif len(V2c)==1:
    print(V1c[0][1])   
  else:
    print(n-max(V1c[0][1]+V2c[1][1],V1c[1][1]+V2c[0][1]))
else:
  print(n-V1c[0][1]-V2c[0][1])

Submission status: Wrong Answer

Solution code:
#%%
import collections

n = int(input())
v = list(input().split())
v1 = v[0::2]
v2 = v[1::2]

#print(v1)
#print(v2)


l1 = list(collections.Counter(v1).items())
l2 = list(collections.Counter(v2).items())

#print(l1)
#print(l2)

if l1[0][0] != l2[0][0]:
    tmp = l1[0][1] + l2[0][1]
else:
    if len(l1) > 1 and len(l2) > 1: 
        tmp = max(l1[1][1] + l2[0][1], l1[0][1] + l2[1][1])
    elif len(l1) == 1 and len(l2) > 1:
        tmp = max(l2[0][1], l1[0][1] + l2[1][1])
    elif len(l2) == 1 and len(l1) > 1:
        tmp = max(l1[1][1] + l2[0][1], l1[0][1])
    else:
        tmp = max(l2[0][1], l1[0][1])

ans = n - tmp
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
v = input().split()
set_v = set(v)
if len(set_v) == 1:
  print(len(v)//2)
else:
  cnt_a , cnt_b = 0,0
  for i in range(3,n+1,2):
    if v[1] !=v[i]:
      cnt_a +=1
  for i in range(2,n,2):
    if v[0] !=v[i]:
      cnt_b +=1
  print(cnt_a+cnt_b)

Submission status: Wrong Answer

Solution code:
n = int(input())
v = input().split()
set_v = set(v)
if set_v == 1:
  print(len(v)//2)
else:
  cnt_a , cnt_b = 0,0
  for i in range(3,n+1,2):
    if v[1] !=v[i]:
      cnt_a +=1
  for i in range(2,n,2):
    if v[0] !=v[i]:
      cnt_b +=1
  print(cnt_a+cnt_b)

Submission status: Wrong Answer

Solution code:
def count_rewrite(v):
  ct = {}
  for x in v:
    if x in ct:
      ct[x] += 1
    else:
      ct[x] = 1
  total = 0
  max = 0
  maxx = 0
  for x in ct:
    total += ct[x]
    if ct[x] > max:
      nmax = max
      max = ct[x]
      maxx = x
  return maxx, total - max, total - nmax
n = int(input())
v = [int(e) for e in input().split()]
r1 = count_rewrite(v[::2])
r2 = count_rewrite(v[1::2])
if r1[0] != r2[0]:
  print(r1[1] + r2[1])
else:
  if r1[2] >= r2[2]:
    print(r1[1] + r2[2])
  else:
    print(r1[2] + r2[1])

Submission status: Wrong Answer

Solution code:
def count_rewrite(v):
  ct = {}
  for x in v:
    if x in ct:
      ct[x] += 1
    else:
      ct[x] = 1
  total = 0
  max = -1
  for x in ct:
    total += ct[x]
    if ct[x] > max:
      max = ct[x]
  return total - max
n = int(input())
v = [int(e) for e in input().split()]
print(count_rewrite(v[::2]) + count_rewrite(v[1::2]))

Submission status: Wrong Answer

Solution code:
from itertools import groupby
N = int(input())
v_list = list(map(int, input().split()))
v_list.sort()
first = 0
second = 0
for key, group in groupby(v_list):
    count = len(list(group))
    # print(key, count)
    if count >= first:
        first, second = count, first
    elif count >= second:
        second = count

# print("1，2番目に多い要素の数", first, second)

rest = N - first - second

if N//2 < first:  # 3位以下を2位に変えても追いつかないとき
    print(rest + (first - N // 2))
else:  # 3位以下をうまく振り分ければよいとき
    print(rest)

Submission status: Wrong Answer

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

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

Z = X + Y
X_srt = collections.Counter(X)
Y_srt = collections.Counter(Y)
Z_srt = collections.Counter(Z)
X_mc0 = X_srt.most_common()[0][0]
Y_mc0 = Y_srt.most_common()[0][0]
Z_mc0 = Z_srt.most_common()[0][0]
a_0 = X_srt[X_mc0]
b_0 = Y_srt[Y_mc0]
c_0 = Z_srt[Z_mc0]

if len(Z) == c_0:
    print(int(n/2))
else:
    if X_mc0 != Y_mc0:
        print(n - a_0 - b_0)
    else:
        X_mc1 = X_srt.most_common()[1][0]
        Y_mc1 = Y_srt.most_common()[1][0]
        a_1 = X_srt[X_mc1]
        b_1 = Y_srt[X_mc1]
        if X_mc1 >= Y_mc1:
            print(n - a_1 - b_0)
        else:
            print(n - a_0 - b_1)

Submission status: Wrong Answer

Solution code:
import collections as c
n = int(input())
v = list(map(int,input().split()))
pre = c.Counter([v[i] for i in range(n) if i%2==0])
epi = c.Counter([v[i] for i in range(n) if i%2==1])
ans = sum(pre.values()) - max(pre.values()) + sum(epi.values()) - max(epi.values())
if len(list(set(v))) == 1:
    print(n//2)
else:
    print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
import numpy as np
v = np.array(list(map(int, input().split())))
vset = tuple(set(v))
import itertools

count = 10**9

for a,b in itertools.combinations(vset,2):
  alist = [a,b] * (n//2)
  blist = [b,a] * (n//2)
  count = min(count, min(sum(v==alist), sum(v==blist)))
  
print(count)

Submission status: Wrong Answer

Solution code:
from collections import Counter

N = int(input())
V = [int(i) for i in input().split()]
V1 = V[1::2]
V2 = V[0::2]

v1 = Counter(V1).most_common(2)
v2 = Counter(V2).most_common(2)

v1.append((0,0))
v2.append((0,0))

if V1 == V2:
  print(N // 2)

elif v1[0][0] != v2[0][0]:
  print(N - v1[0][1] - v2[0][1])
  
else:
  print(min(N - v1[1][1] - v2[0][1], N - v1[0][1] - v2[1][1]))

Submission status: Wrong Answer

Solution code:
from collections import Counter

N = int(input())
V = [int(i) for i in input().split()]
V1 = V[1::2]
V2 = V[0::2]

v1 = Counter(V1)
v2 = Counter(V2)

if v1 == v2:
  print(N // 2)

elif v1.most_common()[0][0] != v2.most_common()[0][0]:
  print(N - v1.most_common()[0][1] - v2.most_common()[0][1])
else:
  print(min(N - v1.most_common(2)[0][1] - v2.most_common(1)[0][1],N - v1.most_common(1)[0][1] - v2.most_common(2)[0][1]))

Submission status: Wrong Answer

Solution code:
n = int(input()) # sを取得し、strに値を入れる
num= input()
num=list(map(int,num.split()))

from collections import defaultdict

d0=defaultdict(int)
d1=defaultdict(int)
for i in range(n):
    if i%2==0:
        d0[num[i]]+=1
    else:
        d1[num[i]]+=1

l0=[(k,d0[k]) for k in d0]
l1=[(k,d1[k]) for k in d1]
l0=sorted(l0, key=lambda d:d[1],reverse=True)
l1=sorted(l1,key=lambda d:d[1],reverse=True)
l0.append(("wild card",0))
l1.append(("wild card",0))

if l0[0][0]!=l1[0][0]:
    print(len(num)-l0[0][1]-l1[0][1])
elif n==2:
    print(1)
else:
    s=0
    if l0[0][1]>=l1[0][1]:
        s=l0[0][1]+l1[1][1]
    else:
        s=l0[1][1]+l1[0][1]
    print(n-s)

Submission status: Wrong Answer

Solution code:
n = int(input()) # sを取得し、strに値を入れる
num= input()
num=list(map(int,num.split()))

from collections import defaultdict

d0=defaultdict(int)
d1=defaultdict(int)
for i in range(n):
    if i%2==0:
        d0[num[i]]+=1
    else:
        d1[num[i]]+=1

l0=[(k,d0[k]) for k in d0]
l1=[(k,d1[k]) for k in d1]
l0=sorted(l0, key=lambda d:d[1],reverse=True)
l1=sorted(l1,key=lambda d:d[1],reverse=True)
l0.append(("wild card",0))
l1.append(("wild card",0))

if l0[0][0]!=l1[0][0]:
    print(len(num)-l0[0][1]-l1[0][1])
elif len(num)==2:
    print(1)
else:
    s=0
    if l0[0][1]>=l1[0][1]:
        s=l0[0][1]+l1[1][1]
    else:
        s=l0[1][1]+l1[0][1]
    print(len(num)-s)

Submission status: Wrong Answer

Solution code:
str = input() # sを取得し、strに値を入れる
num= input()
num=list(map(int,num.split()))

from collections import defaultdict

d0=defaultdict(int)
d1=defaultdict(int)
for i in range(len(num)):
    if i%2==0:
        d0[num[i]]+=1
    else:
        d1[num[i]]+=1

l0=[(k,d0[k]) for k in d0]
l1=[(k,d1[k]) for k in d1]
l0=sorted(l0, key=lambda d:d[1],reverse=True)
l1=sorted(l1,key=lambda d:d[1],reverse=True)
l0.append((0,0))
l1.append((0,0))
l0.append((0,0))
l1.append((0,0))

if l0[0][0]!=l1[0][0]:
    print(len(num)-l0[0][1]-l1[0][1])
else:
    s=0
    if l0[0][1]>=l1[0][1]:
        s=l0[0][1]+l1[1][1]
    else:
        s=l0[1][1]+l1[0][1]
    print(len(num)-s)

Submission status: Wrong Answer

Solution code:
str = input() # sを取得し、strに値を入れる
num= input()
num=list(map(int,num.split()))
from collections import defaultdict

d0=defaultdict(int)
d1=defaultdict(int)
for i in range(len(num)):
    if i%2==0:
        d0[num[i]]+=1
    else:
        d1[num[i]]+=1

l0=[(k,d0[k]) for k in d0]
l1=[(k,d1[k]) for k in d1]
l0=sorted(l0, key=lambda d:d[1],reverse=True)
l1=sorted(l1,key=lambda d:d[1],reverse=True)
l0.append((0,0))
l1.append((0,0))

if l0[0][0]!=l1[0][0]:
    print(len(num)-l0[0][1]-l1[0][1])
else:
    s=0
    if l0[0][1]>=l1[0][1]:
        s=l0[0][1]+l1[1][1]
    else:
        s=l0[1][1]+l1[0][1]
    print(len(num)-s)

Submission status: Wrong Answer

Solution code:


sequence_list=[]
sequence_even_value_cnt_sortlist=[]
sequence_odd_value_cnt_sortlist=[]
sequence_even_value_cnt={}
sequence_odd_value_cnt={}
even_2_maxnum=0
odd_2_maxnum=0

sequence_num=int(input())
sequence_list=input().split()

for i in range(sequence_num):
    if i%2==0:
        sequence_even_value_cnt[sequence_list[i]]=sequence_even_value_cnt.get(sequence_list[i],0)+1
    else:
        sequence_odd_value_cnt[sequence_list[i]]=sequence_odd_value_cnt.get(sequence_list[i],0)+1
        
sequence_even_value_cnt_sortlist=sorted(sequence_even_value_cnt.items(),key=lambda x:x[1],reverse=True)
sequence_odd_value_cnt_sortlist=sorted(sequence_odd_value_cnt.items(),key=lambda x:x[1],reverse=True)

even_1_maxnum=sequence_even_value_cnt_sortlist[0][1]
odd_1_maxnum=sequence_odd_value_cnt_sortlist[0][1]

for j in sequence_even_value_cnt_sortlist:
    
    if even_1_maxnum!=j[1]:
        even_2_maxnum=j[1]
        break

for k in sequence_odd_value_cnt_sortlist:
    
    if odd_1_maxnum!=k[1]:
        odd_2_maxnum=k[1]
        break

if sequence_even_value_cnt_sortlist[0][0]!=sequence_odd_value_cnt_sortlist[0][0]:
    ans=sequence_num-(even_1_maxnum+odd_1_maxnum)
elif len(sequence_even_value_cnt_sortlist)==1 and len(sequence_odd_value_cnt_sortlist)==1:
    ans=sequence_num//2
elif even_2_maxnum>odd_2_maxnum:
    ans=sequence_num-(even_2_maxnum+odd_1_maxnum)
else:
    ans=sequence_num-(even_1_maxnum+odd_2_maxnum)

print(ans)

Submission status: Wrong Answer

Solution code:


sequence_list=[]
sequence_even_value_cnt_sortlist=[]
sequence_odd_value_cnt_sortlist=[]
sequence_even_value_cnt={}
sequence_odd_value_cnt={}
even_2_maxnum=0
odd_2_maxnum=0

sequence_num=int(input())
sequence_list=input().split()

for i in range(sequence_num):
    if i%2==0:
        sequence_even_value_cnt[sequence_list[i]]=sequence_even_value_cnt.get(sequence_list[i],0)+1
    else:
        sequence_odd_value_cnt[sequence_list[i]]=sequence_odd_value_cnt.get(sequence_list[i],0)+1
        
sequence_even_value_cnt_sortlist=sorted(sequence_even_value_cnt.items(),key=lambda x:x[1],reverse=True)
sequence_odd_value_cnt_sortlist=sorted(sequence_odd_value_cnt.items(),key=lambda x:x[1],reverse=True)

even_1_maxnum=sequence_even_value_cnt_sortlist[0][1]
odd_1_maxnum=sequence_odd_value_cnt_sortlist[0][1]

for j in sequence_even_value_cnt_sortlist:
    
    if even_1_maxnum!=j[1]:
        even_2_maxnum=j[1]
        break

for k in sequence_odd_value_cnt_sortlist:
    
    if odd_1_maxnum!=k[1]:
        odd_2_maxnum=k[1]
        break

if sequence_even_value_cnt_sortlist[0][0]!=sequence_odd_value_cnt_sortlist[0][0]:
    ans=sequence_num-(even_1_maxnum+odd_1_maxnum)
elif len(sequence_even_value_cnt_sortlist)==1 and len(sequence_odd_value_cnt_sortlist)==1:
    ans=sequence_num//2
elif even_2_maxnum>=odd_2_maxnum:
    ans=sequence_num-(even_2_maxnum+odd_1_maxnum)
else:
    ans=sequence_num-(even_1_maxnum+odd_2_maxnum)

print(ans)

Submission status: Wrong Answer

Solution code:


sequence_list=[]
sequence_even_value_cnt_sortlist=[]
sequence_odd_value_cnt_sortlist=[]
sequence_even_value_cnt={}
sequence_odd_value_cnt={}
even_2_maxnum=0
odd_2_maxnum=0

sequence_num=int(input())
sequence_list=input().split()

for i in range(sequence_num):
    if i%2==0:
        sequence_even_value_cnt[sequence_list[i]]=sequence_even_value_cnt.get(sequence_list[i],0)+1
    else:
        sequence_odd_value_cnt[sequence_list[i]]=sequence_odd_value_cnt.get(sequence_list[i],0)+1
        
sequence_even_value_cnt_sortlist=sorted(sequence_even_value_cnt.items(),key=lambda x:x[1],reverse=True)
sequence_odd_value_cnt_sortlist=sorted(sequence_odd_value_cnt.items(),key=lambda x:x[1],reverse=True)

even_1_maxnum=sequence_even_value_cnt_sortlist[0][1]
odd_1_maxnum=sequence_odd_value_cnt_sortlist[0][1]

for j in sequence_even_value_cnt_sortlist:
    
    if even_1_maxnum!=j[1]:
        even_2_maxnum=j[1]
        break

for k in sequence_odd_value_cnt_sortlist:
    
    if odd_1_maxnum!=k[1]:
        odd_2_maxnum=k[1]
        break

if sequence_even_value_cnt_sortlist[0][0]!=sequence_odd_value_cnt_sortlist[0][0]:
    ans=sequence_num-(even_1_maxnum+odd_1_maxnum)
else:
    if even_2_maxnum>=odd_2_maxnum:
        ans=sequence_num-(even_2_maxnum+odd_1_maxnum)
    else:
        ans=sequence_num-(even_1_maxnum+odd_2_maxnum)

print(ans)

Submission status: Wrong Answer

Solution code:


sequence_list=[]
sequence_even_value_cnt_sortlist=[]
sequence_odd_value_cnt_sortlist=[]
sequence_even_value_cnt={}
sequence_odd_value_cnt={}
even_2_maxnum=0
odd_2_maxnum=0

sequence_num=int(input())
sequence_list=input().split()

for i in range(sequence_num):
    if i%2==0:
        sequence_even_value_cnt[sequence_list[i]]=sequence_even_value_cnt.get(sequence_list[i],0)+1
    else:
        sequence_odd_value_cnt[sequence_list[i]]=sequence_odd_value_cnt.get(sequence_list[i],0)+1
        
print(sequence_odd_value_cnt)
print(sequence_even_value_cnt)
    
sequence_even_value_cnt_sortlist=sorted(sequence_even_value_cnt.items(),key=lambda x:x[1],reverse=True)
sequence_odd_value_cnt_sortlist=sorted(sequence_odd_value_cnt.items(),key=lambda x:x[1],reverse=True)

even_1_maxnum=sequence_even_value_cnt_sortlist[0][1]
odd_1_maxnum=sequence_odd_value_cnt_sortlist[0][1]

for j in sequence_even_value_cnt_sortlist:
    
    if even_1_maxnum!=j[1]:
        even_2_maxnum=j[1]
        break

for k in sequence_odd_value_cnt_sortlist:
    
    if odd_1_maxnum!=k[1]:
        odd_2_maxnum=k[1]
        break

if sequence_even_value_cnt_sortlist[0][0]!=sequence_odd_value_cnt_sortlist[0][0]:
    ans=sequence_num-(even_1_maxnum+odd_1_maxnum)
else:
    if even_2_maxnum>=odd_2_maxnum:
        ans=sequence_num-(even_2_maxnum+odd_1_maxnum)
    else:
        ans=sequence_num-(even_1_maxnum+odd_2_maxnum)

print(ans)

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
v = list(map(int, input().split()))
a = []
b = []
for i in range(n // 2):
    a.append(v[(i+1)*2-1])
    b.append(v[(i+1)*2-2])
a = collections.Counter(a)
b = collections.Counter(b)


if a.most_common()[0][0] != b.most_common()[0][0]:
    print(n-a.most_common()[0][1]-b.most_common()[0][1])
else:
    print(1)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Tue Jun 11 10:08:15 2019

@author: plosi
"""

def main(): 
    n=int(input()) 
    arr=input().split(" ") 
    o=[] 
    e=[] 
    for i in range(n): 
        if i%2==0: 
            e.append(int(arr[i])) 
        else: 
            o.append(int(arr[i])) 
    de={}
    for i in range(len(e)): 
        if e[i] not in de: 
            de[e[i]]=1 
        else: 
            de[e[i]]=de[e[i]]+1 
    do={}
    for i in range(len(o)): 
        if o[i] not in do: 
            do[o[i]]=1 
        else: 
            do[o[i]]=do[o[i]]+1
    me=0
    for key in de:
        if de[key]>me: 
            me=de[key] 
    mo=0
    for key in do: 
        if do[key]>mo: 
            mo=do[key] 
    print(n-(mo+me))
main()

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
v = list(map(int, input().split()))
even = [v[2*i] for i in range(n//2)]
odd = [v[2*i+1] for i in range(n//2)]
dEven = collections.Counter(even).most_common()
dOdd = collections.Counter(odd).most_common()
if dEven[0][0] != dOdd[0][0]:
    ans = n - dEven[0][1]  - dOdd[0][1]
else:
    if len(dEven) >=2 and len(dOdd) >= 2:
        ans = n - max(dEven[0][0]+dOdd[1][0], dEven[1][0]+dOdd[0][0])
    elif len(dEven) < len(dOdd):
        ans = n - (dEven[0][0]+dOdd[1][0])
    elif len(dEven) > len(dOdd):
        ans = n - (dEven[1][0]+dOdd[0][0])
    else:
        ans = n//2
print(ans)

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
v = list(map(int, input().split()))
even = [v[2*i] for i in range(n//2)]
odd = [v[2*i+1] for i in range(n//2)]
dEven = collections.Counter(even).most_common()
dOdd = collections.Counter(odd).most_common()
if dEven[0][0] != dOdd[0][0]:
    ans = n - dEven[0][1]  - dOdd[0][1]
else:
    if len(dEven) >=2 and len(dOdd) >= 2:
        ans = n - max(dEven[0][1]+dOdd[1][0], dEven[1][0]+dOdd[0][1])
    elif len(dEven) < len(dOdd):
        ans = n - (dEven[0][1]+dOdd[1][0])
    elif len(dEven) > len(dOdd):
        ans = n - (dEven[1][0]+dOdd[0][1])
    else:
        ans = n//2
print(ans)

Submission status: Wrong Answer

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

v1, v2 = {}, {}

for v in V[::2]:
	if not v in v1:
		v1[v] = 1
	else:
		v1[v] += 1

for v in V[1::2]:
	if not v in v2:
		v2[v] = 1
	else:
		v2[v] += 1

a1 = sorted(v1, key=lambda x:v1[x])
a2 = sorted(v2, key=lambda x:v2[x])

r = []
for k1 in a1[:2]:
	for k2 in a2[:2]:
		if k1 != k2:
			r += [N - v1[k1] - v2[k2]]

if not r:
	r += [N // 2]

#print(r)
print(min(r))

Submission status: Wrong Answer

Solution code:
n = int(input())
l = input().split()
v = [sorted([int(l[2 * i]) for i in range(n // 2)]) + [-1], \
sorted([int(l[2 * i + 1]) for i in range(n // 2)]) + [-1]]

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

m[0] = sorted(m[0], reverse = True)
m[1] = sorted(m[1], reverse = True)

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

Submission status: Wrong Answer

Solution code:
n = int(input())
l = input().split()
v = [sorted([int(l[2 * i]) for i in range(n // 2)]) + [-1], \
sorted([int(l[2 * i + 1]) for i in range(n // 2)]) + [-1]]

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

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

Submission status: Wrong Answer

Solution code:
n = int(input())
l = input().split()
v = [sorted([int(l[2 * i]) for i in range(n // 2)]), \
sorted([int(l[2 * i + 1]) for i in range(n // 2)])]

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

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

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

Submission status: Wrong Answer

Solution code:
n = int(input())
l = input().split()
v = [sorted([int(l[2 * i]) for i in range(n // 2)]), \
sorted([int(l[2 * i + 1]) for i in range(n // 2)])]

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

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

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

Submission status: Wrong Answer

Solution code:
n = int(input())
l = input().split()
v = [sorted([int(l[2 * i]) for i in range(n // 2)]), \
sorted([int(l[2 * i + 1]) for i in range(n // 2)])]

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

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

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