```go
package main
import (
"fmt"
)
func main() {
var a, b, c, d int
fmt.Scan(&a, &b, &c, &d)
var ans int64
// We iterate over the sum of x and y, let s = x + y.
// The range of s is [A+B, B+C].
// For a non-degenerate triangle, we need x + y > z => s > z => z < s.
// Also C <= z <= D. So we need z in [C, min(D, s-1)].
// If min(D, s-1) < C, there are no valid z. Thus s-1 >= C => s >= C+1.
start := a + b
if c+1 > start {
start = c + 1
}
for s := start; s <= b+c; s++ {
// Calculate number of pairs (x, y) such that x+y = s
// Constraints: A <= x <= B, B <= y <= C
// x = s - y
// B <= y <= C => B <= s - x <= C => s - C <= x <= s - B
// Combined with A <= x <= B:
// x in [max(A, s-C), min(B, s-B)]
l := a
if s-c > l {
l = s - c
}
r := b
if s-b < r {
r = s - b
}
if l > r {
continue
}
countXY := int64(r - l + 1)
// Calculate number of z
zMax := d
if s-1 < zMax {
zMax = s - 1
}
// Since s >= c + 1, zMax >= c is guaranteed.
countZ := int64(zMax - c + 1)
ans += countXY * countZ
}
fmt.Println(ans)
}
```