#include <bits/stdc++.h>
using namespace std;
bool debug = 0;
int n, m, k;
int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
string direc = "RDLU";
long long ln, lk, lm;
struct fw {
  int z[5005];
  void rs() { memset(z, 0, sizeof z); }
  void zFunc(const char* s) {
    int n = strlen(s);
    int L = 0, R = 0;
    for (int i = 1; i < n; i++) {
      if (i > R) {
        L = R = i;
        while (R < n && s[R] == s[R - L]) R++;
        R--;
        z[i] = R - L + 1;
      } else {
        int k = i - L;
        if (z[k] < R - i + 1)
          z[i] = z[k];
        else {
          L = i;
          while (R < n && s[R] == s[R - L]) R++;
          R--;
          z[i] = R - L + 1;
        }
      }
    }
  }
} fun;
void addmod(int& x, int y) {
  x += y;
  if (x >= 1000000007) x -= 1000000007;
}
struct tree {
  int b[5005] = {0};
  void update(int x, int val) {
    for (int i = x; i < 5005; i += i & -i) {
      addmod(b[i], val);
    }
  }
  int query(int x) {
    int ret = 0;
    for (; x > 0; addmod(ret, b[x]), x -= x & -x)
      ;
    return ret;
  }
  int qy(int l, int r) {
    return (query(r) + 1000000007 - query(l - 1)) % 1000000007;
  }
} tr[5005];
bool lar[5005][5005];
char s[5005];
int dp[5005][5005];
void fmain() {
  scanf("%d%s", &n, s + 1);
  for (int i = 1; i < n; i++)
    if (s[i] != '0') {
      fun.rs();
      fun.zFunc(s + i);
      for (int j = i; j + 1 + j - i <= n; j++)
        if (s[j + 1] != '0') {
          int L = fun.z[j + 1 - i];
          int nxt = i + L;
          if (nxt <= j && s[nxt] < s[j + 1 + L]) {
            lar[i][j] = 1;
          }
        }
    }
  dp[0][0] = 1;
  for (int j = 1; j <= n; j++) {
    for (int i = 1; i <= j; i++)
      if (s[i] != '0') {
        if (i == 1)
          dp[i][j] = 1;
        else {
          int L = i - 1 - (j - i) + 1;
          addmod(dp[i][j], tr[i - 1].qy(max(1, L), i - 1));
          L--;
          if (L >= 1 && lar[L][i - 1]) {
            addmod(dp[i][j], dp[L][i - 1]);
          }
        }
      }
    for (int i = 1; i <= j; i++) {
      tr[j].update(i, dp[i][j]);
    }
  }
  printf("%d\n", tr[n].query(n));
}
int main() {
  fmain();
  return 0;
}
