#15. 数组前两项求和及边界处理
数组前两项求和及边界处理
Sum of First Two Elements
Background
Congcong is currently learning about array operations and has encountered a simple problem that requires careful handling of edge cases.
Problem Description
Given an array of integers, return the sum of the first two elements in the array. If the array length is less than , just sum up the elements that exist, returning if the array is length .
Input Format
Input is given from standard input in the following format.
A single line containing several space-separated integers.
Output Format
Output is printed to standard output in the following format.
A single integer, representing the calculated sum.
Sample
1 2 3
3
1 1
2
1 1 1 1
2
Sample Explanation
For the first sample, the array is [1, 2, 3]. The first two elements are and , and their sum is .
For the second sample, the array is [1, 1]. The first two elements are and , and their sum is .
For the third sample, the array is [1, 1, 1, 1]. The first two elements are and , and their sum is .
Constraints
Time limit: second, Memory limit: KiB for each test case.