{"trustable":true,"prependHtml":"\u003cscript\u003e window.katexOptions \u003d { disable: true }; \u003c/script\u003e\n\u003cscript type\u003d\"text/x-mathjax-config\"\u003e\n MathJax.Hub.Config({\n tex2jax: {\n inlineMath: [[\u0027$$$\u0027,\u0027$$$\u0027], [\u0027$\u0027,\u0027$\u0027]],\n displayMath: [[\u0027$$$$$$\u0027,\u0027$$$$$$\u0027], [\u0027$$\u0027,\u0027$$\u0027]]\n }\n });\n\u003c/script\u003e\n\u003cscript async src\u003d\"https://mathjax.codeforces.org/MathJax.js?config\u003dTeX-AMS-MML_HTMLorMML\" type\u003d\"text/javascript\"\u003e\u003c/script\u003e","sections":[{"title":"","value":{"format":"HTML","content":"\u003cdiv class\u003d\"panel_content\"\u003eHere is a famous story in Chinese history.\u003cbr\u003e\u003cbr\u003e\"That was about 2300 years ago. General Tian Ji was a high official in the country Qi. He likes to play horse racing with the king and others.\"\u003cbr\u003e\u003cbr\u003e\"Both of Tian and the king have three horses in different classes, namely, regular, plus, and super. The rule is to have three rounds in a match; each of the horses must be used in one round. The winner of a single round takes two hundred silver dollars from the loser.\"\u003cbr\u003e\u003cbr\u003e\"Being the most powerful man in the country, the king has so nice horses that in each class his horse is better than Tian\u0027s. As a result, each time the king takes six hundred silver dollars from Tian.\"\u003cbr\u003e\u003cbr\u003e\"Tian Ji was not happy about that, until he met Sun Bin, one of the most famous generals in Chinese history. Using a little trick due to Sun, Tian Ji brought home two hundred silver dollars and such a grace in the next match.\"\u003cbr\u003e\u003cbr\u003e\"It was a rather simple trick. Using his regular class horse race against the super class from the king, they will certainly lose that round. But then his plus beat the king\u0027s regular, and his super beat the king\u0027s plus. What a simple trick. And how do you think of Tian Ji, the high ranked official in China?\"\u003cbr\u003e\u003cbr\u003e\u003cimg style\u003d\"max-width:100%;\" src\u003d\"CDN_BASE_URL/c4c9b604b2ccd9c212f3b05c47cda298?v\u003d1713645029\"\u003e\u003cbr\u003e\u003cbr\u003eWere Tian Ji lives in nowadays, he will certainly laugh at himself. Even more, were he sitting in the ACM contest right now, he may discover that the horse racing problem can be simply viewed as finding the maximum matching in a bipartite graph. Draw Tian\u0027s horses on one side, and the king\u0027s horses on the other. Whenever one of Tian\u0027s horses can beat one from the king, we draw an edge between them, meaning we wish to establish this pair. Then, the problem of winning as many rounds as possible is just to find the maximum matching in this graph. If there are ties, the problem becomes more complicated, he needs to assign weights 0, 1, or -1 to all the possible edges, and find a maximum weighted perfect matching...\u003cbr\u003e\u003cbr\u003eHowever, the horse racing problem is a very special case of bipartite matching. The graph is decided by the speed of the horses --- a vertex of higher speed always beat a vertex of lower speed. In this case, the weighted bipartite matching algorithm is a too advanced tool to deal with the problem.\u003cbr\u003e\u003cbr\u003eIn this problem, you are asked to write a program to solve this special case of matching problem.\u003cbr\u003e\u003c/div\u003e"}},{"title":"Input","value":{"format":"HTML","content":"The input consists of up to 50 test cases. Each case starts with a positive integer n (n \u0026lt;\u003d 1000) on the first line, which is the number of horses on each side. The next n integers on the second line are the speeds of Tian’s horses. Then the next n integers on the third line are the speeds of the king’s horses. The input ends with a line that has a single 0 after the last test case.\u003cbr\u003e"}},{"title":"Output","value":{"format":"HTML","content":"For each input case, output a line containing a single number, which is the maximum money Tian Ji will get, in silver dollars.\u003cbr\u003e"}},{"title":"Sample","value":{"format":"HTML","content":"\u003ctable class\u003d\u0027vjudge_sample\u0027\u003e\n\u003cthead\u003e\n \u003ctr\u003e\n \u003cth\u003eInput\u003c/th\u003e\n \u003cth\u003eOutput\u003c/th\u003e\n \u003c/tr\u003e\n\u003c/thead\u003e\n\u003ctbody\u003e\n \u003ctr\u003e\n \u003ctd\u003e\u003cpre\u003e3\r\n92 83 71\r\n95 87 74\r\n2\r\n20 20\r\n20 20\r\n2\r\n20 19\r\n22 18\r\n0\r\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e200\r\n0\r\n0\r\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n"}}]}