#include <bits/stdc++.h>
using namespace std;
string s;
long long int n;
vector<vector<bool>> pre;
long long int gen_base(const long long int before, const long long int after) {
  auto seed =
      std::chrono::high_resolution_clock::now().time_since_epoch().count();
  std::mt19937 mt_rand(seed);
  long long int base =
      std::uniform_int_distribution<long long int>(before + 1, after)(mt_rand);
  return base % 2 == 0 ? base - 1 : base;
}
long long int mod, base, mxPow;
vector<long long int> pow1(1, 1);
vector<unsigned long long int> pow2(1, 1);
struct Polyhash {
  vector<long long int> pref1, pref2;
  long long int n;
  Polyhash(string &s) {
    n = s.size();
    pref1.resize(n + 1);
    pref2.resize(n + 1);
    for (long long int i = 0; i < n; i++) {
      pref1[i + 1] = (pref1[i] + 1LL * s[i] * pow1[i]) % mod;
      pref2[i + 1] = pref2[i] + s[i] * pow2[i];
    }
  }
  pair<long long int, unsigned long long int> findhash(long long int pos,
                                                       long long int len) {
    long long int hash1 = pref1[pos + len] - pref1[pos];
    unsigned long long int hash2 = pref2[pos + len] - pref2[pos];
    if (hash1 < 0) hash1 += mod;
    hash1 = 1LL * hash1 * pow1[mxPow - (pos + len - 1)] % mod;
    hash2 *= pow2[mxPow - (pos + len - 1)];
    return {hash1, hash2};
  }
};
pair<long long int, unsigned long long int> stringtohash(string s) {
  long long int n = s.size(), a = 0;
  unsigned long long int b = 0;
  for (long long int i = 0; i < n; i++) {
    a = (a + 1LL * s[i] * pow1[i]) % mod;
    b = b + s[i] * pow2[i];
  }
  return {a, b};
}
void init_poly(long long int n) {
  mod = (long long int)1e9 + 123;
  mxPow = n;
  base = gen_base(256, mod);
  while ((long long int)pow1.size() <= n) {
    pow1.push_back((pow1.back() * base) % mod);
    pow2.push_back(pow2.back() * base);
  }
}
long long int check(long long int a, long long int b, long long int c,
                    long long int d, Polyhash &w) {
  if (s[a] > s[c]) return 0;
  if (s[a] < s[c]) return 1;
  if (a == b) {
    return 2;
  }
  long long int mid = (b - a + 1) / 2;
  if (w.findhash(a, mid) != w.findhash(c, mid)) {
    long long int k = check(a, a + mid - 1, c, c + mid - 1, w);
    if (k == 1) return 1;
    if (k == 0) return 0;
  }
  if (w.findhash(a + mid, b - a - mid + 1) !=
      w.findhash(c + mid, d - c - mid + 1)) {
    long long int k = check(a + mid, b, c + mid, d, w);
    return k;
  }
  return 0;
}
void Weapons19() {
  cin >> n;
  cin >> s;
  init_poly(n);
  Polyhash w(s);
  pre.resize(n + 1, vector<bool>(n + 1));
  for (long long int i = 1; i < n; i++) {
    if (s[i] > s[i - 1]) pre[i + 1][i + 1] = 1;
  }
  for (long long int i = 2; i <= n; i++) {
    for (long long int j = i + 1; j <= n; j++) {
      if (i - (j - i) - 2 >= 0) {
        long long int x = check(i - (j - i) - 2, i - 2, i - 1, j - 1, w);
        if (x == 1) pre[i][j] = 1;
      }
    }
  }
  vector<vector<long long int>> dp(n + 1, vector<long long int>(n + 1));
  vector<vector<long long int>> cm = dp;
  for (long long int i = 1; i <= n; i++) {
    dp[1][i] = 1;
    cm[1][i] = 1;
  }
  for (long long int i = 1; i <= n; i++) {
    for (long long int j = 2; j <= n; j++) {
      long long int k = j + i - 1;
      if (k > n) continue;
      if (s[j - 1] == '0') {
        if (j != n) cm[j][j + i - 1] += cm[j + 1][j + i - 1];
        cm[j][j + i - 1] %= 1000000007;
        if (j == 2) cm[1][j + i - 1] += cm[2][j + i - 1];
        continue;
      }
      long long int p = j - i + 1, c = 0;
      dp[j][k] += cm[max(1ll, p)][j - 1];
      if (pre[j][k]) dp[j][k] += dp[p - 1][j - 1];
      cm[j][k] = dp[j][k];
      dp[j][k] %= 1000000007;
      if (j != n) cm[j][k] += cm[j + 1][k];
      if (j == 2) cm[1][k] += cm[2][k];
      cm[j][k] %= 1000000007;
    }
  }
  long long int ans = 0;
  for (long long int i = 1; i <= n; i++) {
    ans += dp[i][n];
  }
  cout << ans % 1000000007;
}
int32_t main() {
  cout << fixed << setprecision(16);
  cin.sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  Weapons19();
}
