{"problem":{"name":"Pairing Wizards","description":{"content":"There are $N$ wizards, numbered $1, \\ldots, N$.   Wizard $i$ has a strength of $a_i$ and plans to defeat a monster with a strength of $b_i$. You can perform the following operation any number of times","description_type":"Markdown"},"platform":"AtCoder","limit":{"time_limit":2000,"memory_limit":262144},"difficulty":"None","is_remote":true,"is_sync":true,"sync_url":null,"sign":"arc142_e"},"statements":[{"statement_type":"Markdown","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.\n\n## Constraints\n\n*   $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.\n\n## Input\n\nInput 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$\n\n[samples]","is_translate":false,"language":"English"}],"meta":{"iden":"arc142_e","tags":[],"sample_group":[["5\n1 5\n2 4\n3 3\n4 2\n5 1\n3\n1 4\n2 5\n3 5","2\n\nYou can perform the operation once for Wizard $1$ and once for Wizard $4$ to achieve the objective with the fewest operations."],["4\n1 1\n1 1\n1 1\n1 1\n3\n1 2\n2 3\n3 4","0\n\nNo operation is needed."],["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","22"]],"created_at":"2026-03-03 11:01:14"}}