PROGRAMMING:Pet Adoption Center
Fanfan opened a pet adoption center. There are two kinds of services: adopting pets abandoned by their owners and letting new owners adopt them. Every adopter hopes to adopt a pet that he is satisfied with. According to the requirements of the adopter, through a special formula invented by himself, he obtains the characteristic value a of the pet that the adopter wants to adopt (a is a positive integer, a < 2 ^ 31), and he also gives each pet in the adoption yard a characteristic value. In this way, he can easily handle the whole process of pet adoption. There are always two situations in pet adoption: too many abandoned pets or too many people who want to adopt pets, but too few pets.
When there are too many abandoned pets, if an adopter comes, and the adopter wants to adopt a pet with a characteristic value of a, he will adopt the pet with the characteristic value closest to a among the pets not adopted at present( If there are two pets that meet the requirements, that is, there are two pets whose characteristic values are A-B and a + B respectively, then the adopter will adopt the pet whose characteristic value is a-b.
There are too many people adopting pets. If an adopted pet comes, which adopter can adopt it? The adopter who can adopt the pet is the one who wants to adopt the pet with the characteristic value closest to the characteristic value of the pet. If the characteristic value of the pet is a, there are two adopters who want to adopt the pet with the characteristic values of A-B and a + B respectively, then the adopter with the characteristic value of A-B will successfully adopt the pet.
If an adopter adopts a pet with a characteristic value of a and wants to adopt a pet with a characteristic value of B, the dissatisfaction degree of the adopter is ABS (a-b).
You get the situation of adopters and adopted pets coming to the adoption center in one year. Please calculate the total dissatisfaction of all adopters who have adopted pets. At the beginning of the year, there were no pets or adopters.
###Input format:
The first line is a positive integer n, n < = 80000, which indicates the total number of pets and adopters who come to the adoption farm in a year. The next N lines describe the situation of the pets and adopters who come to the adoption center in a year according to the order of arrival time. Each line has two positive integers a and B, where a = 0 represents the pet, a = 1 represents the adopter, and B represents the characteristic value of the pet or the characteristic value that the adopter wants to adopt( The number of pets and adopters who stay in the adoption center at the same time is not more than 10000
###Output format:
There is only one positive integer, which represents the total dissatisfaction degree of all adopters who have adopted pets in one year, and the result after mod 1000000.
###Input example:
Here is a set of inputs. For example:
```in
five
0 2
0 4
1 3
1 2
1 5
```
###Output example:
The corresponding output is given here. For example:
```out
three
```
Note: ABS (3-2) + ABS (2-4) = 3,
The last adopter had no pets to adopt.
answer:If there is no answer, please comment
When there are too many abandoned pets, if an adopter comes, and the adopter wants to adopt a pet with a characteristic value of a, he will adopt the pet with the characteristic value closest to a among the pets not adopted at present( If there are two pets that meet the requirements, that is, there are two pets whose characteristic values are A-B and a + B respectively, then the adopter will adopt the pet whose characteristic value is a-b.
There are too many people adopting pets. If an adopted pet comes, which adopter can adopt it? The adopter who can adopt the pet is the one who wants to adopt the pet with the characteristic value closest to the characteristic value of the pet. If the characteristic value of the pet is a, there are two adopters who want to adopt the pet with the characteristic values of A-B and a + B respectively, then the adopter with the characteristic value of A-B will successfully adopt the pet.
If an adopter adopts a pet with a characteristic value of a and wants to adopt a pet with a characteristic value of B, the dissatisfaction degree of the adopter is ABS (a-b).
You get the situation of adopters and adopted pets coming to the adoption center in one year. Please calculate the total dissatisfaction of all adopters who have adopted pets. At the beginning of the year, there were no pets or adopters.
###Input format:
The first line is a positive integer n, n < = 80000, which indicates the total number of pets and adopters who come to the adoption farm in a year. The next N lines describe the situation of the pets and adopters who come to the adoption center in a year according to the order of arrival time. Each line has two positive integers a and B, where a = 0 represents the pet, a = 1 represents the adopter, and B represents the characteristic value of the pet or the characteristic value that the adopter wants to adopt( The number of pets and adopters who stay in the adoption center at the same time is not more than 10000
###Output format:
There is only one positive integer, which represents the total dissatisfaction degree of all adopters who have adopted pets in one year, and the result after mod 1000000.
###Input example:
Here is a set of inputs. For example:
```in
five
0 2
0 4
1 3
1 2
1 5
```
###Output example:
The corresponding output is given here. For example:
```out
three
```
Note: ABS (3-2) + ABS (2-4) = 3,
The last adopter had no pets to adopt.
answer:If there is no answer, please comment