Challenge: Add Them Up

Lab C++ Beginner 10 points

Read n numbers and print their total. The total can be bigger than an int can hold, so use long long. This is an O(n) algorithm.

Input

Line 1: n. Line 2: n whole numbers (each up to 109).

Output

The total.

Example

Input

5
1 2 3 4 5

Output

15
Sample input available Sample output available
Editor
C++

Hints

Start with long long total = 0.

Read each number and add it.

Solution explanation

Three numbers of 10⁹ add up to 3 × 10⁹ – too big for an int, fine for long long.

Show solution
#include <iostream>
using namespace std;

int main() {
    int n;
    cin >> n;
    long long total = 0;
    for (int i = 0; i < n; i++) {
        long long x;
        cin >> x;
        total += x;
    }
    cout << total << endl;
    return 0;
}
Output
Answer
HOME LABS COMMUNITY DASHBOARD