#P1575J. Jeopardy of Dropped Balls
Jeopardy of Dropped Balls
Description
Mr. Chanek has a new game called Dropping Balls. Initially, Mr. Chanek has a grid of size
Each cell contains an integer denoting the direction of how the ball will move.
- — the ball will move to the right (the next cell is );
- — the ball will move to the bottom (the next cell is );
- — the ball will move to the left (the next cell is ).
Every time a ball leaves a cell , the integer will change to . Mr. Chanek will drop balls sequentially, each starting from the first row, and on the -th () columns.
Determine in which column each ball will end up in (position of the ball after leaving the grid).
The first line contains three integers , , and (, ) — the size of the grid and the number of balls dropped by Mr. Chanek.
The -th of the next lines contains integers (). It will satisfy and .
The next line contains integers () — the balls' column positions dropped by Mr. Chanek sequentially.
Output integers — the -th integer denoting the column where the -th ball will end.
Input
The first line contains three integers , , and (, ) — the size of the grid and the number of balls dropped by Mr. Chanek.
The -th of the next lines contains integers (). It will satisfy and .
The next line contains integers () — the balls' column positions dropped by Mr. Chanek sequentially.
Output
Output integers — the -th integer denoting the column where the -th ball will end.
Note
In the first example, the first ball will drop as follows. Note that the cell will change direction to the bottom direction.

The second and third balls will drop as follows.

All balls will be dropped from the first row and on the -th columns respectively. A ball will stop dropping once it leaves the grid.