11. Two-Wheelers and Four-Wheelers

Difficulty: easy · Math

Problem

An automobile company manufactures two-wheelers (TW) and four-wheelers (FW). The manager knows only two numbers: - `V`, the total number of vehicles to build (two-wheelers + four-wheelers), and - `W`, the total number of wheels needed for them. Find how many two-wheelers and how many four-wheelers must be manufactured. The input is **invalid** if any of the following holds: `W` is odd, `W < 2`, `V >= W`, or no split into a non-negative number of two-wheelers and four-wheelers uses exactly `W` wheels. In that case print `INVALID INPUT`.

Input

- Line 1: the integer `V`. - Line 2: the integer `W`.

Output

Print `TW=x FW=y` where `x` is the number of two-wheelers and `y` the number of four-wheelers (no spaces around `=`, one space between the two parts), or print `INVALID INPUT`.

Example 1

Input:
200
540
Output:
TW=130 FW=70

Explanation: 130 two-wheelers and 70 four-wheelers give 130+70 = 200 vehicles and 130*2 + 70*4 = 540 wheels.

Example 2

Input:
5
6
Output:
INVALID INPUT

Explanation: Even though W is even and V < W, 6 wheels cannot be shared by 5 vehicles (each needs at least 2), so the input is invalid.

Example 3

Input:
3
9
Output:
INVALID INPUT

Explanation: W is odd, so no combination of 2- and 4-wheeled vehicles can produce it.

Constraints

- 0 <= V <= 10^9 - 0 <= W <= 4 * 10^9

Solutions are judged against 3 sample and 12 hidden tests. Sign in to solve it · All problems