Hectic Harbour

아직 제출이 없습니다시간 제한3초메모리 제한512 MB

문제

There are two gantry cranes operating on the same gantry of length nn. The gantry has some fixed integral positions, labelled from 11 to nn, at which the cranes must perform loading/unloading operations. In the beginning the first gantry crane is located on the very left of the gantry at position 11, while the second one is located on the very right of the gantry at position nn. In each time step a gantry crane can either move to a neighbouring integral position or stay at its current position (and potentially perform a loading/unloading operation). To prevent the gantry cranes from hitting each other, the first crane needs to stay strictly to the left of the second crane at all times. For both cranes you are given a task list consisting of gantry positions at which the cranes must perform loading/unloading operations. Both cranes must perform their assigned operations in the given order. What is the minimal amount of time necessary for both gantry cranes to finish their tasks? It is guaranteed that the first gantry crane never has to operate at position nn of the gantry while the second gantry crane never has to operate at position 11. For both gantry cranes the first and last loading/unloading operation in the task list is their initial position.

입력

The input consists of:

  • One line with integers nn, aa and bb where
  • nn (2n2,0002 \le n \le 2\\,000) is the length of the gantry;
  • aa (2a502 \le a \le 50) is the number of operations in the task list of the first gantry crane;
  • bb (2b502 \le b \le 50) is the number of operations in the task list of the second gantry crane. 
  • One line with aa integers k_1,,k_ak\_1, \ldots, k\_a (1k_in11 \le k\_i \le n-1 for all ii), the tasks of the first gantry crane. 
  • One line with bb integers _1,,_b\ell\_1, \ldots, \ell\_b (2_in2 \le \ell\_i \le n for all ii), the tasks of the second gantry crane. 

The first and last task of both gantry cranes are at their initial position, i.e., k_1=k_a=1k\_1 = k\_a = 1 and _1=_b=n\ell\_1 = \ell\_b = n.

출력

Output the minimum number of time steps necessary for both gantry cranes to finish their assigned tasks.

힌트

In the first sample test case the gantry is of length 3, the first gantry crane has 2 operations in its task list while the second gantry crane has 4 operations in its task list. At least 6 time steps are necessary for both gantry cranes to finish their assigned tasks.

TimeGantry Crane 1Gantry Crane 2
1Operate at 1Operate at 3
2Operate at 1Operate at 3
3Idle at 1Move from 3 to 2
4Idle at 1Operate at 2
5Idle at 1Move from 2 to 3
6Idle at 1Operate at 3

In the second sample test case the gantry is of length 4 and both gantry cranes have to perform 4 operations. At least 9 time steps are necessary for both gantry cranes to finish their assigned tasks.

TimeGantry Crane 1Gantry Crane 2
1Operate at 1Operate at 4
2Move from 1 to 2Move from 4 to 3
3Operate at 2Operate at 3
4Move from 2 to 3Move from 3 to 4
5Operate at 3Idle at 4
6Move from 3 to 2Move from 4 to 3
7Move from 2 to 1& Operate at 3
8Operate at 1Move from 3 to 4
9Idle at 1Operate at 4