Hello everybody! The problem you see is an algorithmic problem I could not solve. :( This is ZIO $2010$, P$3$.
The first thing that I thought when I saw the problem was that - "Umm... this sounds easy, just go step by step" and I did try to go step by step on the first part.. BUT this problem is too long and the fact that there are a lot of functions this takes too long. Of course, if the problem could be solved manually one by one, why would this be on a high school competition? I somehow managed to calculate a few values and tried to find a pattern but no use. The real difficulty of this problem in my opinion is the fact that all functions depend on each other somehow (leave the function $f$) which should probably be cleverly used to find the solution, I guess. Moreover, $g(n)$ and $h(n)$ give values $\pmod{10}$. Would some sort of a recursive algorithm work? (Note that in this competition, you are given $30$ minutes to solve one problem or $10$ minutes to solve a sub-case. That's pretty low.)
The answers are $3,0,2$.
Any help would be appreciated. Thanks!