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

naked = input()
a = int(naked)
x = list(map(int,input().split()))
y = x[0:a:2]
z = x[1:a:2]
v = collections.Counter(y)
w = collections.Counter(z)
sv = 0
sw = 0

mvi = v.most_common()[0][0]
mwi = w.most_common()[0][0]
mvn = v.most_common()[0][1]
mwn = w.most_common()[0][1]
a2 =a//2

if a%2 ==0:
    sv = a2
    sw = a2
else:
    sv = a2+1
    sw = a2
if mvi == mwi:
    if mvi> mwi:
        mwn = w.most_common()[1][0]
    else:
        if  sw == mwn:
            mwn = 0
        else:
            mvn = v.most_common()[1][0]
    
print(sv+sw-mvn-mwn)

Submission status: Wrong Answer

Solution code:
a = int(input())
ar = list(map(int,input().split(" ")))
br = []
cr = []
count = 0
ma = 0
if len(set(ar)) == 1:
    print(a // 2)
else:
    for i,r in enumerate(ar):
        if i % 2 == 0:
            br.append(r)
        else:
            cr.append(r)
    if len(set(br)) >= 2:
        for r in set(br):
            if ma < br.count(r):
                ma = br.count(r)
    count += a // 2 - ma
    ma = 0
    if len(set(cr)) >= 2:
        for r in set(cr):
            if ma < cr.count(r):
                ma = cr.count(r)
    count += a // 2 - ma
    print(count)

Submission status: Wrong Answer

Solution code:
a = int(input())
ar = list(map(int,input().split(" ")))
br = []
cr = []
count = 0
ma = 0
if len(set(ar)) == 1:
    print(a // 2)
else:
    for i,r in enumerate(ar):
        if i % 2 == 0:
            if r not in br:
                br.append(r)
        else:
            if r not in cr:
                cr.append(r)
    for r in br:
        if ma < ar.count(r):
            ma = ar.count(r)
    count += a // 2 - ma
    ma = 0
    for r in cr:
        if ma < ar.count(r):
            ma = ar.count(r)
    count += a // 2 - ma
    print(count)

Submission status: Wrong Answer

Solution code:
import collections
n=int(input())
x=[i for i in input().split()]
c = collections.Counter(x)
#print(x)

#a=[]
#b=[]
#for i in range(n):
#  if i%2==0:
#    a+=[x[i]]
#  else:
#    b+=[x[i]]
a=x[::2]
b=x[1::2]
#print(a)
#print(b)
ca = collections.Counter(a)
cb = collections.Counter(b)

if c.most_common()[0][1] == n:
  ans=int(0.5*n)

else:
  ansa=len(a)-ca.most_common()[0][1]
  ansb=len(b)-cb.most_common()[0][1]
  ans=ansa+ansb
  
print(ans)

Submission status: Wrong Answer

Solution code:
import collections
n=int(input())
x=[i for i in input().split()]
c = collections.Counter(x)
#print(x)

a=[]
b=[]
for i in range(n):
  if i%2==0:
    a+=[x[i]]
  else:
    b+=[x[i]]
#a=x[::2]
#b=x[1::2]
#print(a)
#print(b)
ca = collections.Counter(a)
cb = collections.Counter(b)

if c.most_common()[0][1] == n:
  ans=int(0.5*n)

else:
  ansa=len(a)-ca.most_common()[0][1]
  ansb=len(b)-cb.most_common()[0][1]
  ans=ansa+ansb
  
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
x=[i for i in input().split()]
#print(x)

a=[]
b=[]
for i in range(n):
  if i%2==0:
    a+=[x[i]]
  else:
    b+=[x[i]]
#a=x[::2]
#b=x[1::2]
print(a)
print(b)

seta=list(set(a))
setb=list(set(b))

if len(list(set(x))) == 1:
  ans=int(0.5*n)

else:
  dicta={}
  dictb={}

  for i in range(len(seta)):
    dicta[seta[i]]=a.count(seta[i])

  for i in range(len(setb)):
    dictb[setb[i]]=b.count(setb[i])
  
#  print(dicta)
#  print(dictb)
  ansa=len(a)-max(dicta.values())
  ansb=len(b)-max(dictb.values())
  ans=ansa+ansb
  
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
A = list(map(int,input().split()))
E = [A[i] for i in range(n) if i%2 == 1]
O = [A[i] for i in range(n) if i%2 == 0]
e = Counter(E).most_common(2)
o = Counter(O).most_common(2)
if e[0][0] != o[0][0]: ##Eの最頻値とOの最頻値が違う
    ans = (len(E)-e[0][1])+(len(O)-o[0][1])
    print(ans)
    ##以下、EとOの最頻値が同じ時の処理を書く
elif len(e)>=2 and len(o)>=2:
    ans = min((len(E)-e[0][1])+(len(O)-o[1][1]), (len(E)-e[1][1])+(len(o)-o[0][1]))
    print(ans)
else:
    print(n//2)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
A = list(map(int,input().split()))
E = [A[i] for i in range(n) if i%2 == 1]
O = [A[i] for i in range(n) if i%2 == 0]
e = Counter(E).most_common(2)
o = Counter(O).most_common(2)
if e[0][0] != o[0][0]:
    ans = (len(E)-e[0][1])+(len(O)-o[0][1])
    print(ans)
elif len(e)>=2 and len(o)>=2:
    ans = min((len(E)-e[0][1])+(len(O)-o[1][1]), (len(E)-e[1][1])+(len(o)-o[0][1]))
    print(ans)
elif len(e)>=2:
    ans = min((len(E)-e[0][1])+len(O), (len(E)-e[1][1])+(len(o)-o[0][1]))
    print(ans)
elif len(o)>=2:
    ans = min((len(E)-e[0][1])+(len(O)-o[1][1]), len(E)+(len(o)-o[0][1]))
    print(ans)
else:
    print(n//2)

Submission status: Wrong Answer

Solution code:
n=int(input())

x=[i for i in input().split()]
a=x[::2]
b=x[1::2]
#print(a)
#print(b)
if len(set(x))==1:
  ans=max(len(a),len(b))
else:
  ans=len(set(a))-1+len(set(b))-1

print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())

x=[i for i in input().split()]
a=x[::2]
b=x[1::2]
#print(a)
#print(b)
if len(set(x))==1:
  ans=len(a)
else:
  ans=len(set(a))-1+len(set(b))-1

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
d0 = defaultdict(int)
d1 = defaultdict(int)
N=int(input())
v=list(map(int,input().split()))
for i in range(N):
    if i%2==0:
        d0[v[i]]+=1
    else:
        d1[v[i]]+=1
D0=sorted(d0.items(), key=lambda x:x[1],reverse=True)
D1=sorted(d1.items(), key=lambda x:x[1],reverse=True)
print(D0)
print(D1)
if (D0[0][1]+D1[0][1])==len(v) and D0[0][0]==D1[0][0]:
    print(len(v)//2)
else:
    i0=0
    i1=0
    while i0<=len(D0) or i1<=len(D1):
        if D0[i0][0]!=D1[i1][0]:
            print(len(v)-D0[i0][1]-D1[i1][1])
            break
        else:
            if D0[i0][1]>D1[i1][1]:
                i1+=1
            elif D0[i0][1]<D1[i1][1]:
                i0+=1
            else:
                if (len(D0)-1-i0)>0 and (len(D1)-1-i1)>0:
                    if D0[i0+1][1]>D1[i1+1][1]:
                        i0+=1
                    else:
                        i1+=1
                elif (len(D0)-1-i0)==0 :
                    i1+=1
                elif (len(D1)-1-i1)==0:
                    i0+=1

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
d0 = defaultdict(int)
d1 = defaultdict(int)
N=int(input())
v=list(map(int,input().split()))
for i in range(N):
    if i%2==0:
        d0[v[i]]+=1
    else:
        d1[v[i]]+=1
D0=sorted(d0.items(), key=lambda x:x[1],reverse=True)
D1=sorted(d1.items(), key=lambda x:x[1],reverse=True)
if (D0[0][1]+D1[0][1])==len(v) and D0[0][0]==D1[0][0]:
    print(len(v)//2)
else:
    i0=0
    i1=0
    while i0<=min(len(D0),len(D1)) and i1<=min(len(D0),len(D1)):
        if D0[i0][0]!=D1[i1][0]:
            print(len(v)-D0[i0][1]-D1[i1][1])
            break
        else:
            if D0[i0][1]>D1[i1][1]:
                i1+=1
            else:
                i0+=1

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
d0 = defaultdict(int)
d1 = defaultdict(int)
N=int(input())
v=list(map(int,input().split()))
for i in range(N):
    if i%2==0:
        d0[v[i]]+=1
    else:
        d1[v[i]]+=1
D0=sorted(d0.items(), key=lambda x:x[1],reverse=True)
D1=sorted(d1.items(), key=lambda x:x[1],reverse=True)
if (D0[0][1]+D1[0][1])==len(v) and D0[0][0]==D1[0][0]:
    print(len(v)//2)
else:
    print(len(v)-D0[0][1]-D1[0][1])

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
d0 = defaultdict(int)
d1 = defaultdict(int)
N=int(input())
v=list(map(int,input().split()))
V0=[]
V1=[]
for i in range(N):
    if i%2==0:
        V0.append(v[i])
        d0[v[i]]+=1
    else:
        V1.append(v[i])
        d1[v[i]]+=1
D0=sorted(d0.items(), key=lambda x:x[1],reverse=True)
D1=sorted(d1.items(), key=lambda x:x[1],reverse=True)
if D0[0][1]+D1[0][1]==len(v) and D0[0][0]==D1[0][0]:
    print(len(v)//2)
else:
    print(len(v)-D0[0][1]-D1[0][1])

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
d = defaultdict(int)
n=int(input())
v=list(map(int,input().split()))
for i in range(n):
    d[v[i]]+=1
D=sorted(d.items(), key=lambda x:x[1],reverse=True)
if len(D)==1:
    print(D[0][1]//2)
else:
    if v[0]==D[0][0]:
        a=D[0][0]
        b=D[1][0]
    elif v[0]==D[1][0]:
        b=D[0][0]
        a=D[1][0]
    else:
        a=D[0][0]
        b=D[1][0]
    c=0
    for i in range(n):
        if i%2==0:
            if v[i]!=a:
                c+=1
        if i%2!=0:
            if v[i]!=b:
                c+=1
    print(c)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
d = defaultdict(int)
n=int(input())
v=list(map(int,input().split()))
for i in range(n):
    d[v[i]]+=1
D=sorted(d.items(), key=lambda x:x[1],reverse=True)
if len(D)==1:
    print(D[0][1]//2)
else:
    if v[0]==D[1][0]:
        b=D[0][0]
        a=D[1][0]
    else:
        a=D[0][0]
        b=D[1][0]
    c=0
    print(a,b)
    for i in range(n):
        if i%2==0:
            if v[i]!=a:
                c+=1
        if i%2!=0:
            if v[i]!=b:
                c+=1
    print(c)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
d = defaultdict(int)
n=int(input())
v=list(map(int,input().split()))
for i in range(n):
    d[v[i]]+=1
D=sorted(d.items(), key=lambda x:x[1])
if len(D)==1:
    print(D[0][1]//2)
elif len(D)==2:
    print(0)
elif len(D)>=3:
    h=0
    for i in range(len(D)-2):
        h+=D[i][1]
    print(h)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
d = defaultdict(int)
n=int(input())
v=list(map(int,input().split()))
for i in range(n):
    d[v[i]]+=1
D=sorted(d.items(), key=lambda x:x[1])
if len(D)==1:
    print(D[0][1]//2)
elif len(D)==2:
    print(0)
else:
    h=0
    for i in range(len(D)-2):
        h+=D[i][1]
    print(h)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
d = defaultdict(int)
n=int(input())
v=list(map(int,input().split()))
for i in range(n):
    d[v[i]]+=1
D=sorted(d.items(), key=lambda x:x[1])
if len(D)==1:
    print(2)
elif len(D)==2:
    print(0)
else:
    h=0
    for i in range(len(D)-2):
        h+=D[i][1]
    print(h)

Submission status: Wrong Answer

Solution code:
n = int(input())

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

count1 = [0 for i in range(max(v)+1)]
count2 = [0 for i in range(max(v)+1)]
max1 = 0
max2 = 0
for i in range(n):
    if i%2!=0:
        count1[v[i]] += 1
        if max1 < count1[v[i]] :
            max1 = v[i]
    else:
        count2[v[i]] += 1
        if max2 < count2[v[i]] :
            max2 = v[i]
if max1!=max2:
    print(n-count1[max1]-count2[max2])
else:
    if count1[max1] < count2[max2]:
        count1[max1] = 0
        print(n-count2[max2]-max(count1))
    elif count1[max1] > count2[max2]:
        count2[max2] = 0
        print(n-count1[max1]-max(count2))
    elif count1[max1] == n//2 and count2[max2] == n//2:
        print(n//2)
    elif count1[max1] == count2[max2]:
        temp1 = count1[max1]
        temp2 = count2[max2]
        count1[max1] = 0
        count2[max2] = 0
        if max(count1) <= max(count2):
            print(n-temp1-max(count2))
        else:
            print(n-temp2-max(count1))

Submission status: Wrong Answer

Solution code:
from collections import Counter

n = int(input())
V = list(map(int, input().split()))
X = Counter([V[i] for i in range(0, n, 2)]).most_common()
Y = Counter([V[i] for i in range(1, n, 2)]).most_common()

ans = 0

if X[0][0] != Y[0][0]:
    ans = n - X[0][1] - Y[0][1]
else:
    if len(X) == 1 and len(Y) == 1:
        ans = n // 2
    elif len(X) == 1 and len(Y) != 1:
        ans = n // 2 - Y[1][1]
    elif len(X) != 1 and len(Y) == 1:
        ans = n // 2 - X[1][1]
    else:
        a = n // 2 - X[0][1] - Y[1][1]
        b = n // 2 - X[1][1] - Y[0][1]
        ans = min(a, b)
        
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

n = int(input())
V = list(map(int, input().split()))
X = Counter([V[i] for i in range(0, n, 2)]).most_common()
Y = Counter([V[i] for i in range(1, n, 2)]).most_common()

ans = 0

if X[0][0] != Y[0][0]:
    ans = n - X[0][1] - Y[0][1]
else:
    if len(X) == 1 and len(Y) == 1:
        ans = n // 2
    elif len(X) == 1 and len(Y) != 1:
        ans = n - Y[1][1]
    elif len(X) != 1 and len(Y) == 1:
        ans = n - X[1][1]
    else:
        a = n // 2 - X[0][1] - Y[1][1]
        b = n // 2 - X[1][1] - Y[0][1]
        ans = min(a, b)
        
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())

N=input().split()
output_cnt=n
cnt=0

for i in N:
    for j in N:
        if(i!=j):
            for v in range(n):
                if(v%2==1 and N[v]!=i):
                    cnt+=1
                elif(v%2==0 and N[v]!=j):
                    cnt+=1
        else:
            break
        output_cnt=min(cnt,output_cnt)

print(output_cnt)

Submission status: Wrong Answer

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

v_index_odds = []
v_index_evens = []
ans_count = 0
for i in range(0,n,2):
    v_index_evens.append(v[i])
    v_index_odds.append(v[i+1])
    
evens_counter = collections.Counter(v_index_evens).most_common()
odds_counter = collections.Counter(v_index_odds).most_common()
evens_majority = evens_counter[0][0]
odds_majority = odds_counter[0][0]
if evens_counter == odds_counter:
    print(len(v_index_odds))
    exit()
elif evens_majority == odds_majority:
    if evens_counter[0][1]<odds_counter[0][1]:
        evens_majority = evens_counter[1][0]
        tmp = evens_counter[0]
        evens_counter[0] = evens_counter[1]
        evens_counter[1] = tmp
    else :
        odds_majority = odds_counter[1][0]
        tmp = odds_counter[0]
        odds_counter[0] = odds_counter[1]
        odds_counter[1] = tmp
ans_count += len(v_index_evens) - evens_counter[0][1]
ans_count += len(v_index_odds) - odds_counter[0][1]
print(ans_count)

Submission status: Wrong Answer

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

v_index_odds = []
v_index_evens = []
ans_count = 0
for i in range(0,n,2):
    v_index_evens.append(v[i])
    v_index_odds.append(v[i+1])
    
evens_counter = collections.Counter(v_index_evens).most_common()
odds_counter = collections.Counter(v_index_odds).most_common()
evens_majority = evens_counter[0][0]
odds_majority = odds_counter[0][0]
if evens_counter == odds_counter:
    print(len(v_index_odds))
    exit()
elif evens_majority == odds_majority:
    if evens_counter[0][1]<odds_counter[0][1]:
        evens_majority = evens_counter[1][0]
        tmp = evens_counter[0]
        evens_counter[0] = evens_counter[1]
        evens_counter[1] = tmp
    else :
        odds_majority = odds_counter[1][0]
        tmp = odds_counter[0]
        odds_counter[0] = odds_counter[1]
        odds_counter[1] = tmp

for i in range(1,len(evens_counter)):
    ans_count += evens_counter[i][1]
for i in range(1,len(odds_counter)):
    ans_count += odds_counter[i][1]

print(ans_count)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
num = list(map(int, input().split()))
num1 = []
num2 = []
ans = 0

for i in range(0, n, 2):
    num1.append(num[i])
    
for i in range(1, n, 2):
    num2.append(num[i])

num1 = Counter(num1).most_common()
num2 = Counter(num2).most_common()    

if num1[0][0] != num2[0][0]:
    ans = n - num1[0][1] - num2[0][1]
else:
    if n - num1[0][1] - num2[0][1] == 0:
        ans = n // 2
    else:
        if n // 2 - num1[0][1] == 0:
            ans = n // 2 - num2[0][1]
        elif n // 2 - num2[0][1] == 0:
            ans = n // 2 - num1[0][1]
        else:
            ans = min(n // 2 - num1[0][1], n // 2 - num2[0][1])

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
v = list(map(int, input().split()))
num = None
count = []

v_unique = list(set(v))

a = len(v_unique)

if a == 1:
    num = n/2

elif a == 2:
    num = 0

else:
    for i in range(a):
        tmp = v.count(v_unique[i])
        count.append(tmp)
    
    count.sort(reverse=False)

    num = sum(count) - count[a-1] - count[a-2]

print(num)

Submission status: Wrong Answer

Solution code:
n = int(input())
v = list(map(int, input().split()))
num = None
count = []

v_unique = list(set(v))

a = len(v_unique)

if a == 1:
    num = n/2

elif a == 2:
    num = 0

else:
    for i in range(a):
        tmp = v.count(v_unique[i])
        count.append(tmp)
    
    count.sort(reverse=False)

    print(sum(count) - count[a-1] - count[a-2])

Submission status: Wrong Answer

Solution code:
import collections

N = int(input()) # N
V = list(map(int, input().split()))
Ve = V[0::2]
Vo = V[1::2]

Ve_ = collections.Counter(Ve)
Vo_ = collections.Counter(Vo)

Ve_1st = max(Ve_.items(), key=(lambda v:v[1]))
Vo_1st = max(Vo_.items(), key=(lambda v:v[1]))
Ve_.pop(Ve_1st[0])
Vo_.pop(Vo_1st[0])
if len(Ve_) == 0: Ve_ = {'-1':0}
if len(Vo_) == 0: Vo_ = {'-1':0}
Ve_2nd = max(Ve_.items(), key=(lambda v:v[1]))
Vo_2nd = max(Vo_.items(), key=(lambda v:v[1]))

if Ve_1st[0] != Vo_1st[0]:
    M = N - Ve_1st[1] - Vo_1st[1]
else:
    M = max(N - Ve_1st[1] - Vo_2nd[1], N - Ve_2nd[1] - Vo_1st[1])
print(M)

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*2])
	b.append(v[i*2+1])
A = collections.Counter(a)
B = collections.Counter(b)

if A.most_common()[0][0] != B.most_common()[0][0]:
	ans = n - A.most_common()[0][1] - B.most_common()[0][1]
elif len(A) > 1 and len(B) > 1:
	if A.most_common()[0][0] + B.most_common()[1][0] < A.most_common()[1][0] + B.most_common()[0][0]:
		ans = n - (A.most_common()[1][0] + B.most_common()[0][0])
	else:
		ans = n - (A.most_common()[0][0] + B.most_common()[1][0])
elif len(A)==1 and len(B)>1:
	ans = n - B.most_common()[1][0]
elif len(A)>1 and len(B)==1:
	ans = n - A.most_common()[1][0]
else:
	ans = n//2
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
v = [int(i) for i in input().split()]
odd = [v[i] for i in range(n) if i % 2 == 1]
even = [v[i] for i in range(n) if i % 2 == 0]
summ_odd = {i: odd.count(i) for i in set(odd)}
summ_even = {i: even.count(i) for i in set(even)}
odd_max_k = max(summ_odd.items(), key=lambda x: x[1])[0]
even_max_k = max(summ_even.items(), key=lambda x: x[1])[0]
if odd_max_k == even_max_k:
    if len(summ_odd) >= 1:
        if len(summ_even) >= 1:
            print(n//2)
            exit()
        else:
            tmp = summ_even.pop(even_max_k)
            even_max_k = max(summ_even.items(), key=lambda x: x[1])[0]
            summ_even.upddate(tmp)
    else:
        tmp = summ_odd.pop(odd_max_k)
        odd_max_k = max(summ_odd.items(), key=lambda x: x[1])[0]
        summ_odd.upddate(tmp)

summ_odd.pop(odd_max_k)
summ_even.pop(even_max_k)
res = sum(summ_odd.values()) + sum(summ_even.values())
print(res)

Submission status: Wrong Answer

Solution code:
import collections

n = int(input())
v = list(map(int, input().split()))
v1 = collections.Counter([x for i, x in enumerate(v) if i % 2 == 0]).most_common()
v2 = collections.Counter([x for i, x in enumerate(v) if i % 2 == 1]).most_common()
max_v1 = v1[0][1]
max_v2 = v2[0][1]

if v1[0][0] == v2[0][0]:
    if max_v1 >= max_v2 and len(v2) > 1:
        max_v2 = v2[1][1]
    elif max_v1 >= max_v2:
        max_v2 = 0
    elif max_v1 < max_v2 and len(v1) > 1:
        max_v1 = v1[1][1]
    elif max_v1 < max_v2:
        max_v2 = 0

ans = 0
for a in v1:
    ans += a[1]

for a in v2:
    ans += a[1]

print(ans - max_v1 - max_v2)

Submission status: Wrong Answer

Solution code:
from collections import Counter
 
n = int(input())
v_array = list(map(int,input().split()))
 
v_odd = v_array[0::2]
v_even = v_array[1::2]
 
v_odd_common = Counter(v_odd).most_common()
v_even_common = Counter(v_even).most_common()

v_odd_common.append((0,0))
v_even_common.append((0,0))

if v_odd_common[0] != v_even_common[0]:
    print(n-v_odd_common[0][1]-v_even_common[0][1])
else:
    print(min([n-v_odd_common[i][1]-v_even_common[i][1] for i in range(0,2)]))

Submission status: Wrong Answer

Solution code:
from collections import Counter
from sys import exit

n = input()
v_array = list(map(int,input().split()))
 
v_odd = v_array[0::2]
v_even = v_array[1::2]
 
v_odd_common = Counter(v_odd).most_common()
v_even_common = Counter(v_even).most_common()

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

if v_odd_common[0] == v_even_common[0]:
    if v_odd_common[1][1] > v_even_common[1][1]:
        v_odd_common_candidate = v_odd_common[0][1]
        v_even_common_candidate = v_even_common[1][1]
    elif v_odd_common[1][1] < v_even_common[1][1]:
        v_odd_common_candidate = v_odd_common[1][1]
        v_even_common_candidate = v_even_common[0][1]
    else:
        v_odd_common_candidate = v_odd_common[1][1]
        v_even_common_candidate = v_even_common[1][1]
else:
    v_odd_common_candidate = v_odd_common[0][1]
    v_even_common_candidate = v_even_common[0][1]
    
print(len(v_odd) - v_odd_common_candidate + len(v_even) - v_even_common_candidate)

Submission status: Wrong Answer

Solution code:
from collections import Counter
from sys import exit

n = input()
v_array = list(map(int,input().split()))
 
v_odd = v_array[0::2]
v_even = v_array[1::2]
 
v_odd_common = Counter(v_odd).most_common()
v_even_common = Counter(v_even).most_common()

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

if v_odd_common[0] == v_even_common[0]:
    if v_odd_common[1][1] > v_even_common[1][1]:
        v_odd_common_candidate = v_odd_common[0][1]
        v_even_common_candidate = v_even_common[1][1]
    elif v_odd_common[1][1] < v_even_common[1][1]:
        v_odd_common_candidate = v_odd_common[1][1]
        v_even_common_candidate = v_even_common[0][1]
    else:
        v_odd_common_candidate = v_odd_common[0][1]
        v_even_common_candidate = v_even_common[1][1]
else:
    v_odd_common_candidate = v_odd_common[0][1]
    v_even_common_candidate = v_even_common[0][1]
    
print(len(v_odd) - v_odd_common_candidate + len(v_even) - v_even_common_candidate)

Submission status: Wrong Answer

Solution code:
from collections import Counter
from sys import exit

n = input()
v_array = list(map(int,input().split()))
 
v_odd = v_array[0::2]
v_even = v_array[1::2]
 
v_odd_common = Counter(v_odd).most_common()
v_even_common = Counter(v_even).most_common()

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

for i in range(0,min(len(v_odd_common),len(v_even_common))):
    if v_odd_common[i] == v_even_common[i]:
        if v_odd_common[i+1][1] > v_even_common[i+1][1]:
            v_odd_common_candidate = v_odd_common[i][1]
            v_even_common_candidate = v_even_common[i+1][i]
            break
        elif v_odd_common[i+1][1] < v_even_common[i+1][1]:
            v_odd_common_candidate = v_odd_common[i+1][1]
            v_even_common_candidate = v_even_common[i][i]
            break
        else:
            v_odd_common_candidate = v_odd_common[i][1]
            v_even_common_candidate = v_even_common[i][1]
            break
    else:
        v_odd_common_candidate = v_odd_common[0][1]
        v_even_common_candidate = v_even_common[0][1]
    
print(len(v_odd) - v_odd_common_candidate + len(v_even) - v_even_common_candidate)

Submission status: Wrong Answer

Solution code:
import sys
from collections import Counter
n=int(input())
v=list(map(int,input().split()))
if len(set(v))==1:
    print(int(n//2))
    sys.exit()
v_even=[]
v_odd=[]
for i in range(n):
    if i%2==0:
        v_odd.append(v[i])
    else:
        v_even.append(v[i])
v_even_tmp=Counter(v_even)
v_odd_tmp=Counter(v_odd)
if v_even_tmp.most_common()[0][0]==v_odd_tmp.most_common()[0][0]:
    if v_even_tmp.most_common()[0][1]>v_odd_tmp.most_common()[0][0]:
        print((len(v_even)-v_even_tmp.most_common()[0][1])+(len(v_odd)-v_odd_tmp.most_common()[1][1]))
    elif v_even_tmp.most_common()[0][1]<=v_odd_tmp.most_common()[0][0]:
        print((len(v_even)-v_even_tmp.most_common()[1][1])+(len(v_odd)-v_odd_tmp.most_common()[0][1]))
else:
    print((len(v_even)-v_even_tmp.most_common()[0][1])+(len(v_odd)-v_odd_tmp.most_common()[0][1]))

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

v_odd = v_array[0::2]
v_even = v_array[1::2]

v_odd_common = Counter(v_odd).most_common()
v_even_common = Counter(v_even).most_common()

print(len(v_odd) - v_odd_common[0][1] + len(v_even) - v_even_common[0][1])

Submission status: Wrong Answer

Solution code:
#!/mnt/c/Users/moiki/bash/env/bin/python
n = int(input())
v = list(map(int, input().split()))
vodd = []
dodd = {}
veve = []
deve = {}

kind = 0
inst_kinds = {}
for e,i in enumerate(v):
    if e % 2 == 0:
        # veve.append(i)
        if not i in deve:
            deve[i] = 1
        else:
            deve[i] += 1
    else:
        # vodd.append(i)
        if not i in dodd:
            dodd[i] = 1
        else:
            dodd[i] += 1

for k in deve:
    veve.append((deve[k], k))
veve.sort()
veve.reverse()
for k in dodd:
    vodd.append((dodd[k], k))
vodd.sort()
vodd.reverse()
from functools import reduce
from operator import add

# sum = reduce(add, [k[0] for k in vodd])
sum = n
# sum += reduce(add, [k[0] for k in veve])

# print("beforesum", sum)
# print(vodd, veve)
if vodd[0][0] >= veve[0][0]:
    sum -= vodd[0][0]
    if veve[0][1] == vodd[0][1] and len(veve) >= 2:
        sum -= veve[1][0]
    elif not veve[0][1] == vodd[0][1]:
        sum -= veve[0][0]

elif vodd[0][0] < veve[0][0]:
    sum -= veve[0][0]
    if veve[0][1] == vodd[0][1] and len(vodd) >= 2:
        sum -= vodd[1][0]
    elif not  veve[0][1] == vodd[0][1]:
        sum -= vodd[0][0]

print(sum)

Submission status: Wrong Answer

Solution code:
#!/mnt/c/Users/moiki/bash/env/bin/python
n = int(input())
v = list(map(int, input().split()))
vodd = []
dodd = {}
veve = []
deve = {}

kind = 0
inst_kinds = {}
for e,i in enumerate(v):
    if e % 2 == 0:
        # veve.append(i)
        if not i in deve:
            deve[i] = 1
        else:
            deve[i] += 1
    else:
        # vodd.append(i)
        if not i in dodd:
            dodd[i] = 1
        else:
            dodd[i] += 1

for k in deve:
    veve.append((deve[k], k))
veve.sort()
veve.reverse()
for k in dodd:
    vodd.append((dodd[k], k))
vodd.sort()
vodd.reverse()
from functools import reduce
from operator import add

sum = reduce(add, [k[0] for k in vodd])
sum += reduce(add, [k[0] for k in veve])

# print("beforesum", sum)
# print(vodd, veve)
if vodd[0][0] >= veve[0][0]:
    if vodd[0][1] == veve[0][1]: # same number
        sum -= vodd[0][0]      # keep vdd[0]
        if len(veve) >= 2:
            sum -= veve[1][0]        # choose second

    else:
        sum -= veve[0][0]  
        sum -= vodd[0][0] 
    
elif vodd[0][0] < veve[0][0]:
    sum -= veve[0][0]
    if vodd[0][1] == veve[0][1]: # same number
        if len(veve) >= 2:
            sum -= veve[1][0]        # choose second

        # sum -= veve[0][0]  # keep veve[0]
    else:
        sum -= vodd[0][0]
        # sum -= veve[0][0]
    # sum += reduce(add, [k[0] for k in veve[1:]])
print(sum)

Submission status: Wrong Answer

Solution code:
#!/mnt/c/Users/moiki/bash/env/bin/python
n = int(input())
v = list(map(int, input().split()))
vodd = []
dodd = {}
veve = []
deve = {}

kind = 0
inst_kinds = {}
for e,i in enumerate(v):
    if e % 2 == 0:
        # veve.append(i)
        if not i in deve:
            deve[i] = 1
        else:
            deve[i] += 1
    else:
        # vodd.append(i)
        if not i in dodd:
            dodd[i] = 1
        else:
            dodd[i] += 1

for k in deve:
    veve.append((deve[k], k))
veve.sort()
veve.reverse()
for k in dodd:
    vodd.append((dodd[k], k))
vodd.sort()
vodd.reverse()
from functools import reduce
from operator import add
sum = reduce(add, [k[0] for k in vodd])
sum += reduce(add, [k[0] for k in veve])

# print("beforesum", sum)
# print(vodd, veve)
if vodd[0][0] >= veve[0][0]:
    if vodd[0][1] == veve[0][1]: # same number
        if len(veve) >= 2:
            sum -= veve[1][0]        # choose second
        else:
            pass
            # sum -= veve[0][0]
    else:
        sum -= veve[0][0]  
    sum -= vodd[0][0]      
else:
    if vodd[0][1] == veve[0][1]: # same number
        if len(vodd) >= 2:
            sum -= vodd[1][0]        # choose second
        else:
            pass
            # sum -= vodd[0][0]
        sum -= veve[0][0]
    else:
        sum -= vodd[0][0]
        sum -= veve[0][0]
    # sum += reduce(add, [k[0] for k in veve[1:]])
print(sum)

Submission status: Wrong Answer

Solution code:
n = int(input())
v = []
count = [0 for i in range(100001)]
v = list(map(int, input().split()))
for elem in v:
    count[elem] += 1
count = sorted(count, key=lambda x: -x)

if count[1]==0:
    print(n//2)
else:
    if count[2]!=0:
        print(n-count[0]-count[1])
    else:
        print((count[0]-count[1])//2)

Submission status: Wrong Answer

Solution code:
n = int(input())
v = []
count = [0 for i in range(100001)]
v = list(map(int, input().split()))
for elem in v:
    count[elem] += 1
count = sorted(count, key=lambda x: -x)

if count[1]==0:
    print(n//2)
else:
    print(n-count[0]-count[1])

Submission status: Wrong Answer

Solution code:
# coding: utf-8
import collections

n=int(input())
v=list(map(int, input().split()))
ans=0
c = collections.Counter(v)

if len(c) == 1:
    print(n//2)
else:
    for i in range(0,n-2):
        if v[i] != v[i+2]:
            if v[i] != v[i+1]:
                v[i+2] = v[i]
            else:
                v[i] = v[i+2]
            ans+=1
    print(ans)

Submission status: Wrong Answer

Solution code:
import collections

n=int(input())
v=list(map(int, input().split()))
ans=0
c = collections.Counter(v)

if len(c) == 1:
    print(n//2)
else:
    for i in range(0,n-2):
        if v[i] != v[i+2]:
            v[i+2] = v[i]
            ans+=1
    print(ans)