COCI '11 Contest 2 #5 Funkcija

View as PDF

Submit solution


Points: 15 (partial)
Time limit: 1.0s
Memory limit: 128M

Problem type

Mirko has written the following function:

Copy
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;
}
Copy
function fun: longint;
var
  ret: longint;
  a, b, ... , y, z: longint;
begin
  ret := 0;
  for a := X1 to Y1 do
    for b := X2 to Y2 do
      ...
        for <N-th> := XN to YN do
          ret := (ret + 1) mod 1000000007;
  fun := ret;
end;

<N-th> denotes the Nth lowercase letter of the English alphabet. Each Xi and Yi denotes either a positive integer less than or equal to 100000 or a name of a variable that some outer loop iterates over. For example, X3 can be either a, b, or an integer literal. At least one of Xi and Yi will be an integer literal (i.e. not a variable name) for every i.

Compute the return value of the function.

Input Specification

The first line of input contains the positive integer N (1N26).

For the next N lines, the ith line contains Xi and Yi, separated with a space. If Xi and Yi are both integer literals, then XiYi.

Output Specification

The first and only line of output must contain the return value of the function.

Sample Input 1

Copy
2
1 2
a 3

Sample Output 1

Copy
5

Sample Input 2

Copy
3
2 3
1 2
1 a

Sample Output 2

Copy
10

Sample Input 3

Copy
3
1 2
a 3
1 b

Sample Output 3

Copy
11

Comments

There are no comments at the moment.