Under construction

Still being built. Things may change

HŽ

Interview

Time limit1sMemory limit1024 MB

Summary
Count the tickets whose route crosses a closed section, the fewest sections to reopen so no ticket needs a bus, and the longest run of stations with no closure.
Level

Easy3 of 10

Topics
Intervals, Prefix sum
Solved
No attempts yet

Problem

A railway line has NN stations numbered from 1 to NN. For maintenance, KK sections of the track are closed. No trains run in either direction on a closed section, and passengers travel through those sections by bus. Each closed section is given by its start station and its end station.

Consider this situation. A passenger arrives at station XX and buys a ticket to station YY. If any part of the route between XX and YY is traveled by bus, the ticket must say so. There are MM such situations to study.

Answer the following questions:

  1. On how many of the MM tickets is it written that some or all of the route is traveled by bus?
  2. What is the minimum number of the KK sections that must be reopened so that none of the MM tickets has a bus warning?
  3. What is the length, in number of stations, of the longest stretch of the line that can be traveled only by train?

Input

The first line contains a natural number NN (1≤N≤10001 \le N \le 1000).

The second line contains a natural number KK (1≤K≤10001 \le K \le 1000).

Each of the next KK lines contains two natural numbers PiP_i and KiK_i (1≤Pi≤N1 \le P_i \le N, 1≤Ki≤N1 \le K_i \le N, Pi≠KiP_i \ne K_i), the start and end stations of the ii-th closed section. The closed sections do not overlap.

The next line contains a natural number MM (1≤M≤10001 \le M \le 1000).

Each of the next MM lines contains two natural numbers XiX_i and YiY_i (1≤Xi≤N1 \le X_i \le N, 1≤Yi≤N1 \le Y_i \le N, Xi≠YiX_i \ne Y_i), the stations for the ii-th situation.

Output

On the first line, print the answer to the first question.

On the second line, print the answer to the second question.

On the third line, print the answer to the third question.

Hint

In the first sample, the work on the section from station 8 to station 11 means that the first, second, and fourth passengers get a bus warning on their tickets. If that section were reopened, all passengers would travel by train only. The longest stretch with no work runs from station 11 to station 18 (or from station 1 to station 8), with a length of 8 stations.

Examples3

  1. Example 1

    Input
    20
    2
    18 20
    8 11
    5
    14 10
    8 11
    6 8
    8 18
    14 17
    
    Expected output
    3
    1
    8
    
  2. Example 2

    Input
    20
    3
    16 12
    8 2
    17 20
    2
    2 1
    9 4
    
    Expected output
    1
    1
    5
    
  3. Example 3

    Input
    12
    1
    4 8
    4
    6 8
    9 10
    6 8
    5 8
    
    Expected output
    3
    1
    5