4962: 新年和古代预言

内存限制:512 MB 时间限制:2 S
题面:传统 评测方式:文本比较 上传者:
提交:8 通过:4

题目描述

D. New Year and Ancient Prophecy
time limit per test
2.5 seconds
memory limit per test
512 megabytes
input
standard input
output
standard output
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 109+7.

利马克是一只小北极熊。在雪地里,他发现了一个带有古老预言的卷轴。利马克不懂任何古代语言,因此无法理解预言。但他知道数字!

预言的一个片段是n个数字的序列。第一个数字不为零。利马克认为这是一些特殊年份的清单。很难看到任何逗号或空格,所以也许古代人没有使用它们。现在利马克想知道那里列出了哪些年份。

利马克假设三件事:

  • 年份按严格递增顺序列出;
  • 每一年都是一个正整数;
  • 没有前导零。

Limak将考虑所有可能的方法将序列拆分为数字(年),满足上述条件。他会在没有任何帮助的情况下做到这一点。但是,他要求你告诉他这样做的方法的数量。由于这个数字可能非常大,因此仅要求您计算它 模109+ 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 109+7.
Examples
Input
6
123434
Output
8
Input
8
20152016
Output
4
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"

输入样例 复制


输出样例 复制