#P9155. Folding Rod Length in Binary

    ID: 22312 Type: Default 1000ms 256MiB

Folding Rod Length in Binary

Folding Rod Length in Binary

You are given a folding rod that initially has a length \( \ell=0 \). To completely unfold the rod, you need to perform exactly \( n \) operations. There are two kinds of operations:

  1. Type 1: Unfold the folding joint at the end of the rod. This operation does not have any extra parameter, and it doubles the rod's current length, i.e. \( \ell \gets 2\ell \).
  2. Type 2: Unfold the telescopic section at the rod end. This operation comes with an extra parameter \( d \) and increases the rod's length by \( d \), i.e. \( \ell \gets \ell+d \).

After executing the \( n \) operations in order, output the binary representation of the final length \( \ell \). Note that both the final rod length and the values provided may be extremely large, so you should use arbitrary precision arithmetic in your implementation.

inputFormat

The first line contains a single integer \( n \) representing the number of operations.

The following \( n \) lines each describe an operation. An operation is either:

  • A line containing a single integer 1 indicating a type-1 operation, or
  • A line starting with 2 followed by a space and a positive integer \( d \) (in decimal) for a type-2 operation.

outputFormat

Output a single line containing the binary representation of the final length \( \ell \) after processing all operations. The binary representation should not have any leading zeros (except if the number itself is 0, in which case output a single 0).

sample

1
2 5
101

</p>