Under construction

Still being built. Things may change

Sums of Blue and Red Cubes

Interview

Time limit2sMemory limit1024 MB

Summary
Count the pairs (x, y) with x and y each taken from the integers a to b whose sum lies between c and d inclusive.
Level

Medium4 of 10

Topics
Math, Implementation
Solved
No attempts yet

Problem

Krosh received several gifts on a holiday. Barash and Losyash each gave him a set of cubes. Barash gave blue cubes and Losyash gave red cubes. Each set has one cube for every integer from aa to bb inclusive, and no two cubes in the same set share a number.

Krosh chooses two numbers cc and dd. He then picks one blue cube and one red cube so that the sum of their numbers is between cc and dd inclusive. Count the number of ways to do this.

Input

The input is a single line with four integers aa, bb, cc, and dd. 0≤a≤b≤1090 \le a \le b \le 10^9, 0≤c≤d≤2⋅1090 \le c \le d \le 2 \cdot 10^9.

Output

Print one integer: the number of ways to choose one blue cube and one red cube so that their sum is in the given range.

Examples2

  1. Example 1

    Input
    3 6 7 9
    
    Expected output
    9
    
  2. Example 2

    Input
    1 1 10 10
    
    Expected output
    0