Language: C++

#ifdef _WIN32
#include "stdc++.h"
#else
#include <bits/stdc++.h>
#endif

// 継承可能な型
template <class Type>
struct IN : Type
{
	IN()
	{
		std::cin >> *this;
	}
};

// 継承不可能な型
template <class Type>
struct IN_
{
	Type val;

	IN_()
	{
		std::cin >> val;
	}

	operator Type&()
	{
		return val;
	}

	IN_<Type>& operator=(const Type& _value)
	{
		val = _value;
		return *this;
	}
};

template <class Char, class Type>
std::basic_ostream<Char>& operator <<(std::basic_ostream<Char>& os, const IN_<Type>& value)
{
	return os << value.val;
}

template <class Char, class Type>
std::basic_istream<Char>& operator >>(std::basic_istream<Char>& is, IN_<Type>& value)
{
	return is >> value.val;
}

template <class Type>
void OUT(const Type& value)
{
	std::cout << value << std::endl;
}

template <class Type, class ... Args>
void OUT(const Type& value, const Args& ... args)
{
	std::cout << value << ' ';
	OUT(args...);
}

void YES()
{
	OUT("YES");
}
void NO()
{
	OUT("NO");
}
void YESNO(const bool cond)
{
	OUT(cond ? "YES" : "NO");
}

void Yes()
{
	OUT("Yes");
}
void No()
{
	OUT("No");
}
void YesNo(const bool cond)
{
	OUT(cond ? "Yes" : "No");
}

using ll = long long;
using inll = IN_<ll>;
using vll = std::vector<ll>;
using vvll = std::vector<vll>;
using setll = std::set<ll>;
using msetll = std::multiset<ll>;
using P = std::pair<ll, ll>;
using instr = IN<std::string>;

// 階乗を計算 O(N) (N=10^7 で O(10^7))
ll factorial(ll n)
{
	for (ll i = n - 1; i > 1; --i)
		n *= i;
	return n;
}

// nCrを計算 O(N) (N=10^7 で O(10^7))
ll ncr(const ll n, ll r)
{
	if (r * 2 > n) r = n - r;

	ll dividend = 1, divisor = 1;

	for (ll i = 1; i <= r; ++i) {
		dividend *= n - i + 1;
		divisor *= i;
	}

	return dividend / divisor;
}

// 素数判定 O(sqrt(N)) (N=10^7 で O(10^3))
bool isprime(const ll num)
{
    if (num < 2) return false;
    if (num == 2) return true;
    if (num % 2 == 0) return false;

    double sqrtNum = sqrt(num);
    for (ll i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0) return false;
    }

    return true;
}

// 各桁の和を計算 O(logN) (N=10^7 で O(7))
ll digsum(ll n)
{
	ll sum = 0;
	while(n != 0){
		sum += n % 10;
		n /= 10;
	}
	return sum;
}

// ２つの数の最大公約数を求める
ll gcd(ll m, ll n)
{
	// 引数に０がある場合は０を返す
	if (m == 0 || n == 0)
		return 0;

	// ユークリッドの方法
	while(m != n)
	{
		if (m > n) m = m - n;
		else n = n - m;
	}
	return m;
}

// ２つの数の最小公倍数を求める
ll lcm(const ll m, const ll n)
{
	// 引数に０がある場合は０を返す
	if (m == 0 || n == 0)
		return 0;

	// lcm = m * n / gcd(m,n)
	return m / gcd(m, n) * n;
}

// ３以上の数の最大公約数を求める
template <class Container>
ll gcd(const Container& v)
{
	ll res = *std::begin(v);
	for (const auto& i : v)
	{
		res = gcd(res, i);
	}
	return res;
}

// ３以上の数の最小公倍数を求める
template <class Container>
ll lcm(const Container& v)
{
	ll res = *std::begin(v);
	for (const auto& i : v)
	{
		res = lcm(res, i);
	}
	return res;
}

// 結果を切り上げる除算
ll divup(const ll a, const ll b)
{
	return (a + b - 1) / b;
}

ll inrange(const ll x, const ll y, const ll w, const ll h)
{
	return 0 <= x && x < w && 0 <= y && y < h;
}

// 指数が整数のpow
// https://kazu-yamamoto.hatenablog.jp/entry/20090223/1235372875
template <typename Type>
Type pow_i(const Type x, const ll n)
{
	if (n == 0)
		return 1;
	else if (n % 2 == 0)
		return pow_i(x * x, n / 2);
	else
		return x * pow_i(x, n - 1);
}

// 指数が整数のpow (mを法として)
// http://augusuto04.hatenablog.com/entry/2015/05/02/183451
ll pow_im(const ll x, const ll n, const ll m)
{
	if (n == 0)
		return 1;
	else if (n % 2 == 0)
		return pow_im(x * x % m, n / 2, m);
	else
		return x * pow_im(x, n - 1, m) % m;
}

const ll MOD = (ll)1e9 + 7;
const ll INF = (ll)1e18;
const ll dy[] = { 0, 0, 1, -1 };
const ll dx[] = { 1, -1, 0, 0 };

#define FOR(i, m, n) for (ll (i) = (m); (i) < (n); ++(i))
#define REP(i, n) for (ll (i) = 0; (i) < (n); ++(i))
#define REPR(i, n) for (ll (i) = (n); (i) >= 0; --(i))
#define ITRREP(it, v) for (auto (it) = (v).begin(); (it) != (v).end(); ++(it))
#define ITRREPR(it, v) for (auto (it) = (v).rbegin(); (it) != (v).rend(); ++(it))

void Main();

int main()
{
	std::cin.tie(nullptr);
	std::ios::sync_with_stdio(false);

	Main();

#ifdef _DEBUG
	std::cin.clear();
	std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
	std::cout << std::endl << "Press Enter key to continue...";
	std::cin.get();
#endif

	return 0;
}

using namespace std;

//////////////////////////////

vll h, p;

ll rec(ll n, ll x)
{
	if (n == 0) return max(x, 0ll);
	if (x < h[n-1] + 2) return rec(n-1, x-1);
	if (x == h[n-1] + 2) return p[n-1] + 1;
	if (x > h[n-1] + 2) return p[n-1] + 1 + rec(n-1, x - h[n-1] - 2);
}

void Main()
{
	inll n, x;
	h.resize(51);
	p.resize(51);
	h[0] = 1;
	p[0] = 1;
	FOR(i, 1, n)
	{
		h[i] = h[i-1] * 2 + 3;
		p[i] = p[i-1] * 2 + 1;
	}
	OUT(rec(n, x));
}
#ifdef _WIN32
#include "stdc++.h"
#else
#include <bits/stdc++.h>
#endif

// 継承可能な型
template <class Type>
struct IN : Type
{
	IN()
	{
		std::cin >> *this;
	}
};

// 継承不可能な型
template <class Type>
struct IN_
{
	Type val;

	IN_()
	{
		std::cin >> val;
	}

	operator Type&()
	{
		return val;
	}

	IN_<Type>& operator=(const Type& _value)
	{
		val = _value;
		return *this;
	}
};

template <class Char, class Type>
std::basic_ostream<Char>& operator <<(std::basic_ostream<Char>& os, const IN_<Type>& value)
{
	return os << value.val;
}

template <class Char, class Type>
std::basic_istream<Char>& operator >>(std::basic_istream<Char>& is, IN_<Type>& value)
{
	return is >> value.val;
}

template <class Type>
void OUT(const Type& value)
{
	std::cout << value << std::endl;
}

template <class Type, class ... Args>
void OUT(const Type& value, const Args& ... args)
{
	std::cout << value << ' ';
	OUT(args...);
}

void YES()
{
	OUT("YES");
}
void NO()
{
	OUT("NO");
}
void YESNO(const bool cond)
{
	OUT(cond ? "YES" : "NO");
}

void Yes()
{
	OUT("Yes");
}
void No()
{
	OUT("No");
}
void YesNo(const bool cond)
{
	OUT(cond ? "Yes" : "No");
}

using ll = long long;
using inll = IN_<ll>;
using vll = std::vector<ll>;
using vvll = std::vector<vll>;
using setll = std::set<ll>;
using msetll = std::multiset<ll>;
using P = std::pair<ll, ll>;
using instr = IN<std::string>;

// 階乗を計算 O(N) (N=10^7 で O(10^7))
ll factorial(ll n)
{
	for (ll i = n - 1; i > 1; --i)
		n *= i;
	return n;
}

// nCrを計算 O(N) (N=10^7 で O(10^7))
ll ncr(const ll n, ll r)
{
	if (r * 2 > n) r = n - r;

	ll dividend = 1, divisor = 1;

	for (ll i = 1; i <= r; ++i) {
		dividend *= n - i + 1;
		divisor *= i;
	}

	return dividend / divisor;
}

// 素数判定 O(sqrt(N)) (N=10^7 で O(10^3))
bool isprime(const ll num)
{
    if (num < 2) return false;
    if (num == 2) return true;
    if (num % 2 == 0) return false;

    double sqrtNum = sqrt(num);
    for (ll i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0) return false;
    }

    return true;
}

// 各桁の和を計算 O(logN) (N=10^7 で O(7))
ll digsum(ll n)
{
	ll sum = 0;
	while(n != 0){
		sum += n % 10;
		n /= 10;
	}
	return sum;
}

// ２つの数の最大公約数を求める
ll gcd(ll m, ll n)
{
	// 引数に０がある場合は０を返す
	if (m == 0 || n == 0)
		return 0;

	// ユークリッドの方法
	while(m != n)
	{
		if (m > n) m = m - n;
		else n = n - m;
	}
	return m;
}

// ２つの数の最小公倍数を求める
ll lcm(const ll m, const ll n)
{
	// 引数に０がある場合は０を返す
	if (m == 0 || n == 0)
		return 0;

	// lcm = m * n / gcd(m,n)
	return m / gcd(m, n) * n;
}

// ３以上の数の最大公約数を求める
template <class Container>
ll gcd(const Container& v)
{
	ll res = *std::begin(v);
	for (const auto& i : v)
	{
		res = gcd(res, i);
	}
	return res;
}

// ３以上の数の最小公倍数を求める
template <class Container>
ll lcm(const Container& v)
{
	ll res = *std::begin(v);
	for (const auto& i : v)
	{
		res = lcm(res, i);
	}
	return res;
}

// 結果を切り上げる除算
ll divup(const ll a, const ll b)
{
	return (a + b - 1) / b;
}

ll inrange(const ll x, const ll y, const ll w, const ll h)
{
	return 0 <= x && x < w && 0 <= y && y < h;
}

// 指数が整数のpow
// https://kazu-yamamoto.hatenablog.jp/entry/20090223/1235372875
template <typename Type>
Type pow_i(const Type x, const ll n)
{
	if (n == 0)
		return 1;
	else if (n % 2 == 0)
		return pow_i(x * x, n / 2);
	else
		return x * pow_i(x, n - 1);
}

// 指数が整数のpow (mを法として)
// http://augusuto04.hatenablog.com/entry/2015/05/02/183451
ll pow_im(const ll x, const ll n, const ll m)
{
	if (n == 0)
		return 1;
	else if (n % 2 == 0)
		return pow_im(x * x % m, n / 2, m);
	else
		return x * pow_im(x, n - 1, m) % m;
}

const ll MOD = (ll)1e9 + 7;
const ll INF = (ll)1e18;
const ll dy[] = { 0, 0, 1, -1 };
const ll dx[] = { 1, -1, 0, 0 };

#define FOR(i, m, n) for (ll (i) = (m); (i) < (n); ++(i))
#define REP(i, n) for (ll (i) = 0; (i) < (n); ++(i))
#define REPR(i, n) for (ll (i) = (n); (i) >= 0; --(i))
#define ITRREP(it, v) for (auto (it) = (v).begin(); (it) != (v).end(); ++(it))
#define ITRREPR(it, v) for (auto (it) = (v).rbegin(); (it) != (v).rend(); ++(it))

void Main();

int main()
{
	std::cin.tie(nullptr);
	std::ios::sync_with_stdio(false);

	Main();

#ifdef _DEBUG
	std::cin.clear();
	std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
	std::cout << std::endl << "Press Enter key to continue...";
	std::cin.get();
#endif

	return 0;
}

using namespace std;

//////////////////////////////

vll h, p;

ll rec(ll n, ll x)
{
	if (n == 0) return max(x, 0ll);
	if (x < h[n-1] + 2) return rec(n-1, x-1);
	if (x == h[n-1] + 2) return p[n-1] + 1;
	if (x > h[n-1] + 2) return p[n-1] + 1 + rec(n-1, x - h[n-1] - 2);
}

void Main()
{
	inll n, x;
	h.resize(51);
	p.resize(51);
	h[0] = 1;
	p[0] = 1;
	FOR(i, 1, n)
	{
		h[i] = h[i-1] * 2 + 3;
		p[i] = p[i-1] * 2 + 1;
	}
	OUT(rec(n, x));
}


Compiler output:
a.cc:303:8: error: redefinition of 'struct IN<Type>'
  303 | struct IN : Type
      |        ^~
a.cc:9:8: note: previous definition of 'struct IN<Type>'
    9 | struct IN : Type
      |        ^~
a.cc:313:8: error: redefinition of 'struct IN_<Type>'
  313 | struct IN_
      |        ^~~
a.cc:19:8: note: previous definition of 'struct IN_<Type>'
   19 | struct IN_
      |        ^~~
a.cc:335:27: error: redefinition of 'template<class Char, class Type> std::basic_ostream<Char>& operator<<(std::basic_ostream<Char>&, const IN_<Type>&)'
  335 | std::basic_ostream<Char>& operator <<(std::basic_ostream<Char>& os, const IN_<Type>& value)
      |                           ^~~~~~~~
a.cc:41:27: note: 'template<class Char, class Type> std::basic_ostream<Char>& operator<<(std::basic_ostream<Char>&, const IN_<Type>&)' previously declared here
   41 | std::basic_ostream<Char>& operator <<(std::basic_ostream<Char>& os, const IN_<Type>& value)
      |                           ^~~~~~~~
a.cc:341:27: error: redefinition of 'template<class Char, class Type> std::basic_istream<Char>& operator>>(std::basic_istream<Char>&, IN_<Type>&)'
  341 | std::basic_istream<Char>& operator >>(std::basic_istream<Char>& is, IN_<Type>& value)
      |                           ^~~~~~~~
a.cc:47:27: note: 'template<class Char, class Type> std::basic_istream<Char>& operator>>(std::basic_istream<Char>&, IN_<Type>&)' previously declared here
   47 | std::basic_istream<Char>& operator >>(std::basic_istream<Char>& is, IN_<Type>& value)
      |                           ^~~~~~~~
a.cc:347:6: error: redefinition of 'template<class Type> void OUT(const Type&)'
  347 | void OUT(const Type& value)
      |      ^~~
a.cc:53:6: note: 'template<class Type> void OUT(const Type&)' previously declared here
   53 | void OUT(const Type& value)
      |      ^~~
a.cc:353:6: error: redefinition of 'template<class Type, class ... Args> void OUT(const Type&, const Args& ...)'
  353 | void OUT(const Type& value, const Args& ... args)
      |      ^~~
a.cc:59:6: note: 'template<class Type, class ... Args> void OUT(const Type&, const Args& ...)' previously declared here
   59 | void OUT(const Type& value, const Args& ... args)
      |      ^~~
a.cc:359:6: error: redefinition of 'void YES()'
  359 | void YES()
      |      ^~~
a.cc:65:6: note: 'void YES()' previously defined here
   65 | void YES()
      |      ^~~
a.cc:363:6: error: redefinition of 'void NO()'
  363 | void NO()
      |      ^~
a.cc:69:6: note: 'void NO()' previously defined here
   69 | void NO()
      |      ^~
a.cc:367:6: error: redefinition of 'void YESNO(bool)'
  367 | void YESNO(const bool cond)
      |      ^~~~~
a.cc:73:6: note: 'void YESNO(bool)' previously defined here
   73 | void YESNO(const bool cond)
      |      ^~~~~
a.cc:372:6: error: redefinition of 'void Yes()'
  372 | void Yes()
      |      ^~~
a.cc:78:6: note: 'void Yes()' previously defined here
   78 | void Yes()
      |      ^~~
a.cc:376:6: error: redefinition of 'void No()'
  376 | void No()
      |      ^~
a.cc:82:6: note: 'void No()' previously defined here
   82 | void No()
      |      ^~
a.cc:380:6: error: redefinition of 'void YesNo(bool)'
  380 | void YesNo(const bool cond)
      |      ^~~~~
a.cc:86:6: note: 'void YesNo(bool)' previously defined here
   86 | void YesNo(const bool cond)
      |      ^~~~~
a.cc:395:4: error: redefinition of 'll factorial(ll)'
  395 | ll factorial(ll n)
      |    ^~~~~~~~~
a.cc:101:4: note: 'll factorial(ll)' previously defined here
  101 | ll factorial(ll n)
      |    ^~~~~~~~~
a.cc:403:4: error: redefinition of 'll ncr(ll, ll)'
  403 | ll ncr(const ll n, ll r)
      |    ^~~
a.cc:109:4: note: 'll ncr(ll, ll)' previously defined here
  109 | ll ncr(const ll n, ll r)
      |    ^~~
a.cc:418:6: error: redefinition of 'bool isprime(ll)'
  418 | bool isprime(const ll num)
      |      ^~~~~~~
a.cc:124:6: note: 'bool isprime(ll)' previously defined here
  124 | bool isprime(const ll num)
      |      ^~~~~~~
a.cc:434:4: error: redefinition of 'll digsum(ll)'
  434 | ll digsum(ll n)
      |    ^~~~~~
a.cc:140:4: note: 'll digsum(ll)' previously defined here
  140 | ll digsum(ll n)
      |    ^~~~~~
a.cc:445:4: error: redefinition of 'll gcd(ll, ll)'
  445 | ll gcd(ll m, ll n)
      |    ^~~
a.cc:151:4: note: 'll gcd(ll, ll)' previously defined here
  151 | ll gcd(ll m, ll n)
      |    ^~~
a.cc:461:4: error: redefinition of 'll lcm(ll, ll)'
  461 | ll lcm(const ll m, const ll n)
      |    ^~~
a.cc:167:4: note: 'll lcm(ll, ll)' previously defined here
  167 | ll lcm(const ll m, const ll n)
      |    ^~~
a.cc:473:4: error: redefinition of 'template<class Container> ll gcd(const Container&)'
  473 | ll gcd(const Container& v)
      |    ^~~
a.cc:179:4: note: 'template<class Container> ll gcd(const Container&)' previously declared here
  179 | ll gcd(const Container& v)
      |    ^~~
a.cc:485:4: error: redefinition of 'template<class Container> ll lcm(const Container&)'
  485 | ll lcm(const Container& v)
      |    ^~~
a.cc:191:4: note: 'template<class Container> ll lcm(const Container&)' previously declared here
  191 | ll lcm(const Container& v)
      |    ^~~
a.cc:496:4: error: redefinition of 'll divup(ll, ll)'
  496 | ll divup(const ll a, const ll b)
      |    ^~~~~
a.cc:202:4: note: 'll divup(ll, ll)' previously defined here
  202 | ll divup(const ll a, const ll b)
      |    ^~~~~
a.cc:501:4: error: redefinition of 'll inrange(ll, ll, ll, ll)'
  501 | ll inrange(const ll x, const ll y, const ll w, const ll h)
      |    ^~~~~~~
a.cc:207:4: note: 'll inrange(ll, ll, ll, ll)' previously defined here
  207 | ll inrange(const ll x, const ll y, const ll w, const ll h)
      |    ^~~~~~~
a.cc:509:6: error: redefinition of 'template<class Type> Type pow_i(Type, ll)'
  509 | Type pow_i(const Type x, const ll n)
      |      ^~~~~
a.cc:215:6: note: 'template<class Type> Type pow_i(Type, ll)' previously declared here
  215 | Type pow_i(const Type x, const ll n)
      |      ^~~~~
a.cc:521:4: error: redefinition of 'll pow_im(ll, ll, ll)'
  521 | ll pow_im(const ll x, const ll n, const ll m)
      |    ^~~~~~
a.cc:227:4: note: 'll pow_im(ll, ll, ll)' previously defined here
  227 | ll pow_im(const ll x, const ll n, const ll m)
      |    ^~~~~~
a.cc:531:10: error: redefinition of 'const ll MOD'
  531 | const ll MOD = (ll)1e9 + 7;
      |          ^~~
a.cc:237:10: note: 'const ll MOD' previously defined here
  237 | const ll MOD = (ll)1e9 + 7;
      |          ^~~
a.cc:532:10: error: redefinition of 'const ll INF'
  532 | const ll INF = (ll)1e18;
      |          ^~~
a.cc:238:10: note: 'const ll INF' previously defined here
  238 | const ll INF = (ll)1e18;
      |          ^~~
a.cc:533:10: error: redefinition of 'const ll dy []'
  533 | const ll dy[] = { 0, 0, 1, -1 };
      |          ^~
a.cc:239:10: note: 'const ll dy [4]' previously defined here
  239 | const ll dy[] = { 0, 0, 1, -1 };
      |          ^~
a.cc:534:10: error: redefinition of 'const ll dx []'
  534 | const ll dx[] = { 1, -1, 0, 0 };
      |          ^~
a.cc:240:10: note: 'const ll dx [4]' previously defined here
  240 | const ll dx[] = { 1, -1, 0, 0 };
      |          ^~
a.cc:544:5: error: redefinition of 'int main()'
  544 | int main()
      |     ^~~~
a.cc:250:5: note: 'int main()' previously defined here
  250 | int main()
      |     ^~~~
a.cc:565:5: error: redefinition of 'vll h'
  565 | vll h, p;
      |     ^
a.cc:271:5: note: 'vll h' previously declared here
  271 | vll h, p;
      |     ^
a.cc:565:8: error: redefinition of 'vll p'
  565 | vll h, p;
      |        ^
a.cc:271:8: note: 'vll p' previously declared here
  271 | vll h, p;
      |        ^
a.cc:567:4: error: redefinition of 'll rec(ll, ll)'
  567 | ll rec(ll n, ll x)
      |    ^~~
a.cc:273:4: note: 'll rec(ll, ll)' previously defined here
  273 | ll rec(ll n, ll x)
      |    ^~~
a.cc:575:6: error: redefinition of 'void Main()'
  575 | void Main()
      |      ^~~~
a.cc:281:6: note: 'void Main()' previously defined here
  281 | void Main()
      |      ^~~~
a.cc: In function 'll rec(ll, ll)':
a.cc:279:1: warning: control reaches end of non-void function [-Wreturn-type]
  279 | }
      | ^
a.cc: In function 'll rec(ll, ll)':
a.cc:573:1: warning: control reaches end of non-void function [-Wreturn-type]
  573 | }
      | ^