Biswa and Red-Black Ants

Limits: 3s, 1.0 GB

Biswa has come to Antland for a trip. There are N holes in total in Antland. He can start visiting from any of the holes. In each hole, there is a magic number which is the number of the hole that Biswa should visit after the current hole. K of the holes are the hubs for red ants and the remaining holes are the hubs for black ants. One of the black ants’ hole is also the headquarter of the black ants. There are some conditions while visiting the holes:


This is a companion discussion topic for the original entry at https://toph.co/p/biswa-and-red-black-ants