time limit per test: 0.25
memory limit per test: 4096
Let phi(W) is the result of encoding for algorithm:
1. If the length of W is 1 then phi(W) is W;
2. Let coded word is W = w1w2...wN and K = N / 2 (rounded down);
3. phi(W) = phi(wNwN-1...wK+1) + phi(wKwK-1...w1).
For example, phi('Ok') = 'kO', phi('abcd') = 'cdab'.
Your task is to find position of letter wq in encoded word phi(W).
Given integers N, q (1 <= N <= 10^9; 1<= q <= N), where N is the length of word W.
Write position of letter wq in encoded word phi(W).
|Author:||Michael R. Mirzayanov
|Resource:||Saratov ST team Spring Contest #1
|Server time: 2018-02-19 01:02:53||Online Contester Team © 2002 - 2016. All rights reserved.|