My solution to avoid repeated inputs.