#P9943. Year of the Ox

    ID: 23087 Type: Default 1000ms 256MiB

Year of the Ox

Year of the Ox

Farmer John's cows are excited about the celebration of the Year of the Ox. The Chinese zodiac follows a \(12\)-year cycle in the order: \(Ox, Tiger, Rabbit, Dragon, Snake, Horse, Goat, Monkey, Rooster, Dog, Pig, Rat\). Bessie, one of the cows, proudly claims she was born in an Ox year (year 0). Her friend Elsie would like to know the absolute difference in birth years between herself and Bessie. Using a list of relationships that indicate how some cows' birth years relate to one another, your task is to determine the number of years between Elsie and Bessie.

inputFormat

The input begins with an integer \(N\) (where \(N \ge 3\)), representing the number of relationship descriptions. Each of the following \(N\) lines contains a statement in the following format:

X born in [previous|next] Z year from Y

Here, X and Y are cow names, and Z is one of the zodiac animals: Ox, Tiger, Rabbit, Dragon, Snake, Horse, Goat, Monkey, Rooster, Dog, Pig, or Rat. Bessie’s birth year is defined to be 0.

outputFormat

Output a single integer: the absolute difference in years between Elsie and Bessie.

sample

4
Mildred born in previous Dragon year from Bessie
Gretta born in next Rat year from Mildred
Betsy born in previous Horse year from Gretta
Elsie born in next Goat year from Betsy
6

</p>