Create Main.rb

The same logic implemented in the c language but the time limit is exceeding.