# Value of strings

I have a set of strings $$s_1,. . . , s_n$$ from small letters of total length S =$$\sum\limits_{i = 1}^n |s_i|$$ . Each line is associated with the value $$a_1,. . . , a_n$$. The $$value$$ of a string $$t$$ from small letters is called $$\sum\limits_{i = 1}^n cnt (s_i, t) · ai$$, where $$cnt (s_i, t)$$ is the number of occurrences of the string si in the string $$t$$ (occurrences can overlap). Using the number l, find the maximum possible cost of a string $$t$$ of length $$l$$. Asymptotics: $$O (S^3\log l).$$