R script with the soultion