Vasya works as a watchman in the gallery. Unfortunately, one of the most expensive paintings was stolen while he was on duty. He doesn't want to be fired, so he has to quickly restore the painting. He remembers some facts about it.  The painting is a square 3 × 3, each cell contains a single integer from 1 to n, and different cells may contain either different or equal integers.  The sum of integers in each of four squares 2 × 2 is equal to the sum of integers in the top left square 2 × 2.  Four elements a, b, c and d are known and are located as shown on the picture below. $\left. \begin{array}{|c|c|c|} \hline ? & {a} & {?} \\ \hline b & {?} & {c} \\ \hline ? & {d} & {?} \\ \hline \end{array} \right.$

Help Vasya find out the number of distinct squares the satisfy all the conditions above. Note, that this number may be equal to 0, meaning Vasya remembers something wrong.

Two squares are considered to be different, if there exists a cell that contains two different integers in different squares.


-----Input-----

The first line of the input contains five integers n, a, b, c and d (1 ≤ n ≤ 100 000, 1 ≤ a, b, c, d ≤ n) — maximum possible value of an integer in the cell and four integers that Vasya remembers.


-----Output-----

Print one integer — the number of distinct valid squares.


-----Examples-----
Input
2 1 1 1 2

Output
2

Input
3 3 1 2 3

Output
6



-----Note-----

Below are all the possible paintings for the first sample. $\left. \begin{array}{|l|l|l|} \hline 2 & {1} & {2} \\ \hline 1 & {1} & {1} \\ \hline 1 & {2} & {1} \\ \hline \end{array} \right.$ $\left. \begin{array}{|l|l|l|} \hline 2 & {1} & {2} \\ \hline 1 & {2} & {1} \\ \hline 1 & {2} & {1} \\ \hline \end{array} \right.$

In the second sample, only paintings displayed below satisfy all the rules. $\left. \begin{array}{|c|c|c|} \hline 2 & {3} & {1} \\ \hline 1 & {1} & {2} \\ \hline 2 & {3} & {1} \\ \hline \end{array} \right.$ $\left. \begin{array}{|c|c|c|} \hline 2 & {3} & {1} \\ \hline 1 & {2} & {2} \\ \hline 2 & {3} & {1} \\ \hline \end{array} \right.$ $\left. \begin{array}{|l|l|l|} \hline 2 & {3} & {1} \\ \hline 1 & {3} & {2} \\ \hline 2 & {3} & {1} \\ \hline \end{array} \right.$ $\left. \begin{array}{|c|c|c|} \hline 3 & {3} & {2} \\ \hline 1 & {1} & {2} \\ \hline 3 & {3} & {2} \\ \hline \end{array} \right.$ $\left. \begin{array}{|c|c|c|} \hline 3 & {3} & {2} \\ \hline 1 & {2} & {2} \\ \hline 3 & {3} & {2} \\ \hline \end{array} \right.$ $\left. \begin{array}{|c|c|c|} \hline 3 & {3} & {2} \\ \hline 1 & {3} & {2} \\ \hline 3 & {3} & {2} \\ \hline \end{array} \right.$

Difficulty: interview

Starter code:

Solutions:
n, a, b, c, d= [int(i) for i in input().split()]
o = 0
for i in range(1, n+1):
	if i+b-c>0 and i+b-c<=n:
		if i+a-d>0 and i+a-d<=n:
			if i+a+b-c-d>0 and i+a+b-c-d<=n:
				o+=1
print(o*n)


n, a, b, c, d = map(int, input().split())
ans = 0
for i in range(1, n + 1):
	x = i + b - c
	y = i + a + b - c - d
	z = i + a - d
	ans += n * (1 <= x <= n and 1 <= y <= n and 1 <= z <= n)
print(ans)

n,a,b,c,d=[int(x) for x in input().split()]
possib=0
for x in range(1,n+1):
    if 1<=(a+b+x-c-d)<=n and 1<=(b+x-c)<=n and 1<=(a+x-d)<=n:
        possib+=1
print(possib*n)


n, a, b, c, d = list(map(int, input().split()))
ans = 0
for x1 in range(1, n + 1):
    x2 = x1 + b - c
    x4 = a + x1 - d
    x5 = b + x4 - c
    if 1 <= x2 <= n and 1 <= x4 <= n and 1 <= x5 <= n:
        ans += 1
print(ans * n)
    


n, a, b, c, d = list(map(int, input().split()))
l = max(1 - b + c, 1 - a + d, 1 - a - b + c + d)
h = min(n - b + c, n - a + d, n - a - b + c + d)
if (l < 0):
    l = 1
if (h > n):
    h = n
if h < l:
    print(0)
else:
    print(n * (h - l + 1))


n,a,b,c,d = list(map(int, input().split()))
num = 0
i = 0
while n > i:
    i += 1
    if i + b - c < 1 or i + b - c > n:
        continue
    if i + a - d < 1 or i + a - d > n:
        continue
    if i + a - d + b - c  < 1 or i + a - d + b - c > n:
        continue
    num += 1
print(num * n)


n, a, b, c, d = list(map(int, input().split()))
ans = 0
for i in range(1, n + 1):
    s = i + a + b
    x2 = s - a - c
    x3 = s - c - d
    x4 = s - b - d
    if max(x2, x3, x4) <= n and min(x2, x3, x4) >= 1:
        ans += n
print(ans)


#!/usr/bin/env python3

def main():
    n, a, b, c, d = [int(x) for x in input().split()]
    cnt = 0
    for x in range(1, n + 1):
        z1 = x + b - c
        z2 = x + a + b - d - c
        z3 = x + a - d

        if all(1 <= xx <= n for xx in (z1, z2, z3)):
            cnt += n

    print(cnt)

def __starting_point():
    main()

__starting_point()

n,a,b,c,d=map(int,input().split())
q={}
for x1 in range(1,n+1):
    x4=a+x1-d
    if x4<1 or x4>n: continue
    x2=x1+b-c
    if x2<1 or x2>n: continue
    x5=x2+a-d
    if x5<1 or x5>n: continue
    q[(x1,x2,x4,x5)]=1
print(len(q)*n)

n, a, b, c, d = list(map(int, input().split()))
arr = [0] * 4
arr[0] = a + b
arr[1] = a + c
arr[2] = c + d
arr[3] = b + d
arr.sort()
if n + arr[0] - arr[3] >= 0:
    print(n * (n + arr[0] - arr[3]))
else:
    print(0)


n, a, b, c, d = map(int, input().split())
ans = 0
for e in range(1, n + 1):
    min1 = a + b + e + 1
    max1 = a + b + e + n
    min2 = b + e + d + 1
    max2 = b + d + e + n
    min3 = d + c + e + 1
    max3 = d + c + e + n
    min4 = a + c + e + 1
    max4 = a + c + e + n
    l = max(min1, min2, min3, min4)
    r = min(max1, max2, max3, max4)
    if l <= r:
        ans += r - l + 1
print(ans)

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

ans = 0
for i in range(1, n+1) :
    s = a+b+i
    j = s - a - c
    k = s - b - d
    l = s - c - d
    if 1 <= j <=n and 1<= k <= n and 1<= l <= n :
        ans += n

print(ans)

n, a, b, c, d = list(map(int, input().split()))
lst = [a+b, a+c, c+d, b+d]
if (n-(max(lst)-min(lst))) <=0:
    print(0)
else:
    print((n-(max(lst)-min(lst)))*n)



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

ans = 0

for x1 in range(1, n+1):
	x2 = x1+b-c
	if x2 < 1 or x2 > n:
		continue
	x4 = x1+a-d
	if x4 < 1 or x4 > n:
		continue
	x5 = x1+a+b-c-d
	if x5 < 1 or x5 > n:
		continue

	ans += 1

print(ans*n)

def solve(n,a,b,c,d):
    ans = 0
    sums = [a+b, b+d, d+c, c+a]
    minsum = min(sums)
    maxsum = max(sums)
    tmp = minsum + n
    if (tmp <= maxsum):
        return ans
    else:
        ans += n * (tmp - maxsum)
    return ans
    
(n,a,b,c,d) = [int(x) for x in input().split()]
print(solve(n,a,b,c,d))

n, a, b, c, d = list(map(int, input().split()))
lo = min(a+b, a+c, c+d, b+d)
hi = max(a+b, a+c, c+d, b+d)
ans = 0
for x in range(1, n+1):
    ans += max(0, n-(hi-lo))
print(ans)


n, a, b, c, d = [int(s) for s in input().split()]
def solve(p):
    s = []
    s.append(p[0][0] + p[0][1] + p[1][0] + p[1][1])
    s.append(p[0][1] + p[0][2] + p[1][1] + p[1][2])
    s.append(p[1][0] + p[1][1] + p[2][0] + p[2][1])
    s.append(p[1][1] + p[1][2] + p[2][1] + p[2][2])
    return max(0, n - (max(s) - min(s)))
p = [
    [0, a, 0],
    [b, 0, c],
    [0, d, 0],
]
res = 0
for m in range(1, n + 1):
    p[1][1] = m
    res += solve(p)
print(res)


# You lost the game.
n,a,b,c,d = list(map(int, input().split()))
r = 0
for e in range(1,n+1):
    h = e + (a-d)
    i = h + (b-c)
    f = i + (d-a)
    if e == f + (c-b) and h <= n and i <= n and f <= n and h > 0 and i > 0 and f > 0:
        r += 1
print(r*n)



import sys

arr = list(map(int, input().strip().split()))
n = arr[0]
top = arr[1]
left = arr[2]
right = arr[3]
bottom = arr[4]

top_left = top + left
top_right = top + right
bottom_left = bottom + left
bottom_right = bottom + right

max_greater = 0
max_lesser = 0
nums = [top_right, bottom_left, bottom_right]
for e in nums:
    diff = e - top_left
    max_greater = max(max_greater, diff)
    max_lesser = min(max_lesser, diff)
max_diff = max_greater - max_lesser

if max_diff > n - 1:
    ans = 0
else:
    ans = (n - max_diff) * n
print(ans)


def f(n, r, p, q):
    if r < 1 or r > n: return 0
    if p < 1 or p > n: return 0
    if q < 1 or q > n: return 0
    return 1

n, a, b, c, d = [int(i) for i in input().split()]
box = 0
for i in range(1, n + 1):
    r = i + b - c
    p = r + a - d
    q = p + c - b
    box += f(n, r, p, q)
    '''
    for j in range(1, n + 1):
        print(i, a, r)
        print(b, j, c)
        print(q, d, p)
        print()
        '''
box *= n
print(box)
    



def __starting_point():
    #n, m = list(map(int, input().split()))
    n, a, b, c, d = list(map(int, input().split()))
    x = max([1 - a + d, 1 - b + c, 1, 1 - a - b + d + c])
    y = min([n - a + d, n - b + c, n, n - a - b + d + c])
    #print(x, y)
    if x > y:
        print(0)
        return
    else:
        print(n *(y - x + 1))
    

__starting_point()

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

min_sum = max(a + b, a + c, b + d, c + d) + 1
max_sum = min(a + b, a + c, b + d, c + d) + n

print(max((max_sum - min_sum + 1) * n, 0))

import sys

n, a, b, c, d = list(map(int,sys.stdin.readline().split()))

c1 = 0
for x11 in range(n):
    x13 = x11 + 1 - c + b
    x31 = x11 + 1 - d + a
    x33 = x11 + 1 - c - d + a + b
    #print (x11 + 1, x13, x31, x33)
    if x13 >= 1 and x13 <= n and x31 >= 1 and x31 <= n and x33 >= 1 and x33 <= n:
        c1 = c1 + 1
print(c1 * n)


n, a, b, c, d = map(int, input().split())
ans = 0
for i in range(1, n + 1):
    if c + d + 1 <= a + b + i <= c + d + n and a + c + 1 <= a + b + i <= a + c + n and b + d + 1 <= a + b + i <= b + d + n:
        ans += n
print(ans)

n, a, b, c, d = list(map(int, input().split(' ')))
print(max(0, n*(n-max([a+b, a+c, c+d, b+d])+min([a+b, a+c, c+d, b+d]))))