You on That Day
Time limit1sMemory limit512 MB
Given measured environmental factors and one-operation definitions, compute each factor's partial derivative of HAPPY and print it as a reduced fraction.
- Level
Medium6 of 10
- Topics
- Dynamic programming, DFS, Math, Recursion
- Solved
- No attempts yet
Problem
Human moods are hard to predict. Even in the same setting, reactions differ with personality and experience, and someone who cried all day may smile comfortably the next day.
Dr. Seojisu, who develops personalized AI systems, starts from one hypothesis.
"If we know the factors that shaped a person's happiness today and how those factors relate to each other, we can predict tomorrow's mood."
Factors that shape the mood fall into two kinds.
An environmental factor can be measured numerically through observation. The day's temperature, the number of friends met, and hours of sleep are examples.
A complex factor is determined by combining two different factors through one operation. For example, if study satisfaction equals the number of classes taken plus fatigue , it is written as . Happiness itself can be seen as one such complex factor.
Suppose we know today's measured values of all environmental factors and every relation between the factors. For each factor we want its influence on happiness, defined as the instantaneous rate of change of happiness with respect to that factor.
For example, let happiness be the product of income and work satisfaction , with today's measurements and . Then , the influence of is , the influence of is , and the influence of on itself is .
Given the kinds of factors and their relations, write a program that computes the influence of every factor.
Input
The first line gives , the number of factors. Each of the following lines describes one factor.
- An environmental factor is given as
{name} E {measured value}.
- The name is an uppercase alphabetic string of length at most 20.
- The measured value is an integer whose absolute value is at most 20.
- A complex factor is given as
{name} {operation} {operand 1} {operand 2}.
- The name is an uppercase alphabetic string of length at most 20, and happiness is always named .
- The two operands are two different names among the factors, listed in left-hand then right-hand order.
- The operation is one of (addition), (subtraction), (multiplication), and (division).
Every input satisfies the following.
- Each factor value and each influence is a rational number whose reduced form has a denominator of at most million and a numerator with absolute value at most billion.
- No complex factor takes itself as an operand, and no computation refers back to itself cyclically.
- No single factor appears as an operand in more than one complex factor.
Output
Print lines, one per factor, sorted by factor name in lexicographic order. Each line has the form {name} {influence}.
- Print each influence as a reduced fraction. If the influence of is , print
MONEY -1/4. - A factor that does not affect happiness at all has influence , printed as
0/1.
Hint
The second and third public test cases do not appear in the Small subtask.