Nebius Welcome Round (Div. 1 + Div. 2)
H
Code Lock
Codeforces
3300
原题
← G→
翻译中…

Lara has a safe that is locked with a circle-shaped code lock that consists of a rotating arrow, a static circumference around the arrow, an input screen, and an input button.

翻译中…

The circumference of the lock is split into $k$ equal sections numbered from $1$ to $k$ in clockwise order. Arrow always points to one of the sections. Each section is marked with one of the first $k$ letters of the English alphabet. No two sections are marked with the same letter.

翻译中…

Due to the lock limitations, the safe's password is a string of length $n$ that consists of first $k$ letters of the English alphabet only. Lara enters the password by rotating the lock's arrow and pressing the input button. Initially, the lock's arrow points to section $1$ and the input screen is empty. In one second she can do one of the following actions.

翻译中…
  • Rotate the arrow one section clockwise. If the arrow was pointing at section $x \lt k$ it will now point at section $x + 1$. If the arrow was pointing at section $k$ it will now point at section $1$.
  • Rotate the arrow one section counter-clockwise. If the arrow was pointing at section $x \gt 1$ it will now point at section $x - 1$. If the arrow was pointing at section $1$ it will now point at section $k$.
  • Press the input button. The letter marked on the section that the arrow points to will be added to the content of the input screen.
翻译中…

As soon as the content of the input screen matches the password, the safe will open. Lara always enters her password in the minimum possible time.

翻译中…

Lara has recently found out that the safe can be re-programmed. She can take the first $k$ letters of the English alphabet and assign them to the sectors in any order she likes. Now she wants to re-arrange the letters in a way that will minimize the number of seconds it takes her to input the password. Compute this minimum number of seconds and the number of ways to assign letters, for which this minimum number of seconds is achieved.

翻译中…

Two ways to assign letters to sectors are considered to be distinct if there exists at least one sector $i$ that is assigned different letters.

翻译中…

Input

翻译中…

The first line of the input contains two integers $k$ and $n$ ($2 \leq k \leq 16$, $2 \leq n \leq 100\,000$) — the number of sectors on the lock's circumference and the length of Lara's password, respectively.

翻译中…

The second line of the input contains a string of length $n$ that consists of the first $k$ lowercase letters of the English alphabet only. This string is the password.

翻译中…

Output

翻译中…

On the first line print minimum possible number of seconds it can take Lara to enter the password and open the safe if she assigns letters to sectors optimally.

翻译中…

On the second line print the number of ways to assign letters optimally.

翻译中…

Note

翻译中…

The initial states of optimal arrangements for the first example are shown in the figure below.

翻译中…

image

翻译中…

The initial states of optimal arrangements for the second example are shown in the figure below.

翻译中…

image

翻译中…

The initial states of optimal arrangements for the third example are shown in the figure below.

翻译中…

image

翻译中…

样例

Input #1
3 10
abcabcabca
Output #1
19
2
InputCopy OutputCopy
Input #2
4 20
bcbcbcbcadadadadcbda
Output #2
40
2
InputCopy OutputCopy
Input #3
4 6
adcbda
Output #3
12
4
InputCopy OutputCopy
题目信息
题号
1804H
时间限制
7 s
内存限制
512 MB
标签
位运算
动态规划

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。