I need to save some money to buy a gift. I think I can do something like that:

First week (W0) I save nothing on Sunday, 1 on Monday, 2 on Tuesday... 6 on Saturday,
second week (W1) 2 on Monday... 7 on Saturday and so on according to the table below where the days are numbered from 0 to 6.

Can you tell me how much I will have for my gift on Saturday evening after I have saved 12? (Your function finance(6) should return 168 which is the sum of the savings in the table). 

Imagine now that we live on planet XY140Z-n where the days of the week are numbered from 0 to n (integer n > 0) and where
I save from week number 0 to week number n included (in the table below n = 6).

How much money would I have at the end of my financing plan on planet XY140Z-n?



  -- |Su|Mo|Tu|We|Th|Fr|Sa|
   --|--|--|--|--|--|--|--|
  W6 |  |  |  |  |  |  |12|
  W5 |  |  |  |  |  |10|11|
  W4 |  |  |  |  |8 |9 |10|
  W3 |  |  |  |6 |7 |8 |9 |
  W2 |  |  |4 |5 |6 |7 |8 |
  W1 |  |2 |3 |4 |5 |6 |7 |
  W0 |0 |1 |2 |3 |4 |5 |6 |
  
#Example:
```
finance(5) --> 105
finance(6) --> 168
finance(7) --> 252
finance(5000) --> 62537505000
```
#Hint: 
try to avoid nested loops

Source: codewars | Difficulty: EASY
Tags: Mathematics

Starter code: def finance(n):
	

Solutions:
def finance(n):
	return n * (n + 1) * (n + 2) / 2


def finance(n):
	savings = 0
	for weeks in range(n + 1):
		for days in range(weeks, n + 1):
			savings += weeks + days
	return savings


finance = lambda n: n * (n + 1) * (n + 2) / 2


def finance(n):
	return sum(((i + 1) * 3 * i // 2 for i in range(1, n + 1)))


def finance(n):
	week = [sum(range(2 * i, n + i + 1)) for i in range(n + 1)]
	return sum(week)


def finance(n):
	return sum([sum(range(2 * a, 2 * n + 1 - 2 * a)) for a in range(n)])