Jon wants to go in birthday party of Arya. But he is busy in finding solution of crazy equations, so he wants your help to solve this problem. Jon has four integers a, b, c, d now he wants to calculate how many distinct set of x, y, z, w are present such that  a + b - x  == a + c - y == c + d - z == b + d - w
NOTE :  1<= x, y, z, w<=n   where n is a given integer.
Two set of x, y, z, w will be different if atleast one value will be different.
Example 1:
Input: n = 5, a = 1, b = 2, c = 2, d = 2
Output: 4
Explanation: Sets of x, y, z, w can be
             (1, 1, 2, 2)
             (2, 2, 3, 3)
             (3, 3, 4, 4)
             (4, 4, 5, 5).
Example 2:
Input: n = 5, a = 1, b = 2, c = 2, d = 1
Output: 5
Explanation: same explanation as previous one.
Your Task:  
You dont need to read input or print anything. Complete the function distinctValues() which takes n, a, b, c and d as input parameter and returns the total number of distinct set of x, y, z, w are present. 
Expected Time Complexity: O(n)
Expected Auxiliary Space: O(1)
Constraints:
1 <= n <= 10^{6}
1 <= a, b, c, d <= n

Source: geeksforgeeks | Difficulty: MEDIUM
Tags: Mathematics

Starter code: #User function Template for python3
class Solution:
	def distinctValues(self, n, a, b, c, d):
		# code here


Solutions:
class Solution:

	def distinctValues(self, n, a, b, c, d):
		arr = [a + b, a + c, c + d, b + d]
		arr.sort()
		diff = arr[-1] - arr[0]
		ans = 0
		return max(n - diff, 0)


class Solution:

	def distinctValues(self, n, a, b, c, d):
		x = a + b
		y = a + c
		z = c + d
		w = b + d
		m1 = max(x, y, z, w)
		m2 = min(x, y, z, w)
		diff = abs(m1 - m2)
		return 0 if n - diff < 0 else n - diff


class Solution:

	def distinctValues(self, n, a, b, c, d):
		a1 = a + b
		a2 = a + c
		a3 = c + d
		a4 = b + d
		b1 = max(a1, a2, a3, a4)
		b2 = min(a1, a2, a3, a4)
		if b1 - b2 + 1 <= n:
			return 1 + (n - (b1 - b2 + 1))
		return 0