Dynamics of dinuclear system formation and its decay in heavy ion collisions