Residence time densities for non-Markovian systems. (I). The two-state system