#include <bits/stdc++.h>
using namespace std;
template <typename T>
T sqr(const T &a) {
  return a * a;
}
const long double pi = acos(-1.0);
const int maxn = 5010;
int dp[maxn][maxn], sd[maxn][maxn];
int M = 1488148811, p = 13;
unsigned long long H[maxn], pows[maxn];
int N;
char s[maxn];
void precalc() {
  pows[0] = 1;
  for (decltype(N) i = 1; i <= N; i++) pows[i] = pows[i - 1] * p;
  H[0] = s[0] - '0' + 1;
  for (decltype(N - 1) i = 1; i <= N - 1; i++) {
    H[i] = H[i - 1] * p + s[i] - '0' + 1;
  }
}
inline unsigned long long getH(int i, int j) {
  return (H[j] - (i == 0 ? 0 : H[i - 1] * pows[j - i + 1]));
}
bool comp(int i, int j, int len) {
  int l = 0, r = len + 1;
  while (r > l + 1) {
    int m = (l + r) >> 1;
    if (getH(i, i + m - 1) == getH(j, j + m - 1))
      l = m;
    else
      r = m;
  }
  return (l == len ? false : s[i + l] < s[j + l]);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin >> N;
  string t;
  cin >> t;
  for (decltype(N) i = 0; i < N; i++) s[i] = t[i];
  precalc();
  int M = 1E9 + 7;
  for (decltype(N) i = 0; i < N; i++) {
    for (decltype(i) l = 1; l <= i; l++) {
      if (l != 1 && s[i - l + 1] == '0') continue;
      dp[i][l] = (dp[i][l] + sd[i - l][min(i - l + 1, l - 1)]) % M;
      if (i - (l << 1) + 1 >= 0 && (l == 1 || s[i - (l << 1) + 1] != '0') &&
          comp(i - (l << 1) + 1, i - l + 1, l))
        dp[i][l] = (dp[i][l] + dp[i - l][l]) % M;
    }
    dp[i][i + 1] = 1;
    for (decltype(i + 1) l = 1; l <= i + 1; l++)
      sd[i][l] = (sd[i][l - 1] + dp[i][l]) % M;
  }
  cout << sd[N - 1][N] << endl;
  return 0;
}
