시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 512 MB333100.000%

문제

A hanging rack is composed of n levels of connected rods. Level i (for i ∈ {0, 1, ..., n-1}) consists of 2i rods. The midpoint of the rod at level 0 is fixed to the wall. At all other levels, the midpoint of the j-th rod (for j ∈ {1, ..., 2i}) is fixed to the left endpoint of the ⌈j/2⌉-th rod at the previous level if j is odd and to the right endpoint of the same rod if j is even. At the last level, there is a hook for hanging a coat on both endpoints of each rod. The hooks are numbered from 1 to 2n in the left-to-right order.

For example, the rack for n = 3 looks as follows:

Mojca would like to hang all her coats on the rack. Every coat weighs exactly 1 unit. To avoid breaking the delicate structure, she has to hang them in such an order that the difference between the total weight wl placed on the left endpoint of any given rod and the total weight wr placed on the right endpoint of the same rod is either 0 or 1 (wl - wr ∈ {0, 1}). (By the laws of physics, the difference could also be -1, but a right-leaning rack looks really ugly to Mojca.) The rods are so thin that their weight can be neglected.

Having heard about your problem-solving proficience, Mojca asks you for help. Write a program that reads the integer n and an integer k and prints the sequential number (modulo (109 + 7)) of the hook on which Mojca has to hang her k-th coat.

입력

The input consists of a single line, which contains the integers n and k, separated by a space.

출력

Print the number (modulo (109 + 7)) of the hook to be used in the k-th step.

제한

  • n ∈ [1, 106]
  • k ∈ [1, min{2n, 1018}]

서브태스크

번호배점제한
120

n ∈ [1, 10]

220

n ∈ [1, 20]

360

no additional constraints.

예제 입력 1

3 2

예제 출력 1

5

In this case, the hooks should be used in the following order: 1, 5, 3, 7, 2, 6, 4, 8. In the second step, Mojca thus has to hang her coat on the hook with number 5.

예제 입력 2

5 10

예제 출력 2

19

Here, the order of hooks is 1, 17, 9, 25, 5, 21, 13, 29, 3, 19, etc.

채점 및 기타 정보

  • 예제는 채점하지 않는다.