#include <bits/stdc++.h>
using namespace std;
const int maxN = 5005;
int n, memo[maxN][maxN], memo2[maxN][maxN], mod = 1e9 + 7;
string x;
int solve2(int i, int j) {
  if (j >= n) return 1e9;
  int &ret = memo2[i][j];
  if (~ret) return ret;
  if (x[j] > x[i]) return ret = 0;
  if (x[i] > x[j]) return ret = 1e9;
  return ret = 1 + solve2(i + 1, j + 1);
}
int solve(int idx, int cnt) {
  if (idx + cnt > n) return 0;
  if (idx + cnt == n) return 1;
  int &ret = memo[idx][cnt];
  if (~ret) return ret;
  ret = solve(idx, cnt + 1);
  if (x[idx + cnt] == '0') return ret;
  int j = idx + cnt;
  int k = solve2(idx, j);
  if (k < cnt)
    ret += solve(j, cnt);
  else
    ret += solve(j, cnt + 1);
  if (ret >= mod) ret -= mod;
  return ret;
}
int main() {
  memset(memo, -1, sizeof memo);
  memset(memo2, -1, sizeof memo2);
  scanf("%d", &n);
  cin >> x;
  cout << solve(0, 1);
}
