Language: C++

import java.util.Scanner;

class Main{


	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);			//文字の入力

		String S = sc.next();
		long mod = 1000000007;
		String ABC = "ABC";
		long[][] dp = new long[S.length()+1][4];
		dp[0][0] = 1;
		if(S.charAt(0) == 'A'){
			dp[0][1] = 1;
		}
		dp[0][0] = 1;
		dp[0][1] = 1;
		dp[0][1] = 1;

		for(int i = 1;i < S.length();i++){
			for(int j = 0;j < 4;j++){

				if(j == 0){
					if(S.charAt(i) == 'A' ||S.charAt(i) == 'B'||S.charAt(i) == 'C'){
						dp[i][j] = dp[i-1][0];
					}else{
						dp[i][j] = dp[i-1][0]*3;
					}

				}else{

					if(i+1 == j){
						dp[i][j] =1;

					}else if(i + 1 > j){
						long x = (S.charAt(i) == '?' ? 3 : 1);				//?だったら３、他は１
						long y =(((S.charAt(i) == ABC.charAt(j-1))||( S.charAt(i)) == '?') ? 1 :0);


						if(j == 1 || j == 2){
							dp[i][j] = dp[i-1][j]*x + dp[i-1][j-1]*y;


						}else if(j == 3){				//この時はABCの数だけカウント増やす

							dp[i][j] = (dp[i-1][j] * x) + (dp[i-1][j-1]*y); 
						}

						dp[i][j] %=mod;

					}


				}
			}


		}
//		for(int f= 0;f < S.length();f++){
//			for(int g = 0;g < 4;g++){
//				System.out.print(dp[f][g]);
//			}
//			System.out.println();
//		}
//		System.out.println();


		System.out.println(dp[S.length()-1][3]);
	}

}

Compiler output:
a.cc:1:1: error: 'import' does not name a type
    1 | import java.util.Scanner;
      | ^~~~~~
a.cc:1:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:6:15: error: expected ':' before 'static'
    6 |         public static void main(String[] args) {
      |               ^~~~~~~
      |               :
a.cc:6:33: error: 'String' has not been declared
    6 |         public static void main(String[] args) {
      |                                 ^~~~~~
a.cc:6:42: error: expected ',' or '...' before 'args'
    6 |         public static void main(String[] args) {
      |                                          ^~~~
a.cc:73:2: error: expected ';' after class definition
   73 | }
      |  ^
      |  ;
a.cc: In static member function 'static void Main::main(int*)':
a.cc:8:17: error: 'Scanner' was not declared in this scope
    8 |                 Scanner sc = new Scanner(System.in);                    //文字の入力
      |                 ^~~~~~~
a.cc:10:17: error: 'String' was not declared in this scope
   10 |                 String S = sc.next();
      |                 ^~~~~~
a.cc:12:24: error: expected ';' before 'ABC'
   12 |                 String ABC = "ABC";
      |                        ^~~
a.cc:13:21: error: structured binding declaration cannot have type 'long int'
   13 |                 long[][] dp = new long[S.length()+1][4];
      |                     ^~
a.cc:13:21: note: type must be cv-qualified 'auto' or reference to cv-qualified 'auto'
a.cc:13:21: error: empty structured binding declaration
a.cc:13:23: error: expected initializer before '[' token
   13 |                 long[][] dp = new long[S.length()+1][4];
      |                       ^
a.cc:14:17: error: 'dp' was not declared in this scope
   14 |                 dp[0][0] = 1;
      |                 ^~
a.cc:15:20: error: 'S' was not declared in this scope
   15 |                 if(S.charAt(0) == 'A'){
      |                    ^
a.cc:22:35: error: 'S' was not declared in this scope
   22 |                 for(int i = 1;i < S.length();i++){
      |                                   ^
a.cc:39:75: error: 'ABC' was not declared in this scope
   39 |                                                 long y =(((S.charAt(i) == ABC.charAt(j-1))||( S.charAt(i)) == '?') ? 1 :0);
      |                                                                           ^~~
a.cc:70:17: error: 'System' was not declared in this scope
   70 |                 System.out.println(dp[S.length()-1][3]);
      |                 ^~~~~~
a.cc:70:39: error: 'S' was not declared in this scope
   70 |                 System.out.println(dp[S.length()-1][3]);
      |                                       ^