def main(): S = input() S_reverse = S[::-1] ing_count = [0] for idx, letter in enumerate(S_reverse): if S_reverse[idx:].startswith("gni"): ing_count[-1] += 1 if letter == "S": ing_count.append(0) ing_count = ing_count[:-1] if not ing_count: print(0) return ing_count_partial_sum = [] for count_ in ing_count: if not ing_count_partial_sum: ing_count_partial_sum.append(count_) else: ing_count_partial_sum.append(ing_count_partial_sum[-1]+count_) print(sum(ing_count_partial_sum)) if __name__ == "__main__": main()