#arc142e. [arc142_e]Pairing Wizards

[arc142_e]Pairing Wizards

Problem Statement

There are NN wizards, numbered 1,ldots,N1, \\ldots, N.
Wizard ii has a strength of aia_i and plans to defeat a monster with a strength of bib_i.

You can perform the following operation any number of times.

  • Increase the strength of any wizard of your choice by 11.

A pair of Wizard ii and Wizard jj (let us call this pair (i,j)(i, j)) is said to be good when at least one of the following conditions is satisfied.

  • Wizard ii has a strength of at least bib_i and Wizard jj has a strength of at least bjb_j.
  • Wizard ii has a strength of at least bjb_j and Wizard jj has a strength of at least bib_i.

Your objective is to make the pair (xi,yi)(x_i, y_i) good for every i=1,ldots,Mi=1, \\ldots, M.
Find the minimum number of operations needed to achieve it.

Constraints

  • 2leqNleq1002 \\leq N \\leq 100
  • 1leqai,bileq1001 \\leq a_i,b_i \\leq 100
  • 1leqMleqfracN(N1)21 \\leq M \\leq \\frac{N(N-1)}{2}
  • 1leqxiltyileqN1 \\leq x_i \\lt y_i \\leq N
  • (xi,yi)neq(xj,yj)(x_i,y_i) \\neq (x_j,y_j), if ineqji\\neq j.
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN a1a_1 b1b_1 vdots\\vdots aNa_N bNb_N MM x1x_1 y1y_1 vdots\\vdots xMx_M yMy_M

Output

Print the answer.


Sample Input 1

5
1 5
2 4
3 3
4 2
5 1
3
1 4
2 5
3 5

Sample Output 1

2

You can perform the operation once for Wizard 11 and once for Wizard 44 to achieve the objective with the fewest operations.


Sample Input 2

4
1 1
1 1
1 1
1 1
3
1 2
2 3
3 4

Sample Output 2

0

No operation is needed.


Sample Input 3

9
1 1
2 4
5 5
7 10
9 3
9 13
10 9
3 9
2 9
7
1 5
2 5
1 6
2 4
3 4
4 9
8 9

Sample Output 3

22