{"trustable":false,"prependHtml":"\u003cstyle type\u003d\u0027text/css\u0027\u003e\n .input, .output {\n border: 1px solid #888888;\n }\n .output {\n margin-bottom: 1em;\n position: relative;\n top: -1px;\n }\n .output pre, .input pre {\n background-color: #EFEFEF;\n line-height: 1.25em;\n margin: 0;\n padding: 0.25em;\n }\n \u003c/style\u003e\n \u003clink rel\u003d\"stylesheet\" href\u003d\"//codeforces.org/s/96598/css/problem-statement.css\" type\u003d\"text/css\" /\u003e\n\u003cscript\u003e\n window.katexOptions \u003d {\n delimiters: [\n {left: \u0027$$$$$$\u0027, right: \u0027$$$$$$\u0027, display: true},\n {left: \u0027$$$\u0027, right: \u0027$$$\u0027, display: false},\n {left: \u0027$$\u0027, right: \u0027$$\u0027, display: true},\n {left: \u0027$\u0027, right: \u0027$\u0027, display: false}\n ]\n };\n\u003c/script\u003e\n","sections":[{"title":"","value":{"format":"HTML","content":"\u003cdiv\u003e\n \u003cp\u003eyxc and wwl love playing computer games. yxc has recently found a new game that greatly interested wwl. The game consists of \u003cspan class\u003d\"tex-span\"\u003e\u003ci\u003en\u003c/i\u003e\u003c/span\u003e parts and to complete each part a player may probably need to complete some other ones. We know that the game can be fully completed, that is, its parts do not form cyclic dependencies. \u003c/p\u003e\n \u003cp\u003ewwl has \u003cspan class\u003d\"tex-span\"\u003e3\u003c/span\u003e computers, on which he can play this game. All computers are located in different houses. Besides, it has turned out that each part of the game can be completed only on one of these computers. Let\u0027s number the computers with integers from \u003cspan class\u003d\"tex-span\"\u003e1\u003c/span\u003e to \u003cspan class\u003d\"tex-span\"\u003e3\u003c/span\u003e. wwl can perform the following actions: \u003c/p\u003e\n \u003cul\u003e \n \u003cli\u003e Complete some part of the game on some computer. wwl spends exactly \u003cspan class\u003d\"tex-span\"\u003e1\u003c/span\u003e hour on completing any part on any computer. \u003c/li\u003e\n \u003cli\u003e Move from the 1-st computer to the 2-nd one. wwl spends exactly \u003cspan class\u003d\"tex-span\"\u003e1\u003c/span\u003e hour on that. \u003c/li\u003e\n \u003cli\u003e Move from the 1-st computer to the 3-rd one. wwl spends exactly \u003cspan class\u003d\"tex-span\"\u003e2\u003c/span\u003e hours on that. \u003c/li\u003e\n \u003cli\u003e Move from the 2-nd computer to the 1-st one. wwl spends exactly \u003cspan class\u003d\"tex-span\"\u003e2\u003c/span\u003e hours on that. \u003c/li\u003e\n \u003cli\u003e Move from the 2-nd computer to the 3-rd one. wwl spends exactly \u003cspan class\u003d\"tex-span\"\u003e1\u003c/span\u003e hour on that. \u003c/li\u003e\n \u003cli\u003e Move from the 3-rd computer to the 1-st one. wwl spends exactly \u003cspan class\u003d\"tex-span\"\u003e1\u003c/span\u003e hour on that. \u003c/li\u003e\n \u003cli\u003e Move from the 3-rd computer to the 2-nd one. wwl spends exactly \u003cspan class\u003d\"tex-span\"\u003e2\u003c/span\u003e hours on that. \u003c/li\u003e\n \u003c/ul\u003e\n \u003cp\u003eHelp wwl to find the minimum number of hours he will need to complete all parts of the game. Initially wwl can be located at the computer he considers necessary. \u003c/p\u003e\n\u003c/div\u003e"}},{"title":"Input","value":{"format":"HTML","content":"\u003cdiv class\u003d\"input-specification\"\u003e\n \u003cdiv class\u003d\"section-title\"/div\u003e\n \u003cp\u003eThe first line contains integer \u003cspan class\u003d\"tex-span\"\u003e\u003ci\u003en\u003c/i\u003e\u003c/span\u003e \u003cspan class\u003d\"tex-span\"\u003e(1 ≤ \u003ci\u003en\u003c/i\u003e ≤ 200)\u003c/span\u003e — the number of game parts. The next line contains \u003cspan class\u003d\"tex-span\"\u003e\u003ci\u003en\u003c/i\u003e\u003c/span\u003e integers, the \u003cspan class\u003d\"tex-span\"\u003e\u003ci\u003ei\u003c/i\u003e\u003c/span\u003e-th integer — \u003cspan class\u003d\"tex-span\"\u003e\u003ci\u003ec\u003c/i\u003e\u003csub class\u003d\"lower-index\"\u003e\u003ci\u003ei\u003c/i\u003e\u003c/sub\u003e\u003c/span\u003e \u003cspan class\u003d\"tex-span\"\u003e(1 ≤ \u003ci\u003ec\u003c/i\u003e\u003csub class\u003d\"lower-index\"\u003e\u003ci\u003ei\u003c/i\u003e\u003c/sub\u003e ≤ 3)\u003c/span\u003e represents the number of the computer, on which you can complete the game part number \u003cspan class\u003d\"tex-span\"\u003e\u003ci\u003ei\u003c/i\u003e\u003c/span\u003e. \u003c/p\u003e\n \u003cp\u003eNext \u003cspan class\u003d\"tex-span\"\u003e\u003ci\u003en\u003c/i\u003e\u003c/span\u003e lines contain descriptions of game parts. The \u003cspan class\u003d\"tex-span\"\u003e\u003ci\u003ei\u003c/i\u003e\u003c/span\u003e-th line first contains integer \u003cspan class\u003d\"tex-span\"\u003e\u003ci\u003ek\u003c/i\u003e\u003csub class\u003d\"lower-index\"\u003e\u003ci\u003ei\u003c/i\u003e\u003c/sub\u003e\u003c/span\u003e \u003cspan class\u003d\"tex-span\"\u003e(0 ≤ \u003ci\u003ek\u003c/i\u003e\u003csub class\u003d\"lower-index\"\u003e\u003ci\u003ei\u003c/i\u003e\u003c/sub\u003e ≤ \u003ci\u003en\u003c/i\u003e - 1)\u003c/span\u003e, then \u003cspan class\u003d\"tex-span\"\u003e\u003ci\u003ek\u003c/i\u003e\u003csub class\u003d\"lower-index\"\u003e\u003ci\u003ei\u003c/i\u003e\u003c/sub\u003e\u003c/span\u003e distinct integers \u003cspan class\u003d\"tex-span\"\u003e\u003ci\u003ea\u003c/i\u003e\u003csub class\u003d\"lower-index\"\u003e\u003ci\u003ei\u003c/i\u003e, \u003ci\u003ej\u003c/i\u003e\u003c/sub\u003e\u003c/span\u003e \u003cspan class\u003d\"tex-span\"\u003e(1 ≤ \u003ci\u003ea\u003c/i\u003e\u003csub class\u003d\"lower-index\"\u003e\u003ci\u003ei\u003c/i\u003e, \u003ci\u003ej\u003c/i\u003e\u003c/sub\u003e ≤ \u003ci\u003en\u003c/i\u003e;\u0026nbsp;\u003ci\u003ea\u003c/i\u003e\u003csub class\u003d\"lower-index\"\u003e\u003ci\u003ei\u003c/i\u003e, \u003ci\u003ej\u003c/i\u003e\u003c/sub\u003e ≠ \u003ci\u003ei\u003c/i\u003e)\u003c/span\u003e — the numbers of parts to complete before part \u003cspan class\u003d\"tex-span\"\u003e\u003ci\u003ei\u003c/i\u003e\u003c/span\u003e.\u003c/p\u003e\n \u003cp\u003eNumbers on all lines are separated by single spaces. You can assume that the parts of the game are numbered from 1 to \u003cspan class\u003d\"tex-span\"\u003e\u003ci\u003en\u003c/i\u003e\u003c/span\u003e in some way. It is guaranteed that there are no cyclic dependencies between the parts of the game.\u003c/p\u003e\n\u003c/div\u003e"}},{"title":"Output","value":{"format":"HTML","content":"\u003cdiv class\u003d\"output-specification\"\u003e\n \u003cdiv class\u003d\"section-title\"/div\u003e\n \u003cp\u003eOn a single line print the answer to the problem.\u003c/p\u003e\n\u003c/div\u003e"}},{"title":"Example","value":{"format":"HTML","content":"\u003cstyle type\u003d\u0027text/css\u0027\u003e .input, .output {border: 1px solid #888888;} .output {margin-bottom:1em;position:relative;top:-1px;} .output pre,.input pre {background-color:#EFEFEF;line-height:1.25em;margin:0;padding:0.25em;} .title {background-color:#FFFFFF;border-bottom: 1px solid #888888;font-family:arial;font-weight:bold;padding:0.25em;} \u003c/style\u003e\u003cdiv class\u003d\"sample-tests\"\u003e\n \u003cdiv class\u003d\"section-title\"/div\u003e\n \u003cdiv class\u003d\"sample-test\"\u003e\n \u003cdiv class\u003d\"input\"\u003e\n \u003cdiv class\u003d\"title\"\u003e\n Input\n \u003c/div\u003e\n \u003cpre\u003e1\u003cbr\u003e1\u003cbr\u003e0\u003cbr\u003e\u003c/pre\u003e\n \u003c/div\u003e\n \u003cdiv class\u003d\"output\"\u003e\n \u003cdiv class\u003d\"title\"\u003e\n Output\n \u003c/div\u003e\n \u003cpre\u003e1\u003cbr\u003e\u003c/pre\u003e\n \u003c/div\u003e\n \u003cdiv class\u003d\"input\"\u003e\n \u003cdiv class\u003d\"title\"\u003e\n Input\n \u003c/div\u003e\n \u003cpre\u003e5\u003cbr\u003e2 2 1 1 3\u003cbr\u003e1 5\u003cbr\u003e2 5 1\u003cbr\u003e2 5 4\u003cbr\u003e1 5\u003cbr\u003e0\u003cbr\u003e\u003c/pre\u003e\n \u003c/div\u003e\n \u003cdiv class\u003d\"output\"\u003e\n \u003cdiv class\u003d\"title\"\u003e\n Output\n \u003c/div\u003e\n \u003cpre\u003e7\u003cbr\u003e\u003c/pre\u003e\n \u003c/div\u003e\n \u003c/div\u003e\n\u003c/div\u003e"}},{"title":"Note (You Will Win)","value":{"format":"HTML","content":"\u003cdiv class\u003d\"note\"\u003e\n \u003cdiv class\u003d\"section-title\"Note/div\u003e\n \u003cp\u003eNote to the second sample: before the beginning of the game the best strategy is to stand by the third computer. First we complete part 5. Then we go to the 1-st computer and complete parts 3 and 4. Then we go to the 2-nd computer and complete parts 1 and 2. In total we get 1+1+2+1+2, which equals 7 hours.\u003c/p\u003e\n\u003c/div\u003e"}}]}