QOJ.ac

QOJ

Süre Sınırı: 3 s Bellek Sınırı: 1024 MB Toplam puan: 100 Hack'lenebilir ✓

#19020. Force!

İstatistikler

Little N defined a function $f(X, Y)$ on two strings $X$ and $Y$ (both strings are indexed starting from $1$), satisfying:

$$\begin{aligned} f(X, Y) = \sum_{i = 1}^{\min(\vert X \vert, \vert Y \vert)} [X_i = Y_i] \end{aligned}$$

(For a proposition $A$, if $A$ is true, then $[A] = 1$; otherwise, $[A] = 0$.)

That is, it is the number of positions where the corresponding characters of strings $X$ and $Y$ are equal. For example, $f(\texttt{axc}, \texttt{abc}) = 2$, $f(\texttt{abxc}, \texttt{abc}) = 2$, $f(\texttt{abc}, \texttt{abxc}) = 2$.

Now, Little N gives a string $S$ of length $n$ consisting only of lowercase English letters. Let $S_i$ denote the suffix of $S$ starting from the $i$-th character. Please output, for each $k = 1, 2, \dots, n$, the value of $f(S_1, S_k) + f(S_2, S_k) + \dots + f(S_n, S_k)$.

Input

There are two lines of input.

The first line contains an integer $n$ $(1 \le n \le 10^5)$, representing the length of string $S$.

The second line contains a string $S$ of length $n$ consisting only of lowercase English letters.

Output

Output $n$ lines. The $k$-th line contains the value of $f(S_1, S_k) + f(S_2, S_k) + \cdots + f(S_n, S_k)$.

Examples

Input 1

3
abb

Output 1

4
4
2

Input 2

11
mississippi

Output 2

24
26
23
24
21
17
15
11
7
6
4

Note

For sample 1, $S_1 = \texttt{abb}$, $S_2 = \texttt{bb}$, $S_3 = \texttt{b}$.

When $k = 1$, $f(S_1, S_1) + f(S_2, S_1) + f(S_3, S_1) = 3 + 1 + 0 = 4$.

When $k = 2$, $f(S_1, S_2) + f(S_2, S_2) + f(S_3, S_2) = 1 + 2 + 1 = 4$.

When $k = 3$, $f(S_1, S_3) + f(S_2, S_3) + f(S_3, S_3) = 0 + 1 + 1 = 2$.

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.