{"trustable":true,"sections":[{"title":"","value":{"format":"HTML","content":"\u003cdiv class\u003d\"problem_par\"\u003e\u003cdiv class\u003d\"problem_par_normal\"\u003eOne of the stages of the Robot Cross-Country World Cup was held at the Uktus\r\nSki Lodge in Yekaterinburg.\r\n\r\n\u003c/div\u003e\u003c/div\u003e\u003cdiv class\u003d\"problem_par\"\u003e\u003cdiv class\u003d\"problem_par_normal\"\u003eProfessor Popov\u0027s laboratory sent its newest Robot NS6 to take part in the\r\nrace. The neural networks of this robot were well-trained in the classic style\r\nskiing. The robot was not very lucky with the drawing: he was one of the last\r\nracers to start and the trails had been already heaped up with the participants\r\nwho hadn\u0027t been able to make their way to the finish. This created a serious\r\nproblem, as the robot now had to keep switching between the ski trails in order\r\nto skirt the obstacles. As a result, it lost the precious time because moving\r\nto an adjacent trail each time took one second.\r\n\u003c/div\u003e\u003c/div\u003e\u003cdiv class\u003d\"problem_par\"\u003e\u003cdiv class\u003d\"problem_par_normal\"\u003eGiven the places where the fallen robots lie, determine the optimal way to\r\nskirt them all in the minimum time.\u003c/div\u003e\u003c/div\u003e\u003cdiv class\u003d\"problem_centered_picture\"\u003e\u003cimg src\u003d\"CDN_BASE_URL/56d8cd62ae697d3797ab7330fc8c6bcb?v\u003d1714979416\" border\u003d\"0\" alt\u003d\"Problem illustration\"\u003e\u003c/div\u003e"}},{"title":"Input","value":{"format":"HTML","content":"\u003cdiv class\u003d\"problem_par\"\u003e\u003cdiv class\u003d\"problem_par_normal\"\u003eThe first line contains integers \u003ci\u003en\u003c/i\u003e, \u003ci\u003es\u003c/i\u003e, and \u003ci\u003ek\u003c/i\u003e separated with a space (2 ≤ \u003ci\u003en\u003c/i\u003e ≤ 10\u003csup\u003e5\u003c/sup\u003e; 1 ≤ \u003ci\u003es\u003c/i\u003e ≤ \u003ci\u003en\u003c/i\u003e; \r\n0 ≤ \u003ci\u003ek\u003c/i\u003e ≤ 10\u003csup\u003e5\u003c/sup\u003e). There are \u003ci\u003en\u003c/i\u003e parallel\r\nski trails that lead from start to finish. They are numbered successively from\r\n1 to \u003ci\u003en\u003c/i\u003e. Robot NS6 starts along the trail with number \u003ci\u003es\u003c/i\u003e. The integer \u003ci\u003ek\u003c/i\u003e is the number of robots which fell down on the trails.\r\n\u003c/div\u003e\u003c/div\u003e\u003cdiv class\u003d\"problem_par\"\u003e\u003cdiv class\u003d\"problem_par_normal\"\u003eThe following \u003ci\u003ek\u003c/i\u003e lines describe the lying robots in the order from start to\r\nfinish. In each line there are integers \u003ci\u003el\u003c/i\u003e and \u003ci\u003er\u003c/i\u003e, which mean that a robot\r\nblocked the trails with numbers from \u003ci\u003el\u003c/i\u003e to \u003ci\u003er\u003c/i\u003e inclusive (1 ≤ \u003ci\u003el\u003c/i\u003e ≤ \u003ci\u003er\u003c/i\u003e ≤ \u003ci\u003en\u003c/i\u003e). You can assume that all the fallen robots lie at a sufficient distance\r\nfrom each other (and from the start) so that Robot NS6 can perform the\r\nnecessary maneuvers. If some robot blocks an outermost trail, it can be skirted\r\non one side only. No robot blocks all the trails simultaneously.\u003c/div\u003e\u003c/div\u003e"}},{"title":"Output","value":{"format":"HTML","content":"\u003cdiv class\u003d\"problem_par\"\u003e\u003cdiv class\u003d\"problem_par_normal\"\u003eOutput the minimum time in seconds that Robot NS6 spent for switching from\r\ntrail to trail in order to skirt all the fallen contestants and successfully\r\ncomplete the race.\r\n\u003c/div\u003e\u003c/div\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\u003e5 3 2\r\n2 5\r\n1 4\r\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e6\r\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n"}}]}