Solution for DBC Challenge 306