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: Runtime Error

Solution code:
n=int(input())
V=list(map(int, input().split(" ")))
d1=[0 for i in range(10000)]
for i in V[::2]:
    d1[i]+=1
d2=[0 for i in range(10000)]
for i in V[1::2]:
    d2[i]+=1


if d1.index(max(d1)) == d2.index(max(d2)):
    if max(d1)>max(d2):
        d2[d2.index(max(d2))]=0
    else:
        d1[d1.index(max(d1))]=0

#print(d1[:5])
#print(d2[:5])
tmp1=n/2-max(d1)
tmp2=n/2-max(d2)
print(int(tmp1+tmp2))

Submission status: Runtime Error

Solution code:
n = int(input())
v = [int(_) for _ in input().split()]
cnt = 0
for i in range(n):
  if v[i] != v[i+2]:
    cnt += 1
print(cnt)

Submission status: Runtime Error

Solution code:
from statistics import mode

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

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

x1_count = v1.count(mode(v1))
x2_count = v2.count(mode(v2))

n = n//2
ans = (n - x1_count) + (n - x2_count)
print(ans)

Submission status: Runtime Error

Solution code:
import collections
N=list(map(int,input().split(" ")))
list_odd=N[::2]
list_even=N[1::2]
c_odd = collections.Counter(list_odd)
c_even = collections.Counter(list_even)
most_odd=c_odd.most_common()[0][1]
most_even=c_even.most_common()[0][1]
print(len(list_even)+len(list_odd)-most_even-most_odd)

Submission status: Runtime Error

Solution code:
from collections import Counter
from collections import deque

if __name__ == '__main__':
    n = int(input())
    vs0 = []
    vs1 = []
    for i,v in enumerate(map(int, input().split())):
        if i % 2 == 0:
            vs0.append(v)
        else:
            vs1.append(v)
    vs0 = deque(sorted(Counter(vs0).items(), key=lambda t: t[0]))
    vs1 = deque(sorted(Counter(vs1).items(), key=lambda t: t[0]))
    t0 = vs0.pop()
    t1 = vs1.pop()
    if t0[0] != t1[0]:
        vs0 = (t[1] for t in vs0)
        vs1 = (t[1] for t in vs1)
        print(sum(vs0) + sum(vs1))
    else:
        if len(vs1) == 0:
            if len(vs0) == 0:
                print(t1[1])
            else:
                vs0 = (t[1] for t in vs0)
                print(sum(vs0))
        elif len(vs0) == 0:
            vs1 = (t[1] for t in vs1)
            print(sum(vs1))
        else:
            t00 = vs0.pop()
            t11 = vs1.pop()
            a = t00 + t1
            b = t11 + t0
            print(sum(vs0) + sum(vs1) + (a if a < b else b))

Submission status: Runtime Error

Solution code:
n=int(input())
V=list(map(int, input().split(" ")))
d1=[0 for i in range(100000)]
for i in V[::2]:
    d1[i]+=1
d2=[0 for i in range(100000)]
for i in V[1::2]:
    d2[i]+=1


if d1.index(max(d1)) == d2.index(max(d2)):
    if max(d1)>max(d2):
        d2[d2.index(max(d2))]=0
    else:
        d1[d1.index(max(d1))]=0

#print(d1[:5])
#print(d2[:5])
tmp1=n/2-max(d1)
tmp2=n/2-max(d2)
print(int(tmp1+tmp2))

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
import math,string,itertools,fractions,heapq,collections,re,array,bisect
import numpy as np

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

odd = V[::2]
even = V[1:N:2]

odd_d = collections.Counter(odd)
even_d = collections.Counter(even)

if odd == even:
    print(len(odd))
    exit()

if len(odd_d.keys()) == 1 and len(even_d.keys()) == 1:
    if odd[0] == even[0]:
        ans =len(odd)
    else:
        ans = 0
else:
    for i,n in enumerate(odd_d.keys()):
        if i == 0:
            odd_ind = n
        elif i == 1:
            odd_ind2 = n
        else:
            break


    for n in even_d.keys():
        if i == 0:
            even_ind = n
        elif i == 1:
            even_ind2 = n
        else:
            break

    if odd_ind != even_ind:
        ans = (N//2 - odd_d[odd_ind]) + (N//2 - even_d[even_ind])
    else:
        if odd_ind > even_ind:
            ans = (N//2 - odd_d[odd_ind]) + (N//2 - even_d[even_ind2])
        else:
            ans = (N//2 - odd_d[odd_ind2]) + (N//2 - even_d[even_ind])
print(ans)

Submission status: Runtime Error

Solution code:
import collections

N=list(map(int,input().split(" ")))
list_odd=N[::2]
list_even=N[1::2]
c_odd = collections.Counter(list_odd)
c_even = collections.Counter(list_even)
most_odd=c_odd.most_common()[0][1]
most_even=c_even.most_common()[0][1]
print(len(list_even)+len(list_odd)-most_even-most_odd)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
import math,string,itertools,fractions,heapq,collections,re,array,bisect
import numpy as np

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

odd = V[::2]
even = V[1:N:2]

odd_d = collections.Counter(odd)
even_d = collections.Counter(even)

if odd == even:
    print(len(odd))
    exit()

if len(odd_d.keys()) == 1 and len(even_d.keys()) == 0:
    if odd[0] == even[0]:
        ans =len(odd)
    else:
        ans = 0
else:
    for i,n in enumerate(odd_d.keys()):
        if i == 0:
            odd_ind = n
        elif i == 1:
            odd_ind2 = n
        else:
            break


    for n in even_d.keys():
        if i == 0:
            even_ind = n
        elif i == 1:
            even_ind2 = n
        else:
            break

    if odd_ind != even_ind:
        ans = (N//2 - odd_d[odd_ind]) + (N//2 - even_d[even_ind])
    else:
        if odd_ind > even_ind:
            ans = (N//2 - odd_d[odd_ind]) + (N//2 - even_d[even_ind2])
        else:
            ans = (N//2 - odd_d[odd_ind2]) + (N//2 - even_d[even_ind])
print(ans)

Submission status: Runtime Error

Solution code:
int(input())
v = [int(x) for x in input().split()]
count = {x: v.count(x) for x in set(v)}
N = 0
while len(count) != 2:
    a = min(count.items(), key=lambda x: x[1])
    N += a[1]
    count.pop(a[0])
print(N)

Submission status: Runtime Error

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

num = set(v)

if len(num) == 1:
    print(n//2)
else:
    value = []
    num = list(num)
    for i in range(len(num)):
        value.append(v.count(num[i]))

    value.sort()

    if len(num) == 3:
        print(value[0])
    elif len(num) == 2:
        print(0)
    else:
        print(sum(value.sort[0:2]))

Submission status: Runtime Error

Solution code:
import collections

def inputN(typ=str):
    return map(typ, raw_input().split())


N = inputN(int)[0]
v = inputN(int)

col0 = collections.Counter(v[::2])
col1 = collections.Counter(v[1::2])
X0 = col0.most_common()
X1 = col1.most_common()
#print X0
#print X1

if X0[0][0] == X1[0][0]:
    if len(X0) == 1 and len(X1) == 1:
        k0 = X[0][1]
        k1 = 0
    elif len(X0) == 1:
        k0 = X0[0][1]
        k1 = X1[1][1]
    elif len(X1) == 1:
        k0 = X0[1][1]
        k1 = X1[0][1]
    elif X0[1][1] >= X1[1][1]:
        k0 = X0[1][1]
        k1 = X1[0][1]
    elif X0[1][1] < X1[1][1]:
        k0 = X0[0][1]
        k1 = X1[1][1]
else:
    k0 = X0[0][1]
    k1 = X1[0][1]

print N - k0 - k1

Submission status: Runtime Error

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

M0=[]
M1=[]

for i in range(n):
	if i%2==0: M0.append(A[i])
	else: M1.append(A[i])

C0=Counter(M0)
C1=Counter(M1)

l0=len(C0)
l1=len(C1)

ans=0
if l0>1:
	L=sorted(C1.items(), key=lambda x:x[1])
	ans=0
	for i in range(l0-1):
		ans+=L[i][1]

if l1>1:
	L=sorted(C1.items(), key=lambda x:x[1])
	ans=0
	for i in range(l1-1):
		ans+=L[i][1]

print ans

Submission status: Runtime Error

Solution code:
n = int(input())
v = set[[int(_) for _ input().split()]]
if len(v) == 1:
  print(n/2)
elif len(v) == 2:
  print(0)
else:
  print(n-len(v))

Submission status: Runtime Error

Solution code:
if __name__ == '__main__':                                                                                                                                                  n = int(input())
    vs = list(map(int, input().split()))

    even = vs[::2]
    odd = vs[1::2]

    from collections import Counter

    result = 0
    #evenの処理
    c = Counter(even)
    emode = c.most_common(1)[0][0]
    for i in range(len(even)):
        if even[i] != emode:
            result += 1

    c = Counter(odd)
    if c.most_common(1)[0][0] != emode:
        omode = c.most_common(1)[0][0]
    else:
        if len(c.most_common()) == 1:
            omode = -1
        else:
            omode = c.most_common(2)[0][0]


    for i in range(len(odd)):
        if odd[i] != omode:
            result += 1
if __name__ == '__main__':                                                                                                                                                  n = int(input())
    vs = list(map(int, input().split()))

    even = vs[::2]
    odd = vs[1::2]

    from collections import Counter

    result = 0
    #evenの処理
    c = Counter(even)
    emode = c.most_common(1)[0][0]
    for i in range(len(even)):
        if even[i] != emode:
            result += 1

    c = Counter(odd)
    if c.most_common(1)[0][0] != emode:
        omode = c.most_common(1)[0][0]
    else:
        if len(c.most_common()) == 1:
            omode = -1
        else:
            omode = c.most_common(2)[0][0]


    for i in range(len(odd)):
        if odd[i] != omode:
            result += 1
    print(result)

Submission status: Runtime Error

Solution code:
import collections

def inputN(typ=str):
    return map(typ, raw_input().split())


N = inputN(int)[0]
v = inputN(int)

col0 = collections.Counter(v[::2])
col1 = collections.Counter(v[1::2])
X0 = col0.most_common()
X1 = col1.most_common()
#print X0
#print X1

if X0[0][0] == X1[0][0]:
    if len(X0) == 1 and len(X1) == 1:
        k0 = X[0][1]
        k1 = 0
    elif len(X0) == 1:
        k0 = X0[0][1]
        k1 = X1[1][1]
    elif len(X1) == 1:
        k0 = X0[1][1]
        k1 = X1[0][1]
    elif X0[1][1] >= X1[1][1]:
        k0 = X0[0][1]
        k1 = X1[1][1]
    elif X0[1][1] < X1[1][1]:
        k0 = X0[1][1]
        k1 = X1[0][1]
else:
    k0 = X0[0][1]
    k1 = X1[0][1]

print N - k0 - k1

Submission status: Runtime Error

Solution code:
a = int(input())

b = list(map(int,input().split()))
d = max(b)
c = [0 for i in range(pow(10,5))]

for i in range(a):
    c[b[i]-1] += 1

one = max(c[0],c[1])
two = min(c[0],c[1])

for i in range(d):
    if c[i+2] >= one:
        two = one
        one = c[i+2]

print(a-one-two)

Submission status: Runtime Error

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

a = [0] * 100000
for i in v:
    a[i] += 1

A = sorted(a)
if A[-2] == 0:
    print(int(n/2))
else:
    print(len(v) - A[-1] - A[-2])