Curious Jury
시간 제한3초메모리 제한1024 MB
각 팀이 벌점으로 s 또는 l을 고르며, 2^n가지 선택 전체에서 순위가 벌점과 같은 팀 수의 합을 구한다.
문제
There are multiple ways to break ties based on submit time in competitive programming contests. In particular, the time penalty can either be the sum of all the times that you submit a correct solution (like in this contest!), or it can be the time that the last accepted submission of a team came in.
As a jury member of a prestigious team contest, you are really excited by "fixed points". These are places in the scoreboard where the rank of a particular team is equal to their penalty time. Because all teams solved all problems, the rank of a team is equal to the number of teams who had a strictly lower penalty time .
For each team, you know the sum of submit times of submissions , and a last submit time . The contest consists of more than one problem, so it must hold that for each team. Additionally, we assume that the sum of submit times does not exceed the number of teams.
For example, say the penalty times for teams A, B, and C are minute, minutes, and minute, respectively. Teams A and C both share rank , because no other teams have a strictly lower penalty time. They both also have penalty time , so they both form a fixed point on the scoreboard. There are two other teams which have a strictly lower penalty time than team B, so team B has rank , and its penalty time is , so it does not constitute a fixed point. In this example, there are fixed points.
For each team, you decide to arbitrarily pick between the two ways of calculating the penalty time, to make fixed points.
For a given way of picking the sum or last submit time for each team, define as the number of fixed points the scoreboard has.
Find the sum of over all ways of choosing penalty times.
입력
The input consists of:
- One line with an integer (), the number of participating teams.
- lines with two integers and (), the last submit time and the sum of submit times for a team.
출력
Output the sum of , the number of fixed points, over all ways of choosing penalty times.
Because the answer can be huge, output the answer modulo the prime .