CF BUDDY
← Problems·

1182E · Product Oriented Recurrence

2300 · dp, math, matrices

Problem: Let fx=c2x6fx1fx2fx3f_{x} = c^{2x-6} \cdot f_{x-1} \cdot f_{x-2} \cdot f_{x-3} for x4x \ge 4.

You have given integers nn, f1f_{1}, f2f_{2}, f3f_{3}, and cc. Find fnmod(109+7)f_{n} \bmod (10^{9}+7).

Input Format: The only line contains five integers nn, f1f_{1}, f2f_{2}, f3f_{3}, and cc (4n10184 \le n \le 10^{18}, 1f11 \le f_{1}, f2f_{2}, f3f_{3}, c109c \le 10^{9}).

Output Format: Print fnmod(109+7)f_{n} \bmod (10^{9} + 7).

Note: In the first example, f4=90f_{4} = 90, f5=72900f_{5} = 72900.

In the second example, f172.28×1029587f_{17} \approx 2.28 \times 10^{29587}.

Sample Cases

Case 1

Input

5 1 2 5 3

Output

72900

Case 2

Input

17 97 41 37 11

Output

317451037

Similar problems

00:00:00
Loading editor…
Welcome! I'm your coding tutor for this problem. Use the chips below to reveal stored hints or get AI feedback on your code. I'll guide you step by step — never giving away the solution.

Sign in to unlock AI tutor feedback