Under construction

Still being built. Things may change

Hash Function

Time limit3sMemory limit1024 MB

Summary
Given n and H, find a 2n-bit number A such that the XOR-and-modular hash h_n(A) equals H.
Level

Hard8 of 10

Topics
Bit manipulation, Math, Dynamic programming
Solved
No attempts yet

Problem

A hash function h_nh\_n encrypts a number AA consisting of 2n2n bits as follows.

Let A=(a_2n−1a_2n−2⋯a_1a_0)_2A = (a\_{2n-1}a\_{2n-2} \cdots a\_1a\_0)\_2, where a_ia\_i is the ii-th bit of AA.

The number B=(b_2n−1b_2n−2⋯b_1b_0)_2B = (b\_{2n-1}b\_{2n-2} \cdots b\_1b\_0)\_2, also consisting of 2n2n bits, is computed as follows:

b_i=a_i⊕a_2i+1, for 0≤i<n,b\_i = a\_i \oplus a\_{2i+1},\text{ for } 0 \le i < n, b_i=a_i⊕a_4n−2i−2, for n≤i<2n,b\_i = a\_i \oplus a\_{4n-2i-2},\text{ for } n \le i < 2n,

where ⊕\oplus is bitwise exclusive OR (XOR). In other words, B=A⊕(a_0a_2⋯a_2n−4a_2n−2a_2n−1a_2n−3⋯a_3a_1)_2.B = A \oplus (a\_0a\_2 \cdots a\_{2n-4}a\_{2n-2}a\_{2n-1}a\_{2n-3} \cdots a\_3a\_1)\_2.

Next, the number C=B⊕RSH(B)C = B \oplus \text{RSH}(B) is computed, also consisting of 2n2n bits, where RSH(B)\text{RSH}(B) is a cyclic right shift of BB by 1 bit. In other words, C=B⊕(b_0b_2n−1b_2n−2⋯b_2b_1)_2C = B \oplus (b\_0b\_{2n-1}b\_{2n-2} \cdots b\_2b\_1)\_2.

Finally, the hash value is h_n(A)=239A+153C mod (22n−1−1)h\_n(A) = 239A + 153C \bmod (2^{2n-1}-1).

For example, let n=4n=4 and A=00001101_2=13A = 00001101\_2 = 13. Then B=00001101_2⊕11000010_2=11001111_2=207B = 00001101\_2 \oplus 11000010\_2 = 11001111\_2 = 207. Next, C=11001111_2⊕11100111_2=00101000_2=40C = 11001111\_2 \oplus 11100111\_2 = 00101000\_2 = 40. Finally, h_4(A)=239×13+153×40 mod (27−1)=9227 mod 127=83h\_4(A) = 239 \times 13 + 153 \times 40 \bmod (2^7-1) = 9227 \bmod 127 = 83.

Your goal is to invert this hash function. For given nn and HH, find AA such that h_n(A)=Hh\_n(A)=H.

Input

You are given two integers nn and HH (2≤n≤162 \le n \le 16, 0≤H<22n−1−10 \le H < 2^{2n-1}-1).

It is guaranteed that there exists AA (0≤A<22n0 \le A < 2^{2n}) such that h_n(A)=Hh\_n(A)=H.

Output

Print one integer AA (0≤A<22n0 \le A < 2^{2n}) such that h_n(A)=Hh\_n(A)=H.

If there are several such AA, output any of them.

Examples1

  1. Example 1

    Input
    4 83
    
    Expected output
    13