The End of the World

(Easy Problem No# 2)


A solution for this problem can be found here.

A prophet has been told that the end of the world is possibly going to be some time in the period 01994 to 99999 inclusive. She has been given different hints as to when it might occur from her spiritual sources, and these are of the form: ``The tens digit is three times the hundreds digit plus six''.

The prophet has translated these into the form: ``d = 3c + 6;'' where e is 10000s, d is 1000s, c is 100s, b is 10s and a is units of years.

Write a program to input a set of hints of the form: statement: k<v>, <v> or k, where <v> is a variable (a, b, c, d, or e), and K is a constant in the range 0 to 9. Hint:

  • <v> = statement +/- statement, or
  • <v> = statement.
  • Each line in the input file contains a seperate set of hints. There is at most five hints in each set. For each set, print out the first date after 1993 that does not contradict the hints, or ``We are saved!'' if no date before 100000 poses any contradictions. All calculations are done modulus 10. The input file is terminated by a line containing a # character.



    SAMPLE INPUT

    a=2;b=4;e=9+a;
    d=3;
    c=e+e;d=4;c=d+e;
    e=e+1;
    c=2d+4;e=4-2c;a=4d+5;d=3;b=a-e;
    #
    


    SAMPLE OUTPUT

    10042
    03000
    44800
    We are saved!
    43037
    


    ########################################################################## Competition Server comp@arcadia.cs.rmit.edu.au (via comp@cs.curtin.edu.au) Problems with server: contact Craig Dillon (cdillon@cs.curtin.edu.au) ##########################################################################