String theory#10639

String theory

1 second
128 megabytes
Very hard

One of the most popular and (in many physicists' opinion) promising is a string theory. It states, that the multiverse is made of different dimensions but the highest is -th dimension. Beyond dimensions, the universe would become unstable and dimensions higher than would collapse to an -dimensional universe. You are now faced with the challenge in modelling String theoretical problem.

Our system has strings numbered from to placed at the lines = for = , ..., on OTP Cartesian plane, where OT represent time frames and OS represent current string of the particle. Particles move only into the future and maybe jump between the strings expending the energy. Initially, particles only can stay in a rest without losing any energy, i.e. transition from state (, ) to ( + , ) costs energy, and no other transitions are given within our system (yet). Note, our system does not possess backward time travelling (or assume that cost of transition back in time is infinity). Your main aim will be to calculate the minimum amount of energy particle require to travel from string s_1 at the time frame t_1 to the string s_2 at the time frame t_2, or say that this impossible to happen.

We now describe the certain external forces that may appear: teleports and massive objects. When teleport appear at time frame with energies costs (a_1, ..., a_{n-1}), it allows any particle at the state (, ) to immediately jump to the state (, + ) with energy loss a_i or to the state (, - ) with energy loss a_{i-1} (whenever the string + or - exist). If we add massive object at time frame with energies (b_1, ..., b_n) it affect transition between time frames and + so that particle at string require to expend b_i energy to stay at the same string (otherwise particle just disappear in space-time). So there are type of requests you must fulfil:

- **1 t** a_1, ..., a_{n-1} - add teleport at time frame t with energies a_i; - **2 t** b_1, ..., b_n - add massive object at time frame with energies b_i; - **3** t_1 s_1 t_2 s_2 - we encountered a particle travelling between the states (t_1, s_1) (t_2, s_2), what is minimal possible amount of energy expended by this particle?

Note, that if you are told to add teleports / massive objects in the same time frame, then later one replaces earlier one.

Input

In the first line you are given two numbers and - number of strings in our system and number of requests (1 \le n \le 11, 1 \le q \le 10^4).

In the next lines on the -th line you are given the description of the queries in the format described in the statement with restrictions:

- 0 \le a_i, b_i \le 100 - energy costs; - 1 \le t \le 5 \cdot 10^4, 1 \le t_1 \le t_2 \le 5 \cdot 10^4 - time frames; - 1 \le s_1, s_2 \le n - string positions.

Output

For each query of the third type output single number - the answer for the query.

Examples

Example 1

Loading
Loading