Secret Cow Code

An infinite code string grows by doubling: each step appends the current string rotated right by one. Find the N-th character.

Medium6RecursionDivide and conquerMathNo attempts yetTime limit2sMemory limit512 MB

Problem

The cows are experimenting with secret codes, and have devised a method for creating an infinite-length string to be used as part of one of their codes.

Given a string ss, let F(s)F(s) be ss followed by ss "rotated" one character to the right. In a right rotation, the last character of ss moves around to become the new first character. Starting from an initial string ss, the cows build their infinite-length code string by repeatedly applying FF, so each step doubles the length of the current string.

Given the initial string and an index NN, compute the character at the NN-th position of the infinite code string.

Input

The input is a single line containing a string followed by NN, separated by a space. The string consists of at most 30 uppercase letters, and N1018N \le 10^{18}.

NN may not fit in a standard 32-bit integer, so you may want to use a 64-bit integer type (for example, long long in C/C++).

Output

Print the NN-th character of the infinite code built from the initial string. The first character is at N=1N=1.

Hint

In the sample, the initial string COW expands as follows:

COW -> COWWCO -> COWWCOOCOWWC
                 12345678