Cocktail Party

아직 제출이 없습니다시간 제한1초메모리 제한1024 MB

문제

You are given a string of length nn representing the labels of nn cups of cocktail. The ii-th cup of cocktail has label s_is\_i, and the labels are among the 26 lowercase English letters. Let Str(l,r)=s_ls_l+1s_r\mathrm{Str}(l,r) = s\_l s\_{l+1} \cdots s\_r be the string formed by the labels of the cocktails from the ll-th cup to the rr-th cup. If Str(p,p_0)=Str(q,q_0)\mathrm{Str}(p,p\_0) = \mathrm{Str}(q,q\_0) where 1pp_0n1 \le p \le p\_0 \le n1qq_0n1 \le q \le q\_0 \le npqp \ne qp_0p+1=q_0q+1=rp\_0-p+1 = q\_0-q+1 = r, we say the pp-th cup of cocktail and qq-th cup of cocktail are rr-similar. Of course, for two cups of cocktail that are rr-similar (r>1r > 1) they are also 1-similar, 2-similar, ..., and (r1)(r-1)-similar. In particular, for any 1pqn,pq1 \le p \le q \le n, p \ne q, the pp-th cup of cocktail and qq-th cup of cocktail are 00-similar.

Freda assigns the "deliciousness" for each cup of cocktail, and the ii-th cup has deliciousness a_ia\_i. If we mix pp-th cup of cocktail and qq-th cup of cocktail, we may obtain cocktail with deliciousness a_pa_qa\_p a\_q. The problem asks for each r=0,,n1r = 0,\dots,n-1, how many ways we may select two cups of cocktail that are rr-similar, and compute the maximum possible deliciousness by mixing two cups of cocktail that are rr-similar.

입력

The first line of the input contains an integer nn denoting the number of cups of cocktail. The second line contains a string SS with length nn such that the ii-th character denotes the label of the ii-th cup of cocktail. The third line contains nn integers separated by a single space such that the ii-th integer denotes the ii-th cup of cocktail has deliciousness a_ia\_i.

출력

The output contains nn lines. The ii-th line contains two integers separated by a single space. The first integer denotes the number of ways to choose two cups of (i1)(i-1)-similar cocktails. The second integer denotes the maximum possible deliciousness by mixing two cups of cocktails that are (i1)(i-1)-similar. Notice if there does not exist two cups of cocktail that are (i1)(i-1)-similar, both integers in that line of the output shall be 0.

제한

  • 10n300,00010 ≤ n ≤ 300\\,000
  • a_i1,000,000,000|a\_i| \le 1\\,000\\,000\\,000