#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
int n, lcp[5010][5010], f[5010][5010];
char s[5010];
int main() {
  scanf("%d%s", &n, s + 1);
  if (s[1] == '0') return puts("0"), 0;
  for (int i = n; i >= 1; i--)
    for (int j = n; j >= 1; j--)
      if (s[i] == s[j]) lcp[i][j] = lcp[i + 1][j + 1] + 1;
  for (int i = 1; i <= n; i++) {
    for (int j = i, last = j + j - i - 1; j >= 1; j--, last = j + j - i - 1)
      if (s[j] == '0')
        f[i][j] = f[i][j + 1];
      else if (last > 0 && lcp[last][j] < i - j + 1 &&
               s[last + lcp[last][j]] < s[j + lcp[last][j]])
        f[i][j] = (f[i][j + 1] + f[j - 1][last]) % mod;
      else
        f[i][j] = (f[i][j + 1] + f[j - 1][max(1, last + 1)]) % mod;
    f[i][1]++;
  }
  printf("%d", f[n][1]);
  return 0;
}
