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).
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.
Print two integers — time (in seconds), Vanya needs to be authorized to Codehorses in the best case for him and in the worst case respectively.
5 2 cba abc bb1 abC ABC abc
1 15
4 100 11 22 1 2 22
3 4
#include<cstdio> #include<cstring> #include<algorithm> using namespace std; int main() { int n,k; char mima[110]; int a[110]; while(~scanf("%d%d",&n,&k)) { for(int i = 0; i <= n; i++) { memset(mima,'\0',sizeof(mima)); scanf("%s",mima); a[i] = strlen(mima); } sort(a,a+n); int t = lower_bound(a,a+n,a[n]) - a; int e = upper_bound(a,a+n,a[n]) - a; int min_T = 0,max_T = 0; min_T = t / k * 5 + (t + 1); max_T = (e - 1) / k * 5 + e; printf("%d %d\n",min_T,max_T); } return 0; }