Language: C

#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<vector>
#define ll __int64
using namespace std ;

const int maxn = 300001 ;
const int mod = 1000000007 ;
ll ans[maxn] ;

struct SAM  {

    int fa[maxn<<1] , val[maxn<<1] , c[26][maxn<<1] ;
    ll cnt[maxn<<1] ; int tot , last ;
    int ws[maxn<<1] , wv[maxn<<1] ;
    vector<int> vec[maxn<<1] ;

    inline int new_node ( int _val ) {
        val[++tot] = _val ;
        for ( int i = 0 ; i < 26 ; i ++ ) c[i][tot] = 0 ;
        cnt[tot] = fa[tot] = 0 ;
        return tot ;
    }

    void add ( int k ) {
        int p = last , i ;
        int np = new_node ( val[p] + 1 ) ;
        while ( p && !c[k][p] ) c[k][p] = np , p = fa[p] ;
        if ( !p ) fa[np] = 1 ;
        else {
            int q = c[k][p] ;
            if ( val[q] == val[p] + 1 ) fa[np] = q ;
            else {
                int nq = new_node ( val[p] + 1 ) ;
                for ( i = 0 ; i < 26 ; i ++ )
                    c[i][nq] = c[i][q] ;
                fa[nq] = fa[q] ;
                fa[q] = fa[np] = nq ;
                while ( p && c[k][p] == q ) c[k][p] = nq , p = fa[p] ;
            }
        }
        last = np ;
    }

    void init () {
        tot = 0 ;
        last = new_node ( 0 ) ;
    }

    void SORT () {
        for ( int i = 0 ; i < maxn ; i ++ ) wv[i] = 0 ;
        for ( int i = 1 ; i <= tot ; i ++ ) wv[val[i]] ++ ;
        for ( int i = 1 ; i < maxn ; i ++ ) wv[i] += wv[i-1] ;
        for ( int i = 1 ; i <= tot ; i ++ ) ws[wv[val[i]]--] = i ;
    }

    void get_cnt ( char *s , int n ) {
        SORT () ;
        int now = 1 , i ;
        memset ( cnt , 0 , sizeof ( cnt ) ) ;
        for ( i = 0 ; i < n ; i ++ ) {
            int k = s[i] - 'a' ;
            now = c[k][now] ;
            cnt[now] ++ ;
        }
        for ( i = tot ; i >= 1 ; i -- ) {
            now = ws[i] ;
            cnt[fa[now]] += cnt[now] ;
        }
    }

    ll cnt_s1[maxn<<1] , cnt_s2[maxn<<1] ;
    void gao ( char *s ) {
        int n = strlen ( s ) ;
        int now = 1 , temp = 0 ;
        for ( int i = 0 ; i < n ; i ++ ) {
            int k = s[i] - 'a' ;
            if ( c[k][now] ) now = c[k][now] , temp ++ ;
            else {
                while ( now && !c[k][now] )
                    now = fa[now] ;
                if ( !now ) now = 1 , temp = 0 ;
                else temp = val[now] + 1 , now = c[k][now] ;
            }
            cnt_s1[fa[now]] ++ ;
            vec[now].push_back ( temp ) ;
        }
        for ( int i = tot ; i >= 1 ; i -- ) {
            now = ws[i] ;
            cnt_s1[fa[now]] += cnt_s1[now] ;
        }
    }
    void gao2 ( char *s ) {
        int n = strlen ( s ) ;
        int now = 1 , temp = 0 ;
        for ( int i = 0 ; i < n ; i ++ ) {
            int k = s[i] - 'a' ;
            if ( c[k][now] ) now = c[k][now] , temp ++ ;
            else {
                while ( now && !c[k][now] ) now = fa[now] ;
                if ( !now ) now = 1 , temp = 0 ;
                else temp = val[now] + 1 , now = c[k][now] ;
            }
            if ( now == 1 ) continue ;
            cnt_s2[fa[now]] ++ ;
            for ( int j = 0 ; j < vec[now].size () ; j ++ ) {
                int l = val[fa[now]] + 1 , r = min ( temp , vec[now][j] ) ;
                if ( l <= r ) {
                   ans[l] = ( ans[l] + cnt[now] ) % mod ;
                    ans[r+1] = ( ans[r+1] - cnt[now] + mod ) % mod ;
                }
            }
            int p = now ;
            int l = val[fa[p]] + 1 , r = min ( temp , val[p] ) ;
            if ( l <= r ) {
                    ans[l] = ( ans[l] + cnt[p] * cnt_s1[p] ) % mod ;
                    ans[r+1] = ( ans[r+1] -cnt[p] * cnt_s1[p] % mod + mod ) % mod ;
            }
        }
        for ( int i = tot ; i >= 1 ; i -- ) {
            now = ws[i] ;
            cnt_s2[fa[now]] += cnt_s2[now] ;
                int l = val[fa[now]] + 1 , r = val[now] ;
                if ( l <= r ) {
                    ans[l] = ( ans[l] + cnt[now] * cnt_s1[now] % mod * cnt_s2[now] ) % mod ;
                    ans[r+1] = ( ans[r+1] - cnt[now] * cnt_s1[now] % mod * cnt_s2[now] % mod + mod ) % mod ;
                }
        }
        for ( int i = 1 ; i <= tot ; i ++ ) {
            for ( int j = 0 ; j < vec[i].size () ; j ++ ) {
                int l = val[fa[i]] + 1 , r = vec[i][j] ;
                if ( l <= r ) {
                    ans[l] = ( ans[l] + cnt[i] * cnt_s2[i] ) % mod ;
                    ans[r+1] = ( ans[r+1] - cnt[i] * cnt_s2[i] % mod + mod ) % mod ;
                }
            }
        }
    }
} ac ;
char s1[maxn] , s2[maxn] ;

int main (){
    ac.init () ;
    scanf ( "%s" , s1 ) ;
    int l = strlen ( s1 ) ;
    int k = l ;
    for ( int i = 0 ; i < l ; i ++ )
        ac.add ( s1[i] - 'a' ) ;
    ac.get_cnt ( s1 , l ) ;
    scanf ( "%s" , s1 ) ;
    l = strlen ( s1 ) ;
    k = min ( k , l ) ;
    ac.gao ( s1 ) ;
    scanf ( "%s" , s1 ) ;
    l = strlen ( s1 ) ;
    k = min ( k , l ) ;
    ac.gao2 ( s1 ) ;
    for ( int i = 1 ; i <= k ; i ++ ) {
        if ( i != 1 ) ans[i] = ( ans[i] + ans[i-1] ) % mod ;
        printf ( "%I64d " , ans[i] ) ;
    }
    puts ( "" ) ;
    return 0 ;
}
/*
aa
aa
aa

abac
abacaba
abcd
asdfsasd
asdasfasd
asdasdasdasd
*/

Compiler output:
main.c:3:9: fatal error: algorithm: No such file or directory
    3 | #include<algorithm>
      |         ^~~~~~~~~~~
compilation terminated.