Sleeping on the Train
시간 제한2초메모리 제한2048 MB
안토니오가 깨어난 구간 기록이 주어질 때, 정류장 a에서 b로 가는 동안 열차가 방향을 바꾼 최소 횟수를 구한다.
문제
Antonio is sightseeing in Line Town. Part of his sightseeing involves taking the famous Line Train. The Line Train goes through stops conveniently numbered from to . The path the Line Train takes involves starting at stop , then going to every stop in numerically increasing order until it reaches stop , at which point it turns around and goes to every stop in numerically decreasing order until it reaches stop , where it turns around and repeats its journey. When the train gets to either stop or stop , it lets all passengers that want to disembark leave the train. It then turns around, and then allows new passengers to board before heading to the next stop.
Antonio is traveling from stop to stop . Antonio is very sleepy, so he is not paying attention when he boards the train and could board a train initially heading in the wrong direction. Immediately upon boarding the train, he falls asleep and wakes up times during the trip. Each time he wakes up, he notices that he is somewhere between stop and . Since he is very sleepy, he does not know which direction the train is traveling in. Also, since he is not presently at his destination, he immediately falls back asleep.
After the time waking up, Antonio decides he should stay awake for the rest of the trip. He stays on the train until the next time it stops at stop , at which point he disembarks.
Compute the minimum number of times the train turned around while he was on it.
입력
The first line contains four integers, , , , and ().
The second line contains integers. The integer, , indicates that when Antonio woke up for the time, he was somewhere between stops and .
출력
Output the minimum number of times the train turned around while he was on it.