Practice on Toph

Participate in exhilarating programming contests, solve unique algorithm and data structure challenges and be a part of an awesome community.

Paper Folding

Limits 1s, 512 MB

Tonmoy has a paper of length L mm and height of H mm. For any of his purpose he wants to fold it. But he folds the paper according to following conditions:

  1. Q times he will fold the paper.

  2. Each time he folds the paper from a specific position of length.

  3. He folds the paper only from left to right.

After completing his folding, Tonmoy asks you to say the H’ height of P mm of length and L’ remaining length after completing folding. As you are a programmer, can’t you write a programme to say the height of that specific length.

[N.B: You can assume that no part of the paper won’t be wasted by folding.]

Input

L H

Q

Q1

Q2

.

.

.

Qn

P

Constraints

1<=L<=106

0<=Q<=104

0<=Qn<=L&L’

1<=P<=L’

Output

Only print H’ and remaining length L’ after completing folding separated by a single space.

Samples

InputOutput
10 1
4
5
4
3
2
1
6 2
InputOutput
11 11
11
11
10
9
8
7
6
5
4
3
2
1
1
121 1

Problem Setter: Md. Masud Mazumder


    Discussion
    Statistics

    38% Solution Ratio

    nishat19Earliest, 3M ago

    nishat19Fastest, 0.0s

    CoderMLightest, 12 MB

    subhashis_cseShortest, 470B

    Submit

    Login to submit