I.2 Solution in R