#P9710. [KMOI R1] 五五五五(Easy)

[KMOI R1] 五五五五(Easy)

Background

“Numbers in slow order are not born from the supernatural. They have a form that can be checked, and a quantity that can be inferred.” — Zu Chongzhi.

Problem Description

Xiao Song has a sequence a1,a2,ana_1,a_2\dots,a_n. For i[1,n]i\in [1,n], it satisfies ai[0,9]a_i\in[0,9].

For 1lrn1\le l\le r\le n, he defines f(l,r)f(l,r) as the number of consecutive trailing 55’s at the end of ala(l+1)ar\overline{a_la_{(l+1)}\dots a_r}.

For example, for the sequence a={1,1,4,5,1,4}a=\{1,1,4,5,1,4\}, we have f(2,4)=1f(2,4)=1 and f(1,3)=0f(1,3)=0.

Now please compute:

$$\Big(\sum\limits_{l=1}^ {n}\sum\limits_{r=l}^{n} f(l,r)\Big) \bmod 10^9+7$$

Input Format

The first line contains a positive integer nn, representing the length of the sequence.

The second line contains nn integers a1,a2,,ana_1,a_2,\dots,a_n, representing the sequence aa.

Output Format

One positive integer ansans, representing the answer.

2
5 5
4
4
1 1 4 5
4

Hint

Explanation for Sample 11:

f(1,1)=1f(1,1)=1.

f(1,2)=2f(1,2)=2.

f(2,2)=1f(2,2)=1.

So the answer is ans=f(1,1)+f(1,2)+f(2,2)=4ans=f(1,1)+f(1,2)+f(2,2)=4, therefore output 44.

Constraints

This problem uses bundled subtask testdata.

Let m=max{a1,a2,,an}m=\max\{a_1,a_2,\dots,a_n\}.

Subtask ID Test Point ID nn\le mm\le Special Property Score
11 100100 33 None 33
22 242\sim 4 2×1052\times 10^5 55 A\mathbf{A} 2222
33 5,65,6 100100 None 1010
44 7107\sim 10 2×1052\times 10^5 B\mathbf{B} 2525
55 112011\sim 20 99 None 4040

Special property A:\mathbf{A}: The average of the sequence is 55.

Special property B:\mathbf{B}: The sequence is monotone non-increasing.

For 100%100\% of the data: 1n2×1051\le n\le 2\times 10^5, 0m90\le m\le 9.

For i[1,n]\forall i\in [1,n], it holds that ai[0,9]a_i\in[0,9].

Translated by ChatGPT 5