Editorial for CTU Open Contest 2018 - Numbers Generator
                Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.
Submitting an official solution before solving the problem yourself is a bannable offence.
        Submitting an official solution before solving the problem yourself is a bannable offence.
- Keep track of current state with Finite automaton.
 - We can use Aho-Corasick algorithm to achieve this.
 - We create matrix 
with probabilities of transitions.
 - We can achieve this by giving each edge in Aho-Corasick 
probability of traversal, and creating edges with probability
from all final states to one common final state.
 - Now find the expected number of steps before ending in absorbing state.
 - After solving 
, the answer can be found in
.
 - To solve this equation, we can use Gaussian Elimination.
 - Complexity 
 
Comments