#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <stdio.h>
#include <cmath>
#include <math.h>
#include <map>
#include <vector>
#include <set>
#include <string>
#include <string.h>
#include <cstring>
#include <algorithm>
#include <time.h>
#include <ctime>
#include <list>
#include <fstream>
#define fname "1"
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define in scanf
#define out printf
#define y1 dasdasfasfas
#define x1 wqdadfasfasfas
using namespace std;
typedef long long ll;
inline double Time() {return ((clock() * 1.0) / CLOCKS_PER_SEC);}
const int N = 100500, MOD = 1000000007, inf = 2000000000;
char CH[5100];
string S;
int n, d[5100][5100];
bool was[5100][5100];
ll h[5100], deg[5100];
const ll P = 2017ll, base = 1e18 + 7ll;
ll mod(ll x) {
return ((x % base) + base) % base;
}
ll mult(ll x, ll y, ll M) {
if (x < y) {
swap(x, y);
}
ll rec = 0ll;
while (y) {
if (y & 1) {
y--;
rec += x;
rec = mod(rec);
}
else {
x += x;
x = mod(x);
y /= 2ll;
}
}
return rec;
}
bool H(int l, int r, int L, int R) {
return mod(h[r] - mult(h[l - 1], deg[r - l + 1], base)) == mod(h[R] - mult(h[L - 1], deg[R - L + 1], base));
}
bool check(int l, int r, int L, int R) {
if (l < 1) {
return 0;
}
int lt = 0;
int rt = r - l;
int rec = -1;
while (lt <= rt) {
int mid = ((lt + rt) / 2);
if (H(l, l + mid, L, L + mid)) {
lt = mid + 1;
}
else {
rt = mid - 1;
rec = mid;
}
}
if (rec == -1 || S[l + rec - 1] > S[L + rec - 1]) {
return 0;
}
return 1;
}
int DP(int MAX, int cur, int done) {
if (cur < 1 || MAX < 1 || S[cur - 1] == '0') {
return 0ll;
}
if (was[MAX][cur]) {
return d[MAX][cur];
}
was[MAX][cur] = 1;
if (cur == 1) {
return d[MAX][cur] = 1;
}
for (int er = 1; er < MAX; er++) {
d[MAX][cur] += DP(er, cur - er, cur - 1);
while (d[MAX][cur] >= MOD) {
d[MAX][cur] -= MOD;
}
}
if (check(cur - MAX, cur - 1, cur, done)) {
d[MAX][cur] += DP(MAX, cur - MAX, cur - 1);
while (d[MAX][cur] >= MOD) {
d[MAX][cur] -= MOD;
}
}
return d[MAX][cur];
}
int main() {
srand(time(NULL));
#ifndef ONLINE_JUDGE
freopen(".in", "r", stdin);
freopen(fname".out", "w", stdout);
#endif
scanf("%d\n%s", &n, CH);
S = CH;
deg[0] = 1ll;
for (int i = 1; i <= n; i++) {
deg[i] = mult(deg[i - 1], P, base);
h[i] = mult((h[i - 1] + ll(S[i - 1])), P, base);
}
int answer = 0;
for (int i = 1; i <= n; i++) {
answer += DP(i, n - i + 1, n);
while (answer >= MOD) {
answer -= MOD;
}
}
printf("%d", answer);
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8Y3N0ZGxpYj4KI2luY2x1ZGUgPGNzdGRpbz4KI2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxjbWF0aD4KI2luY2x1ZGUgPG1hdGguaD4KI2luY2x1ZGUgPG1hcD4KI2luY2x1ZGUgPHZlY3Rvcj4KI2luY2x1ZGUgPHNldD4KI2luY2x1ZGUgPHN0cmluZz4KI2luY2x1ZGUgPHN0cmluZy5oPgojaW5jbHVkZSA8Y3N0cmluZz4KI2luY2x1ZGUgPGFsZ29yaXRobT4KI2luY2x1ZGUgPHRpbWUuaD4KI2luY2x1ZGUgPGN0aW1lPgojaW5jbHVkZSA8bGlzdD4KI2luY2x1ZGUgPGZzdHJlYW0+CgojZGVmaW5lIGZuYW1lICIxIgojZGVmaW5lIHBiIHB1c2hfYmFjawojZGVmaW5lIG1wIG1ha2VfcGFpcgojZGVmaW5lIEYgZmlyc3QKI2RlZmluZSBTIHNlY29uZAojZGVmaW5lIGluIHNjYW5mCiNkZWZpbmUgb3V0IHByaW50ZgojZGVmaW5lIHkxIGRhc2Rhc2Zhc2ZhcwojZGVmaW5lIHgxIHdxZGFkZmFzZmFzZmFzCgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKdHlwZWRlZiB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