module String = struct include String let fold_left f init str = let n = String.length str - 1 in let rec doit i acc = if i > n then acc else doit (i + 1) (f acc str.[i]) in doit 0 init end let () = let s = read_line () in let rec doit cnt (t, r, e) = if t < 1 || r < 1 || e < 2 then cnt else doit (cnt + 1) (t - 1, r - 1, e - 2) in String.fold_left (fun (t, r, e) c -> if c = 't' then t + 1, r, e else if c = 'r' then t, r + 1, e else if c = 'e' then t, r, e + 1 else t, r, e) (0, 0, 0) s |> doit 0 |> Printf.printf "%d\n"