Myth Busters

Time limit1sMemory limit128 MB

Summary
For each city's list of four-digit carriage IDs, decide whether every ID can reach the value 10 by permuting its digits and inserting +, -, *, / with parentheses.
Level

Medium7 of 10

Topics
Brute force, Recursion, Math, Implementation
Solved
No attempts yet

Problem

Every train carriage operated by CityRail of Sydney has a unique four-digit ID number. A common myth among local school pupils is that any ID number can be turned into the number 1010 by permuting its four digits, adding brackets, and combining them with the arithmetic operations in the set {+, -, *, /}.

Your task is to verify whether this myth actually holds, both for the carriages of CityRail of Sydney and for train carriages from other cities whose ID numbers were collected.

Note: here / denotes integer division. Most of you already know this, but as two examples, 5 / 2 is 2 and 2 / 5 is 0.

Input

The input consists of several test cases. Each test case is given as follows:

  • A line with a single integer NN (1<N<10001 < N < 1000), the number of IDs collected from one city.
  • NN lines follow, each containing one four-digit number.

A line containing only 0 marks the end of the input and must not be processed.

Output

For each test case, print the conclusion of your investigation on its own line as TRUE or BUSTED. Print TRUE if the myth holds for every carriage ID number of that city (that is, every one of them can be turned into 1010); otherwise print BUSTED.

Examples4

  1. Example 1

    Input
    2
    6666
    5555
    1
    1234
    0
    
    Expected output
    BUSTED
    TRUE
    
  2. Example 2

    Input
    1
    1234
    0
    
    Expected output
    TRUE
    
  3. Example 3

    Input
    1
    6666
    0
    
    Expected output
    BUSTED
    
  4. Example 4

    Input
    3
    1234
    5555
    9999
    0
    
    Expected output
    TRUE