{"trustable":false,"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":"\u003cscript type\u003d\u0027text/x-mathjax-config\u0027\u003eMathJax.Hub.Config({tex2jax: { inlineMath: [[\u0027$\u0027,\u0027$\u0027]] } }); \u003c/script\u003e\n\u003cscript type\u003d\u0027text/javascript\u0027 src\u003d\u0027https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config\u003dTeX-AMS-MML_HTMLorMML\u0027\u003e\u003c/script\u003e\n\u003cscript type\u003d\u0027text/javascript\u0027\u003esetTimeout(function(){MathJax.Hub.Queue([\u0027Typeset\u0027, MathJax.Hub, \u0027left_view\u0027]);}, 2000);\u003c/script\u003e\n\u003cdiv class\u003d\"panel_content\"\u003e\n JGShining\u0027s kingdom consists of 2n(n is no more than 500,000) small cities which are located in two parallel lines. \n \u003cbr\u003e \n \u003cbr\u003eHalf of these cities are rich in resource (we call them rich cities) while the others are short of resource (we call them poor cities). Each poor city is short of exactly one kind of resource and also each rich city is rich in exactly one kind of resource. You may assume no two poor cities are short of one same kind of resource and no two rich cities are rich in one same kind of resource. \n \u003cbr\u003e \n \u003cbr\u003eWith the development of industry, poor cities wanna import resource from rich ones. The roads existed are so small that they\u0027re unable to ensure the heavy trucks, so new roads should be built. The poor cities strongly BS each other, so are the rich ones. Poor cities don\u0027t wanna build a road with other poor ones, and rich ones also can\u0027t abide sharing an end of road with other rich ones. Because of economic benefit, any rich city will be willing to export resource to any poor one. \n \u003cbr\u003e \n \u003cbr\u003eRich citis marked from 1 to n are located in Line I and poor ones marked from 1 to n are located in Line II. \n \u003cbr\u003e \n \u003cbr\u003eThe location of Rich City 1 is on the left of all other cities, Rich City 2 is on the left of all other cities excluding Rich City 1, Rich City 3 is on the right of Rich City 1 and Rich City 2 but on the left of all other cities ... And so as the poor ones. \n \u003cbr\u003e \n \u003cbr\u003eBut as you know, two crossed roads may cause a lot of traffic accident so JGShining has established a law to forbid constructing crossed roads. \n \u003cbr\u003e \n \u003cbr\u003eFor example, the roads in Figure I are forbidden. \n \u003cbr\u003e \n \u003cbr\u003e \n \u003ccenter\u003e \n \u003cimg style\u003d\"max-width:100%;\" SRC\u003d\"CDN_BASE_URL/1b6d9fcf6bd94b098baf0168f377fdc6?v\u003d1563011052\"\u003e \n \u003c/center\u003e \n \u003cbr\u003e \n \u003cbr\u003eIn order to build as many roads as possible, the young and handsome king of the kingdom - JGShining needs your help, please help him. ^_^ \n \u003cbr\u003e \n\u003c/div\u003e"}},{"title":"Input","value":{"format":"HTML","content":"Each test case will begin with a line containing an integer n(1 ≤ n ≤ 500,000). Then n lines follow. Each line contains two integers p and r which represents that Poor City p needs to import resources from Rich City r. Process to the end of file. \n\u003cbr\u003e"}},{"title":"Output","value":{"format":"HTML","content":"For each test case, output the result in the form of sample. \n\u003cbr\u003eYou should tell JGShining what\u0027s the maximal number of road(s) can be built. \n\u003cbr\u003e"}},{"title":"Sample Input","value":{"format":"HTML","content":"\u003cpre\u003e2\n1 2\n2 1\n3\n1 2\n2 3\n3 1\u003c/pre\u003e"}},{"title":"Sample Output","value":{"format":"HTML","content":"\u003cpre\u003eCase 1:\nMy king, at most 1 road can be built.\n\nCase 2:\nMy king, at most 2 roads can be built.\n\n\n \n \u003ci style\u003d\"font-size:1px\"\u003e \u003c/i\u003e\u003c/pre\u003e"}},{"title":"Hint","value":{"format":"HTML","content":"\u003cpre\u003e\nHuge input, scanf is recommended.\n\nLIS问题\n \n \u003c/pre\u003e"}}]}