Submit solution


Points: 15 (partial)
Time limit: 1.0s
Memory limit: 1G

Author:
Problem types

You are given an array of N positive integers, a1,a2,aN. Let the value of an array be the number of trailing zeros in the product of all its elements. Determine the sum of the values of all subarrays of a.

Constraints

1N5×105
1ai109

Subtask 1 [20%]

1N5000

Subtask 2 [80%]

No additional constraints.

Input Specification

The first line contains one integer, N, the length of the array.

The next line contains N space-separated integers, a1,a2,,aN, the array of positive integers.

Output Specification

Output one line containing one integer, the sum of the values of all subarrays.

Note: This number may not fit within a 32-bit integer type.

Sample Input 1

Copy
5
3 1 4 1 5

Sample Output 1

Copy
3

Explanation for Sample 1

The only 3 subarrays with a nonzero value are [4,1,5], [1,4,1,5], and [3,1,4,1,5]. The products of each subarray are 20, 20, and 60, respectively. Each product has only 1 trailing zero, for a total value of 1+1+1=3. All of the other subarrays have products with no trailing zeroes.

Sample Input 2

Copy
7
10 2 5 4 5 6 7

Sample Output 2

Copy
35

Comments


  • 0
    tofu  commented 81 days ago

    marcorz