Promotions

Given precedence rules and promotion counts A and B, count employees in every valid promotion set of each size and those in none of size B.

Medium7Topological sortGraphNo attempts yetTime limit2sMemory limit256 MB

Problem

The management of Fair Inc. decided to promote its best employees and capped the number of promotions to the interval [A,B][A, B]. The directors compared the employees' results, and their evaluation produced a consistent precedence relation among employees that every promotion round has to respect. For every pair of employees xx and yy, if xx outperformed yy, then yy may be promoted only if xx is promoted.

To learn whether the data collected so far is enough to guarantee fairness, the executive chairman asks two questions.

  • How many employees are certainly promoted at each endpoint of the interval, that is, when the number of promotions is AA and when it is BB?
  • How many employees have no possibility of being promoted, even when the number of promotions is BB?

Look at the example in the figure. There are seven employees and eight precedence rules. An arrow from employee xx to employee yy means that xx outperformed yy. The number of promotions is capped to the interval [3,4][3, 4].

  • With three promotions the promoted set is either Anne, Bob and Greg, or Anne, Eve and Greg. Two employees (Anne and Greg) are therefore certainly promoted. The current data does not say whether Bob and Eve get a promotion.
  • With four promotions the only promoted set is Anne, Bob, Eve and Greg. So four employees (Anne, Bob, Eve and Greg) are certainly promoted, and three employees (Cora, Dan and Fred) have no possibility of being promoted.

Write a program that, given the interval for the number of promotions, the set of employees and the precedence relation among them, computes the number of employees that are certainly promoted at each endpoint of the interval, and the number of employees that have no possibility of being promoted.

The precedence relation is consistent. If employee xx outperformed employee yy, then yy did not outperform xx, directly or indirectly.

Input

The first line has four space separated integers AA, BB, EE and PP. AA and BB are the endpoints of the interval, EE is the number of employees, and PP is the number of precedence rules. Employees are identified by the integers 00 to E1E - 1. Each of the next PP lines holds two distinct space separated integers xx and yy, meaning that employee xx outperformed employee yy.

Constraints

  • 1A<B<E1 \le A < B < E (interval endpoints)
  • 2E50002 \le E \le 5000 (number of employees)
  • 1P200001 \le P \le 20000 (number of precedence rules)

Output

Print three lines.

The first line holds the number of employees that are certainly promoted when the number of promotions is AA. The second line holds the number of employees that are certainly promoted when the number of promotions is BB. The third line holds the number of employees that have no possibility of being promoted, even when the number of promotions is BB.