#include <bits/stdc++.h>
using namespace std;
const int P = 17;
const long long MOD = 1e9 + 7;
int F[5005][5005], G[5005][5005];
long long p[5005], h[5005];
int n;
string s;
void initHash() {
  for (int i = 0; i < n; i++) {
    h[i] = (s[i] - '0' + 1) * p[i];
    if (i) h[i] += h[i - 1];
  }
}
long long calHash(int x, int y) {
  long long res = h[y];
  if (x) res -= h[x - 1];
  return res;
}
bool better(int x, int y, int _x, int _y) {
  int l = 1, r = y - x + 1, mid, change = x - _x;
  while (l + 1 < r) {
    mid = (l + r) >> 1;
    long long pre = calHash(_x, _x + mid - 1) * p[change],
              cur = calHash(x, x + mid - 1);
    if (pre != cur)
      r = mid;
    else
      l = mid;
  }
  if (calHash(_x, _x + r - 1) * p[change] == calHash(x, x + r - 1)) {
    if (_x + r < x) return s[_x + r] < s[x + r];
  } else if (calHash(_x, _x + l - 1) * p[change] == calHash(x, x + l - 1)) {
    if (_x + l < x) return s[_x + l] < s[x + l];
  } else {
    return s[_x] < s[x];
  }
  return 0;
}
int main() {
  ios::sync_with_stdio(0);
  cin >> n >> s;
  p[0] = 1;
  for (int i = 1; i <= n; i++) p[i] = p[i - 1] * P;
  initHash();
  F[1][1] = G[1][1] = 1;
  for (int i = 2; i <= n; i++) {
    for (int j = i; j > 1; j--) {
      int len = i - j + 1;
      int X = j - len;
      int nearest = max(X + 1, 1);
      if (s[j - 1] != '0') {
        F[j][i] = G[nearest][j - 1];
        if (X >= 1 && better(j - 1, i - 1, X - 1, j - 2))
          F[j][i] = (F[j][i] + F[X][j - 1]) % MOD;
      }
      G[j][i] = F[j][i];
      if (j + 1 <= i) G[j][i] = (G[j + 1][i] + G[j][i]) % MOD;
    }
    F[1][i] = 1;
    G[1][i] = (G[2][i] + 1) % MOD;
  }
  cout << G[1][n] << '\n';
  return 0;
}
