#include <bits/stdc++.h>   using namespace std;   template <class T>   inline T BM(T p, T e, T M) {     long long int ret = 1;     for (; e > 0; e >>= 1) {       if (e & 1) ret = (ret * p) % M;       p = (p * p) % M;     }     return (T)ret;   }   template <class T>   inline T gcd(T a, T b) {     if (b == 0) return a;     return gcd(b, a % b);   }   template <class T>   inline T MDINV(T a, T M) {     return BM(a, M - 2, M);   }   template <class T>   inline T PW(T p, T e) {     long long int ret = 1;     for (; e > 0; e >>= 1) {       if (e & 1) ret = (ret * p);       p = (p * p);     }     return (T)ret;   }   template <class T>   string NTS(T Number) {     stringstream ss;     ss << Number;     return ss.str();   }   template <class T>   T stringtonumber(const string &Text) {     istringstream ss(Text);     T result;     return ss >> result ? result : 0;   }   template <class T>   bool ISLEFT(T a, T b, T c) {     if (((a.first - b.first) * (b.second - c.second) -          (b.first - c.first) * (a.second - b.second)) < 0.0)       return 1;     else       return 0;   }   char a[10009];   int z[10009];   char ch[5000 + 2];   int ar[5000 + 2][5000 + 2];   int res[5000 + 2][5000 + 2];   void zalgo() {     int l, r;     l = r = 0;     z[0] = strlen(a);     for (int i = 1; i < z[0]; i++) {       if (i > r) {         l = r = i;         for (int j = i; j < z[0]; j++) {           if (a[j - i] != a[j])             break;           else             r = j;         }         if (a[i] != a[0])           z[i] = 0;         else           z[i] = r - l + 1;       } else {         int k = i - l;         if (z[k] < r - i + 1) {           z[i] = z[k];         } else {           l = i;           for (int j = r + 1; j < z[0]; j++) {             if (a[j - l] != a[j])               break;             else               r = j;           }           z[i] = r - l + 1;         }       }     }   }   int dp[5009][5009];   void update(int x1, int y1, int val) {     while (y1 <= 5002) {       dp[x1][y1] = (dp[x1][y1] + val) % 1000000007;       y1 += (y1 & -y1);     }   }   int query(int x1, int y1) {     int sum1 = 0;     while (y1 > 0) {       sum1 = (sum1 + dp[x1][y1]) % 1000000007;       y1 -= (y1 & -y1);     }     return sum1;   }   int main() {     int n;     scanf( %d , &n);     scanf( %s , ch + 1);     for (int i = 1; i <= n; i++) {       int sz = 0;       for (int j = i; j <= n; j++) {         a[sz++] = ch[j];       }       int len = sz;       for (int j = i + 1; j <= n; j++) {         a[sz++] = ch[j];       }       a[sz] =   0 ;       zalgo();       for (int j = i + 1; j <= n; j++) {         ar[i][j] = z[len + (j - i - 1)];       }     }     res[0][0] = 1;     for (int i = 1; i <= n; i++) {       if (ch[i] ==  0 ) continue;       for (int j = i; j <= n; j++) {         if (i == 1)           res[i][j] = 1;         else {           int ga = j - i;           int x = i - 1 - ga;           int y = i - 1;           x = max(1, x);           if (y - x == ga) {             int in = x;             int mil = ar[x][i];             if (mil < (ga + 1)) {               if (ch[x + mil] < ch[i + mil]) {                 in = x - 1;               }             }             int sum = query(y, y) - query(y, in);             if (sum < 0) sum += 1000000007;             res[i][j] = sum;           } else {             int sum = query(y, y) - query(y, x - 1);             if (sum < 0) sum += 1000000007;             res[i][j] = sum;           }         }         update(j, i, res[i][j]);       }     }     int su = 0;     for (int i = 1; i <= n; i++) {       su = (su + res[i][n]) % 1000000007;     }     printf( %d n , su);     return 0;   }