{"raw_statement":[{"iden":"problem statement","content":"There are $N$ wizards, numbered $1, \\ldots, N$.  \nWizard $i$ has a strength of $a_i$ and plans to defeat a monster with a strength of $b_i$.\nYou can perform the following operation any number of times.\n\n*   Increase the strength of any wizard of your choice by $1$.\n\nA pair of Wizard $i$ and Wizard $j$ (let us call this pair $(i, j)$) is said to be **good** when at least one of the following conditions is satisfied.\n\n*   Wizard $i$ has a strength of at least $b_i$ and Wizard $j$ has a strength of at least $b_j$.\n*   Wizard $i$ has a strength of at least $b_j$ and Wizard $j$ has a strength of at least $b_i$.\n\nYour objective is to make the pair $(x_i, y_i)$ good for every $i=1, \\ldots, M$.  \nFind the minimum number of operations needed to achieve it."},{"iden":"constraints","content":"*   $2 \\leq N \\leq 100$\n*   $1 \\leq a_i,b_i \\leq 100$\n*   $1 \\leq M \\leq \\frac{N(N-1)}{2}$\n*   $1 \\leq x_i \\lt y_i \\leq N$\n*   $(x_i,y_i) \\neq (x_j,y_j)$, if $i\\neq j$.\n*   All values in input are integers."},{"iden":"input","content":"Input is given from Standard Input in the following format:\n\n$N$\n$a_1$ $b_1$\n$\\vdots$\n$a_N$ $b_N$\n$M$\n$x_1$ $y_1$\n$\\vdots$\n$x_M$ $y_M$"},{"iden":"sample input 1","content":"5\n1 5\n2 4\n3 3\n4 2\n5 1\n3\n1 4\n2 5\n3 5"},{"iden":"sample output 1","content":"2\n\nYou can perform the operation once for Wizard $1$ and once for Wizard $4$ to achieve the objective with the fewest operations."},{"iden":"sample input 2","content":"4\n1 1\n1 1\n1 1\n1 1\n3\n1 2\n2 3\n3 4"},{"iden":"sample output 2","content":"0\n\nNo operation is needed."},{"iden":"sample input 3","content":"9\n1 1\n2 4\n5 5\n7 10\n9 3\n9 13\n10 9\n3 9\n2 9\n7\n1 5\n2 5\n1 6\n2 4\n3 4\n4 9\n8 9"},{"iden":"sample output 3","content":"22"}],"translated_statement":null,"sample_group":[],"show_order":["default"],"formal_statement":null,"simple_statement":null,"has_page_source":true}