cswork / OAOpen practice workspace

IBMOA #63

Process Execution Time

Estimated MediumJudge-ready

Topics (AI-labelled)Prefix & Ranges

Each process runs during the integer closed interval [start[i],end[i]]. Find the number of integer moments at which at least one process is running. The source statement body is truncated; the original example explicitly merges overlapping intervals into [1,6], counting 6, then adds [8,10], counting 3, and the union-length rule is recovered from that explanation.

Input

The first line contains n, followed by n lines of start end. Full original bounds: 1≤n≤200000, 1≤start≤end≤10^9.

Output

Output one integer, the answer.

Example 1

Input:

3
1 5
2 6
8 10

Output:

9

Example 2

Input:

1
5 5

Output:

1

Example 3

Input:

3
3 8
1 10
10 10

Output:

10

Example notes

The outputs of the three public examples are, in order: 9; 1; 10. These answers were verified by independent enumeration or direct simulation.

Editorial

Loading solution…