s = input()
pos = 0
str_len = len(s)
count = 0
seq_a = 0
seq_bc = 0

while pos < str_len:
    if s[pos] == "A":
        while pos < str_len and s[pos] == "A":
            seq_a += 1
            pos += 1
        if pos+1 < str_len and s[pos] == "B" and s[pos + 1] == "C":
            while pos < str_len and s[pos] == "B" and pos + 1 < str_len and s[pos + 1] == "C":
                seq_bc += 1
                pos += 2
            count += seq_a * seq_bc
            if pos < str_len and s[pos] != "A":
                seq_a = 0
            seq_bc = 0
        else:
            pos += 1
            seq_a = 0
    else:
        pos += 1
        seq_a = 0

print(count) s = input() s input() input pos = 0 pos 0 str_len = len(s) str_len len(s) len s count = 0 count 0 seq_a = 0 seq_a 0 seq_bc = 0 seq_bc 0 while pos < str_len:
    if s[pos] == "A":
        while pos < str_len and s[pos] == "A":
            seq_a += 1
            pos += 1
        if pos+1 < str_len and s[pos] == "B" and s[pos + 1] == "C":
            while pos < str_len and s[pos] == "B" and pos + 1 < str_len and s[pos + 1] == "C":
                seq_bc += 1
                pos += 2
            count += seq_a * seq_bc
            if pos < str_len and s[pos] != "A":
                seq_a = 0
            seq_bc = 0
        else:
            pos += 1
            seq_a = 0
    else:
        pos += 1
        seq_a = 0 pos < str_len pos str_len if s[pos] == "A":
        while pos < str_len and s[pos] == "A":
            seq_a += 1
            pos += 1
        if pos+1 < str_len and s[pos] == "B" and s[pos + 1] == "C":
            while pos < str_len and s[pos] == "B" and pos + 1 < str_len and s[pos + 1] == "C":
                seq_bc += 1
                pos += 2
            count += seq_a * seq_bc
            if pos < str_len and s[pos] != "A":
                seq_a = 0
            seq_bc = 0
        else:
            pos += 1
            seq_a = 0
    else:
        pos += 1
        seq_a = 0 s[pos] == "A" s[pos] s pos "A" while pos < str_len and s[pos] == "A":
            seq_a += 1
            pos += 1
         pos < str_len and s[pos] == "A" pos < str_len pos str_len s[pos] == "A" s[pos] s pos "A" seq_a += 1 seq_a 1 pos += 1 pos 1 if pos+1 < str_len and s[pos] == "B" and s[pos + 1] == "C":
            while pos < str_len and s[pos] == "B" and pos + 1 < str_len and s[pos + 1] == "C":
                seq_bc += 1
                pos += 2
            count += seq_a * seq_bc
            if pos < str_len and s[pos] != "A":
                seq_a = 0
            seq_bc = 0
        else:
            pos += 1
            seq_a = 0
     pos+1 < str_len and s[pos] == "B" and s[pos + 1] == "C" pos+1 < str_len and s[pos] == "B" pos+1 < str_len pos+1 pos 1 str_len s[pos] == "B" s[pos] s pos "B" s[pos + 1] == "C" s[pos + 1] s pos + 1 pos 1 "C" while pos < str_len and s[pos] == "B" and pos + 1 < str_len and s[pos + 1] == "C":
                seq_bc += 1
                pos += 2
             pos < str_len and s[pos] == "B" and pos + 1 < str_len and s[pos + 1] == "C" pos < str_len and s[pos] == "B" and pos + 1 < str_len pos < str_len and s[pos] == "B" pos < str_len pos str_len s[pos] == "B" s[pos] s pos "B" pos + 1 < str_len pos + 1 pos 1 str_len s[pos + 1] == "C" s[pos + 1] s pos + 1 pos 1 "C" seq_bc += 1 seq_bc 1 pos += 2 pos 2 count += seq_a * seq_bc count seq_a * seq_bc seq_a seq_bc if pos < str_len and s[pos] != "A":
                seq_a = 0
             pos < str_len and s[pos] != "A" pos < str_len pos str_len s[pos] != "A" s[pos] s pos "A" seq_a = 0 seq_a 0 seq_bc = 0 seq_bc 0 pos += 1 pos 1 seq_a = 0 seq_a 0 pos += 1 pos 1 seq_a = 0 seq_a 0 print(count) print count seq_a = 0 0 seq_a seq_bc = 0 0 seq_bc seq_bc = 0 0 seq_bc pos += 1 1 pos pos += 2 2 pos pos = 0 0 pos str_len = len(s) len(s) str_len seq_a += 1 1 seq_a count += seq_a * seq_bc seq_a * seq_bc count pos += 1 1 pos seq_bc += 1 1 seq_bc pos += 1 1 pos s = input() input() s seq_a = 0 0 seq_a seq_a = 0 0 seq_a count = 0 0 count seq_a = 0 0 seq_a
s = input()
pos = 0
str_len = len(s)
count = 0
seq_a = 0
seq_bc = 0

while pos < str_len:
    if s[pos] == "A":
        while pos < str_len and s[pos] == "A":
            seq_a += 1
            pos += 1
        if pos+1 < str_len and s[pos] == "B" and s[pos + 1] == "C":
            while pos < str_len and s[pos] == "B" and pos + 1 < str_len and s[pos + 1] == "C":
                seq_bc += 1
                pos += 2
            count += seq_a * seq_bc
            if pos < str_len and s[pos] != "A":
                seq_a = 0
            seq_bc = 0
        else:
            pos += 1
            seq_a = 0
    else:
        pos += 1
        seq_a = 0

print(count)
