Under construction

Still being built. Things may change

Frankenstein and the Flasks

Time limit1sMemory limit1024 MB

Summary
Given the classes of two reagents (N, Z, Q, R) and an operation (+, -, *), find the smallest class that contains every possible result.
Level

Easy2 of 10

Topics
Implementation, Math
Solved
No attempts yet

Problem

Doctor Frankenstein decided to take up the most interesting pursuit on Earth: mixing flasks of reagents.

Each reagent is described by one real number, its coefficient. The coefficient determines the class of the reagent. There are four classes:

  1. N\mathbb{N}: the coefficient is a natural number, that is, a number that arises naturally when counting (for example, 11, 22, 33, 44, and so on).
  2. Z\mathbb{Z}: the coefficient is an integer. Integers include the natural numbers, their negatives, and 00 (for example, 55, −1-1, 00).
  3. Q\mathbb{Q}: the coefficient is a rational number, that is, a number that can be written as a fraction mn\frac{m}{n}, where mm and nn are integers (for example, 11, 2.72.7, 4.(3)4.(3)).
  4. R\mathbb{R}: the coefficient is a real number. Real numbers include both rational and irrational numbers (for example, π\pi, 2\sqrt{2}).

Each class contains the previous one, so every reagent is assigned the smallest class that contains it.

Two reagents can be mixed. The mixing produces one of three reactions: addition, subtraction, or multiplication. The new reagent has a coefficient equal to the sum, the difference, or the product of the two coefficients, respectively.

Frankenstein took two reagents and mixed them. Given the reaction and the classes of the two reagents, determine the class of the resulting reagent. Determine the class in the general case. For example, 2⋅2=2∈N\sqrt{2} \cdot \sqrt{2} = 2 \in \mathbb{N} is a special case, but in general the product of two real numbers is real, and not necessarily even rational.

Input

A single line contains three characters. The second character is +, -, or *. The other two are each one of N, Z, Q, or R.

The first character is the class of the first reagent, the second is the reaction (+ for addition, - for subtraction, * for multiplication), and the third is the class of the second reagent.

Output

Print a single character, N, Z, Q, or R: the class of the resulting reagent.

Examples1

  1. Example 1

    Input
    Q + Z
    
    Expected output
    Q