class Solution(object):
def sumOfPower(self, nums):
"""
:type nums: List[int]
:rtype: int
"""
nums.sort()
dp = [0] * len(nums)
pre_sum = [0] * (len(nums) + 1)
ans = 0
mod = 10 ** 9 + 7
for i in range(len(nums)):
dp[i] = (nums[i] + pre_sum[i]) % mod
pre_sum[i + 1] = (pre_sum[i] + dp[i]) % mod
ans = (ans + nums[i] * nums[i] * dp[i]) % mod
return ans