f=input;s=f();l=len(s);d={*eval("f(),"*int(f()))};print(sum(sum(s[i:i+j+1]in d for j in range(min(10,l-i)))for i in range(l)))