cho.sh
Notes
Loading...

Counting Grid Triangles

Time limit

2s

Memory limit

128 MB

Problem

All integer lattice points with coordinates 0 ≤ x ≤ N and 0 ≤ y ≤ M are given. Choose three distinct points. They form a triangle only when the area is positive.

Count how many different triangles can be formed. When N=1 and M=2, the answer is 18.

Input

The first line contains two integers N and M.

Output

Print the number of possible triangles on the first line.

Constraints

  • 1 ≤ N, M ≤ 1,000