#include using namespace std; typedef long long LL; int n; LL s; string str; bool out; int main() { cin >> n >> s >> str; for (int i = 0; i < n; i++) { if (str[i] == 'U') { // 第一种操作 if (s == 1) // 根,不动 continue; if (out) { // 超过1e12,向上一层 out = false; continue; } s /= 2; // 变成父节点 } else if (str[i] == 'L') { // 第二种操作 if (s * 2 > 1e12) { // 左子结点编号超过1e12,向下一层 out = true; continue; } s *= 2; // 变成左子结点 } else if (str[i] == 'R') { // 第三种操作 if (s * 2 + 1 > 1e12) { // 右子节点编号如果超过1E12,向下一层 out = true; continue; } s = s * 2 + 1; // 变成右子节点 } } cout << s << endl; return 0; }