#include <bits/stdc++.h>
using namespace std;
const int M = 1e9 + 7, x = 123;
int n;
char s[5555];
int dp[5050][5050], lcp[5050][5050];
inline void up(int &x, int y) {
  x += y;
  if (x >= M) x -= M;
}
int main() {
  scanf("%d", &n);
  scanf("%s", s + 1);
  for (int i = 1; i < n; i++) lcp[i][n] = s[i] == s[n];
  for (int i = n - 1; i >= 1; i--)
    for (int j = i - 1; j >= 1; j--) {
      lcp[j][i] = s[i] == s[j] ? (lcp[j + 1][i + 1] + 1) : 0;
    }
  for (int i = 1; i <= n; i++) dp[i][i] = s[1] != '0';
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j < i; j++) {
      if (s[i - j + 1] == '0') {
        dp[i][j] = 0;
        continue;
      }
      up(dp[i][j], dp[i - j][j - 1]);
      if (i >= j + j) {
        int l2 = i - j + 1, r2 = i;
        int r1 = l2 - 1, l1 = r1 - j + 1;
        if (lcp[l1][l2] >= j) continue;
        int tp = lcp[l1][l2];
        if (s[l1 + tp] >= s[l2 + tp]) continue;
        up(dp[i][j], (dp[r1][j] - dp[r1][j - 1] + M) % M);
      }
    }
    for (int j = 1; j <= n; j++) up(dp[i][j], dp[i][j - 1]);
  }
  printf("%d\n", dp[n][n]);
}
