All-pairs suffix/prefix in optimal time using Aho-Corasick space