Dd4d2FṙRḄṢIS

Too slow and memory hungry for the last two test cases. This could be fixed, at the cost of a byte, by replacing ṙR with ṙJ\$.