I’m struggling with this question: http://www.usaco.org/index.php?page=viewproblem2&cpid=595.

I don’t understand the USACO Guide’s code solution.

USACO Guide’s Code: https://usaco.guide/solutions/usaco-595?lang=cpp

From what I understand, they loop through each element (O(n)) and create a prefix sum reminder for each element. So at each element, we have the remainder of the sum of the prior elements by 7. I’m not sure what happens next, and I don’t understand the purpose of the vistos set. Please let me know.

Thanks!