#include <bits/stdc++.h>
using namespace std;
int dp[5123][5123];
int nxt[5123][5123];
string s;
inline int add(int a, int b) {
  if (a + b >= 1000000007) {
    return a + b - 1000000007;
  }
  return a + b;
}
int main() {
  int n, i, j, k, l;
  cin >> n;
  cin >> s;
  s = s + "$";
  dp[n][n] = 1;
  nxt[n][n] = n;
  for (i = n - 1; i >= 0; --i) {
    dp[i][n] = 1;
    dp[i][n + 1] = 0;
    nxt[i][n] = n;
    for (j = n - 1; j > i; --j) {
      if (s[i] == s[j]) {
        nxt[i][j] = nxt[i + 1][j + 1];
      } else {
        nxt[i][j] = j;
      }
      dp[i][j] = dp[i][j + 1];
      if (s[j] == '0' || s[i] == '0') {
        continue;
      }
      k = nxt[i][j];
      l = j - i;
      if (k - j + 1 <= l && k < n) {
        if (s[k] > s[i + k - j]) {
          dp[i][j] = add(dp[i][j], dp[j][min(n + 1, j + l)]);
          continue;
        }
      }
      dp[i][j] = add(dp[i][j], dp[j][min(n + 1, j + l + 1)]);
    }
  }
  cout << dp[0][1] << endl;
  return 0;
}
