Isosceles Triangles

Time limit2sMemory limit128 MB

Summary
Count all isosceles triangles (non-collinear, at least two equal sides) formed by points in an N by M lattice grid, N and M up to 200.
Level

Hard8 of 10

Topics
Geometry, Combinatorics, Math, Implementation
Solved
No attempts yet

Problem

A triangle is isosceles if two of its side lengths are equal.

There are lattice points arranged in N rows and M columns. The three vertices of a triangle must be distinct lattice points, and three collinear points do not form a triangle.

Two triangles are different if at least one vertex position differs. Count how many different isosceles triangles can be formed from the given lattice points.

Input

The first line contains two positive integers N and M separated by a space. Both N and M are at most 200.

Output

Print the number of different isosceles triangles.

Hint

For a 2 by 3 grid of lattice points, the following 10 arrangements are possible.

XX. XX. .X. X.. X.X
X.. .X. XX. XX. .X.

.XX .XX ..X .X. .X.
.X. ..X .XX .XX X.X

Examples4

  1. Example 1

    Input
    2 3
    
    Expected output
    10
    
  2. Example 2

    Input
    1 10
    
    Expected output
    0
    
  3. Example 3

    Input
    2 2
    
    Expected output
    4
    
  4. Example 4

    Input
    5 4
    
    Expected output
    248