Solution for ABCheck algorithm