#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
const int MAXN = 5005;
const int MOD = 1000000007;
string t;
int z[2 * MAXN];
void zf() {
  memset(z, 0, sizeof(z));
  int len = t.length();
  for (int i = 1, l = 0, r = 0; i < len; ++i) {
    if (i <= r) z[i] = min(r - i + 1, z[i - l]);
    while (i + z[i] < len && t[z[i]] == t[i + z[i]]) ++z[i];
    if (i + z[i] - 1 > r) l = i, r = i + z[i] - 1;
  }
}
int n;
string s;
int dp[MAXN][MAXN], sum[MAXN];
void solve() {
  memset(dp, 0, sizeof(dp));
  for (int i = 1; i <= n; i++) {
    dp[0][i] = 1;
  }
  for (int i = 1; i < n; i++) {
    if (s[i] == '0') {
      continue;
    }
    memset(sum, 0, sizeof(sum));
    for (int j = 1; j <= i; j++) {
      sum[j] = dp[i - j][j];
    }
    for (int j = 1; j <= n - i; j++) {
      sum[j] = (sum[j] + sum[j - 1]) % MOD;
    }
    t = s.substr(i) + "#" + s.substr(0, i);
    zf();
    for (int j = 1; j <= n - i; j++) {
      dp[i][j] = sum[j - 1];
    }
    for (int j = 1; j <= i; j++) {
      if (z[n + 1 - j] < j && s[i - j + z[n + 1 - j]] < s[i + z[n + 1 - j]]) {
        dp[i][j] = (dp[i][j] + dp[i - j][j]) % MOD;
      }
    }
  }
  int ans = 0;
  for (int j = 1; j <= n; j++) {
    ans = (ans + dp[n - j][j]) % MOD;
  }
  printf("%d\n", ans);
}
int main() {
  while (cin >> n >> s) {
    solve();
  }
}
