Let's build an interpreter that computes with lists. It must handle several kinds of expressions. In order of precedence, from highest to lowest, the operators are: parentheses, array slicing, unary operators, binary operators, list concatenation, and assignment.
Array slicing is written as [begin:end] and placed after an expression, returning a sublist of that list. Indices start at 0; begin is inclusive and end is exclusive. Thus L[1:3] is the list made of the elements of L at indices 1 and 2. Either begin or end may be omitted: an omitted begin is treated as 0, and an omitted end as the length of the list. If end is less than or equal to begin, the result is the empty list. Both begin and end are at most 15, and indices are never out of range.
Unary operators +, -, *, / are placed before a list. Repeatedly, the first two elements are removed, the operator is applied to them as a binary operation, and the result is placed back at the front of the list; this continues until a single element remains. For example, +(1:2:4) removes 1 and 2 and puts their sum 3 at the front, giving +(3:4); then it removes 3 and 4 and puts their sum 7 at the front, giving +(7); since only one element remains, the result is 7. A unary operator is never applied to an infinite or empty list.
Binary operators +, -, *, / combine the elements at corresponding positions of two lists. If one list is shorter than the other, its last element is repeated at the end to match the longer length. For instance, in (1:2:3)+(4:5) the list (4:5) is padded with one more copy of its last element 5 to become (4:5:5), and adding position by position yields (5:7:8). If either list is empty, the result is the empty list; for example, A-A[2:2] has an empty right operand, so the result is empty. Among binary operations, multiplication and division have higher precedence than addition and subtraction.
List concatenation is written with the colon : operator. A constant is treated as a list of length 1.
Assignment is written with the equals = operator. Every variable is a single character and is case-sensitive; a variable is never redefined. A variable's definition never refers to a not-yet-defined variable, but it may refer to itself recursively.
All division is integer division following the rules of C/C++ (truncation toward zero). Division by zero never occurs. Constants in expressions are always integers, and a unary operator never appears directly before a constant. Every integer that arises during the computation fits in a 32-bit integer type.
The input consists of several lines. Each line is either an assignment statement or an output statement beginning with the keyword print. Each line is at most 50 characters long, and the whole input is at most 30 lines. A line containing only # may appear at the end of the input; that line is ignored.
For each output statement, print on one line the elements of the list denoted by the expression after print, separated by colons : with no spaces. If the list is empty, print an empty line. The length of a printed list never exceeds 15.