#include <bits/stdc++.h>
using namespace std;
const int MAXN = 5000 + 5;
long long dp[MAXN][MAXN];
char op[MAXN];
int nxt[MAXN][MAXN];
int main() {
  int n;
  while (scanf("%d", &n) != EOF) {
    scanf("%s", op + 1);
    memset(nxt, 0, sizeof(nxt));
    memset(dp, 0, sizeof(dp));
    for (int i = n; i >= 1; i--) {
      for (int j = n; j >= i; j--) {
        if (op[i] == op[j])
          nxt[i][j] = nxt[i + 1][j + 1] + 1;
        else
          nxt[i][j] = 0;
      }
    }
    for (int j = 1; j <= n; j++) {
      for (int i = 1; i <= j; i++) {
        if (i == 1)
          dp[i][j] = 1;
        else if (op[i] == '0')
          dp[i][j] = 0;
        else {
          int k = max(1, 2 * i - j);
          dp[i][j] =
              (dp[i][j] + dp[i - 1][i - 1] - dp[k - 1][i - 1]) % (1000000007);
          k = 2 * i - j - 1;
          if (k >= 1 && nxt[k][i] <= j - i &&
              op[k + nxt[k][i]] < op[i + nxt[k][i]])
            dp[i][j] += (dp[k][i - 1] - dp[k - 1][i - 1]) % (1000000007);
        }
      }
      for (int i = 1; i <= j; i++)
        dp[i][j] = (dp[i][j] + dp[i - 1][j]) % (1000000007);
    }
    long long ans = dp[n][n];
    ans = (ans % (1000000007) + (1000000007)) % (1000000007);
    printf("%I64d\n", ans);
  }
  return 0;
}
