Under construction

Still being built. Things may change

Oriental P.A.D.A.K

Time limit1sMemory limit512 MB

Summary
Given a grid where sauce spreads from K cells each second, find the minimum and maximum pieces dippers can eat when both groups race to eat.
Level

Medium7 of 10

Topics
BFS, Greedy, Sorting
Solved
No attempts yet

Problem

Oz Food, a restaurant company, developed the ultimate dish 'Oriental P.A.D.A.K' (hereafter Padak). Padak is chicken topped with crisp green onions, then doused with 'Oriental soy sauce' that has an East Asian flavor.

Seunghyeong and Seongjun, Oz Food's promotional ambassadors, invited their friends to taste Padak. Seunghyeong poured the 'Oriental soy sauce' as the Oz Food manual says, and this small act turned into a fight. Seongjun prefers to dip every dish in sauce, so he was horrified by Seunghyeong's move. The followers of Seongjun (nicknamed the dippers) all blamed Seunghyeong. In response, Seunghyeong's followers (nicknamed the pourers) all blamed Seongjun.

Seongjun shouted, 'If we wait, the sauce will spread further, so let's eat fast!' and urged the dippers to eat Padak quickly. Seunghyeong pushed the pourers to eat quickly too. The dippers pick up chicken pieces that have not touched the sauce and dip them before eating. The pourers pick up chicken pieces that have already touched the sauce and eat them. Every friend, including Seunghyeong and Seongjun, can eat at most one chicken piece per second, and whenever a piece is available, they always pick one up and eat it.

The 'Oriental P.A.D.A.K' is packed in a box shaped like a grid with NN rows and MM columns, and each cell holds one chicken piece. Seunghyeong has already poured sauce, so the KK chicken pieces are already soaked in sauce. Every second, the sauce spreads from each cell to its four neighbors (up, down, left, and right) and soaks the chicken pieces it reaches. Sauce in cells without chicken spreads in the same way. The sauce spreads after the friends have eaten their pieces. In time order, this means: friends eat chicken pieces, then the sauce spreads, then friends eat chicken pieces, and so on.

The pourers, including Seunghyeong, number BB in total, and the dippers, including Seongjun, number ZZ in total. Seongjun realized that the number of chicken pieces the dippers can eat depends on which pieces they pick. Help Seongjun by writing a program that finds the maximum and minimum number of chicken pieces the dippers can eat in total.

Input

The first line contains the number of rows NN of the Padak box, the number of columns MM, the number of cells where Seunghyeong poured sauce KK, the number of pourers BB, and the number of dippers ZZ. (1≤N,M≤1061 \le N, M \le 10^6, 1≤K≤NM≤1061 \le K \le NM \le 10^6, 1≤B,Z≤1061 \le B, Z \le 10^6)

From the second line onward, the next KK lines each contain a position RiR_i, CiC_i where Seunghyeong poured sauce. This means he poured sauce on the chicken piece that is RiR_i-th from the top and CiC_i-th from the left. (1≤Ri≤N1 \le R_i \le N, 1≤Ci≤M1 \le C_i \le M)

All KK positions where sauce was poured are distinct.

Output

Print, on the first line, the minimum and maximum total number of chicken pieces the dippers can eat.

Examples1

  1. Example 1

    Input
    3 4 3 2 3
    1 1
    2 4
    3 2
    
    Expected output
    3 4