Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style.

Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of consecutive characters in a string) in a given text makes our hero especially joyful. Recently he felt an enormous fit of energy while reading a certain text. So Volodya decided to count all powerful substrings in this text and brag about it all day long. Help him in this difficult task. Two substrings are considered different if they appear at the different positions in the text.

For simplicity, let us assume that Volodya's text can be represented as a single string.


-----Input-----

Input contains a single non-empty string consisting of the lowercase Latin alphabet letters. Length of this string will not be greater than 10^6 characters.


-----Output-----

Print exactly one number — the number of powerful substrings of the given string.

Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier.


-----Examples-----
Input
heavymetalisheavymetal

Output
3
Input
heavymetalismetal

Output
2
Input
trueheavymetalissotruewellitisalsosoheavythatyoucanalmostfeeltheweightofmetalonyou

Output
3


-----Note-----

In the first sample the string "heavymetalisheavymetal" contains powerful substring "heavymetal" twice, also the whole string "heavymetalisheavymetal" is certainly powerful.

In the second sample the string "heavymetalismetal" contains two powerful substrings: "heavymetal" and "heavymetalismetal".

Difficulty: EASY
Tags: String algorithms

Amortized analysis

Implementation
Skill types: Amortized analysis

Starter code:

Solutions:
def main():
	line = input()
	final = 0
	count = 0
	for i in range(len(line) - 4):
		if 'heavy' == line[i:i + 5]:
			count += 1
			i += 5
		elif 'metal' == line[i:i + 5]:
			final += count
			i += 5
	print(final)

def __starting_point():
	main()
__starting_point()


s = input()
dic = {}
l = len(s)
i = diclen = sub = 0
while 1:
	if i <= l - 5:
		if s[i:i + 5] == 'heavy':
			dic[i] = 0
			diclen += 1
			i += 5
		elif s[i:i + 5] == 'metal':
			sub += diclen
			i += 5
		else:
			i += 1
	else:
		break
print(sub)


z = r = 0
for w in input().split('heavy'):
	r += w.count('metal') * z
	z += 1
print(r)


s = input()
h = 0
ans = 0
i = 0
for i in range(len(s)):
	if s[i] == 'h' and s[i:i + 5] == 'heavy':
		h += 1
	if s[i] == 'm' and s[i:i + 5] == 'metal':
		if h >= 1:
			ans += h
print(ans)


s = input()
a = 0
su = 0
for i in range(len(s)):
	if s[i:i + 5] == 'heavy':
		a += 1
	elif s[i:i + 5] == 'metal':
		su += a
print(su)


from bisect import bisect_left
s = input()
heavy = []
driver = []
for i in range(len(s)):
	if i + 5 <= len(s):
		if s[i:i + 5] == 'heavy':
			heavy.append(i)
	if i + 5 <= len(s):
		if s[i:i + 5] == 'metal':
			driver.append(i)
ans = 0
for j in heavy:
	x = bisect_left(driver, j)
	ans += len(driver) - x
print(ans)


s = input()
(i, heavy, count) = (0, 0, 0)
while i < len(s):
	temp = s[i:i + 5]
	if temp == 'heavy':
		heavy += 1
		i += 5
	elif temp == 'metal':
		count += heavy
		i += 5
	else:
		i += 1
print(count)


s = input()
ans = 0
s = s.replace('heavy', '1')
s = s.replace('metal', '2')
heavy = []
metal = []
n = len(s)
for i in range(n):
	if s[i] == '1':
		heavy.append(i)
	elif s[i] == '2':
		metal.append(i)
n = len(heavy)
nn = len(metal)
x = 0
l = nn
for item in heavy:
	for i in range(x, nn):
		if metal[i] > item:
			ans += nn - i
			l = i
			break
	x = l
print(ans)


x = input()
a = 'heavy'
b = 'metal'
c = 0
s = 0
for i in range(len(x) - 4):
	if x[i:i + 5] == a:
		c += 1
	if x[i:i + 5] == b:
		s += c
print(s)


import io, os, sys, atexit
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline

@atexit.register
def write():
	sys.__stdout__.write(io.StringIO().getvalue())
from collections import deque as que, defaultdict as vector
from bisect import bisect as bsearch
from heapq import *
inin = lambda : int(input())
inar = lambda : list(map(int, input().split()))
inst = lambda : input().decode().rstrip('\n\r')
INF = float('inf')
_T_ = 1
for _t_ in range(_T_):
	s = inst()
	hv = 0
	ans = 0
	for i in range(len(s) - 4):
		if s[i:i + 5] == 'heavy':
			hv += 1
		if s[i:i + 5] == 'metal':
			ans += hv
	print(ans)


s = input().strip()
H = s.split('heavy')
(co, k) = (0, 0)
for i in H:
	co += i.count('metal') * k
	k += 1
print(co)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
import math
import bisect
mod = 998244353
from collections import Counter
import bisect
from heapq import *
from collections import defaultdict, deque

def okay(x, y):
	if x < 0 or x >= 3:
		return False
	if y < n and mat[x][y] != '.':
		return False
	if y + 1 < n and mat[x][y + 1] != '.':
		return False
	if y + 2 < n and mat[x][y + 2] != '.':
		return False
	return True
from collections import defaultdict
s = input()
h = 0
m = 0
n = len(s)
i = 0
ans = 0
while i < n:
	if s[i] == 'h':
		if i + 4 < n:
			if s[i:i + 5] == 'heavy':
				i += 5
				h += 1
			else:
				i += 1
		else:
			break
	elif s[i] == 'm':
		if i + 4 < n:
			if s[i:i + 5] == 'metal':
				ans += h
				i += 5
			else:
				i += 1
		else:
			break
	else:
		i += 1
print(ans)


s = input()
l = s.split('heavy')
res = 0
for i in range(1, len(l)):
	res += i * l[i].count('metal')
print(res)


a = input()
if 'heavy' not in a:
	print(0)
elif 'metal' not in a:
	print(0)
elif len(a) < 10:
	print(0)
else:
	p = 0
	d = 0
	for k in range(len(a) - 9):
		if d == 0:
			if a[k:k + 5] == 'heavy':
				p += a[k + 5:].count('metal')
				s = a[k + 5:].count('metal')
				d += 1
		elif a[k:k + 5] == 'heavy':
			p += s
		elif a[k:k + 5] == 'metal':
			s -= 1
	print(p)


s = input()
c = ans = 0
for i in range(len(s) - 4):
	if s[i:i + 5] == 'heavy':
		c += 1
	elif s[i:i + 5] == 'metal':
		ans += c
print(ans)


import sys
from collections import Counter
input = sys.stdin.readline
printt = sys.stdout.write

def aa():
	return int(input())

def bb():
	return list(map(int, input().split()))

def cc():
	s = input()
	return s

def dd():
	return map(int, input().split())
s = cc()
h = 0
m = 0
for i in range(len(s) - 4):
	if s[i:i + 5] == 'heavy':
		h += 1
	elif s[i:i + 5] == 'metal':
		m += h
print(str(m) + '\n')


import sys
text = sys.stdin.readline().strip()
i = 0
heavys = 0
result = 0
while i + 5 <= len(text):
	if text[i:i + 5] == 'heavy':
		heavys += 1
		i += 5
	elif text[i:i + 5] == 'metal':
		result += heavys
		i += 5
	else:
		i += 1
print(result)


from functools import reduce
from operator import *
from math import *
from sys import *
from string import *
from collections import *
setrecursionlimit(10 ** 7)
dX = [-1, 1, 0, 0, -1, 1, -1, 1]
dY = [0, 0, -1, 1, 1, -1, -1, 1]
RI = lambda : list(map(int, input().split()))
RS = lambda : input().rstrip().split()
s = RS()[0]
(h, m) = ([], [])
i = s.find('heavy')
while i != -1:
	h.append(i)
	i = s.find('heavy', i + 1)
j = s.find('metal')
while j != -1:
	m.append(j)
	j = s.find('metal', j + 1)
(i, j) = (0, 0)
ans = 0
while i < len(h):
	while j < len(m) and m[j] < h[i]:
		j += 1
	if j < len(m):
		ans += len(m) - j
	i += 1
print(ans)


s = input()
(h, m) = ([], [])
cur = s.find('heavy')
while cur != -1:
	h.append(cur)
	cur = s.find('heavy', cur + 5)
cur = s.find('metal')
while cur != -1:
	m.append(cur)
	cur = s.find('metal', cur + 5)
(mi, val) = (0, 0)
for x in h:
	while mi < len(m) and m[mi] < x:
		mi += 1
	val += len(m) - mi
print(val)


from sys import stdin, stdout
nmbr = lambda : int(stdin.readline())
lst = lambda : list(map(int, stdin.readline().split()))
for _ in range(1):
	s = input()
	n = len(s)
	cnt = ans = 0
	for i in range(n):
		if s[i - 4:i + 1] == 'heavy':
			cnt += 1
		if s[i - 4:i + 1] == 'metal':
			ans += cnt
	print(ans)


s = input()
i = 0
j = len(s) - 1
c = 'metal'
p = 'heavy'
h = []
m = []
while i < len(s) - 4 and j >= 4:
	if s[i:i + 5] == p:
		h.append(i)
	i += 1
	if s[j - 4:j + 1] == c:
		m.append(j)
	j -= 1
c = 0
for i in range(len(m)):
	lower = 0
	upper = len(h) - 1
	while lower <= upper:
		mid = (lower + upper) // 2
		if h[mid] > m[i]:
			upper = mid - 1
		elif h[mid] < m[i]:
			lower = mid + 1
		elif h[mid] == m[i]:
			break
	c += lower
print(c)


import sys

def fastio():
	from io import StringIO
	from atexit import register
	global input
	sys.stdin = StringIO(sys.stdin.read())
	input = lambda : sys.stdin.readline().rstrip('\r\n')
	sys.stdout = StringIO()
	register(lambda : sys.__stdout__.write(sys.stdout.getvalue()))
fastio()

def debug(*var, sep=' ', end='\n'):
	print(*var, file=sys.stderr, end=end, sep=sep)
INF = 10 ** 20
MOD = 10 ** 9 + 7
I = lambda : list(map(int, input().split()))
from math import gcd
from math import ceil
from collections import defaultdict as dd, Counter
from bisect import bisect_left as bl, bisect_right as br
s = input()
ans = 0
heavy = metal = 0
n = len(s)
for i in range(5, n + 1):
	if s[i - 5:i] == 'heavy':
		heavy += 1
	elif s[i - 5:i] == 'metal':
		ans += heavy
print(ans)


import re

def main():
	l = input()
	heavyCnt = 0
	res = 0
	for i in range(4, len(l)):
		if l[i - 4:i + 1] == 'heavy':
			heavyCnt += 1
		if l[i - 4:i + 1] == 'metal':
			res += heavyCnt
	print(res)
main()


aisa = input()
kyu = 0
channa = 0
for i in range(len(aisa) - 4):
	if aisa[i:i + 5] == 'heavy':
		kyu += 1
	if aisa[i:i + 5] == 'metal':
		channa += kyu
print(channa)


def STR():
	return list(input())

def INT():
	return int(input())

def MAP():
	return map(int, input().split())

def MAP2():
	return map(float, input().split())

def LIST():
	return list(map(int, input().split()))

def STRING():
	return input()
import string
import sys
from heapq import heappop, heappush
from bisect import *
from collections import deque, Counter, defaultdict
from math import *
from itertools import permutations, accumulate
dx = [-1, 1, 0, 0]
dy = [0, 0, 1, -1]
s = STR()
n = len(s)
c1 = 0
l1 = []
for i in range(len(s) - 4):
	s2 = s[i:i + 5]
	if ''.join(s2) == 'heavy':
		c1 += 1
	elif ''.join(s2) == 'metal':
		l1.append(c1 * 1)
print(sum(l1))


s = input()
m = 0
h = 0
for i in range(4, len(s)):
	if s[i] == 'l':
		if s[i - 4] == 'm' and s[i - 3] == 'e' and (s[i - 2] == 't') and (s[i - 1] == 'a'):
			m = m + h
	elif s[i - 4] == 'h' and s[i - 3] == 'e' and (s[i - 2] == 'a') and (s[i - 1] == 'v') and (s[i] == 'y'):
		h = h + 1
print(m)


s = input()
(a, b) = (0, 0)
n = len(s)
for i in range(n):
	if s[i:i + 5] == 'heavy':
		a = a + 1
	elif s[i:i + 5] == 'metal':
		b = b + a
print(b)


def solve(s):
	(c, r) = (0, 0)
	for i in range(5, len(s) + 1):
		if s[i - 5:i] == 'heavy':
			c += 1
		elif s[i - 5:i] == 'metal':
			r += c
	return r
print(solve(input()))


s = input()
l = len(s)
k = [0 for i in range(l)]
start = 0
while True:
	temp = s.find('heavy', start, l)
	if temp == -1:
		break
	else:
		k[temp] = 1
		start = temp + 1
start = 0
while True:
	temp = s.find('metal', start, l)
	if temp == -1:
		break
	else:
		k[temp] = 2
		start = temp + 1
sol = 0
ones = 0
for i in range(l):
	if k[i] == 1:
		ones += 1
	elif k[i] == 2:
		sol += ones
print(sol)


a = list(input().split('metal'))
l = len(a)
sum = 0
for i in range(l):
	sum += (l - i - 1) * a[i].count('heavy')
print(sum)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
s = input()
n = len(s)
if n < 10:
	print(0)
else:
	i = 0
	(c1, c2) = (0, 0)
	l1 = [0] * n
	l2 = [0] * n
	while i <= n - 5:
		if s[i] == 'h':
			if s[i + 1:i + 5] == 'eavy':
				c1 += 1
		l1[i] = c1
		if s[n - 5 - i] == 'm':
			if s[n - 4 - i:n - i] == 'etal':
				c2 += 1
		l2[n - 5 - i] = c2
		i += 1
	ans = 0
	for i in range(n - 5):
		if i == 0:
			if l1[i] == 1:
				ans += l2[1]
		elif l1[i] - l1[i - 1] > 0:
			ans += l2[i]
	print(ans)


(song, heavy_count, result) = (input(), 0, 0)
for i in range(len(song) - 4):
	if song[i:i + 5] == 'heavy':
		heavy_count += 1
	elif song[i:i + 5] == 'metal':
		result += heavy_count
print(result)


def finder(S, t):
	n = len(S)
	answer = []
	i1 = 0
	for i in range(n):
		if S[i] == t[i1]:
			i1 += 1
			if i1 == len(t):
				i1 = 0
				answer.append(i - len(t) + 1)
		else:
			i1 = 0
			if S[i] == t[i1]:
				i1 += 1
	return answer

def process(S):
	heavy = finder(S, 'heavy')
	metal = finder(S, 'metal')
	answer = 0
	i1 = 0
	i2 = 0
	n = len(heavy)
	m = len(metal)
	while i1 < n and i2 < m:
		if heavy[i1] < metal[i2]:
			answer += len(metal) - i2
			i1 += 1
		else:
			i2 += 1
	return answer
S = input()
print(process(S))


s = input()
n = len(s)
h = 0
x = 0
i = 0
while i < n - 4:
	temp = s[i:i + 5]
	if temp == 'heavy':
		h += 1
		i += 5
	elif temp == 'metal':
		x += h
		i += 5
	else:
		i += 1
print(x)


import sys
s = sys.stdin.readline()[:-1]
heavy = []
metal = []
for i in range(len(s) - 4):
	w = s[i:i + 5]
	if w == 'heavy':
		heavy.append(i)
	elif w == 'metal':
		metal.append(i)
c = 0
x = 0
for i in range(len(heavy)):
	for j in range(x, len(metal)):
		if metal[j] > heavy[i]:
			c += len(metal) - j
			x = j
			break
sys.stdout.write(str(c))


import os
import sys
from io import BytesIO, IOBase

def main():
	s = input()
	n = len(s)
	h = 0
	ans = 0
	for i in range(n):
		if s[i] == 'y':
			try:
				if s[i - 5 + 1:i + 1] == 'heavy':
					h += 1
			except:
				pass
		elif s[i] == 'l':
			try:
				if s[i - 5 + 1:i + 1] == 'metal':
					ans += h
			except:
				pass
	print(ans)

def nouse0():
	a = 420
	b = 420
	print(f'i am nitish{(a + b) // 2}')

def nouse1():
	a = 420
	b = 420
	print(f'i am nitish{(a + b) // 2}')

def nouse2():
	a = 420
	b = 420
	print(f'i am nitish{(a + b) // 2}')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def nouse3():
	a = 420
	b = 420
	print(f'i am nitish{(a + b) // 2}')

def nouse4():
	a = 420
	b = 420
	print(f'i am nitish{(a + b) // 2}')

def nouse5():
	a = 420
	b = 420
	print(f'i am nitish{(a + b) // 2}')
main()


s = input()
h = 0
ans = 0
for i in range(len(s)):
	c = s[i:i + 5]
	if c == 'metal':
		ans += h
	if c == 'heavy':
		h += 1
print(ans)


import os
import sys
from math import *
from io import BytesIO, IOBase

def vsInput():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

def array():
	return [int(i) for i in input().split()]
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def bs(a, k):
	l = 0
	h = len(a) - 1
	while l <= h:
		m = l + (h - l) // 2
		if a[m] > k and (m == 0 or a[m - 1] < k):
			return len(a) - m
		elif k < a[m]:
			h = m - 1
		else:
			l = m + 1
	return 0
s = input()
i = 0
n = len(s)
h = []
m = []
while i < n:
	if s[i:i + 5] == 'heavy':
		h.append(i)
		i += 5
	elif s[i:i + 5] == 'metal':
		m.append(i)
		i += 5
	else:
		i += 1
ans = 0
for i in h:
	ans += bs(m, i)
print(ans)


s = str(input())
n = len(s)
hcount = 0
count = 0
for i in range(n - 4):
	if s[i] == 'h' and s[i + 1] == 'e' and (s[i + 2] == 'a') and (s[i + 3] == 'v') and (s[i + 4] == 'y'):
		hcount += 1
	if s[i] == 'm' and s[i + 1] == 'e' and (s[i + 2] == 't') and (s[i + 3] == 'a') and (s[i + 4] == 'l'):
		count = count + hcount
print(count)


s = input()
mask1 = 'heavy'
mask2 = 'metal'
index1 = []
index2 = []

def smallestbigger(arr, left, right, element):
	if left == right:
		return left
	if left < right:
		mid = (left + right) // 2
		if arr[mid] == element:
			return mid
		if arr[mid] > element:
			return smallestbigger(arr, left, mid, element)
		else:
			return smallestbigger(arr, mid + 1, right, element)
for i in range(len(s) - len(mask1) + 1):
	if s[i:i + 5] == mask1:
		index1.append(i)
	elif s[i:i + 5] == mask2:
		index2.append(i)
total = 0
for i in index1:
	total += len(index2) - smallestbigger(index2, 0, len(index2), i)
print(total)


s = input()
c = 0
answer = 0
s = ''.join(reversed(s))
for i in range(len(s) - 4):
	if s[i:i + 5] == 'latem':
		c += 1
	elif s[i:i + 5] == 'yvaeh':
		answer += c
print(answer)


t = input()
t = t.replace('heavy', '0')
t = t.replace('metal', '1')
(a, b, s) = (0, t.count('1'), 0)
for i in t:
	if i == '0':
		a += 1
		s += b
	if i == '1':
		b -= 1
print(s)


n = cou = 0
t = input().split('heavy')
for i in t:
	cou += i.count('metal') * n
	n += 1
print(cou)


from collections import defaultdict
s = input()
d = defaultdict(list)
for x in range(len(s) - 4):
	if s[x] == 'h' and s[x + 1] == 'e' and (s[x + 2] == 'a') and (s[x + 3] == 'v') and (s[x + 4] == 'y'):
		d['h'].append(x)
	elif s[x] == 'm' and s[x + 1] == 'e' and (s[x + 2] == 't') and (s[x + 3] == 'a') and (s[x + 4] == 'l'):
		d['m'].append(x)
p = len(d['m'])
from bisect import *
c = 0
for x in d['h']:
	k = bisect_left(d['m'], x)
	c += p - k
print(c)


from collections import defaultdict, deque, Counter, OrderedDict
from bisect import insort, bisect_right, bisect_left
import threading, sys

def main():
	s = input()
	(ans, c) = (0, 0)
	for i in range(0, len(s) - 4):
		ss = s[i:i + 5]
		if ss == 'heavy':
			c += 1
		elif ss == 'metal':
			ans += c
	print(ans)
thread = threading.Thread(target=main)
thread.start()


s = input()
s = s.replace('heavy', '1')
s = s.replace('metal', '0')
tmp = ''
for i in s:
	if i == '1':
		tmp += '1'
	if i == '0':
		tmp += '0'
if len(tmp) == 0:
	print(0)
	return
d = [0 for i in range(10 ** 6 + 1)]
if tmp[len(tmp) - 1] == '0':
	d[len(tmp) - 1] = 1
for i in reversed(list(range(len(tmp) - 1))):
	if tmp[i] == '0':
		d[i] = d[i + 1] + 1
	else:
		d[i] = d[i + 1]
res = 0
for i in range(len(tmp)):
	if tmp[i] == '1':
		res += d[i]
print(res)


s = input()
metalPositions = []
i = 0
while True:
	i = s.find('metal', i)
	if i == -1:
		break
	metalPositions.append(i)
	i += 5
count = 0
beg = 0
i = 0
while True:
	i = s.find('heavy', i)
	if i == -1:
		break
	i += 5
	for j in range(beg, len(metalPositions)):
		if metalPositions[j] >= i:
			count += len(metalPositions) - j
			beg = j
			break
print(count)


import bisect
s = input()
answer = 0
hpos = []
metpos = []
for i in range(len(s) - 4):
	if s[i:i + 5] == 'heavy':
		hpos.append(i + 4)
for i in range(len(s) - 4):
	if s[i:i + 5] == 'metal':
		metpos.append(i)
hpos.sort()
metpos.sort()
s = len(metpos)
for pos in hpos:
	k = bisect.bisect_left(metpos, pos)
	if k != -1:
		answer += s - k
print(answer)


s = input()
l = []
l1 = []
j = -3
i = -3
while True:
	j = s.find('metal', j + 3)
	if j == -1:
		break
	l.append(j)
while True:
	i = s.find('heavy', i + 3)
	if i == -1:
		break
	l1.append(i)
p = len(l1)
k1 = 0
j1 = 0
ost = 0
out = 0
for i in range(len(l)):
	if l[i] > ost:
		for j in range(j1, p):
			if l1[j] > l[i]:
				break
			j1 += 1
			ost = l1[j]
			k1 += 1
	out += k1
print(out)


ans = 0
s = input()
heavy = 0
i = 0
if not len(s) < 5:
	while i < len(s) - 4:
		if s[i] == 'h' and s[i + 1] == 'e' and (s[i + 2] == 'a') and (s[i + 3] == 'v') and (s[i + 4] == 'y'):
			heavy += 1
			i += 5
		elif s[i] == 'm' and s[i + 1] == 'e' and (s[i + 2] == 't') and (s[i + 3] == 'a') and (s[i + 4] == 'l'):
			ans += heavy
			i += 5
		else:
			i += 1
print(ans)


s = input()
num2 = len(s)
num_heavy = 0
num = 0
for i in range(num2 - 4):
	if s[i] == 'h':
		if s[i + 1:i + 5] == 'eavy':
			num_heavy += 1
	if s[i] == 'm':
		if s[i + 1:i + 5] == 'etal':
			num += num_heavy
print(num)


import os
from math import *
s = input()
ch = 0
cm = 0
ans = []
z = 0
for i in range(len(s) - 4):
	if s[i:i + 5] == 'heavy':
		z = 1
		ans.append(ch * cm)
		cm = 0
		ch += 1
	elif s[i:i + 5] == 'metal':
		if z == 1:
			cm += 1
ans.append(ch * cm)
print(sum(ans))


a = input()
n = len(a)
b = []
c = []
y = k = 0
for i in range(n - 4):
	if a[i] == 'h':
		if a[i:i + 5] == 'heavy':
			b.append(i)
			i += 4
			k += 1
	if a[i] == 'm':
		if a[i:i + 5] == 'metal':
			c.append(i)
			i += 4
			y += k
	else:
		i += 1
print(y)


s = input()
n = len(s)
counter = 0
heavy = 0
i = 0
while i < n:
	if s[i:i + 5] == 'heavy':
		heavy += 1
		i = i + 5
	elif s[i:i + 5] == 'metal':
		counter += heavy
		i += 5
	else:
		i += 1
print(counter)


import sys
import os
import math
import copy
from math import gcd
from bisect import bisect
from io import BytesIO, IOBase
from math import sqrt, floor, factorial, gcd, log, ceil
from collections import deque, Counter, defaultdict
from itertools import permutations, combinations

def Int():
	return int(sys.stdin.readline())

def Mint():
	return map(int, sys.stdin.readline().split())

def Lstr():
	return list(sys.stdin.readline().strip())

def Str():
	return sys.stdin.readline().strip()

def Mstr():
	return map(str, sys.stdin.readline().strip().split())

def List():
	return list(map(int, sys.stdin.readline().split()))

def Hash():
	return dict()

def Mod():
	return 1000000007

def Ncr(n, r, p):
	return fact[n] * (ifact[r] * ifact[n - r] % p) % p

def Most_frequent(list):
	return max(set(list), key=list.count)

def Mat2x2(n):
	return [List() for _ in range(n)]

def btod(n):
	return int(n, 2)

def dtob(n):
	return bin(n).replace('0b', '')

def solution():
	n = Str()
	s = 0
	e = 0
	for i in range(len(n)):
		if n[i:i + 5] == 'heavy':
			s += 1
		if n[i:i + 5] == 'metal':
			e += s
	print(e)
solution()


a = input()
b = ''
sh = 0
sm = 0
for i in range(0, len(a) - 4):
	if a[i:i + 5] == 'heavy':
		sh += 1
	if a[i:i + 5] == 'metal':
		sm += sh
print(sm)


l = input().split('metal')
ans = cur = 0
for str in l:
	cur += str.count('heavy')
	ans += cur
print(ans - cur)


res = 0
i = 0
for word in input().split('heavy'):
	res += i * word.count('metal')
	i += 1
print(res)


s = input()
res = 0
h = 0
for i in range(len(s)):
	if s[i:i + 5] == 'heavy':
		h += 1
	elif s[i:i + 5] == 'metal':
		res += h
print(res)


from sys import stdin
from collections import defaultdict as dd
s = stdin.readline().rstrip()
c = 0
ans = 0
for i in range(len(s) - 4):
	if s[i:i + 5] == 'heavy':
		c += 1
	elif s[i:i + 5] == 'metal':
		ans += c
print(ans)


from sys import stdin

def main():
	cadena = stdin.readline().strip()
	i = 0
	j = i + 4
	heavy = 0
	ans = 0
	while j < len(cadena):
		if cadena[i:j + 1] == 'heavy':
			heavy += 1
		elif cadena[i:j + 1] == 'metal':
			ans += heavy
		i += 1
		j += 1
	print(ans)
main()


L = input().split('heavy')
ans = 0
for i in range(len(L)):
	ans += i * L[i].count('metal')
print(ans)


from bisect import bisect_left
(s, starts, start, k) = (input(), [], 0, 0)
while True:
	pos = s.find('heavy', start)
	start = pos + 1
	if pos < 0:
		break
	starts.append(pos)
while True:
	pos = s.find('metal', start)
	if pos < 0:
		print(k)
		break
	(start, k) = (pos + 1, k + bisect_left(starts, pos))


str = input()
countM = 0
countResult = 0
for i in range(0, len(str) - 4):
	if str[i:i + 5] == 'heavy':
		countM = countM + 1
	elif str[i:i + 5] == 'metal':
		countResult = countResult + countM
print(countResult)


s = input().split('heavy')
start = 0
rs = 0
for i in range(1, len(s)):
	rs = rs + s[i].count('metal') * i
print(rs)


a = input()
st = ''
if len(a) < 5:
	print(0)
else:
	for i in range(4, len(a)):
		if a[i - 4] == 'h' and a[i - 3] == 'e' and (a[i - 2] == 'a') and (a[i - 1] == 'v') and (a[i] == 'y'):
			st += 'h'
		elif a[i - 4] == 'm' and a[i - 3] == 'e' and (a[i - 2] == 't') and (a[i - 1] == 'a') and (a[i] == 'l'):
			st += 'm'
	totm = st.count('m')
	tot = 0
	for i in st:
		if i == 'h':
			tot += totm
		else:
			totm -= 1
	print(tot)


s = input()
h = []
m = []
for i in range(len(s) - 4):
	if s[i:i + 5] == 'heavy':
		h.append(i)
for i in range(len(s) - 4):
	if s[i:i + 5] == 'metal':
		m.append(i)
l = 0
r = 0
total = 0
while l < len(h) and r < len(m):
	if m[r] > h[l]:
		total += len(m) - r
		l += 1
	else:
		r += 1
print(total)


def powerful(s):
	h = 'heavy'
	m = 'metal'
	i = 0
	j = 0
	dp = ''
	ans = 0
	countH = 0
	for it in range(len(s)):
		if s[it] == h[i]:
			i += 1
			if i == 5:
				countH += 1
				i = 0
		elif s[it] == h[0]:
			i = 1
		else:
			i = 0
		if s[it] == m[j]:
			j += 1
			if j == 5:
				ans += countH
				j = 0
		elif s[it] == m[0]:
			j = 1
		else:
			j = 0
	return ans
s = input()
print(powerful(s))


s = input()
heavy = 0
total = 0
i = 0
while i < len(s) - 4:
	if s[i:i + 5] == 'heavy':
		i += 5
		heavy += 1
	elif s[i:i + 5] == 'metal':
		i += 5
		total += heavy
	else:
		i += 1
print('%d' % total)


str = input()
heavy = 0
ans = 0
for i in range(0, len(str)):
	if str[i:i + 5] == 'heavy':
		heavy += 1
	elif str[i:i + 5] == 'metal':
		ans += heavy
print(ans)


L = list(input().split('heavy'))
ans = 0
for i in range(len(L)):
	ans += i * (len(list(L[i].split('metal'))) - 1)
print(ans)


import math
import time
str = input()
array = []
for i in range(4, len(str)):
	if str[i - 4] == 'h' and str[i - 3] == 'e' and (str[i - 2] == 'a') and (str[i - 1] == 'v') and (str[i] == 'y'):
		array.append(1)
	if str[i - 4] == 'm' and str[i - 3] == 'e' and (str[i - 2] == 't') and (str[i - 1] == 'a') and (str[i] == 'l'):
		array.append(0)
pos = [0 for i in range(len(array))]
tot = 0
for i in range(len(pos)):
	j = len(pos) - 1 - i
	pos[j] = tot
	if array[j] == 0:
		tot += 1
res = 0
for i in range(len(pos)):
	if array[i] == 1:
		res += pos[i]
print(res)


s = input()
n = len(s)
i = 0
heavycount = 0
totalcount = 0
while i <= n - 5:
	if s[i:i + 5] == 'heavy':
		heavycount = heavycount + 1
		i = i + 5
	elif s[i:i + 5] == 'metal':
		totalcount = totalcount + heavycount
		i = i + 5
	else:
		i = i + 1
print(totalcount)


s = input()
total = 0
heavy = []
for i in range(len(s) - 4):
	if s[i:i + 5] == 'heavy':
		heavy.append(i)
	if s[i:i + 5] == 'metal':
		total += len(heavy)
print(total)


str1 = input()
heavycount = 0
sol = 0
i = 0
while i < len(str1) - 4:
	if str1[i] == 'h':
		if str1[i:i + 5] == 'heavy':
			heavycount += 1
	if str1[i] == 'm':
		if str1[i:i + 5] == 'metal':
			sol += heavycount
	i += 1
print(sol)


s = input() + '#'
n = len(s)
ans = [0] * 2
for i in range(4, n):
	aa = s[i - 4:i + 1]
	if aa == 'heavy':
		ans[0] += 1
	elif aa == 'metal':
		ans[1] += ans[0]
print(ans[1])


st = input()
ch = 0
c = 0
cm = 0
for i in range(0, len(st) - 4):
	if st[i:i + 5] == 'heavy':
		ch += 1
	elif st[i:i + 5] == 'metal':
		if cm == 0 and ch >= 1:
			cm = 1
			cm = cm * ch
		else:
			cm = cm + ch
print(cm)


import time, math, bisect, sys
from sys import stdin, stdout
from collections import deque
from fractions import Fraction
from collections import Counter
pi = 3.141592653589793

def II():
	return int(stdin.readline())

def IO():
	return stdin.readline()

def IP():
	return map(int, stdin.readline().split())

def L():
	return list(map(int, stdin.readline().split()))

def P(x):
	return stdout.write(str(x) + '\n')

def PI(x, y):
	return stdout.write(str(x) + ' ' + str(y) + '\n')

def lcm(a, b):
	return a * b // gcd(a, b)

def gcd(a, b):
	if a == 0:
		return b
	elif b == 0:
		return a
	if a > b:
		return gcd(a % b, b)
	else:
		return gcd(a, b % a)

def readTree():
	v = int(input())
	adj = [set() for i in range(v + 1)]
	for i in range(v - 1):
		(u1, u2) = In()
		adj[u1].add(u2)
		adj[u2].add(u1)
	return (adj, v)

def bfs(adj, v):
	visited = [False] * (v + 1)
	q = deque()
	while q:
		pass

def sieve():
	li = [True] * 1000001
	(li[0], li[1]) = (False, False)
	for i in range(2, len(li), 1):
		if li[i] == True:
			for j in range(i * i, len(li), i):
				li[j] = False
	prime = []
	for i in range(1000001):
		if li[i] == True:
			prime.append(i)
	return prime

def setBit(n):
	count = 0
	while n != 0:
		n = n & n - 1
		count += 1
	return count

def solve():
	s = input()
	h = 0
	c = 0
	n = len(s)
	for i in range(n - 4):
		if s[i:i + 5] == 'heavy':
			h += 1
		elif s[i:i + 5] == 'metal':
			c = c + h
	print(c)
solve()


s = input()
p1 = 0
p2 = 0
hvy = []
mtl = []
p1 = s.find('heavy')
p2 = s.find('metal')
while p1 >= 0 or p2 >= 0:
	if p1 >= 0:
		hvy.append(p1)
		p1 = s.find('heavy', p1 + 1)
	if p2 >= 0:
		mtl.append(p2)
		p2 = s.find('metal', p2 + 1)
v = len(s)
d = [0] * v
for i in hvy:
	d[i] += 1
for i in range(1, v):
	d[i] += d[i - 1]
s = 0
for i in mtl:
	s += d[i]
print(s)


s = input()

def heavy(s, i):
	if i - 4 >= 0 and s[i] == 'y' and (s[i - 1] == 'v') and (s[i - 2] == 'a') and (s[i - 3] == 'e') and (s[i - 4] == 'h'):
		return 1
	return 0

def metal(s, i):
	if i - 4 >= 0 and s[i] == 'l' and (s[i - 1] == 'a') and (s[i - 2] == 't') and (s[i - 3] == 'e') and (s[i - 4] == 'm'):
		return 1
	return 0
a = 0
count = 0
i = len(s) - 1
while i > 0:
	if metal(s, i):
		a = a + 1
		i = i - 5
	elif heavy(s, i):
		count = count + a
		i = i - 5
	else:
		i = i - 1
print(count)


def f(a):
	return a * (a + 1) // 2
x = input()
if 'heavy' in x:
	x = x.replace('heavy', '@')
if 'metal' in x:
	x = x.replace('metal', '#')
c = 0
n = len(x)
res = 0
for i in range(n):
	if x[i] == '@':
		c += 1
	if x[i] == '#':
		res += c
print(res)


s = input()
(count, ans, i) = (0, 0, 0)
while i < len(s) - 4:
	if s[i:i + 5] == 'heavy':
		count += 1
		i += 5
	elif s[i:i + 5] == 'metal':
		ans += count
		i += 5
	else:
		i += 1
print(ans)


s = input()[::-1]
h = 'heavy'[::-1]
m = 'metal'[::-1]
sum = 0
cnt_b = 0
if h and m in s:
	for i in range(len(s)):
		if s[i:i + len(m)] == m:
			cnt_b += 1
		elif s[i:i + len(h)] == h:
			sum += cnt_b
print(sum)


def main():
	l = []
	for s in input().split('heavy')[1:]:
		l.append(0)
		for ss in s.split('metal'):
			l.append(1)
		del l[-1]
	res = a = 0
	for t in l:
		if t:
			res += a
		else:
			a += 1
	print(res)
main()


import math
import bisect
s = input()
heavy = []
metal = []
for i in range(len(s) - 4):
	if s[i] in ['m', 'h']:
		temp = s[i:i + 5]
		if temp == 'heavy':
			heavy.append(i)
		elif temp == 'metal':
			metal.append(i)
ans = 0
for i in heavy:
	ans += len(metal) - bisect.bisect(metal, i)
print(ans)


c = 0
for (x, z) in enumerate(input().split('heavy')):
	c += x * z.count('metal')
print(c)


str = input()
h = 0
m = 0
for i in range(len(str) - 4):
	if str[i:i + 5] == 'heavy':
		h += 1
	if str[i:i + 5] == 'metal':
		m += h
print(m)


from bisect import bisect as bs
s = input()
posHeavy = []
posMetal = []
for i in range(len(s) - 4):
	if s[i:i + 5] == 'heavy':
		posHeavy.append(i + 4)
for i in range(len(s) - 4):
	if s[i:i + 5] == 'metal':
		posMetal.append(i)
res = 0
for i in posHeavy:
	res += len(posMetal) - bs(posMetal, i)
print(res)


s = input()
n = len(s)
ans = 0
m = 0
for i in range(n - 5, -1, -1):
	if s[i:i + 5] == 'metal':
		m += 1
	elif s[i:i + 5] == 'heavy':
		ans += m
print(ans)


import sys
s = sys.stdin.readline()
l = len(s)
i = length = sub = 0
while 1:
	if i <= l - 5:
		if s[i] == 'h':
			i += 1
			if s[i] == 'e':
				i += 1
				if s[i] == 'a':
					i += 1
					if s[i] == 'v':
						i += 1
						if s[i] == 'y':
							i += 1
							length += 1
		elif s[i] == 'm':
			i += 1
			if s[i] == 'e':
				i += 1
				if s[i] == 't':
					i += 1
					if s[i] == 'a':
						i += 1
						if s[i] == 'l':
							i += 1
							sub += length
		else:
			i += 1
	else:
		break
sys.stdout.write(str(sub))


string = input()
h = string.count('heavy')
m = string.count('metal')
out = h * m
lmh = 0
lmm = 0
for i in range(len(string)):
	mb = lmm
	if string[i] == 'h':
		if string[i:i + 5] == 'heavy':
			lmh += 1
	elif string[i] == 'm':
		if string[i:i + 5] == 'metal':
			lmm += 1
	if lmm > mb:
		out -= h - lmh
print(out)


print(sum((i * s.count('metal') for (i, s) in enumerate(input().split('heavy')))))


import io, os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
from collections import deque as que, defaultdict as vector
from bisect import bisect as bsearch
from heapq import *
inin = lambda : int(input())
inar = lambda : list(map(int, input().split()))
inst = lambda : input().decode().rstrip('\n\r')
INF = float('inf')
from types import GeneratorType

def bootstrap(f, stack=[]):

	def wrappedfunc(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		else:
			to = f(*args, **kwargs)
			while True:
				if type(to) is GeneratorType:
					stack.append(to)
					to = next(to)
				else:
					stack.pop()
					if not stack:
						break
					to = stack[-1].send(to)
			return to
	return wrappedfunc
_T_ = 1
for _t_ in range(_T_):
	s = inst()
	hv = 0
	ans = 0
	for i in range(len(s) - 4):
		if s[i:i + 5] == 'heavy':
			hv += 1
		if s[i:i + 5] == 'metal':
			ans += hv
	print(ans)


s = input().strip()
ans = 0
head = 0
for i in range(4, len(s)):
	if s[i - 4:i + 1] == 'heavy':
		head += 1
	if s[i - 4:i + 1] == 'metal':
		ans += head
print(ans)


input_str = input()
if input_str.find('heavy') == -1:
	print(0)
else:
	a = input_str.index('heavy') + 5
	b = 1
	result = 0
	while a < len(input_str):
		if input_str[a:a + 5] == 'heavy':
			b += 1
			a += 4
		elif input_str[a:a + 5] == 'metal':
			result += b
			a += 4
		else:
			a += 1
	print(result)


from re import findall
(h, acc) = (0, 0)
for i in findall('heavy|metal', input()):
	if i.startswith('h'):
		h += 1
	else:
		acc += h
print(acc)


a = input()
ch = 0
cm = 0
for i in range(0, len(a) - 4):
	if a[i:i + 5] == 'heavy':
		ch += 1
	elif a[i:i + 5] == 'metal':
		cm += ch
print(cm)


def sol(s):
	h = 'heavy'
	m = 'metal'
	i = 0
	j = 0
	occ = ''
	for c in s:
		if c == h[i]:
			if i == len(h) - 1:
				occ += 'h'
				i = 0
			else:
				i += 1
		elif c == h[0]:
			i = 1
		else:
			i = 0
		if c == m[j]:
			if j == len(m) - 1:
				occ += 'm'
				j = 0
			else:
				j += 1
		elif c == m[0]:
			j = 1
		else:
			j = 0
	ans = 0
	n = len(occ)
	count_m = 0
	for c in range(n - 1, -1, -1):
		if occ[c] == 'm':
			count_m += 1
		else:
			ans += count_m
	return ans
s = input()
print(sol(s))


string = input('')
heavy = list()
metal = list()
start = 0
while string.find('heavy', start) != -1:
	heavy.append(string.find('heavy', start))
	start = string.find('heavy', start) + 5
start = 0
while string.find('metal', start) != -1:
	metal.append(string.find('metal', start))
	start = string.find('metal', start) + 5
start = 0
output = 0
for i in range(len(heavy)):
	for j in range(start, len(metal)):
		if heavy[i] > metal[j]:
			continue
		else:
			output = output + (len(metal) - j)
			start = j
			break
print(output)


s = input()
h = 0
m = 0
ans = 0
for i in range(len(s) - 1, 3, -1):
	if s[i - 4:i + 1] == 'heavy':
		h += 1
		ans += m
	if s[i - 4:i + 1] == 'metal':
		m += 1
print(ans)


from collections import *
from math import *
from sys import *
s = input()
n = len(s)
ct = 0
ans = 0
for i in range(n - 4):
	if s[i:i + 5] == 'heavy':
		ct += 1
	elif s[i:i + 5] == 'metal':
		ans += ct
print(ans)


r = input()
S = r.split('heavy')
k = 0
for i in range(len(S)):
	p = S[i].count('metal')
	k = k + i * p
print(k)


from collections import deque as que, defaultdict as vector
from bisect import bisect as bsearch
from heapq import *
inin = lambda : int(input())
inar = lambda : list(map(int, input().split()))
INF = float('inf')
_T_ = 1
for _t_ in range(_T_):
	s = input()
	hv = 0
	ans = 0
	for i in range(len(s) - 4):
		if s[i:i + 5] == 'heavy':
			hv += 1
		if s[i:i + 5] == 'metal':
			ans += hv
	print(ans)


from bisect import bisect_left
s = input()
h = [i for i in range(len(s)) if s.startswith('heavy', i)]
m = [i for i in range(len(s)) if s.startswith('metal', i)]
ans = 0
for i in h:
	ans += len(m) - bisect_left(m, i)
print(ans)


st = input()
p = 0
ans = 0
for i in range(len(st) - 4):
	if st[i:i + 5] == 'heavy':
		p += 1
	if st[i:i + 5] == 'metal':
		ans += p
print(ans)


def main():
	s = str(input())
	s = s.replace('heavy', '-')
	s = s.replace('metal', '+')
	(p, n) = (0, 0)
	for k in s:
		if k == '-':
			n += 1
		elif k == '+':
			p += n
	print(p)
main()


s = str(input())
s = s[::-1]
count = 0
ans = 0
for i in range(0, len(s)):
	if s[i:i + 5] == 'latem':
		count += 1
	if s[i:i + 5] == 'yvaeh':
		ans += count
print(ans)


import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import *
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect, insort
from time import perf_counter
from fractions import Fraction
import copy
from copy import deepcopy
import time
starttime = time.time()
mod = int(pow(10, 9) + 7)
mod2 = 998244353

def data():
	return sys.stdin.readline().strip()

def out(*var, end='\n'):
	sys.stdout.write(' '.join(map(str, var)) + end)

def L():
	return list(sp())

def sl():
	return list(ssp())

def sp():
	return map(int, data().split())

def ssp():
	return map(str, data().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(n, val) for j in range(m)]
try:
	sys.stdin = open('input.txt', 'r')
except:
	pass

def pmat(A):
	for ele in A:
		print(*ele, end='\n')
s = input()
heavy = []
driver = []
for i in range(len(s)):
	if i + 5 <= len(s):
		if s[i:i + 5] == 'heavy':
			heavy.append(i)
	if i + 5 <= len(s):
		if s[i:i + 5] == 'metal':
			driver.append(i)
ans = 0
for ele in heavy:
	x = bl(driver, ele)
	ans += len(driver) - x
print(ans)
endtime = time.time()


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from collections import defaultdict
from math import ceil, floor, sqrt, log2, gcd
from heapq import heappush, heappop
from bisect import bisect_left, bisect
import sys
abc = 'abcdefghijklmnopqrstuvwxyz'
s = input()
h = 0
m = 0
n = len(s)
for i in range(n - 4):
	if s[i:i + 5] == 'heavy':
		h += 1
	elif s[i:i + 5] == 'metal':
		m += 1
ans = 0
for i in range(n - 4):
	if s[i:i + 5] == 'heavy':
		ans += m
		h -= 1
	elif s[i:i + 5] == 'metal':
		m -= 1
print(ans)


arr = input()
countex = 0
countin = 0
for i in range(len(arr)):
	if arr[i:i + 5] == 'heavy':
		countin += 1
	if arr[i:i + 5] == 'metal':
		countex += countin
print(countex)


s = input()
start = 0
rs = 0
for i in range(len(s)):
	if s[i:i + 5] == 'heavy':
		start += 1
	if s[i:i + 5] == 'metal':
		rs = rs + start
print(rs)


s = input()
metals = []
heavys = []
ind = cur = -1
while True:
	cur = s.find('heavy', ind + 1)
	if cur != -1:
		heavys.append(cur)
		ind = cur
	else:
		break
ind = cur = -1
while True:
	cur = s.find('metal', ind + 1)
	if cur != -1:
		metals.append(cur)
		ind = cur
	else:
		break
ind = ans = 0
for x in metals:
	while ind < len(heavys) and heavys[ind] < x:
		ind += 1
	ans += ind
print(ans)


import re

def binarySearch(a, x):
	low = 0
	n = len(a)
	high = n - 1
	while low <= high:
		mid = (low + high) // 2
		if a[mid] > x and mid == 0:
			return n
		elif a[mid] > x and a[mid - 1] < x:
			return n - mid
		elif x < a[mid]:
			high = mid - 1
		else:
			low = mid + 1
	return -1
s = input()
x = 'heavy'
y = 'metal'
s1 = [s.start() for s in re.finditer(x, s)]
s2 = [s.start() for s in re.finditer(y, s)]
total = 0
n1 = len(s1)
n2 = len(s2)
i = 0
j = 0
while i < n1 and j < n2:
	if s1[i] < s2[j]:
		total += n2 - j
		i += 1
	else:
		j += 1
print(total)


from sys import stdin, stdout
import math
import bisect
s = stdin.readline().strip()
heavy = []
metal = []
for i in range(len(s) - 5 + 1):
	if s[i] not in ['m', 'h']:
		continue
	tmp = s[i:i + 5]
	if tmp == 'heavy':
		heavy.append(i)
	elif tmp == 'metal':
		metal.append(i)
ans = 0
for i in heavy:
	ans += len(metal) - bisect.bisect(metal, i)
stdout.writelines(str(ans))


st = input()
l = len(st)
h = 0
c = 0
for i in range(0, l):
	if i + 5 <= l:
		if st[i:i + 5] == 'heavy':
			h = h + 1
		elif st[i:i + 5] == 'metal':
			c = c + h
print(c)


s = input()
c = 0
t = 0
for i in range(len(s)):
	if s[i:i + 5] == 'heavy':
		c += 1
	elif s[i:i + 5] == 'metal':
		t += c
print(t)


z = res = 0
t = input().split('heavy')
for i in t:
	res += i.count('metal') * z
	z += 1
print(res)


subst = input().split('heavy')
res = 0
for i in range(len(subst)):
	res += i * subst[i].count('metal')
print(res)


s = input().strip().split('metal')
l = len(s) - 1
found = 0
head = 'heavy'
for i in range(l):
	mt = s[i].count(head)
	found += mt * (l - i)
print(found)


word = input()
n = len(word)
a = 'heavy'
b = 'metal'
arr = [0 for i in range(n)]
brr = [0 for i in range(n)]
for i in range(n):
	if word[i:i + 5] == a:
		arr[i] += 1
	if word[i:i + 5] == b:
		brr[i] += 1
for i in range(n - 2, -1, -1):
	brr[i] += brr[i + 1]
ans = 0
for i in range(n):
	ans += arr[i] * brr[i]
print(ans)


string = input()
n = len(string)
havyMetals = []
for i in range(n):
	if i < n - 4:
		if string[i:i + 5] in ['heavy', 'metal']:
			havyMetals.append(string[i:i + 5])
counts = [[0, 0]]
for i in range(len(havyMetals)):
	if havyMetals[i] == 'heavy':
		counts.append([counts[-1][0] + 1, counts[-1][1]])
	else:
		counts.append([counts[-1][0], counts[-1][1] + 1])
counts.pop(0)
if len(counts) == 0:
	print(0)
	exit()
heavys = counts[-1][0]
metals = counts[-1][1]
total = 0
for i in range(len(havyMetals)):
	if havyMetals[i] == 'heavy':
		total += metals - counts[i][1]
print(total)


s = input()
a = []
for i in range(len(s)):
	c = s[i:i + 5]
	if c == 'heavy':
		a.append(0)
	elif c == 'metal':
		a.append(1)
k = 0
ans = 0
for i in a:
	if i == 0:
		k += 1
	else:
		ans += k
print(ans)


inp = input()
if len(inp) < 10:
	print(0)
	exit(0)
string = inp.split('heavy')[1:]
count = 0
counter = [None for i in range(len(string))]
for i in range(len(string)):
	counter[i] = string[i].count('metal')
count = counter[int(len(string) - 1)]
for i in range(len(string) - 2, -1, -1):
	counter[i] += counter[i + 1]
	count += counter[i]
print(count)


inp = input()
out = 0
heavys = 0
for i in range(len(inp) - 4):
	if inp[i:i + 5] == 'heavy':
		heavys += 1
	elif inp[i:i + 5] == 'metal':
		out += heavys
print(out)