#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
int N, dp[5000][5001], cumlcp[5000][5000];
vector<int> sa, ra, rsa, lcp;
string s;
void saInit() {
  int l = (int)s.size();
  sa.resize(l);
  iota(sa.begin(), sa.end(), 0);
  ra.assign(s.begin(), s.end());
  for (int k = 1; k < l; k *= 2) {
    sort(sa.begin(), sa.end(), [&](int a, int b) {
      if (ra[a] != ra[b]) return ra[a] < ra[b];
      int ak = a + k < l ? ra[a + k] : -1;
      int bk = b + k < l ? ra[b + k] : -1;
      return ak < bk;
    });
    vector<int> ra2(l);
    int x = 0;
    for (int i = 1; i < l; i++) {
      if (ra[sa[i]] != ra[sa[i - 1]] || sa[i - 1] + k >= l ||
          ra[sa[i] + k] != ra[sa[i - 1] + k])
        x++;
      ra2[sa[i]] = x;
    }
    ra = ra2;
  }
  rsa.resize(l);
  for (int i = 0; i < int(l); i++) rsa[sa[i]] = i;
}
void saLCP() {
  int l = (int)s.size();
  lcp.resize(l);
  vector<int> p(l);
  for (int i = 0; i < l; i++) {
    p[sa[i]] = (i) ? sa[i - 1] : -1;
  }
  int x = 0;
  for (int i = 0; i < l; i++) {
    while (p[i] != -1 && p[i] + x < l && s[i + x] == s[p[i] + x] &&
           s[i + x] != '$')
      x++;
    lcp[rsa[i]] = x;
    if (x) x--;
  }
  for (int i = 0; i < int(l); i++) {
    cumlcp[i][i] = INT_MAX;
    for (int j = i + 1; j < int(l); j++)
      cumlcp[i][j] = min(cumlcp[i][j - 1], lcp[j]);
  }
}
bool ism(int a, int b, int n) {
  int as = a - n + 1, bs = b - n + 1;
  if (as < 0) return false;
  if (rsa[bs] <= rsa[as]) return false;
  return cumlcp[rsa[as]][rsa[bs]] < n;
}
int main() {
  cin >> N >> s;
  saInit();
  saLCP();
  for (int i = 0; i < int(N); i++)
    for (int j = 1; j < int(5001); j++) {
      int& ans = dp[i][j];
      ans = dp[i][j - 1];
      if (j > i + 1) {
        continue;
      } else if (s[i - j + 1] == '0') {
      } else if (j == i + 1) {
        ans = (ans + 1) % MOD;
      } else if (ism(i - j, i, j)) {
        ans = (ans + dp[i - j][j]) % MOD;
      } else {
        ans = (ans + dp[i - j][j - 1]) % MOD;
      }
    }
  cout << dp[N - 1][N] << endl;
}
