func_code_string: #include <bits/stdc++.h>   using namespace std;   const long long INF = 1111111111;   const long long MOD = 1e9 + 7;   int pref[5001][5001];   int nxt[5001][5001];   int dp(int i, int j) {     int x;     if (i > 0) {       x = pref[i][j] - pref[i - 1][j];     } else {       x = pref[0][j];     }     x %= MOD;     if (x < 0) {       x += MOD;     }     return x;   }   int digits[5001];   int main() {     ios_base::sync_with_stdio(false);     int n;     cin >> n;     string x;     cin >> x;     for (int i = 1; i <= n; i++) {       digits[i] = x.at(i - 1) -  0 ;     }     for (int i = 0; i < 5001; i++) {       for (int j = 0; j < 5001; j++) {         if (j == 0) {           pref[j][i] = 0;         } else if (i == 0) {           pref[j][i] = 0;         } else {           pref[j][i] = 1;         }       }     }     for (int i = n; i >= 1; i--) {       for (int j = n; j >= i; j--) {         if (digits[i] == digits[j]) {           if (j == n) {             nxt[i][j] = INF;           } else {             nxt[i][j] = nxt[i + 1][j + 1] + 1;           }         } else {           nxt[i][j] = 0;         }       }     }     int a;     int next;     for (int b = 2; b <= n; b++) {       for (int c = b; c <= n; c++) {         if (digits[b] == 0) {           pref[b][c] = pref[b - 1][c];         } else {           a = max(1, 2 * b - c);           pref[b][c] = (pref[b - 1][c] % MOD + pref[b - 1][b - 1] % MOD -                         pref[a - 1][b - 1] % MOD) %                        MOD;           if (2 * b - c - 1 > 0) {             a = 2 * b - c - 1;             next = nxt[a][b];             if (next < INF) {               if (next + a < b && next + b <= c &&                   digits[next + a] < digits[next + b]) {                 pref[b][c] += dp(a, b - 1);                 pref[b][c] %= MOD;               }             }           }         }       }     }     int ans = 0;     for (int i = 1; i <= n; i++) {       ans += dp(i, n);       ans %= MOD;     }     if (ans < 0) {       ans += MOD;     }     cout << ans;     return 0;   }   