S = gets.strip icnt = 0 cnt = 0 (S.length-1).downto(0) {|i| cnt += icnt if S[i] == "S" icnt += 1 if S[i,3] == "ing" } puts cnt