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 sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))
from collections import Counter

n=int(input())
v=lnii()

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

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

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

v1_max=0
v1_num=-1
for i in c1:
  if i>v1_max:
    v1_max=max(v1_max,c1[i])
    v1_num=i

v2_max=0
for i in c2:
  if i==v1_num:
    continue
  v2_max=max(v2_max,c2[i])

ans1=n-v1_max-v2_max

v2_max=0
v2_num=-1
for i in c2:
  if i>v2_max:
    v2_max=max(v2_max,c2[i])
    v2_num=i

v1_max=0
for i in c1:
  if i==v2_num:
    continue
  v1_max=max(v1_max,c1[i])

ans2=n-v1_max-v2_max

print(min(ans1,ans2))

Submission status: Wrong Answer

Solution code:
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))
from collections import Counter

n=int(input())
v=lnii()

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

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

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

v1_max=0
v1_num=-1
for i in c1:
  if i>v1_max:
    v1_max=max(v1_max,c1[i])
    v1_num=i

v2_max=0
for i in c2:
  if i==v1_num:
    continue
  v2_max=max(v2_max,c2[i])

print(n-v1_max-v2_max)

Submission status: Wrong Answer

Solution code:
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))
from collections import Counter

n=int(input())
v=lnii()

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

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

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

v1_max=0
v2_max=0
for i in c1:
  v1_max=max(v1_max,c1[i])
for i in c2:
  v2_max=max(v2_max,c2[i])

print(n-v1_max-v2_max)

Submission status: Wrong Answer

Solution code:
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))
from collections import Counter

n=int(input())
v=lnii()

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

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

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

v1_max=0
v2_max=0
for i,j in zip(c1,c2):
  v1_max=max(v1_max,c1[i])
  v2_max=max(v2_max,c2[j])

print(n-v1_max-v2_max)

Submission status: Wrong Answer

Solution code:
import collections as co
if __name__ == '__main__':
	
	n = int(input())
	A = list(map(int,input().split()))

	S = A[1::2]
	T = A[0::2]
	set_S = set(A[1::2])
	set_T = set(A[0::2])

	total_cnt = 0
	#奇数をチェック
	if len(set_S) == 1:
		#何もしない
		pass
	else:
		s = co.Counter(S)
#		print(len(S))
#		print(s)
		c1 = s.most_common()
#		print("C1="+str(c1[0][1]))
#		print("len(S)="+str(len(S)))
		#最大値
		total_cnt = len(S) - c1[0][1]
		
#	print("total_cnt="+str(total_cnt))

	#偶数をチェック
	if len(T) == 1:
		#何もしない
		pass
	else:
		t = co.Counter(T)
		c2 = t.most_common()
#		print(t)
		#最大値
		total_cnt += len(T) - c2[0][1]

#	print("total_cnt="+str(total_cnt))

	#全体をチェック
	U = set(A)
	if len(U) == 1:
		total_cnt += len(A[1::2])


	print(total_cnt)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# hello worldと表示する
#float型を許すな
#numpyはpythonで
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,factorial
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

n=I()//2
lis=LI()
lis1=[]
lis2=[]
for i in range(n):
    lis1.append(lis[2*i])
    lis2.append(lis[2*i+1])
x=Counter(lis1).most_common(2)
y=Counter(lis2).most_common(2)
#print(x)
#print(y)
if len(x)==1:
    x.append((0,0))
if len(y)==1:
    y.append((-1,0))
#print(x)
#print(y)
if x[0][0]!=y[0][0]:
    print(2*n-x[0][1]-y[0][1])
else:
    print(min(2*n-x[1][1]-y[0][1],2*n-x[0][1]-y[1][0]))

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
ODD = defaultdict(int)
EVEN = defaultdict(int)
ALL = set([])
N = int(input())

A = list(map(int,input().split()))
for i in range(N):
  ALL.add(A[i])
  if i%2 == 0:
    EVEN[A[i]] += 1
  else:
    ODD[A[i]] += 1
if len(ALL) == 1:
  ans = N//2
  print(ans)
  exit()
modd = max(ODD.values())
meven = max(EVEN.values())
mlodd = [];mleven = []
dicodd = sorted(ODD.items(), key=lambda x:x[1], reverse = True)
diceven = sorted(EVEN.items(), key=lambda x:x[1], reverse = True)
ans = N
for x, vx in dicodd:
  for y, vy in diceven:
    if x != y:
      temp = N-(vx+vy)
      if ans >= temp:
        ans = min(ans,temp)
      else:
        print(ans)
        exit()
print(ans)
exit()
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
ODD = defaultdict(int)
EVEN = defaultdict(int)
ALL = set([])
N = int(input())

A = list(map(int,input().split()))
for i in range(N):
  ALL.add(A[i])
  if i%2 == 0:
    EVEN[A[i]] += 1
  else:
    ODD[A[i]] += 1
if len(ALL) == 1:
  ans = N//2
  print(ans)
  exit()
modd = max(ODD.values())
meven = max(EVEN.values())
mlodd = [];mleven = []
dicodd = sorted(ODD.items(), key=lambda x:x[1], reverse = True)
diceven = sorted(EVEN.items(), key=lambda x:x[1], reverse = True)
ans = N
for x, vx in dicodd:
  for y, vy in diceven:
    if x != y:
      temp = N-(vx+vy)
      if ans > temp:
        ans = min(ans,temp)
      else:
        print(ans)
        exit()
print(ans)
exit()
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
v = list(map(int, input().split()))
l,r = [], []
for i in range(n):
    if i%2==0: l.append(v[i])
    else: r.append(v[i])
l,r = Counter(l), Counter(r)
ans = n
for a,b in l.items():
    for c,d in r.items():
        if a < c:
            ans = min(n-b-d, ans)
        elif a > c:
            if a==1: continue
            ans = min(n//2 + n//2-d, n//2-a + n//2, ans)
        else:
            ans = min(ans, n//2)
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
ODD = defaultdict(int)
EVEN = defaultdict(int)
ALL = set([])
N = int(input())
neven = N//2+1
nodd = N//2
A = list(map(int,input().split()))
for i in range(N):
  ALL.add(A[i])
  if i%2 == 0:
    EVEN[A[i]] += 1
  else:
    ODD[A[i]] += 1
if len(ALL) == 1:
  ans = N//2
else:
  ans = N - (max(EVEN.values())+max(ODD.values()))
print(ans)

Submission status: Wrong Answer

Solution code:
import collections as co
if __name__ == '__main__':
	
	n = int(input())
	A = list(map(int,input().split()))

	S = set(A[1::2])
	T = set(A[0::2])

	total_cnt = 0
	#奇数をチェック
	if len(S) == 1:
		#何もしない
		pass
	else:
		s = co.Counter(S)
		c1 = s.most_common()
		#最大値
		total_cnt = len(S) - c1[0][1]

	#偶数をチェック
	if len(T) == 1:
		#何もしない
		pass
	else:
		t = co.Counter(T)
		c2 = t.most_common()
		#最大値
		total_cnt = len(T) - c2[0][1]

	#全体をチェック
	U = set(A)
	if len(U) == 1:
		total_cnt = len(A[1::2])

	print(total_cnt)

Submission status: Wrong Answer

Solution code:
n = int(input())
V = list(map(int,input().split()))
C = {}
for i in range(n):
    v = V[i]
    if v not in C:
        C[v]=0
    C[v] += 1
C = sorted(list(C.items()),key=lambda x:x[1],reverse=True)
cnt = 0
for i in range(2,len(C)):
    cnt += C[i][1]
if C[0][1]>n//2:
    cnt += C[0][1]-n//2
print(cnt)

Submission status: Wrong Answer

Solution code:
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush
from bisect import bisect_left,bisect_right 
import sys,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n = inp()
a = inpl()
b = defaultdict(int)
c = defaultdict(int)
for i,x in enumerate(a):
    if i%2: b[x]+=1
    else: c[x]+=1
print(n - max(b.values()) - max(c.values()))

Submission status: Wrong Answer

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

zero_d = {}
one_d = {}
for i,v in enumerate(vl):
    if i%2 == 0:
        zero_d.setdefault(v,0)
        zero_d[v] += 1
    else:
        one_d.setdefault(v,0)
        one_d[v] += 1

zero_l = sorted(zero_d.items(), reverse=True)
one_l = sorted(one_d.items(), reverse=True)

zero_l.append((-1,0))
one_l.append((-1,0))

zero_cnt = (n+1)//2
one_cnt = n//2
if zero_l[0][0] != one_l[0][0]:
    ans = n - zero_l[0][1] - one_l[0][1]
else:
    ans1 = n - zero_l[0][1] - one_l[1][1]
    ans2 = n - zero_l[1][1] - one_l[0][1]
    ans = min(ans1,ans2)

print(ans)

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
v = list(map(int,input().split()))
x = collections.Counter(v)
if x[max(x)] == len(v):
    print(len(v)//2)
    exit()
n_even = v[0::2]
n_odd = v[1::2]
a = collections.Counter(n_even)
b = collections.Counter(n_odd)
ans = len(n_even) - a[max(a)]
ans += (len(n_odd) - b[max(b)])
print(ans)

Submission status: Wrong Answer

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

A = collections.Counter(v)
B = list(A.values())
B.sort(reverse=True)

if len(A) == 1:
    ans = N//2
elif B[0] > N//2:
    ans = max(B[0] - N//2, N//2 - B[1])
else:
    ans = N//2 - B[0] + N//2 - B[1]
print(ans)

Submission status: Wrong Answer

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

A = collections.Counter(v)
B = list(A.values())
B.sort(reverse=True)

if len(A) == 1:
    ans = N//2
elif B[0] > N//2:
    ans = max(B[0] - N//2, N//2 - B[1])
else:
    ans = N//2 - B[1]
print(ans)

Submission status: Wrong Answer

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

A = collections.Counter(v)
B = list(A.values())
B.sort(reverse=True)

if len(set(B)) == 1:
    ans = N//2
elif B[0] > N//2:
    ans = max(B[0] - N//2, N//2 - B[1])
else:
    ans = N//2 - B[1]
print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    v = list(map(int,input().split()))
    e,o = {},{}
    for i in range(n):
        if (i+1)%2==1:
            if v[i] not in o.keys():
                o[v[i]]=1
            else:
                o[v[i]]+=1
        else:
            if v[i] not in e.keys():
                e[v[i]]=1
            else:
                e[v[i]]+=1
    e1,o1 = max(e,key=e.get),max(o,key=o.get)
    if e1!=o1:
        print(n-e[e1]-o[o1])
    else:
        me,mo = e[e1],o[o1]
        e[e1] = 0
        o[o1] = 0
        m = n-me-max(o.values())
        if m<n-mo-max(e.values()):
            m = n-mo-max(e.values())
        print(m)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    v = list(map(int,input().split()))
    e,o = {},{}
    for i in range(n):
        if (i+1)%2==1:
            if v[i] not in o.keys():
                o[v[i]]=1
            else:
                o[v[i]]+=1
        else:
            if v[i] not in e.keys():
                e[v[i]]=1
            else:
                e[v[i]]+=1
    if max(o, key=o.get)!=max(e, key=e.get):
        print(n-max(o.values())-max(e.values()))
    else:
        ok,ek = max(o, key=o.get),max(e, key=e.get)
        Mo,Me = o[ok],e[ek]
        o[ok]=0
        m = n-max(o.values())-Me
        e[ek]=0
        if m<n-Mo-max(e.values()):
            m = n-Mo-max(e.values())
        print(m)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    v = list(map(int,input().split()))
    e,o = {},{}
    for i in range(n):
        if (i+1)%2==1:
            if v[i] not in o.keys():
                o[v[i]]=1
            else:
                o[v[i]]+=1
        else:
            if v[i] not in e.keys():
                e[v[i]]=1
            else:
                e[v[i]]+=1
    if max(o, key=o.get)!=max(e, key=e.get):
        print(n//2-max(o.values())+n//2-max(e.values()))
    else:
        M = o[max(o,key=o.get)]
        o[max(o,key=o.get)]=0
        m = n-max(o.values())-max(e.values())
        e[max(e,key=e.get)]=0
        if m<n-M-max(e.values()):
            m = n-M-max(e.values())
        print(m)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    v = list(map(int,input().split()))
    e,o = {},{}
    for i in range(n):
        if (i+1)%2==1:
            if v[i] not in o.keys():
                o[v[i]]=1
            else:
                o[v[i]]+=1
        else:
            if v[i] not in e.keys():
                e[v[i]]=1
            else:
                e[v[i]]+=1
    if max(o, key=o.get)!=max(e, key=e.get):
        print(n//2-max(o.values())+n//2-max(e.values()))
    else:
        M = o[max(o,key=o.get)]
        o[max(o,key=o.get)]=0
        m = n-o[max(o)]-max(e.values())
        e[max(e,key=e.get)]=0
        if m<n-M-max(e.values()):
            m = n-M-max(e.values)
        print(m)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    v = list(map(int,input().split()))
    e,o = {},{}
    for i in range(n):
        if (i+1)%2==1:
            if v[i] not in o.keys():
                o[v[i]]=1
            else:
                o[v[i]]+=1
        else:
            if v[i] not in e.keys():
                e[v[i]]=1
            else:
                e[v[i]]+=1
    if max(o, key=o.get)!=max(e, key=e.get):
        print(n//2-max(o.values())+n//2-max(e.values()))
    else:
        M = o[max(o)]
        o[max(o)]=0
        m = n-o[max(o)]-max(e.values())
        e[max(e)]=0
        if m<n-M-max(e.values()):
            m = n-M-max(e.values)
        print(m)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

even_=[]
odd_=[]
for i in range(len(v)):
  if i%2==0:
    even_.append(v[i])

  else:
    odd_.append(v[i])

from collections import Counter
even=Counter(even_)
odd=Counter(odd_)


even1=[]
for i,j in even.items():
  even1.append([i,j])

odd1=[]
for i,j in odd.items():
  odd1.append([i,j])

even1.sort()
odd1.sort()


if even1[-1][0]!=odd1[-1][0]:
  print(n//2-even1[-1][1]+n//2-odd1[-1][1])

else:
  if len(even1)>=2 and len(odd1)>=2:
    
    s=n//2-even1[-1][1]+n//2-odd1[-2][1]
    t=n//2-even1[-2][1]+n//2-odd1[-1][1]
    print(min(s,t))

  elif len(even1)==1 and len(odd1)>1:
    t=n//2-even1[-2][1]+n//2-odd1[-1][1]
    print(t)

  elif len(odd1)==1 and len(even1)>1:
    s=n//2-even1[-1][1]+n//2-odd1[-2][1]
    print(s)

  else:
    print(even1[-1][1])

Submission status: Wrong Answer

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

even_=[]
odd_=[]
for i in range(len(v)):
  if i%2==0:
    even_.append(v[i])

  else:
    odd_.append(v[i])

from collections import Counter
even=Counter(even_)
odd=Counter(odd_)


even1=[]
for i,j in even.items():
  even1.append([i,j])

odd1=[]
for i,j in odd.items():
  odd1.append([i,j])

even1.sort()
odd1.sort()


if even1[-1][0]!=odd1[-1][0]:
  print(n//2-even1[-1][1]+n//2-odd1[-1][1])

else:
  if len(even1)>=2 and len(odd1)>=2:
    
    s=n//2-even1[-1][1]+n//2-odd1[-2][1]
    t=n//2-even1[-2][1]+n//2-odd1[-1][1]
    print(min(s,t))

  elif len(even1)==1 and len(odd1)>1:
    t=n//2-even1[-2][1]+n//2-odd1[-1][1]
    print(s)

  elif len(odd1)==1 and len(even1)>1:
    s=n//2-even1[-1][1]+n//2-odd1[-2][1]
    print(s)

  else:
    print(even1[-1][1])

Submission status: Wrong Answer

Solution code:
from collections import Counter
odd=[]
even=[]
n=int(input())
m=1
for i in list(map(int, input().split())):
    if m%2==0:
        even.append(i)
    else:
        odd.append(i)
    m+=1
odd=Counter(odd)
even=Counter(even)
ans=(n//2-odd.most_common()[0][1])+(n//2-even.most_common()[0][1])
print(n//2 if len(odd+even)==1 else ans)

Submission status: Wrong Answer

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

n, *v = map(int, open(0).read().split())
odd = [v[i] for i in range(0, n, 2)]
even = [v[i] for i in range(1, n, 2)]
o = Counter(odd)
e = Counter(even)

if o.most_common()[0][0] != e.most_common()[0][0]:
    print(n - o.most_common()[0][1] - e.most_common()[0][1])
else:
    if set(o) ^ set(e) == set():
        print(n - max(o.most_common()[0][1], e.most_common()[0][1]))
    else:
        a = n - o.most_common()[0][1] - max(sorted(e.values())[:-1] + [0])
        b = n - e.most_common()[0][1] - max(sorted(o.values())[:-1] + [0])
        print(min(a, b))

Submission status: Wrong Answer

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

n, *v = map(int, open(0).read().split())
odd = [v[i] for i in range(0, n, 2)]
even = [v[i] for i in range(1, n, 2)]
o = Counter(odd)
e = Counter(even)

if o.most_common()[0][0] != e.most_common()[0][0]:
    print(n - o.most_common()[0][1] - e.most_common()[0][1])
else:
    if set(o) ^ set(e) == set():
        print(n - max(o.most_common()[0][1], e.most_common()[0][1]))
    else:
        a = n - o.most_common()[0][1] - max(sorted(e.values())[1:] + [0])
        b = n - e.most_common()[0][1] - max(sorted(o.values())[1:] + [0])
        print(min(a, b))

Submission status: Wrong Answer

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

n, *v = map(int, open(0).read().split())
odd = [v[i] for i in range(0, n, 2)]
even = [v[i] for i in range(1, n, 2)]
o = Counter(odd)
e = Counter(even)

if o.most_common()[0][0] != e.most_common()[0][0]:
    print(n - o.most_common()[0][1] - e.most_common()[0][1])
else:
    if set(o) ^ set(e) == set():
        print(n - max(o.most_common()[0][1], e.most_common()[0][1]))
    else:
        a = n - o.most_common()[0][1] - max(list(e.values())[1:] + [0])
        b = n - e.most_common()[0][1] - max(list(o.values())[1:] + [0])
        print(min(a, b))

Submission status: Wrong Answer

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

n, *v = map(int, open(0).read().split())
odd = [v[i] for i in range(0, n, 2)]
even = [v[i] for i in range(1, n, 2)]
o = Counter(odd)
e = Counter(even)

if o.most_common()[0][0] != e.most_common()[0][0]:
    print(n - o.most_common()[0][1] - e.most_common()[0][1])
else:
    if set(o) ^ set(e) == set():
        print(n - max(o.most_common()[0][1], e.most_common()[0][1]))
    else:
        print(n - max(list(o.values())[1:] + [0]) -
              max(list(e.values())[1:] + [0]))

Submission status: Wrong Answer

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

from collections import*
C1=Counter(V[::2])
C1=sorted(C1.items(),key=lambda x:x[1])
C2=Counter(V[1::2])
C2=sorted(C2.items(),key=lambda x:x[1])

K1=C1[-1][0]
V1=C1[-1][1]
K2=C2[-1][0]
V2=C2[-1][1]
if V1>V2:
    if K1==K2:
        if len(C2)>1:
            V2=C2[-2][1]
        else:
            V2=0
elif V2>V1:
    if K1==K2:
        if len(C1)>1:
            V1=C1[-2][1]
        else:
            V1=0
elif K1==K2:
    if len(set(C1))==1:
        V2=C2[-2*(len(set(C2))>1)][1]*(len(set(C2))>1)
    else:
        V1=C1[-2*(len(set(C1))>1)][1]*(len(set(C1))>1)

print(N-V1-V2)

Submission status: Wrong Answer

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

from collections import*
C1=Counter(V[::2])
C1=sorted(C1.items(),key=lambda x:x[1])
C2=Counter(V[1::2])
C2=sorted(C2.items(),key=lambda x:x[1])

K1=C1[-1][0]
V1=C1[-1][1]
K2=C2[-1][0]
V2=C2[-1][1]
if V1>=V2:
    if K1==K2:
        if len(C2)>1:
            V2=C2[-2][1]
        else:
            V2=0
else:
    if K1==K2:
        if len(C1)>1:
            V1=C1[-2][1]
        else:
            V1=0

print(N-V1-V2)

Submission status: Wrong Answer

Solution code:
import copy

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

la = [0 for i in range(5+10**5)]
lb = [0 for i in range(5+10**5)]

for i in range(0, n, 2):
    la[v[i]] += 1
for i in range(1, n, 2):
    lb[v[i]] += 1

# print(sum(la))
# print(sum(lb))
# print(max(la))
# print(max(lb))
# print(la.index(max(la)))
# print(lb.index(max(lb)))

sla = sum(la)
slb = sum(lb)
maxla = max(la)
maxlb = max(lb)
argmaxla = la.index(max(la))
argmaxlb = lb.index(max(lb))

if argmaxla != argmaxlb:
    if maxla != maxlb:
        print(0)
    else:
        print(sla-maxla+slb-maxlb)
else:
    # laの2番目に大きい値を使う
    _la = copy.deepcopy(la)
    _la[argmaxla] = 0
    _maxla = max(_la)
    aa = sla-_maxla+slb-maxlb
    # lbの2番目に大きい値を使う
    _lb = copy.deepcopy(lb)
    _lb[argmaxlb] = 0
    _maxlb = max(_lb)
    bb = sla-maxla+slb-_maxlb
    if bb>aa:
        print(aa)
    else:
        print(bb)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

e=Counter(v[0::2])
o=Counter(v[1::2])
e_key=sorted(e.items(),reverse=True,key=lambda x:x[1])
o_key=sorted(o.items(),reverse=True,key=lambda x:x[1])

if e_key[0][0]!=o_key[0][0]: print(n-e_key[0][1]-o_key[0][1])
else:
    if len(e_key)==1 and len(o_key)==1: print(n//2)
    elif len(e_key)==1: print(n//2-o_key[1][1])
    elif len(o_key)==1: print(n//2-e_key[1][1])
    else:
        if e_key[0][1]>o_key[0][1]: print(n-e_key[0][1]-o_key[1][1])
        elif e_key[0][1]<o_key[0][1]: print(n-o_key[0][1]-e_key[1][1])
        else:
            pass

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

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

count1,count2=map(Counter,(count1,count2))
mc1,mc2 = map(lambda c: c.most_common(),(count1,count2))

if mc1[0][0] != mc2[0][0]:
  print(n-mc1[0][1]-mc2[0][1])
else:
  if len(mc2)>1 and len(mc1)>1:
    if mc1[0][1] >= mc2[0][1]:
      print(n-mc1[0][1]-mc2[1][1])
    else:
      print(n-mc1[1][1]-mc2[0][1])
  elif len(mc2)>1:
    print(n-mc1[0][1]-mc2[1][1])
  elif len(mc1)>1:
    print(n-mc1[1][1]-mc2[0][1])
  else:
    print(n-mc1[0][1])

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

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

count1,count2=map(Counter,(count1,count2))
mc1,mc2 = map(lambda c: c.most_common(),(count1,count2))

while 1:
  if mc1[0][0] != mc2[0][0]:
    print(n-mc1[0][1]-mc2[0][1])
    exit()
  else:
    if len(mc2)>1 and len(mc1)>1:
      if mc1[0][1] >= mc2[0][1]:
        print(n-mc1[0][1]-mc2[1][1])
        exit()
      else:
        print(n-mc1[1][1]-mc2[0][1])
        exit()
    elif len(mc2)>1:
      print(n-mc1[0][1]-mc2[1][1])
      exit()
    elif len(mc1)>1:
      print(n-mc1[1][1]-mc2[0][1])
      exit()
    else:
      print(n-mc1[0][1])
      exit()

Submission status: Wrong Answer

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

import collections

if len(set(V)) == 1:
  print(N//2)
else:
  evens = [V[n] for n in range(0,N,2)]
  odds = [V[n] for n in range(1,N,2)]
  
  c_evens = collections.Counter(evens).most_common()
  c_odds = collections.Counter(odds).most_common()
  
  standard_in_evens = c_evens[0][1]
  standard_in_odds = c_odds[0][1]
  
  if c_evens[0][0] == c_odds[0][0]:
    if len(c_evens) == 1:
      if len(c_odds) != 1:
        standard_in_odds = c_odds[1][1]
      else:
        pass
    elif len(c_odds) == 1:
      standard_in_evens = c_evens[1][1]
    else:
      if len(evens)-c_evens[0][1]-c_evens[1][1] > len(odds)-c_odds[0][1]-c_odds[1][1]:
        standard_in_odds = len(odds)-c_odds[1][1]
      else:
        standard_in_evens = len(evens)-c_evens[1][1]
        
  change_evens = len(evens) - standard_in_evens
  change_odds = len(odds) - standard_in_odds
  
  print(change_evens+change_odds)

Submission status: Wrong Answer

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

import collections

if len(set(V)) == 1:
  print(N//2)
else:
  evens = [V[n] for n in range(0,N,2)]
  odds = [V[n] for n in range(1,N,2)]
  
  c_evens = collections.Counter(evens).most_common()
  c_odds = collections.Counter(odds).most_common()
  
  standard_in_evens = c_evens[0][1]
  standard_in_odds = c_odds[0][1]
  
  if standard_in_evens == standard_in_odds:
    if len(c_evens) == 1:
      if len(c_odds) != 1:
        standard_in_odds = c_odds[1][1]
      else:
        pass
    elif len(c_odds) == 1:
      standard_in_evens = c_evens[1][1]
    else:
      if len(evens)-c_evens[0][1]-c_evens[1][1] > len(odds)-c_odds[0][1]-c_odds[1][1]:
        standard_in_odds = len(odds)-c_odds[1][1]
      else:
        standard_in_evens = len(evens)-c_evens[1][1]
        
  change_evens = len(evens) - standard_in_evens
  change_odds = len(odds) - standard_in_odds
  
  print(change_evens+change_odds)

Submission status: Wrong Answer

Solution code:
import collections
import sys
n = int(input())
a = list(map(int,input().split()))
if len(set(a)) == 1:
  print(n//2)
  sys.exit()
a1 = [a[x] for x in range(0,n,2)]
l_a1 = len(a1)
a2 = [a[y] for y in range(1,n,2)]
l_a2 = len(a2)
c1 = collections.Counter(a1)
c2 = collections.Counter(a2)
K_a1 = c1.most_common()[0][0]
#print(K_a1)
K_a2 = c2.most_common()[0][0]
#print(K_a2)
F_a1 = c1.most_common()[0][1]
F_a2 = c2.most_common()[0][1]
if K_a1 == K_a2:
  if  F_a1 >= F_a2:
    F_a2 = c2.most_common()[1][1]
  else:
    F_a1 = c1.most_common()[1][1]
   # print(F_a1)
print((l_a1 - F_a1)+(l_a2 - F_a2))

Submission status: Wrong Answer

Solution code:
import collections
import sys
n = int(input())
a = list(map(int,input().split()))
if len(set(a)) == 1:
  print(n//2)
  sys.exit()
a1 = [a[x] for x in range(0,n,2)]
l_a1 = len(a1)
a2 = [a[y] for y in range(1,n,2)]
l_a2 = len(a2)
c1 = collections.Counter(a1)
c2 = collections.Counter(a2)
K_a1 = c1.most_common()[0][0]
#print(K_a1)
K_a2 = c2.most_common()[0][0]
#print(K_a2)
F_a1 = c1.most_common()[0][1]
F_a2 = c2.most_common()[0][1]
if K_a1 == K_a2:
  if  c1.most_common()[1][1] >= c2.most_common()[1][1]:
    F_a2 = c2.most_common()[1][1]
  else:
    F_a1 = c1.most_common()[1][1]
   # print(F_a1)
print((l_a1 - F_a1)+(l_a2 - F_a2))

Submission status: Wrong Answer

Solution code:
import collections
import sys
n = int(input())
a = list(map(int,input().split()))
if len(set(a)) == 1:
  print(n//2)
  sys.exit()
a1 = [a[x] for x in range(0,n,2)]
l_a1 = len(a1)
a2 = [a[y] for y in range(1,n,2)]
l_a2 = len(a2)
c1 = collections.Counter(a1)
c2 = collections.Counter(a2)
K_a1 = c1.most_common()[0][0]
#print(K_a1)
K_a2 = c2.most_common()[0][0]
#print(K_a2)
F_a1 = c1.most_common(1)[0][1]
F_a2 = c2.most_common(1)[0][1]
if K_a1 == K_a2:
  if  c1.most_common(2)[0][1] >= c2.most_common(2)[0][1]:
    F_a2 = c2.most_common()[1][1]
  else:
    F_a1 = c1.most_common()[1][1]
   # print(F_a1)
print((l_a1 - F_a1)+(l_a2 - F_a2))

Submission status: Wrong Answer

Solution code:
import collections
import sys
n = int(input())
a = list(map(int,input().split()))
if len(set(a)) == 1:
  print(n//2)
  sys.exit()
a1 = [a[x] for x in range(0,n,2)]
l_a1 = len(a1)
a2 = [a[y] for y in range(1,n,2)]
l_a2 = len(a2)
c1 = collections.Counter(a1)
c2 = collections.Counter(a2)
F_a1 = c1.most_common(1)[0][1]
F_a2 = c2.most_common(1)[0][1]
print((l_a1 - F_a1)+(l_a2 - F_a2))

Submission status: Wrong Answer

Solution code:
# https://atcoder.jp/contests/abc111/tasks/arc103_a
import sys
from collections import Counter
n = int(input())
nums = [int(i) for i in input().split()]

for i in range(n - 1):
    if nums[i + 1] != nums[i]:
        break
else:
    print(n // 2)
    sys.exit()


odd = Counter(nums[1::2]).most_common()
even = Counter(nums[::2]).most_common()
i = j = 0
while True:
    if odd[i][0] != even[j][0]:
        odd_ans = odd[i][1]
        even_ans = even[j][1]
        break
    else:
        if odd[i][0] > even[j][0]:
            if j + 1 < len(even):
                j += 1
            else:
                i += 1
        else:
            if i + 1 < len(odd):
                i += 1
            else:
                j += 1

ans = n - (odd_ans + even_ans)
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N = int(input())
Vs = list(mapint())

even = []
odd = []
for i in range(N):
    if i%2==1:
        even.append(Vs[i])
    else:
        odd.append(Vs[i])

from collections import Counter
ceven = Counter(even)
ans = 0
even_second = 0
for i, (num, cnt) in enumerate(ceven.most_common()):
    if i==0:
        even_most = num
        continue
    if i==1:
        even_second = num
    ans += cnt
codd = Counter(odd)
odd_second = 0
for i, (num, cnt) in enumerate(codd.most_common()):
    if i==0:
        odd_most = num
        continue
    if i==1:
        odd_second = num
    ans += cnt

if even_most==odd_most:
    ans += min(even_second, odd_second)
print(ans)

Submission status: Wrong Answer

Solution code:
def resolve():
    '''
    code here
    '''
    n = int(input())
    vs = [int(item) for item in input().split()]
    num_max = max(vs)

    memo_ev = [0 for _ in range(num_max+1)]
    memo_od = [0 for _ in range(num_max+1)]

    for i in range(n-2):
        if i%2 == 0:
            if vs[i] == vs[i+2]:
                memo_ev[vs[i]] +=1
        else:
            if vs[i] == vs[i+2]:
                memo_od[vs[i]] +=1
    
    ev_max = max(memo_ev)
    od_max = max(memo_od)

    if memo_ev.index(ev_max) == memo_od.index(od_max):
        if len(set(vs)) == 1:
            print(n//2)
        elif ev_max > od_max:
            memo_od.remove(od_max)
            if max(memo_od) > 0:
                print((n//2-(ev_max+1)) + (n//2 - (max(memo_od)+1)))
            else:
                print((n//2-(ev_max+1)) + (n//2 - (max(memo_od))))
        
        elif ev_max < od_max:
            memo_ev.remove(ev_max)
            if max(memo_ev) > 0:
                print((n//2-(od_max+1)) + (n//2 - (max(memo_ev)+1)))
            else:
                print((n//2-(od_max+1)) + (n//2 - (max(memo_ev))))
        else:
            print(n-2)
    else:
        a = od_max+1
        b = ev_max+1
        print(n -a-b)

if __name__ == "__main__":
    resolve()