QOJ.ac

QOJ

時間限制: 1 s 記憶體限制: 512 MB 總分: 100

#16547. Hotel

统计

Xiao C opened a hotel called CC Hotel.

One day, $n$ guests arrived at CC Hotel. Xiao C needs to accommodate all of them on a single floor of the hotel. Each room can accommodate only one guest.

There are $m$ rooms on this floor, all of which are currently empty. These $m$ rooms are arranged in a circle, meaning that for all $1 \le x \le m$, room $x$ is adjacent to room $((x \bmod m)+1)$, and room $((x \bmod m)+1)$ is adjacent to room $x$, where $x \bmod m$ denotes the remainder of $x$ divided by $m$.

The $n$ guests are very picky; they wish for no one to be in the rooms adjacent to their own. For a given guest, if $k$ rooms adjacent to their room are occupied, this guest will generate $k$ points of anger.

You need to help Xiao C arrange the rooms to minimize the total sum of anger values of all guests, and output this minimum sum.

Input

Two integers $n, m$.

Output

A single integer representing the minimum total sum of anger values of all guests.

Examples

Input 1

3 5

Output 1

2

Note 1

For these $5$ rooms, one possible arrangement satisfying the conditions is: empty, occupied, occupied, empty, occupied.

It can be proven that the minimum total sum of anger values for all guests is $2$.

Input 2

1 4

Output 2

0

Constraints

For $100\%$ of the data, $1 \le n \le 100$, $3 \le m \le 100$, and it is guaranteed that $n \le m$.

Test Case ID Special Property
$1\sim3$ Guaranteed $2n \le m$
$4\sim6$ Guaranteed $m = n+1$
$7\sim10$ None

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.