Yup!! The problem name reflects your task; just add a set of numbers. But you may feel yourselves condescended, to write a C/C++ program just to add a set of numbers. Such a problem will simply question your erudition. So, lets add some flavor of ingenuity to it. Addition operation requires cost now, and the cost is the summation of those two to be added. So,to add 1 and 10, you need a cost of 11. If you want to add 1, 2 and 3. There are several ways

```c++
1 + 2 = 3, cost = 3,
3 + 3 = 6, cost = 6,
Total = 9.
```
```c++
1 + 3 = 4, cost = 4,
2 + 4 = 6, cost = 6,
Total = 10.
```
```c++
2 + 3 = 5, cost = 5,
1 + 5 = 6, cost = 6,
Total = 11.
```
I hope you have understood already your mission, to add a set of integers so that the cost is minimal

# Your Task 
Given a vector of integers, return the minimum total cost of addition.

Source: codewars | Difficulty: EASY
Tags: Fundamentals

Mathematics

Starter code: def add_all(lst):
	

Solutions:
from heapq import *

def add_all(lst):
	heapify(lst)
	total = 0
	while len(lst) > 1:
		s = heappop(lst) + heappop(lst)
		total += s
		heappush(lst, s)
	return total


import heapq

def add_all(xs):
	heapq.heapify(xs)
	cost = 0
	while len(xs) > 1:
		c = heapq.heappop(xs) + xs[0]
		cost += c
		heapq.heapreplace(xs, c)
	return cost


def add_all(lst):
	if len(lst) == 1:
		return 0
	lst.sort()
	cost = sum(lst[:2])
	lst[:2] = (cost,)
	return cost + add_all(lst)


import heapq

def add_all(arr):
	n = len(arr)
	heapq.heapify(arr)
	res = 0
	while len(arr) > 1:
		first = heapq.heappop(arr)
		second = heapq.heappop(arr)
		res += first + second
		heapq.heappush(arr, first + second)
	return res


import heapq

def add_all(heap):
	heapq.heapify(heap)
	sum = 0
	while len(heap) > 1:
		(a, b) = (heapq.heappop(heap), heapq.heappop(heap))
		cost = a + b
		sum += cost
		heapq.heappush(heap, cost)
	return sum


from heapq import heapify, heappush, heappop

def add_all(lst):
	heapify(lst)
	s = 0
	print(lst)
	while len(lst) > 1:
		m1 = heappop(lst)
		m2 = heappop(lst)
		s += m1 + m2
		if not lst:
			return s
		heappush(lst, m1 + m2)


from heapq import *

def add_all(a):
	n = m = 0
	heapify(a)
	while len(a) > 1:
		m = heappop(a) + heappop(a)
		n += m
		heappush(a, m)
	return n


from queue import PriorityQueue

def add_all(lst):
	q = PriorityQueue()
	for x in lst:
		q.put(x)
	s = 0
	while q.qsize() > 1:
		a = q.get()
		b = q.get()
		s += a + b
		q.put(a + b)
	return s


from heapq import *

def add_all(lst):
	heapify(lst)
	res = 0
	while len(lst) >= 2:
		s = heappop(lst) + heappop(lst)
		res += s
		heappush(lst, s)
	return res