Exercise B from the "Desafio de Programadores" help at SECOMP 2014 in UFSCar. This exercise is part of a task from the class "Projeto e Análise de Algoritmos", given by Prof. Dr. Mario Lizier at UFSCar on the second semester of 2014.