#include <bits/stdc++.h>
using namespace std;
const int maxn = 5010;
const int mod = 1e9 + 7;
const int mod2 = 1e9 + 13;
char s[maxn];
int nx[maxn];
int dp[maxn][maxn], n;
int hs[maxn][maxn];
void Init() {
  int id = n;
  nx[n] = n;
  for (int i = n - 1; i >= 0; i--) {
    nx[i] = id;
    if (s[i] != '0') id = i;
  }
  for (int i = 0; i <= n - 1; i++) {
    hs[i][i] = s[i] - '0';
    for (int j = i + 1; j <= n - 1; j++)
      hs[i][j] = (10ll * hs[i][j - 1] % mod2 + s[j] - '0') % mod2;
  }
}
int NX(int k) {
  if (k >= n)
    return n;
  else
    return nx[k];
}
bool Cmpr(int s1, int t1, int s2, int t2) {
  if (t1 - s1 != t2 - s2)
    return t1 - s1 < t2 - s2;
  else {
    if (hs[s1][t1] == hs[s2][t2]) return false;
    for (int i = s1; i <= t1; i++) {
      if (s[i] != s[s2 + i - s1]) return s[i] < s[s2 + i - s1];
    }
    return false;
  }
}
void DP() {
  memset(dp, 0, sizeof(dp));
  for (int i = n - 1; i >= 0; i--) {
    if (s[i] == '0') continue;
    dp[i][n - 1] = 1;
    for (int j = i + 1; j <= n - 1; j++) {
      if (s[j] == '0') continue;
      int id = NX(2 * j - i - 1);
      if (Cmpr(i, j - 1, j, id - 1))
        dp[i][j - 1] = dp[j][id - 1];
      else {
        id = NX(id);
        if (Cmpr(i, j - 1, j, id - 1)) dp[i][j - 1] = dp[j][id - 1];
      }
    }
    for (int j = n - 1; j >= i; j--) {
      dp[i][j] = (dp[i][j] + dp[i][j + 1]) % mod;
    }
  }
  int id = nx[0];
  cout << dp[0][id - 1] << endl;
}
int main() {
  scanf("%d", &n);
  scanf("%s", s);
  Init();
  DP();
  return 0;
}
