#include <bits/stdc++.h>
using namespace std;
const int MAXN = 5005;
const int MOD = 1000000007;
int n, dp[MAXN][MAXN], dp2[MAXN][MAXN];
long long assoc[MAXN], power[MAXN];
string arr;
bool isokay(int x, int y, int idx) {
  int mx = 0;
  for (int st = 0, en = y - x + 1; st <= en;) {
    int mid = (st + en) / 2;
    long long lef = assoc[x + mid - 1] - assoc[x - 1] * power[mid];
    long long righ = assoc[idx + mid - 1] - assoc[idx - 1] * power[mid];
    if (lef == righ) {
      mx = max(mx, mid);
      st = mid + 1;
    } else
      en = mid - 1;
  }
  if (mx == y - x + 1) return 0;
  return (arr[x + mx] > arr[idx + mx]);
}
int main() {
  cin >> n >> arr;
  arr = "0" + arr;
  power[0] = 1;
  for (int i = 1; i <= n; i++) {
    power[i] = power[i - 1] * 3731;
    assoc[i] = assoc[i - 1] * 3731 + arr[i];
  }
  for (int i = 0; i <= n; i++) dp[0][0] = dp2[0][i] = 1;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= i; j++) {
      if (arr[i - j + 1] != '0') {
        dp[i][j] = dp2[i - j][j - 1];
        if (i < 2 * j)
          dp[i][j] += dp[i - j][j];
        else if (isokay(i - j + 1, i, i - 2 * j + 1))
          dp[i][j] += dp[i - j][j];
        dp[i][j] %= MOD;
      }
    }
    for (int j = 1; j <= n; j++) dp2[i][j] = (dp2[i][j - 1] + dp[i][j]) % MOD;
  }
  cout << dp2[n][n] << "\n";
  return 0;
}
