program main implicit none integer::N,L,i,time integer,allocatable::XWT(:,:) integer::X,W,T read *,N,L allocate(XWT(3,0:N)) read *, XWT(:,1:N) XWT(:,0) = 0 time = 0 do i=1,N W = XWT(2,i) T = XWT(3,i) time = time + XWT(1,i)-(XWT(1,i-1)+XWT(2,i-1)) if(MOD(time,2*T).ge.0.and. & MOD(time,2*T).le.T-W ) then time = time + W else time = time + 2*T-MOD(time,2*T) + W end if end do time = time + L - (XWT(1,N)+XWT(2,N)) print '(i0)',time end program main