#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
const long long MOD = 1000000000 + 7;
const int MAXN = 5000 + 10;
int n;
char s[MAXN];
long long bef[MAXN];
long long f[MAXN];
int q[MAXN];
void init(int l) {
  memset(q, 0, sizeof(q));
  for (int i = 1; i <= (int)(n); i++) {
    if (i + l > n) break;
    if (s[i] == s[i + l])
      q[i] = 0;
    else if (s[i] > s[i + l])
      q[i] = 2;
    else
      q[i] = 1;
  }
  for (int i = 0; i < (int)(n); i++) q[i] = q[i - 1] + q[i];
}
bool check(int i, int l) {
  if (s[i - l] == '0') return false;
  int tmp = upper_bound(q + i - l, q + i, q[i - l - 1]) - q;
  if (tmp == i) return false;
  return q[tmp] - q[i - l - 1] == 1;
}
int main() {
  scanf("%d", &n);
  s[0] = '0' - 2;
  scanf("%s", s + 1);
  memset(bef, 0, sizeof(bef));
  bef[0] = 0;
  bef[1] = 1;
  long long sum = 0;
  for (int i = 2; i <= n; i++)
    if (bef[i - 1])
      if (s[i] > s[i - 1]) bef[i] = bef[i - 1];
  for (int l = 2; l <= n; l++) {
    memset(f, 0, sizeof(f));
    init(l);
    for (int i = 1; i <= n - l + 1; i++)
      if (s[i] != '0') {
        if (i == 1)
          f[i] = 1;
        else
          f[i] = bef[i - 1];
        if (i > l)
          if (check(i, l)) f[i] = (f[i - l] + f[i]) % MOD;
      }
    for (int i = 1; i <= n - l + 1; i++) bef[i + l - 1] += f[i];
    for (int i = 1; i <= n - l + 1; i++) bef[i + l - 1] %= MOD;
  }
  sum = bef[n] % MOD;
  cout << sum << endl;
}
