S = gets.chomp s_cnt = 0 ing_cnt = 0 ans = 0 S.each_char.with_index do |s, idx| if s == 'S' s_cnt += 1 elsif idx >= 2 && S[idx - 2..idx] == 'ing' ing_cnt += 1 ans += s_cnt end end puts ans