Under construction

Still being built. Things may change

Max-Queen

Time limit2sMemory limit1024 MB

Summary
Place queens on an n by m board to maximize the number of attacking pairs, where a queen blocked by another queen does not attack past it.
Level

Medium5 of 10

Topics
Math, Implementation
Solved
No attempts yet

Problem

There is a chessboard with nn rows and mm columns. You want to place at least 11 queen on this board.

You can place at most 11 queen in each cell. In other words, each cell either holds one queen or holds no queen.

Two queens can attack each other when they are in the same row, the same column, or the same diagonal, and no queen stands between them. When queen AA and queen BB can attack each other, the ordered pair (A,B)(A,B) is called an attacking pair. The attacking pairs (A,B)(A,B) and (B,A)(B,A) are treated as the same.

For example, placing queens as shown below gives 44 distinct attacking pairs.

Write a program that finds the maximum possible number of distinct attacking pairs.

Input

The first line contains the number of rows nn and the number of columns mm, separated by a space. (2≤n,m≤1062 \le n,m \le 10^6)

Output

Print the answer to the problem on one line.

Hint

The answer can exceed the maximum value of a 32-bit integer. Use the following types to store the value.

  • C/C++: long long
  • Java: long
  • Python: int (no special handling is needed.)
  • Other languages: refer to the language reference.

Examples2

  1. Example 1

    Input
    3 4
    
    Expected output
    29
    
  2. Example 2

    Input
    314159 265358
    
    Expected output
    333456677139