P9585 "MXOI Round 2" Hotel

Description

Xiao C opened a hotel called CC Hotel. One day, $n$ guests came to CC Hotel. Xiao C needs to arrange all of them on a certain floor of the hotel. Each room can accommodate only one guest. There are $m$ rooms on this floor. All $m$ rooms are empty, and these $m$ rooms form a ring. That is, for every $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 when $x$ is divided by $m$. All $n$ guests are very picky: they want the rooms adjacent to their own room to be unoccupied. For a guest, if among the rooms adjacent to their room there are $k$ occupied rooms, then this guest will gain $k$ points of anger. You need to help Xiao C assign rooms so that the sum of all guests' anger values is minimized, and output the minimum possible sum of anger values of all guests.

Input Format

Two integers $n,m$.

Output Format

One integer, representing the minimum possible sum of all guests' anger values.

Explanation/Hint

#### Sample Explanation #1 For these $5$ rooms, one feasible arrangement is: empty, occupied, occupied, empty, occupied. It can be proven that the minimum possible sum of all guests' anger values is $2$. #### Constraints For $100\%$ of the testdata, $1 \le n \le 100$, $3 \le m \le 100$, and it is guaranteed that $n \le m$. |Test Point ID|Special Property| |:---:|:---:| |$1\sim3$|Guaranteed that $2n \le m$| |$4\sim6$|Guaranteed that $m = n + 1$| |$7\sim10$|None| Translated by ChatGPT 5