added Lin's R solution