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

N = int(input())
A = list(map(int, input().split()))
e = [A[i] for i in range(len(A)) if i % 2 == 0]
o = [A[i] for i in range(len(A)) if i % 2 == 1]

if len(set(A))==1:
    print(len(A)//2)
else:
    ce = collections.Counter(e)
    co = collections.Counter(o)
    esp = [v for k,v in ce.items()]
    osp = [v for k,v in co.items()]
    cnte = sum(esp[1:])
    cnto = sum(osp[1:])
    print(cnte+cnto)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
e = [A[i] for i in range(len(A)) if i % 2 == 0]
o = [A[i] for i in range(len(A)) if i % 2 == 1]

if len(set(A))==1:
    print(len(A)//2)
else:
    print(len(set(e))-1+len(set(o))-1)

Submission status: Wrong Answer

Solution code:
n=input()
v=input().split()
#vin=[int(i) for i in v]
nlis=list(n)
nint=int(n)
part_num=int((nint/2))
ev_num=[]
for i in range(part_num):
    ev = 2*i
    ev_num.extend(v[ev])
count_ev=[]
for i in range(part_num):
    count=0
    count_ev.append(ev_num.count(ev_num[i]))
    
ans_ev=min(count_ev)

od_num=[]
for i in range(part_num):
    od = (2*i) + 1
    od_num.extend(v[od])
count_od=[]
for i in range(part_num):
    count=0
    count_od.append(od_num.count(od_num[i]))
ans_od=min(count_od)

if v.count(v[0]) == len(v):
    ans=part_num
else:
    ans=ans_ev+ans_od
print(ans)

Submission status: Wrong Answer

Solution code:
n=input()
v=input().split()
#vin=[int(i) for i in v]
nlis=list(n)
nint=int(n)
part_num=int((nint/2))
ev_num=[]
for i in range(part_num):
    ev = 2*i
    ev_num.extend(v[ev])
count_ev=[]

for i in range(part_num):
    count=0
    for j in range(part_num):
        if ev_num[i]!=ev_num[j]:
            count=count+1
    count_ev.append(count)
ans_ev=min(count_ev)

od_num=[]
for i in range(part_num):
    od = (2*i) + 1
    od_num.extend(v[od])
count_od=[]

for i in range(part_num):
    count=0
    for j in range(part_num):
        if od_num[i]!=od_num[j]:
            count=count+1
    count_od.append(count)
ans_od=min(count_od)

if v.count(v[0]) == len(v):
    ans=part_num
else:
    ans=ans_ev+ans_od
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

a1 = list(Counter(V[::2]).items())
a2 = list(Counter(V[1::2]).items())

a1.sort(key=lambda a: a[1])
a2.sort(key=lambda a: a[1])

if a1[0][0] != a2[0][0]:
    print(N - a1[0][1] - a2[0][1])
else:
    if len(a1) == 1 and len(a2) == 1:
        print(N // 2)
    elif len(a1) == 1:
        print(N - a2[1][1])
    elif len(a2) == 1:
        print(N - a1[1][1])
    else:
        print(min(N - a1[1][1] - a2[0][1], N - a1[0][1] - a2[1][1]))

Submission status: Wrong Answer

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

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

print(even)
print(odd)

even_map = {}
for x in even:
    if not x in even_map:
        even_map[x] = even.count(x)

odd_map = {}
for x in odd:
    if not x in odd_map:
        odd_map[x] = odd.count(x)

sorted_even = sorted(even_map.items(), key=lambda x:x[1], reverse=True)
sorted_odd = sorted(odd_map.items(), key=lambda x:x[1], reverse=True)

e = 0
o = 0

if sorted_even[0][1] > sorted_odd[0][1]:
    e = sorted_even[0][0]
    if sorted_odd[0][0] != sorted_even[0][0]:
        o = sorted_odd[0][0]
    else:
        if len(sorted_odd) >= 2:
            o = sorted_odd[1][0]
        else:
            o = -1
else:
    o = sorted_odd[0][0]
    if sorted_odd[0][0] != sorted_even[0][0]:
        e = sorted_even[0][0]
    else:
        if len(sorted_even) >= 2:
            e = sorted_even[1][0]
        else:
            e = -1

ans = 0
for x in even:
    if x != e:
        ans = ans + 1

for x in odd:
    if x != o:
        ans = ans + 1

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
v = list(map(int, input().rstrip().split()))
count_even = {}
count_odd = {}
if v.count(v[0]) == N:
    print(N//2)
    exit()
for i in range(N):
    num = v[i]
    if i % 2 == 0:
        value = count_odd.get(num)
        if value == None:
            count_odd[num] = 1
        else:
            count_odd[num] += 1
    else:
        value = count_even.get(num)
        if value == None:
            count_even[num] = 1
        else:
            count_even[num] += 1
count_even = sorted(count_even.items(), key=lambda x: x[1],reverse=True)
count_odd = sorted(count_odd.items(), key=lambda x: x[1],reverse=True)
if count_even[0][0] == count_odd[0][0]:
    a, b = count_even[0][1], count_odd[0][1]
    if a > b:
        tmp = count_odd[0]
        count_odd[0] = count_odd[1]
        count_odd[1] = tmp
    else:
        tmp = count_even[0]
        count_even[0] = count_even[1]
        count_even[1] = tmp
count_even = [x[1] for x in count_even]
count_odd = [x[1] for x in count_odd]
answer = 0
if len(count_odd) > 1:
    for i in range(1, len(count_odd)):
        answer += count_odd[i] 
if len(count_even) > 1:
    for i in range(1, len(count_even)):
        answer += count_even[i] 
print(answer)

Submission status: Wrong Answer

Solution code:
N = int(input())
v = list(map(int, input().rstrip().split()))
count_even = {}
count_odd = {}
if v.count(v[0]) == N:
    print(N//2)
    exit()
for i in range(N):
    num = v[i]
    if i % 2 == 0:
        value = count_odd.get(num)
        if value == None:
            count_odd[num] = 1
        else:
            count_odd[num] += 1
    else:
        value = count_even.get(num)
        if value == None:
            count_even[num] = 1
        else:
            count_even[num] += 1
count_even = sorted(count_even.items(), key=lambda x: x[1],reverse=True)
count_odd = sorted(count_odd.items(), key=lambda x: x[1],reverse=True)
count_even = [x[1] for x in count_even]
count_odd = [x[1] for x in count_odd]
answer = 0
if len(count_odd) > 1:
    for i in range(1, len(count_odd)):
        answer += count_odd[i] 
if len(count_even) > 1:
    for i in range(1, len(count_even)):
        answer += count_even[i] 
print(answer)

Submission status: Wrong Answer

Solution code:
import collections

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

odd_v = v[1::2]
evn_v = v[0::2]


odd_dict = collections.Counter(odd_v)
evn_dict = collections.Counter(evn_v)

res = 0
if odd_dict.most_common()[0][0] != evn_dict.most_common()[0][0]:
    for i in range(n):
        if i % 2 == 1:
            if v[i] != odd_dict.most_common()[0][0]:
                res += 1
        else:
            if v[i] != evn_dict.most_common()[0][0]:
                res += 1
                
elif all(v[i] == v[0] for i in range(n)):
    print(n // 2)
    exit()

else:
    odd_2 = odd_dict.most_common()[1][0]
    evn_2 = evn_dict.most_common()[1][0]
    res1 = 0
    res2 = 0
    for i in range(n):
        if i % 2 == 1:
            if v[i] != odd_dict.most_common()[0][0]:
                res1 += 1
            elif v[i] != odd_2:
                res2 += 1
        else:
            if v[i] != evn_2:
                res1 += 1
            else:
                res2 += 1

    res = min(res1, res2)

print(res)

Submission status: Wrong Answer

Solution code:
import collections
N = int(input())
V = input().split(' ')

EVEN = V[0::2]
ODD = V[1::2]
EVEN_V = collections.Counter(EVEN)
ODD_V = collections.Counter(ODD)
if N == 2:
  print(0)
A = len(EVEN_V)
B = len(ODD_V)


if EVEN_V.most_common()[0][1] >= ODD_V.most_common()[0][1]:
  MAX_ELE = EVEN_V.most_common()[0][0]
  count_max =EVEN_V.most_common()[0][1]
  for i in range(B):
    if MAX_ELE != ODD_V.most_common()[i][0]:
      SECOND_ELE = ODD_V.most_common()[i][0]
      count_SEC = ODD_V.most_common()[i][1]
      break
    else:
      count_SEC = 0
  
else:
  MAX_ELE = ODD_V.most_common()[0][0]
  count_max = ODD_V.most_common()[0][1]
  for i in range(A):
    if MAX_ELE != EVEN_V.most_common()[i][0]:
      SECOND_ELE =EVEN_V.most_common()[i][0]
      count_SEC = EVEN_V.most_common()[i][1]
      break
    else:
      count_SEC = 0
print((N- int(count_max) - int(count_SEC)))

Submission status: Wrong Answer

Solution code:
import collections
N = int(input())
V = input().split(' ')

EVEN = V[0::2]
ODD = V[1::2]
EVEN_V = collections.Counter(EVEN)
ODD_V = collections.Counter(ODD)
if N == 2:
  print(0)
A = len(EVEN_V)
B = len(ODD_V)


if EVEN_V.most_common()[0][1] >= ODD_V.most_common()[0][1]:
  MAX_ELE = EVEN_V.most_common()[0][0]
  count_max =EVEN_V.most_common()[0][1]
  for i in range(B):
    if MAX_ELE != ODD_V.most_common()[i][0]:
      SECOND_ELE = ODD_V.most_common()[i][0]
      count_SEC = ODD_V.most_common()[i][1]
      break
    else:
      count_SEC = N/2
  
else:
  MAX_ELE = ODD_V.most_common()[0][0]
  count_max = ODD_V.most_common()[0][1]
  for i in range(A):
    if MAX_ELE != EVEN_V.most_common()[i][0]:
      SECOND_ELE =EVEN_V.most_common()[i][0]
      count_SEC = EVEN_V.most_common()[i][1]
      break
    else:
      count_SEC = N/2
print((N- int(count_max) - int(count_SEC)))

Submission status: Wrong Answer

Solution code:
import collections
N = int(input())
V = input().split(' ')

EVEN = V[0::2]
ODD = V[1::2]
EVEN_V = collections.Counter(EVEN)
ODD_V = collections.Counter(ODD)
if N == 2:
  print(0)
A = len(EVEN_V)
B = len(ODD_V)


if EVEN_V.most_common()[0][1] >= ODD_V.most_common()[0][1]:
  MAX_ELE = EVEN_V.most_common()[0][0]
  count_max =EVEN_V.most_common()[0][1]
  for i in range(B):
    if MAX_ELE != ODD_V.most_common()[i][0]:
      SECOND_ELE = ODD_V.most_common()[i][0]
      count_SEC = ODD_V.most_common()[i][1]
      break
    else:
      count_SEC = B
  
else:
  MAX_ELE = ODD_V.most_common()[0][0]
  count_max = ODD_V.most_common()[0][1]
  for i in range(A):
    if MAX_ELE != EVEN_V.most_common()[i][0]:
      SECOND_ELE =EVEN_V.most_common()[i][0]
      count_SEC = EVEN_V.most_common()[i][1]
      break
    else:
      count_SEC = A
print((N- int(count_max) - int(count_SEC)))

Submission status: Wrong Answer

Solution code:
n=int(input())
mona=list(map(int,input().split()))
hoge=[]
huga=[]
for i in range(n):
  if(i%2==0):
    hoge.append(mona[i])
  else:
    huga.append(mona[i])
hoges=list(set(hoge))
hugas=list(set(huga))
ans1=[]
ans2=[]
for i in range(len(hoges)):
  ans1.append(hoge.count(hoges[i]))
for i in range(len(hugas)):
  ans2.append(huga.count(hugas[i]))
  
print(n-max(ans1)-max(ans2))

Submission status: Wrong Answer

Solution code:
import collections
N = int(input())
V = input().split(' ')

EVEN = V[0::2]
ODD = V[1::2]
EVEN_V = collections.Counter(EVEN)
ODD_V = collections.Counter(ODD)

A = len(EVEN_V)
B = len(ODD_V)


if EVEN_V.most_common()[0][1] >= ODD_V.most_common()[0][1]:
  MAX_ELE = EVEN_V.most_common()[0][0]
  count_max =EVEN_V.most_common()[0][1]
  for i in range(B):
    if MAX_ELE != ODD_V.most_common()[i][0]:
      SECOND_ELE = ODD_V.most_common()[i][0]
      count_SEC = ODD_V.most_common()[i][1]
      break
    else:
      count_SEC = B
  
else:
  MAX_ELE = ODD_V.most_common()[0][0]
  count_max = ODD_V.most_common()[0][1]
  for i in range(A):
    if MAX_ELE != EVEN_V.most_common()[i][0]:
      SECOND_ELE =EVEN_V.most_common()[i][0]
      count_SEC = EVEN_V.most_common()[i][1]
      break
    else:
      count_SEC = A
print((N- int(count_max) - int(count_SEC)))

Submission status: Wrong Answer

Solution code:
import collections
N = int(input())
V = input().split(' ')

EVEN = V[0::2]
ODD = V[1::2]
EVEN_V = collections.Counter(EVEN)
ODD_V = collections.Counter(ODD)

A = len(EVEN_V)
B = len(ODD_V)


if EVEN_V.most_common()[0][1] >= ODD_V.most_common()[0][1]:
  MAX_ELE = EVEN_V.most_common()[0][0]
  count_max =EVEN_V.most_common()[0][1]
  for i in range(B):
    if MAX_ELE != ODD_V.most_common()[0][0]:
      SECOND_ELE = ODD_V.most_common()[i][0]
      count_SEC = ODD_V.most_common()[i][1]
      break
    else:
      count_SEC = B
  
else:
  MAX_ELE = ODD_V.most_common()[0][0]
  count_max = ODD_V.most_common()[0][1]
  for i in range(A):
    if MAX_ELE != EVEN_V.most_common()[i][0]:
      SECOND_ELE =EVEN_V.most_common()[i][0]
      count_SEC = EVEN_V.most_common()[i][1]
      break
    else:
      count_SEC = A
print((N- int(count_max) - int(count_SEC)))

Submission status: Wrong Answer

Solution code:
import collections

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

odd = []
even = []
for i in range(n_half):
  odd.append(v[i*2])
  even.append(v[i*2+1])

oc = collections.Counter(odd)
ec = collections.Counter(even)
ocm = oc.most_common()
ecm = ec.most_common()
if ocm[0][0] != ecm[0][0]:
  print(n - ocm[0][1] - ecm[0][1])
else:
  if ocm[0][1] == n_half and ecm[0][1] == n_half:
    print(n_half)
  elif ocm[0][1] >= ecm[0][1]:
    print(n - ocm[0][1] - ecm[1][1])
  else:
    print(n - ocm[1][1] - ecm[0][1])

Submission status: Wrong Answer

Solution code:
import collections

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

odd = []
even = []
for i in range(int(n/2)):
  odd.append(v[i*2+1])
  even.append(v[i*2])

oc = collections.Counter(odd)
ec = collections.Counter(even)
ocm = oc.most_common()
ecm = ec.most_common()
if ocm[0][0] != ecm[0][0]:
  print(n - ocm[0][1] - ecm[0][1])
else:
  if ocm[0][1] + ecm[0][1] == n:
    print(int(n / 2))
  elif ocm[0][1] >= ecm[0][1]:
    print(n - ocm[0][1] - ecm[1][1])
  else:
    print(n - ocm[1][1] - ecm[0][1])

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys


def solve(n: int, v: "List[int]"):
    counts = [{}, {}]
    for i in range(n):
        if v[i] in counts[i % 2]:
            counts[i % 2][v[i]] += 1
        else:
            counts[i % 2][v[i]] = 1
    l1 = list(counts[0].items()) + [(-1, 0)]
    l2 = list(counts[1].items()) + [(-1, 0)]
    #print(l1)
    #print(l2)
    tmp = 0
    if l1[0][0] == l2[0][0]:
        tmp = max(l1[0][1] + l2[1][1], l1[1][1] + l2[0][1])
    else:
        tmp = l1[0][1] + l2[0][1]
    ret = n - tmp
    print(ret)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    n = int(next(tokens))  # type: int
    v = [ int(next(tokens)) for _ in range(n) ]  # type: "List[int]"
    solve(n, v)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import collections , sys



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


c2 = collections.Counter(v[::2])
c1 = collections.Counter(v[1::2])

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

ceven = c2.most_common()[0][:]
codd = c1.most_common()[0][:]

if ceven[1] != codd[1] and ceven[0] == codd[0]:
    if ceven[1] > codd[1]:
        codd = c1.most_common()[1][:]
    else:
        ceven = c2.most_common()[1][:]
    
ans = n - codd[1] - ceven[1]

print(ans)

Submission status: Wrong Answer

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

box = []
counter = Counter(v)
for word, cnt in counter.most_common():
    box.append([cnt, word])
    
box.sort()
box.reverse()
if len(box) == 1:
    print(n//2)
    exit()
    
a = box[0][1]
b = box[1][1]

temp1, temp2 = [], []
for i in range(n):
    if i % 2 == 0:
        temp1.append(a)
        temp2.append(b)
    else:
        temp1.append(b)
        temp2.append(a)
a_score = 0
b_score = 0
for i in range(n):
    if v[i] != temp1[i]:
        a_score += 1
    elif v[i] != temp2[i]:
        b_score += 1
        
print(min(a_score, b_score))

Submission status: Wrong Answer

Solution code:
n, = (int(x) for x in input().split())
vi_arr = [int(x) for x in input().split()]
odd_dict = {"a":0}
even_dict = {"a":0}
for i, vi in enumerate(vi_arr):
    if i%2 == 1:
        idict = odd_dict
    else:
        idict = even_dict
    idict.setdefault(vi, 0)
    idict[vi] += 1

odd_hist = sorted(odd_dict.items(), key=lambda x:x[1], reverse=True)
even_hist = sorted(even_dict.items(), key=lambda x:x[1], reverse=True)

max_odd = odd_hist[0][1]
max_even = even_hist[0][1]
if odd_hist[0][0] == even_hist[0][0]:
    if odd_hist[0][1] > even_hist[0][1]:
        max_even = even_hist[1][1]
    else:
        max_odd = odd_hist[1][1]



print(len(vi_arr)-max_odd-max_even)

Submission status: Wrong Answer

Solution code:
n=int(input())
s=list(map(int,input().split()))
d1=dict()
d2=dict()
for i in range(0,n,2):
  if s[i] not in d1:
    d1[s[i]]=1
  else:
    d1[s[i]]+=1
for i in range(1,n,2):
  if s[i] not in d2:
    d2[s[i]]=1
  else:
    d2[s[i]]+=1
dmk,dm,dmmk,dmm=[],0,[],0
for i in d1.keys():
  if dm<d1[i]:
    dmm=dm
    dmmk=dmk
    dm=d1[i]
    dmk=[i]
  elif d1==d1[i]:
    dmk+=[i]
  elif dmm<d1[i]:
    dmm=d1[i]
    dmmk=[i]
  elif dmm==d1[i]:
    dmmk+=[i]
d1=[dm,dmk,dmm,dmmk]
dmk,dm,dmmk,dmm=[],0,[],0
for i in d2.keys():
  if dm<d2[i]:
    dmm=dm
    dmmk=dmk
    dm=d2[i]
    dmk=[i]
  elif d2==d2[i]:
    dmk+=[i]
  elif dmm<d2[i]:
    dmm=d2[i]
    dmmk=[i]
  elif dmm==d2[i]:
    dmmk+=[i]
d2=[dm,dmk,dmm,dmmk]
if len(d1[1])>1 or len(d2[1])>1:
  print(n-d1[0]-d2[0])
else:
  print(n-max(d1[0]+d2[2],d1[2]+d2[0]))

Submission status: Wrong Answer

Solution code:
n=int(input())
s=list(map(int,input().split()))
d1=dict()
d2=dict()
for i in range(0,n,2):
  if i not in d1:
    d1[i]=1
  else:
    d1[i]+=1
for i in range(1,n,2):
  if i not in d2:
    d2[i]=1
  else:
    d2[i]+=1
dmk,dm,dmmk,dmm=[],0,[],0
for i in d1.keys():
  if dm<d1[i]:
    dmm=dm
    dmmk=dmk
    dm=d1[i]
    dmk=[i]
  elif d1==d1[i]:
    dmk+=[i]
  elif dmm<d1[i]:
    dmm=d1[i]
    dmmk=[i]
  elif dmm==d1[i]:
    dmmk+=[i]
d1=[dm,dmk,dmm,dmmk]
dmk,dm,dmmk,dmm=[],0,[],0
for i in d2.keys():
  if dm<d2[i]:
    dmm=dm
    dmmk=dmk
    dm=d2[i]
    dmk=[i]
  elif d2==d2[i]:
    dmk+=[i]
  elif dmm<d2[i]:
    dmm=d2[i]
    dmmk=[i]
  elif dmm==d2[i]:
    dmmk+=[i]
d2=[dm,dmk,dmm,dmmk]
if len(d1[1])>1 or len(d2[1])>1:
  print(n-d1[0]-d2[0])
else:
  print(n-max(d1[0]+d2[2],d1[2]+d2[0]))

Submission status: Wrong Answer

Solution code:
n=int(input())
s=list(map(int,input().split()))
d1=dict()
d2=dict()
for i in range(0,n,2):
  if i not in d1:
    d1[i]=1
  else:
    d1[i]+=1
for i in range(1,n,2):
  if i not in d2:
    d2[i]=1
  else:
    d2[i]+=1
dmk,dm,dmmk,dmm=[],0,[],0
for i in d1.keys():
  if dm<d1[i]:
    dmm=dm
    dmmk=dmk
    dm=d1[i]
    dmk=[i]
  elif d1==d1[i]:
    dmk+=[i]
  elif dmm<d1[i]:
    dmm=d1[i]
    dmmk=[i]
  elif dmm==d1[i]:
    dmmk+=[i]
d1=[len(dmk),len(dmmk)]
dmk,dm,dmmk,dmm=[],0,[],0
for i in d2.keys():
  if dm<d2[i]:
    dmm=dm
    dmmk=dmk
    dm=d2[i]
    dmk=[i]
  elif d2==d2[i]:
    dmk+=[i]
  elif dmm<d2[i]:
    dmm=d2[i]
    dmmk=[i]
  elif dmm==d2[i]:
    dmmk+=[i]
d2=[len(dmk),len(dmmk)]
if d1[0]>1 or d2[0]>1:
  print(n-d1[0]-d2[0])
else:
  print(n-max(d1[0]+d2[1],d1[1]+d2[0]))

Submission status: Wrong Answer

Solution code:
n = int(input())
v = list(map(int, input().split()))
even, odd = v[::2], v[1::2]

set_e = list(set(even))
set_o = list(set(odd))
set_e.sort(key=lambda x: set_e.count(x))
set_o.sort(key=lambda x: set_o.count(x))
e1, o1 = set_e[0], set_o[0]
ce1, co1 = even.count(e1), odd.count(o1)

if e1 != o1:
    a, b = even.count(e1), odd.count(o1)
    print(n-a-b)
    exit()
if len(set_o) == 1 and len(set_e) == 1:
    print(len(even))
    exit()
if len(set_o) == 1:
    e2 = set_e[1]
    a = even.count(e2)
    print(len(even)-a)
    exit()
if len(set_e) == 1:
    o2 = set_o[1]
    a = odd.count(o2)
    print(len(odd)-a)
    exit()

e2, o2 = set_e[1], set_o[1]
ce2, co2 = even.count(e2), odd.count(o2)

print(min(n-ce1-co2, n-ce2-co1))

Submission status: Wrong Answer

Solution code:
import collections


def split_even_odd_by_index(target_list):
    odd = []
    even = []
    for i in range(len(target_list)):
        if i % 2 == 0:
            odd.append(target_list[i])
        else:
            even.append(target_list[i])

    return [even, odd]


if __name__ == '__main__':
    n = int(input())
    number_list = list(map(int, input().split()))
    split_list = split_even_odd_by_index(number_list)
    even_list = split_list[0]
    odd_list = split_list[1]

    even_dic = collections.Counter(even_list).most_common()
    odd_dic = collections.Counter(odd_list).most_common()

    even_first = even_dic[0]
    if len(even_dic) != 1:
        even_second = even_dic[1]
    else:
        even_second = (0, 0)

    odd_first = odd_dic[0]

    if len(odd_dic) != 1:
        odd_second = odd_dic[1]
    else:
        odd_second = (0, 0)

    if even_first[0] != odd_first[0]:
        print(len(even_list) - even_first[1] + len(odd_list) - odd_first[1])
    else:
        print(max(len(even_list) - even_first[1] + len(odd_list) - odd_second[1], len(even_list) - even_second[1] + len(odd_list) - odd_first[1]))

Submission status: Wrong Answer

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

v_odd = [vs[2 * i] for i in range(n // 2 + n % 2)]
v_even = [vs[2 * i + 1] for i in range(n // 2)]

d_odd = {}
d_even = {}

for vo in v_odd:
    if vo in d_odd:
        d_odd[vo] += 1
    else:
        d_odd[vo] = 1

for ve in v_even:
    if ve in d_even:
        d_even[ve] += 1
    else:
        d_even[ve] = 1

so = -1
se = -1
num_so = 0
num_se = 0
num_so_prime = 0
num_se_prime = 0

for vo, num_vo in d_odd.items():
    if num_so < num_vo:
        num_so_prime = num_so
        so = vo
        num_so = num_vo

for ve, num_ve in d_even.items():
    if num_se < num_ve:
        num_se_prime = num_se
        se = ve
        num_se = num_ve

if so != se:
    print(n - num_so - num_se)
else:
    tmp_o = 10 ** 10
    tmp_e = 10 ** 10
    if len(d_odd) > 1:
        tmp0 = n - num_so_prime - num_se
    if len(d_even) > 1:
        tmp1 = n - num_se_prime - num_so
    ans = min(tmp_o, tmp_e)
    if len(d_odd) == 1 and len(d_even) == 1:
        ans = n // 2
    print(ans)

Submission status: Wrong Answer

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

v_odd = [vs[2 * i] for i in range(n // 2 + n % 2)]
v_even = [vs[2 * i + 1] for i in range(n // 2)]

d_odd = {}
d_even = {}

for vo in v_odd:
    if vo in d_odd:
        d_odd[vo] += 1
    else:
        d_odd[vo] = 1

for ve in v_even:
    if ve in d_even:
        d_even[ve] += 1
    else:
        d_even[ve] = 1

so = -1
se = -1
num_so = 0
num_se = 0
num_so_prime = 0
num_se_prime = 0

for vo, num_vo in d_odd.items():
    if num_so < num_vo:
        num_so_prime = num_so
        so = vo
        num_so = num_vo

for ve, num_ve in d_even.items():
    if num_se < num_ve:
        num_se_prime = num_se
        se = ve
        num_se = num_ve

if so != se:
    print(n - num_so - num_se)
else:
    print(min(n - num_se_prime - num_so, n - num_so_prime - num_se))

Submission status: Wrong Answer

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

v_odd = [vs[2 * i] for i in range(n // 2 + n % 2)]
v_even = [vs[2 * i + 1] for i in range(n // 2)]

d_odd = {}
d_even = {}

for vo in v_odd:
    if vo in d_odd:
        d_odd[vo] += 1
    else:
        d_odd[vo] = 1

for ve in v_even:
    if ve in d_even:
        d_even[ve] += 1
    else:
        d_even[ve] = 1

so = -1
se = -1
num_so = 0
num_se = 0
num_so_prime = -1
num_se_prime = -1

for vo, num_vo in d_odd.items():
    if num_so < num_vo:
        num_so_prime = num_so
        so = vo
        num_so = num_vo

for ve, num_ve in d_even.items():
    if num_se < num_ve:
        num_se_prime = num_se
        se = ve
        num_se = num_ve

if so != se:
    print(n - num_so - num_se)
else:
    print(min(n - num_se_prime - num_so, n - num_so_prime - num_se))

Submission status: Wrong Answer

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

v_odd = [vs[2 * i] for i in range(n // 2 + n % 2)]
v_even = [vs[2 * i + 1] for i in range(n // 2)]

d_odd = {}
d_even = {}

for vo in v_odd:
    if vo in d_odd:
        d_odd[vo] += 1
    else:
        d_odd[vo] = 1

for ve in v_even:
    if ve in d_even:
        d_even[ve] += 1
    else:
        d_even[ve] = 1

so = -1
se = -1
num_so = 0
num_se = 0
num_so_prime = 0
num_se_prime = 0

for vo, num_vo in d_odd.items():
    if num_so < num_vo:
        num_so_prime = num_so
        so = vo
        num_so = num_vo

for ve, num_ve in d_even.items():
    if num_se < num_ve:
        num_se_prime = num_se
        se = ve
        num_se = num_ve

if so != se:
    print(n - num_so - num_se)
else:
    if num_so_prime == 0:
        print(num_se)
    else:
        print(min(n - num_se_prime - num_so, n - num_so_prime - num_se))

Submission status: Wrong Answer

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

v_odd = [vs[2 * i] for i in range(n // 2 + n % 2)]
v_even = [vs[2 * i + 1] for i in range(n // 2)]

d_odd = {}
d_even = {}

for vo in v_odd:
    if vo in d_odd:
        d_odd[vo] += 1
    else:
        d_odd[vo] = 1

for ve in v_even:
    if ve in d_even:
        d_even[ve] += 1
    else:
        d_even[ve] = 1

so = -1
se = -1
num_so = 0
num_se = 0
num_so_prime = 0
num_se_prime = 0

for vo, num_vo in d_odd.items():
    if num_so < num_vo:
        num_so_prime = num_so
        so = vo
        num_so = num_vo

for ve, num_ve in d_even.items():
    if num_se < num_ve:
        num_se_prime = num_ve
        se = ve
        num_se = num_ve

if so != se:
    print(n - num_so - num_se)
else:
    if num_so_prime == 0:
        print(num_se)
    else:
        print(min(n - num_se_prime - num_so, n - num_so_prime - num_se))

Submission status: Wrong Answer

Solution code:
from operator import itemgetter
import collections
import math
import sys
import itertools
n = int(input())
vs = list(map(int,input().split()))
guusuu = vs[1::2]
kisuu = vs[0::2]
kisuucount = collections.Counter(kisuu).most_common(2)
guusuucount = collections.Counter(guusuu).most_common(2)
kisuu.append((0,0))
guusuu.append((0,0))
if guusuucount[0][0]!=kisuucount[0][0]:
    print(n-guusuucount[0][1]-kisuucount[0][1])
elif len(guusuucount)==len(kisuucount):
    print(len(guusuu))
else:
    print(min(n-guusuucount[1][1]-kisuucount[0][1],(n-guusuucount[0][1]-kisuucount[1][1])))

Submission status: Wrong Answer

Solution code:
from operator import itemgetter
import collections
import math
import sys
import itertools
n = int(input())
vs = list(map(int,input().split()))
guusuu = vs[1::2]
kisuu = vs[0::2]
kisuucount = collections.Counter(kisuu).most_common()
guusuucount = collections.Counter(guusuu).most_common()
if guusuucount[0][0]!=kisuucount[0][0]:
    print(n-guusuucount[0][1]-kisuucount[0][1])
elif len(guusuucount)==len(kisuucount):
    print(len(guusuu))
else:
    print(min(n-guusuucount[1][1]-kisuucount[0][1],(n-guusuucount[0][1]-kisuucount[1][1])))

Submission status: Wrong Answer

Solution code:
from operator import itemgetter
import collections
import math
import sys
import itertools
n = int(input())
vs = list(map(int,input().split()))
guusuu = vs[1::2]
kisuu = vs[0::2]
kisuucount = collections.Counter(kisuu).most_common()
guusuucount = collections.Counter(guusuu).most_common()
if guusuucount[0][0]!=kisuucount[0][0]:
    print(len(guusuu)-guusuucount[0][1]+len(kisuu)-kisuucount[0][1])
elif len(guusuucount)==len(kisuucount):
    print(len(guusuu))
else:
    print(min(n-guusuucount[1][1]-kisuucount[0][1],(n-guusuucount[0][1]-kisuucount[1][1])))

Submission status: Wrong Answer

Solution code:
import collections
import math
import sys
import itertools
n = int(input())
vs = list(map(int,input().split()))
guusuu = vs[1::2]
kisuu = vs[0::2]
kisuucount = collections.Counter(kisuu).most_common()
guusuucount = collections.Counter(guusuu).most_common()
if guusuucount[0][0]!=kisuucount[0][0]:
    print(len(guusuu)-guusuucount[0][1]+len(kisuu)-kisuucount[0][1])
elif len(guusuucount)==len(kisuucount):
    print(len(guusuu))
else:
    print(min(len(guusuu)-guusuucount[1][1]+len(kisuu)-kisuucount[0][1],(len(guusuu)-guusuucount[0][1]+len(kisuu)-kisuucount[1][1])))

Submission status: Wrong Answer

Solution code:
from operator import itemgetter
import collections
import math
import sys
import itertools
n = int(input())
vs = list(map(int,input().split()))
guusuu = vs[1::2]
kisuu = vs[0::2]
kisuucount = collections.Counter(kisuu).most_common()
guusuucount = collections.Counter(guusuu).most_common()
if guusuucount[0][0]!=kisuucount[0][0]:
    print(len(guusuu)-guusuucount[0][1]+len(kisuu)-kisuucount[0][1])
elif len(guusuucount)==len(kisuucount):
    print(len(guusuu))
else:
    print(min(len(guusuu)-guusuucount[1][1]+len(kisuu)-kisuucount[0][1],len(guusuu)-guusuucount[0][1]+len(kisuu)-kisuucount[1][1]))

Submission status: Wrong Answer

Solution code:
from collections import Counter as ct

n = int(input())
s = input().split()
a = ct(s[::2])
b = ct(s[1::2])
sa = sorted(a.items(), key=lambda x: -x[1])
sb = sorted(b.items(), key=lambda x: -x[1])
print(sa)
print(sb)

if sa[0][0] == sb[0][0]:
    if len(sa)*len(sb)==1:
        dt=n//2
    elif sa[0][1] - sa[1][1] < sb[0][1] - sb[1][1] or len(sb)==1:
        dt = sa[1][1] + sb[0][1]
    else:
        dt = sa[0][1] + sb[1][1]
else:
    dt = sa[0][1] + sb[0][1]
print(sum([x for x in a.values()]+[y for y in b.values()])-dt)

Submission status: Wrong Answer

Solution code:
import collections
n=int(input())
v=list(map(int,input().split()))
vo=v[0::2]
ve=v[1::2]
co=collections.Counter(vo)
ce=collections.Counter(ve)
cmo=co.most_common()
cme=ce.most_common()
ans=n-cmo[0][1]-cme[0][1]
if cmo[0][0]==cme[0][0]:
    if cmo[0][1]>cme[0][1]:
       if cmo[0][1]!=n//2:
           ans=n-cmo[0][1]-cme[1][1]
    else:
        if cme[0][1]!=n//2:
            ans=n-cmo[1][1]-cme[0][1]
print(ans)