Under construction

Still being built. Things may change

Pony wants to play!

Time limit0.25sMemory limit1024 MB

Summary
Given today's weekday K and integers A, B, C, find the weekdays A^(B^C) and B^C/A days later, then count how many of them match the claimed weekday L.
Level

Medium4 of 10

Topics
Number theory, Math
Solved
No attempts yet

Problem

Twin and Pony are quizzing each other.

  • Pony: If today is Monday, what day is it 1212 days from now?
  • Twin: Saturday!
  • Pony: Then what about 343^{4} days later?
  • Twin: Um... Friday?
  • Pony: Then what day is it 6543216^{54^{321}} days later? What about 543216\frac{54^{321}}{6} days later?
  • Twin: Are you kidding me??

Annoyed by the joke, Twin walked home in the middle of the quiz. Before leaving, Twin heard the answers and now wants to know how Pony solved them so fast.

For Twin, write a program that takes today's weekday KK and finds the weekday ABCA^{B^{C}} days later and the weekday BCA\frac{B^{C}}{A} days later. It should also check whether Pony's answer LL is correct.

Weekdays are numbered as follows: Monday is 00, Tuesday is 11, Wednesday is 22, Thursday is 33, Friday is 44, Saturday is 55, and Sunday is 66.

Input

The first line contains integers AA, BB, and CC. (1≤A<71\leq A < 7, 1≤B,C≤1091\leq B, C \leq 10^{9}, BCB^C is a multiple of AA)

The second line contains integers KK and LL. (0≤K,L<70\leq K,L < 7)

Output

If today is weekday KK and both the date ABCA^{B^{C}} days later and the date BCA\frac{B^{C}}{A} days later fall on weekday LL, print 33. Otherwise, if only the date ABCA^{B^{C}} days later falls on weekday LL, print 11. If only the date BCA\frac{B^{C}}{A} days later falls on weekday LL, print 22. If neither date falls on weekday LL, print 00.

Examples2

  1. Example 1

    Input
    1 2 2
    5 2
    
    Expected output
    2
    
  2. Example 2

    Input
    5 1000000000 1000000000
    1 3
    
    Expected output
    1