Problem: There are N Reversi pieces arranged in a row. (A _Reversi piece_ is a disc with a black side and a white side.) The state of each piece is represented by a string S of length N. If S_i=`B`, the i-th piece from the left is showing black; If S_i=`W`, the i-th piece from the left is showing white.  Consider performing the following operation:    * Choose i (1 \leq i < N) such that the i-th piece from the left is showing black and the (i+1)-th piece from the left is showing white, then flip both of those pieces. That is, the i-th piece from the left is now showing white and the (i+1)-th piece from the left is now showing black.  Find the maximum possible number of times this operation can be performed.

Submission attempts (in order):
#AGC030 B - Powers of two
beki=[]
for i in range(1,32):
    beki.append(2**i)
def tasitekesu(data,n):
    result=[]
    kosu=0
    for i in range(len(data)):
        if i in result:
            continue
        for j in range(i):
            if j in result:
                continue
            if data[i]+data[j]==n:
                result.append(i)
                result.append(j)
                kosu=kosu+1
                break
    result.sort(reverse=True)
    for i in result:
        del data[i]
    return [data,kosu]

N=int(input())
A=input().split()
ans=0
for i in range(N):
    A[i]=int(A[i])
for i in (reversed(beki)):
    R=tasitekesu(A,i)
    A=R[0]
    ans=ans+R[1]
print(ans)

#AGC030 B - Powers of two
beki=[]
for i in range(1,32):
    beki.append(2**i)
N=int(input())
for i in range(N):
    A[i]=int(A[i])
sorted(A)
for i in (reversed(beki)):
    inverseA=[]
    for j in range(len(A)):
        inverseA.append(i-A[j])#inverseA
    for j in range(len(A)):
        if inverseA[j] in A:
            A.remove(inverseA[j])
print((N-len(A))%2)

#AGC030 B - Powers of two
beki=[]
for i in range(1,32):
    beki.append(2**i)
N=int(input())
A=input().split()
for i in range(N):
    A[i]=int(A[i])
sorted(A)
for i in (reversed(beki)):
    inverseA=[]
    for j in range(len(A)):
        inverseA.append(i-A[j])#inverseA
    for j in range(len(A)):
        if inverseA[j] in A:
            A.remove(inverseA[j])
print((N-len(A))//2)

#AGC030 B - Powers of two
beki=[]
for i in range(1,32):
    beki.append(2**i)
N=int(input())
for i in range(N):
    A[i]=int(A[i])
sorted(A)
for i in (reversed(beki)):
    inverseA=[]
    for j in range(len(A)):
        inverseA.append(i-A[j])#inverseA
    for j in range(len(A)):
        A.remove(inverseA[j])
print((N-len(A))%2)

#AGC029 A - Irreversible operation
def countB(data):
    sum=0
    kosu=0
    for i in range(len(data)):
        if data[i]=="B":
            kosu=kosu+1
            sum=sum+i
    return[sum,kosu]

text=input()
S=[]
N=len(text)
for i in range(N):
    S.append(text[i])
result=countB(S)
x=result[1]
Ans=(2*N-x-1)*x/2-result[0]
print(Ans)

#AGC029 A - Irreversible operation
def countB(data):
    sum=0
    kosu=0
    for i in range(len(data)):
        if data[i]=="B":
            kosu=kosu+1
            sum=sum+i
    return[sum,kosu]

text=input()
S=[]
N=len(text)
for i in range(N):
    S.append(text[i])
result=countB(S)
x=result[1]
Ans=int((2*N-x-1)*x/2-result[0])
print(Ans)

Verdicts: Runtime Error

Runtime Error

Runtime Error

Runtime Error

Wrong Answer

Accepted