Compute the punishment number of an integer by checking which squares can be partitioned into decimal chunks that sum back to the original number.
Punishment Number
gfgGiven a positive integer , consider every integer from $1n$.
For each , square it to get . If the decimal representation of can be split into one or more contiguous substrings such that the integer values of those substrings add up exactly to , then contributes to the answer.
Return the sum of the squares of all such valid integers in the range .
The task is to determine this total punishment number.
Example 1
Input
n = 10
Output
182
Explanation
Valid values are 1, 9, and 10.
So the answer is 1 + 81 + 100 = 182.
Example 2
Input
n = 1
Output
1
Explanation
Only 1 is checked, and = 1 can be split as [1], which sums to 1.
Premium problem context
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.