ISPC 2019 - ABSTEPS

Please Share your approach of solving this problem:
ABSTEPS

it was matrix expo

in the worst case matrix size can be 25*25 ?