#K86167. Minimum Page Turns

    ID: 36805 Type: Default 1000ms 256MiB

Minimum Page Turns

Minimum Page Turns

In this problem, you are given a book with ( n ) pages and a target page ( p ). Your task is to determine the minimum number of page turns required to reach page ( p ) when you can start turning pages from either the front or the back of the book.

When starting from the front, the number of page turns is given by ( \left\lfloor \frac{p}{2} \right\rfloor ). When starting from the back, the number of page turns depends on whether the total number of pages ( n ) is even or odd. Specifically, when ( n ) is even, the number of turns from the back is ( \left\lfloor \frac{n - p + 1}{2} \right\rfloor ) and when ( n ) is odd, it is ( \left\lfloor \frac{n - p}{2} \right\rfloor ). The answer is the minimum of these two values.

inputFormat

The input consists of a single line containing two integers ( n ) and ( p ) separated by a space, where ( n ) represents the total number of pages in the book and ( p ) represents the target page number.

outputFormat

Output a single integer, the minimum number of page turns needed to reach the target page.## sample

6 2
1

</p>