{"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\u003eThe television at the boy\u0027s home contains the channels from 1 to n inclusive. The father wanted to avoid his son to watch some channels in the Television. You are given k unique channels that are banned by the father. For example assume that the TV contains 25 channels and the father bans the channels 15, 17 and 18 and you are currently at channel 16. If you press the \u0027down\u0027 button in the remote,\u0026nbsp; you will move to channel 14 and if you press the \u0027up\u0027 button in the remote, you will move to channel 19. Also if you press up button from channel 25 you will move to channel 1 and if you press down button from channel 1 you will move to channel 25. There are 13 buttons in the remote as shown in the figure.\u003c/p\u003e\r\n\u003cp style\u003d\"text-align: center;\"\u003e\u003cimg src\u003d\"CDN_BASE_URL/efca2d6632c4448f2a375c80e46912bf?v\u003d1725591381\" alt\u003d\"\"\u003e\u003c/p\u003e\r\n\u003cp\u003e\u003cbr\u003eTo move to a channel you can press the digits of the channel or you can use Up/Down/Previous buttons. The previous button will take you to the immediately previous channel you watched. (The previous button does not take effect until you have moved to some other channel after the first one.)\u003c/p\u003e\r\n\u003cp\u003eThe remote control responds to delays. So you can take the button presses \"1\" and \"9\" either as a way to go to channel 1 and then to channel 9, or to channel 19 directly.\u003cbr\u003e\u003cbr\u003eYou are given the sequence of channels that the boy wanted to watch. Find the minimum number of remote button presses required by the boy. It\u0027s not necessary to watch the given channels consecutively, but it is necessary to watch them in the order specified. (In other words, the given sequence must be a subsequence of the optimal channel series the boy chooses to watch.)\u003c/p\u003e\r\n\u003cp\u003eTo watch the first channel in the sequence, you must press the digits of the channel.\u003c/p\u003e\r\n\u003cp\u003e\u003cbr\u003e\u003cstrong\u003eInput:\u003c/strong\u003e\u003c/p\u003e\r\n\u003cp\u003eThe first line consists of and integer t, the number of test cases. Each test case consists of 4 lines. The first line consists of 2 integers n and k, the number of channels in the remote and the number of channels blocked. The next line consists of k unique integers - the id of the blocked channels. The next line consists of an integer m the number of channels the boy wants to watch followed by a line with m integers - the channel id\u0027s of the channels that the boy wants to watch.\u003c/p\u003e\r\n\u003cp\u003e\u003cstrong\u003eOutput:\u003c/strong\u003e\u003c/p\u003e\r\n\u003cp\u003eFor each test case print the minimum number of remote button clicks required.\u003cbr\u003e\u003cbr\u003e\u003cstrong\u003eInput Constraints:\u003c/strong\u003e\u003c/p\u003e\r\n\u003cp\u003e1 \u0026lt;\u003d t \u0026lt;\u003d 100\u003c/p\u003e\r\n\u003cp\u003e1 \u0026lt;\u003d n \u0026lt;\u003d 1000\u003c/p\u003e\r\n\u003cp\u003e0 \u0026lt;\u003d k \u0026lt;\u003d n-1\u003c/p\u003e\r\n\u003cp\u003e1 \u0026lt;\u003d m \u0026lt;\u003d 1000\u003c/p\u003e\r\n\u003cp\u003eChannelToWatch[i] !\u003d ChannelToWatch[i-1]\u003c/p\u003e\r\n\u003cp\u003eChannelToWatch[any] !\u003d BannedChannel[any]\u003c/p\u003e\r\n\u003cp\u003e\u003cbr\u003e\u003cstrong\u003eSample Input:\u003c/strong\u003e\u003c/p\u003e\r\n\u003cp\u003e3\u003c/p\u003e\r\n\u003cp\u003e5 0\u003c/p\u003e\r\n\u003cp\u003e\u0026nbsp;\u003c/p\u003e\r\n\u003cp\u003e5\u003c/p\u003e\r\n\u003cp\u003e1 2 3 4 5\u003c/p\u003e\r\n\u003cp\u003e500 0\u003c/p\u003e\r\n\u003cp\u003e\u0026nbsp;\u003c/p\u003e\r\n\u003cp\u003e4\u003c/p\u003e\r\n\u003cp\u003e140 160 139 160\u003c/p\u003e\r\n\u003cp\u003e5 2\u003c/p\u003e\r\n\u003cp\u003e2 4\u003c/p\u003e\r\n\u003cp\u003e5\u003c/p\u003e\r\n\u003cp\u003e1 3 5 3 5\u003cbr\u003e\u003cbr\u003e\u003cstrong\u003eSample Output:\u003c/strong\u003e\u003c/p\u003e\r\n\u003cp\u003eCase #1: 5\u003c/p\u003e\r\n\u003cp\u003eCase #2: 9\u003c/p\u003e\r\n\u003cp\u003eCase #3: 5\u003c/p\u003e\r\n\u003cp\u003e\u0026nbsp;\u003c/p\u003e\r\n\u003cp\u003e\u003cstrong\u003eNote:\u003c/strong\u003e Suppose you are currently at channel 6 and press up button twice you will move to channel 8. Now if you click on previous button, you will move to channel 7 and not channel 6.\u003cbr\u003e\u003cbr\u003e\u003cstrong\u003eExplanation of Case #2\u003c/strong\u003e:\u003cbr\u003e\u003cbr\u003eThe moves are \"1\", \"4\", \"0\", \"down\", \"1\", \"6\", \"0\", \"previous\", \"previous\"\u003c/p\u003e\r\n\u003cp\u003e\u0026nbsp;\u003c/p\u003e\r\n\u003cp\u003eCongrats and thanks to \u003cstrong\u003e\u003ca style\u003d\"text-decoration: none; color: #0000a0;\" href\u003d\"https://www.spoj.com/users/cyclops\"\u003eMitch Schwartz\u003c/a\u003e\u0026nbsp;\u003c/strong\u003efor solving this problem first and for helping on setting test cases for this problem.\u003c/p\u003e\n\u003c/div\u003e"}}]}