Protocol
Time limit2sMemory limit256 MB
Starting from one wire of capacity N, each year every wire splits into two wires transformed by two quadratic polynomials, and after M years we need the sum of 112345 raised to each wire's capacity, mod 1e9+9.
- Level
Hard8 of 10
- Topics
- Math, Divide and conquer, Combinatorics, Recursion
- Solved
- No attempts yet
Problem
Risha lives in the country of Meiji and built a communication system that runs over wires. In the protocol Risha wrote, every wire has a fixed capacity, and a wire of capacity carries characters.
Meiji uses 112345 different characters. A wire of capacity therefore sends one of messages, and the value of that wire is .
Meiji has many engineers besides Risha. Every year they take every wire in the country and cut it into two wires with the Banach-Tarski paradox. One wire of capacity becomes a wire of capacity and a wire of capacity . Start with a single wire of capacity . After one year there are two wires, with capacities and . After two years there are four wires, with capacities , , and . After years there are wires built the same way. Find the sum of the values of all wires after years.
Input
The first line contains and , separated by a space.
The second line contains , , , , , , separated by spaces.
All values satisfy .
Output
Print the sum of the values of all wires after years, modulo .
Hint
In the first example the total value of the wires is .