Solution on ruby.

Hash solution has better coefficients than tree solution.