Language: C++

#include <iostream>
#include <string>
#include <math.h>
using namespace std;
//int D, G;
//int p[20], c[20];

int ABC(string str) {
	if (str.length < 3) {
		return 0;
	}
	int cnt = 0;
	for (int i = 0; i < str.length - 2; i++) {
		for (int j = i + 1; j < str.length - 1; j++) {
			for (int k = j + 1; k < str.length; k++) {
				if (str[i] == 'A' && str[j] == 'B' && str[k] == 'C') {
					cnt++;
				}
			}
		}
	}
	return cnt;
}

int main() {
	long long int mod = 1000000007;
	long long int result = 0;
	string s;
	cin >> s;
	int Q = 0;
	for (int i = 0; i < s.length; i++) {
		if (s[i] == '?') {
			Q++;
		}
	}
	if (Q > 1) {
		for (int i = 0; i < s.length - 1; i++) {
			for (int j = i+1; j < s.length; j++) {
				if (s[i] == '?' && s[j] == '?') {
					string c(s.length,'a');
					int ind = 0;
					int indi = 0, indj = 0;
					for (int k = 0; k < s.length; k++) {
						if (s[k] != '?' || k == i || k == j) {
							c[ind] = s[k];
							if (k == i)indi = ind;
							if (k == j)indj = ind;
							ind++;
						}
					}
					c[ind] = '\0';
					for (int p = 'A'; p <= 'C'; p++) {
						for (int q = 'A'; q <= 'C'; q++) {
							c[indi] = p;
							c[indj] = q;
							result += ABC(c);
							result %= mod;
						}
					}
				}
			}
		}
		for (int k = 0; k < Q - 2; k++) {
			result *= 3;
			result %= mod;
		}
	}
	if (Q == 1) {
		for (int i = 0; i < s.length; i++) {
			if (s[i] == '?') {
				s[i] = 'A';
				result += ABC(s);
				s[i] = 'B';
				result += ABC(s);
				s[i] = 'C';
				result += ABC(s);
			}
		}
	}
	else {
		result = ABC(s);
	}
	cout << result;
	return 0;
}

Compiler output:
a.cc: In function 'int ABC(std::string)':
a.cc:9:17: error: invalid use of member function 'std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::size_type std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::length() const [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>; size_type = long unsigned int]' (did you forget the '()' ?)
    9 |         if (str.length < 3) {
      |             ~~~~^~~~~~
      |                       ()
a.cc:13:33: error: invalid use of member function 'std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::size_type std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::length() const [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>; size_type = long unsigned int]' (did you forget the '()' ?)
   13 |         for (int i = 0; i < str.length - 2; i++) {
      |                             ~~~~^~~~~~
      |                                       ()
a.cc:14:45: error: invalid use of member function 'std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::size_type std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::length() const [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>; size_type = long unsigned int]' (did you forget the '()' ?)
   14 |                 for (int j = i + 1; j < str.length - 1; j++) {
      |                                         ~~~~^~~~~~
      |                                                   ()
a.cc:15:53: error: invalid use of member function 'std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::size_type std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::length() const [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>; size_type = long unsigned int]' (did you forget the '()' ?)
   15 |                         for (int k = j + 1; k < str.length; k++) {
      |                                                 ~~~~^~~~~~
      |                                                           ()
a.cc: In function 'int main()':
a.cc:31:31: error: invalid use of member function 'std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::size_type std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::length() const [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>; size_type = long unsigned int]' (did you forget the '()' ?)
   31 |         for (int i = 0; i < s.length; i++) {
      |                             ~~^~~~~~
      |                                     ()
a.cc:37:39: error: invalid use of member function 'std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::size_type std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::length() const [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>; size_type = long unsigned int]' (did you forget the '()' ?)
   37 |                 for (int i = 0; i < s.length - 1; i++) {
      |                                     ~~^~~~~~
      |                                             ()
a.cc:38:49: error: invalid use of member function 'std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::size_type std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::length() const [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>; size_type = long unsigned int]' (did you forget the '()' ?)
   38 |                         for (int j = i+1; j < s.length; j++) {
      |                                               ~~^~~~~~
      |                                                       ()
a.cc:40:52: error: invalid use of non-static member function 'std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::size_type std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::length() const [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>; size_type = long unsigned int]'
   40 |                                         string c(s.length,'a');
      |                                                  ~~^~~~~~
In file included from /usr/include/c++/14/string:54,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:1:
/usr/include/c++/14/bits/basic_string.h:1083:7: note: declared here
 1083 |       length() const _GLIBCXX_NOEXCEPT
      |       ^~~~~~
a.cc:43:63: error: invalid use of member function 'std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::size_type std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::length() const [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>; size_type = long unsigned int]' (did you forget the '()' ?)
   43 |                                         for (int k = 0; k < s.length; k++) {
      |                                                             ~~^~~~~~
      |                                                                     ()
a.cc:69:39: error: invalid use of member function 'std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::size_type std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::length() const [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>; size_type = long unsigned int]' (did you forget the '()' ?)
   69 |                 for (int i = 0; i < s.length; i++) {
      |                                     ~~^~~~~~
      |                                             ()