시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 128 MB3151018436.207%

문제

상근이는 숙제가 너무 하기 싫어서, 숙제 한 달치를 걸고 창영이와 게임을 하기로 했다. 진 사람은 한 달동안 숙제 두 명분을 해야 한다. 상근이는 영리하게 자신이 어렸을 때, 하던 게임을 하자고 했다. 창영이는 흔쾌히 수락했다.

이 게임을 하기 위해서는 주사위가 필요하다. 주사위는 왼쪽 그림과 같이 생겼다. 마주보는 면에 쓰여 있는 숫자의 합은 항상 7이다. 즉, 6은 1, 5는 2, 4는 3은 마주보는 면이다.

그 다음, 한 칸의 크기가 주사위의 한 면과 같은 표를 그린다. 이 표의 크기는 R행 C열이다. 주사위는 가장 처음에 왼쪽 위 칸에 있다. 윗 면에는 숫자 1이 있고, 오른쪽 면에는 숫자 3이 있다. 이제 다음과 같이 주사위를 굴린다.

1. 주사위를 마지막 열에 도착하기 전까지 오른쪽으로 굴린다.

2. 주사위를 아래줄로 한 칸 굴린다.

3. 주사위를 첫 번째 열에 도착하기 전까지 왼쪽으로 굴린다.

4. 2단계와 비슷하게 주사위를 한 칸 아래로 굴린다.

상근이는 위와 같은 단계를 할 수 있을 때 까지, 즉, 마지막 줄까지 반복한다. 주사위가 어떤 칸에 도착하면, 창영이는 주사위 윗 면의 숫자를 적는다. 마지막에, 지금까지 적은 숫자를 모두 더한 다음, 상근이에게 물어본다.

상근이는 정답을 말할 것이고, 이 숫자가 창영이가 더한 합과 같다면 상근이가 이긴다. 상근이는 잠시 머뭇거리다가 정답을 말했다. 이제 창영이는 이 정답이 맞는지 확인해야 한다. R과 C가 주어졌을 때, 윗 면의 합을 구하는 프로그램을 작성하시오.

입력

첫째 줄에 R과 C가 주어진다. (1 ≤ R, C ≤ 100,000)

출력

첫째 줄에 정답을 출력한다.

예제 입력 1

3 2

예제 출력 1

19
1 4
1 5
3 5

예제 입력 2

3 4

예제 출력 2

42

예제 입력 3

737 296

예제 출력 3

763532
W3sicHJvYmxlbV9pZCI6IjI4MTgiL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