#include <bits/stdc++.h>
using namespace std;
const int N = 5000 + 10;
const int BASE = 1e9 + 7;
int n;
int memo[N][N], _memo[N][N];
string s;
int _solve(int pos_1, int pos_2) {
  if (pos_1 > n || pos_2 > n) return 0;
  if (_memo[pos_1][pos_2] != -1) return _memo[pos_1][pos_2];
  int cur = 0;
  if (s[pos_1] == s[pos_2]) cur += _solve(pos_1 + 1, pos_2 + 1) + 1;
  return _memo[pos_1][pos_2] = cur;
}
int solve(int pos, int len) {
  if (s[pos] == '0') return 0;
  if (pos + len - 1 > n) return 0;
  if (pos + len - 1 == n) return 1;
  if (memo[pos][len] != -1) return memo[pos][len];
  int cur = 0;
  cur = (cur + solve(pos, len + 1)) % BASE;
  if (pos + 2 * len - 1 <= n) {
    int tmp = _solve(pos, pos + len);
    if (tmp < len && s[pos + tmp] < s[pos + len + tmp]) {
      cur = (cur + solve(pos + len, len)) % BASE;
    } else
      cur = (cur + solve(pos + len, len + 1)) % BASE;
  }
  return memo[pos][len] = cur;
}
int main() {
  ios ::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> s;
  s = "@" + s;
  memset(memo, -1, sizeof(memo));
  memset(_memo, -1, sizeof(_memo));
  cout << solve(1, 1);
}
