pbmcgY29uc2lzdGluZyBvZiA8ZW0+bTwvZW0+IGNoYXJhY3RlcnMsCiBleHByZXNzaW5nIGNvbG9ycyBvZiBkb3RzIGluIGVhY2ggbGluZS4gRWFjaCBjaGFyYWN0ZXIgaXMgYW4gdXBwZXJjYXNlIExhdGluIGxldHRlci48L3A+CgoKCk91dHB1dAo8cD4KT3V0cHV0IA=="Yes" if there exists a cycle, and "No" otherwise. Sample test(s) input
3 4
AAAA
ABCA
AAAA
output
Yes
input
3 4
AAAA
ABCA
AADA
output
No
input
4 4
YYYR
BYBY
BBBY
BBBY
output
Yes
input
7 6
AAAAAB
ABBBAB
ABAAAB
ABABBB
ABAAAB
ABBBAB
AAAAAB
output
Yes
input
2 13
ABCDEFGHIJKLM
NOPQRSTUVWXYZ
output
No
Note
In first sample test all 'A' form a cycle.
In second sample there is no such cycle.
The third sample is displayed on the picture above ('Y' = Yellow, 'B' = Blue, 'R' = Red).
#include
#include
#include
#include
#include
#include
#include