Virus Spread
Limits: 2 sec., 256 MiB
This statement was translated automatically from Ukrainian.
The city of Tuskavets looks like a square region of size \(n \times n\), where each cell is a house.
Zenyk knows that initially in his city there are exactly \(k\) houses with sick people. He also knows that a certain house can get sick only if this house has at least two neighboring houses with sick people. Houses are considered neighboring if they share a common side. Note that newly infected houses will also be able to infect other houses.
Unfortunately, Zenyk does not have complete information about all the sick people, so he does not know which specific houses are infected, but he is interested in how many houses with sick people there can be at the end.
Help Zenyk and find the maximum number of houses with sick people.
Input
The single line contains two integers \(n\) and \(k\) — the size of the square and the number of infected cells at the beginning, respectively.
Output
In a single line, print an integer — the maximum number of houses that have sick people.
Constraints
\(1 \le n \le 10^3\),
\(1 \le k \le n^2\),
for 40% of the tests, the additional constraint \(n \le k\) holds.
Samples
| Input (stdin) | Output (stdout) |
|---|---|
| 3 3 | 9 |
Notes
In the example, the answer is 9. The figure on the right shows 3
initially infected houses (red cells). Then all other houses will
gradually get sick in the following order by colors: orange, yellow,
green. Thus, all houses can be infected, so the answer is 9. Note that the answer cannot be greater than the number of houses in
the city.
Submit a solution
| Element Type | Created | Who | Problem | Compiler | Result | Time (sec.) | Memory (MiB) | # | Actions |
|---|
| Element Type | Created | Who | Problem | Compiler | Result | Time (sec.) | Memory (MiB) | # | Actions |
|---|