#include<bits/stdc++.h> #define MAX_N 300000 usingnamespace std; typedeflonglong lnt; int n, a[MAX_N+5]; char s[MAX_N+5]; int sa[MAX_N+5], rk[MAX_N+5], height[MAX_N+5], tsa[MAX_N+5], cntA[MAX_N+5], cntB[MAX_N+5], A[MAX_N+5], B[MAX_N+5]; lnt ans[MAX_N+5][2]; vector <int> m[MAX_N+5]; int fa[MAX_N+5], mina[MAX_N+5], maxa[MAX_N+5], size[MAX_N+5]; intgetf(int x){return x == fa[x] ? x : fa[x] = getf(fa[x]);} voidCalcSA(){ for (int i = 1; i <= 26; i++) cntA[i] = 0; for (int i = 1; i <= n; i++) cntA[s[i]-'a'+1]++; for (int i = 1; i <= 26; i++) cntA[i] += cntA[i-1]; for (int i = n; i >= 1; i--) sa[cntA[s[i]-'a'+1]--] = i; rk[sa[1]] = 1; for (int i = 2; i <= n; i++) {rk[sa[i]] = rk[sa[i-1]]; if (s[sa[i]] != s[sa[i-1]]) rk[sa[i]]++;} for (int l = 1; l < n; l <<= 1) { for (int i = 1; i <= n; i++) cntA[i] = 0; for (int i = 1; i <= n; i++) cntB[i] = 0; for (int i = 1; i <= n; i++) cntA[A[i] = rk[i]]++, cntB[B[i] = (i+l <= n) ? rk[i+l] : 0]++; for (int i = 1; i <= n; i++) cntB[i] += cntB[i-1]; for (int i = n; i >= 1; i--) tsa[cntB[B[i]]--] = i; for (int i = 1; i <= n; i++) cntA[i] += cntA[i-1]; for (int i = n; i >= 1; i--) sa[cntA[A[tsa[i]]]--] = tsa[i]; rk[sa[1]] = 1; for (int i = 2; i <= n; i++) { rk[sa[i]] = rk[sa[i-1]]; if (A[sa[i]] != A[sa[i-1]] || B[sa[i]] != B[sa[i-1]]) rk[sa[i]]++; } } for (int i = 1, j = 0; i <= n; i++) { if (j) j--; while (s[i+j] == s[sa[rk[i]-1]+j]) j++; height[rk[i]] = j; } } intmain(){ scanf("%d", &n), scanf("%s", s+1); lnt tot = 0, pro = 0; for (int i = 1; i <= n; i++) scanf("%d", a+i); CalcSA(); for (int i = 2; i <= n; i++) m[height[i]].push_back(i); for (int i = 1; i <= n; i++) fa[i] = i, size[i] = 1, mina[i] = maxa[i] = a[sa[i]]; for (int i = n-1; ~i; i--) { for (int j = 0; j < (int)m[i].size(); j++) { int u = getf(m[i][j]), v = getf(m[i][j]-1); if (u == v) continue; if (!tot) pro = max(1LL*mina[u]*mina[v], 1LL*maxa[u]*maxa[v]); else pro = max(pro, max(1LL*mina[u]*mina[v], 1LL*maxa[u]*maxa[v])); tot += 1LL*size[u]*size[v], fa[v] = u, size[u] += size[v]; mina[u] = min(mina[u], mina[v]), maxa[u] = max(maxa[u], maxa[v]); } ans[i][0] = tot, ans[i][1] = pro; } for (int i = 0; i < n; i++) printf("%lld %lld\n", ans[i][0], ans[i][1]); return0; }