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:
from collections import defaultdict

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

if len(set(L)) == 1:
    print(N//2)
    exit()
if N == 2:
    print(0)
    exit()


d_even = defaultdict(int)
d_odd = defaultdict(int)

for i in range(N):
    v = L[i]
    if i % 2 == 0:
        d_even[v] += 1
    else:
        d_odd[v] += 1

l_even = sorted(d_even.items(), key=lambda x: -x[1])
l_odd = sorted(d_odd.items(), key=lambda x: -x[1])

if l_even[0][0] != l_odd[0][0]:
    print(N - l_odd[0][1] - l_even[0][1])
    exit()

ans = N
ans = min(N, N - l_odd[0][1] - l_even[1][1])
ans = min(N, N - l_odd[1][1] - l_even[0][1])
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

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

if len(set(L)) == 1:
    print(N//2)
    exit()
if N == 2:
    print(0)
    exit()


d_even = defaultdict(int)
d_odd = defaultdict(int)

for i in range(N):
    v = L[i]
    if i % 2 == 0:
        d_even[v] += 1
    else:
        d_odd[v] += 1

l_even = sorted(d_even.items(), key=lambda x: -x[1])
l_odd = sorted(d_odd.items(), key=lambda x: -x[1])

odd_1 = l_odd[0]
even_1 = l_even[0]

if even_1[0] != odd_1[0]:
    print(N - odd_1[1] - even_1[1])
    exit()

even_2 = l_even[1]
odd_2 = l_odd[1]

ans = N
ans = min(N, N - odd_1[1] - even_2[1])
ans = min(N, N - odd_2[1] - even_1[1])
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

N = int(input())
L = list(map(int, input().split()))
odd = [v for i, v in enumerate(L) if i % 2 == 0]
even = [v for i, v in enumerate(L) if i % 2 == 1]

if len(set(L)) == 1:
    print(N//2)
    exit()
if N == 2:
    print(0)
    exit()


c_odd = sorted(dict(Counter(odd)).items(), key=lambda x: -x[1])
c_even = sorted(dict(Counter(even)).items(), key=lambda x: -x[1])

odd_1 = c_odd[0]
even_1 = c_even[0]

if odd_1[0] != even_1[0]:
    print(N - odd_1[1] - even_1[1])
    exit()

even_2 = c_even[1]
odd_2 = c_odd[1]

ans = N
ans = min(N, N - odd_1[1] - even_2[1])
ans = min(N, N - odd_2[1] - even_1[1])
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

N = int(input())
L = list(map(int, input().split()))
odd = [v for i, v in enumerate(L) if i % 2 == 0]
even = [v for i, v in enumerate(L) if i % 2 == 1]

if len(set(L)) == 1:
    print(N//2)
    exit()
if N == 2:
    print(0)
    exit()


c_odd = sorted(dict(Counter(odd)).items(), key=lambda x: -x[1])
c_even = sorted(dict(Counter(even)).items(), key=lambda x: -x[1])

odd_1 = c_odd[0]
odd_2 = (0, 0)
if len(c_odd) > 1:
    odd_2 = c_odd[1]
even_1 = c_even[0]
even_2 = (0, 0)
if len(c_even) > 1:
    even_2 = c_even[1]

if odd_1[0] != even_1[0]:
    print(N - odd_1[1] - even_1[1])
    exit()

ans = N
ans = min(N, N - odd_1[1] - even_2[1])
ans = min(N, N - odd_2[1] - even_1[1])
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

N = int(input())
L = list(map(int, input().split()))
odd = [v for i, v in enumerate(L) if i % 2 == 0]
even = [v for i, v in enumerate(L) if i % 2 == 1]

if len(set(L)) == 1:
    print(N//2)
    exit()
if N == 2:
    print(1)
    exit()


c_odd = sorted(dict(Counter(odd)).items(), key=lambda x: -x[1])
c_even = sorted(dict(Counter(even)).items(), key=lambda x: -x[1])

odd_1 = c_odd[0]
odd_2 = c_odd[0]
if len(c_odd) > 1:
    odd_2 = c_odd[1]
even_1 = c_even[0]
even_2 = c_even[0]
if len(c_even) > 1:
    even_2 = c_even[1]

if odd_1[0] != even_1[0]:
    print(N - odd_1[1] - even_1[1])
    exit()

ans = N
ans = min(N, N - odd_1[1] - even_2[1])
ans = min(N, N - odd_2[1] - even_1[1])
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

N = int(input())
L = list(map(int, input().split()))
odd = [v for i, v in enumerate(L) if i % 2 == 0]
even = [v for i, v in enumerate(L) if i % 2 == 1]

if len(set(L)) == 1:
    print(N//2)
    exit()
if N == 2:
    print(0)
    exit()


c_odd = sorted(dict(Counter(odd)).items(), key=lambda x: -x[1])
c_even = sorted(dict(Counter(even)).items(), key=lambda x: -x[1])

odd_1 = c_odd[0]
odd_2 = c_odd[0]
if len(c_odd) > 1:
    odd_2 = c_odd[1]
even_1 = c_even[0]
even_2 = c_even[0]
if len(c_even) > 1:
    even_2 = c_even[1]

if odd_1[0] != even_1[0]:
    print(N - odd_1[1] - even_1[1])
    exit()

ans = N
ans = min(N, N - odd_1[1] - even_2[1])
ans = min(N, N - odd_2[1] - even_1[1])
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

N = int(input())
L = list(map(int, input().split()))
odd = [v for i, v in enumerate(L) if i % 2 == 0]
even = [v for i, v in enumerate(L) if i % 2 == 1]

if N == 2:
    if odd == even:
        print(2)
    else:
        print(0)
    exit()

if odd == even:
    print(N//2)
    exit()

c_odd = sorted(dict(Counter(odd)).items(), key=lambda x: -x[1])
c_even = sorted(dict(Counter(even)).items(), key=lambda x: -x[1])

odd_1 = c_odd[0]
odd_2 = c_odd[0]
if len(c_odd) > 1:
    odd_2 = c_odd[1]
even_1 = c_even[0]
even_2 = c_even[0]
if len(c_even) > 1:
    even_2 = c_even[1]

if odd_1[0] != even_1[0]:
    print(N - odd_1[1] - even_1[1])
    exit()

ans = N
ans = min(N, N - odd_1[1] - even_2[1])
ans = min(N, N - odd_2[1] - even_1[1])
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
V = list(map(int,input().split()))
if len(set(V)) == 1:
  print(n//2)
else:
  odd = []
  even = []
  for i in range(len(V)):
    if i % 2 == 0:
      even.append(V[i])
    else:
      odd.append(V[i])
  max_even,max_e_count = Counter(even).most_common(1)[0]
  max_odd,max_o_count = Counter(odd).most_common(1)[0]
  if max_even == max_odd:
    sec_even,sec_e_count = Counter(even).most_common(2)[1]
    print(len(odd) - max_o_count + len(even) - sec_e_count)
  else:
    print(len(odd) - max_o_count + len(even) - max_e_count)

Submission status: Wrong Answer

Solution code:
import sys
import collections


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n = int(readline())
    v = list(map(int, readline().split()))
    ve = collections.Counter(v[0::2]).most_common()
    vo = collections.Counter(v[1::2]).most_common()
    if ve[0][0] != vo[0][0]:
        print((n // 2 - ve[0][1]) + (n // 2 - vo[0][1]))
    else:
        if len(ve) == len(vo) == 1:
            print(n // 2)
        elif len(ve) == 1:
            print((n // 2 - ve[0][1]) + (n // 2 - vo[1][1]))
        elif len(vo) == 1:
            print((n // 2 - ve[1][1]) + (n // 2 - vo[0][1]))
        else:
            print(max((n // 2 - ve[0][1]) + (n // 2 - vo[1][1]), (n // 2 - ve[1][1]) + (n // 2 - vo[0][1])))



if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
b=a[::2]
c=a[1::2]
def f(ls):
    max1=-float("INF")
    max2=-float("INF")
    for i in ls:
        if max1<i:
            max1=i
        elif max2<i:
            max2=i
    return max1,max2

b1,b2=f(b)
c1,c2=f(c)
b1_cnt=b.count(b1)
c1_cnt=c.count(c1)
if b1!=c1:
    print(n-b1_cnt-c1_cnt)
else:
    if b1_cnt>c1_cnt:
        print(n-b1_cnt-c.count(c2))
    elif b1_cnt<c1_cnt:
        print(n-c1_cnt-b.count(b2))
    else:
        c2_cnt=c.count(c2)
        b2_cnt=b.count(b2)
        if b2_cnt>c2_cnt:
            print(n-b1_cnt-b2_cnt)
        elif b2_cnt<c2_cnt:
            print(n-b1_cnt-c2_cnt)
        else:
            print(n//2)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
v = list(map(int,input().split()))
a = []
b = []
for i in range(0,n,2):
    a.append(v[i])
    b.append(v[i+1])
a = Counter(a)
b = Counter(b)
p = a.most_common()[0][1]
q = b.most_common()[0][1]
if a.most_common()[0][0] == b.most_common()[0][0]:
    print(n-p-q+n//2)
else:
    print(n-p-q)

Submission status: Wrong Answer

Solution code:
n = int(input())
l = list(map(int, input().split()))
a = {}
b = {}
for i in range(n // 2):
    key_a = l[i * 2]
    key_b = l[i * 2 + 1]
    if key_a in a:
        a[key_a] = a[key_a] + 1
    else:
        a[l[i * 2]] = 1
    if key_b in b:
        b[key_b] = b[key_b] + 1
    else:
        b[key_b] = 1
sorted(a.items(), key=lambda x: x[1], reverse=True)
sorted(b.items(), key=lambda x: x[1], reverse=True)
a = list(a.items())
b = list(b.items())
ca_max = a[0]
cb_max = b[0]
ca_max_num = a[0][1]
cb_max_num = b[0][1]
if ca_max[0] == cb_max[0]:
    if ca_max[1] > cb_max[1]:
        if len(b) > 1:
            cb_max_num = b[1][1]
        else:
            cb_max_num = 0
    else:
        if len(a) > 1:
            ca_max_num = a[1][1]
        else:
            ca_max_num = 0
print((n // 2) * 2 - ca_max_num - cb_max_num)

Submission status: Wrong Answer

Solution code:
n = int(input())
l = list(map(int, input().split()))
a = []
b = []
ca = []
cb = []
for i in range(n // 2):
    a.append(l[i * 2])
    b.append(l[i * 2 + 1])
num = 0
while (len(a) > 0 and num < 2):
    num += 1
    ca.append([a[0], a.count(a[0])])
    a = [s for s in a if not (s == a[0])]
num = 0
while (len(b) > 0 and num < 2):
    num += 1
    cb.append([b[0], b.count(b[0])])
    b = [s for s in b if not (s == b[0])]
ca.sort(key=lambda x: x[1], reverse=True)
cb.sort(key=lambda x: x[1], reverse=True)
ca_max = ca[0]
cb_max = cb[0]
ca_max_num = ca[0][1]
cb_max_num = cb[0][1]
if ca_max[0] == cb_max[0]:
    if ca_max[1] > cb_max[1]:
        if len(cb) > 1:
            cb_max_num = cb[1][1]
        else:
            cb_max_num = 0
    else:
        if len(ca) > 1:
            ca_max_num = ca[1][1]
        else:
            ca_max_num = 0
print((n // 2) * 2 - ca_max_num - cb_max_num)

Submission status: Wrong Answer

Solution code:
import sys
from collections import Counter

sys.setrecursionlimit(10**6)
if sys.platform in (['ios','darwin','win32']):
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return [int(s) for s in input().split()]

N = INT()
A = MAP()

c = Counter(A)
v, c = zip(*c.most_common(2))
if max(c) == 1:
	print(N-2)
	sys.exit
if len(v) < 2:
	print(N//2)
	sys.exit()
a = v[0]
b = v[1]

can_a = [a if i%2 else b for i in range(N)]
can_b = [b if i%2 else a for i in range(N)]
#print(can_a, can_b)

cand = [can_a, can_b]
ans = float('INF')
for c in cand:
	cnt = 0
	for i in range(N):
		if c[i] != A[i]: cnt+=1
	ans = min(ans, cnt)

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
from collections import Counter

sys.setrecursionlimit(10**6)
if sys.platform in (['ios','darwin','win32']):
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return [int(s) for s in input().split()]

N = INT()
A = MAP()

c = Counter(A)
v, _ = zip(*c.most_common(3))
if len(v) < 2:
	print(N//2)
	sys.exit()
a = v[0]
b = v[1]
if len(v) == 3:
	c = v[2]
	#print(a, b)

can_a = [a if i%2 else b for i in range(N)]
can_b = [b if i%2 else a for i in range(N)]
can_c = [a if i%2 else c for i in range(N)]
#print(can_a, can_b)

cand = [can_a, can_b, can_c]
ans = float('INF')
for c in cand:
	cnt = 0
	for i in range(N):
		if c[i] != A[i]: cnt+=1
	ans = min(ans, cnt)

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
from collections import Counter

sys.setrecursionlimit(10**6)
if sys.platform in (['ios','darwin','win32']):
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return [int(s) for s in input().split()]

N = INT()
A = MAP()

c = Counter(A)
v, _ = zip(*c.most_common(2))
if len(v) < 2:
	print(N//2)
	sys.exit()
else:
	a = v[0]
	b = v[1]
	#print(a, b)

can_a = [a if i%2 else b for i in range(N)]
can_b = [b if i%2 else a for i in range(N)]
#print(can_a, can_b)

cand = [can_a, can_b]
ans = float('INF')
for c in cand:
	cnt = 0
	for i in range(N):
		if c[i] != A[i]: cnt+=1
	ans = min(ans, cnt)

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

v_odd=v[::2]
v_even=v[1::2]
c_odd=Counter(v_odd)
cm_odd=c_odd.most_common()
c_even=Counter(v_even)
cm_even=c_even.most_common()

if cm_odd[0][0]!=cm_even[0][0]:
    ans=(len(v_odd)-cm_odd[0][1]+len(v_even)-cm_even[0][1])
elif len(cm_odd)==1 and len(cm_even)==1:
    ans=n//2
elif len(cm_odd)==1:
    ans=len(v_even)-cm_even[1][1]
elif len(cm_even)==1:
    ans=len(v_odd)-cm_odd[1][1]
else:
    print('d')
    ans=min((len(v_odd)-cm_odd[1][1])+(len(v_even)-cm_even[0][1]),(len(v_odd)-cm_odd[0][1])+(len(v_even)-cm_even[1][1]))
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
b=a[::2]
c=a[1::2]
def f(l):
    dic={}
    for i in l:
        if i in dic:
            dic[i]+=1
        else:
            dic[i]=1
    return dic

db=f(b)
dc=f(c)

mb=max(db)
mc=max(dc)
if mb!=mc:
    print(len(a)-db[mb]-dc[mc])
    exit()
b1=db[mb]
db[mb]=0
c1=dc[mc]
dc[mc]=0

mb=max(db)
mc=max(dc)
if mb==mc:
    print(len(a)-b1-db[mb])
elif db[mb]>db[mc]:
    print(len(a)-db[mb]-b1)
else:
    print(len(a)-dc[mc]-b1)

Submission status: Wrong Answer

Solution code:
import collections
n=int(input())
v=list(map(int,input().split()))
v1=v[0::2]
v2=v[1::2]
if v1==v2:
  print(n//2)
else:
  c1 = collections.Counter(v1)
  c2 = collections.Counter(v2)
  arr1=c1.most_common()[1:]
  arr2=c2.most_common()[1:]
  total=0
  for a in arr1+arr2:
    total+=a[1]
  print(total)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
a1=a[::2]
a2=a[1::2]
if a1==a2:
    print(n//2)
    exit()
import collections as c
c1=c.Counter(a1)
c2=c.Counter(a2)
c1=c1.most_common()
c2=c2.most_common()
ans=0
if c1[0][0]==c2[0][0]:
    ans=min((n//2-c1[0][1])+(n//2-c2[1][1]),(n//2-c1[1][1])+(n//2-c2[0][1]))
else:
    ans=(n//2-c1[0][1])+(n//2-c2[0][1])
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
a1=a[::2]
a2=a[1::2]
if a1==a2:
    print(n//2)
    exit()
import collections as c
c1=c.Counter(a1)
c2=c.Counter(a2)
c1=c1.most_common()
c2=c2.most_common()
ans=0
if c1[0][0]==c2[0][0]:
    if c1[0][1]>=c2[0][1]:
        ans+=(n//2-c1[0][1])+(n//2-c2[1][1])
    else:
        ans+=(n//2-c1[1][1])+(n//2-c2[0][1])
else:
    ans+=(n//2-c1[0][1])+(n//2-c2[0][1])
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

o,e = [],[]
for i,m in enumerate(V):
    if i%2 == 0: e.append(m)
    else: o.append(m)

o = sorted([v for v in Counter(o).values()])
e = sorted([v for v in Counter(e).values()])

e1,o1 = e.pop(-1), o.pop(-1)
e2 = e.pop(-1) if len(e) != 0 else e1
o2 = o.pop(-1) if len(o) != 0 else o1

if len(list(set(V))) == 1:
    print(n//2)
    exit()

print(min(n-e1-o2, n-e2-o1))

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

o,e = [],[]
for i,m in enumerate(V):
    if i%2 == 0: e.append(m)
    else: o.append(m)

o = sorted([v for v in Counter(o).values()])
e = sorted([v for v in Counter(e).values()])

e1,o1 = e.pop(-1), o.pop(-1)
e2 = e.pop(-1) if e == True else e1
o2 = o.pop(-1) if o == True else o1

if len(list(set(V))) == 1:
    print(n//2)
    exit()

dn = n // 2
print(min( dn - e1 + dn - o2, dn - e2 + dn - o1 ))

Submission status: Wrong Answer

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

M = 10**5
C = [0 for i in range(M)]
D = [0 for i in range(M)]
for i in range(N):
    if i%2 == 0:
        C[V[i]-1]+=1
    else:
        D[V[i]-1]+=1
        
c,d = (N+1)//2,N//2

MC = max(C)
MD = max(D)

ans = 0
if C.index(MC) == D.index(MD):
    C[C.index(MC)]-=MC
    D[D.index(MD)]-=MC
    
    MC2 = max(C)
    MD2 = max(D)
    if c-MC + d-MD2 >= c-MC2 + d-MD:
        ans = c-MC + d-MD2
    else:
        ans = c-MC2 + d-MD
    
else:
    ans = c-MC + d-MD

print(ans)

Submission status: Wrong Answer

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

M = max(V)
C = [0 for i in range(M)]
D = [0 for i in range(M)]
for i in range(N):
    if i%2 == 0:
        C[V[i]-1]+=1
    else:
        D[V[i]-1]+=1
        
c,d = (N+1)//2,N//2

MC = max(C)
MD = max(D)

ans = 0
if C.index(MC) == D.index(MD):
    C[C.index(MC)]-=MC
    D[D.index(MD)]-=MC
    
    MC2 = max(C)
    MD2 = max(D)
    if c-MC + d-MD2 >= c-MC2 + d-MD:
        ans = c-MC + d-MD2
    else:
        ans = c-MC2 + d-MD
    
else:
    ans = c-MC + d-MD

print(ans)

Submission status: Wrong Answer

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

from collections import Counter
l1 = Counter(l[0::2])
mostl1 = l1.most_common()[0]
#semimostl1 = l1.most_common()[1]

l2 = Counter(l[1::2])
mostl2 = l2.most_common()[0]
#semimostl2 = l2.most_common()[1]

if mostl1[0] != mostl2[0]:
    print(n-mostl1[1]-mostl2[1])
elif l1 == l2:
    print(int(n/2))

else:
    semimostl1 = l1.most_common()[1]
    semimostl2 = l2.most_common()[1]
    print(min(n - mostl1[1] - semimostl2[1], n - semimostl1[1] - mostl2[1]))


#elif print(min(n-mostl1[1]-mostl2[1],n-mostl1[1]-mostl2[1]))

Submission status: Wrong Answer

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

from collections import Counter
l1 = Counter(l[0::2])
mostl1 = l1.most_common()[0]
#semimostl1 = l1.most_common()[1]

l2 = Counter(l[1::2])
mostl2 = l2.most_common()[0]
#semimostl2 = l2.most_common()[1]

if mostl1[0] != mostl2[0]:
    print(n-mostl1[1]-mostl2[1])
#elif print(min(n-mostl1[1]-mostl2[1],n-mostl1[1]-mostl2[1]))

Submission status: Wrong Answer

Solution code:
n=int(input())
v=list(map(int,input().split()))
a=[]
b=[]
for i in range(n):
    if i%2==0:
        a.append(v[i])
    else:
        b.append(v[i])
a.sort()
b.sort()
A=[0]*len(set(a))
B=[0]*len(set(b))
x=a[0]
y=0
for j in range(len(a)):
  if a[j]==x:
    A[y]+=1
  else:
    x=a[j]
    y+=1
    A[y]+=1
x=b[0]  
y=0
for k in range(len(b)):
  if b[k]==x:
    B[y]+=1
  else:
    x=b[k]
    y+=1
    B[y]+=1   
if sum(A)+sum(B)-max(A)-max(B)==0 and a[0]==b[0]:
  print(int(n/2))
else:
  print(sum(A)+sum(B)-max(A)-max(B))

Submission status: Wrong Answer

Solution code:
n=int(input())
v=list(map(int,input().split()))
a=[]
b=[]
for i in range(n):
    if i%2==0:
        a.append(v[i])
    else:
        b.append(v[i])
      
if len(set(a))+len(set(b))==2 and a[0]==b[0]:
    print(1)         
else:
    print(len(set(a))+len(set(b))-2)

Submission status: Wrong Answer

Solution code:
n = int(input())
v = list(map(int, input().split()))
evenVi = {}
oddVi = {}
for i in range(n):
    if i % 2 == 0:
        evenVi[v[i]] = evenVi.get(v[i], 0) + 1
    else:
        oddVi[v[i]] = oddVi.get(v[i], 0) + 1
evenCnt = sorted(list(evenVi.values()), reverse=True)
oddCnt = sorted(list(oddVi.values()), reverse=True)
evenCnt.append(0)
oddCnt.append(0)
if len(list(evenVi.keys())) == len(list(oddVi.keys())) == 1 and v[0] == v[1]:
    print(int(len(v)/2))
else:
    print(sum(evenCnt[1:]) + sum(oddCnt[1:]))

Submission status: Wrong Answer

Solution code:
n = int(input())
v = list(map(int, input().split()))
evenVi = {}
oddVi = {}
for i in range(n):
    if i % 2 == 0:
        evenVi[v[i]] = evenVi.get(v[i], 0) + 1
    else:
        oddVi[v[i]] = oddVi.get(v[i], 0) + 1
evenCnt = sorted(list(evenVi.values()), reverse=True)
oddCnt = sorted(list(oddVi.values()), reverse=True)
evenCnt.append(0)
oddCnt.append(0)
if len(list(evenVi.keys())) == len(list(oddVi.keys())) == 1 and v[0] == v[1]:
    print(int(len(v)/2))
else:
    print(evenCnt[1] + oddCnt[1])

Submission status: Wrong Answer

Solution code:
N=int(input())
A=[int(x) for x in input().split()]
sum_1=0
for i in range(0,N,2):
  sum_1 +=A[i]
sum_2=sum(A)-sum_1
p=sum_1//(N//2)
q=sum_2//(N//2)
if p!=q:
  answer=min(sum(A)-(p+q)*N//2,abs(sum(A)-(p+q+1)*N//2))
else:
  answer=abs(sum(A)-(p+q+1)*N//2)
print(answer)

Submission status: Wrong Answer

Solution code:
N=int(input())
A=[int(x) for x in input().split()]
answer =float('inf')
under=min(A)
upper=max(A)
if under==upper:
  print(N//2)
  exit()
for i in range(under,upper+1):
  for j in range(under,upper+1):
    if i==j:
      break
    diff=0
    for k in range(N):
      if k%2==0:
        diff +=abs(A[k]-i)
      elif k%2==1:
        diff +=abs(A[k]-j)
    answer = min(answer,diff)
print(answer)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys, math, itertools, heapq, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
sys.setrecursionlimit(10**8)
inf = float('inf')
ans = count = 0

n=int(input())
v=list(map(int,input().split()))
v1=[]
v2=[]
for i in range(n):
    if i%2==1:
        v2.append(v[i])
    else:
        v1.append(v[i])
c1=collections.Counter(v1)
c2=collections.Counter(v2)
c1[0]=0;c2[0]=0
c1 = sorted(c1.items(), key=lambda tup: tup[1])
c2 = sorted(c2.items(), key=lambda tup: tup[1])
if not c1[0][0]==c2[0][0]:
    print(n-c1[0][1]-c2[0][1])
else:
    print(min(n-c1[0][1]-c2[1][1],n-c1[1][1]-c2[0][1]))

Submission status: Wrong Answer

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

even = defaultdict(int)
odd = defaultdict(int)

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

even_arr = [even[i] for i in even]
odd_arr = [odd[i] for i in odd]
even_arr.sort()
odd_arr.sort()
even_res = sum(even_arr) - even_arr[-1]
odd_res = sum(odd_arr) - odd_arr[-1]

if even_arr[-1] == odd_arr[-1]:
    print(n // 2)
else:
    print(even_res + odd_res)

Submission status: Wrong Answer

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

even = defaultdict(int)
odd = defaultdict(int)

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

even_arr = [even[i] for i in even]
odd_arr = [odd[i] for i in odd]
even_arr.sort()
odd_arr.sort()
even_res = sum(even_arr) - even_arr[-1]
odd_res = sum(odd_arr) - odd_arr[-1]

if even_arr[-1] != odd_arr[-1]:
    print(n // 2)
else:
    print(even_res + odd_res)

Submission status: Wrong Answer

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

even = defaultdict(int)
odd = defaultdict(int)

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

even_arr = [even[i] for i in even]
odd_arr = [odd[i] for i in odd]
even_arr.sort()
odd_arr.sort()
even_res = sum(even_arr) - even_arr[-1]
odd_res = sum(odd_arr) - odd_arr[-1]

if list(even) == list(odd) and len(even) == 1:
    print(n // 2)
else:
    print(even_res + odd_res)

Submission status: Wrong Answer

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

even = defaultdict(int)
odd = defaultdict(int)

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

even_arr = [even[i] for i in even]
odd_arr = [odd[i] for i in odd]
even_arr.sort()
odd_arr.sort()
even_res = sum(even_arr) - even_arr[-1]
odd_res = sum(odd_arr) - odd_arr[-1]

if list(even) == list(odd):
    print(n // 2)
else:
    print(even_res + odd_res)

Submission status: Wrong Answer

Solution code:
n=int(input())
v=list(map(int,input().split()))
v.insert(0,0) #数合わせ
check=0 #全部同じ数字か？0なら全部同じ数字
now=v[1]
for i in range(2,n):
    if now!=v[i]:
        check=1
        break
        
odd=[]
even=[]
for i in range(1,n+1):
    if i%2==1:
        odd.append(v[i])
    else:
        even.append(v[i])
        
odd2=sorted(odd)
even2=sorted(even)
now_odd,now_even=odd2[0],even2[0]
rensa_odd,rensa_even=1,1
half=n//2
count_odd=[]
count_even=[]

for i in range(1,half):
    if odd2[i]==now_odd:
        rensa_odd+=1
    else:
        count_odd.append([rensa_odd,now_odd])
        now_odd=odd2[i]
        rensa_odd=1
count_odd.append([rensa_odd,now_odd])

for i in range(1,half):
    if even2[i]==now_even:
        rensa_even+=1
    else:
        count_even.append([rensa_even,now_even])
        now_even=even2[i]
        rensa_even=1
count_even.append([rensa_even,now_even])

if check==0:
    print(half)
else:
    if count_odd[0][1]!=count_even[0][1]: #最頻値が違う
        print((half-count_odd[0][0])+(half-count_even[0][0]))
    else:
        if len(count_odd)==1:
            print((half-count_odd[0][0])+(half-count_even[1][0]))
        elif len(count_even)==1:
            print((half-count_odd[1][0])+(half-count_even[0][0]))
        else:
            print(max((half-count_odd[0][0])+(half-count_even[1][0]),(half-count_odd[1][0])+(half-count_even[0][0])))

Submission status: Wrong Answer

Solution code:
import collections

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

V_odd = [V[i] for i in range(0, n, 2)]
V_even = [V[i] for i in range(1, n, 2)]

c_odd = collections.Counter(V_odd)
c_even = collections.Counter(V_even)

list_odd = []
list_even = []

for k, v in c_odd.items():
    list_odd.append([v, k])
list_odd = sorted(list_odd, reverse=True)

for k, v in c_even.items():
    list_even.append([v, k])
list_even = sorted(list_even, reverse=True)

if list_odd[0][1] == list_even[0][1]:
    if list_odd[0][0] >= list_even[0][0]:
        if len(list_even) == 1:
            print(n - list_odd[0][0])
        else:
            print(n - list_odd[0][0] - list_even[1][0])
    else:
        if len(list_odd) == 1:
            print(n - list_even[0][0])
        else:
            print(n - list_odd[1][0] - list_even[0][0])
else:
    print(n - list_odd[0][0] - list_even[0][0])

Submission status: Wrong Answer

Solution code:
n = int(input())
V = list(map(int,input().split()))
cnt = 0
cnt1 = 0
if len(set(V)) == 1:
  print(n//2)
  exit()
for i in range(n-2):
  if V[i] == V[i+2] and i%2==0:
    cnt += 1
  elif V[i] == V[i+2] and i%2==1:
    cnt1 += 1
  elif len(set(V)) == n//2:
    print(n//2)
    exit()
print(max(cnt,cnt1)-min(cnt,cnt1))

Submission status: Wrong Answer

Solution code:
n = int(input())
V = list(map(int,input().split()))
cnt = 0
cnt1 = 0
if len(set(V)) == 1:
  print(n//2)
  exit()
for i in range(n-2):
  if V[i] == V[i+2] and i%2==0:
    cnt += 1
  elif V[i] == V[i+2] and i%2==1:
    cnt1 += 1
  else:
    print(n//2)
    exit()
print(max(cnt,cnt1)-min(cnt,cnt1))

Submission status: Wrong Answer

Solution code:
n = int(input())
V = list(map(int,input().split()))
cnt = 0
cnt1 = 0
if len(set(V)) == 1:
  print(n//2)
  exit()
for i in range(n-2):
  if V[i] == V[i+2] and i%2==0:
    cnt += 1
  elif V[i] == V[i+2] and i%2==1:
    cnt1 += 1
print(max(cnt,cnt1)-min(cnt,cnt1))

Submission status: Wrong Answer

Solution code:
import collections

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

b = a[0::2]
c = a[1::2]

x = collections.Counter(b)
y = collections.Counter(c)
if b == c and len(x.most_common()) != 1:
    print(len(b))
    exit()
elif b == c:
    print(n-2)
    exit()
count = 1000000
for i in range(min(len(x.most_common()), 2)):
    for j in range(min(len(y.most_common()), 2)):
        if x.most_common()[i][0] != y.most_common()[j][0]:
            count_1 = len(b) - x.most_common()[i][1]
            count_2 = len(c) - y.most_common()[j][1]
            if count_1 + count_2 < count:
                count = count_1 + count_2


print(count)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

n = int(input())

v = map(lambda x: int(x), input().split())

counter = defaultdict(int)

for i in v:
    counter[i] += 1

arr = [counter[k] for k in counter]

arr.sort()
if len(arr) != 1:
    print(sum(arr) - arr[-1] - arr[-2])
else:
    print(2)

Submission status: Wrong Answer

Solution code:
import collections

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

b = a[0::2]
c = a[1::2]
if b == c:
    print(len(b))
    exit()
x = collections.Counter(b)
y = collections.Counter(c)
count = 1000000
for i in range(min(len(x.most_common()), 2)):
    for j in range(min(len(y.most_common()), 2)):
        if x.most_common()[i][0] != y.most_common()[j][0]:
            count_1 = len(b) - x.most_common()[i][1]
            count_2 = len(c) - y.most_common()[j][1]
            if count_1 + count_2 < count:
                count = count_1 + count_2


print(count)

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
v = list(map(int,input().split()))
ev = [v[i] for i in range(n) if i % 2 == 0]
ov = [v[i] for i in range(n) if i % 2 == 1]
#print(ov,ev)
E = collections.Counter(ev).most_common()
#print(E)
if len(E) == 1:
    e = E[0][0]
    e1 = E[0][0]
    e2 = E[0][0]
else:
    e = float('inf')
    e1 = E[0][0]
    e2 = E[1][0]
O = collections.Counter(ov).most_common()
#print(O)
if len(O) == 1:
    o = O[0][0]
    if e == o:
        print(n//2)
        exit()
    else:
        if e != float('inf'):
            print(0)
            exit()
        else:
            o1 = O[0][0]
            o2 = O[0][0]
else:
    o1 = O[0][0]
    o2 = O[1][0]

tmp = 0
for i in range(n):
    if i % 2 == 0 and v[i] != e1:
        tmp += 1
    elif i % 2 == 1 and v[i] != o2:
        tmp += 1
ttmp = 0
for i in range(n):
    if i % 2 == 0 and v[i] != e2:
        ttmp += 1
    elif i % 2 == 1 and v[i] != o1:
        ttmp += 1
        
print(min(tmp,ttmp))

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
v = list(map(int,input().split()))
c = collections.Counter(v).most_common()
#print(c,len(c))
if len(c) == 1:
    print(n//2)
    exit()
mc = c[0][0]
sc = c[1][0]
tmp = 0
for i in range(n):
    if i % 2 == 0 and v[i] != mc:
        tmp += 1
    elif i % 2 == 1 and v[i] != sc:
        tmp += 1
ttmp = 0
for i in range(n):
    if i % 2 == 0 and v[i] != sc:
        ttmp += 1
    elif i % 2 == 1 and v[i] != mc:
        ttmp += 1
print(min(tmp,ttmp))

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
v = [int(num) for num in input().split()]

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

counter_v1 = Counter(v1)
counter_v2 = Counter(v2)

most_common_v1 = counter_v1.most_common()
most_common_v2 = counter_v2.most_common()
count = 0
if len(counter_v1) == 1 and len(counter_v2) == 1:
  if most_common_v1[0][0] == most_common_v2[0][0]:
    count = n // 2
    
if len(counter_v1) > 1:
  keys, counts = zip(*most_common_v1)
  counts = [int(num) for num in counts]
  s = sum(counts)
  count += s - counts[0]
  
if len(counter_v2) > 1:
  keys, counts = zip(*most_common_v1)
  counts = [int(num) for num in counts]
  s = sum(counts)
  if most_common_v1[0][0] == most_common_v2[0][0]:
    count += s - counts[1]
  else:
    count += s - counts[0]
print(count)