# The Problem A lazy beaver brought his tally counter to a Turing machine. This counter shows a non-negative integer from 0 to a certain value `k`. It has two buttons, `+` and `-`, to increase and decrease the value by 1 respectively. This Turing machine contains an infinite tape, where each cell can contain a 0 or a 1. Initially, the tape has all 0s. The beaver stands on top of a single cell at a time, and at each step it can move either left or right (but not stand still). Note that the tape is infinite both ways, and the beaver can move an arbitrarily large amount of steps to the right or to the left. The beaver also has 4 possible states, {A, B, C, D}. The initial state is `A`. The lazy beaver's tally counter starts at 0, and can hold any number in the range [0, k). At each step the beaver can increase the counter by 1, decrease it by 1, or leave it as it is. The counter reaching `k` corresponds to a final state: when this happens, the beaver worked enough for the day and will go back home to join a programming contest. The beaver decides what to do at each step using the current state, the number on the tape where the beaver is currently standing, and the number on the tally counter. It can change its state, change the number on the tape where it's standing (before moving), increase or decrease the tally counter (or neither), and move left or right (but cannot stand still!). Formally, this Turing machine can be defined as the 8-tuple , where: * Q = {A, B, C, D} the possible states of the beaver. * N = [0, k) the non-negative natural numbers of the counter. * Γ = {0, 1} the two possible states of the infinite tape. * b = 0 the blank symbol is 0. * Σ = ∅ the tape always starts with all 0s. * q₀ = the initial state is A, and the initial value of the counter is 0. * F = Q x {k} the machine halts when the counter reaches `k`, regardless of the current state. * δ : (Q, N, Γ) → (Q, {+, 0, -}, Γ, {←, →}) the transition function. The transition function δ can be defined as the following, where `n` corresponds to any number in the range [0, k), and `n > 0` corresponds to any number in the range [1, k). The second argument contains `+`, `0`, and `-` if the beaver is to increase the counter, leave it as it is, or decrease the counter respectively. ``` δ(A, 0, 0) = (B, +, 0, →) δ(A, n > 0, 0) = (B, 0, 0, →) δ(A, n, 1) = (A, +, 1, →) δ(B, 0, 0) = (C, 0, 0, ←) δ(B, n > 0, 0) = (B, -, 1, →) δ(B, n, 1) = (B, 0, 1, →) δ(C, 0, 0) = (D, +, 0, ←) δ(C, n > 0, 0) = (D, 0, 0, ←) δ(C, n, 1) = (C, +, 1, ←) δ(D, 0, 0) = (A, 0, 0, →) δ(D, n > 0, 0) = (D, -, 1, ←) δ(D, n, 1) = (D, 0, 1, ←) ``` The transition function is total and unambiguous: there is exactly one tuple of arguments δ that corresponds to each valid combination of state, tally counter, and tape value. The tally counter will never go negative, and it's guaranteed that it will eventually reach `n = k` and terminate the program. # Output The beaver wants to know how many 1s there will be in the tape by the time his tally counter runs out of numbers and he returns home. The solution string consists of four comma separated integers, corresponding to the number of `1` remaining on the tape after the tally counter reaches `k` for the following values of `k`: 1. k = 10 2. k = 144 3. k = 2^20 4. k = 2^60 So for example if the corresponding numbers were 1, 2, 3 and 4, the final answer would be the string "1,2,3,4" # Example Let's follow the steps of this beaver for a few steps. **Step 1**: v 00000000000 State: A Counter: 0 Tape: 0 Chosen Rule: δ(A, 0, 0) = (B, +, 0, →) Ones: 0 **Step 2**: v 00000000000 State: B Counter: 1 Tape: 0 Chosen rule: δ(B, n > 0, 0) = (B, -, 1, →) Ones: 0 **Step 3**: v 00000010000 State: B Counter: 0 Tape: 0 Chosen rule: δ(B, 0, 0) = (C, 0, 0, ←) Ones: 1