#P3643. Celebration Canoe Selection

    ID: 16894 Type: Default 1000ms 256MiB

Celebration Canoe Selection

Celebration Canoe Selection

In Seoul city, the Han River flows from east to west. On the north bank of the Han River, there are N canoe schools (numbered from $1$ to $N$) distributed from west to east. Each school owns several canoes, and all canoes from the same school share the same color while canoes from different schools are of different colors. A school may choose to send some of its canoes to the festival celebration or send none at all. If school $i$ decides to participate, it can send any number of canoes in the interval $[a_i, b_i]$ (with $a_i\le b_i$). However, if school $i$ participates then the number of canoes it sends must be greater than the number of canoes sent by any participating school with a smaller index.

Your task is to count the number of possible ways to choose the participating schools and the number of canoes sent by each such that at least one canoe is sent in total. Two ways are considered different if there is at least one school (i.e. color) for which the number of canoes sent is different.

The strict increasing condition may be formally written as: if for some indices $i$ and $j$ with $i<j$, school $i$ and school $j$ both participate with $x_i$ and $x_j$ canoes respectively, then it must hold that \[ x_i < x_j. \]

inputFormat

The first line contains a single integer $N$, the number of canoe schools. Each of the following $N$ lines contains two integers $a_i$ and $b_i$ separated by a space, representing the lower and upper bound of canoes that school $i$ can send if it participates.

outputFormat

Output a single integer, the number of possible ways to select the participating schools and the number of canoes such that at least one canoe participates, satisfying the conditions described above.

sample

1
1 2
2