Good Bye 2015
D
New Year and Ancient Prophecy
Codeforces
2000
原题
← CE →
翻译中…

Limak is a little polar bear. In the snow he found a scroll with the ancient prophecy. Limak doesn't know any ancient languages and thus is unable to understand the prophecy. But he knows digits!

翻译中…

One fragment of the prophecy is a sequence of $*n*$ digits. The first digit isn't zero. Limak thinks that it's a list of some special years. It's hard to see any commas or spaces, so maybe ancient people didn't use them. Now Limak wonders what years are listed there.

翻译中…

Limak assumes three things:

翻译中…
  • Years are listed in the strictly increasing order;
  • Every year is a positive integer number;
  • There are no leading zeros.
翻译中…

Limak is going to consider all possible ways to split a sequence into numbers (years), satisfying the conditions above. He will do it without any help. However, he asked you to tell him the number of ways to do so. Since this number may be very large, you are only asked to calculate it modulo $10^{9} + 7$.

翻译中…

Input

翻译中…

The first line of the input contains a single integer $*n*$ ($1 ≤ *n* ≤ 5000$) — the number of digits.

翻译中…

The second line contains a string of digits and has length equal to $*n*$. It's guaranteed that the first digit is not '0'.

翻译中…

Output

翻译中…

Print the number of ways to correctly split the given sequence modulo $10^{9} + 7$.

翻译中…

Note

翻译中…

In the first sample there are $8$ ways to split the sequence:

翻译中…
  • "123434" = "123434" (maybe the given sequence is just one big number)
  • "123434" = "1" + "23434"
  • "123434" = "12" + "3434"
  • "123434" = "123" + "434"
  • "123434" = "1" + "23" + "434"
  • "123434" = "1" + "2" + "3434"
  • "123434" = "1" + "2" + "3" + "434"
  • "123434" = "1" + "2" + "3" + "4" + "34"
翻译中…

Note that we don't count a split "123434" = "12" + "34" + "34" because numbers have to be strictly increasing.

翻译中…

In the second sample there are $4$ ways:

翻译中…
  • "20152016" = "20152016"
  • "20152016" = "20" + "152016"
  • "20152016" = "201" + "52016"
  • "20152016" = "2015" + "2016"
翻译中…

样例

Input #1
6
123434
Output #1
8
InputCopy OutputCopy
Input #2
8
20152016
Output #2
4
InputCopy OutputCopy
题目信息
题号
611D
所属比赛
时间限制
2.5 s
内存限制
512 MB
标签
动态规划
哈希
字符串

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。