I found an interesting problem on https://www.codechef.com/LTIME40/problems/LTM40AB:
Chef likes inequalities. Please help him to solve next one.
Given four integers a, b, c, d. Find number of solutions x < y, where a ≤ x ≤ b and c ≤ y ≤ d and x, y integers.

-----Input-----
The first line contains an integer T denoting number of tests.
First line of each test case contains four positive integer numbers a, b, c and d.

-----Output-----
For each test case, output a single number each in separate line denoting number of integer solutions as asked in the problem.

-----Constraints-----
- 1 ≤ T ≤ 20 
- 1 ≤ a, b, c, d ≤ 106 

-----Subtasks-----
- Subtask #1: (30 points)  1 ≤ a, b, c, d ≤ 103.
- Subtask #2: (70 points)  Original constraints.

-----Example-----
Input:1
2 3 3 4

Output:3

Input:1
2 999999 1 1000000

Output:499998500001

I tried it in Python, but could not do it. Can you solve it?
# Akhilesh Ravi
# Codechef - Chef and Inequality

T = int(input())
l = []
for i in range(T):
 l += [[int(j) for j in input().split()]]

l1 = []
for i in l:
 a,b,c,d = tuple(i)
 if a >= d:
  l1 += [0]
  
 elif b < c:
  l1 += [(b-a+1)*(d-c+1)]
  
 elif c <= a <= d <= b:
  n = d-a
  l1 += [n*(n+1)/2]
  
 elif c <= a <= b <= d:
  l1 += [(d-a) * (d-a+1)/2
    - (d-b-1) * (d-b)/2]
  
 elif a < c <= d <= b:
  l1 += [ (d-c+1) * (c-a)
    + (d-c) * (d-c+1)/2 ]
  
 elif a < c <= b <= d:
  l1 += [ (d-c+1) * (c-a)
    + (d-c) * (d-c+1)/2
    - (d-b-1) * (d-b)/2]
  
 else:
  l1 += [0]

for i in l1:
 print(i)