Kakashi is a student of CSE at DIU. In his OOP course, he needs to submit a project as the final lab task. So he decided to make a game as a project. After months of hard work finally he made a game. In his game, there was a scene where there were buildings of different heights in a row. He places robots and on top of the building, so the initial height of the two robots is the height of the building. Robots & had different characteristics than each other.
Robot can only move to the right buildings such that, height of the building is not lower than it’s previous landed building.
Robot can only move to the left buildings such that, height of the building is not higher than it’s previous landed building.
Both robots have to land on the maximum number of buildings they can.
Now, Kakashi wants to test this part of his game to ensure that the game is working well without any bugs before submitting it. So he wants your help to determine the landed buildings height for both Robots and including its starting position.
The first line contains two integers and — the number of the buildings and the starting position of the Robot and respectively.
The next line will contain the heights of the buildings
First line of the output will contain heights of the landed buildings of robot .
Second line of the output will contain heights of the landed buildings of robot .
Input | Output |
---|---|
7 4 1 4 3 2 1 6 7 | 2 6 7 2 1 |
Robot will start at building, then it will move to building but its characteristics does not allow to land there. So, will move to the building and can land there. It will continue its journey so on. likewise, Robot follows its characteristics to land on maximum number of buildings. |
Input | Output |
---|---|
11 5 2 13 23 16 18 21 37 33 12 34 42 | 18 21 37 42 18 16 13 2 |
Be careful about the newline (‘\n’) at the end.