I ran into the following problem when I did scientific research.

Consider an infinite sequence $\{a_{i}\}$ for $p>u>0$. $a_{1}=0$. If $a_{i}\geq p$, $a_{i+1}=a_{i}-p$; otherwise, $a_{i+1}=a_{i}+u$. What is the average of this sequence?

I did some numerical experimentation and felt that the general formula for the average seems very complicated: it is neither monotone nor continuous in $(p,u)$.