#include <bits/stdc++.h>
using namespace std;
const int MOD = (int)1e9 + 7;
void MAIN();
int main() {
  MAIN();
  return 0;
}
const int N = 5004;
const int first = (int)1e9 + 7707;
const long long base = 31;
int n, f[N][N], g[N][N], h[N], p[N];
char s[N];
int F(int, int);
int G(int, int);
int G(int i, int j) {
  if (i > n + 1) return 0;
  int &r = g[i][j];
  if (r != -1) return r;
  r = G(i + 1, j) + F(i, j);
  if (r >= MOD) r -= MOD;
  return r;
}
int getHash(int l, int r) {
  return (h[r] - 1LL * h[l - 1] * p[r - l + 1] % first + first) % first;
}
int F(int i, int j) {
  if (i == n + 1) return 1;
  int &r = f[i][j];
  if (r != -1) return r;
  if (s[i] == '0') return r = 0;
  int l = i - j;
  if (i + l > n + 1) return r = 0;
  r = G(i + l + 1, i);
  int L = 0, R = l;
  while (L < R) {
    int m = L + R + 1 >> 1;
    if (getHash(j, j + m - 1) == getHash(i, i + m - 1))
      L = m;
    else
      R = m - 1;
  }
  if (L == l)
    ;
  else if (s[i + L] > s[j + L])
    r += F(i + l, i);
  if (r >= MOD) r -= MOD;
  return r;
}
void MAIN() {
  scanf("%d", &n);
  scanf("%s", s + 1);
  s[0] = '0';
  p[0] = 1;
  for (int i = 1; i <= n; i++) {
    p[i] = p[i - 1] * base % first;
    h[i] = (h[i - 1] * base + s[i] - '0' + 1) % first;
  }
  memset(g, 0xff, sizeof g);
  memset(f, 0xff, sizeof f);
  printf("%d\n", F(1, 0));
}
