#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
int lcp[5000][5000];
int ways[5000][5000];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int n;
  string s;
  cin >> n >> s;
  for (int i = n - 1; i >= 0; i--)
    for (int j = n - 1; j >= 0; j--)
      if (s[i] != s[j])
        lcp[i][j] = 0;
      else
        lcp[i][j] = lcp[i + 1][j + 1] + 1;
  for (int l2 = 0; l2 < n; l2++)
    if (s[l2] != '0') {
      int sum = 0;
      for (int r2 = l2; r2 < n; r2++) {
        if (l2 == 0) {
          ways[l2][r2] = 1;
          continue;
        }
        ways[l2][r2] = sum;
        int cur_size = r2 - l2 + 1;
        int l1 = l2 - cur_size;
        if (l1 >= 0) {
          sum += ways[l1][l2 - 1];
          if (sum >= mod) sum -= mod;
          int d = min(cur_size - 1, lcp[l1][l2]);
          if (s[l2 + d] > s[l1 + d]) ways[l2][r2] = sum;
        }
      }
    }
  int grand_total = 0;
  for (int i = 0; i < n; i++) {
    grand_total += ways[i][n - 1];
    if (grand_total >= mod) grand_total -= mod;
  }
  cout << grand_total;
}
