After the big birthday party, Katie still wanted Shiro to have some more fun. Later, she came up with a game called treasure hunt. Of course, she invited her best friends Kuro and Shiro to play with her.
The three friends are very smart so they passed all the challenges very quickly and finally reached the destination. But the treasure can only belong to one cat so they started to think of something which can determine who is worthy of the treasure. Instantly, Kuro came up with some ribbons.
A random colorful ribbon is given to each of the cats. Each color of the ribbon can be represented as an uppercase or lowercase Latin letter. Let's call a consecutive subsequence of colors that appears in the ribbon a subribbon. The beauty of a ribbon is defined as the maximum number of times one of its subribbon appears in the ribbon. The more the subribbon appears, the more beautiful is the ribbon. For example, the ribbon aaaaaaa has the beauty of 7
because its subribbon abc appears twice.
The rules are simple. The game will have n
turns. Every turn, each of the cats must change strictly one color (at one position) in his/her ribbon to an arbitrary color which is different from the unchanged one. For example, a ribbon aaab can be changed into acab in one turn. The one having the most beautiful ribbon after nturns wins the treasure.
Could you find out who is going to be the winner if they all play optimally?
The first line contains an integer n
) — the number of turns.
Next 3 lines contain 3 ribbons of Kuro, Shiro and Katie one per line, respectively. Each ribbon is a string which contains no more than 105
uppercase and lowercase Latin letters and is not empty. It is guaranteed that the length of all ribbons are equal for the purpose of fairness. Note that uppercase and lowercase letters are considered different colors.
Print the name of the winner ("Kuro", "Shiro" or "Katie"). If there are at least two cats that share the maximum beauty, print "Draw".
3 Kuroo Shiro Katie
Kuro
7 treasurehunt threefriends hiCodeforces
Shiro
1 abcabc cbabac ababca
Katie
15 foPaErcvJ mZaxowpbt mkuOlaHRE
Draw
In the first example, after 3
, for example by changing Shiro's ribbon into SSiSS and changing Katie's ribbon into Kaaaa). Therefore, the winner is Kuro.
In the fourth example, since the length of each of the string is 9
and the number of turn is 15, everyone can change their ribbons in some way to reach the maximal beauty of 9 by changing their strings into zzzzzzzzz after 9 turns, and repeatedly change their strings into azzzzzzzz and then into zzzzzzzzz thrice. Therefore, the game ends in a draw.
#define happy
#include
using namespace std;
#define ll long long
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define all(a) (a).begin(),(a).end()
#define pll pair
#define vi vector
#define pb push_back
ll rd(){
ll x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
int cnt[52];
int ch(char c){
if(c>='a'&&c<='z')return c-'a';
return c-'A'+26;
}
const int N=1e5+10;
char u[N];
int getans(int n){
scanf("%s",u);
int i,len=strlen(u);
memset(cnt,0,sizeof(cnt));
rep(i,0,len-1)cnt[ch(u[i])]++;
if(len==1)return 1;
int mx=0;
rep(i,0,51)mx=max(mx,cnt[i]);
if(mx==len){
if(n==1)return mx-1;
return mx;
}
return min(len,mx+n);
}
int main(){
#ifdef happy
freopen("in.txt","r",stdin);
#endif
int n=rd();
int v[3];
v[0]=getans(n);
v[1]=getans(n);
v[2]=getans(n);
int mx=max(v[0],max(v[2],v[1]));
int c=0;
rep(i,0,2)if(v[i]==mx)c++;
if(c>=2)return puts("Draw"),0;
if(v[0]==mx)puts("Kuro");
if(v[1]==mx)puts("Shiro");
if(v[2]==mx)puts("Katie");
return 0;
}