input: Write a python function to calculate the weighted sum of elements in an array where each element is multiplied by the sum of the subsequent elements minus itself.
  assert sum([1, 2, 3]) == 6
  assert sum([4, 5, 6]) == 35
  assert sum([1, 1, 1]) == 0
output: def sum(arr):
      weighted_sum = 0
      for i in range(len(arr)):
          subsequent_sum = sum(arr[i+1:])
          weighted_sum += arr[i] * (subsequent_sum - arr[i])
      return weighted_sum