#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:256000000")
using namespace std;
const int MOD = 1000 * 1000 * 1000 + 7;
const int MOD2 = 1000 * 1000 * 1000 + 9;
const int N = 5010;
const int K = 20;
const long long M1 = 13;
const long long M2 = 17;
int n;
string s;
int dp[N][N];
int sdp[N][N];
long long h1[N], h2[N], m1[N], m2[N];
void build() {
  h1[0] = (s[0] - '0');
  h2[0] = (s[0] - '0');
  m1[0] = m2[0] = 1;
  for (int i = 1; i < n; ++i) {
    m1[i] = m1[i - 1] * M1 % MOD;
    m2[i] = m2[i - 1] * M2 % MOD2;
    h1[i] = (h1[i - 1] + (s[i] - '0') * m1[i] % MOD) % MOD;
    h2[i] = (h2[i - 1] + (s[i] - '0') * m2[i] % MOD2) % MOD2;
  }
}
bool isEq(int p1, int p2, int len) {
  assert(p1 + len <= p2);
  const long long f2 = (h1[p2 + len - 1] - h1[p2 - 1] + MOD) % MOD;
  const long long g2 = (h2[p2 + len - 1] - h2[p2 - 1] + MOD2) % MOD2;
  const long long f1 =
      (h1[p1 + len - 1] - (p1 == 0 ? 0 : h1[p1 - 1]) + MOD) % MOD;
  const long long g1 =
      (h2[p1 + len - 1] - (p1 == 0 ? 0 : h2[p1 - 1]) + MOD2) % MOD2;
  const int d = p2 - p1;
  return (f1 * m1[d] % MOD) == f2 && (g1 * m2[d] % MOD2) == g2;
}
bool isLess(int p1, int len1, int p2, int len2) {
  assert(len1 == len2);
  const int len = len1;
  assert(p1 + len <= p2);
  assert(p2 + len <= n);
  if (s[p1] != s[p2]) {
    return s[p1] < s[p2];
  }
  if (isEq(p1, p2, len)) {
    return false;
  }
  int l = 1, r = len;
  while (r - l > 1) {
    int mid = (l + r) / 2;
    if (isEq(p1, p2, mid)) {
      l = mid;
    } else {
      r = mid;
    }
  }
  return s[p1 + r - 1] < s[p2 + r - 1];
}
void calc() {
  for (int i = 0; i < n; ++i) {
    dp[i][0] = 1;
  }
  sdp[0][0] = 1;
  for (int i = 1; i < n; ++i) {
    for (int j = i; j > 0; --j) {
      if (s[j] == '0') {
        dp[i][j] = 0;
        sdp[i][j] = sdp[i][j + 1];
        continue;
      }
      int len = i - j + 1;
      if (i + 1 - 2 * len >= 0) {
        int p2 = i + 1 - 2 * len;
        dp[i][j] = isLess(p2, len, j, len) ? dp[j - 1][p2] : 0;
        if (len > 1) {
          dp[i][j] = (dp[i][j] + sdp[j - 1][p2 + 1]) % MOD;
        }
      } else {
        dp[i][j] = sdp[j - 1][0];
      }
      sdp[i][j] = (dp[i][j] + sdp[i][j + 1]) % MOD;
    }
    sdp[i][0] = (dp[i][0] + sdp[i][1]) % MOD;
  }
}
int main() {
  cin >> n >> s;
  build();
  calc();
  cout << sdp[n - 1][0] << endl;
  return 0;
}
