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:
n = int(input())
v = list(map(int, input().split()))
odd = {}
even = {}
change = 0
for i in range(n):
    if i % 2 == 0:
        if v[i] in even:
            even[v[i]] += 1
        else:
            even[v[i]] = 1
    else:
        if v[i] in odd:
            odd[v[i]] += 1
        else:
            odd[v[i]] = 1
if len(odd) == 1 and len(even) == 1:
    if odd == even:
        change = list(odd.values())[0]
elif len(odd) == 1 and len(even) != 1:
    max_v = max(even, key=even.get)
    change = int(n / 2) - even[max_v]
elif len(odd) != 1 and len(even) == 1:
    max_v = max(odd, key=odd.get)
    change = int(n / 2) - odd[max_v]
else:
    max_e = max(even, key=even.get)
    max_o = max(odd, key=odd.get)
    if max_e != max_o:
        for e in even:
            if e != max_e:
                change += even[e]
        for o in odd:
            if o != max_o:
                change += odd[o]
    else:
        if even[max_e] >= even[max_o]:
            for o in odd:
                if o != max_o:
                    change += 1
            change = n - even[max_e] - change
        else:
            for e in even:
                if e != max_e:
                    change += 1
            change = n - odd[max_o] - change
print(change)

Submission status: Wrong Answer

Solution code:
n = int(input())
v = list(map(int, input().split()))
odd = {}
even = {}
change = 0
for i in range(n):
    if i % 2 == 0:
        if v[i] in even:
            even[v[i]] += 1
        else:
            even[v[i]] = 1
    else:
        if v[i] in odd:
            odd[v[i]] += 1
        else:
            odd[v[i]] = 1

if len(odd) == 1 and len(even) == 1:
    if odd == even:
        change = list(odd.values())[0]
elif len(odd) == 1 and len(even) != 1:
    max_v = max(even, key=even.get)
    for e in even:
        if e != max_v:
            change += even[e]
    
elif len(odd) != 1 and len(even) == 1:
    max_v = max(odd, key=odd.get)
    for o in odd:
        if o != max_v:
            change += odd[o]
else:
    max_e = max(even, key=even.get)
    for e in even:
        if e != max_e:
            change += even[e]
    max_o = max(odd, key=odd.get)
    for o in odd:
        if o != max_o:
            change += odd[o]
print(change)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
v = list(map(int, input().split()))
c1 = Counter(v[::2])
c2 = Counter(v[1::2])
s1 = sorted(c1.items(), key=lambda x: x[1])
s2 = sorted(c2.items(), key=lambda x: x[1])
if s1[0][0] != s2[0][0]:
    print(n - s1[0][1] - s2[0][1])
else:
    if len(s1) == 1 and len(s1) == 1:
        ans = min(n - s1[0][1], n - s2[0][1])
    elif len(s1) == 1:
        ans = n - s1[0][1] - s2[1][1]
    elif len(s2) == 1:
        ans = n - s1[1][1] - s2[0][1]
    else:
        ans = min(n - s1[0][1] - s2[1][1], n - s1[1][1] - s2[0][1])
    print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
v = list(map(int, input().split()))
c1 = Counter(v[::2])
c2 = Counter(v[1::2])
s1 = sorted(c1.items(), key=lambda x: x[1])
s2 = sorted(c2.items(), key=lambda x: x[1])
if s1[0][0] != s2[0][0]:
    print(n - s1[0][1] - s2[0][1])
else:
    if len(s1) == 1 and len(s1) == 1:
        ans = max(n - s1[0][1], n - s2[0][1])
    elif len(s1) == 1:
        ans = n - s1[0][1] - s2[1][1]
    elif len(s2) == 1:
        ans = n - s1[1][1] - s2[0][1]
    else:
        ans = max(n - s1[0][1] - s2[1][1], n - s1[1][1] - s2[0][1])
    print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
MAX = 10**5 + 5
cnt = []
for k in range(2):
  cnt.append([0]*MAX)

for k in range(2):
  for i in range(k, n, 2):
     cnt[k][a[i]] += 1

print(n - max(cnt[0]) - max(cnt[1]))

Submission status: Wrong Answer

Solution code:
import sys
from collections import Counter


def main():
    n = int(input())
    values = list(map(int, input().split()))
    a = [v for i, v in enumerate(values) if i % 2 == 0]
    b = [v for i, v in enumerate(values) if i % 2 == 1]
    ac = list(Counter(a).items())
    bc = list(Counter(b).items())
    for i in range(min(len(ac), len(bc))):
        if ac[i][0] != bc[i][0]:
            print(n - ac[i][1] - bc[i][1])
        elif i+1 < min(len(ac), len(bc)):
            print(n - ac[i][1] - (max(bc[i + 1][1], ac[i + 1][1])))
        else:
            print(len(bc))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
from collections import Counter


def main():
    n = int(input())
    values = list(map(int, input().split()))
    a = [v for i, v in enumerate(values) if i % 2 == 0]
    b = [v for i, v in enumerate(values) if i % 2 == 1]
    ac = list(Counter(a).items())
    bc = list(Counter(b).items())
    for i in range(min(len(ac), len(bc))):
        if ac[i][0] != bc[i][0]:
            print(n - ac[i][1] - bc[i][1])
        elif i+1 < min(len(ac), len(bc)):
            print(n - ac[i][1] - (max(bc[i + 1][1], ac[i + 1][1])))
        else:
            print(n//2)


        
    






if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
iipt=lambda:int(input())
miipt=lambda:map(int,input().split(" "))
o=[0]*112345
e=[0]*112345
n=iipt()
A=miipt()
for i,a in enumerate(A):
    if i%2:
        o[a]+=1
    else:
        e[a]+=1
om=-1,0
om2=-1,0
em=-1,0
em2=-1,0
for i,v in enumerate(o):
    if v>=om[1]:
        om2=om
        om=i,v
for i,v in enumerate(e):
    if v>=em[1]:
        em2=em
        em=i,v
if om[0]==em[0]:
    print(max(n-om2[1]-em[1],n-om[1]-em2[1]))
else:
    print(n-om[1]-em[1])

Submission status: Wrong Answer

Solution code:
import collections
import numpy as np

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

#n = 4
npv = np.array( v, dtype=np.int32)
#npv = np.array( [3,1,3,2], dtype=np.int32)
npv_dic = {}
npv_dic['even'] = npv[0::2]
npv_dic['odd']  = npv[1::2]

#print('n = ', n)
#print('npv = ', npv)
#print('npv_dic[\'even\'] = ', npv_dic['even'])
#print('npv_dic[\'odd\']  = ', npv_dic['odd'])

dict0 = collections.Counter(npv_dic['even'])
dict1 = collections.Counter(npv_dic['odd'])

list0 = list(dict0.items())
list1 = list(dict1.items())

list0.sort(key= lambda x:x[1], reverse=True)
list1.sort(key= lambda x:x[1], reverse=True)

if list0[0][0] == list1[0][0]:
    if list0[0][1] > list1[0][1]:
        del list1[0]
    else:
        del list0[0]

if list0.__len__() != 0:
    change0 = n//2 - list0[0][1]
else:
    change0 = n//2
change1 = n//2 - list1[0][1]
#print('change:', change0, change1)

print(change0 + change1)

Submission status: Wrong Answer

Solution code:
import collections
import numpy as np

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

#n = 4
npv = np.array( v, dtype=np.int32)
#npv = np.array( [3,1,3,2], dtype=np.int32)
npv_dic = {}
npv_dic['even'] = npv[0::2]
npv_dic['odd']  = npv[1::2]

#print('n = ', n)
#print('npv = ', npv)
#print('npv_dic[\'even\'] = ', npv_dic['even'])
#print('npv_dic[\'odd\']  = ', npv_dic['odd'])

dict0 = collections.Counter(npv_dic['even'])
dict1 = collections.Counter(npv_dic['odd'])

list0 = list(dict0.items())
list1 = list(dict1.items())

list0.sort(key= lambda x:x[1], reverse=True)
list1.sort(key= lambda x:x[1], reverse=True)

if list0[0][0] == list1[0][0]:
    if list0[0][1] > list1[0][1]:
        del list1[0]
    else:
        del list0[0]

if list0.__len__() != 0:
    change0 = n//2 - list0[0][1]
else:
    change0 = n//2
change1 = n//2 - list1[0][1]
#print('change:', change0, change1)

print(change0 + change1)

Submission status: Wrong Answer

Solution code:
import collections
import numpy as np

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

#n = 4
#npv = np.array( v, dtype=np.int32)
npv = np.array( [3,1,3,2], dtype=np.int32)
npv_dic = {}
npv_dic['even'] = npv[0::2]
npv_dic['odd']  = npv[1::2]

#print('n = ', n)
#print('npv = ', npv)
#print('npv_dic[\'even\'] = ', npv_dic['even'])
#print('npv_dic[\'odd\']  = ', npv_dic['odd'])

dict0 = collections.Counter(npv_dic['even'])
dict1 = collections.Counter(npv_dic['odd'])

list0 = list(dict0.items())
list1 = list(dict1.items())

list0.sort(key= lambda x:x[1], reverse=True)
list1.sort(key= lambda x:x[1], reverse=True)

if list0[0][0] == list1[0][0]:
    if list0[0][1] > list1[0][1]:
        del list1[0]
    else:
        del list0[0]

change0 = n//2 - list0[0][1]
change1 = n//2 - list1[0][1]
#print('change:', change0, change1)

print(change0 + change1)

Submission status: Wrong Answer

Solution code:
#!/bin/python3

import math
import os
import random
import re
import sys

N=int(input())
A=list(map(int,input().strip().split(' ')))

odd={}
even={}
num_odd=0
for i in range(0,len(A),2):
    
    if A[i] in odd:
        odd[A[i]]+=1
    else:
        odd[A[i]]=1

for i in range(1,len(A),2):
    if A[i] in even:
        even[A[i]]+=1
    else:
        even[A[i]]=1

ans1=max(odd.values())
ans2=max(even.values())
ans=len(A)-ans1-ans2
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
d = [{}, {}]
d1v = [0, 0]
d2v = [0, 0]
d1k = [None, None]
d2k = [None, None]

W = input().split()
ans = 0

for i, v in enumerate(W):
    if v not in d[i%2]:
        d[i%2][v] = 0
    d[i%2][v] += 1
    if d1v[i%2] < d[i%2][v]:
        d2v[i%2] = d1v[i%2]
        d2k[i%2] = d1k[i%2]
        d1v[i%2] = d[i%2][v]
        d1k[i%2] = v
    elif d2v[i%2] < d[i%2][v]:
        d2v[i%2] = d[i%2][v]
        d2k[i%2] = v

if(d[0]==d[1]):
    ans = N//2
else:
    if(d1k[0] != d1k[1]):
        ans = N - sum(d1v)
    else:
        ans = min(N - d1v[0] - d2v[1], N - d1v[1] - d2v[0])

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
d = [{}, {}]
d1v = [0, 0]
d2v = [0, 0]
d1k = [None, None]
d2k = [None, None]

W = input().split()
ans = 0

for i, v in enumerate(W):
    if v not in d[i%2]:
        d[i%2][v] = 0
    d[i%2][v] += 1
    if d1v[i%2] < d[i%2][v]:
        d1v[i%2] = d[i%2][v]
        d1k[i%2] = v
    elif d2v[i%2] < d[i%2][v]:
        d2v[i%2] = d[i%2][v]
        d2k[i%2] = v

if(d[0]==d[1]):
    ans = N//2
else:
    if(d1k[0] != d1k[1]):
        ans = N - sum(d1v)
    else:
        ans = min(N - d1v[0] - d2v[1], N - d1v[1] - d2v[0])

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter


def main():
    n = int(input())
    v = [int(i) for i in input().split()]
    ans = 0
    odd = Counter(v[1::2])
    even = Counter(v[::2])
    odd_mosts = odd.most_common(2)
    even_mosts = even.most_common(2)
    if odd_mosts[0][0] == even_mosts[0][0]:
        if len(odd) == len(even) == 1:
            ans = n//2
        else:
            ans_sel = []
            ans_sel.append(n//2-odd_mosts[0][1]+n//2-even_mosts[1][1])
            ans_sel.append(n//2-odd_mosts[1][1]+n//2-even_mosts[0][1])
            ans = min(ans_sel)
    else:
        ans+=(n//2-odd_mosts[0][1])
        ans+=(n//2-even_mosts[0][1])
    print(ans)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

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

v_odd = []
v_even = []

for i in range(n//2):
    v_odd.append(v[i*2])
    v_even.append(v[i*2+1])

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

for x in v_odd:
    d_odd[x] += 1
for x in v_even:
    d_even[x] += 1

l_odd = list(d_odd.values())
l_even = list(d_even.values())
item_odd = list(d_odd)
item_even = list(d_even)

max_odd = max(l_odd)
max_even = max(l_even)
max_odd_l, max_even_l = [], []

for i,x in enumerate(l_odd):
    if x == max_odd:
        max_odd_l.append(i)

for i,x in enumerate(l_even):
    if x == max_even:
        max_even_l.append(i)

if len(max_odd_l) == 1 and len(max_even_l) == 1:
    if item_odd[max_odd_l[0]] == item_even[max_even_l[0]]:
        if max_odd > max_even:
            l_even.pop(max_even_l[0])
            if l_even:
                max_even = max(l_even)
            else:
                max_even = 0
        else:
            l_odd.pop(max_odd_l[0])
            if l_odd:
                max_odd = max(l_odd)
            else:
                max_odd = 0

print(n - max_odd - max_even)

Submission status: Wrong Answer

Solution code:
import numpy as np

n=int(input())
a=list(map(int,input().split()))
odd=[]
even=[]

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

odd=np.array(odd)  
even=np.array(even)
  
count1 = np.bincount(odd)
mode1 = np.argmax(count1)  
count2 = np.bincount(even)
mode2 = np.argmax(count2)    

c1=len(odd[odd!=mode1])
c2=len(even[even!=mode2])

print(c1+c2)

Submission status: Wrong Answer

Solution code:
n = int(input())
v = [int(t) for t in input().split()]


lvals = {}
rvals = {}

for i in range(0, n, 2):
    if v[i] in lvals:
        lvals[v[i]] += 1
    else:
        lvals[v[i]] = 1
    if v[i + 1] in rvals:
        rvals[v[i + 1]] += 1
    else:
        rvals[v[i + 1]] = 1

if len(lvals) == 1 and len(rvals) == 1:
    if v[0] == v[1]:
        print(int(n/2))
        exit(0)
    else:
        print(0)
        exit(0)

lvals = list(lvals.items())
lvals.sort(key=lambda i: i[1], reverse=True)
rvals = list(rvals.items())
rvals.sort(key=lambda i: i[1], reverse=True)

if lvals[0][0] != rvals[0][0]:
    lchange = n/2 - lvals[0][1]
    rchange = n/2 - rvals[0][1]
else:
    if len(lvals) == 1:
        lchange = n/2 - lvals[0][1]
        rchange = n/2 - rvals[1][1]
    elif len(rvals) == 1:
        lchange = n/2 - lvals[1][1]
        rchange = n/2 - rvals[0][1]
    elif lvals[0][1] + rvals[1][1] < lvals[1][1] + rvals[0][1]:
        lchange = n/2 - lvals[0][1]
        rchange = n/2 - rvals[1][1]
    else:
        lchange = n/2 - lvals[1][1]
        rchange = n/2 - rvals[0][1]

print(int(lchange + rchange))

Submission status: Wrong Answer

Solution code:
import collections

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

#n = 8
#v = [3,1,3,2,3,2,3,1]
v0 = [s for s in v[0::2]]
v1 = [s for s in v[1::2]]

#print(n)
#print(v)
#print(v0)
#print(v1)


d0 = len(sorted(set(v0)))
d1 = len(sorted(set(v1)))
#print(d0, d0 == 1)
#print(d1, d1 == 1)

dict0 = collections.Counter(v0)
dict1 = collections.Counter(v1)

max_num0 = max([dict0[d] for d in dict0])
max_num1 = max([dict1[d] for d in dict1])

#print('max_num:', max_num0, max_num1)
change0 = n//2 - max_num0
change1 = n//2 - max_num1
#print('change:', change0, change1)

print(change0 + change1)

Submission status: Wrong Answer

Solution code:
n = int(input())
v = [int(t) for t in input().split()]

result = float('inf')

for i in range(0, n, 2):
    num = 0
    lval = v[i]
    rval = v[i + 1]

    if lval == rval:
        continue

    for j in range(0, n, 2):
        if v[j] != lval:
            num += 1
        if v[j + 1] != rval:
            num += 1
        if num >= result:
            break
    else:
        result = num

if result == float('inf'):
    result = int(n / 2)

print(result)

Submission status: Wrong Answer

Solution code:
n = int(input())

Submission status: Wrong Answer

Solution code:
n=int(input())
v = list(map(int,input().split()))
od=[]
ev=[]
n_od=[]
n_ev=[]
k=int(n/2)

for i in range(k):
  od.append(v[2*i])
  ev.append(v[2*i-1])
  
od_set=set(od)
ev_set=set(ev)

for j in od_set:
  n_od.append([od.count(j),j])
for j in ev_set:
  n_ev.append([ev.count(j),j])
  
n_od.sort()
n_ev.sort()

if (len(od_set)==1) and (len(ev_set)==1):
  e=k
  o=0
elif (n_od[-1][0]==n_ev[-1][0]) and (n_od[-1][1]==n_ev[-1][1]):
  e=n_ev[-1][0]
  o=max(n_od[-2][0],n_ev[-2][0])
else:
  e=n_ev[-1][0]
  o=n_od[-1][0]

print(n-e-o)

Submission status: Wrong Answer

Solution code:
import sys

input = sys.stdin.readline
n = int(input())
a_list = list(map(int, input().split()))
if len(set(a_list)) == 1:
    print(int(n/2))
else:
    odd_dic = {}
    even_dic = {}
    for i in range(n):
        num = str(a_list[i])
        if i%2 == 0:
            if num in even_dic:
                even_dic[num] += 1
            else:
                even_dic[num] = 1
        else:
            if num in odd_dic:
                odd_dic[num] += 1
            else:
                odd_dic[num] = 1
    print(n-max(odd_dic.values())-max(even_dic.values()))

Submission status: Wrong Answer

Solution code:
N=int(input())
li = input().split()

a = 0
b = 0
c = 0
d = 0
e = 1
x = 0
y = 0
i = 0
j = 0
ans = 0
while a < N / 2:
    if li[a] != li[a + 2]:
        x += 1
    a += 1

while c < N:
    if li[c] == li[c + 1]:
        y += 1
    c += 2

while d < N:
    if N - d < 5:
        break
    else:
        if li[d] != li[d + 4]:
            i += 1
    d += 4

while e < N:
    if N - e < 5 :
        break
    else:
        if li[e] != li[e + 4]:
            b
            j += 1
    e += 4

if j > i:
    ans = j
else:
    ans = i

if x < y:
    ans += y
else:
    ans += x



ans += b

print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
li = input().split()

a = 0
b = 0
c = 0
d = 0
e = 1
x = 0
y = 0
ans = 0
while a < N / 2:
    if li[a] != li[a + 2]:
        x += 1
    a += 1

while c < N:
    if li[c] == li[c + 1]:
        y += 1
    c += 2

while d < N:
    if N - d < 5:
        break
    else:
        if li[d] != li[d + 4]:
            b += 1
    d += 4

while e < N:
    if N - e < 5 :
        break
    else:
        if li[e] != li[e + 4]:
            b += 1
    e += 4

if x < y:
    ans = y
else:
    ans = x

ans += b

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
from itertools import takewhile

n = int(input())
vvv = list(map(int, input().split()))
cnt1 = Counter(vvv[0::2])
cnt2 = Counter(vvv[1::2])
mc1 = cnt1.most_common()
mc2 = cnt2.most_common()
mcs1 = list(takewhile(lambda x: x[1] == mc1[0][1], mc1))
mcs2 = list(takewhile(lambda x: x[1] == mc2[0][1], mc2))
print(mc1, mc2, mcs1, mcs2)
if len(mcs1) == len(mcs2) and mcs1[0][0] == mcs2[0][0]:
    if len(mc1) > 1:
        if len(mc2) > 1:
            print(min(n - mc1[0][1] - mc2[1][1], n - mc1[1][1] - mc2[0][1]))
        else:
            print(min(n - mc1[0][1], n - mc1[1][1] - mc2[0][1]))
    else:
        if len(mc2) > 1:
            print(min(n - mc1[0][1] - mc2[1][1], n - mc2[0][1]))
        else:
            print(min(n - mc1[0][1], n - mc2[0][1]))
else:
    print(n - mc1[0][1] - mc2[0][1])

Submission status: Wrong Answer

Solution code:
from collections import Counter
from itertools import takewhile

n = int(input())
vvv = list(map(int, input().split()))
cnt1 = Counter(vvv[0::2])
cnt2 = Counter(vvv[1::2])
mc1 = cnt1.most_common()
mc2 = cnt2.most_common()
mcs1 = list(takewhile(lambda x: x[1] == mc1[0][1], mc1))
mcs2 = list(takewhile(lambda x: x[1] == mc2[0][1], mc2))
if len(mcs1) == len(mcs2) and mcs1[0] == mcs2[0]:
    print(n - mc1[0][1])
else:
    print(n - cnt1.most_common()[0][1] - cnt2.most_common()[0][1])

Submission status: Wrong Answer

Solution code:
from copy import *
n=int(input())
arr=list(map(int,input().split()))
arr1=[]
arr2=[]
for i in range(1,100001):
	arr1.append([0,i])
	arr2.append([0,i])

for i in range(0,n,2):
	arr1[arr[i]-1][0]+=1
#arr1.sort()
#print(arr1[-1])
for i in range(1,n,2):
	arr2[arr[i]-1][0]+=1
arr1.sort(reverse=True)
arr2.sort(reverse=True)
#print(arr1[-1],arr2[-1])
if(arr1[0][1]==arr2[0][1]):
	print(min(n-arr1[0][0]-arr2[1][0],n-arr1[1][0]-arr2[0][0]))	
else:
	print(n-arr1[-1][0]-arr2[-1][0])

Submission status: Wrong Answer

Solution code:
from copy import *
n=int(input())
arr=list(map(int,input().split()))
arr1=[]
arr2=[]
for i in range(1,100001):
	arr1.append([0,i])
	arr2.append([0,i])

for i in range(0,n,2):
	arr1[arr[i]-1][0]+=1
#arr1.sort()
#print(arr1[-1])
for i in range(1,n,2):
	arr2[arr[i]-1][0]+=1
arr1.sort()
arr2.sort()
#print(arr1[-1],arr2[-1])
if(arr1[-1][1]==arr2[-1][1]):
	if(arr1[-1][0]>arr2[-1][0]):
		print(n-arr1[-1][0]-arr2[-2][0])
	else:
		print(n-arr2[-1][0]-arr1[-2][0])
else:
	print(n-arr1[-1][0]-arr2[-1][0])

Submission status: Wrong Answer

Solution code:
from collections import Counter

n = int(input())
vvv = list(map(int, input().split()))
cnt1 = Counter(vvv[::2])
cnt2 = Counter(vvv[1::2])
print(n - cnt1.most_common()[0][1] - cnt2.most_common()[0][1])

Submission status: Wrong Answer

Solution code:
#! /usr/bin/python
from collections import Counter
N = int(input())
V = list(map(int, input().split()))
#N = 4
#V = list(map(int, "3 1 3 2".split()))


def func(l, aa):
    counter = Counter(l)
    if counter[aa] == 0:
        c, count = counter.most_common()[0]
    else:
        c, count = counter.most_common()[1]
    return (c, len(l) - count)


if len(set(V)) == 1:
    print(N // 2)
else:
    c, count = func(V[::2], -1)
    c2, count2 = func(V[1::2], c)
    print(count + count2)

Submission status: Wrong Answer

Solution code:
#! /usr/bin/python
from collections import Counter
N = int(input())
V = list(map(int, input().split()))
#N = 4
#V = list(map(int, "105 119 105 119 105 119".split()))


def func(l, aa):
    counter = Counter(l)
    if counter[aa] == 0:
        c, count = counter.most_common()[0]
    else:
        c, count = counter.most_common()[1]
    print(l, len(l) - count)
    return (c, len(l) - count)


if len(set(V)) == 1:
    print(N // 2)
else:
    c, count = func(V[::2], -1)
    c2, count2 = func(V[1::2], c)
    print(count + count2)

Submission status: Wrong Answer

Solution code:
#! /usr/bin/python
from collections import Counter
N = int(input())
V = list(map(int, input().split()))
#N = 4
#V = list(map(int, "1 1 1 1 1 1".split()))


def func(l):
    if len(l) == 0:
        return 0
    nanka = Counter(l).most_common()[0][1]
    return len(l) - nanka


if len(set(V)) == 1:
    print(N // 2)
else:
    print(func(V[::2]) + func(V[1::2]))

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
V = list(map(int, input().split()))
c1 = Counter(V[::2])
c2 = Counter(V[1::2])
c1[0] = 0
c2[0] = 0
(x, cx), (_, cxx) = c1.most_common(2)
(y, cy), (_, cyy) = c2.most_common(2)
if x == y:
    print(n - max(cx + cyy, cy + cxx))
else:
    print(n - cx + cy)

Submission status: Wrong Answer

Solution code:
import numpy as np
n = int(input())
v = np.array(list(map(int,input().split())))
v1 = v.reshape(n//2,2)[:,0]
v2 = v.reshape(n//2,2)[:,1]
v1_unique = np.unique(v1)
v2_unique = np.unique(v2)
# 先に数字次に個数（新居まで）
maxs1 = [0,0,0,0]
ma = 0
for i in range(v1_unique.shape[0]):
    num = np.sum(v1 == v1_unique[i])
    if(num > maxs1[1]):
        maxs1[0] = v1_unique[i]
        maxs1[1] = num
    elif(num > maxs1[3]):
        maxs1[2] = v1_unique[i]
        maxs1[3] = num
maxs2 = [0,0,0,0]
for i in range(v2_unique.shape[0]):
    num = np.sum(v2 == v2_unique[i])
    if(num > maxs2[1]):
        maxs2[0] = v2_unique[i]
        maxs2[1] = num
    elif(num > maxs2[3]):
        maxs2[2] = v2_unique[i]
        maxs2[3] = num
if(maxs1[0] != maxs2[0]):
    ma = n - maxs1[1] - maxs2[1]
elif((maxs1[1] + maxs2[3]) > (maxs2[1]+ maxs1[3])):
    ma = n - maxs1[1] - maxs2[3]
else:
    ma = n - maxs2[1] - maxs1[3]
print(ma)

Submission status: Wrong Answer

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

eve = {}
odd = {}

for i in range(len(vs)):
    if i % 2 == 0:
        if vs[i] in eve:
            eve[vs[i]] += 1
        else:
            eve[vs[i]] = 1
    else:
        if vs[i] in odd:
            odd[vs[i]] += 1
        else:
            odd[vs[i]] = 1

es = sorted(eve.items(), key=lambda x: -x[1])
os = sorted(odd.items(), key=lambda x: -x[1])

if es[0][0] == os[0][0]:
    if es[0][1] > os[0][1]:
        del es[0]
        if len(os) > 1 :
            del os[1]
    elif es[0][1] < os[0][1]:
        del os[0]
        if len(es) > 1 :
            del es[1]
    else:
        if len(es) == 1 and len(os) == 1:
            del os[0]
        elif len(es) == 1 and len(os) != 1:
            del es[0]
            del os[1]
        elif len(es) != 1 and len(os) == 1:
            del es[1]
            del os[0]
        else:
            if es[1][1] < os[1][1]:
                del es[1]
                del os[0]
            else:
                del es[0]
                del os[1]
else:
    del os[0]
    del es[0]

trans = 0

for i in range(len(es)):
    trans += es[i][1]
for i in range(len(os)):
    trans += os[i][1]

print(trans)

Submission status: Wrong Answer

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

eve = {}
odd = {}

for i in range(len(vs)):
    if i % 2 == 0:
        if vs[i] in eve:
            eve[vs[i]] += 1
        else:
            eve[vs[i]] = 1
    else:
        if vs[i] in odd:
            odd[vs[i]] += 1
        else:
            odd[vs[i]] = 1

es = sorted(eve.items(), key=lambda x: -x[1])
os = sorted(odd.items(), key=lambda x: -x[1])

if es[0][0] == os[0][0]:
    if es[0][1] > os[0][1]:
        del es[0]
        if len(os) > 1 :
            del os[1]
    elif es[0][1] < os[0][1]:
        del os[0]
        if len(es) > 1 :
            del es[1]
    else:
        if len(es) == 1 and len(os) != 1:
            del es[0]
            del os[1]
        elif len(es) != 1 and len(os) == 1:
            del es[1]
            del os[0]
        elif len(es) == 1 and len(os) == 1:
            del os[0]
        else:
            if es[1][1] < os[1][1]:
                del es[0]
                del os[1]
            else:
                del es[0]
                del os[1]



else:
    del os[0]
    del es[0]

trans = 0

for i in range(len(es)):
    trans += es[i][1]
for i in range(len(os)):
    trans += os[i][1]

print(trans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input().strip())
vs = [int(i) for i in input().split(' ')]
vs1 = vs[::2]
vs2 = vs[1::2]
a = Counter(vs1).most_common()
b = Counter(vs2).most_common()

if a[0][0] != b[0][0]:
    print(n - a[0][1] - b[0][1])
else:
    candidates = []
    candidates.append(n//2)
    if len(a) != 1:
        candidates.append(n - a[1][1] - b[0][1])
    if len(b) != 1:
        candidates.append(n - a[0][1] - b[1][1])
    print(min(candidates))

Submission status: Wrong Answer

Solution code:
from collections import Counter
import sys
N=int(input())
v=[int(i) for i in input().split()]
A=[]
B=[]
for i in range(N):
    if i%2==0:
        A.append(v[i])
    else:
        B.append(v[i])
S=Counter(A).most_common(2)+[(0,-1)]
T=Counter(B).most_common(2)+[(0,-1)]
if S[0][0]!=T[0][0]:
    print(N-S[0][1]-T[0][1])
    sys.exit()
a=S[0][1]+T[1][1]
b=S[1][1]+T[0][1]
c=max(a,b)
print(N-c)

Submission status: Wrong Answer

Solution code:
from collections import Counter
import sys
N=int(input())
v=[int(i) for i in input().split()]
A=[]
B=[]
for i in range(N):
    if i%2==0:
        A.append(v[i])
    else:
        B.append(v[i])
S=Counter(A).most_common(2)+[(0,-N//2)]
T=Counter(B).most_common(2)+[(0,-N//2)]
if S[0][0]!=T[0][0]:
    print(N-S[0][1]-T[0][1])
    sys.exit()
a=S[0][1]+T[1][1]
b=S[1][1]+T[0][1]
c=max(a,b)
print(N-c)

Submission status: Wrong Answer

Solution code:
vs = [int(i) for i in input().strip()]
n = (len(vs) - 2)//2
def main(vs):
    if vs[0] != 1:
        print(-1)
        return -1
    if vs[-1] != 0:
        print(-1)
        return -1
    if vs[-2] != 1:
        print(-1)
        return -1
    for i in range(n):
        if vs[i+1] != vs[-2-i-1]:
            print(-1)
            return

    temp = 1
    for i in range(n+1 if len(vs) % 2 == 0 else n+2):
        print(1, temp+1)
        temp += 1
    temptemp = temp
    temp = 1
    for i in range(n):
        x = 1+n-i
        if vs[n-i] == 1:
            print(temptemp, temptemp+1)
            temp = temptemp
            temptemp += 1
        else:
            print(temp, temptemp+1) 
            temptemp += 1

main(vs)

Submission status: Wrong Answer

Solution code:
from collections import Counter
import sys
N=int(input())
v=[int(i) for i in input().split()]
A=[]
B=[]
for i in range(N):
    if i%2==0:
        A.append(v[i])
    else:
        B.append(v[i])
S=Counter(A).most_common(2)+[(0,-10**6)]
T=Counter(B).most_common(2)+[(0,-10**6)]
if S[0][0]!=T[0][0]:
    print(N-S[0][1]-T[0][1])
    sys.exit()
a=S[0][1]+T[1][1]
b=S[1][1]+T[0][1]
c=max(a,b)
print(N-c)

Submission status: Wrong Answer

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

eve = {}
odd = {}

for i in range(len(vs)):
    if i % 2 == 0:
        if vs[i] in eve:
            eve[vs[i]] += 1
        else:
            eve[vs[i]] = 1
    else:
        if vs[i] in odd:
            odd[vs[i]] += 1
        else:
            odd[vs[i]] = 1

es = sorted(eve.items(), key=lambda x: -x[1])
os = sorted(odd.items(), key=lambda x: -x[1])

trans = 0

if es[0][0] == os[0][0]:
    if es[0][1] > os[0][1]:
        del es[0]
        if(len(os) > 1):
            del os[1]
    else:
        del os[0]
        if(len(es) > 1):
            del es[1]
else:
    del os[0]
    del es[0]

for i in range(len(es)):
    trans += es[i][1]
for i in range(len(os)):
    trans += os[i][1]

print(trans)

Submission status: Wrong Answer

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

eve = {}
odd = {}

for i in range(len(vs)):
    if i % 2 == 0:
        if vs[i] in eve:
            eve[vs[i]] += 1
        else:
            eve[vs[i]] = 1
    else:
        if vs[i] in odd:
            odd[vs[i]] += 1
        else:
            odd[vs[i]] = 1

es = sorted(eve.items(), key=lambda x: -x[1])
os = sorted(odd.items(), key=lambda x: -x[1])

trans = 0

if es[0][0] == os[0][0]:
    print("equal")
    if es[0][1] > os[0][1]:
        del es[0]
        if(len(os) > 1):
            del os[1]
    else:
        del os[0]
        if(len(es) > 1):
            del es[1]
else:
    del os[0]
    del es[0]

for i in range(len(es)):
    trans += es[i][1]
for i in range(len(os)):
    trans += os[i][1]

print(trans)

Submission status: Wrong Answer

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

eve = {}
odd = {}

for i in range(len(vs)):
    if i % 2 == 0:
        if vs[i] in eve:
            eve[vs[i]] += 1
        else:
            eve[vs[i]] = 1
    else:
        if vs[i] in odd:
            odd[vs[i]] += 1
        else:
            odd[vs[i]] = 1

es = sorted(eve.items(), key=lambda x: -x[1])
os = sorted(odd.items(), key=lambda x: -x[1])

trans = 0

if es[0][0] == os[0][0]:
    if es[0][1] > os[0][1]:
        del es[0]
        if(len(os) > 1):
            del os[1]
    else:
        del os[0]
        if(len(es) > 1):
            del es[1]
else:
    del os[0]
    del es[0]

for i in range(1, len(es)):
    trans += es[0][1]
for i in range(1, len(os)):
    trans += os[0][1]

print(trans)