Boxes stacked on the shelves
Statement
A warehouse has shelves stacked in several levels from the bottom up. The rule for filling these shelves is simple. Level 1 takes 1 box, level 2 takes 2 and level 3 takes 3. That is, level k holds k boxes. The shelves get wider as the levels go up, so more boxes fit on them.
The warehouse keeper used to climb the shelves and count the boxes one by one at every stocktake. As the shelves grew taller, that way took far too long. All the keeper knows is how many levels the shelves are stacked to. The filling rule is fixed, so the total number of boxes can be worked out from the number of levels alone.
Write a program that prints the total number of boxes placed from level 1 to level n when the number of shelf levels n is given.
For example, suppose n=10 levels. The number of boxes on each level, and the running total from level 1 up to that level, are as in the following table.
| Level | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 |
|---|---|---|---|---|---|---|---|---|---|---|
| Boxes | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 |
| Running total | 1 | 3 | 6 | 10 | 15 | 21 | 28 | 36 | 45 | 55 |
The running total up to level 10 is 55, so the answer in this case is 55.
Putting the results for other level counts into one table gives the following.
| Number of levels | 1 | 3 | 10 | 100 | 1,000 |
|---|---|---|---|---|---|
| Total number of boxes | 1 | 6 | 55 | 5050 | 500500 |
Even when the shelves have only level 1, the answer is 1 and not 0. As the number of levels grows, the total number of boxes grows quickly as well.
Input and output examples
Example 1
Input
10
Output
55
Example 2
Input
3
Output
6
Example 3
Input
10000
Output
50005000
Input
First the number of shelf levels n is given as a natural number on the first line. n is a natural number from 1 to 10,000. This one line is the only line of input, and the number of boxes on each level is not given separately. You have to work the number of boxes on each level out from the rule that level k holds k boxes. n can also be given as 1. Values such as the width of a shelf or the size of a box are not given.
Output
Print the total number of boxes placed from level 1 to level n on the first line, as a natural number. Print the single number and then break the line, and do not attach a space after the number. Do not print a thousands comma, and do not write a unit either.
Requirements
- The input is one line, and it holds one number
- n is a natural number from 1 to 10,000
- Level k holds k boxes
- The answer is a single number and it is printed on one line
- Print only the number, with no thousands comma
- You must write a program that reads from standard input and writes to standard output
- Trailing spaces at the end of a line and blank lines at the end of the output are ignored when grading
- The languages you can use are Python and JavaScript
- The memory limit is 256MB. The browser does not measure it, it only states it
- The time limit is set by measuring the setter's reference solution on the same runtime
- On this problem you submit code, not a prompt. That code runs in the browser on this device, and all that goes to the server is a fingerprint of the output and the time it took. Whether it is correct is decided by the server. The run time is a number each device reports, so the code and the device details are posted next to it on the leaderboard.
- The output has to match the expected value down to the character. A space inside a line counts the same as any other character.
- There are 15 cases, and 3 of them show the input together with the expected output. The rest are used only when you submit and are not shown on this page.
- You have to pass all 15 cases to solve this.
Examples
3 public cases. Judging also uses hidden cases. You have to pass all 15 cases to solve this.
3
6
10
55
10000
50005000
Solution
Your code runs on this device. Only the fingerprint of the output and the elapsed time go to the server. The server decides whether it is correct.
Submitting requires you to log in. Running against the public cases works without one.
You can test with 3 public cases. Submitting runs the hidden cases too.
People who solved this problem
The time shown is the time spent solving. Input reading time is outside the solver's control, so it is excluded. And since each device reports this value itself, we record which device measured it.
Log in and you can see the code once you solve this problem.
Log in and you can see the code once you solve this problem.