CF1047D Little C Loves 3 II

原题链接:http://codeforces.com/contest/1047/problem/D

Little C Loves 3 II

Little C loves number «3» very much. He loves all things about it.

Now he is playing a game on a chessboard of size n × m n×m n×m. The cell in the x x x-th row and in the y y y-th column is called ( x , y ) (x,y) (x,y). Initially, The chessboard is empty. Each time, he places two chessmen on two different empty cells, the Manhattan distance between which is exactly 3 3 3. The Manhattan distance between two cells ( x i , y i ) (x_i,y_i) (xi,yi) and ( x j , y j ) (x_j,y_j) (xj,yj) is defined as ∣ x i − x j ∣ + ∣ y i − y j ∣ |x_i−x_j|+|y_i−y_j| xixj+yiyj.

He want to place as many chessmen as possible on the chessboard. Please help him find the maximum number of chessmen he can place.

Input

A single line contains two integers n n n and m ( 1 ≤ n , m ≤ 1 0 9 ) m (1≤n,m≤10^9) m(1n,m109) — the number of rows and the number of columns of the chessboard.

Output

Print one integer — the maximum number of chessmen Little C can place.

Examples
input

2 2

output

0

input

3 3

output

8

Note

In the first example, the Manhattan distance between any two cells is smaller than 3 3 3, so the answer is 0 0 0.

In the second example, a possible solution is ( 1 , 1 ) ( 3 , 2 ) , ( 1 , 2 ) ( 3 , 3 ) , ( 2 , 1 ) ( 1 , 3 ) , ( 3 , 1 ) ( 2 , 3 ) (1,1)(3,2), (1,2)(3,3), (2,1)(1,3), (3,1)(2,3) (1,1)(3,2),(1,2)(3,3),(2,1)(1,3),(3,1)(2,3).

题解

这位老哥找规律实在是太强辣,甘拜下风 % % % \%\%\% %%%

代码
#include<bits/stdc++.h>
using namespace std;
int n,m,x[]={0,0,0,0,2,4};
void in(){scanf("%d%d",&n,&m);}
void ac()
{
	if(n>m)swap(n,m);
	if(n==1)printf("%d",m/6*6+x[m%6]);
	else if(n==2)
	{
		if(m==2)puts("0");
		else if(m==3)puts("4");
		else if(m==7)puts("12");
		else printf("%lld",1ll*n*m);
	}
	else printf("%lld",n%2&&m%2?1ll*n*m-1:1ll*n*m);
}
int main(){in();ac();}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

ShadyPi

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值