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 sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)
##############################

from collections import Counter

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

# 奇数
O = V[0::2]
#print(O)

# 偶数
E = V[1::2]
#print(E)

# 最頻値取得
x = Counter(O).most_common(2)
(o1, _) = x[0]
(o2, _) = x[0] if len(x) == 1 else (x[1], _)

y = Counter(E).most_common(2)
(e1, _) = y[0]
(e2, _) = y[0] if len(y) == 1 else (y[1], _)

def count_replace(OE, replace):
    count = 0
    for c in OE:
        if c != replace:
            count += 1

    return count

#print(o1, e1)

# どっちで書き換えるのが手数が少ないか
if o1 == e1:
    if o2 == e2:
        print(len(O))
        exit()

    c1 = count_replace(E, e1) + count_replace(O, o2)
    c2 = count_replace(E, e2) + count_replace(O, o1)
    if c1 < c2:
        print(c1)
    else:
        print(c2)
else:
    x = count_replace(E, e1) + count_replace(O, o1)
    print(x)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

odd_v = v[::2]
even_v = v[1::2]

if len(set(v)) == 1:
  ans = len(even_v)
else:
  ans = len(odd_v) - Counter(odd_v).most_common(1)[0][1] + len(even_v) - Counter(even_v).most_common(1)[0][1]
  
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

odd_v = v[::2]
even_v = v[1::2]

if set(v) == 1:
  ans = len(even_v)
else:
  ans = len(odd_v) - Counter(odd_v).most_common(1)[0][1] + len(even_v) - Counter(even_v).most_common(1)[0][1]
  
print(ans)

Submission status: Wrong Answer

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

odd_v = v[::2]
even_v = v[1::2]

if len(set(odd_v)) == 1 and len(set(even_v)) == 1 and odd_v[0] == even_v[0]:
  ans = len(even_v)    
else:
  ans = len(set(odd_v)) - 1 + len(set(even_v)) -1
  
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
 
N = int(input())
V = [i for i in input().split()]
 
odd = Counter(V[::2]).most_common(2)
even = Counter(V[1::2]).most_common(2)

print(odd)
 
if odd[0][0] != even[0][0]:
    print(N - odd[0][1] - even[0][1])
elif len(odd) == 1:
    print(N // 2)
else:
    o0e1 = N - odd[0][1] - even[1][1]
    o1e0 = N - odd[1][1] - even[0][1]
    print(min(o0e1, o1e0))

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
v = list(map(int,input().split()))
even,odd = [],[]
for i,num in enumerate(v):
  if i % 2 == 0:
    even.append(num)
  else:
    odd.append(num)
mode_even = collections.Counter(even).most_common()[0][0]
mode_odd = collections.Counter(odd).most_common()[0][0]
print(n - len([i for i in even if i==mode_even]) - len([i for i in odd if i==mode_odd]))

Submission status: Wrong Answer

Solution code:
N=int(input())
lst=[int(s) for s in input().split()]
dica={}
dicb={}
i=0
while(i<N):
  if(lst[i] in dica):
    dica[lst[i]]+=1
  else:
    dica[lst[i]]=1
  i+=1
  if(lst[i] in dicb):
    dicb[lst[i]]+=1
  else:
    dicb[lst[i]]=1
  i+=1
lsa=sorted(list(dica.items()), key= lambda x: -x[1])
lsb=sorted(list(dicb.items()), key= lambda x: -x[1])
##1位の値が一致でなければ、そのまま
if lsa[0][0]!=lsb[0][0] :
  print(N-lsa[0][1]-lsb[0][1])
##同じなら2位を見る
elif(len(lsa)>1 and len(lsb)>1):
  print(max([N-lsa[0][1]-lsb[1][1],
             N-lsa[1][1]-lsb[0][1]]))
elif(len(lsa)>1):
  print(N-lsa[1][1]-lsb[0][1])
elif(len(lsb)>1):
  print(N-lsa[0][1]-lsb[1][1])
else:
  print(N//2)

Submission status: Wrong Answer

Solution code:
N=int(input())
lst=[int(s) for s in input().split()]
dica={}
dicb={}
i=0
while(i<N):
  if(lst[i] in dica):
    dica[lst[i]]+=1
  else:
    dica[lst[i]]=1
  i+=1
  if(lst[i] in dicb):
    dicb[lst[i]]+=1
  else:
    dicb[lst[i]]=1
  i+=1
lsa=sorted(list(dica.items()), key= lambda x: -x[1])
lsb=sorted(list(dicb.items()), key= lambda x: -x[1])
##1位の値が一致でなければ、そのまま
if lsa[0][1]!=lsb[0][1] :
  print(N-lsa[0][1]-lsb[0][1])
##同じなら2位を見る
elif(len(lsa)>1 and len(lsb)>1):
  print(max([N-lsa[0][1]-lsb[1][1],
             N-lsa[1][1]-lsb[0][1]]))
elif(len(lsa)>1):
  print(N-lsa[1][1]-lsb[0][1])
elif(len(lsb)>1):
  print(N-lsa[0][1]-lsb[1][1])
else:
  print(N//2)

Submission status: Wrong Answer

Solution code:
import collections,sys
n=int(input())
v=list(map(int,input().split()))
a=[]
b=[]
for i in range(0,n,2):
  a.append(v[i-1])
  b.append(v[i])
c=collections.Counter(a)
d=collections.Counter(b)
C=sorted(c.items(), key=lambda x:-x[1])
D=sorted(d.items(), key=lambda x:-x[1])
A=int(C[0][0])
B=int(D[0][0])
cnt=0
if len(set(a))==len(set(b))==1:
  print(n//2)
  sys.exit()
if A!=B:
  for i in range(n//2):
    if a[i]!=A:
      cnt+=1
  for j in range(n//2):
    if b[j]!=B:
      cnt+=1
  print(cnt)
  sys.exit()
if A==B:
  totla=0
  A_=int(C[1][0]) if len(set(a))!=1 else A
  for i in range(n//2):
    if a[i]!=A_:
      totla+=1
  for j in range(n//2):
    if b[j]!=B:
      totla+=1
  totlb=0
  B_=int(D[1][0]) if len(set(b))!=1 else B
  for i in range(n//2):
    if a[i]!=A:
      totlb+=1
  for j in range(n//2):
    if b[j]!=B_:
      totlb+=1
  print(min(totla,totlb))
  sys.exit()

Submission status: Wrong Answer

Solution code:
import collections,sys
n=int(input())
v=list(map(int,input().split()))
a=[]
b=[]
for i in range(0,n,2):
  a.append(v[i-1])
  b.append(v[i])
c=collections.Counter(a)
d=collections.Counter(b)
C=sorted(c.items(), key=lambda x:-x[1])
D=sorted(d.items(), key=lambda x:-x[1])
A=int(C[0][0])
B=int(D[0][0])
cnt=0
if A!=B:
  for i in range(n//2):
    if a[i]!=A:
      cnt+=1
  for j in range(n//2):
    if b[j]!=B:
      cnt+=1
  print(cnt)
  sys.exit()
if A==B:
  totla=0
  A_=int(C[1][0]) if len(set(a))!=1 else A
  for i in range(n//2):
    if a[i]!=A_:
      totla+=1
  for j in range(n//2):
    if b[j]!=B:
      totla+=1
  totlb=0
  B_=int(D[1][0]) if len(set(b))!=1 else B
  for i in range(n//2):
    if a[i]!=A:
      totlb+=1
  for j in range(n//2):
    if b[j]!=B_:
      totlb+=1
  print(min(totla,totlb))
  sys.exit()

Submission status: Wrong Answer

Solution code:
import collections
n=int(input())
v=list(map(int,input().split()))
a=[]
b=[]
for i in range(0,n,2):
  a.append(v[i-1])
  b.append(v[i])
c=collections.Counter(a)
d=collections.Counter(b)
C=sorted(c.items(), key=lambda x:-x[1])
D=sorted(d.items(), key=lambda x:-x[1])
A=int(C[0][0])
B=int(D[0][0])
cnt=0
for i in range(n//2):
  if a[i]!=A:
    cnt+=1
for j in range(n//2):
  if b[j]!=B:
    cnt+=1
print(cnt)

Submission status: Wrong Answer

Solution code:
import collections
n=int(input())
v=list(map(int,input().split()))
a=[]
b=[]
for i in range(0,n,1):
  a.append(v[i-1])
  b.append(v[i])
c=collections.Counter(a)
d=collections.Counter(b)
C=sorted(c.items(), key=lambda x:-x[1])
D=sorted(d.items(), key=lambda x:-x[1])
A=int(C[0][0])
B=int(D[0][0])
cnt=0
for i in range(n//2):
  if a[i]!=A:
    cnt+=1
for j in range(n//2):
  if b[j]!=B:
    cnt+=1
print(cnt)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict


def resolve():
    n = int(input())
    v = list(map(int, input().split())) + [0, 0]
    d_o = defaultdict(int)
    d_e = defaultdict(int)
    for i in range(n):
        if i % 2:
            d_o[v[i]] += 1
        else:
            d_e[v[i]] += 1
    de = sorted(d_e.items(), key=lambda x: -x[1])
    do = sorted(d_o.items(), key=lambda x: -x[1])
    if de == do:
        print(n - de[0][1])
    elif de[0][0] != do[0][0]:
        print(n - de[0][1] - do[0][1])
    elif de[0][0] == do[0][0]:
        p = max(de[0][1] + do[1][1], de[1][1] + do[0][1])
        print(n - p)


if __name__ == "__main__":
    resolve()

Submission status: Wrong Answer

Solution code:
from collections import defaultdict


def resolve():
    n = int(input())
    v = list(map(int, input().split()))
    d_o = defaultdict(int)
    d_e = defaultdict(int)
    for i in range(n):
        if i % 2:
            d_o[v[i]] += 1
        else:
            d_e[v[i]] += 1
    de = sorted(d_e.items(), key=lambda x: -x[1])
    do = sorted(d_o.items(), key=lambda x: -x[1])
    if de == do:
        print(n - de[0][1])
    elif de[0][0] != do[0][0]:
        print(n - de[0][1] - do[0][1])
    elif de[0][0] == do[0][0]:
        p = max(de[0][1] + do[1][1], de[1][1] + do[0][1])
        print(n - p)


if __name__ == "__main__":
    resolve()

Submission status: Wrong Answer

Solution code:
from collections import defaultdict


def resolve():
    n = int(input())
    v = list(map(int, input().split()))
    d_o = defaultdict(int)
    d_e = defaultdict(int)
    for i in range(n):
        if i % 2:
            d_o[v[i]] += 1
        else:
            d_e[v[i]] += 1
    de = sorted(d_e.items(), key=lambda x: x[1])
    do = sorted(d_o.items(), key=lambda x: x[1])
    if len(de) == len(do) == 1:
        print(n - de[0][1])
    elif de[0][0] == do[0][0]:
        p = max(de[0][1] + do[1][1], de[1][1] + do[0][1])
        print(n - p)
    elif de[0][0] != do[0][0]:
        print(n - de[0][1] - do[0][1])
    else:
        p = max(de[0][1] + do[1][1], de[1][1] + do[0][1])
        print(n - p)


if __name__ == "__main__":
    resolve()

Submission status: Wrong Answer

Solution code:
from collections import defaultdict


def resolve():
    n = int(input())
    v = list(map(int, input().split()))
    d_o = defaultdict(int)
    d_e = defaultdict(int)
    for i in range(n):
        if i % 2:
            d_o[v[i]] += 1
        else:
            d_e[v[i]] += 1
    de = sorted(d_e.items(), key=lambda x: x[1])
    do = sorted(d_o.items(), key=lambda x: x[1])
    if de == do:
        p = max(de[0][1], do[0][1])
        print(n - p)
    elif de[0] != do[0]:
        print(n - de[0][1] - do[0][1])
    else:
        p = max(de[0][1] + do[1][1], de[1][1] + do[0][1])
        print(n - p)


if __name__ == "__main__":
    resolve()

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
    A[V[i]] = A.get(V[i], 0) + 1
  else:#B
    B[V[i]] = B.get(V[i], 0) + 1

max_a = 0
for v in A.values():
  max_a = max(max_a, v)
max_b = 0
for v in B.values():
  max_b = max(max_b, v)
ans = n - max_a - max_b
if ans == 0 and V[0] == V[1]:
  ans = n // 2
print(ans)

Submission status: Wrong Answer

Solution code:
#### import ####
import sys
import math
from collections import defaultdict

#### 設定 ####
sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

#### 定数 ####
mod = 10**9 + 7

#### 読み込み ####
def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N):
    read_all = [tuple(map(int, input().split())) for _ in range(N)]
    return map(list,zip(*read_all))

#################

from collections import Counter

n = I()
v = III()

if v==[v[0]]*len(v):
    print(len(v)//2)
    exit()

x = [v[i] for i in range(0,n,2)]
y = [v[i] for i in range(1,n,2)]

xc = Counter(x)
yc = Counter(y)
xval = xc.most_common(1)[0][0]
yval = yc.most_common(1)[0][1]
xnum = xc.most_common(1)[0][1]
ynum = yc.most_common(1)[0][1]

if xval!=yval:
    print(len(x)-xnum+len(y)-ynum)
else:
    if xnum==len(x):
        print(min(len(x)+len(y)-ynum, len(x)-xnum+len(y)-yc.most_common(2)[1][1]))
    elif ynum==len(y):
        print(min(len(x)-xnum+len(y), len(x)-xc.most_common(2)[1][1]+len(y)-ynum))
    else:
        print(min(len(x)-xc.most_common(2)[1][1]+len(y)-ynum, len(x)-xnum+len(y)-yc.most_common(2)[1][1]))

Submission status: Wrong Answer

Solution code:
#### import ####
import sys
import math
from collections import defaultdict

#### 設定 ####
sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

#### 定数 ####
mod = 10**9 + 7

#### 読み込み ####
def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N):
    read_all = [tuple(map(int, input().split())) for _ in range(N)]
    return map(list,zip(*read_all))

#################

from collections import Counter

n = I()
v = III()

if v==[v[0]]*len(v):
    print(len(v)//2)
    exit()

x = [v[i] for i in range(0,n,2)]
y = [v[i] for i in range(1,n,2)]

xc = Counter(x)
yc = Counter(y)
xnum = xc.most_common(1)[0][1]
ynum = yc.most_common(1)[0][1]

print(len(x)-xnum+len(y)-ynum)

Submission status: Wrong Answer

Solution code:
import collections

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

    even = [j for i, j in enumerate(v) if i % 2 == 0]
    odd = [j for i, j in enumerate(v) if i % 2 == 1]

    cnt_e = collections.Counter(even)
    cnt_o = collections.Counter(odd)

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

    if cnt_e.most_common()[0][0] == cnt_o.most_common()[0][0]:
        if cnt_e.most_common()[0][1] > cnt_o.most_common()[0][1]:
            print(n - cnt_e.most_common()[0][1] - cnt_o.most_common()[1][1])
        else:
            print(n - cnt_e.most_common()[1][1] - cnt_o.most_common()[0][1])
    else:
        print(n - cnt_e.most_common()[0][1] - cnt_o.most_common()[0][1])


main()

Submission status: Wrong Answer

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

odd = []
even = []

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

oddm = collections.Counter(odd)
evenm = collections.Counter(even)

odd1 = oddm.most_common()[0]
even1 = evenm.most_common()[0]

if oddm.most_common()[0][1] + evenm.most_common()[0][1] == n:
  ans = n//2
else:
  if odd1 != even1:
    ans = n - oddm.most_common()[0][1] - evenm.most_common()[0][1] 
  else:
    p1 = ans = n - oddm.most_common()[1][1] - evenm.most_common()[0][1] 
    p2 = ans = n - oddm.most_common()[0][1] - evenm.most_common()[1][1] 
    ans = min(p1, p2)
    
print(ans)

Submission status: Wrong Answer

Solution code:
import collections
n=int(input())
vs=[int(i) for i in input().split()]
vs1=[v for i,v in enumerate(vs) if i%2==0]
vs2=[v for i,v in enumerate(vs) if i%2==1]

ans=0
if len(list(set(vs)))==1:
  ans+=len(vs2)
  
counted=collections.Counter(vs1)
vs1most=counted.most_common()[0][0]
counted=collections.Counter(vs2)
vs2most=counted.most_common()[0][0]

ans+=len(vs1)-vs1.count(vs1most)
ans+=len(vs2)-vs2.count(vs2most)

print(ans)

Submission status: Wrong Answer

Solution code:
import collections
n=int(input())
vs=[int(i) for i in input().split()]
vs1=[v for i,v in enumerate(vs) if i%2==0]
vs2=[v for i,v in enumerate(vs) if i%2==1]

ans=0
if len(list(set(vs)))==1:
  ans+=len(vs2)
  
counted=collections.Counter(vs1)
vs1most=counted.most_common()[0][0]
counted=collections.Counter(vs2)
vs2most=counted.most_common()[0][0]

print(len(vs1)-vs1.count(vs1most))
print(len(vs2)-vs2.count(vs2most))

ans+=len(vs1)-vs1.count(vs1most)
ans+=len(vs2)-vs2.count(vs2most)

print(ans)

Submission status: Wrong Answer

Solution code:
import collections
n=int(input())
vs=[int(i) for i in input().split()]
vs1=[v for i,v in enumerate(vs) if i%2==0]
vs2=[v for i,v in enumerate(vs) if i%2==1]

ans=0
if len(list(set(vs)))==1:
  ans+=len(vs2)
  
counted=collections.Counter(vs1)
vs1most=counted.most_common()[0][0]
counted=collections.Counter(vs2)
vs2most=counted.most_common()[0][0]

ans+=n/2-vs1.count(vs1most)
ans+=n/2-vs2.count(vs2most)

print(int(ans))

Submission status: Wrong Answer

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

x = c.most_common()[0:2]

x1 = x[0][0]
if x[0][1] == n:
  ans = n//2
else:
  x2 = x[1][0]

  count = 0

  for i in range(n):
    if i % 2 == 0:
      if v[i] != x1:
        count += 1
    else:
      if v[i] != x2:
        count += 1

  ans = count
  count = 0

  for i in range(n):
    if i % 2 == 0:
      if v[i] != x2:
        count += 1
    else:
      if v[i] != x1:
        count += 1

  ans = min(ans, count)
print(ans)

Submission status: Wrong Answer

Solution code:
import collections
n=int(input())
vs=[int(i) for i in input().split()]
vs1=[v for i,v in enumerate(vs) if i%2==0]
vs2=[v for i,v in enumerate(vs) if i%2==1]

ans=0
if len(list(set(vs)))==1:
  ans+=len(vs2)
  
if len(list(set(vs1)))!=1:
  counted = collections.Counter(vs1)
  ans+=n/2-counted.most_common()[0][0]

if len(list(set(vs2)))!=1:
  counted = collections.Counter(vs2)
  ans+=n/2-counted.most_common()[0][0]

print(int(ans))

Submission status: Wrong Answer

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

vs1=[v for i,v in enumerate(vs) if i%2==0]
vs2=[v for i,v in enumerate(vs) if i%2==1]

ans=0
if list(set(vs1))==list(set(vs2)):
  ans+=len(vs2)
if len(list(set(vs1)))!=1:
  ans+=len(list(set(vs1)))-1
if len(list(set(vs2)))!=1:
  ans+=len(list(set(vs2)))-1

print(ans)

Submission status: Wrong Answer

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

vs1=[v for i,v in enumerate(vs) if i%2==0]
vs2=[v for i,v in enumerate(vs) if i%2==1]

ans=0
if len(list(set(vs1)))!=1:
  ans+=len(list(set(vs1)))-1
if len(list(set(vs2)))!=1:
  ans+=len(list(set(vs2)))-1
if len(list(set(vs1)))==1 and len(list(set(vs2)))==1:
  ans+=len(vs2)
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

n = int(input())
E = []
O = []
V = [int(el) for el in input().split(' ')]
for i in range(n):
    if i % 2 == 0:
        O.append(V[i])
    else:
        E.append(V[i])

E_count = Counter(E).most_common(1)[0][1]
O_count = Counter(O).most_common(1)[0][1]

if len(set(V)) == 1:
    print(n//2)
else:
    E_change = n // 2 - E_count
    O_change = n //2  - O_count
    print(E_change + O_change)

Submission status: Wrong Answer

Solution code:
from collections import Counter

n = int(input())
E = []
O = []
V = [int(el) for el in input().split(' ')]
for i in range(n):
    if i % 2 == 0:
        O.append(V[i])
    else:
        E.append(V[i])

E_count = Counter(E).most_common(1)[0][1]
O_count = Counter(O).most_common(1)[0][1]

if len(set(V)) == 1:
    print(n//2)
else:
    E_change = n // 2 - E_count
    O_change = n //2  - O_count
    print(E_change, O_change)
    print(E_change + O_change)

Submission status: Wrong Answer

Solution code:
import sys
input=sys.stdin.readline

def main():
    N = int(input())
    V1 = {}
    V2 = {}
    V = list(map(int, input().split()))
    for i,v in enumerate(V):
        if i%2 == 0:
            V1[v] = V1[v] + 1 if v in V1 else 1
        else:
            V2[v] = V2[v] + 1 if v in V2 else 1

    V1 = sorted(V1.items(), key=lambda x:x[1], reverse=True)
    V2 = sorted(V2.items(), key=lambda x:x[1], reverse=True)

    if V1[0] != V2[0]:
        ans = 0
        for v in V1[1:]:
            ans += v[1]
        for v in V2[1:]:
            ans += v[1]
        print(ans)
    else:
        a1 = 0
        for v in V1[1:]:
            a1 += v[1]
        a1 += V2[0][1]
        for v in V2[2:]:
            a1 += v[1]
        a2 = 0
        a2 += V1[0][1]
        for v in V1[2:]:
            a2 += v[1]
        for v in V2[1:]:
            a1 += v[1]
        print(min(a1,a2))

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
input=sys.stdin.readline

def main():
    N = int(input())
    V = {}
    for v in list(map(int, input().split())):
        if v in V:
            V[v] += 1
        else:
            V[v] = 1
    V = sorted(V.items(), key=lambda x:x[1], reverse=True)
    if len(V) == 1:
        print(V[0][1]//2)
    elif len(V) == 2:
        print((V[0][1]-V[1][1])//2)
    else:
        ans = 0
        for i in V[2:]:
            ans += i[1]
        print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import collections
N = int(input())
V = list(map(int,input().split()))
a = [0]*(N//2)
b = [0]*(N//2)
ans = 0
for i in range(0,N,2):
    a[i//2] = V[i]
for j in range(1,N,2):
    b[j//2] = V[j]
if len(list(set(a)))==1 and len(list(set(b)))==1 and list(set(a))==list(set(b)):
    print(N//2)
else:
    a = collections.Counter(a)
    b = collections.Counter(b)
    ans += (N//2)-a.most_common()[0][1]
    ans += (N//2)-b.most_common()[0][1]
    print(ans)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

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

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

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

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

even_sorted = sorted(even.items(), key=lambda x: x[1], reverse=True)
odd_sorted = sorted(odd.items(), key=lambda x: x[1], reverse=True)

#print(even_sorted[0:4])
#print(odd_sorted[0:4])


if(len(even_sorted) == 1): # what if either of them had only one uniq num..
  if(odd_sorted[0][0] == even_sorted[0][0]):
    print(n - odd_sorted[1][1]  - even_sorted[0][1])
  else:
    print(n - odd_sorted[0][1] - even_sorted[0][1])
elif(len(odd_sorted) == 1):
  if(odd_sorted[0][0] == even_sorted[0][0]):
    print(n - even_sorted[1][1] - odd_sorted[0][1])
  else:
    print(n - odd_sorted[0][1] - even_sorted[0][1])


else: # both of them have more than 1 uniq num..
  if(odd_sorted[0][0] == even_sorted[0][0]):
    if(odd_sorted[0][1] == even_sorted[0][1]):
      if(odd_sorted[1][1] < even_sorted[1][1]):
        print(n - odd_sorted[1][1] - even_sorted[0][1])
      else:
        print(n - odd_sorted[0][1] - even_sorted[1][1])
    elif(odd_sorted[0][1] < even_sorted[0][1]): # odd to be changed (even stays)
      print(n - odd_sorted[1][1] - even_sorted[0][1])
    else:
      print(n - odd_sorted[0][1] - even_sorted[1][1])
  else: # both has more than 1 uniq num, and most freq values aren't the same
    print(n - odd_sorted[0][1] - even_sorted[0][1])

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

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

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

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

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

even_sorted = sorted(even.items(), key=lambda x: x[1], reverse=True)
odd_sorted = sorted(odd.items(), key=lambda x: x[1], reverse=True)

#print(even_sorted[0:4])
#print(odd_sorted[0:4])


if(len(even_sorted) == 1): # what if either of them had only one uniq num..
  if(odd_sorted[0][0] == even_sorted[0][0]):
    print(n - odd_sorted[1][1]  - even_sorted[0][1])
  else:
    print(n - odd_sorted[0][1] - even_sorted[0][1])
elif(len(odd_sorted) == 1):
  if(odd_sorted[0][0] == even_sorted[0][0]):
    print(n - even_sorted[1][1] - odd_sorted[0][1])
  else:
    print(n - odd_sorted[0][1] - even_sorted[0][1])


else: # both of them have more than 1 uniq num..
  if(odd_sorted[0][0] == even_sorted[0][0]):
    if(odd_sorted[0][1] == even_sorted[0][1] and \
        odd_sorted[1][1] < even_sorted[1][1]):
      print(n - odd_sorted[1][1] - even_sorted[0][1])
    else:
      print(n - odd_sorted[0][1] - even_sorted[1][1])
    if(odd_sorted[0][1] < even_sorted[0][1]): # odd to be changed (even stays)
      print(n - odd_sorted[1][1] - even_sorted[0][1])
    else:
      print(n - odd_sorted[0][1] - even_sorted[1][1])
  else: # both has more than 1 uniq num, and most freq values aren't the same
    print(n - odd_sorted[0][1] - even_sorted[0][1])

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

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

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

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

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

even_sorted = sorted(even.items(), key=lambda x: x[1], reverse=True)
odd_sorted = sorted(odd.items(), key=lambda x: x[1], reverse=True)

#print(even_sorted[0:4])
#print(odd_sorted[0:4])


if(len(even_sorted) == 1): # what if either of them had only one uniq num..
  if(odd_sorted[0][0] == even_sorted[0][0]):
    print(n - odd_sorted[1][1]  - even_sorted[0][1])
  else:
    print(n - odd_sorted[0][1] - even_sorted[0][1])
elif(len(odd_sorted) == 1):
  if(odd_sorted[0][0] == even_sorted[0][0]):
    print(n - even_sorted[1][1] - odd_sorted[0][1])
  else:
    print(n - odd_sorted[0][1] - even_sorted[0][1])


else: # both of them have more than 1 uniq num..
  if(odd_sorted[0][0] == even_sorted[0][0]):
    if(odd_sorted[0][1] <= even_sorted[0][1]): # odd to be changed (even stays)
      print(n - odd_sorted[1][1] - even_sorted[0][1])
    else:
      print(n - odd_sorted[0][1] - even_sorted[1][1])
  else: # both has more than 1 uniq num, and most freq values aren't the same
    print(n - odd_sorted[0][1] - even_sorted[0][1])

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

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

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

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

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

even_sorted = sorted(even.items(), key=lambda x: x[1], reverse=True)
odd_sorted = sorted(odd.items(), key=lambda x: x[1], reverse=True)

print(even_sorted[0:4])
print(odd_sorted[0:4])


if(len(even_sorted) == 1): # what if either of them had only one uniq num..
  if(odd_sorted[0][0] == even_sorted[0][0]):
    print("a")
    print(n - odd_sorted[1][1]  - even_sorted[0][1])
  else:
    print('b')
    print(n - odd_sorted[0][1] - even_sorted[0][1])
elif(len(odd_sorted) == 1):
  if(odd_sorted[0][0] == even_sorted[0][0]):
    print("c")
    print(n - even_sorted[1][1] - odd_sorted[0][1])
  else:
    print('d')
    print(n - odd_sorted[0][1] - even_sorted[0][1])


else: # both of them have more than 1 uniq num..
  if(odd_sorted[0][0] == even_sorted[0][0]):
    if(odd_sorted[0][1] <= even_sorted[0][1]): # odd to be changed (even stays)
      print('e')
      print(n - odd_sorted[1][1] - even_sorted[0][1])
    else:
      print('f')
      print(n - odd_sorted[0][1] - even_sorted[1][1])
  else: # both has more than 1 uniq num, and most freq values aren't the same
    print('g')
    print(n - odd_sorted[0][1] - even_sorted[0][1])

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

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

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

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

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

even_sorted = sorted(even.items(), key=lambda x: x[1], reverse=True)
odd_sorted = sorted(odd.items(), key=lambda x: x[1], reverse=True)

#print(even_sorted)
#print(odd_sorted)

if(len(even_sorted) == 1): # what if either of them had only one uniq num..
  if(odd_sorted[0][0] == even_sorted[0][0]):
    print(n - odd_sorted[1][1]  - even_sorted[0][1])
  else:
    print(n - odd_sorted[0][1] - even_sorted[0][1])
elif(len(odd_sorted) == 1):
  if(odd_sorted[0][0] == even_sorted[0][0]):
    print(n - even_sorted[1][1] - odd_sorted[0][1])
  else:
    print(n - odd_sorted[0][1] - even_sorted[0][1])


else: # both of them have more than 1 uniq num..
  if(odd_sorted[0][0] == even_sorted[0][0]):
    if(odd_sorted[0][1] < even_sorted[0][1]): # odd to be changed (even stays)
      print(n - odd_sorted[1][1] - even_sorted[0][1])
    else:
      print(n - odd_sorted[0][1] - even_sorted[1][1])
  else: # both has more than 1 uniq num, and most freq values aren't the same
    print(n - odd_sorted[0][1] - even_sorted[0][1])

Submission status: Wrong Answer

Solution code:
from collections import Counter
import sys
input = sys.stdin.readline
n = int(input())
vlist = tuple(map(int,input().split()))
even = Counter(vlist[::2]).most_common(2)
odd = Counter(vlist[1::2]).most_common(2)
if even[0][0]==odd[0][0]:
    if len(even)==1 or len(odd)==1:
        if len(even)==1 or len(odd)==1:
            print(even[0][1])
        else:
            if len(even)==1:
                if even[0][1]>odd[0][1]:
                    print(n-even[0][1]-odd[1][1])
                else:
                    print(n+even[0][1]-odd[0][1])
            else:
                if even[0][1]>odd[0][1]:
                    print(n-even[0][1]+odd[0][1])
                else:
                    print(n-even[1][1]-odd[0][1])
    else:
        if even[0][1]>odd[0][1]:
            print(n-even[0][1]-odd[1][1])
        else:
            print(n-even[1][1]-odd[0][1])            
else:
    print(n-odd[0][1]-even[0][1])

Submission status: Wrong Answer

Solution code:
from collections import Counter
import sys
input = sys.stdin.readline
n = int(input())
vlist = tuple(map(int,input().split()))
even = Counter(vlist[::2]).most_common(2)
odd = Counter(vlist[1::2]).most_common(2)
if even[0][0]==odd[0][0]:
    if len(even)==1 and len(odd)==1:
        print(even[0][1])
    else:
        if even[0][1]>odd[0][1]:
            print(n-even[0][1]-odd[1][1])
        else:
            print(n-even[1][1]-odd[0][1])            
else:
    print(n-odd[0][1]-even[0][1])

Submission status: Wrong Answer

Solution code:
from collections import Counter
import sys
input = sys.stdin.readline
n = int(input())
vcounter = Counter(map(int,input().split()))
if len(vcounter)==1:
    print(tuple(vcounter.values())[0]//2)
else:
    print(n-sum(sorted(vcounter.values())[-2:]))

Submission status: Wrong Answer

Solution code:
from collections import Counter
import sys
input = sys.stdin.readline
n = int(input())
vcounter = Counter(map(int,input().split()))
if len(vcounter)==1:
    print(tuple(vcounter.values())[0]//2)
else:
    print(n-sum(sorted(vcounter.values(),reverse=True)[:2]))

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

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

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

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

if(len(al) == 1):
  print(int(n / 2))
  exit()

even_sorted = sorted(even.items(), key=lambda x: x[1], reverse=True)
odd_sorted = sorted(odd.items(), key=lambda x: x[1], reverse=True)

#print(even_sorted)
#print(odd_sorted)

op = 0
if(even_sorted[0][0] == odd_sorted[0][0]): 
  if(even_sorted[0][1] < odd_sorted[0][1]):
    op = even_sorted[0][1]
    even_sorted.pop(0)
  else:
    op = odd_sorted[0][1]
    odd_sorted.pop(0)

for i in range(1, len(even_sorted)):
  op += even_sorted[i][1]
for i in range(1, len(odd_sorted)):
  op += odd_sorted[i][1]
print(op)