Differentiable solver for time-dependent deformation problems with contact