Under construction

Still being built. Things may change

Memory

Interview

Time limit1sMemory limit256 MB

Summary
Given R times C face-down cards forming pairs, find the best-case and worst-case number of actions a perfect-memory player needs to clear the board.
Level

Medium6 of 10

Topics
Game theory, Math, Dynamic programming, Implementation
Solved
No attempts yet

Problem

Moraeduji carries R×CR \times C cards everywhere. In that deck, every pattern is drawn on exactly two cards. He carries them so that he can play a matching game when he is alone. The game runs like this.

  1. Shuffle the cards well, then lay them out face down in RR rows and CC columns so that no pattern is visible.

  2. Repeat the following action until no card is left.

    1. Pick one card, turn it over, and look at its pattern.
    2. Pick one more card among the rest, turn it over, and look at its pattern.
    3. If the two patterns are the same, remove both cards from the game. If they differ, put both back face down where they were.
  3. Win the game!

Moraeduji remembers the pattern and the position of every card he has ever turned over, and he plans his strategy so that the number of actions in the worst case is as small as possible. Under that strategy, find the number of actions when his luck is best and the number of actions when his luck is worst.

Input

The first line contains two integers RR and CC separated by a single space. (1≤R,C≤101 \le R, C \le 10, and R×CR \times C is even.)

Output

Print the minimum number of actions and the maximum number of actions needed to win the game on one line, separated by a space.

Hint

When R=2R = 2 and C=2C = 2 there are four cards and two pairs. If the first action turns over two cards with the same pattern, remove them, then remove the remaining two with the second action, so two actions finish the game. If the first action turns over two different patterns, the second action checks one card that has not been turned over yet and also turns over the card of the same pattern among the two seen in the first action, removing that pair, and the third action removes the last two cards. So the minimum is two and the maximum is three.

Examples2

  1. Example 1

    Input
    1 2
    
    Expected output
    1 1
    
  2. Example 2

    Input
    2 2
    
    Expected output
    2 3