8671: Spirit Circle Observation

内存限制:128 MB 时间限制:1 S
题面:传统 评测方式:文本比较 上传者:
提交:3 通过:1

题目描述

Potassium, a genius who masters soul conversion, is observing the world line of Potas. The world line can be divided into nnn parts and represented as an n-digit decimal number s (may have leading zeros) that reveals the property of time in the past and future of Potas.

For convenience, let abc denote the concatenation of digits a,b,ca, b, ca,b,c, so the world line can be expressed as s=s1s2⋯sn. When observing, Potassium focuses on the era, which consists of continuous parts in the world line. An era beginning from part l to r can be denoted as slsl+1⋯sr(1≤l≤r≤n1), and may also have leading zeros.
 
When two eras are quite similar, Potassium can observe one from another by Spirit Circle. More specifically, an era B=sl2sl2+1⋯sr can be observed from another era A=sl1sl1+1⋯sr by Spirit Circle if and only if the following two conditions are satisfied, regardless of where A and B locate in s originally.

1. A and B have the same length, i.e. r1l1+1=r2l2+1;
2. B is greater than A by exactly 111, i.e. r1+1=sl2sl2+1sr2.

Potassium is wondering: how many different pairs (A,B) can be found in sss that he can observe era B from era A. Note that two eras having the same representations but differing in the original location in sss are considered as different eras.

输入格式

The first line contains one integer n (1n4105), denoting the number of parts in the world line of Potas.
The second line contains an nnn-digit decimal number sss, denoting the representation of the world line of Potas.

输出格式

Print an integer in a single line, denoting the number of different pairs(A,B) in sss that Potassium can observe era B from era A by Spirit Circle.

输入样例 复制

5
10998

输出样例 复制

5

数据范围与提示

In the first example, Potassium can choose 5 different (A,B) pairs:

1. Choose s2=0, s1=1;
2. Choose s5=8, s3=9;
3. Choose s5=8, s4=9;
4. Choose s3=09, s1s2=10;
5. Choose s5=98, s3s4=99.

分类标签