{"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\u003cb\u003eA genetic code\u003c/b\u003e of the abstract primitivus (\u003ci\u003ePrimitivus recurencis\u003c/i\u003e) is a series of natural numbers\r\n\u003ci\u003eK\u003d\u003c/i\u003e(\u003ci\u003ea_1 ... a_n\u003c/i\u003e). \u003cb\u003e A feature\u003c/b\u003e of primitivus we call each ordered pair of numbers\r\n(\u003ci\u003el\u003c/i\u003e, \u003ci\u003er\u003c/i\u003e), which appears successively in the genetic code, i.e. there exists such\r\n\u003ci\u003e i\u003c/i\u003e that\r\n\u003ci\u003e l\u003da_i, r\u003da_i+1\u003c/i\u003e. There are no (\u003ci\u003ep\u003c/i\u003e, \u003ci\u003ep\u003c/i\u003e) features in a primitivus\u0027 genetic\r\ncode.\u0026nbsp;\r\n\u003c/p\u003e\r\n\r\n\r\n\u003ch3\u003eTask\u003c/h3\u003e\r\n\u003cp\u003e\r\nWrite a program which:\u0026nbsp;\r\n\u003c/p\u003e\u003cul\u003e\r\n\u003cli\u003ereads the list of the features from the standard input,\r\n\u003c/li\u003e\u003cli\u003ecomputes the length of the shortest genetic code having given features,\r\n\u003c/li\u003e\u003cli\u003ewrites the results to the standard output.\u0026nbsp;\r\n\u003c/li\u003e\u003c/ul\u003e\r\n\r\n\u003ch3\u003eInput\u003c/h3\u003e\r\n\u003cp\u003e\r\nThe number of test cases t is in the first line of input, then t test cases follow separated by an empty line.\r\nIn the first line of each test case one positive integer number \u003ci\u003e n\u003c/i\u003e is written. It is the number of different features of the primitivus. In each\r\nof the following \u003ci\u003e n\u003c/i\u003e lines there is a pair of natural numbers\u003ci\u003e l\u003c/i\u003e and\u003ci\u003e r\u003c/i\u003e separated\r\nby a single space, \u003ci\u003e 1 \u0026lt;\u003d l \u0026lt;\u003d 1000, 1 \u0026lt;\u003d r \u0026lt;\u003d 1000\u003c/i\u003e. A pair (\u003ci\u003el\u003c/i\u003e,\r\n\u003ci\u003er\u003c/i\u003e) is one of the primitivus\u0027 features. The features do not repeat in the input file\r\n\u003c/p\u003e\r\n\r\n\u003ch3\u003eOutput\u003c/h3\u003e\r\n\u003cp\u003e\r\nYour program should write for each test case\r\nexactly one integer number equal to the length of the shortest\r\ngenetic code of the primitivus, comprising the features from the input.\r\n\u003c/p\u003e\r\n\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\u003e1\r\n12\r\n2 3\r\n3 9\r\n9 6\r\n8 5\r\n5 7\r\n7 6\r\n4 5\r\n5 1\r\n1 4\r\n4 2\r\n2 8\r\n8 6\r\n\r\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e15\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n\u003c/div\u003e\r\n\r\n\u003cp\u003eAll the features from the example are written in the following genetic code:\u003cbr\u003e\r\n(8, 5, 1, 4, 2, 3, 9, 6, 4, 5, 7, 6, 2, 8, 6)\u003c/p\u003e\r\n\r\n\u003cb\u003eWarning: enormous Input/Output data, be careful with certain languages\u003c/b\u003e\r\n\n\u003c/div\u003e"}}]}