problem 1510 (accepted)
problem 1510 on scala