LA 3510

LA 3510 - Pixel Shuffle

 * http://acmicpc-live-archive.uva.es/nuevoportal/data/problem.php?p=3510

Summary
The problem statements defines several operations on square images. Each of the operations is some simple permutation of the image's pixels. The input contains a sequence of operations. Your program should output the smallest positive K such that applying the whole sequence of operations K times always yields the original image.

Explanation
The sequence of operations defines a (more complicated) permutation of the image's pixels. Split this permutation into cycles, the answer is the least common multiple of the cycle lengths.

Input
256 rot- div rot div 256 bvsym div mix

Output
8 63457