close

ACTIV - Activities


Ana likes many activities. She likes acrobatics, alchemy, archery, art, Arabic dances, and many more. She joined a club that offers several classes. Each class has a time interval in every week. Ana wants to sign up for many classes, but since they overlap in time, she looks for a subset of non-overlapping classes to attend. A subset is non-overlapping if it does not contain two classes that overlap in time. If a class starts at the time another class ends, this is not considered overlapping.

Ana decided to list all the non-overlapping non-empty subsets of classes. Then she will choose the subset she likes best. In order to predict the amount of paper needed to write the list, she wants you to calculate how many of these subsets there are.

Input

Each test case is described using several lines. The first line contains an integer N indicating the number of classes the club offers (1 ≤ N ≤ 105). Each of the next N lines describes a class using two integers S and E that represent the starting and ending times of the class, respectively (1 ≤ S < E ≤ 109). The end of input is indicated with a line containing a single −1.

Output

For each test case, output a single line with a single integer representing the number of non-overlapping non-empty subsets of classes. To make your life easier, output only the last 8 digits of the result. If the result has less than 8 digits, write it with leading zeros to complete 8 digits.

Example

Input: 
5
1 3
3 5
5 7
2 4
4 6
3
500000000 1000000000
1 500000000
1 500000000
1
999999999 1000000000
-1

Output: 
00000012
00000005
00000001

hide comments
Image smso: 2025-11-03 15:46:04

more tests:
7
1 4
4 5
1 2
1 4
2 4
1 5
1 3
7
2 3
4 5
1 5
1 2
3 4
1 3
2 3
7
3 4
3 5
2 4
2 3
1 3
3 5
1 2
7
4 5
4 5
2 4
1 5
1 3
3 5
2 3
7
3 4
1 5
3 4
4 5
4 5
1 4
2 5
7
2 3
3 4
1 2
3 5
3 4
1 2
4 5
7
2 3
1 2
1 4
2 3
4 5
1 2
3 4
7
3 4
4 5
3 5
4 5
2 3
3 4
2 4
7
3 4
2 3
1 5
3 5
1 2
1 4
1 2
7
1 2
2 4
4 5
3 5
1 2
2 4
3 4
-1

output:
00000014
00000028
00000021
00000015
00000013
00000041
00000037
00000022
00000019
00000026

Image joacru: 2025-05-09 17:08:02

Take mod 1e8. Even when output!!! I got some WAs because I was printing ans-1 instead of (ans-1+MOD)%MOD.

Image parasnagpal: 2021-07-18 01:28:34

A hint for the problem: https://youtu.be/8-mUDO9lclY

Image rushi2001: 2021-06-10 09:48:26

Thanks @vivek singh rana
For the testcase
test case-
6
1 2
2 3
3 4
1 8
4 5
5 6
-1
O/P - 00000032

Image anupam_akib: 2021-06-03 09:47:00

After 20 attempts, got AC! -_- facing problem with mod.

Image harshh3010: 2021-03-22 22:06:35

use setw(8) and setfill('0') for output in c++

Image lamda_cdm_10: 2020-09-20 05:22:38

remember to take mod of 10^8 ,costed me 3 WA for that

Image pacific_kafka: 2020-08-23 15:57:56

Dynamic Programming makes me feels sad

Image vakulsingh: 2020-07-30 13:41:23

just take mod 10^8 at every dp step,somehow did'not see that for a long time

Image jopdhiwaala: 2020-05-16 11:45:04

You could do to_string in c++ and output the characters.


Added by:Pablo Ariel Heiber
Date:2010-09-24
Time limit:2.365s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM64 NODEJS OBJC VB.NET
Resource:FCEyN UBA ICPC Selection 2010