class Trie class Node def initialize() @value = 0 @child = {} end attr_accessor :value, :child end def initialize() @root = Node.new end def insert(str) now = @root str.each_char do |c| if now.child[c] == nil now.child[c] = Node.new end now = now.child[c] end now.value = now.value+1 end attr_accessor :root end S = gets M = gets.to_i C = $stdin.read.split(?\n) trie = Trie.new for c in C do trie.insert(c) end N = S.length ans = 0 for i in 0..N-1 do now = trie.root for j in 0..10 do break if now == nil now = now.child[S[i+j]] if now != nil ans += now.value end end end p ans