P15833 [Lanqiao Cup 1st International Contest] Warehouse Layout
Description
Xiaoming manages a warehouse and wants to place some storage cabinets inside it. The cabinets are relatively tall, so they cannot be stacked vertically. Each cabinet has a square base, and one side is the front, used for picking up and placing goods.
Xiaoming divides the warehouse into an $n \times m$ grid, with $n$ cells in the north-south direction and $m$ cells in the east-west direction. Each cell may contain one cabinet or be used as an aisle. To keep the warehouse neat and organized, the fronts of Xiaoming’s cabinets all face either south or north. Specifically, counting rows from north to south: the first row of cabinets faces south, the second row is entirely an aisle, the third row of cabinets faces north, the fourth row of cabinets faces south, the fifth row is entirely an aisle, the sixth row of cabinets faces north, the seventh row of cabinets faces south, the eighth row is entirely an aisle, and so on. If row $n$ is a row of cabinets facing south, then because goods cannot be picked up or placed from these cabinets, this row of cabinets must be removed; in this case, row $n$ becomes an aisle.
Xiaoming not only has aisles in the east-west direction, but also aisles in the north-south direction. For every consecutive $5$ cells, he leaves one north-south aisle, that is, from west to east, columns $6$, $12$, $18$, ... are all aisles.
According to the above rules, when $n = 6$ and $m = 8$, the layout of the warehouse is as follows:
[Image Missing]
When $n = 4$ and $m = 8$, the layout of the warehouse is as follows. The dashed box shows the cabinets that are removed:
[Image Missing]
Given $n$ and $m$, determine how many cabinets can be placed in the warehouse according to Xiaoming’s placement rules (excluding the removed cabinets).
Input Format
One line contains two integers $n, m$.
Output Format
Output one integer, representing the number of cabinets that can be placed.
Explanation/Hint
### Constraints and Assumptions for Test Cases
For $30\%$ of the test cases, $1 \le n \le 100$, $6 \le m \le 100$.
For $70\%$ of the test cases, $1 \le n \le 10000$, $6 \le m \le 10000$.
For all test cases, $1 \le n \le 10^9$, $6 \le m \le 10^9$.
Translated by ChatGPT 5