Language: C++

//Optimise
#include <bits/stdc++.h>
using namespace std;

// #define multitest 1
#define Debug 1
#ifdef Debug
#define db(...) ZZ(#__VA_ARGS__, __VA_ARGS__);
template <typename Arg1>
void ZZ(const char *name, Arg1 &&arg1)
{
	std::cerr << name << " = " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void ZZ(const char *names, Arg1 &&arg1, Args &&... args)
{
	const char *comma = strchr(names + 1, ',');
	std::cerr.write(names, comma - names) << " = " << arg1;
	ZZ(comma, args...);
}
#else
#define db(...)
#endif

typedef long long ll;
typedef long double ld;
#define f first
#define s second
#define pb push_back
const long long mod = 1000000007;

ll power(int base, int index)
{
	if (index == 0)
		return 1;
	ll temp = power(base, index / 2);
	temp = (temp * temp) % mod;
	if (index & 1)
		temp *= base;
	return temp % mod;
}

ll solve(string l, int index, int length)
{
	if (length == 1)
	{
		if (l[index] == '0')
			return 1;
		else
			return 3;
	}
	ll answer = 0;
	if (l[index] == '1')
		answer += power(3, length - 1);
	answer %= mod;
	if (l[index] == '1')
		answer = (answer + 2 * solve(l, index + 1, length - 1)) % mod;
	else
		answer = (answer + solve(l, index + 1, length - 1)) % mod;
	// db(length, answer);
	return answer;
}

void solve()
{
	string l;
	cin >> l;
	// int n = 0;
	// for (char c : l)
	// 	n = n * 2 + (c - '0');
	// int cnt = 0;
	// for (int i = 0; i <= n; ++i)
	// 	for (int j = 0; j <= n; ++j)
	// 	{
	// 		if (i + j <= n)
	// 		{
	// 			if ((i + j) == (i ^ j))
	// 			{
	// 				cnt++;
	// 				cout << i << ' ' << j << '\n';
	// 			}
	// 		}
	// 	}
	// cout << cnt << '\n';
	cout << solve(l, 0, l.length()) << '\n';
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int t = 1;
#ifdef multitest
	cin >> t;
#endif
	while (t--)
		solve();
	return 0;
}//Optimise
#include <bits/stdc++.h>
using namespace std;

// #define multitest 1
#define Debug 1
#ifdef Debug
#define db(...) ZZ(#__VA_ARGS__, __VA_ARGS__);
template <typename Arg1>
void ZZ(const char *name, Arg1 &&arg1)
{
	std::cerr << name << " = " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void ZZ(const char *names, Arg1 &&arg1, Args &&... args)
{
	const char *comma = strchr(names + 1, ',');
	std::cerr.write(names, comma - names) << " = " << arg1;
	ZZ(comma, args...);
}
#else
#define db(...)
#endif

typedef long long ll;
typedef long double ld;
#define f first
#define s second
#define pb push_back
const long long mod = 1000000007;

ll power(int base, int index)
{
	if (index == 0)
		return 1;
	ll temp = power(base, index / 2);
	temp = (temp * temp) % mod;
	if (index & 1)
		temp *= base;
	return temp % mod;
}

ll solve(string l, int index, int length)
{
	if (length == 1)
	{
		if (l[index] == '0')
			return 1;
		else
			return 3;
	}
	ll answer = 0;
	if (l[index] == '1')
		answer += power(3, length - 1);
	answer %= mod;
	if (l[index] == '1')
		answer = (answer + 2 * solve(l, index + 1, length - 1)) % mod;
	else
		answer = (answer + solve(l, index + 1, length - 1)) % mod;
	// db(length, answer);
	return answer;
}

void solve()
{
	string l;
	cin >> l;
	// int n = 0;
	// for (char c : l)
	// 	n = n * 2 + (c - '0');
	// int cnt = 0;
	// for (int i = 0; i <= n; ++i)
	// 	for (int j = 0; j <= n; ++j)
	// 	{
	// 		if (i + j <= n)
	// 		{
	// 			if ((i + j) == (i ^ j))
	// 			{
	// 				cnt++;
	// 				cout << i << ' ' << j << '\n';
	// 			}
	// 		}
	// 	}
	// cout << cnt << '\n';
	cout << solve(l, 0, l.length()) << '\n';
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int t = 1;
#ifdef multitest
	cin >> t;
#endif
	while (t--)
		solve();
	return 0;
}

Compiler output:
a.cc:108:6: error: redefinition of 'template<class Arg1> void ZZ(const char*, Arg1&&)'
  108 | void ZZ(const char *name, Arg1 &&arg1)
      |      ^~
a.cc:10:6: note: 'template<class Arg1> void ZZ(const char*, Arg1&&)' previously declared here
   10 | void ZZ(const char *name, Arg1 &&arg1)
      |      ^~
a.cc:113:6: error: redefinition of 'template<class Arg1, class ... Args> void ZZ(const char*, Arg1&&, Args&& ...)'
  113 | void ZZ(const char *names, Arg1 &&arg1, Args &&... args)
      |      ^~
a.cc:15:6: note: 'template<class Arg1, class ... Args> void ZZ(const char*, Arg1&&, Args&& ...)' previously declared here
   15 | void ZZ(const char *names, Arg1 &&arg1, Args &&... args)
      |      ^~
a.cc:128:17: error: redefinition of 'const long long int mod'
  128 | const long long mod = 1000000007;
      |                 ^~~
a.cc:30:17: note: 'const long long int mod' previously defined here
   30 | const long long mod = 1000000007;
      |                 ^~~
a.cc:130:4: error: redefinition of 'll power(int, int)'
  130 | ll power(int base, int index)
      |    ^~~~~
a.cc:32:4: note: 'll power(int, int)' previously defined here
   32 | ll power(int base, int index)
      |    ^~~~~
a.cc:141:4: error: redefinition of 'll solve(std::string, int, int)'
  141 | ll solve(string l, int index, int length)
      |    ^~~~~
a.cc:43:4: note: 'll solve(std::string, int, int)' previously defined here
   43 | ll solve(string l, int index, int length)
      |    ^~~~~
a.cc:162:6: error: redefinition of 'void solve()'
  162 | void solve()
      |      ^~~~~
a.cc:64:6: note: 'void solve()' previously defined here
   64 | void solve()
      |      ^~~~~
a.cc:186:5: error: redefinition of 'int main()'
  186 | int main()
      |     ^~~~
a.cc:88:5: note: 'int main()' previously defined here
   88 | int main()
      |     ^~~~