#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fll;
const int MAXN = 5010, LOG = 15;
const int MOD = (int)1e9 + 7;
string str;
int len;
int cmp[LOG][MAXN];
long long dp[MAXN][MAXN];
inline bool compare(int i, int j, int sz) {
  if (sz == 0) return 0;
  int e = 31 - __builtin_clz(sz);
  if (cmp[e][i] != cmp[e][j]) return cmp[e][i] < cmp[e][j];
  return cmp[e][i + sz - (1 << e)] < cmp[e][j + sz - (1 << e)];
}
int main() {
  scanf("%d", &len);
  cin >> str;
  for (int e = 0; e < LOG; e++) {
    int sz = (1 << e);
    vector<pair<string, int> > v;
    for (int i = 0; i + sz <= len; i++)
      v.push_back(make_pair(str.substr(i, sz), i));
    sort(v.begin(), v.end());
    int cur = 0;
    for (int i = 0; i < (int)v.size(); i++) {
      if (i > 0 && v[i - 1].first == v[i].first) cur--;
      cmp[e][v[i].second] = cur++;
    }
  }
  for (int pos = len - 1; pos >= 0; pos--) {
    if (str[pos] == '0') continue;
    for (int q = len; q > 0; q--) {
      if (q > len - pos) continue;
      if (q == len - pos) {
        dp[q][pos] = 1;
        continue;
      }
      dp[q][pos] = dp[q + 1][pos];
      if (pos + 2 * q <= len) {
        if (compare(pos, pos + q, q))
          dp[q][pos] += dp[q][pos + q];
        else
          dp[q][pos] += dp[q + 1][pos + q];
        dp[q][pos] %= MOD;
      }
    }
  }
  cout << dp[1][0] << endl;
  return 0;
}
