484. Triangular Sum

0

Medium

Given a 0-indexed integer array nums, where each element nums[i] is a digit between 0 and 9 (inclusive), find the triangular sum of nums. The triangular sum is the value of the only element present in nums after the following process terminates: If nums has only one element, the process ends. Otherwise, create a new array newNums of length n - 1, where each element newNums[i] is calculated as (nums[i] + nums[i+1]) % 10. Replace nums with newNums and repeat the process until nums has only one element. Finally, print the triangular sum of nums.

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