#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
const long long INF = 1e9 + 47;
const long long LINF = INF * INF;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int mod = 1e9 + 7;
inline int add(int x, int y) {
  if (x + y < mod) return x + y;
  return x + y - mod;
}
const int N = 5000 + 7;
int n;
string s;
long long hashi[N];
long long PW[N];
const int Mo = 47;
int dp[N][N];
int suma[N][N];
#pragma GCC optimize("O3")
#pragma GCC target("sse4")
inline bool equal(int i, int j, int len) {
  long long h1 = hashi[i + len - 1];
  if (i) h1 -= hashi[i - 1];
  long long h2 = hashi[j + len - 1];
  if (j) h2 -= hashi[j - 1];
  return h1 * PW[j - i] == h2;
}
inline bool f(int i, int len) {
  int j = i + len;
  if (j + len > n) return 0;
  int mn = min(len, 5);
  for (int k = (0); k < (mn); ++k)
    if (s[i + k] != s[j + k]) return s[i + k] < s[j + k];
  if (len == mn) return 0;
  if (equal(i, j, len)) return 0;
  int L = mn - 1, R = len, M;
  while (R - L > 1) {
    M = (L + R) >> 1;
    if (equal(i, j, M))
      L = M;
    else
      R = M;
  }
  assert(equal(i, j, L));
  assert(!equal(i, j, R));
  return s[i + L] < s[j + L];
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  n = 5000;
  s.resize(n);
  for (int i = (0); i < (n); ++i) s[i] = '0' + (rng() % 10);
  if (s[0] == '0') s[0] = '1' + (rng() % 9);
  cin >> n >> s;
  s += '1';
  PW[0] = 1;
  for (int i = (1); i < (N); ++i) PW[i] = PW[i - 1] * Mo;
  for (int i = (0); i < (n); ++i) {
    hashi[i] = s[i] * PW[i];
    if (i) hashi[i] += hashi[i - 1];
  }
  for (int i = (1); i < (n + 2); ++i) suma[n][i] = 1;
  for (int i = (n)-1; i >= (0); --i) {
    if (s[i] == '0') continue;
    for (int len = (1); len < (n - i + 1); ++len) {
      dp[i][len] = suma[i + len][len + 1];
      if (f(i, len)) dp[i][len] = add(dp[i][len], dp[i + len][len]);
    }
    for (int len = (n + 1) - 1; len >= (1); --len)
      suma[i][len] = add(suma[i][len + 1], dp[i][len]);
  }
  int ans = 0;
  for (int len = (1); len < (n + 1); ++len) ans = add(ans, dp[0][len]);
  cout << ans << endl;
  cerr << "Time elapsed: " << clock() / (double)CLOCKS_PER_SEC << endl;
  return 0;
}
