Consider a pattern, in which 5 repeats 3 times & 4 repeats 1 time. $$5,5,5,4,5,5,5,4,5,5,5,4,...$$
Help me find terms count, when sum of the pattern is at least S.
For example,
if S=29, pattern would be $5+5+5+4+5+5=29$, terms count is 6.
if S=20, pattern would be $5+5+5+4+5=24$, terms count is 5.
Note that you have cycles of $$5+5+5+4$$ and may be a few extra terms.
We have $$5+5+5+4=19$$ so the first step is to divide your S by 19 and then fit the remainder into your cycle.
For example if you have $S=123$, then $123= 6(19)+9$ so you have 6 cycles and the remainder of 9 indicates that you can fit two $5$ into your string.
Therefore the length of your string is $6(4)+2 = 26$ and the string is $$5+5+5+4 + 5+5+5+4 +5+5+5+4+5+5+5+4+5+5+5+4+5+5+5+4+5+5$$