#include <bits/stdc++.h>
using namespace std;
const int N = (int)5e3 + 10;
const int mod = (int)1e9 + 7;
int add(int a, int b) {
  a += b;
  if (a < mod) return a;
  return a - mod;
}
int mult(int a, int b) { return (1LL * a * b) % mod; }
char str[N];
int askdjalds[N][N];
int dp[N][N];
int main() {
  int n;
  scanf("%d %s", &n, str);
  for (int i = n - 1; i >= 0; i--)
    for (int s = n - 1; s >= 0; s--) {
      if (str[i] == str[s])
        askdjalds[i][s] = askdjalds[i + 1][s + 1] + 1;
      else
        askdjalds[i][s] = 0;
    }
  dp[0][1] = 1;
  for (int prev = 0; prev < n; prev++) {
    for (int pos = 0; pos <= n; pos++)
      dp[prev][pos] = add(dp[prev][pos], (pos > 0 ? dp[prev][pos - 1] : 0));
    int it = prev + 2;
    for (int pos = prev + 1; pos <= n; pos++) {
      while (it <= n) {
        if (pos - prev > it - pos) {
          it++;
          continue;
        }
        if (pos - prev < it - pos) break;
        int e = askdjalds[prev][pos];
        int curLen = it - pos;
        if (e < curLen && str[pos + e] > str[prev + e]) break;
        it++;
      }
      if (str[pos] != '0') dp[pos][it] = add(dp[pos][it], dp[prev][pos]);
    }
  }
  int ans = 0;
  for (int i = 0; i < n; i++) ans = add(ans, dp[i][n]);
  printf("%d\n", ans);
  return 0;
}
