{"trustable":true,"prependHtml":"\u003cstyle type\u003d\"text/css\"\u003e\n #problem-body \u003e pre {\n display: block;\n padding: 9.5px;\n margin: 0 0 10px;\n font-size: 13px;\n line-height: 1.42857143;\n word-break: break-all;\n word-wrap: break-word;\n color: #333;\n background: rgba(255, 255, 255, 0.5);\n border: 1px solid #ccc;\n border-radius: 6px;\n }\n\u003c/style\u003e\n","sections":[{"title":"","value":{"format":"HTML","content":"\u003cdiv id\u003d\"problem-body\"\u003e\n\t\u003cp\u003e\r\n\tAgness, a student of computer science, is very keen on crossÂcountry \r\n\trunning, and she participates in races organised every Saturday in a big park. \r\n\tEach of the participants obtains a route card, which specifies a sequence of \r\n\tcheckpoints, which they need to visit in the given order. Agness is a very \r\n\tatractive girl, and a number of male runners have asked her for a date. She \r\n\twould like to choose one of them during the race. Thus she invited all her \r\n\tadmirers to the park on Saturday and let the race decide. The winner would be \r\n\tthe one, who scores the maximum number of points. Agnes came up with the \r\n\tfollowing rules:\r\n\u003c/p\u003e\r\n\u003cdiv align\u003d\"justify\"\u003e\r\n\t\u003cul\u003e\r\n\t\t\u003cli\u003e\r\n\t\ta runner scores one point if he meets Agnes at the checkpoint,\r\n\t\t\u003c/li\u003e\u003cli\u003e\r\n\t\tif a runner scored a point at the checkpoint, then he cannot get another point \r\n\t\tunless he and Agnes move to the next checkpoints specified in their cards.\r\n\t\t\u003c/li\u003e\u003cli\u003e\r\n\t\troute specified by the card may cross the same checkpoint more than once,\r\n\t\t\u003c/li\u003e\u003cli\u003e\r\n\t\t\teach competitor must strictly follow race instructions written on his card.\u003c/li\u003e\r\n\t\u003c/ul\u003e\r\n\u003c/div\u003e\r\n\u003cp\u003e\r\n\tBetween two consecutive meetings, the girl and the competitors may visit any \r\n\tnumber of checkpoints. The boys will be really doing their best, so you may \r\n\tassume, that each of them will be able to visit any number of checkpoints \r\n\twhilst Agnes runs between two consecutive ones on her route.\r\n\u003c/p\u003e\r\n\u003ch3\u003eTask\u003c/h3\u003e\r\n\u003cp\u003e\r\n\tWrite a program which for each data set from a sequence of several data sets:\r\n\u003c/p\u003e\r\n\u003cdiv align\u003d\"justify\"\u003e\r\n\t\u003cul\u003e\r\n\t\t\u003cli\u003e\r\n\t\treads in the contents of Agnes\u0027 race card and contents of race cards presented \r\n\t\tto Tom,\r\n\t\t\u003c/li\u003e\u003cli\u003e\r\n\t\tcomputes the greatest number of times Tom is able to meet Agnes during the \r\n\t\trace,\r\n\t\t\u003c/li\u003e\u003cli\u003e\r\n\t\t\twrites it to output.\u003c/li\u003e\r\n\t\u003c/ul\u003e\r\n\u003c/div\u003e\r\n\u003ch3\u003eInput\u003c/h3\u003e\r\n\u003cp\u003e\r\n\tThere is one integer d in the first line of the input file, 1 \u0026lt;\u003d d \u0026lt;\u003d 10. \r\n\tThis is the number of data sets. The data sets follow. Each data set consists \r\n\tof a number of lines, with the first one specifying the route in Agnes\u0027 race \r\n\tcard. Consecutive lines contain routes on cards presented to Tom. At least one \r\n\troute is presented to Tom. The route is given as a sequence of integers from \r\n\tinterval [1, 1000] separated by single spaces. Number 0 stands for the end of \r\n\tthe route, though when it is placed at the beginning of the line it means the \r\n\tend of data set. There are at least two and at most 2000 checkpoints in a race \r\n\tcard.\r\n\u003c/p\u003e\r\n\u003ch3\u003eOutput\u003c/h3\u003e\r\n\u003cp\u003e\r\n\tThe i-th line of the output file should contain one integer. That integer \r\n\tshould equal the greatest number of times Tom is able to meet with Agnes for \r\n\trace cards given in the i-th data set.\r\n\u003c/p\u003e\r\n\u003ch3\u003eExample\u003c/h3\u003e\r\n\u003cdiv\u003e\u003ctable class\u003d\"vjudge_sample\"\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\n1 2 3 4 5 6 7 8 9 0\r\n1 3 8 2 0\r\n2 5 7 8 9 0\r\n1 1 1 1 1 1 2 3 0\r\n1 3 1 3 5 7 8 9 3 4 0\r\n1 2 35 0\r\n0\r\n1 3 5 7 0\r\n3 7 5 1 0\r\n0\r\n1 2 1 1 0\r\n1 1 1 0\r\n0\r\n\r\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e6\r\n2\r\n3\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n\u003c/div\u003e\r\n\n\u003c/div\u003e"}}]}