No.805 UMG
タグ : / 解いたユーザー数 421
作問者 :
sinsincoscos
/ テスター :
tempura_pp
Problem Statement
There is a string $S$ of length $N$ in which only the three kinds of characters 'U', 'M', and 'G' appear. Let $s_i$ be the $i$-th character from the beginning (1-indexed). Find the number of tuples $(i,j,k)$
satisfying both of the following conditions 1 and 2.
1. $1\le i\lt j \lt k\le N$ and $j-i=k-j$
2. $s_i=$'U', $s_j=$'M', $s_k=$'G'
Note
Python users are recommended to submit with PyPy3.
Input
$N$ $S$
$3\le N \le 5000$
$|S|=N$
$S$ is a string consisting of 'U', 'M', and 'G'.
Output
Output the number representing the answer on one line. Print a newline at the end.
Sample
Sample 1
Input
5 UUMGG
Output
2
$(1,3,5),(2,3,4)$ satisfy the conditions.
Sample 2
Input
4 UUUU
Output
0
There is no 'M' or 'G' in the first place.
Sample 3
Input
10 UUMMGGGUMG
Output
4
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。