Nested integer weighted sum