B - Earth Worms

Languages: C, C++, Java, Python, Kotlin
Time & Memory limits: (details)

Input

Output

Sample test(s)

Input
3 ABC BAC CAB ACAB 1 AAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA 2 PAA AAA AAAAAAAAAAAAAAAP 1 BAB AAAAAAB 0
--- Showing first 30 lines (click "Copy" to get full content) ---
Output
2 6 -1 6
--- Showing first 30 lines (click "Copy" to get full content) ---