Regularity of the minimum time function and minimum energy problems: the linear case.