#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int maxn = 5e3 + 5;
int dp[maxn][maxn], g[maxn][maxn], lcp[maxn][maxn];
int n;
char s[maxn];
int dayu(int i, int j, int len) {
  if (lcp[i][j] >= len) return 0;
  int cc = lcp[i][j];
  return s[i + cc] > s[j + cc];
}
void solve() {
  memset(lcp, 0, sizeof(lcp));
  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;
    }
  }
  memset(dp, 0, sizeof(dp));
  memset(g, 0, sizeof(g));
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j < i; j++) {
      g[i][j] = g[i][j - 1];
      if (s[i - j + 1] == '0') continue;
      dp[i][j] = (dp[i][j] + g[i - j][min(j - 1, i - j)]) % mod;
      if (dp[i - j][j] && dayu(i - j + 1, i - 2 * j + 1, j)) {
        dp[i][j] = (dp[i][j] + dp[i - j][j]) % mod;
      }
      g[i][j] = (g[i][j] + dp[i][j]) % mod;
    }
    dp[i][i] = 1;
    g[i][i] = (g[i][i - 1] + dp[i][i]) % mod;
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    ans = (ans + dp[n][i]) % mod;
  }
  printf("%d\n", ans);
}
int main() {
  while (scanf("%d", &n) != EOF) {
    scanf("%s", s + 1);
    solve();
  }
  return 0;
}
