{"trustable":true,"prependHtml":"\u003cscript\u003e\n window.katexOptions \u003d {\n delimiters: [\n {left: \u0027\\\\(\u0027, right: \u0027\\\\)\u0027, display: false},\n ]\n };\n\u003c/script\u003e\n","sections":[{"title":"","value":{"format":"HTML","content":"\u003cp\u003eHere is a famous story in Chinese history.\u003c/p\u003e\n\n\u003cp\u003e\"That was about 2300 years ago. General Tian Ji was a high official in the country Qi. He\nlikes to play horse racing with the king and others.\"\u003c/p\u003e\n\n\u003cp\u003e\"Both of Tian and the king have three horses in different classes, namely, regular, plus,\nand super. The rule is to have three rounds in a match; each of the horses must be used in\none round. The winner of a single round takes two hundred silver dollars from the loser.\"\u003c/p\u003e\n\n\u003cp\u003e\"Being the most powerful man in the country, the king has so nice horses that in each class\nhis horse is better than Tian\u0027s. As a result, each time the king takes six hundred silver\ndollars from Tian.\"\u003c/p\u003e\n\n\u003cp\u003e\"Tian Ji was not happy about that, until he met Sun Bin, one of the most famous generals\nin Chinese history. Using a little trick due to Sun, Tian Ji brought home two hundred\nsilver dollars and such a grace in the next match.\"\u003c/p\u003e\n\n\u003cp\u003e\"It was a rather simple trick. Using his regular class horse race against the super class from\nthe king, they will certainly lose that round. But then his plus beat the king\u0027s regular, and\nhis super beat the king\u0027s plus. What a simple trick. And how do you think of Tian Ji, the\nhigh ranked official in China?\"\u003c/p\u003e\n\n\u003ccenter\u003e\u003cimg src\u003d\"CDN_BASE_URL/578baa9defc688baf7e592140ffa4839?v\u003d1726284764\"\u003e\u003c/center\u003e\n\n\u003cp\u003eWere Tian Ji lives in nowadays, he will certainly laugh at himself. Even more, were he sitting in\nthe ACM contest right now, he may discover that the horse racing problem can be simply viewed\nas finding the maximum matching in a bipartite graph. Draw Tian\u0027s horses on one side, and the\nking\u0027s horses on the other. Whenever one of Tian\u0027s horses can beat one from the king, we draw an\nedge between them, meaning we wish to establish this pair. Then, the problem of winning as many\nrounds as possible is just to find the maximum matching in this graph. If there are ties, the\nproblem becomes more complicated, he needs to assign weights 0, 1, or -1 to all the possible\nedges, and find a maximum weighted perfect matching...\u003c/p\u003e\n\n\u003cp\u003eHowever, the horse racing problem is a very special case of bipartite matching. The graph is\ndecided by the speed of the horses --- a vertex of higher speed always beat a vertex of lower speed.\nIn this case, the weighted bipartite matching algorithm is a too advanced tool to deal with the\nproblem.\u003c/p\u003e\n\n\u003cp\u003eIn this problem, you are asked to write a program to solve this special case of matching problem.\u003c/p\u003e\n\n\u003cbr\u003e\n\u003cp\u003e\u003cb\u003eInput\u003c/b\u003e\u003c/p\u003e\n\u003cp\u003eThe input consists of up to 50 test cases. Each case starts with a positive integer n (n \u0026lt;\u003d 1000) on\nthe first line, which is the number of horses on each side. The next n integers on the second line\nare the speeds of Tians horses. Then the next n integers on the third line are the speeds of the\nkings horses. The input ends with a line that has a single 0 after the last test case.\u003c/p\u003e\n\n\u003cbr\u003e\n\u003cp\u003e\u003cb\u003eOutput\u003c/b\u003e\u003c/p\u003e\n\u003cp\u003eFor each input case, output a line containing a single number, which is the maximum money Tian\nJi will get, in silver dollars.\u003c/p\u003e\n\n\u003cbr\u003e\n\u003cp\u003e\u003cb\u003eSample Input\u003c/b\u003e\u003c/p\u003e\n\u003cp\u003e\n3\u003cbr\u003e\n92 83 71\u003cbr\u003e\n95 87 74\u003cbr\u003e\n2\u003cbr\u003e\n20 20\u003cbr\u003e\n20 20\u003cbr\u003e\n2\u003cbr\u003e\n20 19\u003cbr\u003e\n22 18\u003cbr\u003e\n0\u003cbr\u003e\n\u003c/p\u003e\n\n\u003cbr\u003e\n\u003cp\u003e\u003cb\u003eSample Output\u003c/b\u003e\u003c/p\u003e\n\u003cp\u003e\n200\u003cbr\u003e\n0\u003cbr\u003e\n0\u003cbr\u003e\n\u003c/p\u003e\n"}}]}