time limit per test2 seconds

memory limit per test256 megabytes

inputstandard input

outputstandard output

Vanya is managed to enter his favourite site Codehorses. Vanya uses n distinct passwords for sites at all, however he can’t remember which one exactly he specified during Codehorses registration.

Vanya will enter passwords in order of non-decreasing their lengths, and he will enter passwords of same length in arbitrary order. Just when Vanya will have entered the correct password, he is immediately authorized on the site. Vanya will not enter any password twice.

Entering any passwords takes one second for Vanya. But if Vanya will enter wrong password k times, then he is able to make the next try only 5 seconds after that. Vanya makes each try immediately, that is, at each moment when Vanya is able to enter password, he is doing that.

Determine how many seconds will Vanya need to enter Codehorses in the best case for him (if he spends minimum possible number of second) and in the worst case (if he spends maximum possible amount of seconds).

Input

The first line of the input contains two integers n and k (1 ≤ n, k ≤ 100) — the number of Vanya’s passwords and the number of failed tries, after which the access to the site is blocked for 5 seconds.

The next n lines contains passwords, one per line — pairwise distinct non-empty strings consisting of latin letters and digits. Each password length does not exceed 100 characters.

The last line of the input contains the Vanya’s Codehorses password. It is guaranteed that the Vanya’s Codehorses password is equal to some of his n passwords.

Output

Consider the first sample case. As soon as all passwords have the same length, Vanya can enter the right password at the first try as well as at the last try. If he enters it at the first try, he spends exactly 1 second. Thus in the best case the answer is 1. If, at the other hand, he enters it at the last try, he enters another 4 passwords before. He spends 2 seconds to enter first 2 passwords, then he waits 5 seconds as soon as he made 2 wrong tries. Then he spends 2 more seconds to enter 2 wrong passwords, again waits 5 seconds and, finally, enters the correct password spending 1 more second. In summary in the worst case he is able to be authorized in 15 seconds.

Examples

input

5 2

cba

abc

bb1

abC

ABC

abc

output

1 15

input

4 100

11

22

1

2

22

output

3 4

Note

Consider the second sample case. There is no way of entering passwords and get the access to the site blocked. As soon as the required password has length of 2, Vanya enters all passwords of length 1 anyway, spending 2 seconds for that. Then, in the best case, he immediately enters the correct password and the answer for the best case is 3, but in the worst case he enters wrong password of length 2 and only then the right one, spending 4 seconds at all.

【题解】



只要找到和正确的密码一样长的“试验”密码即可。

所以密码本身是什么根本不重要。只要记录密码的长度就好。

具体的,记录密码长度为i的密码个数为num[i];

求前缀和。

然后设正确密码的长度为key;

和key一样长的密码组成的序列。

把正确密码放在最前面是最优的,把正确密码放在最后面则是最坏情况。

处理一下输出的情况即可。

看代码吧。

#include <cstdio>
#include <cstring> const int MAXN = 150; int num[MAXN] = { 0 }, n, k, sum[MAXN] = { 0 },key,p = 0;
char s[MAXN]; int main()
{
//freopen("F:\\rush.txt", "r", stdin);
scanf("%d%d", &n, &k);
for (int i = 1; i <= n; i++)
{
scanf("%s", s);
int len = strlen(s);
num[len]++;
}
scanf("%s", s);
key = strlen(s);
for (int i = 1; i <= key; i++)
sum[i] = sum[i - 1] + num[i];
p = sum[key - 1];
for (int i = 1;i <= sum[key-1];i++)
if ((i%k) == 0)//要多加的时间
p += 5;
if (num[key] == 1)//如果和正确密码一样长的只有正确密码本身
printf("%d %d\n", p + 1, p + 1);
else
{
printf("%d ", p + 1);//最优情况
for (int i = sum[key - 1] + 1; i <= sum[key] - 1; i++) //最坏情况是在最后面
{
p++;
if ((i%k) == 0)
p += 5;
}
printf("%d\n", p + 1);
}
return 0;
}

最新文章

  1. how to enable remote access for root user
  2. error LNK2038: 检测到“_ITERATOR_DEBUG_LEVEL”的不匹配项:值“0”不匹配值“2”
  3. POC - ASP.NET &amp; IIS 部分
  4. Android实例] android获取web服务器端session并验证登陆
  5. Altium自定义的快捷键设置
  6. 配置并学习微信JS-SDK(3)&mdash;菜单接口
  7. CTE Recursion Performance
  8. border-radius讲解2
  9. 学习笔记之NodeJs基本操作
  10. 关于svn的安装问题
  11. MYSQL数据库表按月备份,滚动,保留6次备份
  12. [BZOJ1503] [NOI2004] 郁闷的出纳员 (treap)
  13. 设计模式——工厂方法模式(C++实现)
  14. stylus 详解与引入
  15. CountDownLatch、CyclicBarrier和Semaphore基本原理和使用
  16. 安装软件the error code is 2203解决方法
  17. Part-Nine
  18. pom.xml文件最详细的讲解
  19. Oracle中序列(Sequence)详解
  20. 黄聪:Jquery+DataTables插件,如何在ajax调用服务器数据后,自动给tr添加id属性

热门文章

  1. httpurlconnection发送文件到服务端并接收
  2. 前端项目中常用es6知识总结 -- Async、Await让异步美如画
  3. JS数组排序技巧汇总(冒泡、sort、快速、希尔等排序)
  4. MySQLSocketPHPvimApache
  5. CODEVS——T1979 第K个数
  6. Spark MLlib LDA 源代码解析
  7. java和javascript日期校验和闰年问题分析和解决方式
  8. MyCat中间件:读写分离(转)
  9. COGS——C66. [HAOI2004模拟] 数列问题
  10. UVA 294 294 - Divisors (数论)