877. Triangular Sum

0

Medium

Given an array of integers, the triangular sum is the value of the only element present in the array after performing a specific process. Starting with the given array, if the array has only one element, the process ends. Otherwise, create a new array with one less element. For each index i, assign the value of the new array at index i as the sum of the corresponding elements in the original array (nums[i] + nums[i+1]) modulo 10. Replace the original array with the new array and repeat the process until only one element remains. Print the triangular sum of the final array.

Input Format

The first line contains a single integer N, the length of the array. The next line contains N space-separated integers representing the elements of the array.

Output Format

An integer representing the triangular sum.

Example

Input

5
1 2 3 4 5

Output

8

Constraints

1 <= N <= 10^3

Loading...

View Submissions

Console