Count sum of all digits
Mathematica 30-(10+50)= -30
Shortened by 4 chars thanks to ybeltukov.
Range@n returns the numbers from 1 through n.
Integerdigits@n breaks up each of those numbers into its digits.
Total[n,2] sums the digits.  The 2 is to allow summing across different levels, i.e. lists of lists.
IntegerDigits@Range@#~Total~2&amp;

Testing
IntegerDigits@Range@#~Total~2&amp;[12]


51

IntegerDigits@Range@#~Total~2 &amp;[1000000]


27000001


Expressions
IntegerDigits@Range@#~Total~2 &amp;[55*96 - 12]

55*96 - 12


81393
5268

IntegerDigits@Range@#~Total~2 &amp;[5268]


81393


IntegerDigits@Range@#~Total~2 &amp;[55*96^2 - 12]
55*96^2 - 12


12396621
506868

IntegerDigits@Range@#~Total~2 &amp;[506868]


12396621