Polycarp has n dice d_1, d_2, ..., d_{n}. The i-th dice shows numbers from 1 to d_{i}. Polycarp rolled all the dice and the sum of numbers they showed is A. Agrippina didn't see which dice showed what number, she knows only the sum A and the values d_1, d_2, ..., d_{n}. However, she finds it enough to make a series of statements of the following type: dice i couldn't show number r. For example, if Polycarp had two six-faced dice and the total sum is A = 11, then Agrippina can state that each of the two dice couldn't show a value less than five (otherwise, the remaining dice must have a value of at least seven, which is impossible).

For each dice find the number of values for which it can be guaranteed that the dice couldn't show these values if the sum of the shown values is A.


-----Input-----

The first line contains two integers n, A (1 ≤ n ≤ 2·10^5, n ≤ A ≤ s) — the number of dice and the sum of shown values where s = d_1 + d_2 + ... + d_{n}.

The second line contains n integers d_1, d_2, ..., d_{n} (1 ≤ d_{i} ≤ 10^6), where d_{i} is the maximum value that the i-th dice can show.


-----Output-----

Print n integers b_1, b_2, ..., b_{n}, where b_{i} is the number of values for which it is guaranteed that the i-th dice couldn't show them.


-----Examples-----
Input
2 8
4 4

Output
3 3 
Input
1 3
5

Output
4 
Input
2 3
2 3

Output
0 1 


-----Note-----

In the first sample from the statement A equal to 8 could be obtained in the only case when both the first and the second dice show 4. Correspondingly, both dice couldn't show values 1, 2 or 3.

In the second sample from the statement A equal to 3 could be obtained when the single dice shows 3. Correspondingly, it couldn't show 1, 2, 4 or 5.

In the third sample from the statement A equal to 3 could be obtained when one dice shows 1 and the other dice shows 2. That's why the first dice doesn't have any values it couldn't show and the second dice couldn't show 3.

Source: codeforces | Difficulty: MEDIUM_HARD
Tags: Mathematics


Solutions:
(n, A) = map(int, input().split())
d = [int(x) for x in input().split()]
s = sum(d)
print(' '.join([str(x - min(x, A - n + 1) + max(1, A - s + x) - 1) for x in d]))


(n, A) = map(int, input().split())
ds = list(map(int, input().split()))
total = sum(ds)
others_max = [total - d for d in ds]
others_min = n - 1
mins = [max(A - o - 1, 0) for o in others_max]
for i in range(n):
	if ds[i] > A - others_min:
		mins[i] += ds[i] - (A - others_min)
print(' '.join(map(str, mins)))


(n, s) = list(map(int, input().split()))
a = list(map(int, input().split()))
total = sum(a)
ans = []
for i in range(n):
	high = s - (total - a[i])
	low = s - (n - 1)
	cur = 0
	if low <= a[i]:
		cur += a[i] - low
	if high > 0:
		cur += high - 1
	ans.append(cur)
print(' '.join(map(str, ans)))


(n, A) = map(int, input().split())
d = [int(x) for x in input().split()]
x = sum(d)
b = []
for i in range(n):
	b.append(d[i] - min(d[i], A - n + 1) + max(A - x + d[i], 1) - 1)
print(''.join([str(b[i]) + ' ' for i in range(n)]))


(n, a) = [int(x) for x in input().split()]
d = [int(x) for x in input().split()]
total = sum(d)
for i in range(n):
	count = 0
	count += max(0, d[i] - (a - (n - 1)))
	count += max(0, a - total + d[i] - 1)
	print(count, end=' ')


def readline():
	return [int(c) for c in input().split()]

def main():
	(n, A) = readline()
	d = readline()
	tot = sum(d)
	ans = [di - min(A - n + 1, di) + max(A - tot + di, 1) - 1 for di in d]
	print(*ans)
main()


from sys import stdin

def main():
	(n, s) = map(int, stdin.readline().split())
	ar = list(map(int, stdin.readline().split()))
	total = sum(ar)
	ans = [0] * n
	for i in range(n):
		curr_total = total - ar[i]
		max_x = min(ar[i], s - (n - 1))
		min_x = max(1, s - curr_total)
		ans[i] = ar[i] - (max_x - min_x + 1)
	print(*ans)
main()


(n, A) = [int(i) for i in input().split()]
d = [int(i) for i in input().split()]
s = sum(d)
ans = []
for dd in d:
	left = max(0, A - s + dd)
	right = min(dd, A - n + 1)
	cnt = 0
	if left > 1:
		cnt += left - 1
	if right < dd:
		cnt += dd - right
	ans.append(cnt)
print(' '.join([str(i) for i in ans]))


(n, sum) = map(int, input().split())
t = input().split()
array = []
for i in range(0, n):
	array.append(int(t[i]))
total = 0
for i in range(0, n):
	total = total + array[i]
for i in range(0, n):
	k = total - array[i]
	top = sum - (n - 1)
	below = sum - k
	if below <= 0:
		below = 1
	if top > array[i]:
		top = array[i]
	print(array[i] - top + below - 1, end=' ')
print()


[n, A] = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
tot = 0
for x in a:
	tot += x
for x in a:
	up = min(x, A - (n - 1))
	down = max(A - (tot - x), 1)
	print(x - (up - down + 1), end=' ')
print()


(n, a) = map(int, input().split())
b = list(map(int, input().split()))
ans = [0] * n
k = a - (n - 1)
if n == 1:
	print(b[0] - 1)
	exit()
elif a % n == 0:
	d = a // n
	if b.count(d) == n:
		ans = [d - 1] * n
		print(*ans)
		exit()
s = sum(b)
for i in range(n):
	if k < b[i]:
		ans[i] += b[i] - k
	if s - a < b[i]:
		ans[i] += a - (s - b[i]) - 1
print(*ans)


(n, a) = list(map(int, input().split()))
d = list(map(int, input().split()))
q1 = min(sum(d) - max(d) + 1, n - 1 + max(d))
q2 = max(sum(d) - max(d) + 1, n - 1 + max(d))
window = q1 - n + 1
if a >= q1 and a <= q2:
	delta = q1 - n + 1
	for i in d:
		print(i - delta if i - delta > 0 else 0, end=' ')
if a < q1:
	delta = a - n + 1
	for i in d:
		print(i - delta if i - delta > 0 else 0, end=' ')
if a > q2:
	delta = q1 + q2 - a - n + 1
	for i in d:
		print(i - delta if i - delta > 0 else 0, end=' ')


(n, k) = map(int, input().split())
d = list(map(int, input().split()))
(tot, res) = (sum(d), [])
for i in range(n):
	x = max(0, k + d[i] - tot - 1)
	y = max(0, -k + d[i] + n - 1)
	res.append(x + y)
print(*res)


(n, a, *d) = [int(x) for x in input().split() + input().split()]
sd = sum(d)
for e in d:
	t = 0 if a - (sd - e) - 1 < 0 else a - (sd - e) - 1
	b = 0 if e + (n - 1 - a) < 0 else e + (n - 1 - a)
	print(t + b, '', end='')


def getIntersection(l1, r1, l2, r2):
	ans = -1
	if l1 > l2:
		(l1, l2) = (l2, l1)
		(r1, r2) = (r2, r1)
	if l2 > r1:
		ans = 0
	elif r2 >= r1:
		ans = r1 - l2 + 1
	else:
		ans = r2 - l2 + 1
	return ans

def solve(d, a):
	total = sum(d)
	n = len(d)
	ans = []
	for i in d:
		(l, r) = (n - 1, total - i)
		(tgtl, tgtr) = (a - i, a - 1)
		intersect = getIntersection(l, r, tgtl, tgtr)
		ans.append(i - intersect)
	return ans
(n, a) = (int(x) for x in input().split())
d = [int(x) for x in input().split()]
print(*(i for i in solve(d, a)))


(n, s) = input().split()
n = int(n)
s = int(s)
d = list(map(int, input().split()))
s2 = sum(d)
for i in range(0, n):
	temp1 = s - (s2 - d[i])
	temp2 = s - (n - 1)
	ans = max(temp1 - 1, 0) + max(d[i] - temp2, 0)
	print(ans, end=' ')


import sys, os, io
from sys import stdin
from math import log, gcd, ceil
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from bisect import bisect_left, bisect_right
import math

def ii():
	return int(input())

def li():
	return list(map(int, input().split()))
if os.path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
else:
	input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
no = 'NO'
yes = 'YES'

def solve():
	(n, A) = li()
	d = li()
	if n == 1:
		if A == d[0]:
			print(d[0] - 1)
		elif A < d[0]:
			print(d[0] - 1)
		else:
			print(0)
		return
	sd = sum(d)
	for i in range(n):
		minDi = max(min(d[i], A - sd + d[i]), 1)
		maxDi = min(max(1, A - (n - 1)), d[i])
		temp = 0
		ans = maxDi - minDi + 1
		ans = d[i] - ans
		print(ans, end=' ')
	print()
t = 1
for _ in range(t):
	solve()


[n, A] = [int(x) for x in input().split()]
d = [0] + [int(x) for x in input().split()]
sigma = sum(d)
ans = [0] * (n + 1)
for i in range(1, n + 1):
	at_least = A - sigma + d[i] - 1
	at_least = max(at_least, 0)
	ans[i] += at_least
	at_most = d[i] - A + n - 1
	at_most = max(at_most, 0)
	ans[i] += at_most
ans = ans[1:]
ans = [str(x) for x in ans]
print(' '.join(ans))


(n, A) = map(int, input().split())
kosti = list(map(int, input().split()))
summ = 0
temp = 0
for i in kosti:
	summ += i
for i in kosti:
	temp = summ - i
	temp2 = min(A - (n - 1), i)
	ans = i - temp2 + max(0, A - temp - 1)
	print(ans, end=' ')


import math
from sys import stdin, stdout
(n, a) = list(map(int, stdin.readline().split()))
arr = list(map(int, stdin.readline().split()))
SUM = sum(arr)
ans = []
for i in range(n):
	remain_max = SUM - arr[i]
	remain_min = n - 1
	high = min(arr[i], a - remain_min)
	low = max(1, a - remain_max)
	ans.append(arr[i] - (high - low + 1))
print(*ans)


(n, A) = map(int, input().split())
sum_ = 0
d = [int(x) for x in input().split()]
for c in d:
	sum_ += c
for i in range(n):
	mini = max(A - (sum_ - d[i]), 1)
	maxi = min(A - (n - 1), d[i])
	print(d[i] - (maxi - mini + 1), end=' ')


(n, A) = map(int, input().split())
d = list(map(int, input().split()))
sum = 0
for i in range(n):
	sum += d[i]
for i in range(n):
	left = max(1, A - (sum - d[i]))
	right = min(d[i], A - (n - 1))
	ans = d[i] - (right - left + 1)
	print(ans)


(n, a) = [int(i) for i in input().split()]
t = [int(i) for i in input().split()]
s = 0
for i in t:
	s += i
k = []
for i in range(n):
	k.append(0)
	if s - a < t[i]:
		k[i] += t[i] - s + a - 1
	if t[i] - (a - n + 1) > 0:
		k[i] += t[i] - (a - n + 1)
print(*k)


(n, a) = map(int, input().split())
d = list(map(int, input().split()))
Ms = sum(d)
ms = n
ans = []
for i in range(n):
	Mss = Ms - d[i]
	mss = n - 1
	ans.append(max(a - Mss - 1, 0) + max(d[i] - a + mss, 0))
print(*ans)


(n, a) = list(map(int, input().split()))
d = list(map(int, input().split()))
s = sum(d)
ans = []
for i in range(n):
	l = max(1, a - (s - d[i]))
	r = min(d[i], a - (n - 1))
	ans.append(d[i] - (r - l + 1))
print(' '.join(map(str, ans)))


import sys
input = sys.stdin.readline
(n, A) = map(int, input().split())
d = list(map(int, input().split()))
s = sum(d)
for i in range(n):
	l = max(1, d[i] - s + A)
	r = min(d[i], -n + 1 + A)
	if l <= r:
		ans = d[i] - (r - l + 1)
	else:
		ans = d[i]
	if i < n - 1:
		print(ans, end=' ')
	else:
		print(ans)


(n, A) = [int(x) for x in input().split()]
d = [int(x) for x in input().split()]
s = sum(d)
for i in range(n):
	min_d_i = max(1, A - (s - d[i]))
	max_d_i = min(d[i], A - (n - 1))
	print(d[i] - max_d_i + min_d_i - 1, end=' ')


(n, a) = map(int, input().split())
d = list(map(int, input().split()))
b = [0 for i in d]
s = sum(d)
if n == 1:
	print(d[0] - 1)
else:
	for i in range(len(d)):
		if s - d[i] < a:
			b[i] += a - s + d[i] - 1
		if d[i] > a - n + 1:
			b[i] += d[i] - a + n - 1
	print(*b)


(n, m) = map(int, input().split())
lis = list(map(int, input().split()))
s = sum(lis)
for i in range(n):
	t = s - lis[i]
	z = n - 1
	ans = max(0, m - t - 1)
	ans += max(0, lis[i] - m + z)
	print(ans, end=' ')


R = lambda : map(int, input().split())
(n, a) = R()
b = list(R())
sum = 0
for i in range(n):
	sum += b[i]
for i in range(n):
	(print(b[i] - min(b[i], a - n + 1) + max(1, a - sum + b[i]) - 1),)


(n, a) = map(int, input().split())
d = list(map(int, input().split()))
s = sum(d)
b = [0] * n
for i in range(n):
	b[i] += max(d[i] - a + n - 1, 0)
	b[i] += max(d[i] - s + a - 1, 0)
print(' '.join((str(i) for i in b)))


(n, a) = map(int, input().split())
ans = 0
sum = 0
b = list(map(int, input().split()))
for i in range(n):
	sum = sum + b[i]
for i in range(0, n):
	ans = 0
	x = a - n + 1
	if x < b[i]:
		ans += b[i] - x
	x = a - (sum - b[i])
	if x > 1:
		ans = ans + x - 1
	if i != n - 1:
		print(ans, end=' ')
	else:
		print(ans)


3
import sys
(n, A) = list(map(int, sys.stdin.readline().split()))
d = list(map(int, sys.stdin.readline().split()))
s = sum(d)
for x in d:
	z = min(A - n + 1, x) - max(1, A - s + x) + 1
	if z < 0:
		z = 0
	sys.stdout.write('%d ' % (x - z))
sys.stdout.write('\n')


(n, a) = map(int, input().split())
d = [*map(int, input().split())]
from sys import exit
if n == 1:
	print(d[0] - 1)
	exit()
s = sum(d)
mn = n - 1
answer = []
for (i, x) in enumerate(d):
	mx = s - x
	res = 0
	if mx < a:
		res += a - mx - 1
	if mn + x > a:
		res += mn + x - a
	answer.append(res)
print(*answer)


(n, A) = map(int, input().split())
d = list(map(int, input().split()))
s = sum(d)
for i in range(n):
	k = max(A + d[i] - s - 1, 0)
	l = max(d[i] - A + n - 1, 0)
	print(k + l, end=' ')


(n, s) = input().strip().split(' ')
(n, s) = [int(n), int(s)]
a = list(map(int, input().strip().split(' ')))
p = s - (n - 1)
d = []
r = min(a)
kpq = sum(a)
for j in a:
	pp = s - kpq + j
	if pp <= 0:
		pp = 1
	kp = min(p, j)
	if kp - pp < 0:
		d.append(0)
	else:
		d.append(j - (kp - pp + 1))
print(*d)


(a, b) = map(int, input().split(' '))
x = list(map(int, input().split(' ')))
s = sum(x)
t = []
for i in range(a):
	minx = b - (a - 1)
	maxx = b - (s - x[i])
	xx = 0
	if min(minx, maxx) > 0:
		xx += min(minx, maxx) - 1
	if max(minx, maxx) < x[i]:
		xx += x[i] - max(minx, maxx)
	t.append(xx)
print(' '.join([str(x) for x in t]))


(n, a) = map(int, input().split())
d = list(map(int, input().split()))
s = sum(d)
ans = []
for i in range(n):
	k_min = max(a - s + d[i], 1)
	k_max = min(a - n + 1, d[i])
	ans.append(k_min - 1 + d[i] - k_max)
print(' '.join(map(str, ans)))


from sys import stdin
input = stdin.readline
(n, A) = map(int, input().split())
d = [int(x) for x in input().split()]
s = sum(d)
res = [x - max(0, min(x, A - n + 1) - max(1, A - s + x) + 1) for x in d]
print(*res)


(n, A) = map(int, input().split())
d = list(map(int, input().split()))
totSum = 0
for i in range(n):
	totSum += d[i]
answer = [0] * n
for i in range(n):
	mx = min(d[i], A - n + 1)
	mn = max(1, A - totSum + d[i])
	pos = mx - mn + 1
	answer[i] = d[i] - pos
print(*answer)


(n, S) = map(int, input().split())
d = [*map(int, input().split())]
total = sum(d)
for i in range(n):
	print(max(0, S - total + d[i] - 1) + max(0, d[i] - (S - n + 1)), end=' ')


(n, A) = [int(x) for x in input().split(' ')]
d = [int(x) for x in input().split(' ')]
S = sum(d)
p = []
for dice in d:
	q = 0
	q += max(dice - (A - (n - 1)), 0)
	q += max(0, A - (S - dice) - 1)
	p.append(q)
print(*p)


def main():
	(n, a) = map(int, input().split())
	dd = list(map(int, input().split()))
	lo = sum(dd) - a + 1
	hi = a - n + 1
	for (i, d) in enumerate(dd):
		dd[i] = (d - hi if d > hi else 0) + (d - lo if d > lo else 0)
	print(' '.join(map(str, dd)))
main()


import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import *
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
import copy
import time
starttime = time.time()
mod = int(pow(10, 9) + 7)
mod2 = 998244353

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

def out(*var, end='\n'):
	sys.stdout.write(' '.join(map(str, var)) + end)

def L():
	return list(sp())

def sl():
	return list(ssp())

def sp():
	return map(int, data().split())

def ssp():
	return map(str, data().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(n, val) for j in range(m)]
try:
	sys.stdin = open('input.txt', 'r')
except:
	pass

def pmat(A):
	for ele in A:
		print(*ele, end='\n')

def seive():
	prime = [1 for i in range(10 ** 6 + 1)]
	prime[0] = 0
	prime[1] = 0
	for i in range(10 ** 6 + 1):
		if prime[i]:
			for j in range(2 * i, 10 ** 6 + 1, i):
				prime[j] = 0
	return prime
(n, A) = L()
d = L()
s = sum(d)
print(' '.join([str(x - min(x, A - n + 1) + max(1, A - s + x) - 1) for x in d]))
endtime = time.time()


(n, a) = map(int, input().split())
d = list(map(int, input().split()))
x = sum(d)
b = []
for i in range(n):
	x -= d[i]
	dif = 0
	if a > x:
		dif = a - x - 1
	if a - n + 1 < d[i]:
		dif += d[i] - a + n - 1
	if x == 0:
		dif = d[i] - 1
	b.append(dif)
	x += d[i]
print(' '.join(map(str, b)))


(n, A) = map(int, input().split())
x = list(map(int, input().split()))
total = sum(x)
for i in range(n):
	l = max(1, A - (total - x[i]))
	r = min(x[i], A - (n - 1))
	print(x[i] - (r - l + 1), end=' ')


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

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

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

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

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

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

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

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

def mapin():
	return map(int, input().split())
(n, a) = mapin()
d = [int(x) for x in input().split()]
k = sum(d)
ans = [0] * n
for i in range(n):
	y = a - (n - 1)
	z = a - k + d[i]
	z = max(z, 1)
	y = min(y, d[i])
	ans[i] = d[i] - y + z - 1
print(*ans)


(n, a) = map(int, input().split())
d = list(map(int, input().split()))
s = sum(d)

def solve():
	for x in d:
		yield (max(x - (a - n + 1), 0) + max(a - (s - x) - 1, 0))
print(' '.join(map(str, solve())))


from sys import stdin

def arr_inp(n):
	if n == 1:
		return [int(x) for x in stdin.readline().split()]
	elif n == 2:
		return [float(x) for x in stdin.readline().split()]
	else:
		return list(stdin.readline()[:-1])
(n, A) = arr_inp(1)
d = arr_inp(1)
s = sum(d)
for i in range(n):
	tem = 0
	if s - d[i] + 1 < A:
		tem += A - (s - d[i] + 1)
	if n + d[i] - 1 > A:
		tem += n + d[i] - 1 - A
	print(tem, end=' ')


from sys import stdin, stdout
from math import *
from itertools import *
lmap = lambda x, y: list(map(x, y))
lfilter = lambda x, y: list(filter(x, y))

def solve(test):
	inp = lmap(int, test.strip().split())
	(n, s) = inp[:2]
	d = inp[2:]
	ans = [0 for _ in range(n)]
	max_value = s - n + 1
	total_values = sum(d)
	for i in range(n):
		ans[i] += min(max(0, d[i] - max_value), d[i])
		min_value = s - (total_values - d[i])
		ans[i] += min(max(0, min_value - 1), d[i])
	return ' '.join(map(str, ans))
stdout.write(str(solve(stdin.read())))


from sys import stdin

def readline():
	return [int(c) for c in stdin.readline().split()]

def main():
	(n, A) = readline()
	d = readline()
	x = A - n + 1
	y = A - sum(d)
	ans = (di - min(x, di) + max(y + di, 1) - 1 for di in d)
	print(*ans)
main()


(n, A) = map(int, input().split())
arr = list(map(int, input().split()))
s = sum(arr)
for i in range(n):
	v = s - arr[i]
	if n - 1 >= A:
		print(arr[i], end=' ')
	else:
		print(arr[i] - (min(A - (n - 1), arr[i]) - max(1, A - v) + 1), end=' ')


import sys, os, io
import math, bisect, operator
(inf, mod) = (float('inf'), 10 ** 9 + 7)
from itertools import groupby, accumulate
from heapq import heapify, heappop, heappush
from collections import deque, Counter, defaultdict
input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__
Neo = lambda : list(map(int, input().split()))
(n, s) = Neo()
A = Neo()
tot = sum(A)
Ans = []
for i in A:
	t = i - min(i, s - n + 1)
	k = tot - i
	t += max(0, s - k - 1)
	Ans.append(t)
print(*Ans)


(n, A) = map(int, input().split())
(d, ans) = (list(map(int, input().split())), [])
s = sum(d)
for di in d:
	(min_d, max_d) = (max(A - max(s - di, 0), 1), min(s - (n - 1), di, A - (n - 1)))
	ans.append(str(min_d - 1 + di - max_d))
print(' '.join(ans))


(n, a) = map(int, input().split())
ld = list(map(int, input().split()))
s = sum(ld)
res = []
for d in ld:
	l = max(a - (s - d), 1)
	r = min(a - (n - 1), d)
	res.append(d - (r - l + 1))
print(' '.join(map(str, res)))


def main():
	(n, A) = (int(i) for i in input().split())
	di = [int(i) for i in input().split()]
	sdi = sum(di)
	for d in di:
		print(max(1, A - sdi + d) - 1 + max(0, d - A + n - 1))
main()


r = lambda : map(int, input().split())
((n, a), d) = (r(), list(r()))
s = sum(d)
[print(i - min(a - n + 1, i) + max(a - s + i, 1) - 1, end=' ') for i in d]


(n, A) = map(int, input().split())
d = [int(x) for x in input().split()]
s = sum(d)
ans = []
for i in d:
	ss = A - n + 1
	sd = s - i - (n - 1)
	if ss <= 0 or A > s:
		ans.append(i)
	else:
		l = max(A - s + i, 1)
		r = min(ss, i)
		ans.append(i - r + l - 1)
print(''.join([str(ans[i]) + ' ' for i in range(n)]))


(n, a) = map(int, str.split(input()))
ns = tuple(map(int, str.split(input())))
s = sum(ns)
res = []
for x in ns:
	low = max(0, a - (s - x) - 1)
	high = min(x, a - (n - 1))
	res.append(low + x - high)
print(str.join(' ', map(str, res)))


import sys
import itertools
(n, A) = map(int, sys.stdin.readline().strip().split(' '))
d = list(map(int, sys.stdin.readline().strip().split(' ')))
s = sum(d)
ans = []
for i in range(0, n):
	m = 0
	max_bound = A - n + 1
	if max_bound < d[i]:
		m += d[i] - max_bound
	min_bound = A - (s - d[i])
	if min_bound > 0:
		m += min_bound - 1
	ans.append(str(m))
print(' '.join(ans))


(n, A) = map(int, input().split())
d = list(map(int, input().split()))
s = 0
for x in d:
	s += x
for i in range(n):
	print(d[i] - (min(d[i], A - n + 1) - max(A - s + d[i], 1) + 1), end=' ')


import os
import sys
from math import *
from collections import *
from fractions import *
from bisect import *
from heapq import *
from io import BytesIO, IOBase

def vsInput():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
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')

def value():
	return tuple(map(int, input().split()))

def array():
	return [int(i) for i in input().split()]

def Int():
	return int(input())

def Str():
	return input()

def arrayS():
	return [i for i in input().split()]
(n, s) = value()
a = array()
tot = sum(a)
for i in a:
	max_sum = tot - i
	min_sum = n - 1
	left = max(1, s - max_sum)
	right = min(i, s - min_sum)
	print(i - right + left - 1, end=' ')


import sys
import math
MAXNUM = math.inf
MINNUM = -1 * math.inf

def getInts():
	return map(int, sys.stdin.readline().rstrip().split(' '))

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

def solve(n, a, dice):
	sm = a
	mx = sum(dice)
	ans = []
	for d in dice:
		diff = mx - d - sm
		total = 0
		if diff < 0:
			total += abs(diff) - 1
		smdiff = sm - (n - 1) - d
		if smdiff < 0:
			total += abs(smdiff)
		ans.append(total)
	return ans

def printOutput(ans):
	for ele in ans:
		sys.stdout.write(str(ele) + ' ')

def readinput():
	(n, A) = getInts()
	dice = list(getInts())
	printOutput(solve(n, A, dice))
readinput()


import sys

def input():
	return sys.stdin.readline().strip()
(n, A) = map(int, input().split())
a = [int(i) for i in input().split()]
total = sum(a)
for i in range(n):
	l = A - (total - a[i])
	r = A - (n - 1)
	print(max(0, l - 1) + max(0, a[i] - r), end=' ')
print()


(n, a) = [int(x) for x in input().split()]
val = [int(x) for x in input().split()]
vsum = 0
for i in val:
	vsum += i
ans = [0] * n
for i in range(n):
	if a - (vsum - val[i]) > 1:
		ans[i] += a - (vsum - val[i]) - 1
	if val[i] > a - n + 1:
		ans[i] += val[i] - (a - n + 1)
for i in ans:
	print(i, end=' ')


f = lambda : map(int, input().split())
(n, s) = f()
d = list(f())
t = sum(d)
for q in d:
	print(q - max(0, min(q, s - n + 1) - max(0, q - t + s - 1)))