#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
int zet[5010], sum[5010][5010], d[5010][5010];
char v[5010], bun[5010][5010];
int main() {
  int n, sol = 0;
  scanf("%d\n%s", &n, v + 1);
  for (int i = 1; i <= n; i++) {
    zet[i] = 0;
    int x = i;
    for (int j = i + 1; j <= n; j++) {
      if (j <= x + zet[x] - 1)
        zet[j] = min(x + zet[x] - j, zet[i + j - x]);
      else
        zet[j] = 0;
      while (j + zet[j] <= n && v[j + zet[j]] == v[i + zet[j]]) zet[j]++;
      if (x + zet[x] - 1 < j + zet[j] - 1) x = j;
    }
    for (int j = 1; i + 2 * j - 1 <= n; j++)
      if (zet[i + j] < j && v[i + zet[i + j]] < v[i + j + zet[i + j]])
        bun[i][i + j - 1] = 1;
  }
  sum[1][1] = 1;
  for (int i = 1; i <= n; i++)
    if (v[i] != '0') {
      int s = 0;
      for (int j = i; j <= n; j++) {
        s += sum[i][j];
        if (s >= mod) s -= mod;
        d[i][j] = s;
        if (v[j + 1] != '0' && 2 * j - i <= n) {
          if (bun[i][j]) {
            sum[j + 1][2 * j - i + 1] += s;
            if (sum[j + 1][2 * j - i + 1] >= mod)
              sum[j + 1][2 * j - i + 1] -= mod;
          } else {
            sum[j + 1][2 * j - i + 2] += s;
            if (sum[j + 1][2 * j - i + 2] >= mod)
              sum[j + 1][2 * j - i + 2] -= mod;
          }
        }
      }
    }
  for (int i = 1; i <= n; i++) {
    sol += d[i][n];
    if (sol >= mod) sol -= mod;
  }
  printf("%d", sol);
  return 0;
}
