Limits 1s, 512 MB

You all may hear about the USS (United States of Santosh). There is an office in the USS that consist of 10510^5 floors. The name of that office is USS-Economic Office.

Nafisa is an employee of the USS Economic Office. Her apartment is located on XthX^{th} floor and she needs to go to the YthY^{th} floor using the elevator. There's only one elevator in this office.

The initial position of the elevator is A1A_1. The elevator takes 1 unit of time to move from one floor to another (upward or downward). For example, it will take 3 unites of time to move from 3rd floor to 6th floor.

  • If AiA_i << Ai+1A_{i+1} then the elevator is moving upward.

  • if AiA_i >> Ai+1A_{i+1} then the elevator is moving downward.

  • While moving the elevator, it will open its door on each floor, and the time required for this is so small that we can omit it.

Someone has accidentally pressed nn buttons on the elevator (A1,A2,A3,,An)(A_1, A_2, A_3, … , A_n). Now the buttons have stopped working. So Nafisa cannot press any more buttons, she can not change the order either. So it will carry out the pressed sequence only. So the lift will move from floor A1A_1 to floor A2A_2, and then from floor A2A_2 to floor A3A_3 and so on.


  • If XthX^{th} floor lies between AiA_i and Ai+1A_{i+1}(inclusive) then It will take her from XthX^{th} floor.

  • If YthY^{th} floor lies between AiA_i and Ai+1A_{i+1}(inclusive) and Nafisa already in the elevator then it will leave her to the YthY^{th} floor.

  • You can assume it takes 0 units of time to get on and off the elevator.

You have to find out if it is possible to reach the YthY^{th} floor. If it is possible then what is the time required to reach the YthY^{th} floor?

NOTE: You can assume that the time starts when the elevator starts moving from the initial floor and Nafisa has been waiting on the XthX^{th} floor from the beginning of the time.


Input will contain nn (22 \leq nn \leq10410^4), which is the number of calls that someone accidentally pressed.

The next line will be a sequence of nn number of floors AiA_i, Ai+1A_{i+1}, Ai+2A_{i+2}….., AnA_{n} (11 \leq AiA_i \leq10510^5).

The next line will be XX and YY, where XX is Nafisa's floor and YY is the floor that she wants to reach.


If Nafisa can reach YthY^{th} floor from XthX^{th} floor then print YES and the time required to reach YthY^{th} floor.

Otherwise, print NO.


2 7 3 5 10
4 2

Here XX is 4 YY is 22. While moving from 2nd2^{nd} floor to 7th7^{th} floor Nafisa will get into the elevator but after that, the elevator does not reach YthY^{th}floor.

So the answer is NO.

5 12 3 7 4
4 3

Here XX is 44 and YY is 33. While moving the elevator from the 12th12^{th} floor to the 3rd3^{rd} floor Nafisa will get into the elevator and after that as soon as the elevator reaches to 3rd3^{rd} floor she will get off.

1 10
3 4
1 15
4 3


Login to submit.


76% Solution Ratio
ToooonmoyEarliest, Nov '22
HilariaFastest, 0.0s
MursaleenLightest, 5.7 MB
fahimcp495Shortest, 847B
Toph uses cookies. By continuing you agree to our Cookie Policy.