Under construction

Still being built. Things may change

Color Change of Go Stones

Interview

Time limit1sMemory limit128 MB

Summary
Repeat k times the rule that replaces each circular gap with the xor of its two neighbors, then count the white stones.
Level

Easy3 of 10

Topics
Simulation, Array
Solved
No attempts yet

Problem

A box holds plenty of black and white Go stones. Take nn stones out of the box. The mm stones taken out first are all white and the rest are all black. Lay all nn stones around a circle at even spacing, in the order they came out.

Next, look at the colors on that circle and take new stones from the box to build a new circle. Go around the circle once and place one new stone in each gap between two neighboring stones, by these rules.

  • Between two white stones, place a black stone.
  • Between a white stone and a black stone, place a white stone.
  • Between two black stones, place a black stone.
  • Between a black stone and a white stone, place a white stone.

There are nn gaps, so the new circle holds nn stones as well. Once every new stone is in place, remove all nn original stones. That is one repetition, and the circle that remains goes through the same process again.

Find how many white stones are on the circle after the kk-th repetition.

The picture below shows the case n=8n = 8, m=2m = 2, k=2k = 2. From the left: the starting circle, the circle after the first repetition, and the circle after the second repetition.

nn and kk are natural numbers with 0<n<1290 < n < 129 and k<10001k < 10001. mm satisfies 1≤m≤n1 \le m \le n.

Input

Each line holds one group of data. A line has the natural numbers nn, mm, kk separated by single commas, with no spaces. The line after the last group holds -1, which marks the end of the input.

Output

Print one line for each group of data. A line starts with the input data written back in the form n,m,k, then a colon and one space, then the number of white stones.

Examples1

  1. Example 1

    Input
    8,2,2
    3,1,1234
    -1
    
    Expected output
    8,2,2: 4
    3,1,1234: 2