For a string consisting of A and B, define as the maximum number of times the following operation can be performed.
Operation: Remove ABA that appears as a (not necessarily contiguous) subsequence of , and close up the resulting gaps.
You are given a string consisting of A, B, and ?. Find the sum of over all strings obtained by replacing each ? in with either A or B, modulo .