Function Return Value

Time limit1sMemory limit128 MB

Problem

Changyoung wrote the following function.

int fun() {
    int ret = 0;
    for (int a = X1; a <= Y1; ++a)
        for (int b = X2; b <= Y2; ++b)
        ...
            for (int <n-th> = XN; <n-th> <= YN; ++<n-th>)
                ret = (ret + 1) % 1000000007;
    return ret;
}

<N-th> is the N-th lowercase English letter. Each Xi and Yi can be either a positive integer not greater than 100,000, or a variable that appeared in an outer loop.

For instance, X3 can be a, b, or an integer. For every i, at least one of Xi and Yi is an integer rather than a variable name.

Given all values of Xi and Yi, write a program that prints the value returned by the function.

Consider these relations: (X1, Y1) = (1, 2), (X2, Y2) = (a, 3), (X3, Y3) = (1, b). Then the function is as follows.

int fun() {
    int ret = 0;
    for (int a = 1; a <= 2; ++a)
        for (int b = a; b <= 3; ++b)
            for (int c = 1; c <= b; ++c)
                ret = (ret + 1) % 1000000007;
    return ret;
}

Input

The first line contains a positive integer N (1 ≤ N ≤ 26).

Each of the next N lines contains Xi Yi, in order from X1 Y1. If both Xi and Yi are integers, then Xi ≤ Yi.

Output

Print the return value of the function on one line.