Follower of I 1
Time limit3sMemory limit256 MB
Sum, over every distinct ordering of the push, add, and multiply cards, the entries in the top K stack positions after evaluating the RPN process.
- Level
Medium5 of 10
- Topics
- Brute force, Stack, Math
- Solved
- No attempts yet
Problem
Hyeonjong has joined a group whose members treat the number as sacred. They call a good number, and every number that can be built from with addition and multiplication is a good number too. To make many good numbers, Hyeonjong plays the following game.
He needs two things.
- cards with drawn on both sides, cards with on them, and cards with on them.
- A stack that already holds infinitely many copies of .
Hyeonjong lays every card out in a single row, then reads the cards one at a time from the left and does the following.
- card: push onto the stack.
- card: pop the top two numbers off the stack and push their sum.
- card: pop the top two numbers off the stack and push their product.
The bottom of the stack holds infinitely many copies of , so the stack never runs out of numbers to pop.
Cards that show the same symbol are not told apart, so the number of different rows is .
For every different row, Hyeonjong finishes the whole procedure and reads the number that sits -th from the top of the stack. He wants the sum of those numbers over all rows, for . Help him.
Input
The first line contains five integers , , , , and , separated by spaces. is the number of cards, is the number of cards, is the number of cards, and is how many sums to compute.
, , , , , and .
Output
Print lines. On line , print the sum, over every different row of cards, of the number that sits -th from the top of the stack once the procedure ends. Print each sum modulo .