#include <bits/stdc++.h>
using namespace std;
const int INF = (int)1e9 + 7;
const int MAXN = (int)1e6 + 7;
const int dx[] = {0, -1, 0, 1};
const int dy[] = {1, 0, -1, 0};
string second;
int n;
int dp[5050][5050];
int sum[5050][5050];
int gap;
int sa[50050];
int pos[50050];
int tmp[50050];
int table[50050][20];
int lg[50050];
int lcp[50050];
bool cmp(int x, int y) {
  if (pos[x] != pos[y]) return pos[x] < pos[y];
  x += gap;
  y += gap;
  return x <= n && y <= n ? pos[x] < pos[y] : x > y;
}
void buildSA() {
  for (int i = 1; i <= n; i++) {
    pos[i] = second[i];
    sa[i] = i;
  }
  tmp[1] = 1;
  for (gap = 1; gap; gap <<= 1) {
    sort(sa + 1, sa + n + 1, &cmp);
    for (int i = 1; i + 1 <= n; i++)
      tmp[i + 1] = tmp[i] + cmp(sa[i], sa[i + 1]);
    for (int i = 1; i <= n; i++) pos[sa[i]] = tmp[i];
    if (tmp[n] == n) break;
  }
}
void buildLCP() {
  int k = 0;
  for (int i = 1; i <= n; i++) {
    if (pos[i] == n) {
      k = 0;
      continue;
    }
    k = max(0, k - 1);
    int j = sa[pos[i] + 1];
    while (i + k <= n && j + k <= n && second[i + k] == second[j + k]) ++k;
    lcp[pos[i]] = k;
  }
  for (int deg = 0; deg < 20; deg++) {
    for (int i = 1; i + (1 << deg) - 1 <= n; i++) {
      if (deg == 0)
        table[i][deg] = lcp[i];
      else
        table[i][deg] =
            min(table[i][deg - 1], table[i + (1 << (deg - 1))][deg - 1]);
    }
  }
  lg[1] = 0;
  for (int i = 2; i <= n; i++) lg[i] = lg[i / 2] + 1;
}
int getMin(int l, int r) {
  if (l > r) return INF;
  int cc = lg[r - l + 1];
  return min(table[l][cc], table[r - (1 << cc) + 1][cc]);
}
int getLCP(int x, int y) {
  int l = pos[x];
  int r = pos[y];
  if (l > r) swap(l, r);
  return getMin(l, r - 1);
}
bool cmp(int s1, int s2, int len) {
  if (getLCP(s1, s2) >= len) return false;
  return pos[s1] > pos[s2];
}
int main() {
  cin >> n;
  cin >> second;
  second = "#" + second;
  buildSA();
  buildLCP();
  dp[0][0] = 1;
  for (int len = 0; len <= n; len++) sum[0][len] = 1;
  for (int i = 1; i <= n; i++) {
    for (int len = 1; len <= i; len++) {
      if (second[i - len + 1] == '0') continue;
      int en = i - len;
      int res = sum[en][len - 1];
      if (en >= len && second[en - len + 1] != '0' &&
          cmp(i - len + 1, en - len + 1, len)) {
        res += dp[en][len];
        if (res >= INF) res -= INF;
      }
      dp[i][len] = res;
    }
    for (int len = 1; len <= n; len++) {
      sum[i][len] = sum[i][len - 1] + dp[i][len];
      if (sum[i][len] >= INF) sum[i][len] -= INF;
    }
  }
  int ans = 0;
  for (int last = 1; last <= n; last++) ans = (ans + dp[n][last]) % INF;
  cout << ans;
  return 0;
}
