F - Compressing images

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

Input

Output

Sample test(s)

Input
8 36 1 5 1 6 1 7 1 8 2 5 2 6 2 7 2 8 3 1 3 2 3 3 3 4 3 5 3 6 4 1 4 2 4 3 4 4 4 5 4 6 5 5 5 6 5 7 5 8 6 5 6 6 6 7 6 8 7 5 7 6 7 7 7 8 8 5 8 6 8 7 8 8
Output
mmwwwbmbbwwbw
Input
4 8 1 3 1 4 2 3 2 4 3 3 3 4 4 3 4 4
Output
mwbbw