Problem 13: Narrowing it Down

Description

Some things you never know, Some things you've always known, and Some things you gradually find out about as life progresses. This is one of the latter cases.

You are to write a program that works out as much as it can about a number from a series of clues. It starts out with no information at all, but soon receives some clues. The clues are all of the form "The number is less than N" or "The number is more than N", where N is some integer.

For example, if the clues are "The number is less than 27", "The number is more than 19", "The number is more than 12", and "The number is less than 25", then the sum total of your knowledge is that the number is between 19 and 25.

Sometimes the clues you receive may be contradictory. For example, if you are told "The number is more than 98" and "The number is less than 3", then you know that the number can not exist.

The input to your program will be a sequence of integers. A strictly positive integer N (that is, 1 or more) means that the number you are seeking is more than N. A negative integer -N means that the number you are seeking is less than N. An input of zero means that there are no more clues, and it is time to print what you have deduced. You may be assured that the number you are seeking is somewhere between 1 and 1000000000 (one thousand million) inclusive.

Be sure that you understand what a negative input means. -16 means that the number you are seeking is less than 16, not that it is less than -16.

When it reaches the zero that marks the end of the input, your program must print out what it knows about the number, then terminate. If your program knows that the exact value of the number is X, it must print "The number is X". If it knows that the number lies somewhere between A and B inclusive, it must print "The number is between A and B". If it knows that the number does not exist, it must print "There is no such number".

Input Format

The input will be a list of integers terminated with a 0.

On input, numbers are exclusive: 7 means the number is more than (and not equal to) 7.

The negative sign means "less than", it does not signify a negative number: -7 means the number is less than 7.

Output Format

The output of the program should be one of the following:
      The number is A
      The number is between A and B
      There is no such number

in which A and B are replaced with the appropriate values, no leading zeros or extraneous spaces or punctuation.

On output, numbers are inclusive: "between 4 and 6" means that the number is either 4, 5, or 6.

Sample 1 Input

-27
19
12
-25
0

Sample 1 Output

The number is between 20 and 24

Sample 2 Input

-23
19
12
-25
21
0

Sample 2 Output

The number is 22

Sample 3 Input

-23
19
24
-25
21
0

Sample 3 Output

There is no such number

Limits

All inputs will be between -2000000000 and +2000000000 (two thousand million) inclusive.
The number sought will be between 1 and 1000000000 (one thousand million) inclusive.

End of Problem