CF461E.Appleman and a Game

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Appleman and Toastman like games. Today they play a game with strings with the following rules. Firstly Toastman tells Appleman two strings ss and tt both consisting only of letters 'A', 'B', 'C', 'D'. Then Appleman must build string ss 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 tt .

Now, Toastman and Appleman are beginning to play the game. Toastman has already told string tt to Appleman, but he hasn't come up with string ss yet. Toastman only thinks, that he should choose string ss consisting of nn 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 ss in minimal possible time.

输入格式

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

输出格式

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

输入输出样例

  • 输入#1

    5
    ABCCAD
    

    输出#1

    5
    
  • 输入#2

    5
    AAABACADBABBBCBDCACBCCCDDDBDCDD
    

    输出#2

    4
    

说明/提示

In the first example, Toastman can choose ss equal to "AAAAA".

In the second example, Toastman can choose ss equal to "DADDA".

首页