Counting Grid Triangles

Time limit2sMemory limit128 MB

Summary
Count triangles with positive area formed by choosing three distinct lattice points from an (N+1) by (M+1) grid.
Level

Medium6 of 10

Topics
Combinatorics, Math, Number theory
Solved
No attempts yet

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

Examples1

  1. Example 1

    Input
    1 2
    
    Expected output
    18