a = input()
b = input()
litery_a = {}
for litera in 'ABCDEFGHIJKLMNOPQRSTUVWXYZ':
    litery_a[litera] = 0
for litera in a:
    litery_a[litera] += 1
wynik = 0
for litera in b:
    wynik += litery_a[litera]
print(wynik)
