#P7744. [COCI 2011/2012 #3] POGODAK

[COCI 2011/2012 #3] POGODAK

Description

On his desk, he found a cube, as shown in the picture.

On this cube, the sum of the numbers on two opposite faces is 77. This means that 66 is opposite 11, 55 is opposite 22, and 44 is opposite 33. Mirko places the cube at the top-left cell of an r×cr\times c matrix. Initially, the cube is oriented with 11 on the top face and 33 on the right face. Mirko then repeatedly performs the following actions in order:

  1. Roll the cube to the right until it reaches the last column.
  2. Roll it down to the next row.
  3. Roll the cube to the left until it reaches the first column.
  4. As in step 2, roll it down to the next row.

Mirko keeps repeating these steps until the cube can no longer be rolled. Each time the cube arrives at a cell, Mirko writes down the number on the top face in that cell. In the end, he adds up all the numbers he wrote. Mirko bet Slavko that he could calculate this sum without any mistakes. Help Slavko compute this sum to verify Mirko's answer.

Input Format

The input consists of a single line with two integers r,cr,c, representing the number of rows and columns of the matrix.

Output Format

Output a single line with one integer, the sum of all numbers filled in the final matrix.

3 2
19
3 4
42
737 296
763532

Hint

Sample 1 Explanation

For sample 11, the numbers filled in the final matrix are as follows:

11 44
11 55
33

Therefore, the final sum is 1+4+1+5+3+5=191+4+1+5+3+5=19.

Constraints

For 50%50\% of the testdata, r,c100r,c\leqslant 100.
For all testdata, 1r,c1051\leqslant r,c\leqslant 10^5.

Source

This problem is from COCI 2011-2012 CONTEST 3 T3 POGODAK, using the original testdata settings, worth 100100 points.

Translated and整理 (zhengli) provided by Eason_AC.

Translated by ChatGPT 5