Comments

By transition from S to F we get rid of the unnecessary constant (1) in the recurrence relation for S.

gets/std::gets function was removed from the standard library in C++11 (the stdio.h/cstdio headers). There is a gets_s function now. Also a new function with the former (std::get) name was introduced in C++11. Its purpose is to get an element of a std::pair (the utility header) or a std::tuple (the tuple header) with a given index (C++11) or of a given type (C++14). It also may be used to get an element of a std::array (the array header).

H. Bots. It can be simply shown that the number of possible solutions is equal to . So it is needed to find

.