#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
template <class T>
inline T tmin(T a, T b) {
  return (a < b) ? a : b;
}
template <class T>
inline T tmax(T a, T b) {
  return (a > b) ? a : b;
}
template <class T>
inline void amax(T &a, T b) {
  if (b > a) a = b;
}
template <class T>
inline void amin(T &a, T b) {
  if (b < a) a = b;
}
template <class T>
inline T tabs(T a) {
  return (a > 0) ? a : -a;
}
template <class T>
T gcd(T a, T b) {
  while (b != 0) {
    T c = a;
    a = b;
    b = c % b;
  }
  return a;
}
const int N = 5005;
long long dp[N][N];
string s;
int n, k;
int rk[N], tmp[N], sa[N];
bool compare_sa(int i, int j) {
  if (rk[i] != rk[j])
    return rk[i] < rk[j];
  else {
    int ri = i + k <= n ? rk[i + k] : -1;
    int rj = j + k <= n ? rk[j + k] : -1;
    return ri < rj;
  }
}
void construct_sa() {
  for (int i = (0); i < (n + 1); ++i) {
    sa[i] = i;
    rk[i] = i < n ? s[i] : -1;
  }
  for (k = 1; k <= n; k *= 2) {
    sort(sa, sa + n + 1, compare_sa);
    tmp[sa[0]] = 0;
    for (int i = (1); i < (n + 1); ++i)
      tmp[sa[i]] = tmp[sa[i - 1]] + (compare_sa(sa[i - 1], sa[i]) ? 1 : 0);
    for (int i = (0); i < (n + 1); ++i) rk[i] = tmp[i];
  }
}
struct RollingHash {
  const unsigned bs = 1000000007U;
  vector<unsigned long long> tp, th;
  template <class T>
  void init(const T s, const int _size) {
    tp.resize(_size + 1);
    th.resize(_size + 1);
    tp[0] = 1, th[0] = 0;
    for (int i = 0; i < _size; ++i) {
      tp[i + 1] = tp[i] * bs;
      th[i + 1] = s[i] + th[i] * bs;
    }
  }
  unsigned long long range(int l, int r) const {
    return th[r] - th[l - 1] * tp[r - l + 1];
  }
};
int main(int argc, char *argv[]) {
  ios_base::sync_with_stdio(false);
  long long val;
  cin >> n >> s;
  RollingHash rhash;
  rhash.init(s, n);
  construct_sa();
  for (int i = (0); i < (n + 1); ++i) rk[sa[i]] = i;
  for (int i = (0); i < (n); ++i) {
    if (s[i] == '0') continue;
    if (i == 0)
      dp[i][1] = 1;
    else
      dp[i][1] = (s[i] > s[i - 1]) ? dp[i - 1][1] : 0;
    for (int l = (2); l < (n + 1 - i); ++l) {
      val = dp[i][l - 1];
      int di = i - l + 1;
      if (di >= 0) {
        bool ok = false;
        if (rhash.range(di + 1, di + l - 1) == rhash.range(i + 1, i + l - 1))
          ok = true;
        else if (rk[di] > rk[i])
          ok = true;
        if (ok) val += dp[di][l - 1];
      }
      di = i - l;
      if (di >= 0) {
        bool ok = false;
        if (rhash.range(di + 1, di + l) != rhash.range(i + 1, i + l) &&
            rk[i] > rk[di])
          ok = true;
        if (ok) assert(s.substr(di, l) < s.substr(i, l));
        if (ok) val += dp[di][l];
      }
      dp[i][l] = val % MOD;
    }
  }
  long long ret = 0;
  for (int i = (0); i < (n); ++i) ret = (ret + dp[i][n - i]) % MOD;
  cout << ret << endl;
  return 0;
}
