#include #include #include #include #include #include #include #include using namespace std; //Manber & Myers //O(n (log n)^2) class SuffixArray{ public: vector sa; vector lcp; vector rank; SuffixArray(const string& SS) : S(SS), len(SS.size()), sa(SS.size()+1), lcp(SS.size()+1), rank(SS.size()+1) { constract_sa(); constract_lcp(); } void dbg_print(){ for(int i=0; i<=len; i++){ cerr << S.substr(sa[i]) << " " << lcp[i] << endl; } } private: const string& S; int len; //Manber & Myers //O(len (logN)^2) void constract_sa(){ //first character for(int i=0; i<=len; i++){ sa[i] = i; rank[i] = (i tmp(len+1); for(int k=1; k<=len; k *= 2){ auto cmp_func = [&](int x, int y) -> bool{ if(rank[x] != rank[y]) return rank[x] < rank[y]; int l = (x+k <= len) ? rank[x+k] : -1; int r = (y+k <= len) ? rank[y+k] : -1; return l < r; }; sort(sa.begin(), sa.end(), cmp_func); tmp[sa[0]] = 0; for(int i=1; i<=len; i++){ tmp[sa[i]] = tmp[sa[i-1]] + (cmp_func(sa[i-1],sa[i])==true?1:0); } for(int i=0; i<=len; i++){ rank[i] = tmp[i]; } } } void constract_lcp(){ for(int i=0; i<=len; i++) rank[sa[i]] = i; int h=0; lcp[0] = 0; for(int i=0; i0) h--; for(; j+h class SegmentTree{ int n; vector V; Value DEFAULT_VALUE; //evaluation function static Value default_evaluate(Value a, Value b){ return max(a,b); } function< Value(Value, Value) > evaluate; //return evaluated value in [a,b) //T[at] covers [l,r) Value RangeEvaluation(int a, int b, int at, int l, int r){ //out of range if(r <= a || b <= l) return DEFAULT_VALUE; //covered if(a <= l && r <= b) return V[at]; //partially covered else{ Value val_left = RangeEvaluation(a,b, at*2+1, l, (l+r)/2); Value val_right = RangeEvaluation(a,b, at*2+2, (l+r)/2, r); return evaluate(val_left, val_right); } } public: SegmentTree(int size, Value DEFAULT = 0, function< Value(Value, Value) > eval = default_evaluate){ DEFAULT_VALUE = DEFAULT; evaluate = eval; n=1; while(n(2*n - 1, DEFAULT_VALUE); } void update(int at, Value new_val){ at += n-1; V[at] = new_val; while(at>0){ at = (at-1)/2; V[at] = evaluate(V[at*2 + 1], V[at*2 + 2]); } } //return evaluated value in [l,r) Value RangeEvaluation(int l, int r){ if(l>=r) return DEFAULT_VALUE; if(l>=n) return DEFAULT_VALUE; return RangeEvaluation(l,r, 0, 0, n); } }; const long long mod = 1000000007; int main(){ string s; cin >> s; int n = s.size(); assert(1<=n && n<=10000); for(char c : s) assert('a'<=c && c<='z'); SuffixArray sa(s); SegmentTree sg(n+1, 114514, [](int a, int b){return min(a,b);}); for(int i=0; i dp(n+1, 0); dp[0] = 1; long long ans = 1; for(int i=1; i<=n/2; i++){ for(int j=0; jrb) swap(ra,rb); int len = i-j; int lcp = sg.RangeEvaluation(ra,rb); if(lcp>=len){ dp[i] += dp[j]; if(dp[i] >= mod) dp[i] -= mod; } } ans += dp[i]; if(ans>=mod) ans -= mod; } printf("%lld", ans); return 0; }