During the winter holidays, the demand for Christmas balls is exceptionally high. Since it's already 2018, the advances in alchemy allow easy and efficient ball creation by utilizing magic crystals.

Grisha needs to obtain some yellow, green and blue balls. It's known that to produce a yellow ball one needs two yellow crystals, green — one yellow and one blue, and for a blue ball, three blue crystals are enough.

Right now there are A yellow and B blue crystals in Grisha's disposal. Find out how many additional crystals he should acquire in order to produce the required number of balls.


-----Input-----

The first line features two integers A and B (0 ≤ A, B ≤ 10^9), denoting the number of yellow and blue crystals respectively at Grisha's disposal.

The next line contains three integers x, y and z (0 ≤ x, y, z ≤ 10^9) — the respective amounts of yellow, green and blue balls to be obtained.


-----Output-----

Print a single integer — the minimum number of crystals that Grisha should acquire in addition.


-----Examples-----
Input
4 3
2 1 1

Output
2

Input
3 9
1 1 3

Output
1

Input
12345678 87654321
43043751 1000000000 53798715

Output
2147483648



-----Note-----

In the first sample case, Grisha needs five yellow and four blue crystals to create two yellow balls, one green ball, and one blue ball. To do that, Grisha needs to obtain two additional crystals: one yellow and one blue.

Difficulty: EASY
Tags: Implementation
Expected Time Complexity: O(1)

Starter code:

Solutions:
(a, b) = map(int, input().split())
(x, y, z) = map(int, input().split())
s = 0
if 2 * x > a:
	s += 2 * x - a + y
elif 2 * x + y > a:
	s += 2 * x + y - a
if y > b:
	s += y - b + 3 * z
elif y + 3 * z > b:
	s += y + 3 * z - b
print(s)


(a, b) = map(int, input().split())
(x, y, z) = map(int, input().split())
y_cr = x * 2
b_cr = z * 3
y_cr += y
b_cr += y
print(max(y_cr - a, 0) + max(b_cr - b, 0))


(a, b) = map(int, input().split())
(x, y, z) = map(int, input().split())
yellow = 2 * x + y
blue = 3 * z + y
answer = max(0, yellow - a) + max(0, blue - b)
print(answer)


(A, B) = input().split()
A = int(A)
B = int(B)
(y, g, b) = input().split()
y = int(y)
g = int(g)
b = int(b)
B = B - (g + 3 * b)
A = A - (2 * y + g)
m = 0
if A < 0:
	m = m - A
if B < 0:
	m = m - B
print(m)


(n, m) = map(int, input().strip().split()[:2])
(y, g, b) = map(int, input().strip().split()[:3])
yell = y * 2 + g
blu = b * 3 + g
if n >= yell:
	if m >= blu:
		print(0)
	else:
		print(blu - m)
elif m >= blu:
	print(yell - n)
else:
	print(abs(yell - n) + abs(blu - m))


import sys
num_crystals = sys.stdin.readline().rstrip()
num_crystals = num_crystals.split()
(yellow_c, blue_c) = (int(num_crystals[0]), int(num_crystals[1]))
balls = sys.stdin.readline().rstrip()
balls = balls.split()
(yellow, green, blue) = balls
crystals_r_y = int(yellow) * 2 + int(green)
crystals_r_b = int(blue) * 3 + int(green)
yellow_a = max(0, crystals_r_y - yellow_c)
blue_a = max(0, crystals_r_b - blue_c)
sys.stdout.write(str(yellow_a + blue_a) + '\n')


(a, b) = map(int, input().split())
(x, y, z) = map(int, input().split())
(yellow, blue) = (0, 0)
yellow = 2 * x + y
blue = 3 * z + y
x = yellow - a if yellow > a else 0
y = blue - b if blue > b else 0
print(x + y)


R = lambda : map(int, input().split())
(a, b) = R()
(x, y, z) = R()
print(max(2 * x + y - a, 0) + max(y + 3 * z - b, 0))


(x, y) = map(int, input().strip().split())
(a, b, c) = map(int, input().strip().split())
(tx, ty) = (2 * a + b, 3 * c + b)
print(max(0, max(0, tx - x) + max(0, ty - y)))


(A, B) = [int(a) for a in input().strip().split()]
(x, y, z) = [int(a) for a in input().strip().split()]
need_A = 2 * x + y
need_B = y + 3 * z
result_A = 0
result_B = 0
if need_A > A:
	result_A = need_A - A
if need_B > B:
	result_B = need_B - B
print(str(result_A + result_B))


inp = list(map(int, input().split()))
output = list(map(int, input().split()))
(YellowNeed, BlueNeed) = (0, 0)
YellowNeed = max(output[0] * 2 + output[1] - inp[0], 0)
BlueNeed = max(output[1] + output[2] * 3 - inp[1], 0)
ans = YellowNeed + BlueNeed
print(ans)


(y, b) = map(int, input().split())
(yy, gg, bb) = map(int, input().split())
ry = 2 * yy + gg
rb = 3 * bb + gg
print(max(0, ry - y) + max(0, rb - b))


(a, b) = list(map(int, input().split()))
(x, y, z) = list(map(int, input().split()))
ty = x * 2 + y
tb = y + 3 * z
print(max(0, ty - a) + max(0, tb - b))


one = [int(n) for n in input().split()]
two = [int(n) for n in input().split()]
yellowCrystals = one[0]
blueCrystals = one[1]
yellowBals = two[0]
greenBalls = two[1]
blueBalls = two[2]
yellowNeeded = 0 - yellowCrystals
yellowNeeded += yellowBals * 2 + greenBalls
blueNeeded = 0 - blueCrystals
blueNeeded += blueBalls * 3 + greenBalls
if yellowNeeded < 0 and blueNeeded < 0:
	print(0)
elif yellowNeeded < 0:
	print(blueNeeded)
elif blueNeeded < 0:
	print(yellowNeeded)
else:
	print(yellowNeeded + blueNeeded)


s = input().split(' ')
a = int(s[0])
b = int(s[1])
s1 = input().split(' ')
x = int(s1[0])
y = int(s1[1])
z = int(s1[2])
i = x * 2 + y
j = z * 3 + y
ans = 0
if i > a:
	ans += i - a
if j > b:
	ans += j - b
print(ans)


import sys
(Y, B) = sys.stdin.readline().strip().split(' ')
Y = int(Y)
B = int(B)
[y1, g1, b1] = sys.stdin.readline().strip().split(' ')
y1 = int(y1)
g1 = int(g1)
b1 = int(b1)
Y = Y - g1
B = B - g1
Y = y1 * 2 - Y
B = b1 * 3 - B
if Y < 0:
	Y = 0
if B < 0:
	B = 0
t = B + Y
print(t)


(A, B) = map(int, input().split())
(x, y, z) = map(int, input().split())
yellow = 2 * x + y
blue = 3 * z + y
print(max(yellow - A, 0) + max(blue - B, 0))


(a, b) = map(int, input().split())
(x, y, z) = map(int, input().split())
print(max(0, y + z + z + z - b) + max(0, y + x + x - a))


def main():
	(a, b) = map(int, input().split())
	(x, y, z) = map(int, input().split())
	need_y = x * 2 + y
	need_b = 3 * z + y
	print(max(0, need_y - a) + max(0, need_b - b))

def __starting_point():
	main()
__starting_point()


(y, b) = list(map(int, input().split()))
(ny, ng, nb) = list(map(int, input().split()))
print(max(ng + ny * 2 - y, 0) + max(ng + 3 * nb - b, 0))


(A, B) = map(int, input().split())
(x, y, z) = map(int, input().split())
a = 2 * x + y
b = y + 3 * z
balls = 0
if A < a:
	balls += a - A
if B < b:
	balls += b - B
print(balls)


[A, B] = map(int, input().split())
[y, g, b] = map(int, input().split())
print(max(0, 2 * y + g - A) + max(0, g + 3 * b - B))


(a, b) = list(map(int, input().split()))
(x, y, z) = list(map(int, input().split()))
add = 0
if a < 2 * x:
	add += 2 * x - a
	a = 0
else:
	a -= 2 * x
if a < y:
	add += y - a
	a = 0
else:
	a -= y
if b < y:
	add += y - b
	b = 0
else:
	b -= y
if b < 3 * z:
	add += 3 * z - b
	b = 0
else:
	b -= 3 * z
print(add)


(a, b) = map(int, input().split(' '))
(x, y, z) = map(int, input().split(' '))
ans = max(0, 2 * x + y - a) + max(0, y + 3 * z - b)
print(ans)


(a, b) = list(map(int, input().split()))
(P, Q, R) = list(map(int, input().split()))
print(max(2 * P + Q - a, 0) + max(3 * R + Q - b, 0))


(a, b) = [int(i) for i in input().split()]
(x, y, z) = [int(i) for i in input().split()]
a -= 2 * x
a -= y
b -= y
b -= 3 * z
ans = 0
if a < 0:
	ans -= a
if b < 0:
	ans -= b
print(ans)


(a, b) = map(int, input().split())
(x, y, z) = map(int, input().split())
a -= 2 * x + y
b -= y + 3 * z
ans = (-a if a < 0 else 0) + (-b if b < 0 else 0)
print(ans)


(a, b) = map(int, input().split())
(x, y, z) = map(int, input().split())
target_a = 2 * x + y
target_b = y + 3 * z
print(max(0, target_a - a) + max(0, target_b - b))


import math, itertools, fractions, heapq, collections, bisect, sys, queue, copy
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
mod = 10 ** 9 + 7
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 [int(x) for x in sys.stdin.readline().split()]

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

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

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

def S():
	return input()

def main():
	(a, b) = LI()
	(c, d, e) = LI()
	ans = 0
	if a < c * 2:
		ans += c * 2 - a
		a = 0
	else:
		a -= c * 2
	if b < e * 3:
		ans += e * 3 - b
		b = 0
	else:
		b -= e * 3
	(a, b) = sorted([a, b])
	if d < a:
		return ans
	elif d > b:
		return ans + (2 * d - (a + b))
	else:
		return ans + (d - a)
print(main())


import sys
import math
get_string = lambda : sys.stdin.readline().strip()
get_int_list = lambda : list(map(int, sys.stdin.readline().strip().split()))
get_intList_from_str = lambda : list(map(int, list(sys.stdin.readline().strip())))
get_charList_from_str = lambda : list(sys.stdin.readline().strip())
get_char_list = lambda : sys.stdin.readline().strip().split()
get_int = lambda : int(sys.stdin.readline())
pt = lambda x: sys.stdout.write(str(x))
(a, b) = get_int_list()
(x, y, z) = get_int_list()
yellow = x * 2 + y * 1
blue = y * 1 + z * 3
print(max(0, yellow - a) + max(0, blue - b))


(yellow, blue) = map(int, input().split())
(y, g, b) = map(int, input().split())
yellow_needed = y * 2 + g
blue_needed = b * 3 + g
r = max(0, yellow_needed - yellow) + max(0, blue_needed - blue)
print(r)


from sys import stdin, stdout
(A, B) = map(int, stdin.readline().rstrip().split())
(x, y, z) = map(int, stdin.readline().rstrip().split())
A -= 2 * x
A -= y
B -= y
B -= 3 * z
crystals = 0
if A < 0:
	crystals += -A
if B < 0:
	crystals += -B
print(crystals)


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
eps = 1.0 / 10 ** 15
mod = 10 ** 9 + 7

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

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 main():
	(a, b) = LI()
	(x, y, z) = LI()
	a -= x * 2
	a -= y
	b -= y
	b -= z * 3
	r = 0
	if a < 0:
		r -= a
	if b < 0:
		r -= b
	return r
print(main())


(A, B) = map(int, input().split())
(x, y, z) = map(int, input().split())
blue = 3 * z + y
yellow = 2 * x + y
ANS = 0
if blue > B:
	ANS += blue - B
if yellow > A:
	ANS += yellow - A
print(ANS)


(a, b) = map(int, input().split())
(x, y, z) = map(int, input().split())
an = x * 2 + y
bn = z * 3 + y
an = an - a
if an < 0:
	an = 0
bn = bn - b
if bn < 0:
	bn = 0
print(an + bn)


(A, B) = map(int, list(input().split()))
(x, y, z) = map(int, list(input().split()))
print(max(0, 2 * x + y - A) + max(0, 3 * z + y - B))


(yellow, blue) = map(int, input().split())
(YELLOW, GREEN, BLUE) = map(int, input().split())
Yellow = 2 * YELLOW + GREEN
Blue = 3 * BLUE + GREEN
if yellow >= Yellow:
	yellow = 0
	Yellow = 0
if blue >= Blue:
	blue = 0
	Blue = 0
print(Yellow - yellow + Blue - blue)


(A, B) = map(int, input().split())
(yellow, green, blue) = map(int, input().split())
Answer = 0
z = yellow * 2 + green
a = blue * 3 + green
print(max(z - A, 0) + max(a - B, 0))


(a, b) = map(int, input().split())
(x, y, z) = map(int, input().split())
needa = x * 2 + y
needb = y + 3 * z
res = 0
if b < needb:
	res += needb - b
if a < needa:
	res += needa - a
print(res)


(a, b) = [int(i) for i in input().split()]
(x, y, z) = [int(i) for i in input().split()]
a1 = 2 * x + y
b1 = y + 3 * z
print(max(a1 - a, 0) + max(b1 - b, 0))


(y_c, b_c) = map(int, input().split())
(y_b, g_b, b_b) = map(int, input().split())
need_y = 2 * y_b + 1 * g_b - y_c
need_b = 1 * g_b + 3 * b_b - b_c
print(sum([n for n in [need_y, need_b] if n > 0]))


(yellow_crystals, blue_crystals) = map(int, input().split())
(yellow, green, blue) = map(int, input().split())
a = max(yellow * 2 + green - yellow_crystals, 0)
b = max(blue * 3 + green - blue_crystals, 0)
print(a + b)


import itertools

def main():
	(a, b) = [int(v) for v in input().split()]
	(x, y, z) = [int(v) for v in input().split()]
	cx = x * 2 + y
	cz = 3 * z + y
	print(max(0, cx - a) + max(0, cz - b))
main()


s = input().split()
a = int(s[0])
b = int(s[1])
s = input().split()
(x, y, z) = [int(s[i]) for i in range(len(s))]
a1 = 2 * x + y - a
b1 = y + 3 * z - b
if a1 < 0:
	a1 = 0
if b1 < 0:
	b1 = 0
print(a1 + b1)


n = list(map(int, input().split()))
s = list(map(int, input().split()))
print(max(2 * s[0] + s[1] - n[0], 0) + max(3 * s[2] + s[1] - n[1], 0))


(y, bl) = map(int, input().split())
(a, b, c) = map(int, input().split())
ny = nb = 0
ny += 2 * a + b
nb += b + 3 * c
print(max(0, nb - bl) + max(0, ny - y))


(A, B) = map(int, input().split())
(x, y, z) = map(int, input().split())
(A1, B1) = (0, 0)
count = 0
A1 = x * 2 + y
B1 += y + 3 * z
if A1 > A:
	count += A1 - A
if B1 > B:
	count += B1 - B
print(count)


(a, b) = (int(x) for x in input().split())
(x, y, z) = (int(x) for x in input().split())
a_n = 0
b_n = 0
a_n += x * 2
a_n += y
b_n += y
b_n += 3 * z
if a > a_n:
	a_n = 0
else:
	a_n = a_n - a
if b > b_n:
	b_n = 0
else:
	b_n = b_n - b
print(a_n + b_n)


(m, n) = map(int, input().split())
(a, b, c) = map(int, input().split())
t1 = a * 2 + b
t2 = b + 3 * c
if t1 > m:
	t1 = t1 - m
else:
	t1 = 0
if t2 > n:
	t2 = t2 - n
else:
	t2 = 0
print(t1 + t2)


a = list(input().split(' '))
(x, y) = (int(a[0]), int(a[1]))
arr = list(input().split(' '))
(a, b, c) = (int(arr[0]), int(arr[1]), int(arr[2]))
res = 0
if 2 * a + b - x > 0:
	res += 2 * a + b - x
if b + 3 * c - y > 0:
	res += b + 3 * c - y
print(res)


(Y, B) = map(int, input().split())
(y, g, b) = map(int, input().split())
ye = Y - (g + 2 * y)
bl = B - (g + 3 * b)
if ye < 0 or bl < 0:
	print(abs(min(ye, bl, ye + bl)))
else:
	print('0')


[A, B] = [int(i) for i in input().split()]
[x, y, z] = [int(i) for i in input().split()]
a = x * 2 + y
b = y + z * 3
ans1 = 0
ans2 = 0
if A - a < 0:
	ans1 = a - A
if B - b < 0:
	ans2 = b - B
print(ans1 + ans2)


(a, b) = map(int, input().split())
(x, y, z) = map(int, input().split())
ansy = max(2 * x + y - a, 0)
ansb = max(y + 3 * z - b, 0)
print(max(ansy + ansb, 0))


(A, B) = [int(p) for p in input().split()]
(x, y, z) = [int(p) for p in input().split()]
m = 2 * x + y
n = 3 * z + y
yellow = m - A
blue = n - B
if yellow >= 0 and blue >= 0:
	print(yellow + blue)
elif yellow < 0 and blue > 0:
	print(blue)
elif yellow > 0 and blue < 0:
	print(yellow)
else:
	print(0)


(A, B) = map(int, input().split())
(x, y, z) = map(int, input().split())
need_A = 0
need_B = 0
need_A += 2 * x
need_A += y
need_B += y
need_B += 3 * z
need = max(0, need_A - A) + max(0, need_B - B)
print(need)


a = input().split()
b = input().split()
f = 0
if int(b[0]) * 2 + int(b[1]) > int(a[0]):
	f += int(b[0]) * 2 + int(b[1]) - int(a[0])
if int(b[2]) * 3 + int(b[1]) > int(a[1]):
	f += int(b[2]) * 3 + int(b[1]) - int(a[1])
print(f)


(yellow_crystal, blue_crystal) = (int(i) for i in input().split())
(yellow_ball, green_ball, blue_ball) = (int(i) for i in input().split())
print(max(0, yellow_ball * 2 + green_ball - yellow_crystal) + max(0, green_ball + 3 * blue_ball - blue_crystal))


(A, B) = [int(i) for i in input().split()]
(x, y, z) = [int(i) for i in input().split()]
Demand_yellow = 2 * x + y - A
Demand_bule = 3 * z + y - B
if Demand_yellow < 0:
	Demand_yellow = 0
if Demand_bule < 0:
	Demand_bule = 0
print(Demand_yellow + Demand_bule)


(y, b) = map(int, input().split())
(y1, g1, b1) = map(int, input().split())
yell = y1 * 2 + g1
blue = b1 * 3 + g1
if yell > y and blue > b:
	print(yell - y + blue - b)
elif yell > y:
	print(yell - y)
elif blue > b:
	print(blue - b)
else:
	print(0)


(a, b) = list(map(int, input().split()))
(x, y, z) = list(map(int, input().split()))
yellow = 2 * x + y
blue = y + 3 * z
c = max(0, yellow - a) + max(0, blue - b)
print(c)


import sys
input = lambda : sys.stdin.readline().strip()
li = lambda : list(map(int, input().split()))
(a, b) = li()
(x, y, z) = li()
print(max(0, 2 * x + y - a) + max(0, 3 * z + y - b))


(a, b) = [int(i) for i in input().split()]
(x, y, z) = [int(i) for i in input().split()]
e = 2 * x + y
f = y + 3 * z
t = 0
if a < e:
	t = t + e - a
if b < f:
	t = t + f - b
print(t)


(a, b) = list(map(int, input().split()))
(x, y, z) = list(map(int, input().split()))
for (i, j) in ([2 * x, 0], [y, y], [0, 3 * z]):
	a -= i
	b -= j
s = int()
if a < 0:
	s -= a
if b < 0:
	s -= b
print(s)


(yellow_cry, blue_cry) = list(map(int, input().split()))
(yellow, green, blue) = list(map(int, input().split()))
ans = 0
yellow = 2 * yellow + green
blue = 3 * blue + green
ans = max(0, yellow - yellow_cry) + max(0, blue - blue_cry)
print(ans)


(A, B) = map(int, input().split())
(x, y, z) = map(int, input().split())
nem = x * 2 + y
nes = z * 3 + y
print(max(nem - A, 0) + max(nes - B, 0))


s = [int(n) for n in input().split()]
z = [int(n) for n in input().split()]
a = z[0] * 2 + z[1]
b = z[2] * 3 + z[1]
if a > s[0] and b <= s[1]:
	print(a - s[0])
elif a <= s[0] and b > s[1]:
	print(b - s[1])
elif a > s[0] and b > s[1]:
	print(a + b - (s[0] + s[1]))
else:
	print(0)


(a, b) = list(map(int, input().split()))
(x, y, z) = list(map(int, input().split()))
c = 2 * x + y
d = y + 3 * z
print(max(c - a, 0) + max(d - b, 0))


(a, b) = map(int, input().split())
(x, y, z) = map(int, input().split())
a_need = x * 2 + y - a
b_need = z * 3 + y - b
if a_need <= 0:
	a_need = 0
if b_need <= 0:
	b_need = 0
print(a_need + b_need)


(A, B) = [int(k) for k in input().split(' ') if k]
(x, y, z) = [int(k) for k in input().split(' ') if k]
A -= 2 * x
B -= 3 * z
A -= y
B -= y
s = 0
if A < 0:
	s += -A
if B < 0:
	s += -B
print(s)


(a, b) = map(int, input().split())
(x, y, z) = map(int, input().split())
w = 2 * x + y
e = 3 * z + y
rt = w - a
rte = e - b
if rt >= 0 and rte >= 0:
	print(rt + rte)
else:
	if rt < 0:
		rt = 0
	else:
		rte = 0
	if rt <= 0 and rte <= 0:
		rt = 0
		rte = 0
	print(rt + rte)


string = input().split(' ')
a = int(string[0])
b = int(string[1])
string = input().split(' ')
yellow = int(string[0])
green = int(string[1])
blue = int(string[2])
needed = 0
aNeeded = yellow * 2 + green
bNeeded = green + 3 * blue
aAdditional = max(aNeeded - a, 0)
bAdditional = max(bNeeded - b, 0)
print(str(aAdditional + bAdditional))


(g_yellow, g_blue) = input().split()
(r_yellow, r_green, r_blue) = input().split()
req_yellow = int(r_yellow) * 2 + int(r_green)
req_blue = int(r_green) + int(r_blue) * 3
ans_yellow = 0
ans_blue = 0
if req_yellow >= int(g_yellow):
	ans_yellow = req_yellow - int(g_yellow)
if req_blue >= int(g_blue):
	ans_blue = req_blue - int(g_blue)
print(ans_yellow + ans_blue)


(q, w) = map(int, input().split())
(z, x, c) = map(int, input().split())
res = 0
(a, s) = (0, 0)
q -= z * 2 + x
w -= 3 * c + x
if q < 0:
	res += abs(q)
if w < 0:
	res += abs(w)
print(res)


s = input().split()
(yc, bc) = (int(s[0]), int(s[1]))
s = input().split()
(y, g, b) = (int(s[0]), int(s[1]), int(s[2]))
tyc = y * 2 + g
tbc = b * 3 + g
t = (tyc - yc if tyc > yc else 0) + (tbc - bc if tbc > bc else 0)
print(t)


(y, b) = map(int, input().split())
(yb, gb, bb) = map(int, input().split())
reqY = 2 * yb + gb - y if 2 * yb + gb - y > 0 else 0
reqB = 3 * bb + gb - b if 3 * bb + gb - b > 0 else 0
req = reqY + reqB
print(req)


(x, y) = map(int, input().split())
(a, b, c) = map(int, input().split())
x = x - b
y = y - b
p = 0
x = x - a * 2
y = y - c * 3
if x < 0:
	p = p + abs(x)
if y < 0:
	p = p + abs(y)
print(p)


(a, b) = list(map(int, input().split()))
(x, y, z) = list(map(int, input().split()))
yel = 2 * x + y
bl = 3 * z + y
print(max(0, yel - a) + max(0, bl - b))


import sys
R = lambda : map(int, input().split())
(n, m) = R()
(x, y, z) = R()
n -= x * 2 + y
m -= z * 3 + y
print(sum((x * -1 for x in [n, m] if x < 0)))


inp = list(map(int, input().split()))
(yellow_c, blue_c) = (inp[0], inp[1])
inp = list(map(int, input().split()))
(yellow_b, green_b, blue_b) = (inp[0] * 2, inp[1], inp[2] * 3)
cnt = 0
required_y = yellow_b - yellow_c
left_y = left_b = 0
if required_y >= 0:
	cnt += required_y
else:
	left_y = -1 * required_y
required_b = blue_b - blue_c
if required_b >= 0:
	cnt += required_b
else:
	left_b = -1 * required_b
required_g_y = green_b - left_y
required_g_b = green_b - left_b
cnt += required_g_y if required_g_y > 0 else 0
cnt += required_g_b if required_g_b > 0 else 0
print(cnt)


s = input().split()
(a, b) = (int(s[0]), int(s[1]))
s = input().split()
(x, y, z) = (int(s[0]), int(s[1]), int(s[2]))
n = 2 * x + y
m = 3 * z + y
n = n - a
m = m - b
if n < 0:
	n = 0
if m < 0:
	m = 0
print(n + m)


(p, q) = map(int, input().split())
(Yball, Gball, Bball) = map(int, input().split())
ycrys = 2 * Yball + Gball
bcrys = Gball + 3 * Bball
(a, b) = (0, 0)
if ycrys > p:
	a = ycrys - p
if bcrys > q:
	b = bcrys - q
print(a + b)


(x, y) = map(int, input().split())
(a, b, c) = map(int, input().split())
print(abs(min(0, x - 2 * a - b) + min(0, y - 3 * c - b)))


(yc, bc) = map(int, input().split())
(yb, gb, bb) = map(int, input().split())
yreq = 2 * yb + gb
breq = 3 * bb + gb
sum = 0
if yreq > yc:
	sum = sum + (yreq - yc)
if breq > bc:
	sum = sum + (breq - bc)
print(sum)


(a, b) = map(int, input().split())
(x, y, z) = map(int, input().split())
p = 2 * x + y
q = y + 3 * z
print(max(0, p - a) + max(0, q - b))


s = input()
z = int(s.split()[0])
a = int(s.split()[1])
s = input()
z1 = int(s.split()[0])
s1 = int(s.split()[1])
a1 = int(s.split()[2])
z -= z1 * 2
a -= a1 * 3
z -= s1
a -= s1
p = 0
if a < 0:
	p += -a
if z < 0:
	p += -z
print(p)


R = lambda : list(map(int, input().split()))
(a, b) = R()
(x, y, z) = R()
A = x + x + y
B = y + 3 * z
print(max(0, A - a) + max(0, B - b))


(Y, B) = [int(i) for i in input().split()]
(y, g, b) = [int(i) for i in input().split()]
req_y = 2 * y + g
req_b = g + 3 * b
req = 0
if req_b > B:
	req += req_b - B
if req_y > Y:
	req += req_y - Y
print(req)


s = 0
o = input().rstrip().split(' ')
q = input().rstrip().split(' ')
y_m = int(q[0])
g_m = int(q[1])
b_m = int(q[2])
y_c = y_m * 2 + g_m
b_c = g_m + b_m * 3
if y_c > int(o[0]):
	s = s + (y_c - int(o[0]))
if b_c > int(o[1]):
	s = s + (b_c - int(o[1]))
print(s)


(yc, bc) = list(map(int, input().split()))
(y, g, b) = list(map(int, input().split()))
yc -= y * 2
yc -= g
bc -= g
bc -= b * 3
print(abs(min(yc, 0)) + abs(min(bc, 0)))


def main():
	(yl, bl) = map(lambda x: int(x), input().split(' '))
	(x, y, z) = map(lambda x: int(x), input().split(' '))
	need_yl = x * 2 + y - yl
	need_bl = z * 3 + y - bl
	return (need_bl if need_bl > 0 else 0) + (need_yl if need_yl > 0 else 0)
print(main())


(a, b) = map(int, input().split())
(x, y, z) = map(int, input().split())
cnt = 0
if 2 * x + y > a:
	cnt += 2 * x + y - a
if y + 3 * z > b:
	cnt += y + 3 * z - b
print(cnt)


(A, B) = input().split()
A = int(A)
B = int(B)
(x, y, z) = input().split()
x = int(x)
y = int(y)
z = int(z)
yellow_needed = max(x * 2 + y - A, 0)
blue_needed = max(y + z * 3 - B, 0)
print(str(yellow_needed + blue_needed))


(yc, bc) = map(int, input().split())
(y, g, b) = map(int, input().split())
print(max(2 * y + g - yc, 0) + max(g + 3 * b - bc, 0))


(a, b) = (int(i) for i in input().split())
(x, y, z) = (int(i) for i in input().split())
x1 = x * 2 + y
z1 = z * 3 + y
m = 0
if x1 - a >= 0 and z1 - b >= 0:
	m = x1 - a + z1 - b
elif z1 - b < 0 and x1 - a >= 0:
	m = x1 - a
elif x1 - a < 0 and z1 - b >= 0:
	m = z1 - b
print(m)


(yl, b) = map(int, input().split())
(x, y, z) = map(int, input().split())
n_y = x * 2 + y - yl
n_b = y + z * 3 - b
if n_y < 0:
	n_y = 0
if n_b < 0:
	n_b = 0
print(n_y + n_b)


(a, b) = list(map(int, input().split()))
(x, y, z) = list(map(int, input().split()))
aa = 2 * x + y
bb = y + 3 * z
print(max(bb - b, 0) + max(aa - a, 0))


z = lambda : map(int, input().split())
(c, d) = z()
(e, f, g) = z()
a = c - (e * 2 + f) if c - (e * 2 + f) < 0 else 0
b = d - f - g * 3 if d - f - g * 3 < 0 else 0
print(-1 * (a + b))


a = 0
b = 0
x = 0
y = 0
z = 0
(a, b) = map(int, input().split())
(x, y, z) = map(int, input().split())
neededY = 2 * x
neededB = y
neededY += y
neededB += 3 * z
neededY -= a
neededB -= b
print(max(neededB, 0) + max(neededY, 0))


(a, b) = map(int, input().split())
(x, y, z) = map(int, input().split())
a_need = 2 * x + y
b_need = y + 3 * z
a1 = a_need - a if a_need > a else 0
b1 = b_need - b if b_need > b else 0
print(a1 + b1)


(A, B) = list(map(int, input().split()))
(x, y, z) = list(map(int, input().split()))
need_a = 2 * x + 1 * y + 0 * z
need_b = 1 * y + 3 * z
print(max(0, need_a - A) + max(0, need_b - B))


(A, B) = map(int, input().split())
(x, y, z) = map(int, input().split())
A -= x * 2
A -= y
B -= y
B -= 3 * z
if A > 0:
	A = 0
if B > 0:
	B = 0
print(abs(A + B))


(a, b) = map(int, input().split())
s = list(map(int, input().split()))
yellow = 2 * s[0] + s[1]
blue = s[1] + 3 * s[2]
ans = 0
if yellow > a:
	ans += yellow - a
if blue > b:
	ans += blue - b
print(ans)


from sys import stdin
(a, b) = map(int, stdin.readline().split())
(x, y, z) = map(int, stdin.readline().split())
c = 2 * x + y
d = 3 * z + y
c -= a
d -= b
if c < 0:
	c = 0
if d < 0:
	d = 0
answer = c + d
print(answer)


class BallMaker:

	def __init__(self, yellow, blue):
		self.yellow = yellow
		self.blue = blue

	def set_required_crystals(self, y, g, b):
		yellow = 2 * y + g
		blue = g + 3 * b
		self.yellow_required = yellow
		self.blue_required = blue

	def acquire_count(self, y, g, b):
		self.set_required_crystals(y, g, b)
		yellow = max(0, self.yellow_required - self.yellow)
		blue = max(0, self.blue_required - self.blue)
		return yellow + blue
(yellow, blue) = map(int, input().split())
ball_maker = BallMaker(yellow, blue)
(y, g, b) = map(int, input().split())
print(ball_maker.acquire_count(y, g, b))


(a, b) = map(int, input().split())
(x, y, z) = map(int, input().split())
(yy, bb) = (x * 2 + y, z * 3 + y)
print((yy - a if yy > a else 0) + (bb - b if bb > b else 0))


(a, b) = map(int, input().split())
(x, y, z) = map(int, input().split())
yellow = x * 2 + y
blue = y + z * 3
a -= yellow
b -= blue
total = 0
if a < 0 and b < 0:
	total += -(a + b)
elif a < 0:
	total += -a
elif b < 0:
	total += -b
print(total)


(a, b) = map(int, input().split())
(x, y, z) = map(int, input().split())
yr = 2 * x + y
br = y + 3 * z
s = 0
if yr > a:
	s = s + yr - a
if br > b:
	s = s + br - b
print(s)


(A, B) = map(int, input().split())
(x, y, z) = map(int, input().split())
summ = 0
y1 = 0
b1 = 0
y1 = x * 2 + y
b1 = y + 3 * z
summ = 0
if y1 > A:
	summ += y1 - A
if b1 > B:
	summ += b1 - B
print(summ)


entrada = input().split()
yellow = int(entrada[0])
blue = int(entrada[1])
entrada = input().split()
y = int(entrada[0])
g = int(entrada[1])
b = int(entrada[2])
Y = 2 * y + g - yellow
B = g + 3 * b - blue
if Y <= 0 and B <= 0:
	print(0)
elif Y <= 0:
	print(B)
elif B <= 0:
	print(Y)
else:
	print(Y + B)


x = input().split()
a = int(x[0])
b = int(x[1])
s = input().split()
x = int(s[0])
y = int(s[1])
z = int(s[2])
yellow = 2 * x + y
blue = y + 3 * z
sum = 0
if yellow > a:
	sum += yellow - a
if blue > b:
	sum += blue - b
print(sum)


import math
(a, b) = map(int, input().split())
(x, y, z) = map(int, input().split())
yellow = 2 * x + y
blue = y + 3 * z
ans = max(0, yellow - a) + max(0, blue - b)
print(ans)


(yt, bt) = map(int, input().split(' '))
(y, g, b) = map(int, input().split(' '))
yr = y * 2 + g
br = g + 3 * b
print(max(yr - yt, 0) + max(br - bt, 0))


(a, b) = map(int, input().split())
(x, y, z) = map(int, input().split())
(na, nb) = (0, 0)
na = 2 * x + y
nb = 3 * z + y
print('{}'.format(max(na - a, 0) + max(nb - b, 0)))


(a, b) = map(int, input().split())
(x, y, z) = map(int, input().split())
yel = 2 * x + y
bel = y + 3 * z
ans1 = yel - a
ans2 = bel - b
if ans1 < 0:
	ans1 = 0
if ans2 < 0:
	ans2 = 0
print(ans1 + ans2)


def solve(A, B, x, y, z):
	b = z * 3 + y
	y = x * 2 + y
	return max(0, y - A) + max(0, b - B)

def main():
	(A, B) = list(map(int, input().split()))
	(x, y, z) = list(map(int, input().split()))
	print(solve(A, B, x, y, z))
main()


(a, b) = map(int, input().split())
(x, y, z) = map(int, input().split())
yl = 2 * x + y
bl = 3 * z + y
print(max(yl - a, 0) + max(bl - b, 0))


def read():
	return list(map(int, input().split()))
(a, b) = read()
(x, y, z) = read()
a -= 2 * x + y
b -= 3 * z + y
s = 0
if a < 0:
	s -= a
if b < 0:
	s -= b
print(s)


(yel, bul) = map(int, input().split())
(yreq, greq, breq) = map(int, input().split())
yel -= yreq * 2 + greq
bul -= breq * 3 + greq
need = 0
if yel < 0:
	need += -yel
if bul < 0:
	need += -bul
print(need)


def main():
	(have_yellow_cryst, have_blue_cryst) = tuple(map(int, input().split()))
	(yellow, green, blue) = tuple(map(int, input().split()))
	need_yellow_cryst = 2 * yellow + green
	need_blue_cryst = green + 3 * blue
	need_to_buy = 0
	if have_yellow_cryst - need_yellow_cryst < 0:
		need_to_buy += need_yellow_cryst - have_yellow_cryst
	if have_blue_cryst - need_blue_cryst < 0:
		need_to_buy += need_blue_cryst - have_blue_cryst
	print(need_to_buy)
main()


(a, b) = map(int, input().split())
(x, y, z) = map(int, input().split())
yellow = x * 2 + y
blue = y + z * 3
c = 0
d = yellow - a
f = blue - b
if d > 0:
	c += d
if f > 0:
	c += f
print(c)


def main():
	(yCry, bCry) = map(int, input().split())
	(y_b, g_b, b_b) = map(int, input().split())
	yCry = yCry - y_b * 2 - g_b
	bCry = bCry - b_b * 3 - g_b
	res = 0
	if yCry < 0:
		res -= yCry
	if bCry < 0:
		res -= bCry
	print(res)
main()


(a, b) = list(map(int, input().split()))
(x, y, z) = list(map(int, input().split()))
t = 3 * z + y
r = y + 2 * x
p = 0
if b >= t:
	pass
else:
	p += t - b
if a >= r:
	pass
else:
	p += r - a
print(p)


(estZh, estSin) = map(int, input().split())
(sharZh, sharZel, sharSin) = map(int, input().split())
counter = 0
nadoZh = sharZh * 2 + sharZel
nadoSin = sharSin * 3 + sharZel
nexvZh = nadoZh - estZh
if nexvZh > 0:
	counter += nexvZh
nexvSin = nadoSin - estSin
if nexvSin > 0:
	counter += nexvSin
print(counter)


(a, b) = [int(x) for x in input().split()]
(x, y, z) = [int(x) for x in input().split()]
aans = 2 * x + y - a
bans = 3 * z + y - b
print(max(0, aans, bans, aans + bans))


yb = list(map(int, input().split()))
ans = [0, 0]
L = list(map(int, input().split()))
ans[0] = 2 * L[0] + L[1]
ans[1] = L[1] + 3 * L[2]
ans[0] = max(ans[0], yb[0])
ans[1] = max(ans[1], yb[1])
print(sum(ans) - sum(yb))


(A, B) = [int(i) for i in input().split(' ')]
(x, y, z) = [int(i) for i in input().split(' ')]
nA = x * 2 + y
nB = y + z * 3
diff = (0 if nA - A < 0 else nA - A) + (0 if nB - B < 0 else nB - B)
print(diff)


from operator import itemgetter
(a, b) = map(int, input().split())
(x, y, z) = map(int, input().split())
ans = max(0, -a + x * 2 + y)
ans += max(0, -b + z * 3 + y)
print(ans)


n = list(map(int, input().split()))
n1 = list(map(int, input().split()))
y = n[0] - 2 * n1[0]
b = n[1] - 3 * n1[2]
g1 = y - n1[1]
g2 = b - n1[1]
if g1 < 0 and g2 > 0:
	g1 = g1 * -1
	print(g1)
elif g2 < 0 and g1 > 0:
	g2 = g2 * -1
	print(g2)
elif g1 + g2 < 0:
	print((g1 + g2) * -1)
else:
	print('0')


(x, y) = map(int, input().split())
(a, b, c) = map(int, input().split())
if x <= 2 * a + b:
	r = 2 * a + b - x
else:
	r = 0
if y <= 3 * c + b:
	t = b + 3 * c - y
else:
	t = 0
print(r + t)


(countY, countB) = map(int, input().split())
(y, g, b) = map(int, input().split())
print(max(0, y * 2 + g - countY) + max(0, b * 3 + g - countB))


(x, y) = map(int, input().split())
(z, t, p) = map(int, input().split())
print(max(0, 2 * z + t - x) + max(0, 3 * p + t - y))


(A, B) = map(int, input().split())
(x, y, z) = map(int, input().split())
req_yellow = 2 * x + y
req_blue = y + 3 * z
req_yellow_cry = 0
req_blue_cry = 0
if req_yellow > A:
	req_yellow_cry = req_yellow - A
if req_blue > B:
	req_blue_cry = req_blue - B
print(req_yellow_cry + req_blue_cry)


(yc, bc) = [int(x) for x in input().split()]
(yb, gb, bb) = [int(x) for x in input().split()]
ans = 0
if yc < yb * 2:
	ans += yb * 2 - yc
	yc = 0
else:
	yc -= yb * 2
if bc < bb * 3:
	ans += bb * 3 - bc
	bc = 0
else:
	bc -= bb * 3
if yc < gb:
	ans += gb - yc
if bc < gb:
	ans += gb - bc
print(ans)


(A, B) = map(int, input().split())
(Zu, Z, P) = map(int, input().split())
A = A - Zu * 2 - Z
B = B - 3 * P - Z
if A < 0:
	A = abs(A)
else:
	A = 0
if B < 0:
	B = abs(B)
else:
	B = 0
print(A + B)


_1_ = list(map(int, input().split()))
_2_ = list(map(int, input().split()))
_1_[0] -= _2_[0] * 2 + _2_[1] * 1
_1_[1] -= _2_[1] * 1 + _2_[2] * 3
_3_ = 0
if _1_[0] < 0:
	_3_ += abs(_1_[0])
if _1_[1] < 0:
	_3_ += abs(_1_[1])
print(_3_)


(a, b) = map(int, input().split())
(x, y, z) = map(int, input().split())
k = int(0)
a = a - 2 * x - y
b = b - y - 3 * z
if a < 0:
	k = k + abs(a)
if b < 0:
	k = k + abs(b)
print(k)


(A, B) = map(int, input().split())
(y, g, b) = map(int, input().split())
count = 0
X = y * 2 + g * 1
c1 = abs(X - A)
if A < X:
	count += c1
Y = g * 1 + b * 3
c2 = abs(Y - B)
if B < Y:
	count += c2
print(count)


(a, b) = map(int, input().split())
(x, y, z) = map(int, input().split())
yo = max(0, x * 2 + y - a)
oy = max(0, y + z * 3 - b)
print(yo + oy)


(a, b) = map(int, input().split())
(x, y, z) = map(int, input().split())
yel = max(0, 2 * x + y - a)
blu = max(0, y + 3 * z - b)
print(yel + blu)


[a, b] = map(int, input().split())
[x, y, z] = map(int, input().split())
aneed = 0
bneed = 0
aneed += 2 * x
aneed += y
bneed += 3 * z
bneed += y
if aneed >= a:
	aneed -= a
else:
	aneed = 0
if bneed >= b:
	bneed -= b
else:
	bneed = 0
answer = aneed + bneed
print(int(answer))


(y, b) = map(int, input().split())
(yb, gb, bb) = map(int, input().split())
yc = 2 * yb + gb
bc = 3 * bb + gb
res = 0
if yc > y:
	res = yc - y
if bc > b:
	res = res + bc - b
print(res)


import sys
(yellowc, bluec) = tuple(map(int, sys.stdin.readline().strip().split()))
(yellowb, greenb, blueb) = tuple(map(int, sys.stdin.readline().strip().split()))
needyc = max(0, yellowb * 2 + greenb - yellowc)
needbc = max(0, blueb * 3 + greenb - bluec)
result = needyc + needbc
print(result)


def solution(l1, l2):
	ycr = l1[0]
	bcr = l1[1]
	yb = l2[0]
	gb = l2[1]
	bb = l2[2]
	nb = 3 * bb + gb
	ny = 2 * yb + gb
	nb = max(nb - bcr, 0)
	ny = max(ny - ycr, 0)
	return nb + ny

def answer():
	l1 = [int(x) for x in input().split()]
	l2 = [int(x) for x in input().split()]
	print(solution(l1, l2))
answer()


(A, B) = map(int, input().split())
(y, g, b) = map(int, input().split())
y_num = 2 * y + g * 1 + b * 0
b_num = y * 0 + g * 1 + b * 3
if y_num > A:
	y_add = y_num - A
else:
	y_add = 0
if b_num > B:
	b_add = b_num - B
else:
	b_add = 0
print(y_add + b_add)


s = input()
s1 = s.split()
a = int(s1[0])
b = int(s1[1])
s = input()
s1 = s.split()
x = int(s1[0])
y = int(s1[1])
z = int(s1[2])
n1 = 2 * int(x) + int(y)
n2 = int(y) + 3 * int(z)
n = 0
if n1 > a:
	n += n1 - a
if n2 > b:
	n += n2 - b
print(n)


l = [int(e) for e in input().split()]
le = [int(e) for e in input().split()]
print(max(0, le[0] * 2 + le[1] - l[0]) + max(0, le[2] * 3 + le[1] - l[1]))


(a, b) = (int(x) for x in input().split())
(x, y, z) = (int(x) for x in input().split())
total = 0
(aa, bb) = (2 * x + y, 3 * z + y)
if a < aa:
	total += aa - a
if b < bb:
	total += bb - b
print(total)


(a, b) = map(int, input().split())
(x, y, z) = map(int, input().split())
a1 = 2 * x + y
b1 = 3 * z + y
s = max(a1 - a, 0) + max(b1 - b, 0)
print(s)


(Y, B) = map(int, input().split())
(y, g, b) = map(int, input().split())
y_needed = 0 if Y >= 2 * y + g else 2 * y + g - Y
b_needed = 0 if B >= 3 * b + g else 3 * b + g - B
print(y_needed + b_needed)


(a, b) = map(int, input().split())
(x, y, z) = map(int, input().split())
min_a = 2 * x + y
min_b = y + 3 * z
res = max(0, min_a - a) + max(0, min_b - b)
print(res)


from sys import stdin
input = stdin.readline
(n, m) = map(int, input().split())
(first, second, third) = map(int, input().split())
yellow_side = first * 2 + second * 1
blue_side = second * 1 + third * 3
side1 = yellow_side - n
side2 = blue_side - m
if side1 <= 0 and side2 <= 0:
	print(0)
elif side1 <= 0:
	print(side2)
elif side2 <= 0:
	print(side1)
elif side1 <= 0 and side2 <= 0:
	print(0)
else:
	print(side1 + side2)


(yel, bl) = map(int, input().split(' '))
(x, y, z) = map(int, input().split(' '))
yel -= x * 2 + y
bl -= z * 3 + y
print(abs(min(yel, 0) + min(bl, 0)))


def main():
	(A, B) = map(int, input().split())
	(X, Y, Z) = map(int, input().split())
	yellow = X * 2 + Y
	blue = Z * 3 + Y
	if yellow > A:
		y = yellow - A
	else:
		y = 0
	if blue > B:
		b = blue - B
	else:
		b = 0
	print(y + b)
main()


(y, b) = map(int, input().split())
(Y, G, B) = map(int, input().split())
p = Y * 2 + G
q = G + B * 3
if y >= p and b >= q:
	print('0')
elif y >= p and b < q:
	print(q - b)
elif y < p and b >= q:
	print(p - y)
else:
	print(p - y + (q - b))


(yc, bc) = [int(i) for i in input().split()]
(y, g, b) = [int(i) for i in input().split()]
tot_y = 2 * y + g
tot_b = g + 3 * b
print(max(0, tot_y - yc) + max(0, tot_b - bc))


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

def dd(b):
	if b > 0:
		return b
	return 0
print(dd(x[0] * 2 + x[1] - a) + dd(3 * x[2] + x[1] - b))


(a, b) = [int(i) for i in input().split()]
(x, y, z) = [int(i) for i in input().split()]
p = 2 * x + y
q = 3 * z + y
if p > a and q > b:
	print(p - a + q - b)
elif p > a:
	print(p - a)
elif q > b:
	print(q - b)
else:
	print('0')


r = lambda : map(int, input().split())
(y, b) = r()
(j, k, l) = r()
print(max(0, k + 3 * l - b) + max(0, k + 2 * j - y))


[yc, bc] = map(int, input().split())
[y, g, b] = map(int, input().split())
needed_yc = 2 * y + g
needed_bc = 3 * b + g
buy_yc = max(0, needed_yc - yc)
buy_bc = max(0, needed_bc - bc)
print(buy_yc + buy_bc)


inp = lambda : map(int, input().split())
(yell, blue) = inp()
(y, g, b) = inp()
yell -= 2 * y + g
blue -= 3 * b + g
ans = 0
if yell < 0:
	ans += abs(yell)
if blue < 0:
	ans += abs(blue)
print(ans)


(A, B) = map(int, input().split(' '))
(x, y, z) = map(int, input().split(' '))
y_needed = max(0, x * 2 + y - A)
b_needed = max(0, y + 3 * z - B)
print(y_needed + b_needed)


(ay, ab) = map(int, input().split())
(y, g, b) = map(int, input().split())
ty = 2 * y + 1 * g
tb = 3 * b + 1 * g
s = 0
if ay < ty:
	s += ty - ay
if ab < tb:
	s += tb - ab
print(s)


(a1, b1) = input().split()
a = int(a1)
b = int(b1)
(x1, y1, z1) = input().split()
x = int(x1)
y = int(y1)
z = int(z1)
u = x * 2 + y - a
v = z * 3 + y - b
if u < 0:
	u = 0
if v < 0:
	v = 0
print(u + v)


(y, b) = map(int, input().split())
(ye, gr, bl) = map(int, input().split())
print(-min(y - ye * 2 - gr, 0) - min(b - bl * 3 - gr, 0))


(A, B) = map(int, input().split())
(x, y, z) = map(int, input().split())
i = j = k = l = 0
i = x * 2 + y
j = y + z * 3
k = i - A
l = j - B
if k >= 0 and l >= 0:
	print(k + l)
elif k >= 0 and l < 0:
	print(k)
elif k < 0 and l >= 0:
	print(l)
elif k < 0 and l < 0:
	print('0')


(A, B) = map(int, input().split(' '))
(x, y, z) = map(int, input().split())
cy = 2 * x + y
cb = 3 * z + y
ans = max(0, cy - A)
ans += max(0, cb - B)
print(ans)


(a, b) = map(int, input().split())
(x, y, z) = map(int, input().split())
green = x * 2 + y
blue = 3 * z + y
ans = 0
if a < green:
	ans += green - a
if b < blue:
	ans += blue - b
print(ans)


(a, b) = [int(i) for i in input().split()]
(x, y, z) = [int(i) for i in input().split()]
(n, m) = (0, 0)
n += 2 * x
n += y
m += y
m += 3 * z
s = 0
if a - n < 0:
	s += n - a
if b - m < 0:
	s += m - b
print(s)


ab = input().split()
A = int(ab[0])
B = int(ab[1])
xyz = input().split()
x = int(xyz[0])
y = int(xyz[1])
z = int(xyz[2])
a = 2 * x + y
b = y + 3 * z
need = 0
if a - A > 0:
	need += a - A
if b - B > 0:
	need += b - B
print(need)


def main():
	(a, b) = map(int, input().split())
	(x, y, z) = map(int, input().split())
	na = 2 * x + y
	nb = y + 3 * z
	ans = max(0, na - a) + max(0, nb - b)
	print(ans)
main()


(a, b) = map(int, input().split())
(x, y, z) = map(int, input().split())
a = a - y - 2 * x
b = b - y - 3 * z
if a >= 0 and b >= 0:
	print(0)
elif a < 0 and b < 0:
	print(abs(-a - b))
elif a < 0:
	print(abs(-a))
elif b < 0:
	print(abs(-b))


pin = lambda : map(int, input().split())
(y, b) = pin()
(Y, G, B) = pin()
reqy = 2 * Y + G
reqb = G + 3 * B
print(max(0, reqy - y) + max(0, reqb - b))


(a, b) = map(int, input().split())
(x, y, z) = map(int, input().split())
ans1 = max(0, 2 * x + y - a)
ans2 = max(0, y + 3 * z - b)
print(ans1 + ans2)


(A, B) = (int(i) for i in input().split())
(x, y, z) = (int(i) for i in input().split())
Y = 0
C = 0
Y += 2 * x + y
C += 3 * z + y
res = 0
if Y > A:
	res += Y - A
if C > B:
	res += C - B
print(res)


(zlu, blu) = map(int, input().split())
(x, y, z) = map(int, input().split())
zl = 2 * x + y
bl = 3 * z + y
if zl > zlu:
	dif1 = zl - zlu
else:
	dif1 = 0
if bl > blu:
	dif2 = bl - blu
else:
	dif2 = 0
print(dif1 + dif2)


import sys
crystals = sys.stdin.readline().split()
A = int(crystals[0])
B = int(crystals[1])
balls = sys.stdin.readline().split()
x = int(balls[0])
y = int(balls[1])
z = int(balls[2])
req_yellow = 2 * x + y
req_blue = 3 * z + y
req_add = 0
if req_yellow - A > 0:
	req_add += req_yellow - A
if req_blue - B > 0:
	req_add += req_blue - B
print(req_add)


def colour(curr, yNeed, bNeed):
	extra = [0, 0]
	if curr[0] >= yNeed:
		curr[0] -= yNeed
	else:
		extra[0] = yNeed - curr[0]
		curr[0] = 0
	if curr[1] >= bNeed:
		curr[1] -= bNeed
	else:
		extra[1] = bNeed - curr[1]
		curr[1] = 0
	return extra

def getExtra(Current, need):
	crystals = Current
	extraCrystals = 0
	for (i, num) in enumerate(need):
		if i == 0:
			yell = 2
			blue = 0
		elif i == 1:
			yell = 1
			blue = 1
		else:
			yell = 0
			blue = 3
		toAdd = colour(crystals, yell * num, blue * num)
		for item in toAdd:
			extraCrystals += item
	return extraCrystals
while True:
	try:
		crystals = input()
		temp = crystals.split(' ')
		for i in range(len(temp)):
			temp[i] = int(temp[i])
		crystals = temp
		need = input()
		temp = need.split(' ')
		for i in range(len(temp)):
			temp[i] = int(temp[i])
		need = temp
		print(getExtra(crystals, need))
	except EOFError:
		break


(Y, B) = list(map(int, input().split()))
(y, g, b) = list(map(int, input().split()))
print(max(2 * y + g - Y, 0) + max(3 * b + g - B, 0))


str = list(input().split())
y = int(str[0])
b = int(str[1])
str = list(input().split())
Y = int(str[0])
G = int(str[1])
B = int(str[2])
req_y = 2 * Y + G
req_b = G + 3 * B
ans = 0
if y > req_y:
	ans += 0
else:
	ans += req_y - y
if b > req_b:
	ans += 0
else:
	ans += req_b - b
print(ans)


(a, b) = [int(v) for v in input().split()]
(x, y, z) = [int(v) for v in input().split()]
ra = 2 * x + y
rb = y + 3 * z
print(max(ra - a, 0) + max(rb - b, 0))


def crystalsToBuy(a, b, x, y, z):
	toBuy = max(2 * x - a, 0)
	a = max(a - 2 * x, 0)
	toBuy += max(3 * z - b, 0)
	b = max(b - 3 * z, 0)
	return toBuy + max(y - a, 0) + max(y - b, 0)
(a, b) = map(int, input().split())
(x, y, z) = map(int, input().split())
print(crystalsToBuy(a, b, x, y, z))


(a, b) = [int(i) for i in input().split()]
(x, y, z) = [int(i) for i in input().split()]
yc = 0
bc = 0
yc = yc + 2 * x
yc = yc + 1 * y
bc = bc + 1 * y
bc = bc + 3 * z
ayc = yc - a
if ayc <= 0:
	ayc = 0
abc = bc - b
if abc <= 0:
	abc = 0
print(abc + ayc)


import sys
sys.setrecursionlimit(1000000)
read = sys.stdin.readline
(Y, B) = map(int, read().split())
(y, g, b) = map(int, read().split())
nY = 2 * y + g
nB = g + 3 * b
print(max(0, nY - Y) + max(0, nB - B))


(Y, B) = input().split()
Y = int(Y)
B = int(B)
L = [int(i) for i in input().split()]
for (index, count) in enumerate(L):
	if index == 0:
		Y = Y - 2 * count
		B = B - 0
	elif index == 1:
		Y = Y - count
		B = B - count
	elif index == 2:
		Y = Y - 0
		B = B - 3 * count
ans = 0
if Y < 0:
	ans += abs(Y)
if B < 0:
	ans += abs(B)
print(ans)


import sys

def main():
	(x, y, a, b, c) = map(int, sys.stdin.read().strip().split())
	return abs(min(x - a * 2 - b, 0)) + abs(min(y - b - 3 * c, 0))
print(main())


(a, b) = map(int, input().split())
(x, y, z) = map(int, input().split())
a1 = 2 * x + y
b1 = 3 * z + y
if a < a1:
	a2 = a1 - a
else:
	a2 = 0
if b < b1:
	b2 = b1 - b
else:
	b2 = 0
print(a2 + b2)


(y, b) = map(int, input().split())
(x, yy, z) = map(int, input().split())
y -= 2 * x
y -= yy
b -= yy
b -= 3 * z
if y < 0 and b < 0:
	print(-(y + b))
elif y < 0:
	print(-y)
elif b < 0:
	print(-b)
else:
	print(0)


import sys

def main():
	(A, B) = [int(x) for x in sys.stdin.readline().split()]
	(x, y, z) = [int(x) for x in sys.stdin.readline().split()]
	A_need = x * 2 + y
	B_need = y + 3 * z
	more = 0
	if A_need > A:
		more += A_need - A
	if B_need > B:
		more += B_need - B
	print(more)
main()


(A, B) = input().split()
A = int(A)
B = int(B)
(x, y, z) = input().split()
x = int(x)
y = int(y)
z = int(z)
yc = 2 * x + y - A
bc = y + 3 * z - B
if yc < 0:
	yc = 0
if bc < 0:
	bc = 0
print(yc + bc)


(a, b) = map(int, input().split())
(x, y, z) = map(int, input().split())
yellow = blue = 0
yellow += 2 * x
yellow += 1 * y
blue += 1 * y
blue += 3 * z
need = 0
if yellow > a:
	need += yellow - a
if blue > b:
	need += blue - b
print(need)


(A, B) = [int(x) for x in input().split()]
(x, y, z) = [int(x) for x in input().split()]
print(max(0, 2 * x + y - A) + max(0, y + 3 * z - B))


import math
(A, B) = list(map(int, input().split()))
(x, y, z) = list(map(int, input().split()))
blue = 0
yellow = 0
yellow = yellow + x * 2
yellow = yellow + y
blue = blue + y
blue = blue + z * 3
yr = max(yellow - A, 0)
br = max(blue - B, 0)
print(yr + br)


import sys
(y, b) = input().strip().split(' ')
y = int(y)
b = int(b)
(yb, gb, bb) = input().strip().split(' ')
yb = int(yb)
gb = int(gb)
bb = int(bb)
ycrst = yb * 2 + gb
bcrst = bb * 3 + gb
ycount = ycrst - y
bcount = bcrst - b
if ycount >= 0 and bcount >= 0:
	count = ycount + bcount
elif ycount < 0 and bcount < 0:
	count = 0
elif ycount < 0:
	count = bcount
elif bcount < 0:
	count = ycount
if count >= 0:
	print(count)
else:
	print('0')


(a, b) = input().split()
a = int(a)
b = int(b)
(x, y, z) = input().split()
x = int(x)
y = int(y)
z = int(z)
a -= 2 * x
a -= y
b -= y
b -= 3 * z
if a > 0:
	a = 0
if b > 0:
	b = 0
print(-1 * (a + b))


(y, b) = map(int, input().split())
(a, c, d) = map(int, input().split())
q = a * 2 + c - y
w = c + d * 3 - b
if q >= 0 and w >= 0:
	print(q + w)
elif q >= 0 and w < 0:
	print(q)
elif q < 0 and w >= 0:
	print(w)
else:
	print(0)


(x, y) = map(int, input().split())
(a, b, c) = map(int, input().split())
g = 2 * a + b - x
h = 3 * c + b - y
print(max(0, g) + max(0, h))


(yellow, blue) = map(int, input().split())
(y_balls, g_balls, b_balls) = map(int, input().split())
total_yellow = y_balls * 2 + g_balls
total_blue = b_balls * 3 + g_balls
need = max(total_yellow - yellow, 0) + max(total_blue - blue, 0)
if need >= 0:
	print(need)
else:
	print(need)
	print(0)


(A, B) = map(int, input().split())
(x, y, z) = map(int, input().split())
c = 2 * x + y
d = z * 3 + y
print(max(c - A, 0) + max(d - B, 0))


l = list(map(int, input().split()))
m = list(map(int, input().split()))
a = 2 * m[0] + m[1]
b = 3 * m[2] + m[1]
y = a - l[0]
d = b - l[1]
if y > 0 and d > 0:
	h = y + d
	print(h)
elif y > 0:
	print(y)
elif d > 0:
	print(d)
else:
	print('0')


import math
from decimal import Decimal

def na():
	n = int(input())
	b = [int(x) for x in input().split()]
	return (n, b)

def nab():
	n = int(input())
	b = [int(x) for x in input().split()]
	c = [int(x) for x in input().split()]
	return (n, b, c)

def dv():
	(n, m) = map(int, input().split())
	return (n, m)

def dva():
	(n, m) = map(int, input().split())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	return (n, m, b)

def eratosthenes(n):
	sieve = list(range(n + 1))
	for i in sieve:
		if i > 1:
			for j in range(i + i, len(sieve), i):
				sieve[j] = 0
	return sorted(set(sieve))

def nm():
	n = int(input())
	b = [int(x) for x in input().split()]
	m = int(input())
	c = [int(x) for x in input().split()]
	return (n, b, m, c)

def dvs():
	n = int(input())
	m = int(input())
	return (n, m)
(a, b) = map(int, input().split())
(x, y, z) = map(int, input().split())
print(max(2 * x + y - a, 0) + max(y + 3 * z - b, 0))


(yellow, blue) = map(int, input().split())
(y, g, b) = map(int, input().split())
total_yellows = y * 2 + g
total_blues = b * 3 + g
total = 0
if yellow < total_yellows:
	total += total_yellows - yellow
if blue < total_blues:
	total += total_blues - blue
print(total)


import sys

def main():
	(yellow_crystals, blue_crystals) = map(int, input().split())
	(yellow, green, blue) = map(int, input().split())
	yellow_req = yellow * 2 + green
	blue_req = green + blue * 3
	print(max(0, yellow_req - yellow_crystals) + max(0, blue_req - blue_crystals))
main()


(a, b) = map(int, input().split())
(y, g, bl) = map(int, input().split())
c = max(0, 2 * y + g - a) + max(0, 3 * bl + g - b)
print(c)


def main():
	(a, b) = map(int, input().split())
	(x, y, z) = map(int, input().split())
	a -= x * 2 + y
	b -= y + z * 3
	print(max(-a, 0) + max(-b, 0))
main()


(a, b) = [int(x) for x in input().split()]
(x, y, z) = [int(x) for x in input().split()]
a -= x << 1
a -= y
b -= y
b -= 3 * z
t = 0 if a >= 0 else -a
t += -b if b < 0 else 0
print(t)


(n, m) = [int(i) for i in input().split()]
(x, y, z) = [int(i) for i in input().split()]
rn = 2 * x + y
rm = 3 * z + y
ans = 0
if rn > n:
	ans += rn - n
if rm > m:
	ans += rm - m
print(ans)


inp = input().split(' ')
yellowcount = int(inp[0])
bluecount = int(inp[1])
inp = input().split(' ')
yellowneeded = int(inp[0]) * 2 + int(inp[1])
blueneeded = int(inp[2]) * 3 + int(inp[1])
res = 0
if yellowneeded - yellowcount > 0:
	res = res + yellowneeded - yellowcount
if blueneeded - bluecount > 0:
	res = res + blueneeded - bluecount
print(res)


arr1 = [int(x) for x in input().split()]
arr2 = [int(x) for x in input().split()]
oyc = arr1[0]
obc = arr1[1]
yb = arr2[0]
gb = arr2[1]
bb = arr2[2]
val1 = max(0, 2 * yb + gb - oyc)
val2 = max(0, 3 * bb + gb - obc)
print(val1 + val2)


(cy, cb) = map(int, input().split())
(y, g, b) = map(int, input().split())
cb -= b * 3
cy -= y * 2
cy -= g
cb -= g
print(max(-cy, 0) + max(-cb, 0))


(s, b) = list(map(int, input().split()))
(x, y, z) = list(map(int, input().split()))
op = 0
c = 0
sop = 0
op += 2 * x + y
c += 3 * z + y
if op > s:
	sop += op - s
if c > b:
	sop += c - b
print(sop)


(y1, b1) = map(int, input().strip().split(' '))
(y, g, b) = map(int, input().strip().split(' '))
print(max(0, 2 * y + g - y1) + max(0, g + 3 * b - b1))


def get_input():
	return map(int, input().split())
(a, b) = get_input()
(x, y, z) = get_input()
a_ = x * 2 + y
b_ = z * 3 + y
result = a_ - a if a_ > a else 0
result += b_ - b if b_ > b else 0
print(result)


def main():
	[yellow_crystals, blue_crystals] = [int(_) for _ in input().split()]
	[yellow_balls, green_balls, blue_balls] = [int(_) for _ in input().split()]
	additional_yellow_crystals = max(0, yellow_balls * 2 + green_balls - yellow_crystals)
	additional_blue_crystals = max(0, blue_balls * 3 + green_balls - blue_crystals)
	result = additional_yellow_crystals + additional_blue_crystals
	print(result)
main()


(n, m) = map(int, input().split())
k = list(map(int, input().split()))
yellow = k[0] * 2 + k[1]
blue = k[2] * 3 + k[1]
s = 0
if yellow > n:
	s = s + (yellow - n)
if blue > m:
	s = s + (blue - m)
print(s)


(a, b) = [int(i) for i in input().split()]
(x, y, z) = [int(i) for i in input().split()]
res1 = 2 * x + y
res2 = 3 * z + y
res = 0
if res1 > a:
	res += res1 - a
if res2 > b:
	res += res2 - b
print(res)


[n, m] = list(map(int, input().split()))
[x, y, z] = list(map(int, input().split()))
ans = max(x * 2 + y - n, 0) + max(y + z * 3 - m, 0)
print(ans)


(A, B) = map(int, input().split())
(y, g, b) = map(int, input().split())
yc = y * 2 + g
bc = b * 3 + g
if A <= yc and B <= bc:
	print(yc + bc - A - B)
elif A > yc and B <= bc:
	print(bc - B)
elif A <= yc and B > bc:
	print(yc - A)
else:
	print(0)


(y, b) = list(map(int, input().split()))
(yb, gb, bb) = list(map(int, input().split()))
count = 0
if y < yb * 2:
	count += yb * 2 - y
	y = 0
else:
	y = y - yb * 2
if b < bb * 3:
	count += bb * 3 - b
	b = 0
else:
	b = b - bb * 3
if gb > y:
	count += gb - y
if gb > b:
	count += gb - b
if count < 0:
	count = 0
print(count)


(A, B) = input().split()
(x, y, z) = input().split()

def Ans(A, B, x, y, z):
	ans = 0
	yellow = 0
	blue = 0
	yellow += x * 2
	yellow += y * 1
	blue += y * 1
	blue += z * 3
	if yellow > A:
		ans += yellow - A
	if blue > B:
		ans += blue - B
	return ans
print(Ans(int(A), int(B), int(x), int(y), int(z)))


(yel, b) = [int(el) for el in input().split(' ')]
(x, y, z) = [int(ball) for ball in input().split(' ')]
yel_req = x * 2 + y * 1
b_req = y * 1 + z * 3
yel_req = max(0, yel_req - yel)
b_req = max(0, b_req - b)
print(yel_req + b_req)


(A, B) = map(int, input().split())
(a, b, c) = map(int, input().split())
cnt1 = 0
cnt2 = 0
cnt1 += a * 2 + b
cnt2 += b + 3 * c
ans = 0
if cnt1 > A:
	ans += cnt1 - A
if cnt2 > B:
	ans += cnt2 - B
print(ans)


(y, b) = map(int, input().split())
(ye, g, bl) = map(int, input().split())
yellow = 2 * ye + 1 * g
blue = 1 * g + 3 * bl
if yellow <= y and blue > b:
	print(abs(blue - b))
elif yellow > y and blue <= b:
	print(abs(yellow - y))
elif yellow > y and blue > b:
	print(abs(yellow + blue - (y + b)))
else:
	print(0)


(h_Y, h_B) = input().split(' ')
h_Y = int(h_Y)
h_B = int(h_B)
(x, y, z) = input().split(' ')
x = int(x)
y = int(y)
z = int(z)
n_Y = 2 * x + y
n_B = y + 3 * z
short_Y = n_Y - h_Y
short_B = n_B - h_B
if short_B < 0:
	short_B = 0
if short_Y < 0:
	short_Y = 0
shortage = short_Y + short_B
print(shortage)


crystal = input().split()
y_c = int(crystal[0])
b_c = int(crystal[1])
balls = input().split()
yellow = int(balls[0])
green = int(balls[1])
blue = int(balls[2])
need_yellow = 2 * yellow + green
need_blue = green + 3 * blue
ans_yellow = ans_blue = 0
if y_c < need_yellow:
	ans_yellow = need_yellow - y_c
if b_c < need_blue:
	ans_blue = need_blue - b_c
print(ans_yellow + ans_blue)


(y, n) = map(int, input().split())
(a, b, c) = map(int, input().split())
print(max(0, 2 * a + b - y) + max(0, 3 * c + b - n))


(y, b) = [int(x) for x in input().split()]
(a, u, c) = [int(q) for q in input().split()]
y1 = 2 * a + u
b1 = 3 * c + u
k1 = 0
k2 = 0
if y1 > y:
	k1 = y1 - y
if b1 > b:
	k2 = b1 - b
print(k1 + k2)


(m, n) = map(int, input().split())
(y, g, b) = map(int, input().split())
r1 = y * 2 + g * 1
r2 = g * 1 + b * 3
(x1, x2) = (0, 0)
if r1 > m:
	x1 = r1 - m
if r2 > n:
	x2 = r2 - n
if r1 <= m:
	x1 = 0
if r2 <= n:
	x2 = 0
print(x1 + x2)


entrada = input().split()
yellow = int(entrada[0])
blue = int(entrada[1])
entrada = input().split()
y = int(entrada[0])
g = int(entrada[1])
b = int(entrada[2])
nY = 2 * y + g
nB = g + 3 * b
nY -= yellow
nB -= blue
if nY <= 0 and nB <= 0:
	print(0)
elif nB <= 0:
	print(nY)
elif nY <= 0:
	print(nB)
else:
	print(nY + nB)


p = input().rstrip().split(' ')
q = input().rstrip().split(' ')
y = int(q[0]) * 2
g = int(q[1])
y += g
D = 0
b = int(q[2]) * 3
b += g
t_y = int(p[0])
t_b = int(p[1])
if t_y < y:
	D += y - t_y
if t_b < b:
	D += b - t_b
print(D)


(yc, bc) = map(int, input().split())
(yb, gb, bb) = map(int, input().split())
ycr = yb * 2 + gb * 1
bcr = bb * 3 + gb * 1
ye = ycr - yc if ycr > yc else 0
be = bcr - bc if bcr > bc else 0
print(str(ye + be))


(ye, b) = map(int, input().strip().split(' '))
(x, y, z) = map(int, input().strip().split(' '))
ans = max(2 * x + y - ye, 0) + max(y + 3 * z - b, 0)
print(ans)


def main():
	(a, b) = list(map(int, input().split()))
	(x, y, z) = list(map(int, input().split()))
	print(max(x * 2 + y - a, 0) + max(y + z * 3 - b, 0))
try:
	while True:
		main()
except EOFError:
	pass


(yCrystals, bCrystals) = [int(i) for i in input().split()]
(yellow, green, blue) = [int(i) for i in input().split()]
blue_required = 0
yellow_required = 0
A = green + yellow * 2
B = green + blue * 3
if yCrystals >= A:
	yellow_required = 0
else:
	yellow_required = A - yCrystals
if bCrystals >= B:
	blue_required = 0
else:
	blue_required = B - bCrystals
print(yellow_required + blue_required)


(a, b) = map(int, input().split())
(x, y, z) = map(int, input().split())
c = 0
i = 2 * x + y
j = y + 3 * z
if i > a:
	c += i - a
if j > b:
	c += j - b
print(c)


(a, b) = map(int, input().split())
(x, y, z) = map(int, input().split())
yc = x * 2 + y
bc = z * 3 + y
if a < yc:
	a = yc - a
else:
	a = 0
if b < bc:
	b = bc - b
else:
	b = 0
print(a + b)


(ys, bs) = map(int, input().split())
(y, g, b) = map(int, input().split())
ys -= y * 2 + g
bs -= b * 3 + g
ans = 0
if ys < 0:
	ans += abs(ys)
if bs < 0:
	ans += abs(bs)
print(ans)


(a, b) = [int(i) for i in input().split()]
(x, y, z) = [int(i) for i in input().split()]
(c, d) = (2 * x + y, y + 3 * z)
print(max(c - a, 0) + max(d - b, 0))


(a, b) = map(int, input().split())
(x, y, z) = map(int, input().split())
ye = 2 * x + y
bl = y + 3 * z
o = max(0, ye - a) + max(0, bl - b)
print(o)


(a, b) = [int(x) for x in input().split()]
(x, y, z) = [int(x) for x in input().split()]
a = a - x * 2 - y
b = b - y - 3 * z
res = 0
if a < 0:
	res += -1 * a
if b < 0:
	res += -1 * b
print(res)


(y, b) = input().split()
y = int(y)
b = int(b)
(oy, og, ob) = input().split()
oy = int(oy)
og = int(og)
ob = int(ob)
min = 0
yc = oy * 2 + og
yb = ob * 3 + og
if yc > y:
	min += yc - y
if yb > b:
	min += yb - b
print(min)


(a, b) = map(int, input().split())
(y, g, blue) = map(int, input().split())
yellow_needed = 2 * y + g
blue_needed = 3 * blue + g
ans = 0
if yellow_needed > a:
	ans += yellow_needed - a
if blue_needed > b:
	ans += blue_needed - b
print(ans)


crystal_arr = [int(x) for x in input().split(' ')]
ball_arr = [int(x) for x in input().split(' ')]
cry_yellow = crystal_arr[0]
cry_blue = crystal_arr[1]
req_cry_yellow = ball_arr[0] * 2 + ball_arr[1]
req_cry_blue = ball_arr[1] + ball_arr[2] * 3
num = 0
if req_cry_yellow > cry_yellow:
	num += req_cry_yellow - cry_yellow
if req_cry_blue > cry_blue:
	num += req_cry_blue - cry_blue
print(num)


(yellow, blue) = [int(x) for x in input().split()]
(a, b, c) = [int(x) for x in input().split()]
yellow_needed = a * 2 + b * 1 - yellow
if yellow_needed < 0:
	yellow_needed = 0
blue_needed = b * 1 + 3 * c - blue
if blue_needed < 0:
	blue_needed = 0
print(yellow_needed + blue_needed)


import sys
from bisect import bisect_left, bisect_right
from collections import deque, Counter
from math import gcd, sqrt, factorial, ceil, log10
from itertools import permutations
inf = float('inf')
mod = 1000000007
mini = 1000000007

def fact(n):
	if n == 0:
		return 1
	p = 1
	d = 10 ** 9 + 7
	for i in range(1, n + 1):
		p = p * i
		p = p % d
	return p

def ncr(n, r):
	d = 10 ** 9 + 7
	num = fact(n)
	den = fact(r) * fact(n - r) % d
	den = pow(den, d - 2, d)
	return num * den % d

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

def binary(number):
	result = 0
	while number:
		result = result + 1
		number = number & number - 1
	return result

def calculate_factors(n):
	hh = [1] * (n + 1)
	p = 2
	while p * p < n:
		if hh[p] == 1:
			for i in range(p * 2, n, p):
				hh[i] = 0
		p += 1
	total = 1
	for p in range(2, n + 1):
		if hh[p] == 1:
			count = 0
			if n % p == 0:
				while n % p == 0:
					n = int(n / p)
					count += 1
				total *= count + 1
	return total

def prime_factors(n):
	i = 2
	factors = set()
	while i * i <= n:
		if n % i:
			i += 1
		else:
			factors.add(n // i)
			n = n // i
			factors.add(i)
	if n > 1:
		factors.add(n)
	return factors

def isPrime(n):
	if n == 2 or n == 3:
		return True
	if n % 2 == 0 or n < 2:
		return False
	for i in range(3, int(n ** 0.5) + 1, 2):
		if n % i == 0:
			return False
	return True

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()
(yellow, blue) = get_ints()
(a, b, c) = get_ints()
y_req = 2 * a + b
b_req = 3 * c + b
y1 = max(0, y_req - yellow)
y2 = max(0, b_req - blue)
print(y1 + y2)


(yn, bn) = map(int, input().split())
(y, g, b) = map(int, input().split())
yc = y * 2
bc = b * 3
yc += g
bc += g
ans = 0
if yc > yn:
	ans += yc - yn
if bc > bn:
	ans += bc - bn
print(ans)


ab = list(map(lambda x: int(x), input().split(' ')))
xyz = list(map(lambda x: int(x), input().split(' ')))
(a, b) = (ab[0], ab[1])
(x, y, z) = (xyz[0], xyz[1], xyz[2])
yellow = x * 2 + y
blue = z * 3 + y
print(max(yellow - a, 0) + max(blue - b, 0))


(n, m) = map(int, input().split())
(a, b, c) = map(int, input().split())
sum1 = a * 2 + b
sum2 = b + c * 3
if n > sum1:
	n = sum1
if m > sum2:
	m = sum2
ans = sum1 - n + (sum2 - m)
if ans < 0:
	print(0)
else:
	print(ans)


(A, B) = [int(x) for x in input().split()]
(x, y, z) = [int(x) for x in input().split()]
minA = 2 * x + y
minB = y + 3 * z
ans = max(0, minA - A) + max(0, minB - B)
print(ans)


(yellow_cryst, blue_cryst) = list(map(int, input().strip().split()))
(yball_req, gball_req, bball_req) = list(map(int, input().strip().split()))
ycryst_req = 2 * yball_req + gball_req
bcryst_req = 3 * bball_req + gball_req
print(max(0, ycryst_req - yellow_cryst) + max(0, bcryst_req - blue_cryst))


(a, b) = map(int, input().split())
(x, y, z) = map(int, input().split())
a -= x * 2
a -= y
b -= y
b -= z * 3
out = abs(min(a, 0) + min(b, 0))
print(out)


(a, b) = input().split()
(x, y, z) = input().split()
h1 = -int(a) + int(x) * 2 + int(y)
h2 = -int(b) + int(y) + 3 * int(z)
print(max(h1, 0) + max(h2, 0))


ab = list(map(int, input().split()))
xyz = list(map(int, input().split()))
yb = [2 * xyz[0] + xyz[1], xyz[1] + 3 * xyz[2]]
result = [0, 0]
if yb[0] > ab[0]:
	result[0] = yb[0] - ab[0]
if yb[1] > ab[1]:
	result[1] = yb[1] - ab[1]
print(result[0] + result[1])


import os
import sys
from io import BytesIO, IOBase

def main():
	(a, b) = map(int, input().split(' '))
	(x, y, z) = map(int, input().split(' '))
	print(abs(min(0, a - 2 * x - y)) + abs(min(0, b - 3 * z - y)))
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()


x = input()
y = x.split()
yellow = int(y[0])
blue = int(y[1])
z = input()
r = z.split()
i1 = int(r[0])
i2 = int(r[1])
i3 = int(r[2])
req = 0
y_req = 2 * i1 + i2
b_req = 3 * i3 + i2
if y_req > yellow:
	req += y_req - yellow
if b_req > blue:
	req += b_req - blue
print(req)


(n, m) = [int(x) for x in input().split()]
(a, b, c) = [int(x) for x in input().split()]
yellow = 0
blue = 0
yellow += 2 * a
yellow += b
blue += b + 3 * c
print(max(0, yellow - n) + max(0, blue - m))


(yellow, blue) = list(map(int, input().split()))
(y, g, b) = list(map(int, input().split()))
current = [yellow, blue]
required = [y * 2 + g, g + 3 * b]
if required[0] > current[0] and required[1] > current[1]:
	print(required[0] - current[0] + required[1] - current[1])
elif required[0] > current[0]:
	print(required[0] - current[0])
elif required[1] > current[1]:
	print(required[1] - current[1])
else:
	print(0)


(a, b) = [int(i) for i in input().strip().split()]
(y, g, bl) = [int(i) for i in input().strip().split()]
ry = y * 2 + g
rb = bl * 3 + g
ans = 0
if ry > a:
	ans += abs(ry - a)
if rb > b:
	ans += abs(rb - b)
print(ans)


from sys import stdin
(a, b) = [int(x) for x in input().strip().split()]
(x, y, z) = [int(x) for x in input().strip().split()]
yy = 2 * x + y
bb = y + 3 * z
r = max(yy - a, 0)
r += max(bb - b, 0)
print(r)


(y, b) = map(int, input().split())
(Y, G, B) = map(int, input().split())
sum_y = Y * 2 + G
sum_b = G + 3 * B
ans = 0
if sum_y > y:
	ans += sum_y - y
if sum_b > b:
	ans += sum_b - b
print(ans)


[A, B] = map(int, input().split())
[x, y, z] = map(int, input().split())
s = max(2 * x + y - A, 0)
m = max(y + 3 * z - B, 0)
print(s + m)


(a, b) = [int(i) for i in input().split()]
(x, y, z) = [int(i) for i in input().split()]
ye = a - x * 2
bl = b - y
ye -= y
bl -= z * 3
m = 0
if bl < 0:
	m += -bl
if ye < 0:
	m += -ye
print(m)


(a, b) = [int(a) for a in input().split()]
(x, y, z) = [int(x) for x in input().split()]
count1 = 2 * x + y
count2 = y + 3 * z
ans = 0
if count1 >= a:
	ans = count1 - a
if count2 >= b:
	ans = ans + count2 - b
print(ans)


(a, b) = map(int, input().split())
(z, x, y) = map(int, input().split())
A = z * 2 + x
B = 3 * y + x
print(max(0, A - a) + max(0, B - b))


(a, b) = input().split()
(x, y, z) = input().split()
res_y = int(x) * 2 + int(y) - int(a)
if res_y < 0:
	res_y = 0
res_b = int(z) * 3 + int(y) - int(b)
if res_b < 0:
	res_b = 0
print(res_y + res_b)


s = str(input())
l = s.split()
a = int(l[0])
b = int(l[1])
s = str(input())
l = s.split()
x = int(l[0])
y = int(l[1])
z = int(l[2])
zutih = x * 2 + y
plavih = y + 3 * z
dod = 0
if zutih > a:
	dod += zutih - a
if plavih > b:
	dod += plavih - b
print(dod)


(YC, BC) = map(int, input().split())
(YB, GB, BB) = map(int, input().split())
YCR = 2 * YB + GB
BCR = GB + 3 * BB
print(max(0, YCR - YC) + max(0, BCR - BC))


(a, b) = map(int, input().split())
(c, d, e) = map(int, input().split())
q = e * 3 + d
w = c * 2 + d
if q - b >= 0:
	n = q - b
else:
	n = 0
if w - a >= 0:
	m = w - a
else:
	m = 0
print(m + n)


(A, B) = map(int, input().split())
(y, g, b) = map(int, input().split())
yellow_needed = y * 2 + g
blue_needed = 3 * b + g
if A < yellow_needed:
	yn = yellow_needed - A
else:
	yn = 0
if B < blue_needed:
	bn = blue_needed - B
else:
	bn = 0
print(bn + yn)


(A, B) = list(map(int, input().split()))
(x, y, z) = list(map(int, input().split()))
requiredA = 2 * x + y
requiredB = y + 3 * z
ans = 0
if A < requiredA:
	ans += requiredA - A
if B < requiredB:
	ans += requiredB - B
print(ans)


(a, b) = map(int, input().split())
(x, y, z) = map(int, input().split())
a2 = x * 2 + y
b2 = z * 3 + y
print(max(0, a2 - a) + max(0, b2 - b))


def problemA():
	(yellow, blue) = list(map(int, input().strip().split()))
	(x, y, z) = list(map(int, input().strip().split()))
	ny = max(0, 2 * x + y - yellow)
	nb = max(0, 3 * z + y - blue)
	print(nb + ny)
problemA()


def main():
	(k, s) = (list(map(int, input().split(' '))), list(map(int, input().split(' '))))
	t: list = [s[0] * 2 + s[1], s[1] + s[2] * 3]
	r: int = sum(map(lambda x, y: y - x if y - x > 0 else 0, k, t))
	print(r)
	return True
main()


a = list(map(int, input().split()))
b = list(map(int, input().split()))
ye = 2 * b[0] + b[1]
bl = b[1] + 3 * b[2]
if a[0] >= ye:
	yel = 0
else:
	yel = ye - a[0]
if a[1] >= bl:
	blu = 0
else:
	blu = bl - a[1]
print(yel + blu)


(a, b) = [int(s) for s in input().split()]
(x, y, z) = [int(s) for s in input().split()]
needed_yellow = max(2 * x + y - a, 0)
needed_blue = max(y + 3 * z - b, 0)
print(needed_yellow + needed_blue)


ta = tb = 0
(a, b) = map(int, input().split())
(x, y, z) = map(int, input().split())
ta = 2 * x + y
tb = 3 * z + y
p = ta - a
q = tb - b
if p <= 0 and q <= 0:
	print('0')
elif p <= 0 and q > 0:
	print(q)
elif q <= 0 and p > 0:
	print(p)
elif p > 0 and q > 0:
	print(p + q)


def solve():
	(n, m) = list(map(int, input().split()))
	l = list(map(int, input().split()))
	m -= 3 * l[2] + l[1]
	n -= l[1] + 2 * l[0]
	print(abs(min(m, 0)) + abs(min(n, 0)))
solve()


(a, b) = list(map(int, input().split()))
(x, y, z) = list(map(int, input().split()))
Y = x * 2 + y
B = y + z * 3
print(max(Y - a, 0) + max(B - b, 0))


(a, d) = map(int, input().split())
(y, g, b) = map(int, input().split())
m = y * 2 + g
n = b * 3 + g
c = 0
if m > a:
	c += m - a
if n > d:
	c += n - d
print(c)


(yc, bc) = map(int, input().split())
(x, y, z) = map(int, input().split())
(yr, br) = (2 * x + y, y + 3 * z)
yr = yr - yc if yr - yc >= 0 else 0
br = br - bc if br - bc >= 0 else 0
print(yr + br)


(a, b) = map(int, input().split())
(x, y, z) = map(int, input().split())
u = 2 * x + y
v = y + 3 * z
if a < u:
	temp = u - a
else:
	temp = 0
if b < v:
	temp1 = v - b
else:
	temp1 = 0
print(temp + temp1)


import atexit
import io
import sys
import os
from bisect import *
from collections import *
from fractions import gcd
from fractions import Fraction as fr_
from itertools import *
import math
inf = float('inf')
inf_neg = float('-inf')
range_6 = int(10000000.0 + 1)
range_7 = int(1000000.0 + 1)
range_8 = int(100000000.0 + 1)
_INPUT_LINES = sys.stdin.read().splitlines()
input = iter(_INPUT_LINES).__next__
_OUTPUT_BUFFER = io.StringIO()
sys.stdout = _OUTPUT_BUFFER

@atexit.register
def write():
	sys.__stdout__.write(_OUTPUT_BUFFER.getvalue())

def main():
	(A, B) = map(int, input().split())
	(x, y, z) = map(int, input().split())
	yllow = 2 * x + y
	blue = y + 3 * z
	ans = yllow - A
	ans1 = blue - B
	if ans < 0:
		ans = 0
	if ans1 < 0:
		ans1 = 0
	print(ans + ans1)
main()


(yc, bc) = map(int, input().split())
(y, g, b) = map(int, input().split())
y = 2 * y + g - yc
x = 3 * b + g - bc
x = 0 if x < 0 else x
y = 0 if y < 0 else y
print(x + y if x + y >= 0 else 0)


(A, B) = map(int, input().split())
(x, y, z) = map(int, input().split())
ye = x * 2 - A
if ye < 0:
	ye = 0
	A = A - x * 2
else:
	A = 0
bl = z * 3 - B
if bl < 0:
	bl = 0
	B = B - z * 3
else:
	B = 0
gr = y - A
if gr < 0:
	gr = 0
gr2 = y - B
if gr2 < 0:
	gr2 = 0
print(bl + ye + gr + gr2)


(yellow, blue) = list(map(int, input().split()))
(oby, obg, obb) = list(map(int, input().split()))
print(max(0, 2 * oby + obg - yellow) + max(0, 3 * obb + obg - blue))


(A, B) = list(map(int, input().split()))
(y, g, b) = list(map(int, input().split()))
yc = y * 2 + g
bc = g + b * 3
ans = max(0, yc - A) + max(0, bc - B)
print(ans)


inp = input().split(' ')
a = int(inp[0])
b = int(inp[1])
inp = input().split(' ')
x = int(inp[0])
y = int(inp[1])
z = int(inp[2])
foo = 2 * x + y - a
bar = 3 * z + y - b
out = 0
if foo > 0:
	out += foo
if bar > 0:
	out += bar
print(out)


(Y, B) = map(int, input().split())
(a, b, c) = map(int, input().split())
ans = 0
y = 2 * a + b - Y
b1 = b + 3 * c - B
if y > 0:
	ans = ans + y
if b1 > 0:
	ans = ans + b1
print(ans)


(ma, mb) = [int(x) for x in input().split()]
(sa, sb, sc) = [int(x) for x in input().split()]
r = lambda x: x if x >= 0 else 0
print(r(2 * sa + sb - ma) + r(3 * sc + sb - mb))


R = lambda : list(map(int, input().split()))
(A, B) = R()
(x, y, z) = R()
a1 = 2 * x + y
a2 = 3 * z + y
r = 0
if a1 > A:
	r += a1 - A
if a2 > B:
	r += a2 - B
print(r)


def main():
	(a, b) = map(int, input().split())
	(x, y, z) = map(int, input().split())
	required_b = z * 3 + y
	required_a = y + 2 * x
	extra_b = required_b - b
	extra_a = required_a - a
	if extra_b < 0:
		extra_b = 0
	if extra_a < 0:
		extra_a = 0
	print(extra_a + extra_b)
main()


(yellowShards, blueShards) = [int(x) for x in input().split()]
(yBalls, gBalls, bBalls) = [int(x) for x in input().split()]
yellowNeeded = yBalls * 2 + gBalls
blueNeeded = gBalls + 3 * bBalls
ans = 0
if yellowShards < yellowNeeded:
	ans = ans + (yellowNeeded - yellowShards)
if blueShards < blueNeeded:
	ans = ans + (blueNeeded - blueShards)
print(ans)


a = [2, [1, 1], 3]
(y, b) = map(int, input().split())
arr = list(map(int, input().split()))
for (i, ar) in enumerate(arr):
	if i == 1:
		for j in range(2):
			a[i][j] *= ar
	else:
		a[i] *= ar
yc = a[0] + a[1][0]
bc = a[1][1] + a[2]
dy = yc - y
db = bc - b
ans = 0
if dy > 0:
	ans += dy
if db > 0:
	ans += db
print(ans)


import math
(a, b) = map(int, input().split())
(x, y, z) = map(int, input().split())
r = 2 * x + y
t = y + 3 * z
print(max(0, r - a) + max(0, t - b))


(a, b) = map(int, input().split())
(x, y, z) = map(int, input().split())
m = max(x * 2 + y - a, 0)
M = max(0, y + 3 * z - b)
print(m + M)


src = input()
(y, blu) = map(int, src.split())
src = input()
(a, b, c) = map(int, src.split())
res = 0
if 2 * a + b >= y:
	res += 2 * a + b - y
if b + 3 * c >= blu:
	res += b + 3 * c - blu
print(res)


(a, b) = map(int, input().split())
(p, q, r) = map(int, input().split())
t = max(2 * p + q - a, 0)
v = max(3 * r + q - b, 0)
print(t + v)


(a, b) = list(map(int, input().strip().split(' ')))
(a, b) = [int(a), int(b)]
(x, y, z) = list(map(int, input().strip().split(' ')))
(x, y, z) = [int(x), int(y), int(z)]
yellow = 2 * x + y - a
if yellow < 0:
	yellow = 0
blue = 3 * z + y - b
if blue < 0:
	blue = 0
print(yellow + blue)


def main():
	(a, x) = map(int, input().strip().split())
	(y, g, b) = map(int, input().strip().split())
	yl = y * 2 + g * 1
	bl = g * 1 + b * 3
	tot1 = 0
	tot2 = 0
	if yl > a:
		tot1 = yl - a
	if bl > x:
		tot2 = bl - x
	print(tot1 + tot2)
main()


(y, b) = map(int, input().split())
(yc, gc, bc) = map(int, input().split())
p = yc * 2 + gc * 1
l = gc * 1 + bc * 3
if p > y and l > b:
	print(p - y + (l - b))
elif p > y:
	print(p - y)
elif l > b:
	print(l - b)
else:
	print(0)


def validator(chunk: int, i: int, j: int) -> int:
	pass
(yellow_crys, blue_crys) = list(map(int, input().split()))
(yellow, green, blue) = list(map(int, input().split()))
yello_summ = max(yellow * 2 + green - yellow_crys, 0)
blue_summ = max(blue * 3 + green - blue_crys, 0)
ans = yello_summ + blue_summ
print(ans)


(n, m) = map(int, input().split())
a = list(map(int, input().split()))
yellow = a[0] * 2 + a[1] * 1
blue = a[1] * 1 + a[2] * 3
y = yellow - n
b = blue - m
c = 0
if y >= 0:
	c = c + y
if b >= 0:
	c = c + b
print(c)


(A, B) = map(int, input().split())
(x, y, z) = map(int, input().split())
ans = 0
yellow_crystal = 2 * x + y - A
blue_crystal = y + 3 * z - B
if yellow_crystal > 0:
	ans += yellow_crystal
if blue_crystal > 0:
	ans += blue_crystal
print(ans)


from sys import stdin
[A, B] = list(map(int, stdin.readline().strip().split()))
[x, y, z] = list(map(int, stdin.readline().strip().split()))
YellowCrystals = 2 * x + y - A
BlueCrystals = 3 * z + y - B
sol = max(0, YellowCrystals) + max(0, BlueCrystals)
print(sol)


(y, b) = map(int, input().split())
(p, q, r) = map(int, input().split())
reqy = 2 * p + q
reqb = 3 * r + q
res = 0
if reqy > y:
	res += reqy - y
if reqb > b:
	res += reqb - b
print(res)


(A, B) = map(int, input().split())
(x, y, z) = map(int, input().split())
c1 = 2 * x + y
c2 = y + 3 * z
print(max(0, c1 - A) + max(0, c2 - B))


s1 = input().split()
s2 = input().split()
a = int(s1[0])
b = int(s1[1])
x = int(s2[0])
y = int(s2[1])
z = int(s2[2])
c1 = x * 2 + y
c2 = z * 3 + y
res = 0
if a - c1 < 0:
	res += c1 - a
if b - c2 < 0:
	res += c2 - b
print(res)


(a, b) = map(int, input().strip().split(' '))
(x, y, z) = map(int, input().strip().split(' '))
bl = 3 * z + y
yl = 2 * x + y
s1 = bl - b
if s1 < 0:
	s1 = 0
s2 = yl - a
if s2 < 0:
	s2 = 0
s = s1 + s2
print(s)


(n, k) = map(int, input().split())
(x, y, z) = map(int, input().split())
Y = 2 * x + y
G = 0
B = 3 * z + y
ans = 0
if Y > n:
	ans += Y - n
if B > k:
	ans += B - k
print(ans)


(a, b) = map(int, input().split())
(x, y, z) = map(int, input().split())
count = 0
r1 = x * 2 + y
r2 = z * 3 + y
if a < r1:
	count += r1 - a
if b < r2:
	count += r2 - b
print(count)


def no_of_crystals(nyc, nbc, nyb, ngb, nbb):
	blue_needed = 3 * nbb + ngb
	yellow_needed = 2 * nyb + ngb
	total = 0
	if blue_needed - nbc > 0:
		total += blue_needed - nbc
	if yellow_needed - nyc > 0:
		total += yellow_needed - nyc
	return total
(nyc, nbc) = input().split()
(nyb, ngb, nbb) = input().split()
count = no_of_crystals(int(nyc), int(nbc), int(nyb), int(ngb), int(nbb))
if count > 0:
	print(count)
else:
	print(0)


(n, m) = map(int, input().split())
(a, b, c) = map(int, input().split())
n = n - 2 * a - b
m = m - b - 3 * c
w = 0
if n < 0:
	w += abs(n)
if m < 0:
	w += abs(m)
print(w)


(A, B) = [int(i) for i in input().split()]
(x, y, z) = [int(i) for i in input().split()]
needY = 2 * x + y
needB = 3 * z + y
ans = 0
if needY > A:
	ans += needY - A
if needB > B:
	ans += needB - B
print(ans)


(A, B) = map(int, input().split())
(x, y, z) = map(int, input().split())
Ap = 2 * x + y
Bp = y + 3 * z
print(max(Ap - A, 0) + max(Bp - B, 0))


(a, b) = map(int, input().split())
(x, y, z) = map(int, input().split())
l = x * 2 + y
r = z * 3 + y
print(max(0, l - a) + max(0, r - b))


(m, n) = map(int, input().split())
(y, g, b) = map(int, input().split())
c = n - b * 3 - g
if c > 0:
	c = 0
d = m - y * 2 - g
if d > 0:
	d = 0
c += d
if c > 0:
	c = 0
else:
	c *= -1
print(c)


def read():
	return map(int, input().split())
(a, b) = read()
(x, y, z) = read()
num_a = max(x * 2 + y - a, 0)
num_b = max(y + z * 3 - b, 0)
print(num_a + num_b)


def read_word(f):
	return f.strip()

def read_int(f, b=10):
	return int(read_word(f), b)

def read_letters(f):
	return list(read_word(f))

def read_digits(f, b=10):
	return [int(x, b) for x in read_letters(f)]

def read_words(f, d=' '):
	return read_word(f).split(d)

def read_ints(f, b=10, d=' '):
	return [int(x, b) for x in read_words(f, d)]

def read_floats(f, d=' '):
	return [float(x) for x in read_words(f, d)]

def read_arr(f, R, reader=read_ints, *args, **kwargs):
	return [reader(f, *args, **kwargs) for i in range(R)]

def read_case(f):
	R = read_ints(f)
	return R

def begin():
	T = 1
	for i in range(T):
		res = solver()

def solver():
	(y, b) = read_ints(input())
	(Y, G, B) = read_ints(input())
	yMore = -(y - 2 * Y - G)
	bMore = -(b - G - 3 * B)
	if yMore < 0:
		yMore = 0
	if bMore < 0:
		bMore = 0
	print(yMore + bMore)
begin()


(a, b) = map(int, input().split())
(x, y, z) = map(int, input().split())
rb = 0
ry = 0
if y + 3 * z > b:
	rb = y + 3 * z - b
if 2 * x + y > a:
	ry = 2 * x + y - a
print(rb + ry)


(y, b) = map(int, input().split())
(ny, ng, nb) = map(int, input().split())
(ty, tb) = (0, 0)
ty += ny * 2 + ng
tb += ng + 3 * nb
(a1, a2) = (0, 0)
if ty >= y:
	a1 = ty - y
if tb >= b:
	a2 = tb - b
print(a1 + a2)


def tricky(l1, l2):
	(a, b) = (l1[0], l1[1])
	(x, y, z) = (l2[0], l2[1], l2[2])
	cy = 2 * x + y
	cb = 3 * z + y
	res = 0
	if cy > a:
		res += cy - a
	if cb > b:
		res += cb - b
	if res < 0:
		return 0
	return res
m = list(map(int, input().split()))
n = list(map(int, input().split()))
print(tricky(m, n))


(a, b) = map(int, input().split())
(x, y, z) = map(int, input().split())
yellow = 2 * x + y
blue = 3 * z + y
(d1, d2) = (0, 0)
if yellow > a:
	d1 = yellow - a
if blue > b:
	d2 = blue - b
print(d1 + d2)


inp = []
for x in input().split():
	inp.append(int(x))
for y in input().split():
	inp.append(int(y))
(yc, bc, yb, gb, bb) = inp
yc = yc - 2 * yb - gb
bc = bc - 3 * bb - gb
r = 0
if yc < 0:
	r = r - yc
if bc < 0:
	r = r - bc
print(r)


def cal(a):
	if a > 0:
		return 0
	return -a
(a, b) = map(int, input().split())
(x, y, z) = map(int, input().split())
a -= 2 * x
a -= y
b -= y
b -= 3 * z
ans = cal(a) + cal(b)
print(ans)


(A, B) = map(int, input().split())
(x, y, z) = map(int, input().split())
d1 = max(0, 2 * x + y - A)
d2 = max(0, y + 3 * z - B)
print(d1 + d2)


(a, b) = input().split(' ')
(x, y, z) = input().split(' ')
yellow = int(x) * 2
blue = int(y) * 1
yellow += int(y) * 1
blue += int(z) * 3
res = 0
res1 = 0
if int(a) < yellow:
	res = abs(int(a) - yellow)
if int(b) < blue:
	res1 = abs(int(b) - blue)
print(res + res1)


getInputList = lambda : list(input().split())
getInputIntList = lambda : list(map(int, input().split()))
(x, y) = getInputIntList()
(a, b, c) = getInputIntList()
ans = 2 * a + 2 * b + 3 * c
x1 = 2 * a + b
y1 = 3 * c + b
ans = max(x1 - x, 0) + max(y1 - y, 0)
print(ans)


(a, b) = input().split(' ')
(x, y, z) = input().split(' ')
(a, b, x, y, z) = (int(a), int(b), int(x), int(y), int(z))
x_e = x * 2
y_e = y * 1
y_ee = y * 1
z_e = z * 3
if a >= x_e + y_e:
	summ = 0
else:
	summ = x_e + y_e - a
if b > z_e + y_ee:
	pass
else:
	summ += z_e + y_ee - b
print(summ)


(a, b) = map(int, input().split())
(x, y, z) = map(int, input().split())
a1 = x * 2 + y
b1 = y + 3 * z
x = 0
if a - a1 < 0:
	x += a1 - a
if b - b1 < 0:
	x += b1 - b
print(x)


(y, b) = input().split(' ')
(ay, ag, ab) = input().split(' ')
y = int(y)
b = int(b)
ay = int(ay)
ag = int(ag)
ab = int(ab)
b = b - ab * 3
y = y - ay * 2
b = b - ag
y = y - ag
br = 0
if y < 0:
	br = br - y
if b < 0:
	br = br - b
print(br)


(yellow, blu) = list(map(int, input().split()))
(x, y, z) = list(map(int, input().split()))
blue_needed = z * 3 + y
yellow_needed = x * 2 + y
a = blue_needed - blu
c = yellow_needed - yellow
if a < 0:
	a = 0
if c < 0:
	c = 0
print(a + c)


(yellowC, blueC) = map(int, input().split())
(yellowB, greenB, blueB) = map(int, input().split())
yellowC -= 2 * yellowB + greenB
blueC -= greenB + 3 * blueB
requiredC = 0
if yellowC < 0:
	requiredC += yellowC * -1
if blueC < 0:
	requiredC += blueC * -1
print(requiredC)


(a, b) = map(int, input().split())
(x, y, z) = map(int, input().split())
needa = 2 * x + y
needb = y + 3 * z
print(max(0, needa - a) + max(0, needb - b))


(h, b) = map(int, input().split())
(x, y, z) = map(int, input().split())
print(max(0, 2 * x + y - h) + max(0, 3 * z + y - b))


(yellow, blue) = map(int, input().split())
(y, g, b) = map(int, input().split())
count = 0
yt = y * 2 + g
bt = g + b * 3
yc = yellow - yt
if yc < 0:
	count += abs(yc)
bc = blue - bt
if bc < 0:
	count += abs(bc)
print(count)


(a, b) = [int(i) for i in input().split()]
(x, y, z) = [int(i) for i in input().split()]
k = 0
yel = x * 2 + y
blue = z * 3 + y
if b < blue:
	k += blue - b
if a < yel:
	k += yel - a
print(k)


(a, b) = map(int, input().split())
(x, y, z) = map(int, input().split())
sy = 2 * x + y
sb = y + 3 * z
s = 0
if sy > a:
	s = sy - a
if sb > b:
	s = s + (sb - b)
print(s)


(a, b) = list(map(int, input().split()))
(x, y, z) = list(map(int, input().split()))
cntYellow = 2 * x + y
cntBlue = y + 3 * z
if cntYellow <= a:
	cntYellow = 0
else:
	cntYellow = cntYellow - a
if cntBlue <= b:
	cntBlue = 0
else:
	cntBlue = cntBlue - b
print(cntYellow + cntBlue)


(yellow_crystals, blue_crystals) = map(int, input().split())
(yellow, green, blue) = map(int, input().split())
total_yellow = yellow * 2 + green * 1
total_blue = blue * 3 + green * 1
req_crystals = 0
if yellow_crystals < total_yellow:
	req_crystals += total_yellow - yellow_crystals
if blue_crystals < total_blue:
	req_crystals += total_blue - blue_crystals
print(req_crystals)


(yelcr, blucr) = map(int, input().split())
(yb, gb, bb) = map(int, input().split())
yelreq = yb * 2 + gb
blureq = bb * 3 + gb
req = 0
if yelcr < yelreq:
	req += yelreq - yelcr
if blureq > blucr:
	req += blureq - blucr
print(req)


(n, m) = map(int, input().split())
mat = list(map(int, input().split()))
print(abs(min(0, n - mat[0] * 2 - mat[1]) + min(0, m - mat[1] - mat[2] * 3)))


(a1, b1) = map(int, input().split())
(y, g, b) = map(int, input().split())
a2 = 2 * y + g
b2 = 3 * b + g
if a1 >= a2:
	a1 = 0
	a2 = 0
if b1 >= b2:
	b1 = 0
	b2 = 0
print(a2 - a1 + b2 - b1)


(yellow, blue) = input().split(' ')
(x, y, z) = input().split(' ')
yellow = int(yellow)
blue = int(blue)
x = int(x)
y = int(y)
z = int(z)
needed_yellow = x * 2 + y
needed_blue = z * 3 + y
result1 = needed_yellow - yellow
result2 = needed_blue - blue
if result1 < 0:
	result1 = 0
if result2 < 0:
	result2 = 0
print(result1 + result2)


(j, k) = map(int, input().split())
(y, g, b) = map(int, input().split())
l = 0
m = 0
if j >= 2 * y:
	l = max(0, g - (j - 2 * y))
else:
	l = g + (2 * y - j)
if k >= 3 * b:
	m = max(0, g - (k - 3 * b))
else:
	m = g + (3 * b - k)
print(l + m)


l = list(input().split(' '))
v = list(input().split(' '))
y = int(v[0]) * 2 + int(v[1])
b = int(v[1]) + int(v[2]) * 3
e = y - int(l[0])
f = b - int(l[1])
if e < 0:
	e = 0
if f < 0:
	f = 0
a = e + f
print(a)


(a, b) = map(int, input().split())
(x, y, z) = map(int, input().split())
(yellow, blue) = (0, 0)
yellow += x * 2
yellow += y
blue += y
blue += 3 * z
y_need = max(0, yellow - a)
b_need = max(0, blue - b)
print(y_need + b_need)


import sys
import bisect as b
import math
from collections import defaultdict as dd
input = sys.stdin.readline
mo = 10 ** 9 + 7

def cin():
	return map(int, sin().split())

def ain():
	return list(map(int, sin().split()))

def sin():
	return input()

def inin():
	return int(input())

def pref(a, n, f):
	pre = [0] * n
	if f == 0:
		pre[0] = a[0]
		for i in range(1, n):
			pre[i] = a[i] + pre[i - 1]
	else:
		pre[-1] = a[-1]
		for i in range(n - 2, -1, -1):
			pre[i] = pre[i + 1] + a[i]
	return pre
maxint = 10 ** 24

def kadane(a, size):
	max_so_far = -maxint - 1
	max_ending_here = 0
	for i in range(0, size):
		max_ending_here = max_ending_here + a[i]
		if max_so_far < max_ending_here:
			max_so_far = max_ending_here
		if max_ending_here < 0:
			max_ending_here = 0
	return max_so_far
for _ in range(1):
	(a, b) = cin()
	(x, y, z) = cin()
	reqa = 2 * x + y
	reqb = y + 3 * z
	print(max(reqa - a, 0) + max(reqb - b, 0))


(Yellow, Blue) = map(int, input().split())
X = list(map(int, input().split()))
NeedY = X[0] * 2 + X[1]
NeedB = X[2] * 3 + X[1]
Yellow = 0 if Yellow >= NeedY else abs(Yellow - NeedY)
Blue = 0 if Blue > NeedB else abs(Blue - NeedB)
print(Blue + Yellow)


(a, b) = map(int, input().split())
(c, d, e) = map(int, input().split())
s = 0
if a > c:
	a = a - 2 * c
else:
	s = s + 2 * c - a
	a = 0
if b > e:
	b = b - 3 * e
else:
	s = s + 3 * e - b
	b = 0
if a < d:
	s = s + d - a
if b < d:
	s = s + d - b
print(s)


from sys import stdin, stdout
(y, bl) = map(int, stdin.readline().split())
(a, b, c) = map(int, stdin.readline().split())
yr = a * 2 + b
br = b * 1 + c * 3
c = 0
if yr >= y:
	c += yr - y
if br > bl:
	c += br - bl
stdout.write(str(c))


(a, b) = [int(i) for i in input().split()]
(x, y, z) = [int(i) for i in input().split()]
na = 2 * x + y
nb = y + 3 * z
print((na - a if na > a else 0) + (nb - b if nb > b else 0))


(a, b) = map(int, input().strip().split(' '))
(x, y, z) = map(int, input().strip().split(' '))
aq = 2 * x + y
bq = 3 * z + y
s = 0
if aq > a:
	s += aq - a
if bq > b:
	s += bq - b
print(s)


crys = input().split()
crys_yellow = int(crys[0])
crys_blue = int(crys[1])
ball = input().split()
ball_yellow = int(ball[0])
ball_green = int(ball[1])
ball_blue = int(ball[2])
need = 0
need_yellow = ball_yellow * 2 + ball_green
need_blue = ball_blue * 3 + ball_green
if need_yellow >= crys_yellow and need_blue >= crys_blue:
	need = need_yellow - crys_yellow + (need_blue - crys_blue)
elif need_yellow >= crys_yellow and need_blue < crys_blue:
	need = need_yellow - crys_yellow
elif need_yellow < crys_yellow and need_blue >= crys_blue:
	need = need_blue - crys_blue
print(need)


(Yc, Bc) = map(int, input().split())
(yB, gB, bB) = map(int, input().split())
print(max(yB * 2 + gB - Yc, 0) + max(gB + bB * 3 - Bc, 0))


a = input().split()
b = input().split()
a = [int(a[i]) for i in range(2)]
b = [int(b[i]) for i in range(3)]
a[0] = a[0] - b[0] * 2 - b[1]
a[1] = a[1] - b[1] - b[2] * 3
s = 0
for i in range(2):
	if a[i] < 0:
		s += abs(a[i])
print(s)


(a, b) = map(int, input().split())
(a1, a2, a3) = map(int, input().split())
ans1 = a1 * 2 + a2
ans2 = a2 + 3 * a3
print(max(ans1 - a, 0) + max(ans2 - b, 0))


(x, y) = [int(i) for i in input().split()]
(a, b, c) = [int(i) for i in input().split()]
k = a * 2 + b
l = c * 3 + b
k -= x
if k < 0:
	k = 0
l -= y
if l < 0:
	l = 0
print(l + k)


ln1 = input().split()
ln2 = input().split()
numY = int(ln1[0])
numB = int(ln1[1])
wantY = int(ln2[0])
wantG = int(ln2[1])
wantB = int(ln2[2])
x = 2 * wantY + wantG - numY
y = 3 * wantB + wantG - numB
print(max(x, 0) + max(y, 0))


(a, b) = map(int, input().split())
(y, g, bl) = map(int, input().split())
a = a - 2 * y
b = b - 3 * bl
ans = 0
if g >= a and g >= b:
	ans = g - a + g - b
elif g >= a and b >= g:
	ans = g - a
elif g <= a and b <= g:
	ans = g - b
print(ans)


s = input()
n = input()
(y, b) = s.split()
y = int(y)
b = int(b)
(yellow, green, blue) = n.split()
yellow = int(yellow)
green = int(green)
blue = int(blue)
yel = 0
bl = 0
yel += yellow * 2
yel += green
bl += green
bl += blue * 3
result = 0
if y > yel:
	result = bl - b
elif b > bl:
	result = yel - y
else:
	result = yel + bl - (y + b)
if result < 0:
	result = 0
print(result)


(A, B) = map(int, input().split())
(x, y, z) = map(int, input().split())
r = 0
t = 0
SA = 2 * x + y
SB = 3 * z + y
if SA - A > 0:
	r = SA - A
if SB - B > 0:
	t = SB - B
print(r + t)


(a, b) = map(int, input().split())
balls = list(map(int, input().split()))
a -= 2 * balls[0]
a -= balls[1]
b -= balls[1]
b -= 3 * balls[2]
if a < 0 or b < 0:
	if a < 0 and b < 0:
		print(abs(a + b))
	elif a < 0:
		print(abs(a))
	elif b < 0:
		print(abs(b))
else:
	print(0)


(a, b) = list(map(int, input().split()))
(x, y, z) = list(map(int, input().split()))
total_blue = 3 * z + y
total_yellow = 2 * x + y
ans = 0
if b < total_blue:
	ans += total_blue - b
if a < total_yellow:
	ans += total_yellow - a
print(ans)


def alchemy(a, b, lst):
	(y, z, s) = (lst[0] * 2 + lst[1], lst[2] * 3 + lst[1], 0)
	if a < y:
		s += y - a
	if b < z:
		s += z - b
	if s <= 0:
		return 0
	return s
(A, B) = [int(i) for i in input().split()]
colours = [int(j) for j in input().split()]
print(alchemy(A, B, colours))


(a, b) = map(int, input().split(' '))
(x, y, z) = map(int, input().split(' '))
dy = 2 * x + y - a
db = y + 3 * z - b
if dy < 0:
	dy = 0
if db < 0:
	db = 0
print(dy + db)


(A, B) = input().split()
(x, y, z) = input().split()
print(max(0, int(x) * 2 + int(y) * 1 - int(A)) + max(0, int(y) * 1 + int(z) * 3 - int(B)))


(a, b) = [int(s) for s in input().split(' ')]
(x, y, z) = [int(s) for s in input().split(' ')]
ans = max(2 * x + y - a, 0) + max(3 * z + y - b, 0)
print(ans)


(a, b) = map(int, input().split())
(x, y, z) = map(int, input().split())
p = 2 * x + 1 * y
q = 1 * y + 3 * z
m = 0
if p >= a:
	m += p - a
if q >= b:
	m += q - b
print(m)


(a, b) = map(int, input().split())
(x, y, z) = map(int, input().split())
na = x * 2 + y
nb = z * 3 + y
z = lambda l: l if l >= 0 else 0
t = z(na - a) + z(nb - b)
print(t if t > 0 else 0)


(a, b) = map(int, input().split())
(x, y, z) = map(int, input().split())
need_a = x * 2 + y
need_b = y + 3 * z
required = max(need_a - a, 0) + max(need_b - b, 0)
print(required)


(A, B) = list(map(lambda k: int(k), input().split()))
(x, y, z) = list(map(lambda k: int(k), input().split()))

def solve1(A, B, x, y, z):
	blue_crystal_required = max(2 * x + 1 * y - A, 0)
	yellow_crystal_required = max(y * 1 + z * 3 - B, 0)
	total = blue_crystal_required + yellow_crystal_required
	if total > 0:
		return total
	return 0
print(solve1(A, B, x, y, z))


(A, B) = input().split()
(A, B) = (int(A), int(B))
(x, y, z) = input().split()
(x, y, z) = (int(x), int(y), int(z))
totA = 2 * x + y
totB = y + 3 * z
chksum = totA + totB
if A >= totA and B >= totB:
	print('0')
elif A < totA and B > totB:
	print(totA - A)
elif A > totA and B < totB:
	print(totB - B)
elif A < totA and B < totB:
	print(chksum - (A + B))
else:
	print(chksum - (A + B))


(A, B) = list(map(int, input().split()))
(x, y, z) = list(map(int, input().split()))
countA = 2 * x + y
countB = y + 3 * z
needA = countA - A
needB = countB - B
total = 0
if needA > 0:
	total += needA
if needB > 0:
	total += needB
print(total)


(a, b) = list(map(int, input().split()))
(x, y, z) = list(map(int, input().split()))
yy = x * 2
yy = yy + y
bb = y
bb = bb + 3 * z
yellow_require = a - yy
blue_require = b - bb
if yellow_require < 0:
	yellow_require = abs(yellow_require)
else:
	yellow_require = 0
if blue_require < 0:
	blue_require = abs(blue_require)
else:
	blue_require = 0
print(yellow_require + blue_require)


(cy, cb) = map(int, input().split())
(y, g, b) = map(int, input().split())
resy = y * 2 + g * 1
resb = g + b * 3
reqy = resy - cy
reqb = resb - cb
sum = 0
if reqy > 0:
	sum += reqy
if reqb > 0:
	sum += reqb
print(sum)


(a, b) = map(int, input().split())
(q, w, e) = map(int, input().split())
print(max(0, 2 * q + w - a) + max(0, w + 3 * e - b))


(a, b) = map(int, input().strip().split())
(x, y, z) = map(int, input().strip().split())
yellow = 2 * x + y
blue = 3 * z + y
p = yellow - a
q = blue - b
if p <= 0 and q <= 0:
	print(0)
elif p > 0 and q > 0:
	print(p + q)
else:
	print(max(p, q))


(A, B) = [int(x) for x in input().split()]
(x, y, z) = [int(x) for x in input().split()]
yellow = x * 2 + y
blue = y + z * 3
if A >= yellow:
	ans1 = 0
else:
	ans1 = yellow - A
if B >= blue:
	ans2 = 0
else:
	ans2 = blue - B
print(ans1 + ans2)


(ye, bl) = tuple(map(int, input().split()))
(x, y, z) = tuple(map(int, input().split()))
yC = x * 2 + y
bC = y + z * 3
result = 0
if yC > ye:
	result += yC - ye
if bC > bl:
	result += bC - bl
print(result)


from array import *
n = input().split()
x = input().split()
y = int(n[0]) - int(x[0]) * 2
y = int(y)
y -= int(x[1])
m = int(n[1]) - int(x[1])
m = int(m)
m -= int(x[2]) * 3
if m < 0 and y >= 0:
	print(abs(m))
elif y < 0 and m >= 0:
	print(abs(y))
elif m < 0 and y < 0:
	print(abs(m + y))
else:
	print(0)


(a, b) = map(int, input().split())
(x, y, z) = map(int, input().split())
reqy = x * 2 + y
reqb = y + 3 * z
reqy -= a
reqb -= b
if reqy < 0:
	reqy = 0
if reqb < 0:
	reqb = 0
print(reqy + reqb)


(a, b) = [int(x) for x in input().split()]
(x, y, z) = [int(i) for i in input().split()]
yellow = 0
blue = 0
yellow = 2 * x + 1 * y
blue = 1 * y + 3 * z
res = 0
if a < yellow:
	res = res + abs(a - yellow)
if b < blue:
	res = res + abs(b - blue)
print(res)


[A, B] = map(int, input().split())
[x, y, z] = map(int, input().split())
yellow = x * 2 + y
blue = y + 3 * z
if yellow >= A:
	ya = yellow - A
else:
	ya = 0
if blue >= B:
	bl = blue - B
else:
	bl = 0
print(ya + bl)


(yc, bc) = map(int, input().split())
(yb, gb, bb) = map(int, input().split())
ycn = 2 * yb + gb
bcn = gb + 3 * bb
score = 0
if ycn > yc:
	score += ycn - yc
if bcn > bc:
	score += bcn - bc
print(score)


def main():
	(a, b) = map(int, input().split(' '))
	(x, y, z) = map(int, input().split(' '))
	yellow = x * 2 + y * 1
	blue = y * 1 + z * 3
	t = a - yellow
	y = b - blue
	if t < 0:
		t = -t
	else:
		t = 0
	if y < 0:
		y = -y
	else:
		y = 0
	print(t + y)
main()


(y, b) = map(int, input().split())
(y1, g1, b1) = map(int, input().split())
y2 = y - 2 * y1
b2 = b - 3 * b1
t = y2 - g1
z = b2 - g1
if t >= 0 and z >= 0:
	print('0')
elif z >= 0 and t <= 0:
	print(abs(t))
elif z <= 0 and t >= 0:
	print(abs(z))
elif z <= 0 and t <= 0:
	print(abs(z + t))


(a, b) = map(int, input().split())
(x, y, z) = map(int, input().split())
a -= 2 * x + y
b -= 3 * z + y
l = [a, b]
z = 0
for i in l:
	if i < 0:
		z += i
print(abs(z))


(A, B) = list(map(int, input().split()))
(x, y, z) = list(map(int, input().split()))
a = x * 2
b = z * 3
if A - y - a >= 0:
	if B - y - b >= 0:
		print(0)
	else:
		print(y + b - B)
elif B - y - b >= 0:
	print(y + a - A)
else:
	print(y + y + a + b - B - A)


(n, k) = map(int, input().split())
(a, b, c) = map(int, input().split())
res = 0
y = 2 * a + b - n
b = 3 * c + b - k
if y > 0:
	res += y
if b > 0:
	res += b
print(res)


(a, b) = map(int, input().split())
c = list(map(int, input().split()))
d = c[0] * 2 + c[1] - a
e = c[1] + 3 * c[2] - b
if d < 0:
	d = 0
if e < 0:
	e = 0
print(d + e)


(n, m) = map(int, input().split())
(a, b, c) = map(int, input().split())
yellow = 0
yellow += a * 2 + b
blue = 0
blue = b + c * 3
if n < yellow and blue > m:
	print(yellow + blue - m - n)
elif n >= yellow and blue > m:
	print(blue - m)
elif n < yellow and blue <= m:
	print(yellow - n)
else:
	print(0)


(A, B) = map(int, input().split())
(x, y, z) = map(int, input().split())
yellow_needed = 2 * x + y
blue_needed = 3 * z + y
extra_yellow = max(0, yellow_needed - A)
extra_blue = max(0, blue_needed - B)
print(extra_yellow + extra_blue)


a = [int(i) for i in input().split()]
Z = [int(i) for i in input().split()]
A = a[0]
B = a[1]
x = Z[0]
y = Z[1]
z = Z[2]
yellow_crystals = 2 * x + y
blue_crystals = y + 3 * z
additional_yellow_crystals = yellow_crystals - A
additional_blue_crystals = blue_crystals - B
if additional_yellow_crystals >= 0 and additional_blue_crystals >= 0:
	ans = additional_yellow_crystals + additional_blue_crystals
if additional_yellow_crystals >= 0 and additional_blue_crystals < 0:
	ans = additional_yellow_crystals
if additional_yellow_crystals < 0 and additional_blue_crystals >= 0:
	ans = additional_blue_crystals
if additional_yellow_crystals < 0 and additional_blue_crystals < 0:
	ans = 0
print(ans)


(n, k) = map(int, input().split())
(x, y, z) = map(int, input().split())
(a, b) = (0, 0)
a += x * 2
a += y
b += y
b += z * 3
print(max(a - n, 0) + max(b - k, 0))


(A, B) = [int(i) for i in input().split()]
(y, g, b) = [int(i) for i in input().split()]
ansY = y * 2 + g - A
ansB = g + b * 3 - B
print(max(0, ansY) + max(0, ansB))


R = lambda : map(int, input().split())
(a, b) = R()
(x, y, z) = R()
a -= x * 2
a -= y
b -= y
b -= z * 3
if a >= 0 and b >= 0:
	exit(print(0))
if a >= 0 and b < 0:
	exit(print(abs(b)))
if a < 0 and b >= 0:
	exit(print(abs(a)))
if a < 0 and b < 0:
	exit(print(abs(a + b)))
print(0)


(gy, gb) = map(int, input().split())
(y, g, b) = map(int, input().split())
ry = 2 * y + g
rb = 3 * b + g
yellow_required = 0 if gy > ry else ry - gy
blue_required = 0 if gb > rb else rb - gb
print(yellow_required + blue_required)


__ready_for_submit__ = True
import sys, os
file_name = os.path.basename(__file__).split('.')[0]
if __ready_for_submit__:
	infile = sys.stdin
	outfile = sys.stdout
else:
	infile = open(file_name + '.in', 'r')
	outfile = open(file_name + '.out', 'w')
(A, B) = [int(x) for x in infile.readline().split()]
(x, y, z) = [int(x) for x in infile.readline().split()]
TA = 2 * x + y
TB = y + 3 * z
ans = max(0, TA - A) + max(0, TB - B)
outfile.write('%d\n' % ans)
infile.close()
outfile.close()


import sys
(Y, B) = map(int, input().split())
(y, g, b) = map(int, input().split())
ansY = 2 * y
ansB = 3 * b
ansY += g
ansB += g
ans = 0
if ansY - Y > 0:
	ans += ansY - Y
if ansB - B > 0:
	ans += ansB - B
print(ans)


(n, m) = map(int, input().split())
(a, b, c) = map(int, input().split())
l = 0
if a * 2 > n:
	l += 2 * a - n
	n = 0
else:
	n -= a * 2
if c * 3 > m:
	l += 3 * c - m
	m = 0
else:
	m -= 3 * c
if b > n:
	l += b - n
if b > m:
	l += b - m
print(l)


(y, b) = map(int, input().split())
(x, ye, z) = map(int, input().split())
y1 = x * 2 + ye
b1 = ye + z * 3
ans = 0
if y1 > y:
	ans += y1 - y
if b1 > b:
	ans += b1 - b
print(ans)


a = list(map(int, input().split()))
x = list(map(int, input().split()))
y1 = a[0]
b1 = a[1]
y2 = 2 * x[0] + x[1]
b2 = x[1] + 3 * x[2]
sum = 0
if y2 > y1:
	sum += y2 - y1
if b2 > b1:
	sum += b2 - b1
print(sum)


(A, B) = [int(x) for x in input().split()]
(x, y, z) = [int(x) for x in input().split()]
total = 0
if 2 * x + y > A:
	total += abs(2 * x + y - A)
if 3 * z + y > B:
	total += abs(3 * z + y - B)
print(total)


(a, b) = map(int, input().split())
(y, g, bl) = map(int, input().split())
req_a = y * 2 + g
req_b = g + 3 * bl
print(max(0, req_a - a) + max(0, req_b - b))


(a, b) = map(int, input().split())
li = list(map(int, input().split()))
count = 0
if li[0] * 2 > a:
	count += li[0] * 2 - a
	a = 0
elif li[0] * 2 <= a:
	a -= li[0] * 2
if li[2] * 3 > b:
	count += li[2] * 3 - b
	b = 0
elif li[2] * 3 <= b:
	b -= li[2] * 3
if li[1] - a > 0 and li[1] - b > 0:
	count += li[1] - a + li[1] - b
elif li[1] - a <= 0 and li[1] - b > 0:
	count += li[1] - b
elif li[1] - a > 0 and li[1] - b <= 0:
	count += li[1] - a
print(count)


def read():
	return (int(x) for x in input().split())
(a, b) = read()
(x, y, z) = read()
aa = x * 2 + y
bb = y + z * 3
s = 0
if aa > a:
	s += aa - a
if bb > b:
	s += bb - b
print(s)


(y, b) = input().split()
(y, b) = (int(y), int(b))
(sy, sg, sb) = input().split()
(sy, sg, sb) = (int(sy), int(sg), int(sb))
y -= sy * 2
b -= sb * 3
y -= sg
b -= sg
y = -min(y, 0)
b = -min(b, 0)
print(y + b)


def main():
	(a, b) = map(int, input().split())
	(x, y, z) = map(int, input().split())
	result = 0
	a -= x * 2 + y
	b -= y + z * 3
	if a < 0:
		result -= a
	if b < 0:
		result -= b
	print(result)
main()


def list_output(s):
	print(' '.join(map(str, s)))

def list_input(s='int'):
	if s == 'int':
		return list(map(int, input().split()))
	elif s == 'float':
		return list(map(float, input().split()))
	return list(map(str, input().split()))
(A, B) = map(int, input().split())
(x, y, z) = map(int, input().split())
res = 0
A_need = max(0, y - A)
B_need = max(0, y - B)
res += A_need + B_need
A += A_need
B += B_need
A -= y
B -= y
A_need = max(0, 2 * x - A)
B_need = max(0, 3 * z - B)
res += A_need + B_need
print(res)


(a, b) = input().split()
(a, b) = (int(a), int(b))
(x, y, z) = input().split()
(x, y, z) = (int(x), int(y), int(z))
v = 0
oy = a - 2 * x
og = b - 3 * z
if oy > 0:
	if og > 0:
		q = oy - y
		p = og - y
		if q < 0:
			if p < 0:
				v = abs(q) + abs(p)
			else:
				v = abs(q)
		elif p < 0:
			v = abs(q) + abs(p)
		else:
			v = 0
	else:
		q = oy - y
		if q < 0:
			v = abs(q) + abs(og) + y
		else:
			v = abs(og) + y
elif og > 0:
	p = og - y
	if p < 0:
		v = abs(p) + abs(oy) + y
	else:
		v = abs(oy) + y
else:
	v = abs(oy) + abs(og) + 2 * y
print(v)


(yc, bc) = map(int, input().split())
(y, g, b) = map(int, input().split())
p = y * 2 + g - yc
q = b * 3 + g - bc
print((p if p > 0 else 0) + (q if q > 0 else 0))


(a, b) = map(int, input().split())
x = [int(x) for x in input().split()]
y = 2 * x[0] + x[1] - a
if y < 0:
	y = 0
bl = x[1] + 3 * x[2] - b
if bl < 0:
	bl = 0
print(y + bl)


(y, b) = map(int, input().split())
(yy, g, bl) = map(int, input().split())
ny = yy * 2 + g
nb = bl * 3 + g
ans = 0
if ny - y >= 0:
	ans += ny - y
if nb - b >= 0:
	ans += nb - b
if ans >= 0:
	print(ans)
else:
	print(0)


a = []
s = input()
t = ''
for i in range(len(s)):
	t += s[i]
	if s[i] == ' ':
		a.append(int(t))
		t = ''
a.append(int(t))
s1 = input()
t = ''
b = []
for i in range(len(s1)):
	t += s1[i]
	if s1[i] == ' ':
		b.append(int(t))
		t = ''
b.append(int(t))
need_yellow = b[0] * 2 + b[1]
need_blue = b[1] + 3 * b[2]
ans1 = need_yellow - a[0]
ans2 = need_blue - a[1]
if ans1 < 0:
	ans1 = 0
if ans2 < 0:
	ans2 = 0
print(ans1 + ans2)


(y, b) = map(int, input().split())
(ry, rg, rb) = map(int, input().split())
n1 = y - 2 * ry - rg
n2 = b - rg - 3 * rb
Sum = 0
if n1 < 0:
	Sum += -n1
if n2 < 0:
	Sum += -n2
print(Sum)


from __future__ import print_function
(a, b) = (int(x) for x in input().strip().split())
(x, y, z) = (int(x) for x in input().strip().split())
yellow = 2 * x + y
blue = 3 * z + y
e1 = yellow - a
e2 = blue - b
total = 0
if e1 >= 0:
	total += e1
if e2 >= 0:
	total += e2
print(total)


(y, b) = map(int, input().split())
A = list(map(int, input().split()))
yn = 2 * A[0] + A[1]
bn = A[1] + 3 * A[2]
ym = max(0, yn - y)
bm = max(0, bn - b)
print(ym + bm)


(A, B) = map(int, input().split())
(X, Y, Z) = map(int, input().split())
print(max(0, X * 2 + Y - A) + max(0, Z * 3 + Y - B))


(y, b) = [int(x) for x in input().strip().split(' ')]
(dy, dg, db) = [int(x) for x in input().strip().split(' ')]
ry = dy * 2
ry += dg
rb = dg
rb += db * 3
totalReq = 0
if y - ry < 0:
	totalReq += abs(y - ry)
if b - rb < 0:
	totalReq += abs(b - rb)
print(totalReq)


import sys
import math
import bisect
import itertools

def main():
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	yellow = B[0] * 2 + B[1] * 1
	blue = B[1] * 1 + B[2] * 3
	ans = 0
	if A[0] < yellow:
		ans += yellow - A[0]
	if A[1] < blue:
		ans += blue - A[1]
	print(ans)
main()


from sys import stdin, stdout
(a, b) = [int(x) for x in stdin.readline().strip().split()]
(x, y, z) = [int(w) for w in stdin.readline().strip().split()]
A = 2 * x + y
B = 3 * z + y
stdout.write('{}\n'.format(max(0, A - a) + max(0, B - b)))


(x, y) = map(int, input().split())
(a, b, c) = map(int, input().split())
summ = 0
sub = x - 2 * a
if sub > 0:
	x = sub
else:
	summ += abs(sub)
	x = 0
sub1 = x - b
if sub1 > 0:
	x = sub1
else:
	summ += abs(sub1)
	x = 0
sub2 = y - b
if sub2 > 0:
	y = sub2
else:
	summ += abs(sub2)
	y = 0
sub3 = y - 3 * c
if sub3 > 0:
	y = sub3
else:
	summ += abs(sub3)
	y = 0
print(summ)


(a, b) = map(int, input().split())
(x, y, z) = map(int, input().split())
nn = x * 2 + y
mm = 3 * z + y
k1 = 0
k2 = 0
if nn > a:
	k1 = nn - a
if mm > b:
	k2 = mm - b
print(k1 + k2)


(A, B) = list(map(int, input().split()))
(x, y, z) = list(map(int, input().split()))
yellow = x * 2 + y
blue = y + z * 3
y_need = yellow - A
b_need = blue - B
need = 0
if y_need > 0:
	need += y_need
if b_need > 0:
	need += b_need
print(need)


l = list(map(int, input().split()))
color = list(map(int, input().split()))
ans = [0, 0]
ans[0] += 2 * color[0] + color[1]
ans[1] += 3 * color[2] + color[1]
ans[0] -= l[0]
ans[1] -= l[1]
if ans[0] < 0:
	ans[0] = 0
if ans[1] < 0:
	ans[1] = 0
print(sum(ans))


(ye, blue) = map(int, input().split())
A = list(map(int, input().split()))
sum_ye = A[0] * 2 + A[1] * 1
sum_blue = A[1] * 1 + A[2] * 3
subs_ye = sum_ye - ye
subs_blue = sum_blue - blue
if subs_ye < 0:
	subs_ye = 0
elif subs_ye >= 0:
	subs_ye = subs_ye
if subs_blue < 0:
	subs_blue = 0
elif subs_blue >= 0:
	subs_blue = subs_blue
sums_all = subs_ye + subs_blue
print(sums_all)


(y, b) = map(int, input().split())
(Y, G, B) = map(int, input().split())
yy = Y * 2 + G
bb = G + 3 * B
cnt = 0
if yy - y >= 0:
	cnt += yy - y
if bb - b >= 0:
	cnt += bb - b
print(cnt)


(yb, bb) = map(int, input().split(' '))
(cy, cg, cb) = map(int, input().split(' '))
ballReq = 0
yr = 2 * cy + cg
br = 3 * cb + cg
if yb >= yr and bb >= br:
	print(0)
elif yb < yr and bb > br:
	print(yr - yb)
elif yb > yr and bb < br:
	print(br - bb)
else:
	print(yr - yb + br - bb)