Buggy python submission (verdict: Runtime Error):
inf = 1000000007

a = 0
ab = 0
abc = 0
r = 1
 
s = input()
 
for c in s:
    if c == "A":
        a += r
    elif c == "B":
        ab += a
    elif c == "C":
        abc += ab
    else:
        abc = abc * 3 + ab
        ab = ab * 3 + a
        a = a * 3 + r
        r *= 3
 
	a %= inf
	ab %= inf
    abc %= inf
    r %= inf

print(abc)

Fixed submission:
inf = 1000000007
 
a = 0
ab = 0
abc = 0
r = 1
 
s = input()
 
for c in s:
    if c == "A":
        a += r
    elif c == "B":
        ab += a
    elif c == "C":
        abc += ab
    else:
        abc = abc * 3 + ab
        ab = ab * 3 + a
        a = a * 3 + r
        r *= 3
        
    a %= inf
    ab %= inf
    abc %= inf
    r %= inf

print(abc)

Buggy python submission (verdict: Time Limit Exceeded):
a = 0
ab = 0
abc = 0
r = 1
 
s = input()
 
for c in s:
    if c == "A":
        a += r
    elif c == "B":
        ab += a
    elif c == "C":
        abc += ab
    else:
        abc = abc * 3 + ab
        ab = ab * 3 + a
        a = a * 3 + r
        r *= 3
 
print(abc % 1000000007)

Fixed submission:
inf = 1000000007
 
a = 0
ab = 0
abc = 0
r = 1
 
s = input()
 
for c in s:
    if c == "A":
        a += r
    elif c == "B":
        ab += a
    elif c == "C":
        abc += ab
    else:
        abc = abc * 3 + ab
        ab = ab * 3 + a
        a = a * 3 + r
        r *= 3
        
    a %= inf
    ab %= inf
    abc %= inf
    r %= inf

print(abc)

Buggy python submission (verdict: Runtime Error):
#include <iostream>
#include <algorithm>
using namespace std;

typedef long long llint;
llint inf = 1000000007;

llint a = 0;
llint b = 0;
llint c = 0;
llint r = 1;

string s;

int main() {
    cin >> s;
    for (int i = 0; i < s.length(); i++) {
        switch (s[i]) {
        case 'A':
            a = (a + r) % inf;
            break;
        case 'B':
            b = (b + a) % inf;
            break;
        case 'C':
            c = (c + b) % inf;
            break;
        default:
            c = (c * 3 + b) % inf;
            b = (b * 3 + a) % inf;
            a = (a * 3 + r) % inf;
            r = (r * 3) % inf;
        }
    }
    cout << c << endl;
    return 0;
}

Fixed submission:
inf = 1000000007
 
a = 0
ab = 0
abc = 0
r = 1
 
s = input()
 
for c in s:
    if c == "A":
        a += r
    elif c == "B":
        ab += a
    elif c == "C":
        abc += ab
    else:
        abc = abc * 3 + ab
        ab = ab * 3 + a
        a = a * 3 + r
        r *= 3
        
    a %= inf
    ab %= inf
    abc %= inf
    r %= inf

print(abc)

Buggy python submission (verdict: Runtime Error):
a = 0
ab = 0
abc = 0
r = 1

s = input()

for c in s:
    if c == "A":
        a += r
    elif c == "B":
        ab += a
    elif c == "C":
        abc += ab
    else:
        abc = abc * 3 + ab
        ab = ab * 3 + a
        a = a * 3 + r
        r *= 3

print(abc % 1_000_000_007)

Fixed submission:
inf = 1000000007
 
a = 0
ab = 0
abc = 0
r = 1
 
s = input()
 
for c in s:
    if c == "A":
        a += r
    elif c == "B":
        ab += a
    elif c == "C":
        abc += ab
    else:
        abc = abc * 3 + ab
        ab = ab * 3 + a
        a = a * 3 + r
        r *= 3
        
    a %= inf
    ab %= inf
    abc %= inf
    r %= inf

print(abc)