class Solution:
def sum_solution(self, array):
if array is None or len(array) < 1:
return 0
return self.sumsort(array, 0, len(array) - 1)
def sumsort(self, array, l, r):
if l == r:
return 0
mid = (l + r) // 2
return self.sumsort(array, l, mid) + self.sumsort(array, mid + 1, r) + self.sumall(array, l, mid, r)
def sumall(self, array, l, mid, r):
p1 = l
p2 = mid + 1
res = 0
ans = []
while (p1 <= mid and p2 <= r):
if array[p1] < array[p2]:
res += array[p1] * (r - p2 + 1)
ans.append(array[p1])
p1 += 1
else:
ans.append(array[p2])
p2 += 1
print(ans)
while p1 <= mid:
ans.append(array[p1])
p1 += 1
while p2 <= r:
ans.append(array[p2])
p2 += 1
for j in range(0,len(ans)):
array[l+j]=ans[j]
print(res)
print(array)
return res
if __name__ == '__main__':
solution = Solution()
array = list(map(int,input().split(',')))
a = solution.sum_solution(array)
print(a)