Magic Value | HackerRank

Calculate the sum of the magic values of all subarrays.