CF915B.Browser

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Luba is surfing the Internet. She currently has nn opened tabs in her browser, indexed from 11 to nn from left to right. The mouse cursor is currently located at the pospos -th tab. Luba needs to use the tabs with indices from ll to rr (inclusive) for her studies, and she wants to close all the tabs that don't belong to this segment as fast as possible.

Each second Luba can either try moving the cursor to the left or to the right (if the cursor is currently at the tab ii , then she can move it to the tab max(i1,a)max(i-1,a) or to the tab min(i+1,b)min(i+1,b) ) or try closing all the tabs to the left or to the right of the cursor (if the cursor is currently at the tab ii , she can close all the tabs with indices from segment [a,i1][a,i-1] or from segment [i+1,b][i+1,b] ). In the aforementioned expressions aa and bb denote the minimum and maximum index of an unclosed tab, respectively. For example, if there were 77 tabs initially and tabs 11 , 22 and 77 are closed, then a=3a=3 , b=6b=6 .

What is the minimum number of seconds Luba has to spend in order to leave only the tabs with initial indices from ll to rr inclusive opened?

输入格式

The only line of input contains four integer numbers nn , pospos , ll , rr ( 1<=n<=1001<=n<=100 , 1<=pos<=n1<=pos<=n , 1<=l<=r<=n1<=l<=r<=n ) — the number of the tabs, the cursor position and the segment which Luba needs to leave opened.

输出格式

Print one integer equal to the minimum number of seconds required to close all the tabs outside the segment [l,r][l,r] .

输入输出样例

  • 输入#1

    6 3 2 4
    

    输出#1

    5
    
  • 输入#2

    6 3 1 3
    

    输出#2

    1
    
  • 输入#3

    5 2 1 5
    

    输出#3

    0
    

说明/提示

In the first test Luba can do the following operations: shift the mouse cursor to the tab 22 , close all the tabs to the left of it, shift the mouse cursor to the tab 33 , then to the tab 44 , and then close all the tabs to the right of it.

In the second test she only needs to close all the tabs to the right of the current position of the cursor.

In the third test Luba doesn't need to do anything.

首页