The International Committee for Programmable Clocks (ICPC) recently ran into an absolutely catastrophic disaster. A member from their rivalry
— Advanced Clock Machinery (ACM) broke into ICPC’s headquarters! The security guards were quick to act but still unable to take him down before he shot at ICPC’s most valuable assets — clocks, with his powerful railgun. As a consequence, the hour hands on these clocks are now pointing to incorrect positions. You are now hired to help them salvage the clocks by restoring them to their initial states, which is 12 o’clock.
To formalize this problem, initially ICPC has $n (n \leq 8)$ clocks laid sequentially on your table, with hour hands pointing to arbitrary positions from 1 to 12.
You are given a set of $m$ tools $(m \leq 4)$. With tool $i$ (denoted by $(l_i, x_i)$), you can first choose a segment of $l_i$ clocks, then rotate their hour hands. If $x_i$ is positive, then tool $i$ rotates the hour hands by $x_i$ clockwise. If $x_i$ is negative, then tool $i$ rotates the hour hands by -$x_i$ counter-clockwise. The cost of using any tool is 1, and you may use the same tool more than once. However, you may rearrange the order of the clocks without any cost.
So now you are wondering: What is the minimum cost require to restore all the clocks?