House in a low tree
King Julian decided to deal with the housing problems of his subordinates and build one large house for them inside a tree trunk.
This house will have n + 1 floors. Each floor will have 5 square rooms forming a cross. The floors are exactly one above the other. One lemur will live in each room.
Lemurs can easily move between adjacent rooms on the same floor. However, in order for them to go up or down one floor, stairs must be built. King Julian decided to build exactly m stairs in the house. Each staircase will connect two rooms that are on top of each other.
Julian wondered how exactly to arrange the stairs in the house. He decided that the location of the stairs would be optimal if there be a minimum sum over all distances between pairs of rooms. The distance between two rooms is the minimum number of steps you need to make to get from one room to another. In one move, you can go to the room next to the side on the same floor, or go up the stairs to the same room on the next floor, if there is such a staircase.
Help Julian find the total distance for the optimal ladder placement.
Input
Two integers n and m (1 ≤ n ≤ 10^6
, n ≤ m ≤ n * 5).
Output
Print one number - the total distance between all pairs of rooms with the optimal arrangement of stairs.