More elegant format
Haskell solution
C++ solution