Codeforces Round 263 (Div. 1)
E
Appleman and a Game
Codeforces
3000
原题
← D→
翻译中…

Appleman and Toastman like games. Today they play a game with strings with the following rules. Firstly Toastman tells Appleman two strings $*s*$ and $*t*$ both consisting only of letters 'A', 'B', 'C', 'D'. Then Appleman must build string $*s*$ as quickly as possible. Initially he has empty string, and in one second he can append to end of the current string any contiguous substring of $*t*$.

翻译中…

Now, Toastman and Appleman are beginning to play the game. Toastman has already told string $*t*$ to Appleman, but he hasn't come up with string $*s*$ yet. Toastman only thinks, that he should choose string $*s*$ consisting of $*n*$ characters. Of course, he wants to find the worst string for Appleman (such string, that Appleman will spend as much time as possible during the game). Tell Toastman, how much time will Appleman spend during the game if Toastman finds the worst string for him. You can assume that Appleman plays optimally, therefore he builds any string $*s*$ in minimal possible time.

翻译中…

Input

翻译中…

The first line contains an integer $*n*$ ($1 ≤ *n* ≤ 10^{18}$). The second line contains string $*t*$ ($1 ≤ |*t*| ≤ 10^{5}$). String $*t*$ consists of only letters 'A', 'B', 'C', 'D'. Each letter appears at least once in string $*t*$.

翻译中…

Output

翻译中…

Print a single integer — the largest possible time Appleman needs.

翻译中…

Note

翻译中…

In the first example, Toastman can choose $*s*$ equal to "AAAAA".

翻译中…

In the second example, Toastman can choose $*s*$ equal to "DADDA".

翻译中…

样例

Input #1
5
ABCCAD
Output #1
5
InputCopy OutputCopy
Input #2
5
AAABACADBABBBCBDCACBCCCDDDBDCDD
Output #2
4
InputCopy OutputCopy
题目信息
题号
461E
时间限制
1 s
内存限制
256 MB
标签
二分
最短路
字符串

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