#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int sum = 0, ff = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') ff = -1;
    ch = getchar();
  }
  while (isdigit(ch)) sum = sum * 10 + (ch ^ 48), ch = getchar();
  return sum * ff;
}
const int N = 5e3 + 5;
const int mo = 1e9 + 7;
int n, m, a[N], f[N][N], lcp[N][N], sum[N][N], ans;
inline bool check(int l, int r) {
  if (lcp[l][r] >= r - l) return 0;
  if (a[l + lcp[l][r]] < a[r + lcp[l][r]]) return 1;
  if (a[l + lcp[l][r]] > a[r + lcp[l][r]]) return 0;
  return 0;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%1d", &a[i]);
  for (int i = n; i >= 1; i--)
    for (int j = n; j >= 1; j--)
      if (a[i] == a[j]) lcp[i][j] = lcp[i + 1][j + 1] + 1;
  for (int i = 1; i <= n; i++) {
    f[i][1] = 1;
    for (int j = 1; j <= i; j++) {
      if (!a[j]) continue;
      int k = max(1, j * 2 - i);
      f[i][j] = (f[i][j] + sum[j - 1][j - 1] - sum[j - 1][k - 1] + mo) % mo;
      k--;
      if (check(k, j)) f[i][j] = (f[i][j] + f[j - 1][k]) % mo;
    }
    for (int j = 1; j <= i; j++) sum[i][j] = (sum[i][j - 1] + f[i][j]) % mo;
  }
  for (int i = 1; i <= n; i++) ans = (ans + f[n][i]) % mo;
  printf("%d\n", ans);
  return 0;
}
