Challenge: Sum Without sum()

Lab Python Beginner 10 points

Read n numbers and print their total. Don't use Python's built-in sum() – write the loop yourself. This is an O(n) algorithm.

Input

Line 1: n. Line 2: n whole numbers separated by spaces.

Output

The total.

Example

Input

5
1 2 3 4 5

Output

15
Sample input available Sample output available
Editor
Python

Hints

Start with total = 0.

Add each number to total inside a for loop.

Solution explanation

One pass over the list, one addition per item: O(n) time and O(1) extra space.

Show solution
n = int(input())
nums = list(map(int, input().split()))
total = 0
for x in nums:
    total += x
print(total)
Output
Answer
HOME LABS COMMUNITY DASHBOARD