#include <bits/stdc++.h>
using namespace std;
const int nax = 5005;
const int mod = 1e9 + 7;
const int inf = 1e9 + 120;
int t[nax];
char sl[nax];
int pref[nax][nax];
int nxt[nax][nax];
int cmp(int i, int j) {
  if (t[i] < t[j]) return -1;
  if (t[i] > t[j]) return 1;
  return 0;
}
int dp(int a, int b) {
  int x = pref[a][b] - pref[a - 1][b];
  if (x < 0) x += mod;
  return x;
}
int main() {
  int n;
  scanf("%d", &n);
  scanf("%s", sl);
  for (int i = (1); i <= ((n)); ++i) t[i] = sl[i - 1] - '0';
  for (int a = n; a >= 1; --a)
    for (int b = n; b > a; --b) {
      int& x = nxt[a][b];
      if (t[a] != t[b])
        x = a;
      else if (b == n)
        x = inf;
      else
        x = nxt[a + 1][b + 1];
    }
  for (int i = (1); i <= ((n)); ++i) {
    for (int j = (1); j <= ((n)); ++j) pref[j][i] = 1;
  }
  for (int c = (2); c <= (n); ++c)
    for (int d = (c); d <= (n); ++d) {
      int& x = pref[c][d];
      int b = c - 1;
      int a = b - (d - c);
      x = pref[b][b] - pref[max(a, 0)][b];
      if (x < 0) x += mod;
      if (a >= 1) {
        int where = nxt[a][c];
        if (where < c && t[where] < t[c + where - a]) {
          x += dp(a, b);
          if (x >= mod) x -= mod;
        }
      }
      if (t[c] == 0) x = 0;
      pref[c][d] = x + pref[c - 1][d];
      if (pref[c][d] >= mod) pref[c][d] -= mod;
    }
  int ans = 0;
  for (int i = (1); i <= ((n)); ++i) ans = (ans + dp(i, n)) % mod;
  printf("%d\n", ans);
  return 0;
}
