#include <bits/stdc++.h>
using namespace std;
const int mod = (int)1e9 + 7;
const long long h1 = (long long)1e9 + 7;
const long long h2 = (long long)5337;
int n;
char s[5050];
int dp[5050][5050];
long long hh[5050], pw[5050];
long long hh1[5050], pw1[5050];
long long Get1(int l, int r) { return hh[r] - hh[l - 1] * pw[r - l + 1]; }
long long Get2(int l, int r) { return hh1[r] - hh1[l - 1] * pw1[r - l + 1]; }
bool check1(int x, int y, int u) {
  int p = 0;
  for (int l = 0, r = y - x + 1; l <= r;) {
    int m = (l + r) / 2;
    long long u1 = Get1(x, x + m - 1);
    long long u2 = Get1(u, u + m - 1);
    if (u1 == u2)
      p = max(p, m), l = m + 1;
    else
      r = m - 1;
  }
  if (p == y - x + 1) return 0;
  return s[x + p] < s[u + p];
}
bool check2(int x, int y, int u) {
  int p = 0;
  for (int l = 0, r = y - x + 1; l <= r;) {
    int m = (l + r) / 2;
    long long u1 = Get2(x, x + m - 1);
    long long u2 = Get2(u, u + m - 1);
    if (u1 == u2)
      p = max(p, m), l = m + 1;
    else
      r = m - 1;
  }
  if (p == y - x + 1) return 0;
  return s[x + p] < s[u + p];
}
int main() {
  scanf("%d\n", &n);
  scanf("%s\n", s + 1);
  pw[0] = 1;
  pw1[0] = 1;
  for (int i = 1; i <= n; i++) {
    pw[i] = pw[i - 1] * h1;
    pw1[i] = pw1[i - 1] * h2;
    hh[i] = hh[i - 1] * h1 + s[i];
    hh1[i] = hh1[i - 1] * h2 + s[i];
  }
  for (int i = 0; i <= n; ++i) dp[0][i] = 1;
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= i; ++j)
      if (s[j] != '0') {
        int cs = i - j + 1;
        if (j - 1 >= cs && s[j - cs] != 0) {
          if (check1(j - cs, j - 1, i - cs + 1) &&
              check2(j - cs, j - 1, i - cs + 1))
            dp[i][cs] += dp[j - 1][cs];
          else
            dp[i][cs] += dp[j - 1][cs - 1];
        } else {
          dp[i][cs] += dp[j - 1][cs - 1];
        }
        if (dp[i][cs] >= mod) dp[i][cs] -= mod;
      }
    for (int j = 2; j <= n; ++j) {
      dp[i][j] += dp[i][j - 1];
      if (dp[i][j] >= mod) dp[i][j] -= mod;
    }
  }
  printf("%d\n", dp[n][n]);
  return 0;
}
