問題一覧 > 通常問題

No.279 Counting Trees

レベル : / AI推定難易度 : 115 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 64 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 753
作問者 : 紙ぺーぱー
お気に入りにしたユーザー ProblemId : 531 / 自分の提出
問題文最終更新日: 2026-06-25 11:04:52
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
yukicoder contest 121 (順位表) の他の問題:

Problem Statement

kamipeipaa loves trees, but today he is playing with strings.
He is curious about how many substrings "tree" can be formed by rearranging the string $S$. Please tell him.

Input

$S$

The string $S(1 \le |S| \le 10^{6})$ that kamipeipaa has, consisting only of lowercase English letters, is given in one line.

Output

Output in one line the maximum number of substrings "tree" that can be formed by freely rearranging $S$. Do not forget the newline.

Sample

Sample 1
Input
takahashikunlovesyukicoder
Output
1

"takahashikunlovesyukicoder" can be rearranged into "treeakahashikunlovsyukicod", which contains one substring "tree".

Sample 2
Input
treapisnotki
Output
0

No matter how "treapisnotki" is rearranged, the substring "tree" cannot be obtained.

Sample 3
Input
eerteerteerteert
Output
4

The string "eerteerteerteert" can be rearranged into "treetreetreetree", which contains four substrings "tree".

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。