#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const long long infl = 0x3f3f3f3f3f3f3f3fLL;
template <class T>
void rd(T &a) {
  char ch = getchar();
  bool ng = 0;
  a = 0;
  for (; ch < '0' || ch > '9'; ch = getchar())
    if (ch == '-') ng = 1;
  for (; ch >= '0' && ch <= '9'; ch = getchar())
    a = (a << 1) + (a << 3) + (ch ^ '0');
  if (ng) a = ~a + 1;
}
template <class T>
inline void wrt(T a) {
  if (a < 0) {
    putchar('-');
    wrt(~a + 1);
  } else {
    if (a > 9) wrt(a / 10);
    putchar(a % 10 ^ '0');
  }
}
const int N = 5e3 + 5, MOD = 1e9 + 7, BASE = 317;
int n, dp[N][N], h[N], pw[N];
char a[N];
inline void add(int &a, const int &b) {
  a += b;
  if (a < 0) a += MOD;
  if (a > MOD) a -= MOD;
}
inline int get(const int &x, const int &len) {
  return h[x + len] - 1LL * h[x - 1] * pw[len + 1];
}
inline bool check(const int &x, const int &y, const int &len) {
  int lo = 0, hi = len, res = -1;
  while (lo <= hi) {
    int mid = lo + hi >> 1;
    if (get(x, mid) != get(y, mid)) {
      res = mid;
      hi = mid - 1;
    } else {
      lo = mid + 1;
    }
  }
  if (res == -1) return 0;
  if (a[x + res] <= a[y + res]) return 0;
  return 1;
}
int main() {
  rd(n), a[1] = getchar();
  while (a[1] < '0' || a[1] > '9') a[1] = getchar();
  for (int i = 2; i <= n; ++i) a[i] = getchar();
  pw[0] = 1, h[0] = 0;
  for (int i = 1; i <= n; ++i) pw[i] = BASE * pw[i - 1];
  for (int i = 1; i <= n; ++i) h[i] = BASE * h[i - 1] + (a[i] ^ '0');
  for (int i = 1; i <= n; ++i) {
    dp[i][1] = (a[1] != '0');
    for (int j = 2; j <= i; ++j) {
      if (a[j] == '0') {
        dp[i][j] = dp[i][j - 1];
        continue;
      }
      if (i > (j << 1) - 2)
        add(dp[i][j], dp[j - 1][j - 1]);
      else {
        int pos = (j << 1) - i - 1;
        add(dp[i][j], dp[j - 1][j - 1] - dp[j - 1][pos]);
        if (check(j, pos, i - j))
          add(dp[i][j], dp[j - 1][pos] - dp[j - 1][pos - 1]);
      }
      add(dp[i][j], dp[i][j - 1]);
    }
  }
  wrt(dp[n][n]);
  return 0;
}
