#include <bits/stdc++.h>
using namespace std;
const int maxn = 5005;
const int P = 1e9 + 7;
void read(int &x) { scanf("%d", &x); }
int n;
char str[maxn];
int dp[maxn][maxn], sum[maxn][maxn];
int lcp[maxn][maxn];
void update(int &x, int y) {
  if (y >= P) y -= P;
  if (y < 0) y += P;
  x += y;
  if (x >= P) x -= P;
}
bool Check(int x, int y, int z) {
  int l1 = x + 1, r1 = y;
  int l2 = y + 1, r2 = z;
  int tmp = lcp[l1][l2];
  l1 += tmp, l2 += tmp;
  if (l1 > r1) return 0;
  return str[l1] < str[l2];
}
int main() {
  read(n);
  scanf("%s", str + 1);
  for (int i = n; i >= 1; i--)
    for (int j = n; j >= 1; j--)
      if (str[i] == str[j]) lcp[i][j] = lcp[i + 1][j + 1] + 1;
  for (int i = 1; i <= n; i++) {
    dp[i][0] = 1;
    for (int j = 0; j <= i - 1; j++)
      if (str[j + 1] ^ 48) {
        int K = max(2 * j - i, -1);
        update(dp[i][j], sum[j][j - 1] - sum[j][K]);
        if (Check(K, j, i)) update(dp[i][j], dp[j][K]);
      }
    for (int j = 0; j <= n; j++) update(sum[i][j], sum[i][j - 1] + dp[i][j]);
  }
  int ans = 0;
  for (int i = 0; i <= n - 1; i++) update(ans, dp[n][i]);
  printf("%d", ans);
}
