There are a lot of things which could be cut — trees, paper, "the rope". In this problem you are going to cut a sequence of integers.

There is a sequence of integers, which contains the equal number of even and odd numbers. Given a limited budget, you need to make maximum possible number of cuts such that each resulting segment will have the same number of odd and even integers.

Cuts separate a sequence to continuous (contiguous) segments. You may think about each cut as a break between two adjacent elements in a sequence. So after cutting each element belongs to exactly one segment. Say, $[4, 1, 2, 3, 4, 5, 4, 4, 5, 5]$ $\to$ two cuts $\to$ $[4, 1 | 2, 3, 4, 5 | 4, 4, 5, 5]$. On each segment the number of even elements should be equal to the number of odd elements.

The cost of the cut between $x$ and $y$ numbers is $|x - y|$ bitcoins. Find the maximum possible number of cuts that can be made while spending no more than $B$ bitcoins.


-----Input-----

First line of the input contains an integer $n$ ($2 \le n \le 100$) and an integer $B$ ($1 \le B \le 100$) — the number of elements in the sequence and the number of bitcoins you have.

Second line contains $n$ integers: $a_1$, $a_2$, ..., $a_n$ ($1 \le a_i \le 100$) — elements of the sequence, which contains the equal number of even and odd numbers


-----Output-----

Print the maximum possible number of cuts which can be made while spending no more than $B$ bitcoins.


-----Examples-----
Input
6 4
1 2 5 10 15 20

Output
1

Input
4 10
1 3 2 4

Output
0

Input
6 100
1 2 3 4 5 6

Output
2



-----Note-----

In the first sample the optimal answer is to split sequence between $2$ and $5$. Price of this cut is equal to $3$ bitcoins.

In the second sample it is not possible to make even one cut even with unlimited number of bitcoins.

In the third sample the sequence should be cut between $2$ and $3$, and between $4$ and $5$. The total price of the cuts is $1 + 1 = 2$ bitcoins.

Source: codeforces | Difficulty: EASY
Tags: Dynamic programming

Sorting

Greedy algorithms


Solutions:
from sys import *
from math import *
from bisect import *
(n, k) = map(int, stdin.readline().split())
a = list(map(int, stdin.readline().split()))
od = ev = 0
c = []
for i in range(n):
	if a[i] % 2 == 0:
		ev += 1
	else:
		od += 1
	if ev == od and i != n - 1:
		c.append(abs(a[i] - a[i + 1]))
c.sort()
ans = 0
for i in range(len(c)):
	if k == 0:
		break
	if k >= c[i]:
		k -= c[i]
		ans += 1
print(ans)


(_, B) = map(int, input().split())
arr = list(map(int, input().split()))
even = 0
odd = 0
costs = []
for (i, n) in enumerate(arr[:-1]):
	if n % 2 == 0:
		even += 1
	else:
		odd += 1
	if even == odd:
		costs.append(abs(arr[i] - arr[i + 1]))
costs.sort()
price = 0
ans = 0
for c in costs:
	if price + c <= B:
		price += c
		ans += 1
	else:
		break
print(ans)


(n, b) = map(int, input().split())
A = list(map(int, input().split()))
B = []
(o, e) = (0, 0)
if A[0] % 2 == 0:
	o += 1
else:
	e += 1
for i in range(1, n - 1):
	if A[i] % 2 == 0:
		o += 1
	else:
		e += 1
	if o == e:
		B.append(abs(A[i + 1] - A[i]))
B.sort()
i = 0
while i < len(B) and B[i] <= b:
	b -= B[i]
	i += 1
print(i)


(n, b) = map(int, input().split())
li = list(map(int, input().split()))
even_count = 0
odd_count = 0
si = list()
for j in range(len(li)):
	if li[j] % 2 == 0:
		even_count = even_count + 1
	else:
		odd_count = odd_count + 1
	if even_count == odd_count:
		if j + 1 < n:
			diff = abs(li[j + 1] - li[j])
			si.append(diff)
			even_count = 0
			odd_count = 0
su = 0
count = 0
si.sort()
for kt in si:
	su = su + kt
	if su <= b:
		count = count + 1
print(count)


(n, B) = list(map(int, input().split()))
A = [int(x) for x in input().split()]
(odd, even) = (0, 0)
cuts = []
for i in range(n - 1):
	if A[i] % 2 == 0:
		even += 1
	else:
		odd += 1
	if odd == even:
		cuts += [(abs(A[i] - A[i + 1]), i)]
cuts.sort()
result = 0
for (cost, _) in cuts:
	if cost <= B:
		B -= cost
		result += 1
print(result)


raw = input().split(' ')
n = int(raw[0])
b = int(raw[1])
nums = list(map(int, input().split(' ')))
even = 0
odd = 0
cuts = []
for i in range(n):
	if nums[i] % 2 == 0:
		even += 1
	else:
		odd += 1
	if even == odd and i + 1 < n:
		cuts += [abs(nums[i + 1] - nums[i])]
total = 0
cuts.sort()
for c in cuts:
	if c <= b:
		b -= c
		total += 1
	else:
		break
print(total)


import math
(n, b) = input().strip().split(' ')
(n, b) = [int(n), int(b)]
c = list(map(int, input().strip().split(' ')))
odd = 0
even = 0
if n == 2:
	for x in range(0, len(c)):
		if c[x] % 2 == 0:
			even += 1
		elif c[x] % 2 == 1:
			odd += 1
	if even == odd:
		print('0')
else:
	v = []
	x = 0
	ctr = 0
	while x < len(c):
		if c[x] % 2 == 0:
			ctr += -1
		elif c[x] % 2 == 1:
			ctr += 1
		if ctr == 0 and x % 2 == 1 and (x < len(c) - 1):
			v.append(int(math.fabs(c[x + 1] - c[x])))
			ctr = 0
		x += 1
	v.sort()
	if len(v) == 0:
		print('0')
	else:
		while sum(v) > b:
			v.pop()
		print(len(v))


(n, b) = map(int, input().split())
a = [int(i) for i in input().split()]
bl = [0] * n
ce = 0
co = 0
for i in range(n):
	if a[i] % 2 == 0:
		ce += 1
	else:
		co += 1
	if ce == co:
		bl[i] = True
	else:
		bl[i] = False
ans = []
for i in range(n - 1):
	if bl[i]:
		ans.append(abs(a[i] - a[i + 1]))
ans.sort()
c = 0
i = 0
while i < len(ans):
	b -= ans[i]
	if b < 0:
		break
	c += 1
	i += 1
print(c)


(n, b) = map(int, input().split())
v = list(map(int, input().split()))
costs = []
odds = 0
evens = 0
for i in range(n - 1):
	if v[i] % 2 == 0:
		evens += 1
	else:
		odds += 1
	if odds == evens and odds != 0 and (i != n - 1):
		costs.append(abs(v[i + 1] - v[i]))
		odds = 0
		evens = 0
count = 0
acc = 0
for cost in sorted(costs):
	if acc + cost <= b:
		count += 1
		acc = acc + cost
	else:
		break
print(count)


(n, B) = map(int, input().split())
l = list(map(int, input().split()))
if l[0] % 2 == 0:
	c = -1
else:
	c = 1
x = []
y = 0
for i in l[1:-1]:
	if i % 2 == 0:
		c -= 1
	else:
		c += 1
	if c == 0:
		x.append(abs(l[y + 2] - l[y + 1]))
	y += 1
x.sort()
ans = 0
for i in x:
	if B >= i:
		B -= i
		ans += 1
	else:
		break
print(ans)


import sys
(n, bitcoin) = map(int, sys.stdin.readline().split())
liste = list(map(int, sys.stdin.readline().split()))
possible = list()
seen = [[0, 0] for loop in range(n)]
i = 0
p = 0
for loop in range(n):
	if liste[loop] % 2 == 0:
		p += 1
	else:
		i += 1
	seen[loop][0] = p
	seen[loop][1] = i
if seen[n - 1][0] == seen[n - 1][1]:
	for loop in range(n - 1):
		if seen[loop][0] == seen[loop][1]:
			possible.append(abs(liste[loop] - liste[loop + 1]))
	possible.sort()
	somme = 0
	i = 0
	while somme < bitcoin and i < len(possible):
		somme += possible[i]
		i += 1
	if somme > bitcoin:
		i -= 1
	print(i)
else:
	print(0)


def solve(limit, rooms):
	(odd, even) = (0, 0)
	split = []
	for i in range(0, len(rooms) - 2, 2):
		if rooms[i] % 2:
			odd += 1
		else:
			even += 1
		if rooms[i + 1] % 2:
			odd += 1
		else:
			even += 1
		if odd == even and i != len(rooms) - 2:
			split.append(abs(rooms[i + 1] - rooms[i + 2]))
	split.sort()
	i = 0
	while i < len(split):
		if limit - split[i] >= 0:
			limit -= split[i]
			i += 1
		else:
			break
	print(i)
(n, m) = map(int, input().split())
rooms = list(map(int, input().split()))
solve(m, rooms)


import sys
input = sys.stdin.readline
(n, b) = map(int, input().split())
l = list(map(int, input().split()))
possible = []
s = 0
if l[0] % 2 == 0:
	s += 1
else:
	s -= 1
for i in range(1, n):
	if i % 2 == 0 and s == 0:
		possible.append(abs(l[i] - l[i - 1]))
	if l[i] % 2 == 0:
		s += 1
	else:
		s -= 1
possible.sort()
add = 0
c = 0
for i in possible:
	if add + i > b:
		break
	add += i
	c += 1
print(c)


(n, b) = input().split()
n = int(n)
b = int(b)
a = [int(x) for x in input().split()]
costs = []
odd_count = 0
even_count = 0
sum_cost = 0
for i in range(n - 1):
	if a[i] % 2 == 0:
		even_count += 1
	else:
		odd_count += 1
	if odd_count == even_count:
		cost = abs(a[i + 1] - a[i])
		costs += [cost]
		odd_count = 0
		even_count = 0
num_cuts = 0
costs.sort()
for i in costs:
	if sum_cost + i <= b:
		sum_cost += i
		num_cuts += 1
	else:
		break
print(num_cuts)


(qNum, bit) = input().split(' ')
qNum = int(qNum)
bit = int(bit)
num = [0 for i in range(qNum + 1)]
valor = [0 for i in range(qNum + 1)]
num = [int(v) for v in input().split()]
cont = 0
contV = 0
while cont < qNum:
	par = 0
	impar = 0
	while (par != impar or par == 0 or impar == 0) and cont < qNum:
		if num[cont] % 2 == 0:
			par = par + 1
		else:
			impar = impar + 1
		cont = cont + 1
	if cont < qNum:
		if num[cont - 1] > num[cont]:
			valor[contV] = num[cont - 1] - num[cont]
			contV = contV + 1
		else:
			valor[contV] = num[cont] - num[cont - 1]
			contV = contV + 1
nCortes = contV
certo = 0
maior = 0
while certo == 0 and nCortes > 0:
	soma = 0
	maior = 0
	for i in range(0, contV):
		soma = soma + valor[i]
	if soma <= bit:
		certo = 1
	if soma > bit:
		for j in range(0, contV):
			if valor[j] >= maior:
				maior = valor[j]
				pos = j
		valor[pos] = 0
		nCortes = nCortes - 1
print(nCortes)


import math
(n, B) = (int(x) for x in input().split())
a = [int(x) for x in input().split()]
razr = []
if n == 2:
	print(0)
else:
	count_chet = 0
	count_nechet = 0
	for i in range(0, n - 2):
		if a[i] % 2 == 0:
			count_chet += 1
		else:
			count_nechet += 1
		if count_chet == count_nechet:
			razr.append(math.fabs(a[i + 1] - a[i]))
	ans = 0
	razr = sorted(razr)
	sum = 0
	for i in range(len(razr)):
		sum += razr[i]
		if sum <= B:
			ans += 1
	print(ans)


(n, B) = map(int, input().split())
a = list(map(int, input().split()))
b = []
p = 0
for i in range(n - 1):
	if a[i] % 2 == 0:
		p += 1
	else:
		p -= 1
	if p == 0:
		b.append(abs(a[i] - a[i + 1]))
b.sort()
ans = 0
sum = 0
for i in range(len(b)):
	if sum + b[i] <= B:
		ans += 1
		sum += b[i]
print(ans)


l = [int(x) for x in input().split()]
n = [int(x) for x in input().split()]
od = 0
ev = 0
cut = 0
s = 0
m = []
for i in range(l[0] - 1):
	if n[i] % 2 == 0:
		ev += 1
	else:
		od += 1
	if ev == od:
		m.append(abs(n[i] - n[i + 1]))
		cut += 1
		s = s + abs(n[i] - n[i + 1])
if l[1] >= s:
	print(cut)
else:
	m.sort()
	for h in range(len(n)):
		s = s - m[len(m) - 1 - h]
		cut -= 1
		if l[1] >= s:
			break
	print(cut)


(n, b) = map(int, input().split())
arr = list(map(int, input().split()))
odd = 0
even = 0
cut = []
for i in range(n - 1):
	if arr[i] % 2 == 0:
		even += 1
	else:
		odd += 1
	if odd == even:
		cut.append(abs(arr[i + 1] - arr[i]))
cut.sort()
ans = 0
while b > 0 and cut:
	if b - cut[0] < 0:
		break
	b -= cut[0]
	cut.pop(0)
	ans += 1
print(ans)


import math
(n, B) = map(int, input().split())
a = [int(i) for i in input().split()]
odd = 0
even = 0
razr = []
for i in range(n - 2):
	if a[i] % 2 == 1:
		odd += 1
	else:
		even += 1
	if odd == even:
		razr.append(math.fabs(a[i] - a[i + 1]))
razr.sort()
sum = 0
c = 0
i = 0
while i < len(razr):
	sum += razr[i]
	if sum <= B:
		c += 1
	else:
		break
	i += 1
print(c)


(n, b) = map(int, input().split())
a = list(map(int, input().split()))
e = 0
o = 0
c = []
for i in range(len(a)):
	if a[i] % 2 == 0:
		e += 1
		if e == o:
			try:
				c.append(abs(a[i + 1] - a[i]))
			except:
				pass
	else:
		o += 1
		if e == o:
			try:
				c.append(abs(a[i + 1] - a[i]))
			except:
				pass
c = sorted(c)
if len(c) == 0:
	print(0)
	exit()
l = [c[0]]
for i in range(1, len(c)):
	l.append(l[-1] + c[i])
else:
	for i in range(len(l)):
		if l[i] > b:
			print(i)
			exit()
	print(len(c))


(n, B) = [int(x) for x in input().split()]
arr = [int(x) for x in input().split()]
poss_Splits = []
ps = 0
ptlan = 0
for i in range(n - 1):
	if arr[i] % 2 == 0:
		ps += 1
	else:
		ptlan += 1
	if ps == ptlan:
		poss_Splits.append((abs(arr[i] - arr[i + 1]), i))
poss_Splits = sorted(poss_Splits)
i = 0
while i < len(poss_Splits) and B >= poss_Splits[i][0]:
	B -= poss_Splits[i][0]
	i += 1
print(i)


(n, k) = map(int, input().split())
l = [list(map(int, input().split()))]
ans = 0
while True:
	cost = 100000
	indm = -1
	indl = -1
	for i in range(len(l)):
		lis = l[i]
		(eve, odd) = (0, 0)
		for j in range(len(lis)):
			if lis[j] % 2 == 0:
				eve += 1
			else:
				odd += 1
		(x, y) = (0, 0)
		minl = 10000000000
		ind = -1
		for j in range(len(lis) - 1):
			if lis[j] % 2 == 0:
				x += 1
			else:
				y += 1
			if x == y and eve - x == odd - y:
				prev = minl
				minl = min(minl, abs(lis[j] - lis[j + 1]))
				if prev != minl:
					ind = j
		if minl == 10000000000:
			continue
		elif cost > minl:
			cost = minl
			indm = ind
			indl = i
	if cost != 100000:
		i = indl
		j = indm
		i = l[i]
		l.remove(i)
		arr1 = []
		for j in range(indm + 1):
			arr1.append(i[j])
		arr2 = []
		for j in range(indm + 1, len(i)):
			arr2.append(i[j])
		l.append(arr1)
		l.append(arr2)
		if k >= cost:
			k -= cost
			ans += 1
		else:
			break
	else:
		break
print(ans)


(n, b) = map(int, input().split())
a = list(map(int, input().split()))
s = 0
ans = []
answ = 0
for i in range(n - 1):
	if a[i] % 2:
		s += 1
	else:
		s -= 1
	if s == 0:
		ans.append(abs(a[i + 1] - a[i]))
ans.sort()
for i in ans:
	b -= i
	if b >= 0:
		answ += 1
	else:
		break
print(answ)


(n, b) = map(int, input().split())
L = list(map(int, input().split()))
i = 0
p = []
(c1, c2) = (0, 0)
while i < n - 2:
	if L[i] % 2 == 0:
		c1 += 1
	else:
		c2 += 1
	if c1 == c2:
		p.append(abs(L[i + 1] - L[i]))
		(c1, c2) = (0, 0)
	i += 1
p = sorted(p)
c = 0
for i in range(len(p)):
	if b < p[i]:
		break
	b = b - p[i]
	c += 1
print(c)


(n, k) = [int(i) for i in input().split()]
arr = [int(i) for i in input().split()]
i = 0
e = 0
o = 0
c = 0
d = []
while i < n - 1:
	if arr[i] & 1:
		o += 1
	else:
		e += 1
	if e == o:
		d.append(abs(arr[i] - arr[i + 1]))
		e = 0
		o = 0
	i += 1
d.sort()
for i in range(len(d)):
	if d[i] <= k:
		k -= d[i]
		c += 1
	else:
		break
print(c)


(n, B) = map(int, input().split())
a = list(map(int, input().split()))
(odds, evens) = (0, 0)
costs = []
for i in range(n - 1):
	if a[i] % 2 == 0:
		evens += 1
	else:
		odds += 1
	if odds == evens:
		costs.append(abs(a[i] - a[i + 1]))
cnt = 0
if len(costs) > 0:
	costs.sort()
	while B > 0 and cnt < len(costs):
		if costs[cnt] <= B:
			B -= costs[cnt]
			cnt += 1
		else:
			B = 0
print(cnt)


import math

def main():
	(n, b) = map(int, input().split())
	arr = [int(x) for x in input().split()]
	costs = []
	count = 0
	o = e = 0
	for i in range(len(arr)):
		if o == e and (o != 0 and e != 0):
			cost = abs(arr[i] - arr[i - 1])
			costs.append(cost)
		if arr[i] % 2 == 1:
			o += 1
		else:
			e += 1
	costs.sort()
	for i in costs:
		if b - i >= 0:
			b -= i
			count += 1
		else:
			break
	print(count)
main()


from __future__ import print_function
import sys
import math
import os.path
import random
from copy import deepcopy
from functools import reduce
from collections import Counter, ChainMap, defaultdict
from itertools import cycle, chain
from queue import Queue, PriorityQueue
from heapq import heappush, heappop, heappushpop, heapify, heapreplace, nlargest, nsmallest
import bisect
from statistics import mean, mode, median, median_low, median_high
sys.setrecursionlimit(10 ** 9)

def log(*args, **kwargs):
	print(*args, file=sys.stderr, **kwargs)

def ni():
	return map(int, input().split())

def nio(offset):
	return map(lambda x: int(x) + offset, input().split())

def nia():
	return list(map(int, input().split()))

def toString(aList, sep=' '):
	return sep.join((str(x) for x in aList))

def toMapInvertIndex(aList):
	return {k: v for (v, k) in enumerate(aList)}

def sortId(arr):
	return sorted(range(arr), key=lambda k: arr[k])
(n, B) = ni()
a = nia()
a.insert(0, 0)
MAX = 111
c = 0
l = 0
d = []
for i in range(1, n):
	if a[i] % 2 == 0:
		c += 1
	else:
		l += 1
	if c == l and abs(a[i + 1] - a[i]) <= B:
		d.append(abs(a[i + 1] - a[i]))
d.sort()
count = 0
ss = 0
for x in d:
	if ss + x <= B:
		ss += x
		count += 1
	else:
		break
print(count)


def cut(a, n, b):
	odd_even = 0
	oe = []
	cost = []
	for i in range(n - 1):
		if a[i] % 2 == 0:
			odd_even += 1
		else:
			odd_even -= 1
		if odd_even == 0 and i != 0:
			oe.append(i)
			cost.append(abs(a[i + 1] - a[i]))
	cost.sort()
	i = 0
	while i < len(cost) and b - cost[i] >= 0:
		b -= cost[i]
		i += 1
	print(i)
(n, b) = map(int, input().split())
a = list(map(int, input().split()))
cut(a, n, b)


(n, b) = map(int, input().split(' '))
numbers = list(map(int, input().split(' ')))
cuts = []
even = 0
uneven = 0
last = None
for (i, m) in enumerate(numbers):
	if last != None and even == uneven:
		cuts.append(abs(last - m))
	if m % 2 == 0:
		even += 1
	else:
		uneven += 1
	last = m
cuts = sorted(cuts)
s = 0
i = 0
while i < len(cuts) and s <= b:
	s += cuts[i]
	i += 1
if len(cuts) == 0:
	print(0)
elif s > b:
	print(i - 1)
else:
	print(i)


(n, b) = map(int, input().split())
a = list(map(int, input().split()))
(e, o) = (0, 0)
lst = 0
temp = []
for i in a:
	if o == e:
		temp += [abs(i - lst)]
		(o, e) = (0, 0)
	if i % 2 == 0:
		o += 1
	else:
		e += 1
	lst = i
c = 0
for i in sorted(temp[1:]):
	b -= i
	if b >= 0:
		c += 1
print(c)


(n, b) = map(int, input().split())
ai = list(map(int, input().split()))
ai2 = [0] * n
temp1 = 0
for i in range(n - 1):
	if ai[i] % 2 == 0:
		temp1 += 2
	if temp1 == i + 1:
		ai2[i] = 1
ai4 = []
temp1 = 0
for i in range(n - 1, 0, -1):
	if ai[i] % 2 == 0:
		temp1 += 2
	if temp1 == n - i:
		if ai2[i - 1] == 1:
			ai4 += [abs(ai[i] - ai[i - 1])]
ai4.sort()
ans = 0
i = 0
while i < len(ai4) and b >= ai4[i]:
	b -= ai4[i]
	ans += 1
	i += 1
print(ans)


(n, k) = list(map(int, input().split()))
a = list(map(int, input().split()))
total = 0
(ch, nch) = (0, 0)
if a[0] % 2 == 0:
	ch += 1
else:
	nch += 1
if a[1] % 2 == 0:
	ch += 1
else:
	nch += 1
gaps = []
for i in range(2, len(a)):
	if ch == nch:
		gaps.append(abs(a[i] - a[i - 1]))
	if a[i] % 2 == 0:
		ch += 1
	else:
		nch += 1
gaps = sorted(gaps)
idx = 0
while k > 0 and idx < len(gaps):
	if gaps[idx] <= k:
		k -= gaps[idx]
		idx += 1
		total += 1
	else:
		break
print(total)


(n, b) = list(map(int, input().split()))
a = list(map(int, input().split()))
e = [0] * len(a)
o = [0] * len(a)
for (i, elem) in enumerate(a):
	e[i] = e[i - 1]
	o[i] = o[i - 1]
	if elem % 2 == 0:
		e[i] += 1
	else:
		o[i] += 1
cuts = 0
price = 0
while True:
	min_i = -1
	min_val = 1000000000.0
	for i in range(len(a) - 1):
		if e[i] == o[i]:
			if abs(a[i] - a[i + 1]) < min_val:
				min_val = abs(a[i] - a[i + 1])
				min_i = i
	if min_i != -1 and price + min_val <= b:
		cuts += 1
		price += min_val
		a[min_i] = 1000000000.0
	else:
		break
print(cuts)


(n, B) = map(int, input().split())
A = [*map(int, input().split())]
P = []
(e, o) = (0, 0)
for (i, a) in enumerate(A):
	if a % 2 == 0:
		e += 1
	else:
		o += 1
	if e == o and i + 1 < len(A):
		P.append(abs(A[i] - A[i + 1]))
P.sort()
sum_ = 0
j = -1
for i in range(len(P)):
	sum_ += P[i]
	if sum_ > B:
		break
	j = i
print(j + 1)


import math
(n, b) = map(int, input().split())
a = list(map(int, input().split()))
(oddc, evenc) = (0, 0)
diff = list()
for i in range(n - 1):
	if a[i] & 1:
		oddc += 1
	else:
		evenc += 1
	if oddc == evenc:
		diff.append(math.fabs(a[i] - a[i + 1]))
diff.sort()
count = 0
i = 0
while i < len(diff) and b >= diff[i]:
	b -= diff[i]
	count += 1
	i += 1
print(count)


n = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
l = []
even = 0
odd = 0
for i in range(n[0]):
	if a[i] % 2 == 0:
		even += 1
	else:
		odd += 1
	if even == odd and i != n[0] - 1:
		l.append(abs(a[i + 1] - a[i]))
l.sort()
c = 0
s = 0
for i in l:
	s += i
	c += 1
	if s > n[1]:
		c -= 1
		break
print(c)


nb = list(map(int, input().split(' ')))
a = list(map(int, input().split(' ')))
ame = [0 for i in range(nb[0])]
amo = [0 for i in range(nb[0])]
for i in range(nb[0]):
	if a[i] % 2 == 0:
		if i == 0:
			ame[i] = 1
			amo[i] = 0
		ame[i] = ame[i - 1] + 1
		amo[i] = amo[i - 1]
	else:
		if i == 0:
			ame[i] = 0
			amo[i] = 1
		ame[i] = ame[i - 1]
		amo[i] = amo[i - 1] + 1
sums = []
for i in range(nb[0] - 1):
	if ame[i] == amo[i]:
		sums.append(abs(a[i + 1] - a[i]))
sums = sorted(sums)
ans = 0
cur = 0
while nb[1] > 0:
	if cur == len(sums):
		break
	if nb[1] - sums[cur] >= 0:
		ans += 1
		nb[1] = nb[1] - sums[cur]
		cur += 1
	else:
		break
print(ans)


(n, b) = map(int, input().split())
c = 0
io = -1
a = []
for i in input().split():
	i = int(i)
	c += i % 2 * 2 - 1
	if c == 0:
		io = i
	elif io != -1:
		a += [abs(io - i)]
		io = -1
a.sort()
c = 0
while c < len(a) and a[c] <= b:
	b -= a[c]
	c += 1
print(c)


import itertools
import bisect
(n, b) = map(int, input().split())
a = list(map(int, input().split()))
r = []
n_odds = n_evens = 0
for i in range(n - 1):
	if a[i] % 2 == 0:
		n_evens += 1
	else:
		n_odds += 1
	if n_odds == n_evens:
		r.append(abs(a[i + 1] - a[i]))
r = list(itertools.accumulate(sorted(r)))
p = bisect.bisect_left(r, b)
print(p + (p < len(r) and r[p] == b))


(n, k) = map(int, input().split())
l = [int(j) for j in input().split()]
t = 0
d = []
for i in range(n - 1):
	if l[i] % 2 == 0:
		t += 1
	else:
		t -= 1
	if t == 0:
		d.append(abs(l[i] - l[i + 1]))
d.sort()
i = 0
while i < len(d) and k >= d[i]:
	k -= d[i]
	i += 1
print(i)


(n, b) = map(int, input().split())
a = list(map(int, input().split()))
x = 0
y = 0
ans = 0
li = []
for i in range(n - 1):
	if a[i] & 1:
		x += 1
	if not a[i] & 1:
		y += 1
	if x == y:
		li.append((abs(a[i + 1] - a[i]), i))
li.sort()
i = 0
while b > 0 and i < len(li):
	if b - li[i][0] >= 0:
		b -= li[i][0]
		ans += 1
	else:
		break
	i += 1
print(ans)


(n, B) = map(int, input().split())
a = list(map(int, input().split()))
b = [0] * n
dst = 0
last0 = 0
last1 = 0
for i in range(n - 1):
	if a[i] % 2 == 0:
		last0 += 1
	else:
		last1 += 1
	if last0 == last1:
		last0 = 0
		last1 = 0
		b[dst] = abs(a[i] - a[i + 1])
		dst += 1
b = b[:dst]
b.sort()
ans = 0
b_sum = 0
for bi in b:
	b_sum += bi
	if b_sum > B:
		break
	ans += 1
print(ans)


import sys
import math
from functools import reduce
import bisect

def getN():
	return int(input())

def getNM():
	return map(int, input().split())

def getList():
	return list(map(int, input().split()))

def input():
	return sys.stdin.readline().rstrip()

def index(a, x):
	i = bisect.bisect_left(a, x)
	if i != len(a) and a[i] == x:
		return i
	return False
(n, b) = getNM()
arr = getList()
odd = 0
even = 0
segments = []
for i in range(n - 1):
	if arr[i] % 2:
		odd += 1
	else:
		even += 1
	if odd == even:
		segments.append(abs(arr[i] - arr[i + 1]))
segments.sort()
ans = price = 0
for x in segments:
	price += x
	if price > b:
		break
	ans += 1
print(ans)


inp = input().split()
n = int(inp[0])
b = int(inp[1])
a = input().split()
m = []
for i in range(n):
	a[i] = int(a[i])
	m.append((m[i - 1] if i > 0 else 0) + (1 if a[i] % 2 else -1))
valid_a = []
for i in range(len(a) - 1):
	if m[i] == 0:
		valid_a.append(abs(a[i + 1] - a[i]))
valid_a.sort()
count = 0
for x in valid_a:
	b -= x
	if b >= 0:
		count += 1
print(count)


(n, b) = list(map(int, input().split()))
a = list(map(int, input().split()))
e = [a[i] % 2 for i in range(n)]
c = []
for i in range(1, n):
	if sum(e[i:]) == (n - i) / 2 and sum(e[:i]) == i / 2:
		c.append(abs(a[i] - a[i - 1]))
c.sort()
i = 0
d = 0
while i < len(c) and d + c[i] <= b:
	d += c[i]
	i += 1
print(i)


(n, b) = map(int, input().split())
a = list(map(int, input().split()))
lis = list()
even = 0
odd = 0
for i in range(0, n - 1):
	if a[i] & 1:
		odd += 1
	else:
		even += 1
	if odd == even:
		val = abs(a[i + 1] - a[i])
		lis.append(val)
lis.sort()
ans = 0
cnt = 0
for item in lis:
	ans += item
	if ans > b:
		break
	cnt += 1
print(cnt)


(n, B) = map(int, input().split())
A = list(map(int, input().split())) + [10000000000]
R = []
CH = [0] * n
NCH = [0] * n
for i in range(n):
	if A[i] % 2 == 0:
		CH[i] = CH[i - 1] + 1
		NCH[i] = NCH[i - 1]
	else:
		NCH[i] = NCH[i - 1] + 1
		CH[i] = CH[i - 1]
	if CH[i] == NCH[i]:
		R.append(abs(A[i] - A[i + 1]))
R.pop(len(R) - 1)
R.sort()
s = 0
ans = 0
for i in range(len(R)):
	if s + R[i] <= B:
		ans += 1
		s += R[i]
	else:
		break
print(ans)


t = list(map(int, input().split()))
n = t[0]
B = t[1]
A = list(map(int, input().split()))
balance = 0
bits = []
for (i, v) in enumerate(A):
	if v % 2 == 0:
		balance += 1
	else:
		balance -= 1
	if balance == 0 and i != len(A) - 1:
		bits.append(abs(A[i + 1] - v))
ans = 0
for coast in sorted(bits):
	if coast <= B:
		B -= coast
		ans += 1
	else:
		break
print(ans)


import math
import sys
from bisect import bisect_right, bisect_left, insort_right
from collections import Counter, defaultdict
from heapq import heappop, heappush
from itertools import accumulate
from sys import stdout
R = lambda : map(int, input().split())
(n, B) = R()
arr = list(R())
o = 0
res = []
for (i, x) in enumerate(arr):
	o += 1 if x & 1 else -1
	if not o:
		res.append(abs(x - (arr[i + 1] if i < n - 1 else math.inf)))
res = list(accumulate(sorted(res)))
print(bisect_right(res, B))


(n, m) = map(int, input().split())
a = list(map(int, input().split()))
l = 0
r = 0
ans = 0
b = []
for i in range(n - 2):
	if a[i] % 2:
		r += 1
	else:
		l += 1
	if l == r:
		b.append(abs(a[i] - a[i + 1]))
b = sorted(b)
for i in b:
	if i <= m:
		ans += 1
		m -= i
print(ans)


def count(o):
	ans = 0
	for i in o:
		if i % 2 == 0:
			ans += 1
		else:
			ans -= 1
	if ans == 0:
		return True
	else:
		return False
(N, B) = [int(i) for i in input().split()]
x = [int(i) for i in input().split()]
ans = []
for i in range(1, len(x)):
	if count(x[:i]) and count(x[i:]):
		ans.append(abs(x[i] - x[i - 1]))
otvet = 0
if len(ans) > 0:
	while True:
		B -= min(ans)
		if B < 0:
			break
		ans[ans.index(min(ans))] = 1000
		otvet += 1
print(otvet)


(n, b) = map(int, input().split())
a = list(map(int, input().split()))
even = [0] * n
odd = [0] * n
for i in range(n):
	if a[i] % 2:
		odd[i] += 1
	else:
		even[i] += 1
for i in range(n - 1):
	odd[i + 1] += odd[i]
	even[i + 1] += even[i]
cut = []
for i in range(n - 1):
	if odd[i] == even[i]:
		cut.append((abs(a[i] - a[i + 1]), i))
cut.sort()
cnt = 0
s = 0
while s <= b and cut:
	(c, idx) = cut.pop(0)
	s += c
	cnt += 1
if s > b:
	cnt -= 1
print(cnt)


n1 = input()
n1 = n1.split()
n = int(n1[0])
b = int(n1[1])
a = input()
a = a.split()
if int(a[0]) % 2 == 0:
	s = -1
else:
	s = 1
z = []
for i in range(1, n - 1):
	if int(a[i]) % 2 == 0:
		s -= 1
	else:
		s += 1
	if s == 0:
		z += [abs(int(a[i + 1]) - int(a[i]))]
q = len(z)
if q > 0:
	z.sort()
	t = 0
	w = 0
	for i in z:
		t += z[w]
		w += 1
		if t > b:
			w -= 1
			break
	print(w)
else:
	print(0)


(n, b) = map(int, input().split())
a = list(map(int, input().split()))
if a[0] % 2 == 0:
	odd1 = 0
	even1 = 1
else:
	odd1 = 1
	even1 = 0
odd2 = 0
even2 = 0
for val in range(1, len(a)):
	if a[val] % 2 == 0:
		even2 += 1
	else:
		odd2 += 1
l1 = []
if even2 == odd2 and even1 == odd1:
	if abs(a[1] - a[0]) <= b:
		l1.append(abs(a[1] - a[0]))
for val in range(1, len(a) - 1):
	if a[val] % 2 == 0:
		even1 += 1
		even2 -= 1
	else:
		odd1 += 1
		odd2 -= 1
	if even1 == odd1 and even2 == odd2:
		if abs(a[val + 1] - a[val]) <= b:
			l1.append(abs(a[val + 1] - a[val]))
l1.sort()
sp = 0
money = 0
if len(l1) > 0:
	for val in range(0, len(l1)):
		money += l1[val]
		if money > b:
			break
		else:
			sp += 1
print(sp)


(n, b) = map(int, input().split())
a = list(map(int, input().split()))
d = [(abs(a[i] - a[i + 1]), i) for i in range(n - 1)]
d = list(sorted(d))
f = []
s = 0
for i in a:
	if i % 2:
		s += 1
	f.append(s)
s = 0
kk = 0
for i in d:
	if i[1] % 2 and f[i[1]] == (i[1] + 1) // 2 and (s + i[0] <= b):
		kk += 1
		s += i[0]
print(kk)


(MyDp, Odd, Even, Input, Count) = ([], 0, 0, lambda : list(map(int, input().split())), 0)
(X, Numbers) = (Input(), Input())
for i in range(X[0]):
	Odd += 1 if Numbers[i] % 2 == 1 else 0
	Even += 1 if Numbers[i] % 2 == 0 else 0
	if Odd == Even and i < X[0] - 2:
		MyDp.append(abs(Numbers[i] - Numbers[i + 1]))
MyDp.sort()
i = 0
for i in MyDp:
	X[1] -= i
	if X[1] >= 0:
		Count += 1
	else:
		break
print(Count)


(n, b) = [int(i) for i in input().split()]
s = [int(i) for i in input().split()]
even = []
odd = []
c = []
for i in range(n):
	if s[i] % 2 == 0:
		even.append(s[i])
	else:
		odd.append(s[i])
	if len(even) == len(odd):
		if i < n - 1:
			c.append(abs(s[i] - s[i + 1]))
c.sort()
p = 0
for i in c:
	b = b - i
	if b < 0:
		break
	else:
		p += 1
print(p)


(N, Bitcoin) = map(int, input().split())
List = [int(x) for x in input().split()]
Even = 0
Odd = 0
for i in List:
	if i & 1:
		Odd += 1
	else:
		Even += 1
E = Even
O = Odd
Index_Cost = []
for i in range(N - 1):
	if List[i] & 1:
		O += 1
	else:
		E += 1
	if O == E and Odd - O == Even - E:
		Index_Cost.append((abs(List[i + 1] - List[i]), i))
Index_Cost.sort()
Cuts = 0
for (cost, index) in Index_Cost:
	Bitcoin = Bitcoin - cost
	if Bitcoin >= 0:
		Cuts += 1
	else:
		break
print(Cuts)


(n, b) = map(int, input().split())
l = [int(x) for x in input().split()]
if n <= 3 or n % 2 != 0:
	print(0)
else:
	l2 = []
	o = 0
	e = 0
	for i in range(len(l) - 2):
		if l[i] % 2 == 0:
			e += 1
		else:
			o += 1
		if o == e and o > 0:
			l2.append(abs(l[i + 1] - l[i]))
	l2.sort()
	sum1 = 0
	c = 0
	for i in range(len(l2)):
		sum1 += l2[i]
		if sum1 <= b:
			c += 1
		else:
			break
	print(c)


(n, b) = map(int, input().split())
a = list(map(int, input().split()))
dp = [[0] * 101 for i in range(101)]
balance = 0
mx = 0
for i in range(len(a) - 1):
	if a[i] % 2:
		balance += 1
	else:
		balance -= 1
	for j in range(b):
		dp[i + 1][j] = max(dp[i + 1][j], dp[i][j])
		if balance == 0 and j + abs(a[i] - a[i + 1]) <= b:
			dp[i + 1][j + abs(a[i] - a[i + 1])] = max(dp[i + 1][j + abs(a[i] - a[i + 1])], dp[i][j] + 1)
			mx = max(mx, dp[i + 1][j + abs(a[i] - a[i + 1])])
print(mx)


from sys import stdin, stdout
import math, sys, heapq
from itertools import permutations, combinations
from collections import defaultdict, deque, OrderedDict
from os import path
import random
import bisect as bi

def yes():
	print('YES')

def no():
	print('NO')
if path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

	def I():
		return int(input())

	def In():
		return map(int, input().split())
else:

	def I():
		return int(stdin.readline())

	def In():
		return map(int, stdin.readline().split())

def dict(a):
	d = {}
	for x in a:
		if d.get(x, -1) != -1:
			d[x] += 1
		else:
			d[x] = 1
	return d

def find_gt(a, x):
	i = bi.bisect_left(a, x)
	if i != len(a):
		return i
	else:
		return -1

def main():
	try:
		(n, k) = In()
		l = list(In())
		(nodd, neve) = (0, 0)
		temp = []
		for x in range(n):
			if l[x] & 1 == 1:
				nodd += 1
			else:
				neve += 1
			if nodd == neve:
				if x + 1 < n:
					temp.append(abs(l[x] - l[x + 1]))
				nodd = 0
				neve = 0
			else:
				continue
		ans = 0
		temp.sort()
		for x in range(len(temp)):
			if temp[x] <= k:
				k -= temp[x]
				ans += 1
		print(ans)
	except:
		pass
M = 998244353
P = 1000000007
for _ in range(1):
	main()


(n, b) = list(map(int, input().split()))
a = list(map(int, input().split()))
s = 0
prices = []
for i in range(n):
	if a[i] % 2 == 0:
		s += 1
	else:
		s -= 1
	if s == 0 and i != n - 1:
		prices.append(abs(a[i] - a[i + 1]))
prices.sort()
k = 0
sm = 0
for i in range(len(prices)):
	sm += prices[i]
	k += 1
	if sm > b:
		k -= 1
		break
print(k)


[n, B] = list(map(int, input().strip().split()))
ais = list(map(int, input().strip().split()))
c = [0, 0]
cutcost = []
for i in range(n - 1):
	c[ais[i] % 2] += 1
	if c[0] == c[1]:
		cutcost.append(abs(ais[i] - ais[i + 1]))
cutcost.sort()
cnt = 0
for cost in cutcost:
	if cost <= B:
		cnt += 1
		B -= cost
print(cnt)


I = lambda : map(int, input().split())
(n, b, *a) = (*I(), *I())
(dp, s) = ([], [0, 0])
for (i, j) in zip(a, a[1:]):
	s[i % 2] += 1
	if s[0] == s[1]:
		dp.append(abs(j - i))
dp.sort()
print(sum((sum(dp[:i + 1]) <= b for i in range(len(dp)))))


(n, b) = list(map(int, input().split()))
a = list(map(int, input().split()))
costs = []
balance = [False] * n
(odds, evens) = (0, 0)
for x in range(n):
	if a[x] % 2 == 0:
		evens += 1
	else:
		odds += 1
(i, j) = (0, 0)
for x in range(n - 1):
	if a[x] % 2 == 0:
		i += 1
	else:
		j += 1
	if i == j and evens - i == odds - j:
		balance[x] = True
for x in range(n - 1):
	if balance[x]:
		costs.append(abs(a[x] - a[x + 1]))
costSum = 0
costs = sorted(costs)
ans = 0
for x in costs:
	if costSum + x <= b:
		costSum += x
		ans += 1
print(ans)


import math

def Sort(track):
	track.sort(key=lambda x: x[1])
	return track
x = [int(x) for x in input().split()]
n = x[0]
b = x[1]
arr = [int(y) for y in input().split()]
arrlen = len(arr)
track = []
even = 0
odd = 0
if n % 2 != 0 or n == 2:
	print(0)
else:
	for i in range(0, arrlen - 1):
		if arr[i] % 2 == 0:
			even = even + 1
		else:
			odd = odd + 1
		if (i - 1) % 2 == 0 and even == odd:
			x = []
			x.append(i + 1)
			x.append(abs(arr[i] - arr[i + 1]))
			track.append(x)
	tlen = len(track)
	if tlen == 0:
		print(0)
	else:
		track = Sort(track)
		summation = 0
		ans = 0
		for lists in track:
			summation += lists[1]
			if summation <= b:
				ans = ans + 1
			else:
				break
		print(ans)


def max_cut(n, b, l):
	(a, d, k, s) = ([], 0, 0, 0)
	for i in range(n - 1):
		if l[i] % 2:
			k += 1
		else:
			d += 1
		if k == d:
			a.append(abs(l[i + 1] - l[i]))
	a.sort()
	i = 0
	while i < len(a) and s < b:
		s += a[i]
		i += 1
	return i - 1 if s > b else i
R = lambda : list(map(int, input().split()))
(n, b) = R()
l = R()
print(max_cut(n, b, l))


import sys

def mp():
	return list(map(int, input().split()))

def dead():
	print('-1')
	sys.exit()
debug = 0
if debug:
	f = open('input.txt', 'r')
	input = f.readline

def _main():
	(n, k) = mp()
	a = mp()
	(x, y) = (0, 0)
	p = True
	visited = [0] * (n + 5)
	while p:
		p = False
		m = -1
		for i in range(n):
			if a[i] & 1:
				x += 1
			else:
				y += 1
			if visited[i] == 0 and x == y and (i != n - 1):
				if m == -1 or abs(a[m] - a[m + 1]) > abs(a[i] - a[i + 1]):
					m = i
		if m != -1 and k >= abs(a[m] - a[m + 1]):
			k -= abs(a[m] - a[m + 1])
			visited[m] = 1
			p = True
	print(visited.count(1))
_main()


def main():
	(n, b) = list(map(int, input().split()))
	numbers = list(map(int, input().split()))
	values = []
	count = 0
	last_item = 0
	start = False
	for item in numbers:
		if start and count == 0:
			values += [abs(item - last_item)]
		if item % 2 == 0:
			count += 1
		else:
			count -= 1
		last_item = item
		start = True
	answer = 0
	answer_count = 0
	for value in sorted(values):
		if answer + value <= b:
			answer += value
			answer_count += 1
	print(answer_count)
main()


(n, b) = map(int, input().split())
arr = list(map(int, input().split()))
curr = 0
cuts_arr = []
for (i, el) in enumerate(arr):
	if el % 2:
		curr += 1
	else:
		curr -= 1
	if not curr and i < n - 1:
		cuts_arr.append(abs(arr[i + 1] - arr[i]))
cuts_arr = sorted(cuts_arr)
(cuts, cost) = (0, 0)
while cuts < len(cuts_arr) and cost + cuts_arr[cuts] <= b:
	cost += cuts_arr[cuts]
	cuts += 1
print(cuts)


(q, w) = list(map(int, input().split()))
a = list(map(int, input().split()))
d = []
k = 0
for i in range(q - 1):
	k += a[i] % 2
	if k == i - k + 1:
		d.append(abs(a[i] - a[i + 1]))
d.sort()
k = 0
i = 0
while (i < len(d)) & (k <= w):
	k += d[i]
	i += 1
if k > w:
	print(i - 1)
else:
	print(i)


(n, k) = map(int, input().split())
arr = list(map(int, input().split()))
(co, ce) = (0, 0)
cut = []
for i in range(n):
	if arr[i] & 1 == 0:
		ce += 1
	else:
		co += 1
	if i & 1 == 1 and ce == co:
		cut.append(i)
if len(cut) == 1:
	print('0')
else:
	for i in range(len(cut) - 1):
		cut[i] = abs(arr[cut[i] + 1] - arr[cut[i]])
	cut[len(cut) - 1] = 99999999
	cut.sort()
	(ans, count) = (0, 0)
	for i in range(len(cut) - 1):
		if ans + cut[i] <= k:
			ans += cut[i]
			count += 1
		else:
			break
	print(count)


def main():
	(n, b) = map(int, input().split())
	a = [int(i) for i in input().split()]
	(even, odd) = (0, 0)
	(l, r) = ([], [int(i) for i in a])
	(cnt_even_left, cnt_odd_left) = (0, 0)
	(cnt_even_right, cnt_odd_right) = (n // 2, n // 2)
	res = []
	for i in range(n - 1):
		l.append(a[i])
		r.remove(a[i])
		if a[i] % 2 == 0:
			cnt_even_left += 1
			cnt_even_right -= 1
		else:
			cnt_odd_left += 1
			cnt_odd_right -= 1
		cost = ((a[i] - a[i + 1]) ** 2) ** 0.5
		if cost <= b:
			if cnt_even_left == cnt_odd_left and cnt_even_right == cnt_odd_right:
				res += [int(cost)]
	res.sort()
	cnt = 0
	for i in res:
		if b >= i:
			cnt += 1
			b -= i
	print(cnt)
main()


(n, b) = map(int, input().split())
arr = input().split()
even = 0
odd = 0
for a in arr:
	if int(a) % 2 == 0:
		even += 1
	else:
		odd += 1
if even != odd:
	print(0)
else:
	even = 0
	odd = 0
	lis = []
	for i in range(n):
		if int(arr[i]) % 2 == 0:
			even += 1
		else:
			odd += 1
		if even == odd and i != n - 1:
			lis.append(max(int(arr[i]), int(arr[i + 1])) - min(int(arr[i]), int(arr[i + 1])))
	l = len(lis)
	lis.sort(key=int)
	temp = 0
	count = 0
	for i in range(l):
		temp += lis[i]
		if temp <= b:
			count += 1
	print(count)


TN = 1

def solution():
	(n, B) = map(int, input().split())
	a = list(map(int, input().split()))
	d = {}
	for i in range(n):
		if a[i] % 2 == 0:
			d[i] = 1
		else:
			d[i] = 0
	inds = []
	vs = []
	ind_v = {}
	v_ind = {}
	for i in range(2, n, 2):
		s1 = 0
		for j in range(i):
			s1 += d[j]
		if s1 == i // 2:
			s2 = 0
			for j in range(i, n):
				s2 += d[j]
			if s2 == (n - i) // 2:
				inds.append(i)
				vs.append(abs(a[i] - a[i - 1]))
				ind_v[i] = abs(a[i] - a[i - 1])
	ns = 0
	ans = 0
	vs = sorted(vs)
	for i in vs:
		if ns + i <= B:
			ns += i
			ans += 1
		else:
			break
	print(ans)
while TN != 0:
	solution()
	TN -= 1


(n, c) = list(map(int, input().strip().split()))
a = list(map(int, input().strip().split()))
odd = even = 0
cuts = []
for i in range(0, n):
	if i != 0 and odd == even:
		cuts.append(abs(a[i] - a[i - 1]))
	if a[i] % 2 == 0:
		even += 1
	else:
		odd += 1
ans = 0
cuts.sort()
for i in cuts:
	if i <= c:
		ans += 1
		c -= i
print(ans)


(n, b) = input().split()
(n, b) = [int(n), int(b)]
a = [int(i) for i in input().split()]
c = []
o = 0
e = 0
for i in range(0, n):
	if a[i] % 2 == 0:
		e += 1
	else:
		o += 1
	if e == o:
		if i + 1 < n:
			c.append(abs(a[i] - a[i + 1]))
ans = 0
i = 0
c.sort()
while i < len(c):
	if c[i] <= b:
		ans += 1
		b = b - c[i]
	i += 1
print(ans)


(n, b) = map(int, input().split())
l = list(map(int, input().split()))
(ce, co) = (0, 0)
c = 0
s = 0
ans = 0
z = []
for i in range(n):
	if l[i] % 2:
		co += 1
	else:
		ce += 1
	if ce == co:
		if i < n - 1:
			z.append(abs(l[i + 1] - l[i]))
			(ce, co) = (0, 0)
z.sort()
for i in z:
	ans += 1
	s += i
	if s > b:
		ans -= 1
		print(ans)
		exit(0)
print(ans)


(n, b) = map(int, input().split())
arr = list(map(int, input().split()))
ne = 0
ch = 0
mass = []
for i in range(n - 1):
	if arr[i] % 2 == 0:
		ch += 1
	else:
		ne += 1
	if ch == ne:
		mass.append(abs(arr[i] - arr[i + 1]))
ans = 0
mass.sort()
for i in mass:
	if i <= b:
		b -= i
		ans += 1
print(ans)


(n, b) = map(int, input().split())
l = list(map(int, input().split()))
odd = 0
even = 0
l1 = []
for t in range(n - 1):
	if l[t] % 2 == 0:
		even += 1
	else:
		odd += 1
	if odd == even:
		check = abs(l[t] - l[t + 1])
		if check <= b:
			l1.append(check)
		odd = 0
		even = 0
l1.sort()
cut = 0
i = 0
while b > 0 and i < len(l1):
	b -= l1[i]
	if b >= 0:
		cut += 1
	i += 1
print(cut)


(n, b) = [int(s) for s in input().split(' ')]
a = [int(s) for s in input().split(' ')]
bitcoins = []
e = 0
o = 0
for i in range(n - 1):
	if a[i] % 2 == 0:
		e += 1
	else:
		o += 1
	if e == o:
		bitcoin = abs(a[i] - a[i + 1])
		if bitcoin <= b:
			bitcoins.append(bitcoin)
bitcoins.sort()
while True:
	s = sum(bitcoins)
	if s <= b:
		print(len(bitcoins))
		break
	else:
		del bitcoins[len(bitcoins) - 1]


import math
getInputList = lambda : list(input().split())
getInputIntList = lambda : list(map(int, input().split()))
(n, b) = getInputIntList()
arr = getInputIntList()
count = 0
even = 0
odd = 0
cut = []
for i in range(1, n):
	if arr[i - 1] % 2 == 0:
		even += 1
	else:
		odd += 1
	if even == odd and i % 2 == 0 and (b >= abs(arr[i - 1] - arr[i])):
		cut.append(abs(arr[i - 1] - arr[i]))
cut.sort()
for i in cut:
	b -= i
	if b >= 0:
		count += 1
	else:
		break
print(count)


(n, bitcoin) = map(int, input().strip().split(' '))
l = list(map(int, input().strip().split(' ')))
even = [0]
odd = [0]
for i in range(len(l)):
	if l[i] % 2 == 0:
		even.append(even[-1] + 1)
		odd.append(odd[-1])
	else:
		odd.append(odd[-1] + 1)
		even.append(even[-1])
result = []
for i in range(1, len(odd) - 1):
	if odd[i] == even[i]:
		result.append(abs(l[i] - l[i - 1]))
result = sorted(result)
tillBitcoin = 0
cuts = 0
if len(result) != 0:
	for i in result:
		tillBitcoin += i
		if tillBitcoin <= bitcoin:
			cuts += 1
	print(cuts)
else:
	print(0)


from sys import stdin
(n, b) = map(int, stdin.readline().split())
a = [int(i) for i in stdin.readline().split()]
dp = [[0 for j in range(b + 1)] for i in range(n)]
a.insert(0, 0)
(eve, odd) = (0, 0)
coin = 0
for i in range(1, n):
	if a[i] & 1:
		odd += 1
	else:
		eve += 1
	if eve == odd and 0 < eve + odd < n:
		coin = abs(a[i + 1] - a[i])
	else:
		coin = 102
	for j in range(1, b + 1):
		if j >= coin:
			dp[i][j] = max(dp[i - 1][j - coin] + 1, dp[i - 1][j])
		else:
			dp[i][j] = dp[i - 1][j]
print(dp[-1][-1])


import sys
(n, b) = [int(i) for i in input().split()]
l = [int(i) for i in input().split()]
odd = even = 0
for i in l:
	if i % 2 == 0:
		even += 1
	else:
		odd += 1
if even != odd:
	print(0)
	sys.exit()
l1 = []
o = e = 0
for i in range(len(l) - 1):
	if l[i] % 2 == 0:
		e += 1
	else:
		o += 1
	if e == o:
		l1.append(abs(l[i] - l[i + 1]))
c = 0
c1 = 0
l1.sort()
for i in l1:
	c1 += i
	if c1 <= b:
		c += 1
print(c)


(n, b) = map(int, input().split())
a = list(map(int, input().split()))
l = []
c = 0
e = 0
o = 0
for i in range(len(a)):
	c += 1
	if a[i] % 2 == 0:
		e += 1
	else:
		o += 1
	if e == o and c < len(a):
		if a[i + 1] - a[i] <= b:
			e = 0
			o = 0
			l.append(abs(a[i + 1] - a[i]))
l.sort()
c = 0
for i in l:
	b -= i
	if b < 0:
		break
	else:
		c += 1
print(c)


(n, b) = map(int, input().split())
a = list(map(int, input().split()))
splits = []
odd = 0
even = 0
for i in range(len(a) - 1):
	if a[i] % 2 == 0:
		even += 1
	else:
		odd += 1
	if even == odd:
		splits.append(abs(a[i + 1] - a[i]))
splits.sort()
i = 0
while i < len(splits):
	if sum(splits[:i + 1]) <= b:
		i += 1
	else:
		break
print(i)


(n, b) = map(int, input().split())
l = list(map(int, input().split()))
odd1 = 0
even1 = 0
a = []
for i in range(n - 2):
	if l[i] % 2 != 0:
		odd1 += 1
	else:
		even1 += 1
	if odd1 == even1:
		j = i + 1
		odd2 = 0
		even2 = 0
		while j < n:
			if l[j] % 2 != 0:
				odd2 += 1
			else:
				even2 += 1
			j += 1
		if odd2 == even2:
			a.append(abs(l[i] - l[i + 1]))
if a == []:
	print(0)
else:
	a.sort()
	s = 0
	c = 0
	for i in a:
		s += i
		if s <= b:
			c += 1
	print(c)


inp = list(map(int, input().split()))
n = inp[0]
b = inp[1]
inp = list(map(int, input().split()))
x = []
even = 0
odd = 0
for i in range(n):
	if inp[i] % 2 == 1:
		odd += 1
	else:
		even += 1
	if odd == even:
		if i != n - 1:
			x.append(abs(inp[i + 1] - inp[i]))
x.sort()
sumi = 0
k = 0
while sumi <= b and k < len(x):
	sumi += x[k]
	k += 1
if sumi > b:
	k = k - 1
print(k)


(n, b) = map(int, input().split())
l = list(map(int, input().split()))
cut = []
if n == 0 or n % 2 == 1:
	print(0)
else:
	odd = 0
	even = 0
	for i in range(n - 1):
		if l[i] % 2 == 0:
			even += 1
			if odd == even:
				cut.append(abs(l[i] - l[i + 1]))
		else:
			odd += 1
			if odd == even:
				cut.append(abs(l[i] - l[i + 1]))
cut = sorted(cut)
count = 0
for j in range(len(cut)):
	if b - cut[j] >= 0:
		count += 1
		b -= cut[j]
	else:
		break
print(count)


(n, bcn) = map(int, input().split())
ar = list(map(int, input().split()))
c = 0
seg = []
for i in range(n - 1):
	if ar[i] & 1:
		c += 1
	else:
		c -= 1
	if not c:
		seg.append(abs(ar[i] - ar[i + 1]))
seg.sort()
c = 0
ans = 0
for i in range(len(seg)):
	c += seg[i]
	if c <= bcn:
		ans += 1
	else:
		pass
print(ans)


(n, c) = map(int, input().split())
seq = [int(x) for x in input().split()]
cnt = 0
cuts = []
for (a, b) in zip(seq[:-1], seq[1:]):
	if a % 2:
		cnt -= 1
	else:
		cnt += 1
	if cnt == 0:
		cuts.append(abs(a - b))
cuts.sort(reverse=True)
ans = 0
while cuts and c - cuts[-1] >= 0:
	c -= cuts.pop()
	ans += 1
print(ans)


(n, B) = map(int, input().split())
a = [int(i) for i in input().split()]
(e, o) = (0, 0)
b = []
c = []
for i in range(n - 1):
	if a[i] % 2 == 0:
		e += 1
	elif a[i] % 2 != 0:
		o += 1
	if e == o:
		cost = abs(a[i + 1] - a[i])
		b.append(i)
		c.append(cost)
c.sort()
count = 0
ans = 0
for i in c:
	ans = ans + i
	if ans > B:
		break
	else:
		count += 1
print(count)


(n, b) = map(int, input().split())
l = [int(x) for x in input().split()]
arr = [x % 2 for x in l]
cut = 0
cost = []
for i in range(n):
	if arr[i] == 1:
		cut += 1
	else:
		cut -= 1
	if cut == 0 and i != n - 1:
		cost.append(abs(l[i + 1] - l[i]))
cost.sort()
ans = 0
for x in cost:
	if b >= x:
		ans += 1
		b -= x
	else:
		break
print(ans)


from itertools import accumulate
from bisect import bisect_left, bisect_right
(n, k) = [int(_) for _ in input().split()]
A = [int(_) for _ in input().split()]
X = []
c = 0
for _ in range(n):
	if A[_] % 2 == 0:
		c += 1
	else:
		c -= 1
	X.append(c)
Z = []
for _ in range(1, n - 1):
	if X[_] == 0:
		Z.append(abs(A[_] - A[_ + 1]))
Z.sort()
Z = list(accumulate(Z))
print(bisect_right(Z, k))


import bisect

def find_le(a, x):
	i = bisect.bisect_right(a, x)
	if i:
		return a[i - 1]
	raise ValueError
nB = list(map(int, input().rstrip().split(' ')))
(n, B) = (nB[0], nB[1])
ar = list(map(int, input().rstrip().split(' ')))
cuts = []
nums = 0
for i in range(n):
	if ar[i] % 2 == 0:
		nums -= 1
	else:
		nums += 1
	if nums == 0 and i < n - 1:
		cuts.append(abs(ar[i + 1] - ar[i]))
cuts.sort()
if len(cuts) == 0:
	print(0)
else:
	cuts_sum = [cuts[0]]
	for i in range(1, len(cuts)):
		cuts_sum.append(cuts_sum[i - 1] + cuts[i])
	index = bisect.bisect_right(cuts_sum, B)
	print(index)


(n, b) = map(int, input().split())
ch = 0
nch = 0
res = []
a = list(map(int, input().split()))
for i in range(n):
	if a[i] % 2 == 0:
		ch += 1
	else:
		nch += 1
	if nch == ch:
		if i != n - 1:
			res.append(abs(a[i + 1] - a[i]))
res.sort()
if ch != nch:
	print(0)
elif len(res) == 0:
	print(0)
elif res[0] > b:
	print(0)
else:
	s = 0
	c = 0
	for i in range(len(res)):
		if s + res[i] <= b:
			s += res[i]
			c += 1
	print(c)


def main():

	def cut(seq):
		start = 2
		l = len(seq)
		count = seq[0] % 2 + seq[1] % 2
		cuts = []
		while start < l:
			if count == start / 2:
				cuts.append((start, abs(seq[start] - seq[start - 1])))
			count += seq[start] % 2 + seq[start + 1] % 2
			start += 2
		cuts.sort(key=lambda a: a[1])
		if cuts:
			ret = cuts[0]
			return (ret[1], seq[:ret[0]], seq[ret[0]:])
		return (1000, [], [])
	(n, b) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	reta = 0
	temp = [a]
	while True:
		temp.sort(key=lambda d: cut(d)[0])
		tem = cut(temp[0])
		temp = temp[1:]
		if b - tem[0] < 0:
			break
		temp.append(tem[1])
		temp.append(tem[2])
		b -= tem[0]
		reta += 1
	print(reta)
	return 0
main()


(n, b) = map(int, input().split())
(x, a, e, o, r) = ([*map(int, input().split())], [], 0, 0, 0)
for i in range(n - 1):
	if x[i] % 2 == 0:
		e += 1
	else:
		o += 1
	if e == o:
		a.append(abs(x[i + 1] - x[i]))
a.sort()
while a:
	if a[0] <= b:
		b -= a.pop(0)
		r += 1
	else:
		break
print(r)


(noe, cost) = [int(x) for x in input().split()]
arrs = [int(x) for x in input().split()]
valids = 0
cuts = []
for (i, v) in enumerate(arrs[:-1]):
	if v % 2:
		valids += 1
	else:
		valids -= 1
	if valids == 0:
		cuts.append(abs(arrs[i] - arrs[i + 1]))
cuts = sorted(cuts)
done = 0
while done < len(cuts) and cost >= cuts[done]:
	cost -= cuts[done]
	done += 1
print(done)


import collections
from functools import cmp_to_key
import math
import sys

def getIntList():
	return list(map(int, input().split()))
import bisect
try:
	import numpy
	dprint = print
	dprint('debug mode')
except ModuleNotFoundError:

	def dprint(*args, **kwargs):
		pass

def makePair(z):
	return [(z[i], z[i + 1]) for i in range(0, len(z), 2)]

def memo(func):
	cache = {}

	def wrap(*args):
		if args not in cache:
			cache[args] = func(*args)
		return cache[args]
	return wrap

@memo
def comb(n, k):
	if k == 0:
		return 1
	if n == k:
		return 1
	return comb(n - 1, k - 1) + comb(n - 1, k)
(N, B) = getIntList()
za = getIntList()
even = 0
zr = []
for i in range(N - 1):
	if za[i] % 2 == 0:
		even += 1
	else:
		even -= 1
	if even == 0:
		zr.append(abs(za[i] - za[i + 1]))
zr.sort()
dprint(zr)
res = 0
tot = 0
for x in zr:
	if tot + x <= B:
		res += 1
		tot += x
	else:
		break
print(res)


import sys
(n, bitcoins) = [int(x) for x in input().split()]
lis = [int(x) for x in input().split()]
memory = [[[-1 for _ in range(bitcoins + 1)] for _ in range(n)] for _ in range(n)]
prefix_even = []
total = 0
for i in range(n):
	if lis[i] % 2 == 0:
		total += 1
	prefix_even.append(total)
costs = []
for i in range(n - 1):
	even_right = prefix_even[n - 1] - prefix_even[i]
	if prefix_even[i] == i + 1 - prefix_even[i] and even_right == n - i - 1 - even_right:
		costs.append(abs(lis[i] - lis[i + 1]))
costs = sorted(costs)
total = 0
if len(costs) == 0:
	print(0)
	sys.exit()
while total < len(costs):
	if bitcoins >= costs[total]:
		bitcoins -= costs[total]
		total += 1
	else:
		break
print(total)


(n, b) = map(int, input().split())
a = list(map(int, input().split()))
pts = []
odd = 0
even = 0
for i in range(n - 1):
	if a[i] % 2 == 0:
		even += 1
	else:
		odd += 1
	if odd == even:
		pts.append(abs(a[i] - a[i + 1]))
pts.sort()
x = 0
cuts = 0
for y in pts:
	if x + y <= b:
		x += y
		cuts += 1
	else:
		break
print(cuts)


(n, b) = map(int, input().split())
elements = list(map(int, input().split()))
cost = []
even = odd = 0
for i in range(n):
	if elements[i] % 2 == 0:
		even += 1
	else:
		odd += 1
	if even == odd != 0 and i < n - 1:
		cost.append(abs(elements[i + 1] - elements[i]))
		even = odd = 0
cost.sort()
total = sum(cost)
count = len(cost)
while total > b:
	total -= cost[count - 1]
	count -= 1
print(count)


(n, k) = map(int, input().split())
a = [int(i) for i in input().split()]
ans = []
o = 0
e = 0
for i in range(n):
	if a[i] % 2 == 0:
		e += 1
	else:
		o += 1
	if e == o and i != n - 1 and (abs(a[i] - a[i + 1]) <= k):
		ans.append(abs(a[i] - a[i + 1]))
ans.sort()
c = 0
s = 0
for i in range(len(ans)):
	s += ans[i]
	if s > k:
		break
	c += 1
print(c)


(n, B) = list(map(int, input().split()))
a = list(map(int, input().split()))
res = []
if a[0] % 2 == 0:
	bal = 1
else:
	bal = -1
for i in range(1, n):
	if bal == 0:
		res.append(abs(a[i] - a[i - 1]))
	if a[i] % 2 == 0:
		bal += 1
	else:
		bal -= 1
res.sort()
cnt = 0
ans = 0
while cnt <= B:
	if ans == len(res):
		ans += 1
		break
	cnt += res[ans]
	ans += 1
print(ans - 1)


import sys
import math
(n, b) = map(int, input().split())
lista = [int(x) for x in input().strip().split()]
pro = [False for i in range(n)]
for i in range(n):
	if lista[i] % 2 == 0:
		pro[i] = True
(o, e, k) = (0, 0, 0)
suma = 0
send = []
for i in range(0, n - 1):
	if pro[i] == True:
		o += 1
	else:
		e += 1
	if o == e and o != 0 and (e != 0):
		if abs(lista[i + 1] - lista[i]) <= b:
			send.append(abs(lista[i + 1] - lista[i]))
		k = i
		(o, e) = (0, 0)
send = sorted(send)
com = 0
for i in range(len(send)):
	if suma + send[i] > b:
		break
	suma += send[i]
	com += 1
kaani = pro[k:]
if pro.count(True) != pro.count(False):
	com = 0
print(com)


import sys
input = sys.stdin.readline

def main():
	(n, b) = map(int, input().split())
	l = list(map(int, input().split()))
	score = []
	cnt = 0
	for i in range(n - 1):
		if l[i] & 1:
			cnt += 1
		else:
			cnt -= 1
		if cnt == 0:
			score.append(abs(l[i] - l[i + 1]))
	m = len(score)
	DP = [[-1] * (b + 1) for _ in range(m)]

	def solve(i, s):
		if i >= m:
			return 0
		if DP[i][s] >= 0:
			return DP[i][s]
		k = solve(i + 1, s)
		if s - score[i] >= 0:
			k = max(k, 1 + solve(i + 1, s - score[i]))
		DP[i][s] = k
		return k
	print(solve(0, b))
main()


def int_list(arr):
	for i in range(len(arr)):
		arr[i] = int(arr[i])
	return arr

def same_parity(arr):
	net = 0
	for el in arr:
		if el % 2 == 0:
			net += 1
		else:
			net -= 1
	return net == 0

def cost(ind):
	global a
	return abs(a[ind - 1] - a[ind])

def cuts_are_valid(cut_arr):
	global a
	if not same_parity(a[:cut_arr[0]]):
		return False
	for i in range(len(cut_arr) - 1):
		if not same_parity(a[cut_arr[i]:cut_arr[i + 1]]):
			return False
	if not same_parity(a[cut_arr[-1]:]):
		return False
	return True
(n, b) = int_list(input().split(' '))
used = [False for i in range(n)]
a = int_list(input().split(' '))
bitcoin_counter = 0
min_additional_index = 0
best_cuts = []
for i in range(50):
	min_additional_score = 9999
	for ind in range(2, n, 2):
		if ind not in best_cuts:
			tmp = best_cuts.copy()
			tmp.append(ind)
			if cuts_are_valid(tmp):
				score = cost(ind)
				if score < min_additional_score:
					min_additional_score = score
					min_additional_index = ind
	if bitcoin_counter + min_additional_score <= b:
		bitcoin_counter += min_additional_score
		best_cuts.append(min_additional_index)
print(len(best_cuts))


(n, b) = map(int, input().split())
l = list(map(int, input().split()))
o = 0
e = 0
lis = []
for i in range(n - 2):
	if l[i] % 2 == 0:
		e += 1
	else:
		o += 1
	if e == o:
		lis.append(abs(l[i + 1] - l[i]))
lis.sort()
sum = 0
i = 0
while sum <= b and i < len(lis):
	sum += lis[i]
	i += 1
if sum > b:
	i -= 1
print(i)


(n, m) = map(int, input().split())
arr = list(map(int, input().split()))
ls = []
even = 0
for i in range(n):
	if i % 2 == 0 and i > 1:
		if even == i // 2:
			ls += [abs(arr[i] - arr[i - 1])]
	if arr[i] % 2 == 0:
		even += 1
ls.sort()
i = 0
count = 0
while i < len(ls) and m >= ls[i]:
	m -= ls[i]
	count += 1
	i += 1
print(count)


(n, b) = map(int, input().split())
a = list(map(int, input().split()))
odd = 0
even = 0
ans = []
for i in range(n - 1):
	if a[i] % 2 == 0:
		even += 1
	else:
		odd += 1
	if odd == even:
		ans.append(a[i + 1] - a[i] if a[i + 1] > a[i] else a[i] - a[i + 1])
ans = sorted(ans)
sum = 0
cnt = 0
for x in ans:
	if sum + x > b:
		break
	sum += x
	cnt += 1
print(cnt)


(n, m) = map(int, input().split())
a = list(map(int, input().split()))
b = []
cnt1 = 0
cnt2 = 0
for i in range(len(a)):
	if a[i] % 2 == 0:
		cnt1 += 1
	else:
		cnt2 += 1
	if cnt1 == cnt2 and i + 1 < len(a):
		b.append(abs(a[i] - a[i + 1]))
b.sort()
sum = 0
ans = 0
for i in b:
	sum += i
	if sum <= m:
		ans += 1
	else:
		break
print(ans)


import math
(n, b) = input().split()
arr = [int(j) for j in input().split()]
odd = len(arr) / 2
even = len(arr) / 2
rOdd = 0
rEven = 0
money = []
count = 0
for i in range(len(arr)):
	if i != 0 and rOdd == rEven:
		money.append(math.fabs(arr[i] - arr[i - 1]))
	if arr[i] % 2 == 0:
		rEven = rEven + 1
	else:
		rOdd = rOdd + 1
money.sort()
a = int(b)
for i in range(len(money)):
	if a <= 0:
		break
	a = a - money[i]
	if a >= 0:
		count = count + 1
print(count)


from bisect import bisect_right
from itertools import accumulate
(n, B) = map(int, input().split())
a = list(map(int, input().split()))
need = [2 * (el % 2) - 1 for el in a]
acc = list(accumulate(need))
zeros = [i for i in range(n) if acc[i] == 0]
costs = [abs(a[i] - a[i + 1]) for i in zeros if i + 1 < n]
for_ans = list(accumulate(sorted(costs)))
print(bisect_right(for_ans, B))


from collections import defaultdict

def get_max_cuts(n, B, array):
	count_array = [None for __ in range(n)]
	coins_set = set()
	coins_dict = defaultdict(list)
	for j in range(0, n):
		if j == 0:
			if array[0] % 2 == 0:
				count_array[j] = (n // 2, n // 2 - 1)
			else:
				count_array[j] = (n // 2 - 1, n // 2)
		else:
			(prev_odd, prev_even) = count_array[j - 1]
			if array[j] % 2 == 0:
				count_array[j] = (prev_odd, prev_even - 1)
			else:
				count_array[j] = (prev_odd - 1, prev_even)
		if j != n - 1:
			coins = abs(array[j] - array[j + 1])
			coins_set.add(coins)
			coins_dict[coins].append(j)
	max_cuts = 0
	coins_spent = 0
	coins_list = sorted(list(coins_set))
	for coins in coins_list:
		for idx in coins_dict[coins]:
			if coins_spent + coins > B:
				return max_cuts
			(count_odd, count_even) = count_array[idx]
			if count_even == count_odd:
				max_cuts += 1
				coins_spent += coins
	return max_cuts
(n, B) = list(map(int, input().split()))
array = list(map(int, input().split()))
print(get_max_cuts(n, B, array))


(n, b) = map(int, input().split())
a = list(map(int, input().split()))
(lst, chet, nechet) = ([], 0, 0)
for i in range(n - 1):
	x = a[i]
	if x % 2 == 0:
		chet += 1
	else:
		nechet += 1
	if chet == nechet:
		lst.append(abs(x - a[i + 1]))
lst.sort()
(summa, res) = (0, 0)
for (i, x) in enumerate(lst):
	summa += x
	if summa > b:
		break
	res += 1
print(res)


(n, B) = map(int, input().split())
x = list(map(int, input().split()))
cuts = []
even_odd_balance = 1 if x[0] % 2 == 1 else -1
for k in range(1, len(x) - 1):
	if x[k] % 2 == 1:
		even_odd_balance += 1
	else:
		even_odd_balance -= 1
	if even_odd_balance == 0:
		cuts.append(abs(x[k] - x[k + 1]))
cuts.sort()
ans = 0
for elem in cuts:
	if elem > B:
		break
	ans += 1
	B -= elem
print(ans)


(n, k) = map(int, input().split())
l = [int(x) for x in input().split()]
cut = [0 for i in range(n)]
if l[0] & 1:
	cut[0] = -1
else:
	cut[0] = 1
point = []
for i in range(n - 1):
	if l[i] & 1:
		cut[i] = cut[i - 1] - 1
	else:
		cut[i] = cut[i - 1] + 1
	if cut[i] == 0:
		point.append(abs(l[i + 1] - l[i]))
point.sort()
cnt = 0
while point and k >= point[0]:
	cnt += 1
	k -= point[0]
	point = point[1:]
print(cnt)


(n, b) = map(int, input().split())
a = list(map(int, input().split()))
s = ''
suka = []
count = 0
for i in range(len(a)):
	if a[i] % 2 == 0:
		s += '0'
	else:
		s += '1'
for i in range(len(a)):
	if (s[:i].count('1') == s[:i].count('0') and s[:i].count('1') != 0 and (s[:i].count('0') != 0)) and (s[i:].count('0') == s[i:].count('1') and s[i:].count('1') != 0 and (s[i:].count('0') != 0)):
		if b - abs(a[i] - a[i - 1]) >= 0:
			suka.append(abs(a[i] - a[i - 1]))
suka.sort()
for i in range(len(suka)):
	if b - suka[i] >= 0:
		count += 1
		b -= suka[i]
print(count)


from math import ceil
t = 1
for test in range(t):
	(n, b) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	countOdd = 0
	countEven = 0
	cuts = []
	prev = 0
	for i in a:
		if countEven == countOdd:
			cuts.append(abs(prev - i))
		if i % 2 == 0:
			countEven += 1
		else:
			countOdd += 1
		prev = i
	cuts[0] = 200
	cuts.sort()
	ans = 0
	cost = 0
	for i in cuts:
		if cost + i > b:
			break
		else:
			ans += 1
			cost += i
	print(ans)


(n, b) = [int(x) for x in input().split()]
li = [int(x) for x in input().split()]
i = 0
newli = []
first = 0
end = 0
o = 0
e = 0
while i < n:
	if li[i] % 2 == 1:
		o += 1
	elif li[i] % 2 == 0:
		e += 1
	if o == e:
		end = i
		newli.append((first, end))
		first = i + 1
	i += 1
if len(newli) == 1:
	print(0)
	quit()
ansli = []
for i in range(len(newli) - 1):
	ansli.append(abs(li[newli[i][1]] - li[newli[i + 1][0]]))
z = len(ansli)
while z > 0:
	l = sorted(ansli)
	if sum(l[:z]) <= b:
		print(z)
		exit()
	z -= 1
print(0)


(n, k) = map(int, input().split(' '))
li = [int(x) for x in input().split()]
temp = []
odd = 0
even = 0
for i in range(0, n - 1):
	if li[i] % 2:
		odd += 1
	else:
		even += 1
	if odd == even:
		temp.append(abs(li[i + 1] - li[i]))
temp.sort()
sum = 0
count = 0
for i in temp:
	sum = sum + i
	if sum > k:
		break
	else:
		count = count + 1
print(count)


import math
line = input()
line = [int(i) for i in line.split(' ')]
(n, budget) = (line[0], line[1])
line = input().split(' ')
ints = [int(i) for i in line]
(odd, even) = (0, 0)
sections = []
temp = []
for i in ints:
	temp.append(i)
	odd += i % 2
	even += (i + 1) % 2
	if odd != 0 and odd == even:
		sections.append(temp)
		temp = []
		odd = even = 0
if len(sections) == 1:
	print(0)
else:
	costs = []
	for i in range(0, len(sections)):
		if i == 0:
			costs.append(0)
		else:
			costs.append(abs(sections[i][0] - sections[i - 1][-1]))
	costs = sorted(costs)
	while sum(costs) > budget:
		costs = costs[:-1]
	print(len(costs) - 1)


(n, b) = map(int, input().split())
a = list(map(int, input().split()))
(q, w, l, m) = (0, 0, [], 0)
for i in range(n - 1):
	if a[i] & 1:
		q += 1
	else:
		w += 1
	if q == w:
		l.append(abs(a[i] - a[i + 1]))
l.sort()
for i in l:
	if i <= b:
		m += 1
		b -= i
	else:
		break
print(m)


(n, b) = map(int, input().split())
a = list(map(int, input().split()))
r = []
eo = [0, 0]
for i in range(len(a)):
	if eo[0] == eo[1] and eo[0] != 0:
		r.append(abs(a[i - 1] - a[i]))
		eo = [0, 0]
	eo[a[i] % 2] += 1
r.sort()
r.append(b + 1)
i = 0
while b >= 0:
	b -= r[i]
	i += 1
print(i - 1)


(n, b) = map(int, input().split())
a = list(map(int, input().split()))
(ce, co) = (0, 0)
d = []
for i in range(n - 1):
	if a[i] % 2 == 1:
		co += 1
	else:
		ce += 1
	if ce == co:
		d.append(abs(a[i] - a[i + 1]))
d.sort()
res = 0
for i in range(len(d)):
	if b >= d[i]:
		res += 1
		b -= d[i]
print(res)


mod = 1000000007
ii = lambda : int(input())
si = lambda : input()
dgl = lambda : list(map(int, input()))
f = lambda : map(int, input().split())
il = lambda : list(map(int, input().split()))
ls = lambda : list(input())
(n, b) = f()
l = il()
es = [0]
os = [0]
cl = []
for i in l:
	if i & 1:
		os.append(os[-1] + 1)
		es.append(es[-1])
	else:
		os.append(os[-1])
		es.append(es[-1] + 1)
for i in range(1, n):
	if es[i] == os[i]:
		cl.append(abs(l[i] - l[i - 1]))
cl.sort()
c = 0
for i in cl:
	if i <= b:
		b -= i
		c += 1
print(c)


input = __import__('sys').stdin.readline
(n, b) = map(int, input().split())
lis = list(map(int, input().split()))
pre = [[0, 0] for i in range(n)]
cut = []
for i in range(n - 1):
	if lis[i] % 2 == 0:
		pre[i][0] = pre[i - 1][0] + 1
		pre[i][1] = pre[i - 1][1]
	else:
		pre[i][1] = pre[i - 1][1] + 1
		pre[i][0] = pre[i - 1][0]
	if pre[i][0] == pre[i][1]:
		cut.append(abs(lis[i] - lis[i + 1]))
ans = 0
cut.sort()
for i in range(len(cut)):
	if b >= cut[i]:
		b -= cut[i]
		ans += 1
print(ans)


(n, B) = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
possible_splits = []
even = 0
odd = 0
for i in range(n - 1):
	if a[i] % 2 == 0:
		even += 1
	else:
		odd += 1
	if even == odd:
		possible_splits.append((abs(a[i] - a[i + 1]), i))
possible_splits = sorted(possible_splits)
i = 0
while i < len(possible_splits) and B >= possible_splits[i][0]:
	B -= possible_splits[i][0]
	i += 1
print(i)


(n, b) = map(int, input().split())
arr = list(map(int, input().split()))
e = 0
o = 0
arr1 = []
for i in range(n):
	if arr[i] % 2 == 0:
		e += 1
	else:
		o += 1
	if e == o:
		if i != n - 1:
			arr1.append(abs(arr[i + 1] - arr[i]))
arr1.sort()
ans = 0
sumx = 0
i = 0
while sumx < b and i < len(arr1):
	if sumx + arr1[i] <= b:
		ans += 1
		sumx += arr1[i]
	i += 1
print(ans)


(n, b) = map(int, input().split())
a = list(map(int, input().split()))
c = []
f = 0
for i in range(0, n - 1):
	f += a[i] % 2 * -2 + 1
	if f == 0:
		c.append(abs(a[i] - a[i + 1]))
if c == []:
	print(0)
else:
	c.sort()
	x = 0
	i = 0
	k = 0
	while i < len(c):
		if x + c[i] > b:
			break
		else:
			x += c[i]
			i += 1
			k += 1
	print(k)


(n, bit) = map(int, input().split())
a = list(map(int, input().split()))
b = list()
ch = 0
for i in range(n - 1):
	if a[i] % 2 == 0:
		ch += 1
	elif a[i] % 2 == 1:
		ch -= 1
	if ch == 0:
		b.append(abs(a[i] - a[i + 1]))
b.sort()
cn = 0
for i in range(len(b)):
	if bit >= b[i]:
		bit -= b[i]
		cn += 1
print(cn)


def f(b, sequence: list):
	slices = []
	odd_count = 0
	even_count = 0
	for (i, v) in enumerate(sequence):
		if v % 2:
			even_count += 1
		else:
			odd_count += 1
		if even_count == odd_count:
			if i + 1 < len(sequence):
				slices.append(abs(v - sequence[i + 1]))
			odd_count = even_count = 0
	slices.sort()
	slices_count_before_b = 0
	for v in slices:
		if v <= b:
			b -= v
			slices_count_before_b += 1
		else:
			break
	return slices_count_before_b
(in_n, in_b) = [int(i) for i in input().split()]
in_seq = [int(i) for i in input().split()]
print(f(in_b, in_seq))


(n, b) = map(int, input().split())
l = list(map(int, input().split()))
oc = 0
ec = 0
tmp = []
for i in range(0, n - 1):
	if l[i] & 1 == 1:
		oc += 1
	else:
		ec += 1
	if ec == oc:
		tmp.append(abs(l[i + 1] - l[i]))
tmp.sort()
c = 0
for i in range(len(tmp)):
	if b >= tmp[i]:
		c += 1
		b -= tmp[i]
	else:
		break
print(c)


(n, B) = list(map(int, input().split()))
a = list(map(int, input().split()))

def solve(a, B):
	(diff, k) = ([], 0)
	for i in range(0, len(a) - 1):
		if a[i] % 2 == 0:
			k += 1
		else:
			k -= 1
		if k == 0:
			diff.append(abs(a[i + 1] - a[i]))
	diff.sort()
	s = 0
	for i in range(len(diff)):
		s += diff[i]
		if s > B:
			return i
	return len(diff)
print(solve(a, B))


(n, b) = list(map(int, input().split()))
a = list(map(int, input().split()))
c_even = 0
c_odd = 0
book = []
for i in range(n):
	if a[i] % 2 == 0:
		c_even += 1
	else:
		c_odd += 1
	if c_even == c_odd:
		if i < n - 1:
			book.append(abs(a[i + 1] - a[i]))
c = 0
book.sort()
if len(book) == 0:
	print(0)
else:
	while b > 0 and c < len(book):
		b -= book[c]
		c += 1
	if b >= 0:
		print(c)
	else:
		print(c - 1)


(n, m) = map(int, input().split())
l = list(map(int, input().split()))
(x, y, ans, z, p) = (0, 0, [], 0, 0)
for i in range(n - 1):
	if l[i] % 2 == 1:
		x += 1
	else:
		y += 1
	if x == y:
		ans.append(abs(l[i] - l[i + 1]))
ans.sort()
for i in range(len(ans)):
	if p + ans[i] <= m:
		z += 1
		p += ans[i]
	else:
		break
print(z)


def read_nums():
	return [int(x) for x in input().split()]

def find_cuts(nums):
	res = []
	(n_even, n_odd) = (0, 0)
	for (index, num) in enumerate(nums):
		if num % 2 == 0:
			n_even += 1
		else:
			n_odd += 1
		if n_odd == n_even and index != len(nums) - 1:
			res.append(index)
	return res

def find_costs(nums, cuts):
	res = []
	for index in cuts:
		res.append(abs(nums[index] - nums[index + 1]))
	return res

def print_res(b, sorted_costs):
	res = 0
	spent = 0
	for cost in sorted_costs:
		if spent + cost <= b:
			res += 1
			spent += cost
	print(res)

def main():
	(n, b) = read_nums()
	nums = read_nums()
	cuts = find_cuts(nums)
	cut_costs = find_costs(nums, cuts)
	sorted_costs = sorted(cut_costs)
	print_res(b, sorted_costs)
main()


(n, b) = map(int, input().split())
arr = list(map(int, input().split()))
if n <= 2:
	print(0)
else:
	l = []
	v = 0
	l1 = [0, 0]
	for i in range(1, n - 2, 2):
		l1[arr[i] % 2] += 1
		l1[arr[i - 1] % 2] += 1
		if l1[0] == l1[1]:
			l1 = [0, 0]
			l.append(abs(arr[i + 1] - arr[i]))
	l.sort()
	cut = 0
	while cut < len(l) and b - l[cut] >= 0:
		b = b - l[cut]
		cut += 1
	print(cut)


(n, B) = map(int, input().split())
a = list(map(int, input().split()))
(e, o) = (0, 0)
l = []
for i in range(n):
	if a[i] % 2 == 0:
		e += 1
	else:
		o += 1
	if e == o and i != n - 1:
		l.append(abs(a[i + 1] - a[i]))
	if i == n - 1 and e != o:
		l = []
l.sort()
ans = 0
for i in l:
	if i <= B:
		ans += 1
		B -= i
print(ans)


words = []
for word in input().split():
	words.append(word)
n = int(words[0])
b = int(words[1])
v = []
for word in input().split():
	v.append(int(word))
sum = 0
cuts = []
for i in range(n):
	nr = v[i]
	if nr % 2:
		sum += 1
	else:
		sum -= 1
	if sum == 0 and i != n - 1:
		cuts.append(abs(v[i] - v[i + 1]))
cuts.sort()
nrCuts = 0
total = 0
for cut in cuts:
	total += cut
	if total > b:
		break
	nrCuts += 1
print(nrCuts)


import math
(n, b) = map(int, input().split())
a = list(map(int, input().split()))
d = []
tec = 0
lenght = 0
for i in range(n - 1):
	if a[i] % 2 == 0:
		tec += 1
	else:
		tec -= 1
	lenght += 1
	if tec == 0 and lenght > 0:
		d.append(math.fabs(a[i] - a[i + 1]))
		lenght = 0
d.sort()
d.reverse()
tec = 0
k = 0
while tec <= b and len(d) != 0:
	tec += d.pop()
	k += 1
if tec > b:
	k -= 1
print(k)


import math as mt
import sys, string, bisect
input = sys.stdin.readline
import random
from collections import deque, defaultdict
L = lambda : list(map(int, input().split()))
Ls = lambda : list(input().split())
M = lambda : map(int, input().split())
I = lambda : int(input())
(n, b) = M()
x = L()
l = []
even = 0
odd = 0
if x[0] % 2 == 0:
	even += 1
else:
	odd += 1
for i in range(1, n - 1):
	if x[i] % 2 == 0:
		even += 1
	else:
		odd += 1
	if even == odd:
		l.append(abs(x[i] - x[i + 1]))
if x[-1] % 2 == 0:
	even += 1
else:
	odd += 1
if even == odd:
	if len(l) == 0:
		print(0)
	else:
		l.sort()
		ans = 0
		for i in range(len(l)):
			if b - l[i] >= 0:
				ans += 1
				b -= l[i]
			else:
				break
		print(ans)
else:
	print(0)


def oddEvenCounter(theList):
	odds = 0
	evens = 0
	for z in theList:
		if z % 2 == 0:
			evens += 1
		else:
			odds += 1
	if odds == evens:
		return True
	else:
		return False
(n, B) = map(int, input().split())
a = [int(x) for x in input().split()]
if n % 2 == 1:
	print(0)
elif not oddEvenCounter(a):
	print(0)
else:
	prices = []
	for i in range(2, n, +2):
		newL = a[i:]
		if len(newL) == 0:
			break
		elif oddEvenCounter(newL):
			prices.append(max(a[i], a[i - 1]) - min(a[i], a[i - 1]))
	prices.sort()
ans = 0
for j in prices:
	if B - j >= 0:
		B -= j
		ans += 1
	else:
		break
print(ans)


(n, b) = map(int, input().split())
a = list(map(int, input().split()))
z = 0
c = []
for i in range(n - 1):
	if a[i] % 2 == 0:
		z -= 1
	else:
		z += 1
	if z == 0:
		c.append(abs(a[i + 1] - a[i]))
c.sort()
ans = 0
while c:
	if b < c[0]:
		break
	b -= c[0]
	del c[0]
	ans += 1
print(ans)


(n, b) = map(int, input().split())
cost = []
s = list(map(int, input().split()))
even = 0
odd = 0
ev = []
od = []
for i in range(n):
	if s[i] % 2 == 0:
		even += 1
	else:
		odd += 1
	ev += [even]
	od += [odd]
for i in range(1, n - 1):
	if ev[i] == od[i]:
		cost += [abs(s[i + 1] - s[i])]
cost.sort()
ans = 0
for i in cost:
	if b >= i:
		ans += 1
		b = b - i
print(ans)


import bisect
(n, b) = list(map(int, input().split()))
a = list(map(int, input().split()))
(e, o) = (0, 0)
ct = []
for i in range(n):
	if a[i] % 2 == 0:
		e = e + 1
		ct.append([e, o])
	else:
		o = o + 1
		ct.append([e, o])
x = []
for i in range(n):
	if ct[i][0] == ct[i][1]:
		if i + 1 < n:
			x.append(abs(a[i] - a[i + 1]))
if x == []:
	print(0)
else:
	x.sort()
	for i in range(1, len(x)):
		x[i] = x[i - 1] + x[i]
	ans = bisect.bisect_right(x, b)
	print(ans)


a = list(map(int, input().split()))
l = list(map(int, input().split()))
li = []
e = o = 0
for i in range(a[0]):
	if l[i] % 2 == 0:
		e += 1
	else:
		o += 1
if e != o:
	print(0)
else:
	e = o = 0
	if l[0] % 2 == 0:
		e = 1
	else:
		o = 1
	for i in range(1, a[0] - 1):
		if l[i] % 2 == 0:
			e += 1
		else:
			o += 1
		if e == o:
			li.append(abs(l[i] - l[i + 1]))
			e = 0
			o = 0
	c = len(li)
	if c == 0:
		print(0)
	else:
		s = min(li)
		li.remove(min(li))
		c -= 1
		i = 0
		while s <= a[1] and c != 0:
			i += 1
			s += min(li)
			li.remove(min(li))
			c -= 1
		if s <= a[1] and c == 0:
			i += 1
		print(i)


(n, b) = map(int, input().split())
x = list(map(int, input().split()))
o = [x[0] % 2] * n
e = [1 - x[0] % 2] * n
for i in range(1, n):
	o[i] = o[i - 1] + x[i] % 2
	e[i] = e[i - 1] + 1 - x[i] % 2
poss = []
for i in range(1, n - 1):
	if o[i] == e[i]:
		poss += [abs(x[i + 1] - x[i])]
ans = 0
poss.sort()
curcost = 0
for i in range(len(poss)):
	curcost += poss[i]
	if curcost > b:
		break
	ans += 1
print(ans)


(N, B) = map(int, input().split())
S = list(map(int, input().split()))
odd = 0
even = 0
sep = {}
sep2 = []
for i in range(N - 1):
	if S[i] % 2 == 0:
		odd += 1
	else:
		even += 1
	if odd == even:
		sep[i + 1] = S[i + 1] - S[i]
		sep2.append(abs(S[i + 1] - S[i]))
sep2.sort()
count = 0
for i in range(len(sep2)):
	B -= sep2[i]
	if B >= 0:
		count += 1
print(count)


(n, b) = map(int, input().split())
odd = 0
even = 0
l = list(map(int, input().split()))
cuts = []
for i in range(n - 1):
	if l[i] % 2 != 0:
		odd = odd + 1
	else:
		even = even + 1
	if odd == even:
		cuts.append(abs(l[i + 1] - l[i]))
cuts.sort()
ans = 0
sumi = 0
for i in cuts:
	if sumi + i <= b:
		sumi = sumi + i
		ans = ans + 1
print(ans)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
b = []
en = on = cut = 0
for i in range(n - 1):
	if a[i] % 2 == 0:
		en += 1
	if a[i] % 2 != 0:
		on += 1
	if en == on:
		b.append(abs(a[i] - a[i + 1]))
		en = 0
		on = 0
b.sort()
for e in b:
	if e <= k:
		k -= e
		cut += 1
	if k == 0:
		break
print(cut)


import sys
(num_elements, bitcoins) = map(int, sys.stdin.readline().split())
elements = list(map(int, sys.stdin.readline().split()))
cuts_costs = []
odd_balance = -1 if elements[0] % 2 == 0 else 1
for (pos, element) in enumerate(elements[1:-2], start=1):
	odd_balance += -1 if element % 2 == 0 else 1
	if odd_balance == 0:
		cuts_costs.append(abs(element - elements[pos + 1]))
cuts_costs.sort()
num_cuts = 0
for cut in cuts_costs:
	bitcoins -= cut
	if bitcoins >= 0:
		num_cuts += 1
	else:
		break
print(num_cuts)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
ans = []
even = 0
odd = 0
for i in range(n):
	if a[i] % 2 == 0:
		even += 1
	else:
		odd += 1
	if even == odd and i < n - 1:
		ans.append(abs(a[i + 1] - a[i]))
ans.sort()
val = 0
for i in range(len(ans)):
	if ans[i] <= k:
		val += 1
		k -= ans[i]
print(val)


(n, b) = [int(x) for x in input().strip().split(' ')]
a = [int(x) for x in input().strip().split(' ')]
odd = 0
eve = 0
c = []
for i in range(n):
	if a[i] & 1:
		odd += 1
	else:
		eve += 1
	if i < n - 1 and odd == eve:
		c.append(abs(a[i + 1] - a[i]))
c.sort()
l = len(c)
j = 0
ans = 0
while j < l:
	b -= c[j]
	if b >= 0:
		ans += 1
	else:
		break
	j += 1
print(ans)


I = lambda : int(input())
ID = lambda : map(int, input().split())
IL = lambda : list(ID())
(n, b) = ID()
a = IL()
d = []
odd = even = ans = 0
f = False
for i in range(n - 1):
	if a[i] % 2 == 0:
		even += 1
	else:
		odd += 1
	if odd == even and i != n - 1:
		d.append(abs(a[i] - a[i + 1]))
d.sort()
for i in d:
	b -= i
	ans += 1
	if b < 0:
		f = True
		break
	if b == 0:
		break
if f:
	print(ans - 1)
else:
	print(ans)


(n, bi) = input().split()
n = int(n)
bi = int(bi)
a = list(map(int, input().split()))
cnt1 = 0
cnt2 = 0
i = 0
b = []
flag = 0
while i < len(a):
	if a[i] % 2 == 0:
		cnt1 += 1
	else:
		cnt2 += 1
	if cnt1 == cnt2:
		if i == len(a) - 1:
			flag = 1
		else:
			b.append(abs(a[i + 1] - a[i]))
	i += 1
if flag == 0:
	print(0)
else:
	b.sort()
	val = 0
	cnt = 0
	i = 0
	while i < len(b):
		if val + b[i] <= bi:
			cnt += 1
			val += b[i]
		else:
			break
		i += 1
	print(cnt)


def odd(n):
	return n % 2 == 1

def problem():
	in1 = input()
	in2 = input()
	inp1 = list(map(int, in1.split()))
	n = inp1[0]
	btc = inp1[1]
	numbers = list(map(int, in2.split()))
	if odd(len(numbers)):
		return 0
	odd_count = 0
	cut_costs = []
	for (idx, number) in enumerate(numbers):
		if odd(number):
			odd_count += 1
		if idx + 1 - odd_count == odd_count and idx + 1 < n:
			cut_costs.append(abs(numbers[idx + 1] - number))
	if n - odd_count != odd_count:
		return 0
	cut_costs.sort()
	cuts = 0
	for cost in cut_costs:
		if btc >= cost:
			cuts += 1
			btc -= cost
	return cuts
result = problem()
print(result)


(n, m) = map(int, input().split())
a = list(map(int, input().split()))
x = 0
y = 0
b = []
for i in range(n - 1):
	if a[i] % 2 == 0:
		x += 1
	else:
		y += 1
	if x == y:
		b.append(abs(a[i] - a[i + 1]))
b.sort()
t = 0
i = 0
while i < len(b) and m >= t + b[i]:
	t += b[i]
	i += 1
print(i)


(n, B) = map(int, input().split())
a = input()
A = list(map(int, list(a.split())))
i = 0
e = 0
o = 0
c = 0
ls = []
while i < n:
	if A[i] % 2 == 0:
		e = e + 1
	else:
		o = o + 1
	if o == e:
		if i == n - 1:
			break
		else:
			ls.append(abs(A[i] - A[i + 1]))
			o = 0
			e = 0
	i = i + 1
if ls == []:
	print(0)
else:
	ls.sort()
	for i in ls:
		if i <= B:
			c = c + 1
			B = B - i
		else:
			break
	print(c)


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
ans = 0
d = []
eve = 0
odd = 0
for i in range(n - 1):
	if l[i] % 2 == 0:
		eve += 1
	else:
		odd += 1
	if eve == odd:
		d.append(abs(l[i] - l[i + 1]))
d.sort()
n = len(d)
ans = 0
for i in range(n):
	if k >= d[i]:
		k -= d[i]
		ans += 1
	else:
		break
print(ans)


import math as mt
import sys, string, bisect
input = sys.stdin.readline
from collections import deque, defaultdict
L = lambda : list(map(int, input().split()))
Ls = lambda : list(input().split())
M = lambda : map(int, input().split())
I = lambda : int(input())
(n, b) = M()
l = L()
l.append(1000)
ev = 0
od = 0
c = 0
g = []
for i in range(n):
	if l[i] % 2 == 0:
		ev += 1
	if l[i] % 2 == 1:
		od += 1
	if ev == od:
		g.append(abs(l[i] - l[i + 1]))
		c += 1
		ev = 0
		od = 0
g.sort()
ans = 0
key = 0
for i in range(len(g)):
	if ans + g[i] <= b:
		ans += g[i]
		key = i + 1
	else:
		break
print(key)


(n, b) = map(int, input().split())
a = list(map(int, input().split()))
(e, o, bi) = (0, 0, [])
for (i, ai) in enumerate(a):
	if ai % 2 == 0:
		e += 1
	else:
		o += 1
	if e == o:
		if i < n - 1:
			bi.append(abs(ai - a[i + 1]))
		(e, o) = (0, 0)
bi.sort()
from itertools import accumulate
acc = list(accumulate(bi))
from bisect import bisect_right
br = bisect_right(acc, b)
print(br)


(n, B) = list(map(int, input().split()))
a = list(map(int, input().split()))
oMe = 0
Bs = []
for i in range(n):
	if a[i] % 2 == 0:
		oMe -= 1
	else:
		oMe += 1
	if oMe == 0 and i + 1 != n:
		Bs.append(abs(a[i] - a[i + 1]))
Bs = sorted(Bs)
ans = 0
for i in range(len(Bs)):
	if B - Bs[i] >= 0:
		B -= Bs[i]
		ans += 1
print(ans)


(n, b) = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
odd = 0
even = 0
ans = []
for i in range(len(a)):
	if a[i] % 2:
		odd += 1
	else:
		even += 1
	if odd == even:
		if i != len(a) - 1:
			ans.append(abs(a[i] - a[i + 1]))
ans.sort()
count = 0
su = 0
for i in ans:
	su += i
	if su <= b:
		count += 1
	else:
		break
print(count)


(n, b) = map(int, input().split())
a = list(map(int, input().split()))
cost = list()
(add, even) = (0, 0)
for i in range(len(a)):
	if a[i] % 2:
		add += 1
	else:
		even += 1
	if add == even and i != n - 1:
		cost.append(abs(a[i + 1] - a[i]))
		(add, even) = (0, 0)
cost.sort()
(c, i) = (0, 0)
while i < len(cost) and c + cost[i] <= b:
	c += cost[i]
	i += 1
print(i)


(n, b) = list(map(int, input().split()))
a = list(map(int, input().split()))
pref = [a[0] % 2]
for i in range(1, n):
	pref.append(pref[-1] + a[i] % 2)
rs = []
for i in range(0, n - 1):
	if i % 2 == 0:
		continue
	if pref[i] * 2 == i + 1:
		rs.append(abs(a[i + 1] - a[i]))
rs.sort()
k = 0
for i in range(len(rs)):
	if rs[i] <= b:
		b -= rs[i]
		k += 1
	else:
		break
print(k)


import math
from decimal import *
import random
mod = int(1000000000.0) + 7
(n, k) = map(int, input().split())
arr = list(map(int, input().split()))
(odd, even) = (0, 0)
pos = []
for i in range(n - 1):
	if arr[i] % 2 == 0:
		even += 1
	elif arr[i] % 2 == 1:
		odd += 1
	if odd == even:
		pos.append(abs(arr[i + 1] - arr[i]))
pos = sorted(pos)
ans = 0
if pos:
	while k - pos[ans] >= 0:
		k -= pos[ans]
		ans += 1
		if ans == len(pos):
			break
print(ans)


(s, k) = list(map(int, input().split()))
x = list(map(int, input().split()))
(o, e) = (0, 0)
sum = 0
count = 0
ans = []
for i in range(len(x) - 1):
	if x[i] % 2 == 0:
		e += 1
	else:
		o += 1
	yo = abs(x[i] - x[i + 1])
	if e == o and yo <= k:
		ans.append(yo)
ans.sort()
for j in range(len(ans)):
	ans[j] += sum
	sum = ans[j]
	if ans[j] <= k:
		count += 1
	else:
		break
print(count)


import os, sys
from collections import defaultdict, Counter, deque
from io import BytesIO, IOBase
from math import gcd

def main():
	(n, B) = map(int, input().split())
	a = [int(x) for x in input().split()]
	dp = [[0 for i in range(B + 1)] for j in range(n)]
	x = [0, 0]
	for i in range(n - 1):
		x[a[i] % 2] += 1
		for j in range(B + 1):
			dp[i][j] = dp[i - 1][j]
		if x[0] == x[1]:
			cost = abs(a[i + 1] - a[i])
			for j in range(cost, B + 1):
				dp[i][j] = max(dp[i - 1][j - cost] + 1, dp[i][j])
	print(max(dp[n - 2]))
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


(n, k) = map(int, input().split())
u = list(map(int, input().split()))
n = len(u)
p = 0
inf = 10000
ans = [inf]
for i in range(n - 1):
	if u[i] % 2 == 0:
		p -= 1
	else:
		p += 1
	if p == 0:
		ans.append(abs(u[i + 1] - u[i]))
d = []
n = len(ans) - 1
for i in range(n + 1):
	d.append([0] * (k + 1))
for i in range(1, n + 1):
	for j in range(1, k + 1):
		if ans[i] <= j:
			d[i][j] = max(d[i - 1][j], d[i][j - 1], d[i - 1][j - ans[i]] + 1)
		else:
			d[i][j] = max(d[i - 1][j], d[i][j - 1])
print(d[-1][-1])


def main():
	(n, B) = [int(c) for c in input().split()]
	a = [int(c) for c in input().split()]
	even = odd = 0
	costs = []
	for (i, e) in enumerate(a[:-1]):
		if e % 2 == 0:
			even += 1
		else:
			odd += 1
		if even == odd:
			costs.append(abs(a[i] - a[i + 1]))
	ans = 0
	for cost in sorted(costs):
		if cost <= B:
			ans += 1
			B -= cost
	print(ans)
main()


digl = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
ii = lambda : int(input())
si = lambda : input()
dgl = lambda : list(map(int, input()))
f = lambda : map(int, input().split())
il = lambda : list(map(int, input().split()))
ls = lambda : list(input())
mod = 10 ** 9 + 7
(n, k) = f()
l = il()
(es, os) = ([0], [0])
cst = []
for i in l:
	if i & 1:
		os.append(os[-1] + 1)
		es.append(es[-1])
	else:
		os.append(os[-1])
		es.append(es[-1] + 1)
for i in range(1, n):
	if os[i] == es[i]:
		cst.append(abs(l[i] - l[i - 1]))
cst.sort()
c = 0
for i in cst:
	if k - i < 0:
		break
	c += 1
	k -= i
print(c)


def cutting(n, b, a):
	i = 0
	final = []
	odd = 0
	even = 0
	ans = 1
	lastind = 0
	if n % 2 == 0:
		while i < n - 1:
			if a[i] % 2 == 0:
				even += 1
			else:
				odd += 1
			if odd == even:
				final.append(abs(a[i] - a[i + 1]))
				lastind = i
				odd = 0
				even = 0
			i = i + 1
		if abs(odd - even) != 1 or (odd < even and a[i] % 2 == 0) or (odd > even and a[i] % 2 != 0):
			print('odd-even')
			return 0
		final.sort()
		c = 0
		i = 0
		while i < len(final) and b > 0:
			if final[i] <= b:
				c = c + 1
				b = b - final[i]
			i = i + 1
		return c
	else:
		print('n odd')
		return 0
nb = list(map(int, input().rstrip().split()))
n = nb[0]
b = nb[1]
a = list(map(int, input().rstrip().split()))
print(cutting(n, b, a))


(n, b) = map(int, input().split())
arr = list(map(int, input().split()))
cost = []
(ce, co) = (0, 0)
for i in range(n - 1):
	if arr[i] % 2 == 0:
		ce += 1
	else:
		co += 1
	if ce == co:
		cost.append(abs(arr[i] - arr[i + 1]))
cost.sort()
while sum(cost) > b:
	cost.remove(cost[-1])
print(len(cost))


(n, b) = map(int, input().split())
a = [int(x) for x in input().split()]
can = []
count = [0, 0]
for (i, x) in enumerate(a[:-1]):
	count[x & 1] += 1
	if count[0] == count[1]:
		can.append(abs(x - a[i + 1]))
ans = 0
for x in sorted(can):
	if x > b:
		break
	ans += 1
	b -= x
print(ans)


(n, B) = map(int, input().split())
a = list(map(int, input().split()))
even = [0] * n
odd = [0] * n
if a[0] % 2 == 0:
	even[0] = 1
else:
	odd[0] = 1
for i in range(1, n):
	if a[i] % 2 == 0:
		even[i] = even[i - 1] + 1
		odd[i] = odd[i - 1]
	else:
		even[i] = even[i - 1]
		odd[i] = odd[i - 1] + 1
rec = [0] * n
for i in range(n):
	rec[i] = even[i] - odd[i]
cost = []
for i in range(n):
	if rec[i] == 0 and i != n - 1:
		cost.append(abs(a[i + 1] - a[i]))
cost = sorted(cost)
num = 0
j = 0
while B > 0 and j < len(cost):
	B -= cost[j]
	if B >= 0:
		num += 1
	j += 1
print(num)


(n, B) = map(int, input().split())
a = list(map(int, input().split()))
ans = []
try:
	i = 0
	while True:
		even = 0
		odd = 0
		while even != odd or even == 0:
			if a[i] % 2 == 0:
				even += 1
			else:
				odd += 1
			i += 1
		ans.append(abs(a[i - 1] - a[i]))
except IndexError:
	ans.sort()
	ct = 0
	while len(ans) > 0:
		if B - ans[0] >= 0:
			ct += 1
			B -= ans.pop(0)
		else:
			break
	print(ct)


(n, k) = list(map(int, input().split()))
p = list(map(int, input().split()))
l = 0
if p[0] % 2 == 0:
	l += 1
else:
	l -= 1
t = []
po = []
x = 1
for item in p[1:len(p) - 1]:
	if l != 0:
		if p[x] % 2 == 0:
			l += 1
			x += 1
		else:
			l -= 1
			x += 1
	elif l == 0:
		t.append(abs(p[x] - p[x - 1]))
		if p[x] % 2 == 0:
			l += 1
			x += 1
		else:
			l -= 1
			x += 1
if t != list():
	for x in range(len(t) + 9999):
		if sum(po) < k:
			jk = t.index(min(t))
			po.append(t[jk])
			t[jk] = 55555
		elif sum(po) == k:
			break
		else:
			po.pop()
			break
else:
	pass
if po == list():
	print('0')
else:
	print(len(po))


(n, k) = list(map(int, input().split()))
a = list(map(int, input().split()))
odd = [0] * n
even = [0] * n
ans = []
count = 0
if a[0] % 2 == 0:
	even[0] += 1
else:
	odd[0] += 1
for i in range(1, n - 1):
	if a[i] % 2 == 0:
		even[i] = even[i - 1] + 1
		odd[i] = odd[i - 1]
	else:
		even[i] = even[i - 1]
		odd[i] = odd[i - 1] + 1
	if odd[i] == even[i]:
		ans.append(abs(a[i + 1] - a[i]))
ans = sorted(ans)
for i in range(len(ans)):
	if ans[i] <= k:
		k -= ans[i]
		count += 1
print(count)


(n, b) = map(int, input().split())
a = [int(k) for k in input().split()]
new = []
even = 0
odd = 0
sum = 0
div = 0
for i in range(n - 1):
	if a[i] % 2 == 0:
		even += 1
	else:
		odd += 1
	if odd == even:
		new.append(abs(a[i] - a[i + 1]))
new.sort()
for i in new:
	sum += i
	if sum > b:
		break
	div += 1
print(div)


from sys import stdin, stdout
nmbr = lambda : int(stdin.readline())
lst = lambda : list(map(int, stdin.readline().split()))
for _ in range(1):
	(n, b) = lst()
	a = lst()
	ans = []
	o = e = 0
	for i in range(n):
		if a[i] & 1:
			o += 1
		else:
			e += 1
		if o == e:
			if i + 1 < n:
				ans += [abs(a[i] - a[i + 1])]
				o = e = 0
	ans.sort()
	sm = cnt = 0
	for v in ans:
		sm += v
		if sm > b:
			break
		cnt += 1
	print(cnt)


(n, B) = map(int, input().split())
s = [int(i) for i in input().split()]
r = []
even = int(s[0] % 2 == 0)
odd = int(s[0] % 2 != 0)
ans = 0
cnt = 0
count = 0
for i in range(1, n - 1):
	if s[i] % 2 == 0:
		even += 1
	else:
		odd += 1
	a = abs(s[i] - s[i + 1])
	if odd == even:
		r.append(a)
r.sort()
for i in range(len(r)):
	if cnt + r[i] > B:
		ans = count
		break
	count += 1
	cnt += r[i]
print(max(ans, count))


(n, B) = map(int, input().split())
a = [int(x) for x in input().split()]
even = 0
odd = 0
start = 0
pos = []
for i in range(0, n):
	if a[i] % 2 == 0:
		even += 1
	else:
		odd += 1
	if even == odd:
		pos.append((start, i))
		start = i + 1
		even = 0
		odd = 0
if len(pos) == 1:
	print('0')
else:
	cost = []
	for i in range(len(pos) - 1):
		cost.append(abs(a[pos[i][1]] - a[pos[i + 1][0]]))
	cost.sort()
	m = 0
	count = 0
	for x in cost:
		m += x
		if m <= B:
			count += 1
		else:
			break
	print(count)


import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
sys.setrecursionlimit(10000)

def read_int():
	return int(input())

def read_int_n():
	return list(map(int, input().split()))

def read_float():
	return float(input())

def read_float_n():
	return list(map(float, input().split()))

def read_str():
	return input()

def read_str_n():
	return list(map(str, input().split()))

def error_print(*args):
	print(*args, file=sys.stderr)

def mt(f):
	import time

	def wrap(*args, **kwargs):
		s = time.time()
		ret = f(*args, **kwargs)
		e = time.time()
		error_print(e - s, 'sec')
		return ret
	return wrap

@mt
def slv(N, B, A):
	ans = 0
	A = [[(-1 if a % 2 == 1 else 1, a) for a in A]]
	while True:
		div_cnd = []
		for (i, a) in enumerate(A):
			s = 0
			for j in range(1, len(a)):
				if sum(map(lambda x: x[0], a[:j])) == 0 and sum(map(lambda x: x[0], a[j:])) == 0:
					div_cnd.append((abs(a[j][1] - a[j - 1][1]), i, j))
		if len(div_cnd) == 0:
			break
		d = min(div_cnd, key=lambda x: x[0])
		if d[0] <= B:
			B -= d[0]
			a = A.pop(d[1])
			A.append(a[:d[2]])
			A.append(a[d[2]:])
			ans += 1
		else:
			break
	return ans

def main():
	(N, B) = read_int_n()
	A = read_int_n()
	print(slv(N, B, A))
main()


import math
(n, b) = map(int, input().split())
arr = list(map(int, input().split()))
f = 0
count = 0
counteven = 0
count_odd = 0
index = []
for i in range(len(arr)):
	if arr[i] % 2 == 0:
		counteven += 1
	else:
		count_odd += 1
	if counteven == count_odd:
		index.append(i)
ans = []
for i in range(len(index)):
	if index[i] + 1 < n and abs(arr[index[i]] - arr[index[i] + 1]) <= b:
		ans.append(abs(arr[index[i]] - arr[index[i] + 1]))
ans = sorted(ans)
for i in range(len(ans)):
	f += ans[i]
	if f <= b:
		count += 1
print(count)


(n, b) = input().strip().split(' ')
(n, b) = (int(n), int(b))
arr = list(map(int, input().strip().split(' ')))
arr += [0, 0]
dp = []
for i in range(n + 2):
	dp.append([])
	for j in range(b + 1):
		dp[-1].append(-1)
for j in range(b + 1):
	dp[1][j] = 0
a = [0] * (n + 2)
for i in range(n):
	a[i + 1] = arr[i]
a[n + 1] = a[n]
for i in range(2, n + 2):
	for j in range(b + 1):
		c = abs(a[i] - a[i - 1])
		if j - c < 0:
			continue
		(o, e) = (0, 0)
		mx = -1
		for k in range(i - 1, 0, -1):
			if a[k] % 2:
				o += 1
			else:
				e += 1
			if o == e and dp[k][j - c] != -1:
				mx = max(mx, 1 + dp[k][j - c])
		dp[i][j] = mx
print(dp[n + 1][b] - 1)


(n, b) = map(int, input().split())
a = [int(i) for i in input().split()]
dp = [[0 for _ in range(b + 1)] for _ in range(n)]
for j in range(1, b + 1):
	for i in range(n - 2, -1, -1):
		val = 0
		count = 0
		for k in range(i, n - 1):
			if a[k] % 2 == 0:
				count += 1
			else:
				count -= 1
			if k > i and count == 0:
				x = abs(a[k + 1] - a[k])
				if j - x >= 0:
					val = max(val, 1 + dp[k + 1][j - x])
		dp[i][j] = val
print(dp[0][b])


(n, b) = [int(x) for x in input().split(' ')]
a = [int(x) for x in input().split(' ')]
splits = []
rc = 0
for i in range(n - 1):
	rc += (-1) ** a[i]
	if rc == 0:
		splits.append(abs(a[i + 1] - a[i]))
splits.sort()
rs = 0
cnt = 0
for s in splits:
	rs += s
	if rs <= b:
		cnt += 1
	else:
		break
print(cnt)


(n, k) = list(map(int, input().split()))
seq = list(map(int, input().split()))
curr = 0
cut = []
for i in range(n - 1):
	if seq[i] % 2:
		curr += 1
	else:
		curr -= 1
	if curr == 0:
		cut.append(abs(seq[i] - seq[i + 1]))
cut.sort()
ans = 0
currsum = 0
for i in cut:
	currsum += i
	if currsum > k:
		break
	else:
		ans += 1
print(ans)


from sys import stdin
input = lambda : stdin.readline()
from math import ceil, sqrt, gcd
(n, k) = map(int, input().split())
l = list(map(int, input().split()))
z = []
(a, b) = (0, 0)
for i in range(n):
	if l[i] % 2 == 0:
		a += 1
	else:
		b += 1
	if a == b and i != n - 1:
		z.append(abs(l[i] - l[i + 1]))
z.sort()
count = 0
i = 0
while i < len(z) and k >= z[i]:
	count += 1
	k -= z[i]
	i += 1
print(count)


import math
(n, B) = map(int, input().split())
a = list(map(int, input().split()))
c2 = [0] * n
if a[0] % 2 == 0:
	c2[0] = 1
for i in range(1, n):
	if a[i] % 2 == 0:
		c2[i] = c2[i - 1] + 1
	else:
		c2[i] = c2[i - 1]
ans = 0
nu = list(range(n - 1))
while ans < n and B > 0:
	rm = 9000000
	mn = 9000000
	for i in range(0, len(nu)):
		if c2[nu[i]] == nu[i] + 1 - c2[nu[i]]:
			if mn > abs(a[nu[i]] - a[nu[i] + 1]):
				mn = abs(a[nu[i]] - a[nu[i] + 1])
				rm = i
	if rm == 9000000 or B < mn:
		break
	else:
		B -= mn
		ans += 1
		del nu[rm]
print(ans)


(n, B) = map(int, input().split())
a = list(map(int, input().split()))
s = [(0, 0)]
for i in a:
	s.append((s[-1][0] + i % 2, s[-1][1] + 1 - i % 2))
del s[0]
m = []
for e in range(n - 1):
	if s[e][0] == s[e][1]:
		m.append(abs(a[e] - a[e + 1]))
c = d = 0
for j in sorted(m):
	d += j
	if d > B:
		break
	c += 1
print(c)


def main():
	rd = lambda : list(map(int, input().split()))
	(n, b) = rd()
	arr = rd()
	even = 0
	tmp = []
	for i in range(n - 1):
		if arr[i] % 2 == 0:
			even += 1
		else:
			even -= 1
		if even == 0:
			tmp.append(abs(arr[i] - arr[i + 1]))
	tmp.sort()
	cnt = 0
	for val in tmp:
		if b < val:
			break
		cnt += 1
		b -= val
	print(cnt)
main()


from sys import stdin, stdout
nmbr = lambda : int(stdin.readline())
lst = lambda : list(map(int, stdin.readline().split()))
for _ in range(1):
	(n, k) = lst()
	a = lst()
	even = odd = ans = 0
	cost = []
	for i in range(n):
		if a[i] & 1:
			odd += 1
		else:
			even += 1
		if even == odd:
			if i + 1 < n:
				cost += [abs(a[i] - a[i + 1])]
	cost.sort()
	for v in cost:
		if k - v < 0:
			break
		k -= v
		ans += 1
	print(ans)


(n, b) = [int(c) for c in input().split(' ')]
a = [int(c) for c in input().split(' ')]
evenodd = []
evenodd_cur = 0
for i in range(n):
	if a[i] % 2 == 0:
		evenodd_cur += 1
	else:
		evenodd_cur -= 1
	evenodd.append(evenodd_cur)
watchlist = []
for i in range(n - 1):
	if evenodd[i] == 0:
		watchlist.append((abs(a[i] - a[i + 1]), i))
watchlist.sort()
totalcount = 0
for (price, index) in watchlist:
	if b >= price:
		totalcount += 1
		b -= price
	else:
		break
print(totalcount)


(n, B) = map(int, input().split())
a = list(map(int, input().split()))
cuts = []
even = 0
odd = 0
for (i, x) in enumerate(a):
	if x % 2:
		odd += 1
	else:
		even += 1
	if odd == even and i != n - 1:
		odd = 0
		even = 0
		cuts.append(abs(x - a[i + 1]))
cuts = sorted(cuts)
total = 0
while cuts and B - cuts[0] >= 0:
	re = cuts.pop(0)
	B -= re
	total += 1
print(total)


(n, B) = map(int, input().split())
items = [int(k) for k in input().split() if k]
dp = [-1000000000 for _ in range(B + 1)]
dp[0] = 0
even = 0
odd = 0
totalEven = 0
totalOdd = 0
for i in range(n):
	if items[i] % 2 == 0:
		totalEven += 1
	else:
		totalOdd += 1
for i in range(n):
	if items[i] % 2 == 0:
		even += 1
	else:
		odd += 1
	if i + 1 < n and even == odd and (totalEven - even == totalOdd - odd):
		cost = abs(items[i] - items[i + 1])
		dpCopy = dp[:]
		for j in range(cost, B + 1):
			dpCopy[j] = max(dp[j], dp[j - cost] + 1)
		dp = dpCopy
print(max(dp))


(N, B) = map(int, input().split())
numbers = list(map(int, input().split()))
costs = []
div_possible = list(map(lambda x: x % 2 == 0, numbers))
costs = []
current_even = 0
current_odd = 0
for i in range(len(div_possible) - 1):
	divisible = numbers[i] % 2
	current_even += divisible
	current_odd += not divisible
	if current_even == current_odd:
		costs.append(abs(numbers[i + 1] - numbers[i]))
divisible = numbers[len(numbers) - 1] % 2
current_even += divisible
current_odd += not divisible
if current_even != current_odd:
	print(0)
else:
	costs.sort()
	div_count = 0
	for cost in costs:
		B -= cost
		if B >= 0:
			div_count += 1
		else:
			break
	print(div_count)


R = lambda : map(int, input().split())
(n, B) = R()
a = list(R())
b = []
cnt = 1 if a[0] % 2 else -1
for i in range(1, n - 1):
	cnt += 1 if a[i] % 2 else -1
	if cnt == 0:
		b.append(abs(a[i] - a[i + 1]))
b.sort()
cnt = 0
i = 0
while i < len(b) and cnt + b[i] <= B:
	cnt += b[i]
	i += 1
print(i)


(n, b) = map(int, input().split())
l = list(map(int, input().split()))
odd = 0
eve = 0
temp = []
for i in range(n - 1):
	if l[i] % 2 == 0:
		eve += 1
	else:
		odd += 1
	if eve == odd:
		temp.append(abs(l[i + 1] - l[i]))
		eve = 0
		odd = 0
temp.sort()
ans = 0
c = 0
for i in range(len(temp)):
	c += temp[i]
	if c > b:
		break
	else:
		ans += 1
print(ans)


(n, b) = map(int, input().split())
a = list(map(int, input().split()))
a_cost = []
res = 0
c = 0
for i in range(n - 1):
	if a[i] % 2 == 0:
		c += 1
	else:
		c -= 1
	if i > 0 and c == 0:
		a_cost.append(abs(a[i] - a[i + 1]))
a_cost.sort()
while b > 0 and a_cost:
	res += 1
	b -= a_cost.pop(0)
print(res if b >= 0 else res - 1)


(n, b) = map(int, input().split())
arr = list(map(int, input().split()))
money = list()
c0 = 0
c1 = 0
for i in range(n - 1):
	if arr[i] % 2 == 0:
		c0 += 1
	else:
		c1 += 1
	if c0 == c1 != 0:
		money.append(abs(arr[i] - arr[i + 1]))
		(c0, c1) = (0, 0)
money.sort()
count = 0
for i in money:
	if b - i >= 0:
		count += 1
		b -= i
	else:
		break
print(count)


(n, b) = map(int, input().split())
a = list(map(int, input().split()))
no = ne = 0
cuts = []
for (i, x) in enumerate(a):
	if x % 2 == 0:
		ne += 1
	else:
		no += 1
	if ne == no and i < n - 1:
		cuts.append(abs(a[i + 1] - a[i]))
cuts.sort(reverse=True)
i = 0
s = 0
while cuts and s + cuts[-1] <= b:
	s += cuts.pop()
	i += 1
print(i)


from functools import cmp_to_key
s = input()
s = s.split(' ')
n = int(s[0])
B = int(s[1])
s = input()
s = s.split(' ')
a = []
x = 0
y = 0
cut = []
for i in range(0, n):
	a.append(int(s[i]))
for i in range(0, n - 1):
	if a[i] % 2 == 0:
		x += 1
	else:
		y += 1
	if x == y:
		z = a[i + 1] - a[i]
		if z < 0:
			z = -z
		cut.append(z)
cut.sort()
ans = 0
tot = 0
for i in range(0, len(cut)):
	tot += cut[i]
	if tot <= B:
		ans += 1
print(ans)


(n, b) = map(int, input().split())
a = list(map(int, input().split()))

def isequal(c):
	k = len(c)
	count = 0
	for i in c:
		if i % 2 == 0:
			count += 1
	return count == k / 2
if n <= 3 or n % 2 == 1:
	print(0)
else:
	temp = []
	for i in range(1, n - 1, 2):
		if isequal(a[:i + 1]) and isequal(a[i + 1:]):
			temp.append(abs(a[i] - a[i + 1]))
	if sum(temp) <= b:
		print(len(temp))
	else:
		count = 0
		temp.sort()
		sum1 = 0
		for i in temp:
			sum1 += i
			if sum1 <= b:
				count += 1
			else:
				break
		print(count)


(n, coins) = map(int, input().split())
sequence = list(map(int, input().split()))
n_odd = 0
n_even = 0
cuts = []
n_cuts = 0
ans = 0
for i in range(n):
	if n_odd == n_even and n_even != 0:
		cuts.append(sequence[i] - sequence[i - 1])
		if cuts[n_cuts] < 0:
			cuts[n_cuts] *= -1
		n_cuts += 1
	if sequence[i] % 2 == 0:
		n_even += 1
	else:
		n_odd += 1
cuts.sort()
for i in range(n_cuts):
	coins -= cuts[i]
	if coins >= 0:
		ans += 1
	else:
		break
print(ans)


def main():
	(n, b) = [int(i) for i in input().split(' ')]
	a = [int(i) for i in input().split(' ')]
	a_ = []
	for i in range(n):
		a_.append(1 if a[i] % 2 == 0 else -1)
	diff = []
	for i in range(n - 1):
		diff.append((i, abs(a[i] - a[i + 1])))
	diff.sort(key=lambda x: x[1])
	ans = 0
	for i in range(n - 1):
		if diff[i][1] <= b and sum(a_[:diff[i][0] + 1]) == 0 and (sum(a_[diff[i][0] + 1:]) == 0):
			ans += 1
			b -= diff[i][1]
	print(ans)
main()


(n, m) = list(map(int, input().split()))
ls = [int(i) for i in input().split()]
(odd_num, even_num) = (0, 0)
cur_odd = 0
cur_even = 0
ans = []
for i in range(n - 2):
	if ls[i] & 1:
		cur_odd += 1
	else:
		cur_even += 1
	if i >= 1 and cur_odd == cur_even:
		ans.append(abs(ls[i + 1] - ls[i]))
ans.sort()
res = 0
for i in ans:
	if m - i >= 0:
		m -= i
		res += 1
	else:
		break
print(res)


(n, b) = map(int, input().split())
a = list(map(int, input().split()))
(ocount, ecount) = (0, 0)
ans = []
for i in range(n):
	if a[i] & 1:
		ocount += 1
	else:
		ecount += 1
	if ocount == ecount and i != n - 1:
		ans.append(abs(a[i] - a[i + 1]))
ans.sort()
cnt = 0
for i in ans:
	if b >= i:
		cnt += 1
		b -= i
	else:
		break
print(cnt)


(n, B) = map(int, input().split())
a = input().split()
for i in range(n):
	a[i] = int(a[i])
b = []
c1 = 0
c2 = 0
if a[0] % 2 == 0:
	c1 += 1
else:
	c2 += 1
for i in range(1, n):
	if c1 == c2:
		b.append(abs(a[i] - a[i - 1]))
	if a[i] % 2 == 0:
		c1 += 1
	else:
		c2 += 1
b.sort()
count = 0
for i in range(len(b)):
	if B >= b[i]:
		count += 1
		B -= b[i]
print(count)


(n, bit) = map(int, input().split())
arr = list(map(int, input().split()))
odd = 0
even = 0
coin = 0
part = 0
d = []
for r in range(len(arr) - 1):
	if arr[r] % 2 == 0:
		even += 1
	else:
		odd += 1
	if odd == even:
		d.append(abs(arr[r + 1] - arr[r]))
d = sorted(d)
for r in range(len(d)):
	coin += d[r]
	if coin > bit:
		break
if coin > bit:
	print(r)
else:
	print(len(d))


import sys
sys.setrecursionlimit(2000)
inf = float('inf')
mod = 1000000007

def get_array():
	return list(map(int, sys.stdin.readline().split()))

def get_ints():
	return map(int, sys.stdin.readline().split())

def input():
	return sys.stdin.readline()

def recurse(difference, arr, i, b, dp):
	if b < 0:
		return -1 * inf
	if i == len(difference) - 1:
		return 0
	if dp[i][b] != None:
		return dp[i][b]
	if difference[i] == 0:
		dp[i][b] = max(1 + recurse(difference, arr, i + 1, b - abs(arr[i + 1] - arr[i]), dp), recurse(difference, arr, i + 1, b, dp))
	else:
		dp[i][b] = recurse(difference, arr, i + 1, b, dp)
	return dp[i][b]

def main():
	(n, b) = get_ints()
	arr = get_array()
	difference = [0] * n
	(count_even, count_odd) = (0, 0)
	for i in range(n):
		if arr[i] & 1 != 0:
			count_odd += 1
		else:
			count_even += 1
		difference[i] = abs(count_odd - count_even)
	dp = [[None for _ in range(b + 1)] for _ in range(n + 1)]
	print(recurse(difference, arr, 0, b, dp))
main()


(n, k) = input().split()
n = int(n)
k = int(k)
a = [int(x) for x in input().split()]
(odd, even) = (0, 0)
l = []
for i in range(n):
	if a[i] % 2 == 0:
		even += 1
	else:
		odd += 1
	if even == odd and i > 0 and (i < n - 1):
		t = abs(a[i] - a[i + 1])
		l.append(t)
(total, ans) = (0, 0)
l.sort()
for i in l:
	total += i
	if total <= k:
		ans += 1
print(ans)


(n, b) = list(map(int, input().split()))
al = list(map(int, input().split()))
od = (al[0] % 2 << 1) - 1
cl = []
for i in range(1, n - 2):
	od += (al[i] % 2 << 1) - 1
	if od == 0:
		d = al[i + 1] - al[i]
		cl.append(d if d > 0 else -d)
		od = 0
cl.sort()
s = 0
i = 0
while i < len(cl):
	s += cl[i]
	if s > b:
		break
	i += 1
print(i)


(n, b) = map(int, input().split())
arr = list(map(int, input().split()))
cuts = []
count = 0
for i in range(n - 1):
	if arr[i] % 2 == 0:
		count += 1
	else:
		count -= 1
	if count == 0:
		cuts.append(abs(arr[i] - arr[i + 1]))
cuts.sort()
i = 0
sm = 0
while i < len(cuts) and sm + cuts[i] <= b:
	sm += cuts[i]
	i += 1
print(i)


(n, B) = map(int, input().split())
a = list(map(int, input().split()))
b = []
c1 = 0
c2 = 0
for i in range(0, n - 1):
	if a[i] % 2 == 0:
		c1 += 1
	if a[i] % 2 != 0:
		c2 += 1
	if c1 == c2 and c1 != 0:
		b.append(abs(a[i] - a[i + 1]))
b.sort()
sum = 0
c = 0
for items in b:
	if items + sum <= B:
		sum += items
		c += 1
print(c)


(n, B) = [int(ele) for ele in str(input()).split()]
a = [0] + [int(ele) for ele in str(input()).split()]
canSplit = [0 for ele in range(n + 2)]
oddAll = 0
eveAll = 0
for idx in range(1, n + 1):
	if a[idx] % 2 == 0:
		eveAll = eveAll + 1
	else:
		oddAll = oddAll + 1
oddNow = 0
eveNow = 0
for idx in range(1, n + 1):
	if a[idx] % 2 == 0:
		eveNow = eveNow + 1
		eveAll = eveAll - 1
	else:
		oddNow = oddNow + 1
		oddAll = oddAll - 1
	if oddNow == eveNow and oddAll == eveAll:
		canSplit[idx] = 1
canSplit[0] = 1
canSplit[n + 1] = 0
depth = [[-1 for c in range(B + 2)] for r in range(n + 2)]
depth[0][0] = 0
res = 0
for p2 in range(1, n):
	if canSplit[p2] == 0:
		continue
	p2cost = abs(a[p2] - a[p2 + 1])
	for cost in range(p2cost, B + 1):
		maxVal = -1
		if depth[p2][cost] != -1:
			maxVal = depth[p2][cost]
		for p1 in range(0, p2):
			if canSplit[p1] == 0:
				continue
			if depth[p1][cost - p2cost] == -1:
				continue
			if maxVal < depth[p1][cost - p2cost] + 1:
				maxVal = depth[p1][cost - p2cost] + 1
		depth[p2][cost] = maxVal
		if depth[p2][cost] > res:
			res = depth[p2][cost]
print(res)


from sys import stdin, stdout
from queue import PriorityQueue

def main():
	(n, b) = [int(i) for i in stdin.readline().split()]
	a = [int(i) for i in stdin.readline().split()]
	q = PriorityQueue()
	evens = 0
	for i in range(n - 1):
		if a[i] % 2 == 0:
			evens += 1
		else:
			evens -= 1
		if evens == 0:
			q.put(abs(a[i] - a[i + 1]))
	count = 0
	while not q.empty():
		smallest = q.get()
		if b >= smallest:
			b -= smallest
			count += 1
		else:
			break
	print(count)
main()


(n, b) = map(int, input().split())
a = list(map(int, input().split()))
count = 0
lst = []
for i in range(n - 1):
	if a[i] % 2 == 0:
		count += 1
	elif a[i] % 2 == 1:
		count -= 1
	if count == 0:
		lst.append(abs(a[i + 1] - a[i]))
lst.sort()
ans = 0
sum = 0
for i in range(len(lst)):
	ans += 1
	sum += lst[i]
	if sum > b:
		ans -= 1
		break
print(ans)


(n, b) = map(int, input().split())
a = list(map(int, input().split()))
cuts = []
c = 0
for i in range(len(a) - 1):
	e = a[i]
	if e % 2 == 0:
		c += 1
	else:
		c -= 1
	if c == 0:
		cuts.append(abs(a[i] - a[i + 1]))
cuts.sort()
count = 0
for e in cuts:
	if b - e >= 0:
		b -= e
		count += 1
print(count)


(n, b) = map(int, input().split())
arr = list(map(int, input().split()))
even = []
odd = []
ev = 0
od = 0
for i in range(n):
	if arr[i] % 2 == 0:
		ev += 1
		even.append(ev)
		odd.append(od)
	else:
		od += 1
		odd.append(od)
		even.append(ev)
res = []
for i in range(n):
	if even[i] == odd[i] and i != n - 1:
		res.append(abs(arr[i] - arr[i + 1]))
arr1 = []
l = len(res)
for i in range(l + 1):
	c = []
	for j in range(b + 1):
		c.append(0)
	arr1.append(c.copy())
for i in range(1, l + 1):
	for j in range(1, b + 1):
		if res[i - 1] <= j:
			arr1[i][j] = max(1 + arr1[i - 1][j - res[i - 1]], arr1[i - 1][j])
		else:
			arr1[i][j] = arr1[i - 1][j]
print(arr1[-1][-1])


def single():
	return int(input())

def multiple():
	return list(map(int, input().split()))
(n, cost) = multiple()
arr = multiple()

def fun(arr):
	n = len(arr)
	cuts = []
	i = 0
	f = 0
	while i < n:
		d = {0: 0, 1: 0}
		while i < n:
			d[arr[i] % 2] += 1
			if d[0] == d[1]:
				if i != n - 1:
					cuts.append(abs(arr[i + 1] - arr[i]))
				else:
					f = 1
				break
			i += 1
		i += 1
	return [cuts, f]
(a, possible) = fun(arr)
if possible:
	a.sort()
	l = len(a)
	i = 0
	curr = 0
	while i < l and curr < cost:
		curr += a[i]
		if curr > cost:
			break
		i += 1
	print(i)
else:
	print(0)


(n, b) = map(int, input().split())
arr = list(map(int, input().split()))
odd_cnt = 0
even_cnt = 0
seg = []
for i in range(n):
	if arr[i] % 2 == 1:
		odd_cnt += 1
	else:
		even_cnt += 1
	if odd_cnt == even_cnt:
		odd_cnt = 0
		even_cnt = 0
		if i != n - 1:
			seg.append(abs(arr[i + 1] - arr[i]))
if odd_cnt != even_cnt:
	print(0)
	exit(0)
seg.sort()
cnt = 0
sum = 0
for i in seg:
	sum += i
	if sum > b:
		print(cnt)
		exit(0)
	cnt += 1
else:
	print(cnt)


(n, c) = [int(x) for x in input().split()]
ns = [int(x) for x in input().split()]
odd = 0
cost = []
for i in range(n):
	if ns[i] & 1 == 1:
		odd += 1
	else:
		odd -= 1
	if odd == 0:
		if i < n - 1:
			cost.append(abs(ns[i + 1] - ns[i]))
cost.sort()
sum = 0
p = False
for i in range(len(cost)):
	sum += cost[i]
	if sum > c:
		print(i)
		p = True
		break
if not p:
	print(len(cost))


import sys
import math as mt
input = sys.stdin.buffer.readline
t = 1
for __ in range(t):
	(n, b) = map(int, input().split())
	l = list(map(int, input().split()))
	(e, o) = (0, 0)
	ans = []
	for i in range(n):
		if l[i] % 2 == 0:
			e += 1
		else:
			o += 1
		if e == o:
			if i != n - 1:
				ans.append(abs(l[i] - l[i + 1]))
	suma = 0
	ans1 = 0
	ans.sort()
	for i in range(len(ans)):
		if ans[i] + suma <= b:
			suma += ans[i]
			ans1 += 1
		else:
			break
	print(ans1)


class Solution(object):

	def __init__(self):
		pass

	def cutting(self, arr, b):
		acc = [0]
		for i in arr:
			acc.append(acc[-1] + (i & 1))
		ls = []
		n = len(arr)
		for i in range(0, n - 1):
			if (i + 1) % 2 == 0 and acc[i + 1] * 2 == i + 1 and (2 * (acc[n] - acc[i + 1]) == n - i - 1):
				ls.append(abs(arr[i + 1] - arr[i]))
		ls.sort()
		c = 0
		for i in ls:
			b -= i
			if b < 0:
				break
			c += 1
		return c

	def _cutting(self, arr, b):
		self.acc = [0]
		for i in arr:
			self.acc.append(self.acc[-1] + (i & 1))
		return self.best(0, len(arr) - 1, b, arr, {})

	def check(self, i, j):
		n = self.acc[j] - self.acc[i - 1]
		return 2 * n == j - i + 1

	def best(self, i, j, b, arr, tb):
		if b < 0 or i == j or j - i + 1 & 1 != 0:
			return -(1 << 31)
		if (i, j, b) in tb:
			return tb[i, j, b]
		sl = -(1 << 31)
		for k in range(i + 1, j):
			n_b = b - abs(arr[k + 1] - arr[k])
			for l in range(0, n_b + 1):
				rs = self.best(i, k, l, arr, tb) + self.best(k + 1, j, n_b - l, arr, tb)
				if rs > 0 and sl < rs:
					sl = rs
		if self.check(i + 1, j + 1) and sl <= 0:
			sl = 1
		tb[i, j, b] = sl
		return sl

def main():
	p = [int(e) for e in input().split()]
	arr = [int(e) for e in input().split()]
	sol = Solution()
	sets = sol.cutting(arr, p[1])
	if sets <= 0:
		print('0')
	else:
		print(sets)
	return 0
main()


(n, B) = list(map(int, input().split()))
A = list(map(int, input().split()))
(n1, n2) = (0, 0)
pre = 0
L = []
for val in range(n - 1):
	if A[val] % 2 == 0:
		n1 += 1
	else:
		n2 += 1
	if n1 == n2:
		L.append(abs(A[val] - A[val + 1]))
	pre = A[val]
L.sort()
if len(L) == 0:
	print(0)
else:
	count = 0
	for val in L:
		B -= val
		if B >= 0:
			count += 1
	print(count)


(n, B) = map(int, input().split())
l = list(map(int, input().split()))
odd = 0
even = 0
k = []
for i in range(n):
	if l[i] % 2 == 0:
		odd = odd + 1
	elif l[i] % 2 == 1:
		even = even + 1
	if odd == even and i != n - 1:
		k.append(abs(l[i + 1] - l[i]))
k.sort()
if len(k) == 0:
	print(0)
	exit()
for i in range(len(k)):
	B = B - k[i]
	if B == 0:
		print(i + 1)
		exit()
	if B < 0:
		print(i)
		exit()
print(i + 1)


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
ans = []
odd = 0
even = 0
for t in range(n):
	if l[t] % 2:
		odd += 1
	else:
		even += 1
	if odd == even and t + 1 < n:
		ans.append(abs(l[t + 1] - l[t]))
ans.sort()
i = 0
v = 0
for t in ans:
	v += t
	if v <= k:
		i += 1
	else:
		break
print(i)


def func(no_of_items, max_weight, profit, weight):
	matrix = [[0 for i in range(max_weight + 1)] for j in range(no_of_items + 1)]
	for i in range(1, no_of_items + 1):
		for j in range(1, max_weight + 1):
			if j < int(weight[i - 1]):
				matrix[i][j] = matrix[i - 1][j]
			elif j >= int(weight[i - 1]):
				matrix[i][j] = max(matrix[i - 1][j], int(profit[i - 1]) + matrix[i - 1][j - int(weight[i - 1])])
	print(matrix[no_of_items][max_weight])
(n, b) = map(int, input().split())
arr = input().split()
even = 0
odd = 0
for a in arr:
	if int(a) % 2 == 0:
		even += 1
	else:
		odd += 1
if even != odd:
	print(0)
else:
	even = 0
	odd = 0
	lis = []
	for i in range(n):
		if int(arr[i]) % 2 == 0:
			even += 1
		else:
			odd += 1
		if even == odd and i != n - 1:
			lis.append(max(int(arr[i]), int(arr[i + 1])) - min(int(arr[i]), int(arr[i + 1])))
	n = len(lis)
	profit = [1 for i in range(n)]
	func(n, b, profit, lis)


from __future__ import print_function
import pprint
import sys
import math
import os.path
import random
from copy import deepcopy
from functools import reduce
from collections import Counter, ChainMap, defaultdict
from itertools import cycle, chain
from queue import Queue, PriorityQueue
from heapq import heappush, heappop, heappushpop, heapify, heapreplace, nlargest, nsmallest
import bisect
from statistics import mean, mode, median, median_low, median_high
sys.setrecursionlimit(10 ** 9)

def log(*args, **kwargs):
	print(*args, file=sys.stderr, **kwargs)

def ni():
	return map(int, input().split())

def nio(offset):
	return map(lambda x: int(x) + offset, input().split())

def nia():
	return list(map(int, input().split()))

def toString(aList, sep=' '):
	return sep.join((str(x) for x in aList))

def toMapInvertIndex(aList):
	return {k: v for (v, k) in enumerate(aList)}

def sortId(arr):
	return sorted(range(arr), key=lambda k: arr[k])
(n, B) = ni()
a = nia()
a.insert(0, 0)
MAX = 111
countC = [0] * MAX
countL = [0] * MAX
for i in range(1, n + 1):
	if a[i] % 2 == 0:
		countC[i] = 1
	else:
		countL[i] = 1
	if i > 0:
		countC[i] += countC[i - 1]
		countL[i] += countL[i - 1]
l = [[0] * MAX for _ in range(MAX)]
for i in range(2, n + 1, 2):
	for j in range(B + 1):
		for ii in range(2, i, 2):
			(c1, l1) = (countC[ii], countL[ii])
			c2 = countC[i] - countC[ii]
			l2 = countL[i] - countL[ii]
			cost = abs(a[ii + 1] - a[ii])
			if c1 == l1 and c2 == l2 and (j >= cost):
				l[i][j] = max(l[i][j], l[ii][j - cost] + 1)
print(l[n][B])


(n, m) = map(int, input().split())
ls = list(map(int, input().split()))
bls = list()
od = 0
ev = 0
for i in range(n):
	if ls[i] % 2:
		od += 1
	else:
		ev += 1
	if ev == od:
		if i + 1 != n:
			bls.append(abs(ls[i] - ls[i + 1]))
ln = len(bls)
if ln == 0:
	print(0)
else:
	bls = sorted(bls)
	c = 0
	for i in range(ln):
		if m - bls[i] < 0:
			break
		c += 1
		m -= bls[i]
	print(c)


def readline():
	return map(int, input().split())

def main():
	(n, bitcoins) = readline()
	seq = readline()
	possible_cuts = list()
	prev = next(seq)
	balance = 1 if prev & 1 else -1
	for curr in seq:
		if balance == 0:
			possible_cuts.append(abs(curr - prev))
		balance += 1 if curr & 1 else -1
		prev = curr
	cuts_count = 0
	for cut in sorted(possible_cuts):
		if bitcoins < cut:
			break
		bitcoins -= cut
		cuts_count += 1
	print(cuts_count)
main()


(n, b) = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
k = [0, 0]
dp = []
for i in range(len(a) - 1):
	k[a[i] % 2] += 1
	if k[0] == k[1]:
		dp.append(abs(a[i] - a[i + 1]))
dp.sort()
sm = 0
i = 0
while i < len(dp):
	if dp[i] + sm > b:
		break
	sm += dp[i]
	i += 1
print(i)


(n, b) = map(int, input().split())
a = list(map(int, input().split()))
c = 0
ans = []
for i in range(n - 1):
	if a[i] % 2:
		c += 1
	else:
		c -= 1
	if c == 0:
		ans.append(abs(a[i] - a[i + 1]))
if len(ans) == 0:
	print(0)
else:
	ans.sort()
	i = s = 0
	while i < len(ans) and s + ans[i] <= b:
		s += ans[i]
		i += 1
	print(i)


import heapq
header = input()
header = [int(i) for i in header.split()]
bitcoins = header[1]
n = header[0]
nums = input()
nums = [int(i) for i in nums.split()]
numOdds = 0
numEvens = 0
heap = []
for i in range(len(nums) - 1):
	if nums[i] % 2 == 0:
		numEvens += 1
	else:
		numOdds += 1
	if numEvens == numOdds:
		cost = nums[i + 1] - nums[i]
		if cost < 0:
			cost = cost * -1
		heapq.heappush(heap, (cost, i))
remaining = bitcoins
cuts = 0
while remaining > 0:
	if len(heap) <= 0:
		break
	newCut = heapq.heappop(heap)
	if newCut[0] <= remaining:
		remaining -= newCut[0]
		cuts += 1
	else:
		remaining = 0
print(cuts)


from itertools import *
R = lambda : map(int, input().split())
(n, b) = R()
a = [*R()]
c = [0, 0]
r = []
for (x, y) in zip(a, a[1:]):
	c[x % 2] += 1
	if c[0] == c[1]:
		r += [abs(x - y)]
r.sort()
print(next((i for (i, x) in enumerate(accumulate(r)) if x > b), len(r)))


import sys
import math
from collections import OrderedDict

def input():
	return sys.stdin.readline().strip()

def iinput():
	return int(input())

def minput():
	return map(int, input().split())

def listinput():
	return list(map(int, input().split()))
(n, b) = minput()
l = listinput()
co = 0
ce = 0
count = 0
ans = []
for i in range(n - 1):
	if l[i] % 2 == 0:
		ce += 1
	else:
		co += 1
	if co == ce:
		ans.append(abs(l[i] - l[i + 1]))
ans = sorted(ans)
for i in ans:
	if b - i >= 0:
		b -= i
		count += 1
print(count)


(n, b) = input().split()
n = int(n)
b = int(b)
a = [int(x) for x in input().split()]
odd = 0
not_odd = 0
pos = list()
for i in range(n - 1):
	if a[i] % 2 == 0:
		not_odd += 1
	else:
		odd += 1
	if not_odd == odd:
		pos.append(abs(a[i + 1] - a[i]))
pos.sort()
sum = 0
count = 0
for i in range(len(pos)):
	if sum + pos[i] <= b:
		sum += pos[i]
		count += 1
print(count)


def go():
	(n, b) = [int(i) for i in input().split(' ')]
	a = [int(i) for i in input().split(' ')]
	odd = 0
	even = 0
	cuts = []
	for i in range(n - 1):
		if a[i] % 2 == 1:
			odd += 1
		else:
			even += 1
		if odd == even:
			cost = abs(a[i] - a[i + 1])
			if cost <= b:
				cuts.append(cost)
				odd = 0
				even = 0
	cuts = sorted(cuts)
	total = 0
	current = 0
	i = 0
	while current <= b and i < len(cuts):
		current += cuts[i]
		total += 1
		i += 1
	if current > b:
		total -= 1
	return total
print(go())


(n, m) = map(int, input().split())
i = 2
j = 0
l3 = []
l1 = list(map(int, input().split()))
l2 = list([bool(i % 2 == 0) for i in l1])
while i < n:
	if l2[:i].count(True) == l2[:i].count(False):
		l3.append(i)
	i += 2
l = list([abs(l1[i] - l1[i - 1]) for i in l3])
l.sort()
k = 0
i = 0
a = len(l)
while i < a:
	k += l[i]
	if k > m:
		break
	i += 1
j = i
print(j)


def R():
	return map(int, input().split())

def I():
	return int(input())

def S():
	return str(input())

def L():
	return list(R())
from collections import Counter
import math
import sys
(n, b) = R()
a = L()
dp = [0] * n
odd = [0] * (n + 1)
even = [0] * (n + 1)
for i in range(n):
	dp[i] = [0] * (b + 1)
	if a[i] % 2 == 0:
		even[i + 1] = even[i] + 1
		odd[i + 1] = odd[i]
	else:
		even[i + 1] = even[i]
		odd[i + 1] = odd[i] + 1
for i in range(n):
	for j in range(b + 1):
		if odd[i + 1] != even[i + 1]:
			continue
		for k in range(i):
			if odd[k + 1] == even[k + 1] and j - abs(a[k + 1] - a[k]) >= 0:
				dp[i][j] = max(dp[i][j], dp[k][j - abs(a[k + 1] - a[k])] + 1)
print(dp[n - 1][b])


def main():
	(n, m) = map(int, input().split())
	(a, *aa) = map(int, input().split())
	(c, res) = (1 - (a & 1) * 2, [])
	for b in aa:
		if not c:
			res.append(abs(a - b))
		if b & 1:
			c -= 1
		else:
			c += 1
		a = b
	for (i, a) in enumerate(sorted(res)):
		if m < a:
			print(i)
			return
		m -= a
	print(len(res))
main()


(n, k) = list(map(int, input().split()))
m = list(map(int, input().split()))
a = []
p = 0
for i in range(n):
	if m[i] % 2:
		p += 1
	elif m[i] % 2 == 0:
		p -= 1
	if p == 0 and i != n - 1:
		a.append(abs(m[i + 1] - m[i]))
if p == 0:
	a.sort()
	l = 0
	for i in range(len(a)):
		if k >= a[i]:
			k -= a[i]
			l += 1
		else:
			break
	print(l)
else:
	print(0)


buf = input()
m = buf.split()
n = int(m[0])
B = int(m[1])
a = []
N = []
C = []
arr = input()
a = arr.split(' ')
for i in range(0, n):
	a[i] = int(a[i])
if a[0] % 2 == 0:
	N.append(0)
	C.append(1)
else:
	N.append(1)
	C.append(0)
for i in range(1, n):
	if a[i] % 2 == 0:
		N.append(N[i - 1])
		C.append(C[i - 1] + 1)
	else:
		N.append(N[i - 1] + 1)
		C.append(C[i - 1])
k = 0
s = 0
c = []
for i in range(1, n - 1, 2):
	if C[i] == N[i]:
		c.append(abs(a[i + 1] - a[i]))
c.sort()
for i in c:
	if s + i <= B:
		k = k + 1
		s += i
print(k)


import sys
from bisect import bisect_left, bisect_right, insort
from collections import deque, Counter
from math import gcd, sqrt, factorial, ceil, log10, log2, floor
from itertools import permutations
from heapq import heappush, heappop, heapify
inf = float('inf')
mod = 10 ** 9 + 7

def factorial_p(n, p):
	ans = 1
	if n <= p // 2:
		for i in range(1, n + 1):
			ans = ans * i % p
	else:
		for i in range(1, p - n):
			ans = ans * i % p
		ans = pow(ans, p - 2, p)
		if n % 2 == 0:
			ans = p - ans
	return ans

def nCr_p(n, r, p):
	ans = 1
	while n != 0 or r != 0:
		(a, b) = (n % p, r % p)
		if a < b:
			return 0
		ans = ans * factorial_p(a, p) * pow(factorial_p(b, p), p - 2, p) * pow(factorial_p(a - b, p), p - 2, p) % p
		n //= p
		r //= p
	return ans

def prime_sieve(n):
	flag = n % 6 == 2
	sieve = bytearray((n // 3 + flag >> 3) + 1)
	for i in range(1, int(n ** 0.5) // 3 + 1):
		if not sieve[i >> 3] >> (i & 7) & 1:
			k = 3 * i + 1 | 1
			for j in range(k * k // 3, n // 3 + flag, 2 * k):
				sieve[j >> 3] |= 1 << (j & 7)
			for j in range(k * (k - 2 * (i & 1) + 4) // 3, n // 3 + flag, 2 * k):
				sieve[j >> 3] |= 1 << (j & 7)
	return sieve

def prime_list(n):
	res = []
	if n > 1:
		res.append(2)
	if n > 2:
		res.append(3)
	if n > 4:
		sieve = prime_sieve(n + 1)
		res.extend((3 * i + 1 | 1 for i in range(1, (n + 1) // 3 + (n % 6 == 1)) if not sieve[i >> 3] >> (i & 7) & 1))
	return res

def is_prime(n):
	if n < 5 or n & 1 == 0 or n % 3 == 0:
		return 2 <= n <= 3
	s = (n - 1 & 1 - n).bit_length() - 1
	d = n >> s
	for a in [2, 325, 9375, 28178, 450775, 9780504, 1795265022]:
		p = pow(a, d, n)
		if p == 1 or p == n - 1 or a % n == 0:
			continue
		for _ in range(s):
			p = p * p % n
			if p == n - 1:
				break
		else:
			return False
	return True

def all_factors(n):
	(small, large) = ([], [])
	for i in range(1, int(n ** 0.5) + 1, 2 if n & 1 else 1):
		if not n % i:
			small.append(i)
			large.append(n // i)
	large.reverse()
	small.extend(large)
	return small

def get_array():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def input():
	return sys.stdin.readline().strip()
(n, b) = get_ints()
Arr = get_array()
even_suf = [0] * n
odd_suf = [0] * n
if Arr[0] & 1:
	odd_suf[0] = 1
else:
	even_suf[0] = 1
for i in range(1, n):
	if Arr[i] & 1:
		odd_suf[i] = odd_suf[i - 1] + 1
		even_suf[i] = even_suf[i - 1]
	else:
		even_suf[i] = even_suf[i - 1] + 1
		odd_suf[i] = odd_suf[i - 1]
result = []
flag = 0
for i in range(1, n - 1):
	if odd_suf[i] == even_suf[i]:
		result.append(abs(Arr[i] - Arr[i + 1]))
		flag = 1
if flag == 0:
	print(0)
	exit()
result.sort()
index = 0
total = 0
while index < len(result) and total + result[index] <= b:
	total += result[index]
	index += 1
print(index)


(n, b) = map(int, input().split())
a = list(map(int, input().split()))
o = e = 0
ol = [0] * n
el = [0] * n
for i in range(n - 1, -1, -1):
	if a[i] % 2 == 1:
		o += 1
	else:
		e += 1
	ol[i] = o
	el[i] = e
o = e = 0
c = []
for i in range(n):
	if o == e and o != 0 and (ol[i] == el[i]):
		c.append(max(a[i] - a[i - 1], a[i - 1] - a[i]))
		o = e = 0
	if a[i] % 2 == 0:
		e += 1
	else:
		o += 1
c.sort()
co = 0
for i in c:
	b -= i
	if b >= 0:
		co += 1
	else:
		break
print(co)


l = list(map(int, input().split()))
n = l[0]
b = l[1]
oe = 0
ans = 0
l = list(map(int, input().split()))
l1 = []
for i in range(len(l)):
	if l[i] % 2 == 1:
		oe += 1
	else:
		oe -= 1
	if oe == 0 and i != len(l) - 1:
		l1.append(abs(l[i + 1] - l[i]))
if l1 != []:
	mini = min(l1)
	while mini <= b:
		b = b - mini
		ans += 1
		l1.remove(mini)
		if l1 == []:
			break
		else:
			mini = min(l1)
print(ans)


(n, b) = map(int, input().split())
a = list(map(int, input().split()))
j = 0
ans = []
flag = 0
while j < n:
	ev = 0
	odd = 0
	if a[j] % 2 == 0:
		ev += 1
	else:
		odd += 1
	j += 1
	while odd != ev and j < n:
		if a[j] % 2 == 0:
			ev += 1
		else:
			odd += 1
		j += 1
	if j != n:
		ans.append(abs(a[j] - a[j - 1]))
ans.sort()
s = 0
k = 0
for i in range(len(ans)):
	s += ans[i]
	if s <= b:
		k += 1
print(k)


import sys, string
(n, b) = map(int, sys.stdin.readline().split())
arr = list(map(int, sys.stdin.readline().split()))
pf_even = [0] * (n - 1)
pf_odd = [0] * (n - 1)
if arr[0] % 2 == 0:
	pf_even[0] = 1
else:
	pf_odd[0] = 1
for i in range(1, n - 1):
	if arr[i] % 2 == 0:
		pf_even[i] = pf_even[i - 1] + 1
		pf_odd[i] = pf_odd[i - 1]
	else:
		pf_even[i] = pf_even[i - 1]
		pf_odd[i] = pf_odd[i - 1] + 1
path = []
for i in range(n - 1):
	if pf_odd[i] == pf_even[i]:
		path.append((i, i + 1))
path.sort(key=lambda x: abs(arr[x[0]] - arr[x[1]]))
cnt = 0
for i in path:
	if abs(arr[i[1]] - arr[i[0]]) > b:
		break
	cnt += 1
	b -= abs(arr[i[1]] - arr[i[0]])
print(cnt)


(n, b) = map(int, input().split())
a = list(map(int, input().split()))
x = list()
i = 0
e = 0
o = 0
while i < n:
	if e == o and o != 0:
		e = 0
		o = 0
		x.append(abs(a[i] - a[i - 1]))
	if a[i] % 2 == 0:
		e += 1
	elif a[i] % 2 != 0:
		o += 1
	i += 1
c = 0
x.sort()
for i in x:
	b -= i
	if b < 0:
		break
	else:
		c += 1
print(c)


from math import *
from collections import deque
from copy import deepcopy
import sys

def inp():
	return sys.stdin.readline().rstrip('\r\n')

def multi():
	return map(int, input().split())

def strmulti():
	return map(str, inp().split())

def lis():
	return list(map(int, inp().split()))

def lcm(a, b):
	return a * b // gcd(a, b)

def ncr(n, r):
	return factorial(n) // (factorial(r) * factorial(max(n - r, 1)))

def stringlis():
	return list(map(str, inp().split()))

def out(var):
	sys.stdout.write(str(var))

def printlist(a):
	print(' '.join((str(a[i]) for i in range(len(a)))))

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True
(n, B) = multi()
a = lis()
even = 0
odd = 0
ans = 0
allans = []
for i in range(n):
	if a[i] % 2 == 0:
		even += 1
	else:
		odd += 1
	if even == odd:
		if i != n - 1:
			allans.append(abs(a[i] - a[i + 1]))
allans.sort()
count = 0
for i in allans:
	if ans + i <= B:
		ans += i
		count += 1
	else:
		break
print(count)


import math as ma
from sys import exit
from decimal import Decimal as dec

def li():
	return list(map(int, input().split()))

def num():
	return map(int, input().split())

def nu():
	return int(input())
(n, b) = num()
a = li()
o = 0
e = 0
tt = 0
v = b
cost = []
for i in range(n - 1):
	if a[i] % 2 == 0:
		e += 1
	else:
		o += 1
	if o == e:
		cost.append(abs(a[i] - a[i + 1]))
cost.sort()
c = 0
for i in range(len(cost)):
	if cost[i] <= v:
		c += 1
		v = v - cost[i]
print(c)


from math import *
import sys

def main():
	(n, money) = [int(x) for x in input().split(' ')]
	a = [int(x) for x in input().split(' ')]
	p = 0
	parity = [0 for i in range(n + 1)]
	for i in range(n - 1, -1, -1):
		p += -1 if a[i] % 2 == 0 else 1
		parity[i] = p
	p = 0
	sticks = []
	for i in range(n - 1):
		p += -1 if a[i] % 2 == 0 else 1
		if p == 0 and parity[i + 1] == 0:
			sticks.append(abs(a[i + 1] - a[i]))
	sticks = sorted(sticks)
	cnt = 0
	for s in sticks:
		if s > money:
			break
		else:
			cnt += 1
			money -= s
	print(cnt)
main()


(n, B) = map(int, input().split())
a = list(map(int, input().split()))
even = 0
odd = 0
l = []
for i in range(n - 1):
	if a[i] & 1:
		odd += 1
	else:
		even += 1
	if odd == even:
		if a[i] - a[i + 1] < 0:
			l.append(a[i + 1] - a[i])
		else:
			l.append(a[i] - a[i + 1])
l.sort()
c = 0
s = 0
for i in l:
	s += i
	if s <= B:
		c += 1
	else:
		break
print(c)


[n, B] = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
even = 0
odd = 0
i = 0
B1 = []
if n & 1:
	print('0')
else:
	while i < n - 2:
		if A[i] & 1:
			odd += 1
		else:
			even += 1
		if odd == even:
			B1.append(abs(A[i + 1] - A[i]))
		i += 1
	B1.sort()
	s = 0
	i = 0
	c = 0
	while i < len(B1):
		s += B1[i]
		c += 1
		if s > B:
			c -= 1
			s -= B1[i]
			break
		i += 1
	print(c)


from math import *
(n, b) = map(int, input().split())
a = list(map(int, input().split()))
x = 0
y = 0
c = []
for i in range(len(a) - 1):
	if a[i] % 2 == 0:
		x += 1
	else:
		y += 1
	if x == y:
		c.append(abs(a[i + 1] - a[i]))
for i in range(len(c)):
	for j in range(len(c) - i - 1):
		if c[j] > c[j + 1]:
			(c[j], c[j + 1]) = (c[j + 1], c[j])
ans = 0
b1 = 0
for i in range(len(c)):
	if b1 + c[i] <= b:
		b1 += c[i]
		ans += 1
print(ans)


from copy import deepcopy
import itertools
from bisect import bisect_left
from bisect import bisect_right
import math
from collections import deque
from collections import Counter

def read():
	return int(input())

def readmap():
	return map(int, input().split())

def readlist():
	return list(map(int, input().split()))
(N, B) = readmap()
A = readlist()
even = 0
odd = 0
cost = []
for i in range(0, N - 1):
	if A[i] % 2 == 0:
		even += 1
	else:
		odd += 1
	if even == odd:
		cost.append(abs(A[i] - A[i + 1]))
cost.sort()
ans = 0
for c in cost:
	if c > B:
		break
	else:
		ans += 1
		B -= c
print(ans)


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
cost = 0
c = 0
ans = 0
sumc = []
for i in range(n - 2):
	if l[i] % 2 == 1:
		c += 1
	else:
		c -= 1
	if c == 0:
		cost = abs(l[i + 1] - l[i])
		if cost <= k:
			sumc.append(cost)
sumc.sort()
su = 0
for i in range(len(sumc)):
	su += sumc[i]
	if su <= k:
		ans += 1
print(ans)


(n, B) = list(map(int, input().split()))
a = list(map(int, input().split()))
noe = 0
noo = 0
cuts = []
ans = 0
for i in range(n):
	if a[i] & 1 == 0:
		noe += 1
	else:
		noo += 1
	if noo == noe and i < n - 1:
		cuts.append(abs(a[i] - a[i + 1]))
cuts.sort()
curSum = 0
for cut in cuts:
	curSum += cut
	if curSum <= B:
		ans += 1
print(ans)


(n, m) = map(int, input().split())
a = list(map(int, input().split()))
t = 0
b = []
for i in range(n - 1):
	if a[i] % 2:
		t += 1
	else:
		t -= 1
	if t == 0:
		b.append(abs(a[i + 1] - a[i]))
b.sort()
(uttar, pre) = (0, 0)
for i in range(len(b)):
	pre += b[i]
	if pre > m:
		break
	else:
		uttar += 1
print(uttar)


(n, b) = list(map(int, input().split()))
arr = list(map(int, input().split()))
(c_even, c_odd) = (0, 0)
arr1 = []
for i in range(n - 1):
	if arr[i] % 2 == 0:
		c_even += 1
	if arr[i] % 2 != 0:
		c_odd += 1
	if c_even == c_odd and abs(arr[i] - arr[i + 1]) <= b:
		arr1.append(abs(arr[i] - arr[i + 1]))
count = 0
arr1.sort()
for i in range(len(arr1)):
	if b - arr1[i] >= 0:
		b -= arr1[i]
		count += 1
	else:
		break
print(count)


(n, b) = map(int, input().split())
arr = list(map(int, input().split()))
oe = 0
cost = []
for i in range(n):
	if arr[i] % 2:
		oe += 1
	else:
		oe -= 1
	if not oe and i != n - 1:
		cost.append(abs(arr[i + 1] - arr[i]))
cost.sort()
(tot, c) = (0, 0)
for i in cost:
	if tot + i <= b:
		tot += i
		c += 1
	else:
		break
print(c)


(n, b) = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
seg = []
(odd, ev, i) = (0, 0, 0)
while i < n:
	if a[i] % 2 == 0:
		ev += 1
	else:
		odd += 1
	if ev == odd and i != n - 1:
		seg.append(abs(a[i] - a[i + 1]))
	i += 1
seg.sort()
ans = 0
for i in seg:
	if i <= b:
		b -= i
		ans += 1
print(ans)


import sys
(n, b, *a) = [int(s) for s in sys.stdin.read().split()]
emo = 0
l = []
for (i, (x, y)) in enumerate(zip(a[:-1], a[1:])):
	emo += [1, -1][x % 2]
	if emo == 0:
		l.append(max(y - x, x - y))
l.sort()
s = anz = 0
for i in l:
	s += i
	if s > b:
		break
	else:
		anz += 1
print(anz)


(n, coins) = [int(i) for i in input().split(' ')]
tr = [int(i) for i in input().split(' ')]
(od, ev) = (0, 0)
cost = []
for i in range(len(tr) - 1):
	if tr[i] % 2 == 0:
		ev += 1
	else:
		od += 1
	if od == ev:
		cost.append(abs(tr[i] - tr[i + 1]))
cost.sort(reverse=True)
while sum(cost) > coins:
	cost.pop(0)
print(len(cost))


(n, m) = map(int, input().strip().split())
odd = 0
even = 0
l = list(map(int, input().strip().split()))
l1 = []
for i in range(n - 1):
	if l[i] % 2 == 0:
		even = even + 1
	else:
		odd = odd + 1
	if odd == even:
		if l[i] - l[i + 1] < 0:
			l1.append(l[i + 1] - l[i])
		else:
			l1.append(l[i] - l[i + 1])
l1.sort()
count = 0
sum1 = 0
for i in l1:
	sum1 = sum1 + i
	if sum1 <= m:
		count = count + 1
	else:
		break
print(count)


from collections import defaultdict, deque, Counter
from sys import stdin, stdout
from heapq import heappush, heappop
import math
import io
import os
import math
import bisect

def isPrime(x):
	for i in range(2, x):
		if i * i > x:
			break
		if x % i == 0:
			return False
	return True

def ncr(n, r, p):
	num = den = 1
	for i in range(r):
		num = num * (n - i) % p
		den = den * (i + 1) % p
	return num * pow(den, p - 2, p) % p

def primeFactors(n):
	l = []
	while n % 2 == 0:
		l.append(2)
		n = n / 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			l.append(int(i))
			n = n / i
	if n > 2:
		l.append(n)
	return list(set(l))

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def sieve(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	return prime

def digits(n):
	c = 0
	while n > 0:
		n //= 10
		c += 1
	return c

def ceil(n, x):
	if n % x == 0:
		return n // x
	return n // x + 1

def mapin():
	return [int(x) for x in input().split()]
t = 1
for _ in range(t):
	(n, b) = mapin()
	l = mapin()
	s = []
	o = 0
	e = 0
	for i in range(n - 1):
		if l[i] & 1:
			o += 1
		else:
			e += 1
		if o == e:
			s.append(abs(l[i] - l[i + 1]))
	ans = 0
	s.sort()
	for i in s:
		if i <= b:
			ans += 1
			b -= i
		else:
			break
	print(ans)


def calc(a, b):
	(odd_count, even_count) = (0, 0)
	splits = list()
	for i in range(len(a)):
		if a[i] % 2 == 0:
			even_count += 1
		else:
			odd_count += 1
		if i + 1 < len(a) and odd_count == even_count:
			splits.append(abs(a[i] - a[i + 1]))
			(odd_count, even_count) = (0, 0)
	cost = 0
	for (i, item) in enumerate(sorted(splits)):
		cost += item
		if cost > b:
			break
	else:
		i = len(splits)
	return i

def get_ints():
	return [int(n) for n in input().split()]

def get_floats():
	return [float(n) for n in input().split()]
a = get_ints()
assert len(a) == 2
(n, b) = (a[0], a[1])
assert 2 <= n <= 100
assert 1 <= b <= 100
a = get_ints()
assert len(a) == n
res = calc(a, b)
print(res)


(odd, even, dp) = ([0], [0], [])

def process(n, a):
	for i in range(1, n + 1, 1):
		odd.append(odd[i - 1])
		even.append(even[i - 1])
		if a[i] % 2 == 1:
			odd[i] += 1
		if a[i] % 2 == 0:
			even[i] += 1
	for i in range(0, 105 + 1, 1):
		dp.append([])
		for j in range(0, 105 + 1, 1):
			if i >= 2:
				dp[i].append(-1)
			else:
				dp[i].append(0)

def solve(n, b, a):
	a.insert(0, 0)
	process(n, a)
	for i in range(1, n - 1 + 1, 1):
		for j in range(0, b + 1, 1):
			if dp[i][j] != -1:
				for l in range(i + 1, n + 1 + 1, 1):
					cnt_odd = odd[l - 1] - odd[i - 1]
					cnt_even = even[l - 1] - even[i - 1]
					if l == n + 1:
						cost = 0
					else:
						cost = abs(a[l] - a[l - 1])
					if cnt_odd == cnt_even and j + cost <= b:
						if l == n + 1:
							dp[l][j + cost] = max(dp[l][j + cost], dp[i][j])
						else:
							dp[l][j + cost] = max(dp[l][j + cost], dp[i][j] + 1)
	res = 0
	for i in range(0, b + 1, 1):
		res = max(res, dp[n + 1][i])
	return res

def dp004_cutting(n, b, a):
	return solve(n, b, a)
(n, b) = list(map(int, input().split()))
a = list(map(int, input().split()))
print(dp004_cutting(n, b, a))


(n, cost) = map(int, input().split())
lis = [int(x) for x in input().split()]
even = 0
odd = 0
dp = []
for i in range(n - 1):
	if lis[i] % 2 == 0:
		even += 1
	else:
		odd += 1
	if even == odd:
		dp.append(abs(lis[i] - lis[i + 1]))
dp.sort()
count = 0
while dp:
	if dp[0] <= cost:
		cost -= dp[0]
		dp.remove(dp[0])
		count += 1
	else:
		break
print(count)


(n, b) = map(int, input().split())
l = list(map(int, input().split()))
m = []
odd = 0
even = 0
for i in range(n - 2):
	if l[i] % 2 == 0:
		even += 1
	else:
		odd += 1
	if odd == even:
		odd = 0
		even = 0
		m.append(abs(l[i] - l[i + 1]))
m.sort()
count = 0
for i in range(len(m)):
	if m[i] <= b:
		count += 1
		b -= m[i]
print(count)


(n, B) = list(map(int, input().split(' ')))
a = list(map(int, input().split(' ')))
r = []
s = 0
for i in range(0, n):
	if a[i] % 2 == 0:
		s += 1
	else:
		s -= 1
	if i != 0 and i != n - 1 and (s == 0):
		r.append([abs(a[i] - a[i + 1]), i])
		s = 0
res = 0
for i in sorted(r):
	if B - i[0] >= 0:
		B -= i[0]
		res += 1
	else:
		break
print(res)


R = lambda : map(int, input().split())
(n, m) = R()
r = list(R())
s = []
(a, b) = (0, 0)
for i in range(n):
	c = r[i] % 2
	if c == 0:
		a += 1
	else:
		b += 1
	if a == b > 0 and i < n - 1:
		if abs(r[i] - r[i + 1]) <= m:
			s.append(abs(r[i] - r[i + 1]))
			(a, b) = (0, 0)
s = sorted(s)
rr = 0
for i in range(len(s)):
	if rr + s[i] > m:
		print(i)
		exit(0)
	else:
		rr += s[i]
print(len(s))


def max_cuts(a, length):
	cut_prices = []
	odd_count = 0
	even_count = 0
	for i in range(0, length - 1):
		if a[i] % 2 == 0:
			even_count += 1
		else:
			odd_count += 1
		if even_count == odd_count:
			cut_prices.append(abs(a[i] - a[i + 1]))
		else:
			pass
	return cut_prices

def cutting(b, btc):
	b.sort()
	sum = 0
	count = 0
	ind = 0
	flag = 0
	while flag == 0 and ind < len(b):
		if sum + b[ind] > btc:
			break
		else:
			sum += b[ind]
			count += 1
			ind += 1
	return count
(n, in_b) = [int(y) for y in input().split()]
arr = [int(x) for x in input().split()]
result = cutting(max_cuts(arr, n), in_b)
print(result)


(a, b) = map(int, input().split())
z = list(map(int, input().split()))
z1 = []
s = 0
for i in range(a - 1):
	if 1 & z[i]:
		s += 1
	else:
		s -= 1
	if s == 0:
		z1 += [abs(z[i] - z[i + 1])]
sum = 0
i = 0
cuts = 0
z1 = sorted(z1)
while i < len(z1):
	if z1[i] + sum <= b:
		sum += z1[i]
		cuts += 1
	else:
		break
	i += 1
print(cuts)


(n, b) = [int(v) for v in input().split()]
a = [int(v) for v in input().split()]
(n_odd, n_even) = (0, 0)
costs = []
for i in range(n - 1):
	if a[i] % 2 == 0:
		n_even += 1
	else:
		n_odd += 1
	if n_even == n_odd:
		costs.append(abs(a[i] - a[i + 1]))
costs.sort()
ans = 0
while ans < len(costs) and costs[ans] <= b:
	b -= costs[ans]
	ans += 1
print(ans)


from sys import stdin
(n, m) = map(int, stdin.readline().rstrip().split(' '))
l = list(map(int, stdin.readline().rstrip().split(' ')))
z = []
e = 0
o = 0
for i in range(n - 1):
	if l[i] % 2:
		o += 1
	else:
		e += 1
	if o != 0 and o == e:
		z.append(abs(l[i] - l[i + 1]))
if l[-1] % 2:
	o += 1
else:
	e += 1
if e != o:
	print(0)
else:
	z.sort()
	c = 0
	x = 0
	for i in z:
		if x + i > m:
			break
		x += i
		c += 1
	print(c)


(n, b) = map(int, input().split())
a = list(map(int, input().split()))
if a[0] % 2 == 0:
	o = 0
	e = 1
else:
	o = 1
	e = 0
c = []
for i in range(1, n - 1):
	if a[i] % 2 == 0:
		e += 1
	else:
		o += 1
	if e == o:
		c.append(abs(a[i] - a[i + 1]))
c.sort()
sp = 0
cu = 0
for i in c:
	sp += i
	if sp > b:
		break
	cu += 1
print(cu)


rd = lambda : list(map(int, input().split()))
(n, b) = rd()
(a, y, p, l) = (rd(), [], 0, 0)
for x in a:
	if not p:
		y.append(abs(x - l))
	p += [-1, 1][x & 1]
	if not p:
		l = x
g = sorted(y[1:])
(x, r) = (0, 0)
for p in g:
	x += p
	if x > b:
		break
	r += 1
print(r)


(n, B) = map(int, input().split())
a = list(map(int, input().split()))
odd = 0
even = 0
poss = []
for i in range(n - 1):
	if a[i] % 2 == 0:
		even += 1
	else:
		odd += 1
	if odd == even:
		poss.append(abs(a[i + 1] - a[i]))
poss.sort()
ans = 0
i = 0
while i < len(poss) and B > 0:
	B -= poss[i]
	if B >= 0:
		ans += 1
	i += 1
print(ans)


(N, B) = map(int, input().split())
sequence = [int(num) for num in input().split()][0:N]
odd = even = 0
bit = []
res = 0
for i in range(N):
	if sequence[i] % 2 == 0:
		even += 1
	else:
		odd += 1
	if even == odd and len(sequence[0:i]) < N - 1:
		bit += [0]
		bit[-1] = abs(sequence[i + 1] - sequence[i])
bit.sort()
for i in range(len(bit)):
	if bit[i] <= B:
		res += 1
		B -= bit[i]
	else:
		break
print(res)


cache = {}

def makekey(b, arr):
	return (b,) + tuple(arr)

def solve(b, arr):
	if b == 0 or not arr:
		return 0
	key = makekey(b, arr)
	if key not in cache:
		result = 0
		n_odd = 0
		n_even = 0
		for i in range(len(arr) - 1):
			if arr[i] % 2 == 0:
				n_even += 1
			else:
				n_odd += 1
			if n_even == n_odd:
				cost = abs(arr[i] - arr[i + 1])
				if cost <= b:
					result = max(result, 1 + solve(b - cost, arr[i + 1:]))
		cache[key] = result
	return cache[key]

def main():
	(n, b) = map(int, input().split())
	arr = list(map(int, input().split()))
	print(solve(b, arr))
main()


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
dp = list()
(od, ev) = (0, 0)
for i in range(n):
	if a[i] % 2:
		od += 1
	else:
		ev += 1
	if od == ev and i != 0 and (i != n - 1):
		dp.append(abs(a[i + 1] - a[i]))
dp.sort()
(sum, ans) = (0, 0)
for i in dp:
	sum += i
	if sum <= k:
		ans += 1
print(ans)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
b = []
c = len(a)
odd = 0
even = 0
for i in range(c):
	if a[i] % 2 == 0:
		even += 1
	else:
		odd += 1
	if even == odd and i != c - 1:
		q = abs(a[i] - a[i + 1])
		b.append(q)
b.sort()
cut = 0
flag = 0
for i in b:
	k -= i
	cut += 1
	if k < 0:
		flag = 1
		break
	if k == 0:
		break
if flag == 1:
	print(cut - 1)
else:
	print(cut)


(n, s) = map(int, input().split())
l = list(map(int, input().split()))
(od, ev, a) = (0, 0, [])
for i in range(n - 1):
	if l[i] % 2 == 0:
		ev += 1
	if l[i] % 2 != 0:
		od += 1
	if ev == od:
		a.append(abs(l[i] - l[i + 1]))
a.sort()
ans = 0
for i in range(len(a)):
	ans += a[i]
	if ans > s:
		print(i)
		break
else:
	print(len(a))


(n, B) = (int(x) for x in input().split())
a = [int(x) for x in input().split()]
odd = 0
s = []
for i in range(n - 1):
	if a[i] % 2 == 1:
		odd += 1
	else:
		odd -= 1
	if odd == 0:
		s.append(abs(a[i] - a[i + 1]))
s.sort()
k = 0
i = 0
while i < len(s) and k + s[i] <= B:
	k += s[i]
	i += 1
print(i)


(n, b) = input().strip().split()
(n, b) = (int(n), int(b))
cuts = []
a = [int(_) for _ in input().strip().split()]
odd = 0
even = 0
for i in range(len(a) - 1):
	if a[i] % 2 == 0:
		even += 1
	else:
		odd += 1
	if odd == even:
		cuts.append(abs(a[i + 1] - a[i]))
cuts.sort()
ans = 0
for i in cuts:
	if b - i >= 0:
		b -= i
		ans += 1
	else:
		break
print(ans)


(n, B) = map(int, input().split())
a = list(map(int, input().split()))
p = []
bal = 0
for i in range(n - 1):
	if a[i] % 2 == 1:
		bal += 1
	else:
		bal -= 1
	if bal == 0:
		p.append(abs(a[i] - a[i + 1]))
p.sort()
cnt = 0
for v in p:
	if B < v:
		break
	cnt += 1
	B -= v
print(cnt)


(n, k) = map(int, input().split())
e = 0
o = 0
a = list(map(int, input().split()))
b = []
for i in range(0, len(a)):
	if a[i] % 2 == 0:
		e += 1
	else:
		o += 1
	if e == o and i != n - 1:
		b.append(abs(a[i + 1] - a[i]))
b.sort()
if sum(b) <= k:
	print(len(b))
else:
	d = sum(b)
	f = 0
	i = 1
	l = 0
	while d - f > k and i >= 0:
		f = f + b[len(b) - i]
		i += 1
		l += 1
	print(len(b) - l)


firstLine = list(map(int, input().split(' ')))
numberElements = firstLine[0]
btc = firstLine[1]
seq = list(map(int, input().split(' ')))
evenTotal = numberElements / 2
oddTotal = evenTotal
evenSeen = 0
oddSeen = 0
totalCuts = 0
possibleCuts = list()
currentCuts = [numberElements]
while True:
	possibleCuts = list()
	evenSeen = 0
	oddSeen = 0
	for i in range(len(seq)):
		nextCut = min(list(filter(lambda x: x >= i, currentCuts)))
		if i == nextCut:
			evenSeen = 0
			oddSeen = 0
		if seq[i] % 2 == 0:
			evenSeen += 1
		else:
			oddSeen += 1
		if evenSeen == oddSeen and evenSeen > 0 and (oddSeen > 0) and (i < numberElements - 1) and (nextCut - i > 1):
			possibleCuts.append((i, abs(seq[i] - seq[i + 1])))
	if len(possibleCuts) == 0:
		break
	minCut = min(possibleCuts, key=lambda item: item[1])
	if btc - minCut[1] >= 0:
		currentCuts.append(minCut[0] + 1)
		btc -= minCut[1]
		totalCuts += 1
	else:
		break
print(totalCuts)


import sys
input = sys.stdin.readline
(n, B) = map(int, input().split())
a = list(map(int, input().split()))
x = 0
ans = []
for i in range(n - 1):
	if a[i] % 2 == 0:
		x += 1
	else:
		x -= 1
	if x == 0:
		ans.append(abs(a[i] - a[i + 1]))
ans.sort()
j = 0
for i in ans:
	if i <= B:
		j += 1
		B -= i
print(j)


def r(a, b):
	ans = a // b
	if a % b != 0:
		ans += 1
	return ans
(n, B) = map(int, input().split())
a = list(map(int, input().split()))
costs = []
(ch, notch) = (0, 0)
for i in range(n):
	if a[i] % 2 == 0:
		ch += 1
	else:
		notch += 1
	if ch == notch:
		(ch, notch) = (0, 0)
		if i < n - 1:
			costs.append(abs(a[i + 1] - a[i]))
costs.sort()
ans = 0
for i in costs:
	if B < i:
		break
	B -= i
	ans += 1
print(ans)


(n, b) = [int(p) for p in input().split()]
arr = [int(p) for p in input().split()]
index = []
for i in range(len(arr)):
	if arr[i] % 2 == 0:
		index.append(-1)
	else:
		index.append(1)
for i in range(1, len(index)):
	index[i] += index[i - 1]
cost = []
for i in range(len(index) - 1):
	if index[i] == 0:
		cost.append(abs(arr[i + 1] - arr[i]))
cost.sort()
count = 0
for i in range(len(cost)):
	b -= cost[i]
	if b < 0:
		break
	else:
		count += 1
print(count)


from math import *
(n, b) = map(int, input().split())
s = [int(elem) for elem in input().split()]
p = [(0, 0)]
anses = []
for i in range(n):
	if s[i] % 2 == 0:
		p.append((p[i][0] + 1, p[i][1]))
	else:
		p.append((p[i][0], p[i][1] + 1))
for i in range(1, n - 1):
	if p[i][0] == p[i][1]:
		anses.append(abs(s[i - 1] - s[i]))
anses.sort()
summ = 0
k = 0
for i in range(len(anses)):
	if summ + anses[i] <= b:
		k = k + 1
		summ = summ + anses[i]
print(k)


(n, b) = map(int, input().split())
a = list(map(int, input().split()))
e = 0
o = 0
cuts = []
for i in range(n - 1):
	if a[i] % 2:
		o += 1
	else:
		e += 1
	if o == e:
		cuts.append(abs(a[i] - a[i + 1]))
		o = 0
		e = 0
cuts.sort()
ct = 0
for i in cuts:
	if b - i >= 0:
		ct += 1
		b -= i
print(ct)


(n, B) = map(int, input().split(' '))
a = input().split(' ')
for i in range(n):
	a[i] = int(a[i])
cost = []
count = 0
for i in range(n - 1):
	if a[i] % 2 == 1:
		count += 1
	else:
		count -= 1
	if count == 0:
		cost.append(abs(a[i + 1] - a[i]))
s = 0
i = 0
cost = sorted(cost)
while s <= B and i < len(cost):
	s += cost[i]
	i += 1
if i == 0:
	print(0)
elif s > B:
	print(i - 1)
else:
	print(i)


(n, b) = map(int, input().split())
lst = list(map(int, input().split()))
c = []
t = 0
for i in range(len(lst) - 1):
	if lst[i] % 2 == 0:
		t += 1
	else:
		t -= 1
	if t == 0:
		c.append(abs(lst[i + 1] - lst[i]))
c.sort()
j = 0
while j < len(c) and b >= 0:
	b -= c[j]
	if b >= 0:
		j += 1
print(j)


(n, k) = map(int, input().split())
li = [int(k) for k in input().split()]
ans = []
ec = 0
oc = 0
for i in range(n):
	if li[i] % 2 == 1:
		oc += 1
	else:
		ec += 1
	if ec == oc and i < n - 1:
		ans.append(abs(li[i + 1] - li[i]))
ans.sort()
cur = 0
co = 0
for j in range(len(ans)):
	cur = cur + ans[j]
	if cur <= k:
		co += 1
print(co)


(n, b) = map(int, input().split())
arr = list(map(int, input().split()))
ans = []
if arr[0] % 2 == 0:
	count = -1
else:
	count = 1
for i in range(1, n - 1):
	if count == 0:
		ans.append(abs(arr[i] - arr[i - 1]))
	if arr[i] % 2 == 0:
		count += -1
	else:
		count += 1
ans.sort()
c = 0
k = 0
while k < len(ans) and c + ans[k] <= b:
	c += ans[k]
	k += 1
print(k)


def cut(arr, n, cost):
	odd = [0] * n
	even = [0] * n
	if arr[0] % 2 == 0:
		even[0] = 1
	else:
		odd[0] = 1
	for i in range(1, n):
		if arr[i] % 2 == 0:
			even[i] = 1 + even[i - 1]
		else:
			even[i] = even[i - 1]
		if arr[i] % 2 != 0:
			odd[i] = 1 + odd[i - 1]
		else:
			odd[i] = odd[i - 1]
	ans = []
	for i in range(n - 1):
		if even[i] == odd[i]:
			ans.append(abs(arr[i] - arr[i + 1]))
	ans.sort()
	f_cost = 0
	j = 0
	c = 0
	while j < len(ans):
		f_cost += ans[j]
		if f_cost <= cost:
			c += 1
		else:
			break
		j += 1
	return c
(n, cost) = map(int, input().split())
arr = list(map(int, input().split()))
print(cut(arr, n, cost))


(n, k) = map(int, input().strip().split(' '))
lst = list(map(int, input().strip().split(' ')))
odd_count = 0
even_count = 0
c = 0
l = []
for j in range(n):
	if odd_count == even_count and odd_count != 0:
		l.append(j)
		if lst[j] % 2 == 0:
			even_count = 1
			odd_count = 0
		else:
			odd_count = 1
			even_count = 0
	elif lst[j] % 2 == 0:
		even_count += 1
	else:
		odd_count += 1
l1 = []
j = 0
if len(l) == 0:
	print(0)
else:
	for i in range(n):
		if i == l[j]:
			l1.append(abs(lst[i] - lst[i - 1]))
			j += 1
			if j >= len(l):
				break
	l1.sort()
	s = 0
	for i in range(len(l1)):
		if s + l1[i] <= k:
			c += 1
			s += l1[i]
	print(c)


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, copy, functools
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 10 ** 9 + 7
mod2 = 998244353
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

def LI():
	return list(map(int, sys.stdin.readline().split()))

def LLI():
	return [list(map(int, l.split())) for l in sys.stdin.readlines()]

def LI_():
	return [int(x) - 1 for x in sys.stdin.readline().split()]

def LF():
	return [float(x) for x in sys.stdin.readline().split()]

def LS():
	return sys.stdin.readline().split()

def I():
	return int(sys.stdin.readline())

def F():
	return float(sys.stdin.readline())

def S():
	return input()

def pf(s):
	return print(s, flush=True)

def pe(s):
	return print(str(s), file=sys.stderr)

def JA(a, sep):
	return sep.join(map(str, a))

def JAA(a, s, t):
	return s.join((t.join(map(str, b)) for b in a))

def IF(c, t, f):
	return t if c else f

def YES(c):
	return IF(c, 'YES', 'NO')

def Yes(c):
	return IF(c, 'Yes', 'No')

def main():
	t = 1
	rr = []
	for _ in range(t):
		(n, k) = LI()
		a = LI()
		t = []
		b = 0
		for i in range(n - 1):
			if a[i] % 2:
				b += 1
			else:
				b -= 1
			if b == 0:
				t.append(abs(a[i] - a[i + 1]))
		t.sort()
		r = 0
		for c in t:
			if c <= k:
				r += 1
				k -= c
			else:
				break
		rr.append(r)
	return JA(rr, '\n')
print(main())


(n, b) = [int(i) for i in input().split()]
lst = [int(i) for i in input().split()]
co = 0
ce = 0
cost = []
for i in range(n):
	if lst[i] % 2 == 0:
		co += 1
	else:
		ce += 1
	if co == ce and i < n - 1:
		cost.append(abs(lst[i + 1] - lst[i]))
cost.sort()
sum = 0
i = 0
while sum <= b and i < len(cost):
	sum += cost[i]
	i += 1
if co == ce:
	if sum > b:
		print(i - 1)
	else:
		print(i)
else:
	print(0)


s = list(map(int, input().split()))
cl = list(map(int, input().split()))
(n, b) = (s[0], s[1])
dic = {}
nw = []
for x in cl:
	nw.append(x % 2)
count0 = 0
count1 = 0
count0 = nw.count(0)
count1 = nw.count(1)
if count0 != count1 or n % 2 != 0:
	print(0)
else:
	res = []
	for i in range(2, n):
		x = nw[:i]
		k0 = x.count(0)
		k1 = x.count(1)
		if count0 - k0 == count1 - k1:
			res.append(abs(cl[i] - cl[i - 1]))
	counter = 0
	sm = 0
	res = sorted(res)
	i = 0
	while sm <= b and i < len(res):
		sm += res[i]
		counter += 1
		i += 1
	if sm > b:
		counter -= 1
	print(counter)


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
e = o = t = 0
l1 = []
for i in range(n - 1):
	if l[i] % 2 == 0:
		e += 1
	else:
		o += 1
	if e == o:
		l1.append(abs(l[i] - l[i + 1]))
		e = o = 0
l1 = sorted(l1)
s = mc = 0
for i in l1:
	s += i
	if s <= k:
		mc += 1
print(mc)


from collections import deque as de
import math
from collections import Counter as cnt

class My_stack:

	def __init__(self):
		self.data = []

	def my_push(self, x):
		return self.data.append(x)

	def my_pop(self):
		return self.data.pop()

	def my_peak(self):
		return self.data[-1]

	def my_contains(self, x):
		return self.data.count(x)

	def my_show_all(self):
		return self.data

	def isEmpty(self):
		return len(self.data) == 0
arrStack = My_stack()

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True

def get_prime_factors(number):
	prime_factors = []
	while number % 2 == 0:
		prime_factors.append(2)
		number = number / 2
	for i in range(3, int(math.sqrt(number)) + 1, 2):
		while number % i == 0:
			prime_factors.append(int(i))
			number = number / i
	if number > 2:
		prime_factors.append(int(number))
	return prime_factors

def get_frequency(list):
	dic = {}
	for ele in list:
		if ele in dic:
			dic[ele] += 1
		else:
			dic[ele] = 1
	return dic
(n, b) = map(int, input().split())
a = list(map(int, input().split()))
ans = 0
l = []
for i in range(n - 2):
	if a[i] % 2:
		ans += 1
	else:
		ans -= 1
	if ans == 0:
		l.append(abs(a[i] - a[i + 1]))
if len(l) == 0:
	print(0)
else:
	l.sort()
	if b < l[0]:
		print(0)
	else:
		final = 0
		for i in range(len(l)):
			if l[i] <= b:
				b -= l[i]
				final += 1
			else:
				break
		print(final)


(n, b) = map(int, input().split())
a = list(map(int, input().split()))
e = 0
o = 0
ans = []
for i in range(n - 1):
	if a[i] % 2 == 0:
		e += 1
	else:
		o += 1
	if e == o and e != 0:
		ans.append([i, abs(a[i] - a[i + 1])])
ans.sort(key=lambda x: x[1])
sol = 0
ch = 0
for i in ans:
	if sol + i[1] > b:
		break
	sol += i[1]
	ch += 1
print(ch)


from sys import stdin, stdout
from collections import Counter
from itertools import permutations
import bisect
import math
I = lambda : map(int, stdin.readline().split())
I1 = lambda : stdin.readline()
(n, b) = I()
a = list(I())
cut = 0
cost = []
for i in range(n):
	if a[i] % 2 == 0:
		cut += 1
	else:
		cut -= 1
	if cut == 0 and i < n - 1:
		cost.append(abs(a[i + 1] - a[i]))
cost.sort()
c = 0
ans = 0
for x in cost:
	if c + x <= b:
		c += x
		ans += 1
	else:
		break
print(ans)


def main():
	(n, B) = [int(c) for c in input().split()]
	a = [int(c) for c in input().split()]
	even_l = odd_l = 0
	even_r = sum((1 for e in a if e % 2 == 0))
	odd_r = n - even_r
	costs = []
	for (i, e) in enumerate(a[:-1]):
		if e % 2 == 0:
			even_l += 1
			even_r -= 1
		else:
			odd_l += 1
			odd_r -= 1
		if even_l == odd_l and even_r == odd_r:
			costs.append(abs(a[i + 1] - a[i]))
	costs.sort()
	_sum = 0
	i = 0
	while i < len(costs):
		if _sum + costs[i] <= B:
			_sum += costs[i]
			i += 1
		else:
			break
	print(i)
main()


(n, b) = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
even = 0
odd = 0
cuts = []
for i in range(0, n):
	if a[i] % 2 == 0:
		even += 1
	else:
		odd += 1
	if even == odd:
		cuts.append(i)
		even = 0
		odd = 0
cuts.pop()
l = len(cuts)
B = 0
cost = []
for i in range(0, l):
	B += abs(a[cuts[i]] - a[cuts[i] + 1])
	cost.append(abs(a[cuts[i]] - a[cuts[i] + 1]))
L = len(cost)
r = len(cost) - 1
l = 0
while B > b:
	max = cost[0]
	for i in cost:
		if i > max:
			max = i
	B -= max
	cost.remove(max)
print(len(cost))


import bisect
import itertools

def count(i, j, a):
	cnt_even = 0
	cnt_odd = 0
	for k in range(i, j + 1):
		if a[k] % 2 == 0:
			cnt_even += 1
		else:
			cnt_odd += 1
	return cnt_even == cnt_odd
(n, b) = map(int, input().split())
a = list(map(int, input().split()))
p = []
if n % 2 == 1:
	print(0)
else:
	for i in range(1, n - 2, 2):
		if count(0, i, a) and count(i + 1, n - 1, a):
			p.append(abs(a[i + 1] - a[i]))
	p.sort()
	p = list(itertools.accumulate(p))
	print(bisect.bisect_right(p, b))


I = lambda : map(int, input().split())
(n, B) = I()
(A, D, count, k) = (list(I()), [], 0, 0)
for (a1, a2) in zip(A, A[1:]):
	count = count - 1 if a1 % 2 else count + 1
	if count == 0:
		D.append(abs(a1 - a2))
for d in sorted(D):
	if d > B:
		break
	(B, k) = (B - d, k + 1)
print(k)


(n, k) = map(int, input().split())
l = [int(i) for i in input().split()]
z = [1 if i & 1 else -1 for i in l]
sum = 0
cutPzbl = []
for i in range(n - 1):
	sum += z[i]
	if sum == 0:
		cutPzbl.append(abs(l[i] - l[i + 1]))
cutPzbl.sort()
i = 0
y = len(cutPzbl)
sum = 0
c = 0
while i < y and sum + cutPzbl[i] <= k:
	sum += cutPzbl[i]
	c += 1
	i += 1
print(c)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
cnt = []
cnt1 = 0
cnt2 = 0
for i in range(n - 1):
	if a[i] % 2 == 0:
		cnt1 += 1
	else:
		cnt2 += 1
	if cnt1 == cnt2:
		cnt.append(abs(a[i + 1] - a[i]))
		cnt1 = 0
		cnt2 = 0
cnt.sort()
r = 0
sum = 0
for i in range(len(cnt)):
	sum += cnt[i]
	if sum > k:
		sum -= cnt[i]
		break
	r += 1
print(r)


(n, b) = map(int, input().split())
a = list(map(int, input().split()))
x = y = 0
c = []
ans = 0
k = 0
for i in range(n - 1):
	if a[i] % 2 == 0:
		x += 1
	else:
		y += 1
	if x == y:
		c.append(abs(a[i] - a[i + 1]))
c.sort()
for i in c:
	if k + i <= b:
		k += i
		ans += 1
	else:
		break
print(ans)


(n, B) = (int(s) for s in input().split())
arr = [int(s) for s in input().split()]
arr_odd = [0] * n
arr_even = [0] * n
if arr[0] % 2 == 0:
	arr_even[0] = 1
else:
	arr_odd[0] = 1
for i in range(1, n):
	if arr[i] % 2 == 0:
		arr_even[i] = arr_even[i - 1] + 1
		arr_odd[i] = arr_odd[i - 1]
	else:
		arr_odd[i] = arr_odd[i - 1] + 1
		arr_even[i] = arr_even[i - 1]
arr_cost = [123445] * n
for i in range(0, n - 1):
	if i % 2 == 0 or arr_odd[i] != arr_even[i]:
		arr_cost[i] = 123456
	else:
		arr_cost[i] = abs(arr[i + 1] - arr[i])
ans = 0
arr_cost.sort()
i = 0
while B - arr_cost[i] >= 0:
	ans += 1
	B -= arr_cost[i]
	i += 1
print(ans)


l = [int(i) for i in input().split()]
n = l[0]
b = l[1]
a = [int(i) for i in input().split()]
cnt = 0
dif = list()
k = 0
for i in range(n):
	if a[i] % 2 == 0:
		cnt += 1
	else:
		cnt -= 1
	if cnt == 0 and i != n - 1:
		dif.append(abs(a[i] - a[i + 1]))
		k += 1
dif.sort()
ans = 0
for value in dif:
	if value <= b:
		b -= value
		ans += 1
	if b <= 0:
		break
print(ans)


num_input = input()
num_input = num_input.split(' ')
n = int(num_input[0])
B = int(num_input[1])
arr = input()
arr = arr.split(' ')
for i in range(0, len(arr)):
	arr[i] = int(arr[i])
even = 0
odd = 0
res = []
for i in range(0, len(arr)):
	if arr[i] % 2 == 0:
		even += 1
	else:
		odd += 1
	if i < n - 1 and even == odd:
		res.append(abs(arr[i + 1] - arr[i]))
count = 0
res.sort()
index = 0
while index < len(res):
	if B - res[index] >= 0:
		B = B - res[index]
		count += 1
		index += 1
	else:
		break
print(count)


def scanf(t=int):
	return list(map(t, input().split()))
(n, b) = scanf()
m = scanf()
(ct, nct) = (0, 0)
temp = []
for i in range(n - 1):
	if m[i] % 2:
		nct += 1
	else:
		ct += 1
	if ct == nct:
		temp.append(abs(m[i] - m[i + 1]))
(ans, k) = (0, 0)
for x in sorted(temp):
	ans += x
	if ans > b:
		break
	k += 1
print(k)


(n, b) = list(map(int, input().split()))
arr = list(map(int, input().split()))
(even, odd) = (0, 0)
res_arr = []
for i in range(len(arr)):
	if arr[i] % 2 == 0:
		even += 1
	else:
		odd += 1
	if even == odd:
		if i == len(arr) - 1:
			break
		res_arr.append(abs(arr[i + 1] - arr[i]))
res_arr.sort()
(result, count) = (0, 0)
for j in range(len(res_arr)):
	if res_arr[j] <= b:
		b -= res_arr[j]
		count += 1
	if b == 0:
		break
print(count)


R = lambda : list(map(int, input().split(' ')))
(n, B) = R()
a = R()
even = [0 if ai % 2 == 1 else 1 for ai in a]
even_sum = []
sum = 0
for i in range(n):
	sum += even[i]
	even_sum.append(sum)
can = []
for i in range(n):
	can.append(1 if i > 0 and i % 2 == 0 and (even_sum[i - 1] == i // 2) and (even_sum[-1] - even_sum[i - 1] == (n - i) // 2) else 0)
b = [abs(a[i] - a[i - 1]) if can[i] else 1000 for i in range(2, n)]
b.sort()
sum = 0
cnt = 0
while cnt < len(b) and sum + b[cnt] <= B:
	sum += b[cnt]
	cnt += 1
print(cnt)