Language: C++

#include<iostream>
#include<cmath>
#include<string>
using namespace std;

int main(){
  string s;
  cin>>s;
  int l=s.length();
  int a=0,b=0,c=0,q=0;
  for(int i=0;i<l;i++){
    if(s[i]=='A'){
      a++;
    }
    if(s[i]=='B'){
      b++;
    }
    if(s[i]=='C'){
      c++;
    }
    if(s[i]=='?'){
      q++;
    }
  }
  int a[l],b[l],c[l],q[l];
  a[0]=0;
  b[0]=0;
  c[0]=0;
  q[0]=0;
  int ans=0;
  for(int i=0;i<l-1;i++){
    if(s[i]=='A'){
      q[i+1]=q[i];
      a[i+1]=a[i]+1;
      b[i+1]=b[i];
      c[i+1]=c[i];
    }else if(s[i]=='C'){
      q[i+1]=q[i];
      a[i+1]=a[i];
      b[i+1]=b[i];
      c[i+1]=c[i]+1;
    }else if(s[i]=='?'){
      q[i+1]=q[i]+1;
      a[i+1]=a[i];
      b[i+1]=b[i];
      c[i+1]=c[i];
      ans+=(a[i]+q[i])*(c-c[i]+q-q[i]-1);
    }else{
      q[i+1]=q[i];
      a[i+1]=a[i];
      b[i+1]=b[i]+1;
      c[i+1]=c[i];
      ans+=(a[i]+q[i])*(c+q-c[i]-q[i]);
    }
    if(ans>=pow(10,9)+7){
      ans=ans%(pow(10,9)+7);
    }
  }
  cout<<ans<<endl;
}
      
      
    
    

Compiler output:
a.cc: In function 'int main()':
a.cc:25:7: error: conflicting declaration 'int a [l]'
   25 |   int a[l],b[l],c[l],q[l];
      |       ^
a.cc:10:7: note: previous declaration as 'int a'
   10 |   int a=0,b=0,c=0,q=0;
      |       ^
a.cc:25:12: error: conflicting declaration 'int b [l]'
   25 |   int a[l],b[l],c[l],q[l];
      |            ^
a.cc:10:11: note: previous declaration as 'int b'
   10 |   int a=0,b=0,c=0,q=0;
      |           ^
a.cc:25:17: error: conflicting declaration 'int c [l]'
   25 |   int a[l],b[l],c[l],q[l];
      |                 ^
a.cc:10:15: note: previous declaration as 'int c'
   10 |   int a=0,b=0,c=0,q=0;
      |               ^
a.cc:25:22: error: conflicting declaration 'int q [l]'
   25 |   int a[l],b[l],c[l],q[l];
      |                      ^
a.cc:10:19: note: previous declaration as 'int q'
   10 |   int a=0,b=0,c=0,q=0;
      |                   ^
a.cc:26:4: error: invalid types 'int[int]' for array subscript
   26 |   a[0]=0;
      |    ^
a.cc:27:4: error: invalid types 'int[int]' for array subscript
   27 |   b[0]=0;
      |    ^
a.cc:28:4: error: invalid types 'int[int]' for array subscript
   28 |   c[0]=0;
      |    ^
a.cc:29:4: error: invalid types 'int[int]' for array subscript
   29 |   q[0]=0;
      |    ^
a.cc:33:8: error: invalid types 'int[int]' for array subscript
   33 |       q[i+1]=q[i];
      |        ^
a.cc:33:15: error: invalid types 'int[int]' for array subscript
   33 |       q[i+1]=q[i];
      |               ^
a.cc:34:8: error: invalid types 'int[int]' for array subscript
   34 |       a[i+1]=a[i]+1;
      |        ^
a.cc:34:15: error: invalid types 'int[int]' for array subscript
   34 |       a[i+1]=a[i]+1;
      |               ^
a.cc:35:8: error: invalid types 'int[int]' for array subscript
   35 |       b[i+1]=b[i];
      |        ^
a.cc:35:15: error: invalid types 'int[int]' for array subscript
   35 |       b[i+1]=b[i];
      |               ^
a.cc:36:8: error: invalid types 'int[int]' for array subscript
   36 |       c[i+1]=c[i];
      |        ^
a.cc:36:15: error: invalid types 'int[int]' for array subscript
   36 |       c[i+1]=c[i];
      |               ^
a.cc:38:8: error: invalid types 'int[int]' for array subscript
   38 |       q[i+1]=q[i];
      |        ^
a.cc:38:15: error: invalid types 'int[int]' for array subscript
   38 |       q[i+1]=q[i];
      |               ^
a.cc:39:8: error: invalid types 'int[int]' for array subscript
   39 |       a[i+1]=a[i];
      |        ^
a.cc:39:15: error: invalid types 'int[int]' for array subscript
   39 |       a[i+1]=a[i];
      |               ^
a.cc:40:8: error: invalid types 'int[int]' for array subscript
   40 |       b[i+1]=b[i];
      |        ^
a.cc:40:15: error: invalid types 'int[int]' for array subscript
   40 |       b[i+1]=b[i];
      |               ^
a.cc:41:8: error: invalid types 'int[int]' for array subscript
   41 |       c[i+1]=c[i]+1;
      |        ^
a.cc:41:15: error: invalid types 'int[int]' for array subscript
   41 |       c[i+1]=c[i]+1;
      |               ^
a.cc:43:8: error: invalid types 'int[int]' for array subscript
   43 |       q[i+1]=q[i]+1;
      |        ^
a.cc:43:15: error: invalid types 'int[int]' for array subscript
   43 |       q[i+1]=q[i]+1;
      |               ^
a.cc:44:8: error: invalid types 'int[int]' for array subscript
   44 |       a[i+1]=a[i];
      |        ^
a.cc:44:15: error: invalid types 'int[int]' for array subscript
   44 |       a[i+1]=a[i];
      |               ^
a.cc:45:8: error: invalid types 'int[int]' for array subscript
   45 |       b[i+1]=b[i];
      |        ^
a.cc:45:15: error: invalid types 'int[int]' for array subscript
   45 |       b[i+1]=b[i];
      |               ^
a.cc:46:8: error: invalid types 'int[int]' for array subscript
   46 |       c[i+1]=c[i];
      |        ^
a.cc:46:15: error: invalid types 'int[int]' for array subscript
   46 |       c[i+1]=c[i];
      |               ^
a.cc:47:14: error: invalid types 'int[int]' for array subscript
   47 |       ans+=(a[i]+q[i])*(c-c[i]+q-q[i]-1);
      |              ^
a.cc:47:19: error: invalid types 'int[int]' for array subscript
   47 |       ans+=(a[i]+q[i])*(c-c[i]+q-q[i]-1);
      |                   ^
a.cc:47:28: error: invalid types 'int[int]' for array subscript
   47 |       ans+=(a[i]+q[i])*(c-c[i]+q-q[i]-1);
      |                            ^
a.cc:47:35: error: invalid types 'int[int]' for array subscript
   47 |       ans+=(a[i]+q[i])*(c-c[i]+q-q[i]-1);
      |                                   ^
a.cc:49:8: error: invalid types 'int[int]' for array subscript
   49 |       q[i+1]=q[i];
      |        ^
a.cc:49:15: error: invalid types 'int[int]' for array subscript
   49 |       q[i+1]=q[i];
      |               ^
a.cc:50:8: error: invalid types 'int[int]' for array subscript
   50 |       a[i+1]=a[i];
      |        ^
a.cc:50:15: error: invalid types 'int[int]' for array subscript
   50 |       a[i+1]=a[i];
      |               ^
a.cc:51:8: error: invalid types 'int[int]' for array subscript
   51 |       b[i+1]=b[i]+1;
      |        ^
a.cc:51:15: error: invalid types 'int[int]' for array subscript
   51 |       b[i+1]=b[i]+1;
      |               ^
a.cc:52:8: error: invalid types 'int[int]' for array subscript
   52 |       c[i+1]=c[i];
      |        ^
a.cc:52:15: error: invalid types 'int[int]' for array subscript
   52 |       c[i+1]=c[i];
      |               ^
a.cc:53:14: error: invalid types 'int[int]' for array subscript
   53 |       ans+=(a[i]+q[i])*(c+q-c[i]-q[i]);
      |              ^
a.cc:53:19: error: invalid types 'int[int]' for array subscript
   53 |       ans+=(a[i]+q[i])*(c+q-c[i]-q[i]);
      |                   ^
a.cc:53:30: error: invalid types 'int[int]' for array subscript
   53 |       ans+=(a[i]+q[i])*(c+q-c[i]-q[i]);
      |                              ^
a.cc:53:35: error: invalid types 'int[int]' for array subscript
   53 |       ans+=(a[i]+q[i])*(c+q-c[i]-q[i]);
      |                                   ^
a.cc:56:14: error: invalid operands of types 'int' and '__gnu_cxx::__promote<double>::__type' {aka 'double'} to binary 'operator%'
   56 |       ans=ans%(pow(10,9)+7);
      |           ~~~^~~~~~~~~~~~~~
      |           |             |
      |           int           __gnu_cxx::__promote<double>::__type {aka double}