### PROBLEM LINK:

**Author:** Misha Chorniy

**Tester:** Sergey Kulik

**Editorialist:** Pawel Kacprzak

### DIFFICULTY:

CAKEWALK

### PREREQUISITES:

basic math

### PROBLEM:

Given integers **a, b, c, d** find the number of integer solutions of inequality **x < y**, where **a ≤ x ≤ b** and **c ≤ y ≤ d**. In one test file there are several test cases to handle.

### QUICK EXPLANATION:

Iterate through all possible values of **x** and for each one, count the number of valid values of **y** to pair with it.

### EXPLANATION:

### Subtask 1

In the first subtask, we know that **a, b, c, d ≤ 10 ^{3}**. For such low constraints, it can observed that in any valid pair of

**x < y**, both

**x**and

**y**are less or equal than

**10**as well. With this observation, it is possible to iterate over all possible

^{3}**x, y ≤ 10**. Thus, for each fixed pair

^{3}**x, y**, we can explicitly check if

**x < y**and add

**1**to the result if the inequality is fulfilled.

### Subtask 2

In the second subtask we have **a, b, c, d ≤ 10 ^{6}**, so iterating over all possible values of

**x**and

**y**explicitly is not possible here. However, constraints are small enough to iterate over all possible values of one of the variables. Let’s say that we are going to iterate explicitly over all possible values of

**x**. For one such fixed value of

**x**, the problem reduces to how many values of y are there such that

**c ≤ y ≤ d**and

**x < y**. In other words, the task is to count the number of integers

**y**, such that

**y ≥ max(c, x + 1)**and

**y ≤ d**. Let’s assume that

**c ≤ d**, otherwise, there are no valid values of

**y**of course. It follows, that for a fixed

**x**, there are

**d - max(c, x+1) + 1**valid values of

**y**, because the number of integers in a range

**[R**is given by

_{1}, R_{2}]**R2 - R1 + 1**.

The final result is the accumulated result for each possible value of **x** computed as described above. Total time complexity of this method is linear in terms of the number of possible values of **x**, which is at most **10 ^{6}**.

### AUTHOR’S AND TESTER’S SOLUTIONS:

Setter's solution will be uploaded soon. Tester's solution can be found [here][444]. Editorialist's solution can be found [here][555].