TnT/Multi_CodeNet4Repair huggingface dataset:
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):
S = list(str(input()))

ans = 0
cnt = 0
for i in range(len(S)-1):
    if S[i] == "B" and S[i+1] == "W":
        S[i+1] = "B"
        ans = ans + i + 1
        cnt = cnt + 1 

print(ans - cnt)

s = input()
ans = 0
count = 0
for i in range(len(s)):
    if s[i] == "W":
        ans += i - count
        count += 1
print(ans)

Verdicts: Wrong Answer

Accepted
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):
S = list(input())
n = len(S)
cnt_b = 0
cnt = 0
for i in range(n):
    if S[i] == 'B':
        cnt_b += 1
        cnt += i
ans = (2*n - cnt_b -1)*cnt_b*0.5 -cnt
print(ans)

S = list(input())
n = len(S)
cnt_b = 0
cnt = 0
for i in range(n):
    if S[i] == 'B':
        cnt_b += 1
        cnt += i
ans = int((2*n - cnt_b -1)*cnt_b*0.5 - cnt)
print(ans)

Verdicts: Wrong Answer

Accepted
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):
S = input()
num = 0
while(True):
    num += S.count("BW")
    S = S.replace("BW", "WB")
    print(S)
    if not "BW" in S:
        break
print(num)

S = input()
indexes = [i for i, x in enumerate(S) if x == "W"]
print(sum([x-i for i, x in enumerate(indexes)]))

Verdicts: Runtime Error

Accepted
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):
s = input()
cnt = 0
for i in s:
    if i == 'W':
        cnt += 1
print(cnt)

s = input()
ret = 0
st = 0
for i in range(len(s)):
    if (s[i] == 'W'):
        ret += (i-st)
        st += 1
print(ret)

Verdicts: Wrong Answer

Accepted
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):
# -*- coding:utf-8 -*-
S = list(input())

loop_idx = 0
loop_len = -(-len(S)//2)
cnt = 0

if len(S) == 1:
    pass
else:
    while loop_idx < loop_len:
        while True:
            if S[0] == "W":
                S.pop(0)
            else:
                break
        while True:
            if S[-1] == "B":
                S.pop(-1)
            else:
                break
        for i in range(len(S)-1,0,-1):
            if S[i]=="W" and S[i-1] == "B":
                cnt += 1
                S[i],S[i-1] = "B","W"
        loop_idx += 1
        #print(S)
print(cnt)

# -*- coding:utf-8 -*-
S = list(input())

cnt_b = 0 
ans = 0

for i in range(len(S)):
    if S[i] == "B":
        cnt_b += 1
    if S[i] == "W":
        ans += cnt_b
print(ans)        

Verdicts: Runtime Error

Accepted
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):
s = input()
n = len(s)
sum = [0] * (n + 1)
sum[0] = (s[0] == 'B')
for i in range(1 , n):
	sum[i] = sum[i-1] + (s[i] == 'B')
ans = 0
for i in range(n, -1 ,-1):
	print(i)
	if s[i] == 'W':
		ans += sum[i]
print(ans)
	

s = input()
n = len(s)
sum = [0] * (n + 1)
sum[0] = (s[0] == 'B')
for i in range(1 , n):
	sum[i] = sum[i-1] + (s[i] == 'B')
ans = 0
for i in range(n, -1 ,-1):
	if s[i] == 'W':
		ans += sum[i]
print(ans)
	

s = input()
n = len(s)
sum = [0] * (n + 1)
sum[0] = (s[0] == 'B')
for i in range(1 , n):
	sum[i] = sum[i-1] + (s[i] == 'B')
ans = 0
for i in range(n - 1, 0 ,-1):
	print(i)
	if s[i] == 'W':
		ans += sum[i]
print(ans)
	

s = input()
n = len(s)
sum = [0] * (n + 1)
sum[0] = (s[0] == 'B')
for i in range(1 , n):
	sum[i] = sum[i-1] + (s[i] == 'B')
ans = 0
for i in range(n - 1, -1 ,-1):
	if s[i] == 'W':
		ans += sum[i]
print(ans)
	

Verdicts: Runtime Error

Runtime Error

Wrong Answer

Accepted
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):
from itertools import permutations
N = int(input())

val = []
for _ in range(N):
    val.append(int(input()))
ans = 10**10
for i in permutations(val):
    for j in range(1, N):
        ans = min(max(sum(i[:j]), sum(i[j:])), ans)
if N == 1:
    print(val[0])
else:
    print(ans)
    

    


S = input()
ans = 0
count = 0
for i in S:
    print(i)
    if i == 'B':
        count += 1
    elif i == 'W':
        ans += count
print(ans)


S = input()
ans = 0
count = 0
for i in S:
    if i == 'B':
        count += 1
    elif i == 'W':
        ans += count
print(ans)


Verdicts: Runtime Error

Wrong Answer

Accepted
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):
/*test*/
#include<bits/stdc++.h>

using namespace std;

int main() {
    int i = 0,b = 0, bko = 0, sum = 0;
    string s;
    cin >> s;
    for (i = 0; i < s.size(); i++) {
        if (s[i] == 'B') {
            b += bko;
            bko += 1;
            sum += s.size() - 1 - i;
        }
    }
    cout << sum - b << endl;
    return 0;
}

s=list(input())
n=len(s)
ans=0
w=0
for index,value in enumerate(s):
    if value=="W":
        ans+=index-w
        w+=1
print(ans)

Verdicts: Runtime Error

Accepted
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):
s=list(input())

ima=0
wNum=0
for i in range(len(s)):
  if s[i]=="W":
    ima += i
    wNum += 1

def kasan(n):
  if n==0:
    return 0
  else:
    return kasan(n-1) + n

print(0)
#if wNum==0:
#  print(0)
#else:

#  print(ima-saigo)

s=list(input())

ima=0
wNum=0
for i in range(len(s)):
  if s[i]=="W":
    ima += i
    wNum += 1

def kasan(n):
  if n==0:
    return 0
  else:
    return kasan(n-1) + n

saigo = ((wNum-1)+0)*wNum//2
print(ima-saigo)

Verdicts: Wrong Answer

Accepted
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):
s,t,a=input(),0,0
for c in s:
  t+=1 if c is 'B' else a+=t
print(a)

cnt = ans = 0
for c in input():
  if c is 'W':
    ans += cnt
  else:
    cnt += 1
print(ans)

Verdicts: Runtime Error

Accepted
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):
# -*- coding: utf-8 -*-
S = input()
N = len(S)
S = list(S)

count = 0
count2 = 0
kekka = 0
for i in range(len(S)):
	if(S[i] == 'W'):
		count = count + 1
		count2 = count2 + i
for j in range(count):
	kekka = kekka + N - j

print(kekka-count2)

# -*- coding: utf-8 -*-
S = input()
N = len(S)
S = list(S)

count = 0
count2 = 0
kekka = 0
for i in range(len(S)):
	if(S[i] == 'B'):
		count = count + 1
		count2 = count2 + i
for j in range(count):
	kekka = kekka + N - j-1

print(kekka-count2)

Verdicts: Wrong Answer

Accepted
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):
S = array(input())
print(S)

S = list(input().strip())
is_irrversible = 0
answer = 0
position_key_sum = 0
number_of_white = 0
for i in range(len(S)):
    if S[i] == 'W':
        position_key_sum += i
        number_of_white += 1
answer = position_key_sum - number_of_white
print(answer)

S = list(input().strip())
is_irrversible = 0
answer = 0
position_key_sum = 0
number_of_white = 0
sigma = 0
for i in range(len(S)):
    if S[i] == 'W':
        position_key_sum += (i+1)
        number_of_white += 1
        sigma += number_of_white
answer = position_key_sum - sigma
print(answer)

Verdicts: Runtime Error

Wrong Answer

Accepted
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):
S = input()

arr = [0 if s == "W" else 1 for s in S]

state = [arr[i] * i for i in range(len(S))]
final_state = [sorted(arr)[i] * i for i in range(len(S))]

print(final_state - state)

S = input()
 
arr = [0 if s == "W" else 1 for s in S]
sorted_arr = sorted(arr)
 
state = [arr[i] * i for i in range(len(S))]
final_state = [sorted_arr[i] * i for i in range(len(S))]
 
print(final_state - state)
S = input()

arr = [0 if s == "W" else 1 for s in S]

state = sum([arr[i] * i for i in range(len(S))])
final_state = sum([sorted(arr)[i] * i for i in range(len(S))])

print(final_state - state)

S = input()
 
arr = [0 if s == "W" else 1 for s in S]
 
state = [arr[i] * i for i in range(len(S))]
final_state = [sorted(arr)[i] * i for i in range(len(S))]
 
print(final_state - state)
S = input()

arr = [0 if s == "W" else 1 for s in S]

state = sum([arr[i] * i for i in range(len(S))])
final_state = sum([sorted(arr)[i] * i for i in range(len(S))])

print(final_state - state)

S = input()
 
arr = [0 if s == "W" else 1 for s in S]
sorted_arr = sorted(arr)
  
state = sum([arr[i] * i for i in range(len(S))])
final_state = sum([sorted_arr[i] * i for i in range(len(S))])
 
print(final_state - state)

Verdicts: Runtime Error

Runtime Error

Runtime Error

Accepted
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):
S = list(input())
ans = 0
b = 0
print(S)
for i in range(len(S)):
    if S[i] == 'B':
        b += 1
    else:
        ans += b
        
print(ans)

S = list(input())
ans = 0
b = 0
for i in range(len(S)):
    if S[i] == 'B':
        b += 1
    else:
        ans += b
        
print(ans)

Verdicts: Wrong Answer

Accepted
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):
import sys
from io import StringIO
import unittest


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """BBW"""
        output = """2"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """BWBWBW"""
        output = """6"""
        self.assertIO(input, output)


def resolve():
    s = str(input())
    ans = 0
    while True:
        origin = s
        s = s.replace('BW', 'WB', 1)
        if origin == s:
            break
        ans += 1
    print(ans)

    return


if __name__ == "__main__":
    unittest.main()


def resolve():
    s = str(input())
    ans = 0
    ind = []
    for i, char in enumerate(s):
        if char == 'W':
            ind.append(i)
    lst = 0
    # print(ind)
    for i in ind:
        ans += (i - lst)
        lst += 1

    # idx = s.index('W')
    print(ans)
    return


resolve()

Verdicts: Wrong Answer

Accepted
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):
s = list(input())
ret, counter = 0, 0
for a in s:
    if a == "B":
        counter += 1
    else:
        ret += counter


s = list("BWBWBW" * 10000)

s = list(input())
ret, counter = 0, 0
for a in s:
    if a == "B":
        counter += 1
    else:
        ret += counter
print(str(ret))

Verdicts: Wrong Answer

Accepted
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):
s = input()
print(sum(s[:i].count("B") for i in range(len(s)) if s[i]=="W")

c = b = 0
for s in input():
  c += b*(s=="W")
  b += s=="B"
print(c)

Verdicts: Runtime Error

Accepted
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):
S = input()
W = []

for i, s enumerate(S):
  if s == 'W':
    W.append(i)

idx = 0
ans = 0
for w in W:
  ans += w-idx
  idx += 1

print(ans)

S = input()
W = []
 
for i, s in enumerate(S):
  if s == 'W':
    W.append(i)

idx = 0
ans = 0
for w in W:
  ans += w-idx
  idx += 1

print(ans)

Verdicts: Runtime Error

Accepted
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):
s = sorted(list(input()), reverse=True)
ans = []
tmp = 0
for i in s:
    if i == "W":
        tmp += 1
        ans.append(tmp)
print(sum(ans))

s = input()[::-1]
ans = []
tmp = 0
for i in s:
    if i == "W":
        tmp += 1
    elif i == "B":
        ans.append(tmp)
print(sum(ans))

Verdicts: Wrong Answer

Accepted
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):
import numpy as np
S = input()

idx = []
i = 0
for s in S:
    if s == "W":
        idx.append(i)
    i+=1
print(int(np.sum(idx) - (len(idx))))

import numpy as np
S = input()

idx = []
i = 0
W_flag = False
for s in S:
    if not W_flag:
        if s == "W":
            continue
        elif s == "B":
            W_flag = True
    
    if s == "W" and W_flag:
        idx.append(i)
    i+=1
print(int(np.sum(idx) - ((0+len(idx)-1)*len(idx)/2)))
        

Verdicts: Wrong Answer

Accepted
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):
def main():
    s = np.array(list(input()))
    
    ind = np.array(np.where(s=='B'))
    
    len_ind=ind.shape[1]
    
    len=s.shape[0]
    
    dist=np.arange(len-len_ind,len)
    
    ans=np.sum(dist-ind)
    return ans

import numpy as np
def main():
    s = np.array(list(input()))
    
    ind = np.array(np.where(s=='B'))
    
    len_ind=ind.shape[1]
    
    len=s.shape[0]
    
    dist=np.arange(len-len_ind,len)
    
    ans=np.sum(dist-ind)
    return ans

def main(s1):
    s = np.array(list(s1))
    
    ind = np.array(np.where(s=='B'))
    
    len_ind=ind.shape[1]
    
    len=s.shape[0]
    
    dist=np.arange(len-len_ind,len)
    
    ans=np.sum(dist-ind)
    return ans

#import numpy as np
s = np.array(list(input()))

ind = np.array(np.where(s=='B'))

len_ind=ind.shape[1]

len=s.shape[0]

dist=np.arange(len-len_ind,len)

ans=np.sum(dist-ind)
print(ans)

import numpy as np
s = np.array(list(input()))

ind = np.array(np.where(s=='B'))

len_ind=ind.shape[1]

len=s.shape[0]

dist=np.arange(len-len_ind,len)

ans=np.sum(dist-ind)
print(ans)

Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

Runtime Error

Accepted
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):
ans = 0
ans2 = 0
s = input()
l = len(s)
t = 1
for i in range(l):
  print(f'a={t}')
  same = True
  while same:
    if s[i] != s[t]:
      i = t
      print(f'b={t}')
      same = False
    else:
      ans += 1
print(max(ans, ans2))


import sys

input = sys.stdin.readline

def main():
    ans = 0
    S = input().rstrip('\n')
    w = 0
    for s in S[::-1]:
        if s == 'W':
            w += 1
        else:
            ans += w
    print(ans)

if __name__ == '__main__':
    main()

Verdicts: Time Limit Exceeded

Accepted
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):
txt = input()
txt_list = list(txt)

count = 0
n_b = 0
n_w = 0
i = 0
for i in range(len(txt_list)):
    print(txt_list[i])
    if txt_list[i] == 'W':
        n_w += 1
    if (i>=1 and txt_list[i-1] == 'W' and txt_list[i] == 'B') or (i==len(txt_list)-1 and txt_list[i] == 'W'):
        count += n_b * n_w
        # print(n_b)
        # print(n_w)
        n_w = 0
    if txt_list[i] == 'B':
        n_b += 1

print(count)

txt = input()
txt_list = list(txt)

count = 0
n_b = 0
n_w = 0
i = 0
for i in range(len(txt_list)):
    if txt_list[i] == 'W':
        n_w += 1
    if (i>=1 and txt_list[i-1] == 'W' and txt_list[i] == 'B') or (i==len(txt_list)-1 and txt_list[i] == 'W'):
        count += n_b * n_w
        n_w = 0
    if txt_list[i] == 'B':
        n_b += 1

print(count)

Verdicts: Wrong Answer

Accepted
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):
import math
N=int(input())
A=list(map(int,input().split()))
A.sort()
s=0
i=1
while i<=len(A)-1:
    a=int(math.log2(A[-i]))
    if 2**(a+1)-A[-i] in A[:-i]:
        s+=1
        A.remove(2**(a+1)-A[-i])
        i+=1
    else:
        i+=1
print(s)

import math
N=int(input())
A=list(map(int,input().split()))
Ae1=[]
Ao1=[]
for i in range(N):
    if A[i]%2==0:
        Ae1.append(A[i])
    else:
        Ao1.append(A[i])
if Ao1!=[]:
    s=0
    Ao=sorted(Ao1,reverse=True)
    i=0
    while i<=len(Ao)-1:
        a=int(math.log2(Ao[i]))
        if 2**(a+1)-Ao[i] in Ao[i:]:
            s+=1
            Ao.remove(2**(a+1)-Ao[i])
            i+=1
        else:
            i+=1
else:
    s=0
if Ae1!=[]:
    t=0
    Ae=sorted(Ae1,reverse=True)
    j=0
    while j<=len(Ae):
        b=int(math.log2(Ae[j]))
        if 2**(a+1)-Ae[j] in Ae[j:]:
            s+=1
            Ae.remove(2**(a+1)-Ae[j])
            j+=1
        else:
            j+=1
else:
    t=0
print(s+t)
        

S=input()
a=0
b=0
for i in range(len(S)):
    if S[-i-1]=="B":
        a+=i-b
        b+=1
print(a)


Verdicts: Runtime Error

Runtime Error

Accepted
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):
ans=0
for i in range(1000000):
    cnt=N.count("BW")
    ans=ans+cnt
    N=N.replace("BW","WB")
    N=N.lstrip("W")
    N=N.rstrip("B")
    if cnt==0:
        break
print(ans)

from sys import stdin
N=(stdin.readline().rstrip())
ans=0
for i in range(10000):
    index=N.find("W")
    if index==-1:
        break
    ans=ans+index
    N=str_del(N,index)
print(ans)

from sys import stdin
N=(stdin.readline().rstrip())
N=list(N)
cnt=0
ans=0
for i in N:
    if i=="B":
        cnt+=1
    else:
        ans+=cnt
print(ans)

Verdicts: Runtime Error

Runtime Error

Accepted
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):
#S = input().strip()
Sb = [c == "B" for c in S]

def reverse(Sb,i):
    _list = Sb.copy()
    _list[i] = not _list[i]
    return _list

def operate_onestep(Sb):
    _list = Sb.copy()
    cnt = 0
    flg = True
    while flg:
        flg = False
        for i in range(len(_list)-1):
            if _list[i] and not _list[i+1]:
                cnt += 1
                _list = reverse(_list,i)
                _list = reverse(_list,i+1)
                flg = True
    return cnt

print(operate_onestep(Sb))

S = input().strip()
Sb = [c == "B" for c in S]
 
def reverse(Sb,i):
    _list = Sb.copy()
    _list[i] = not _list[i]
    return _list

def operate(Sb):
    _list = Sb.copy()
    cnt = 0
    flg = True
    t_start = 0
    t_end = len(Sb)
    while flg:
        flg = False
        try:
            t_start = _list[t_start:].index(True) + t_start
        except:
            break
        try:
            t_end = t_end -  list(reversed(_list[:t_end])).index(False)
        except:
            break
        
        for i in range(t_start,t_end-1):
            if _list[i] and not _list[i+1]:
                cnt += 1
                _list = reverse(_list,i)
                _list = reverse(_list,i+1)
                flg = True
    return cnt, _list, t_start, t_end
 
print(operate(Sb))

S = input().strip()

w_total = 0
num_op = 0
for i,c in enumerate(S):
    if c == "W":
        w_total += 1
        num_op += i + 1 - w_total
        
print(num_op)

Verdicts: Runtime Error

Wrong Answer

Accepted
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):
N = int(input())
A_list = list(map(int, input().split()))
two_list = [2 ** i for i in range(32)]
 
count = 0
items = {}
for a in A_list:
    if a in items:
        items[a] += 1
 
    else:
        items[a] = 1
A_list.sort(reverse=True)
 
for a in A_list:
    if items[a] >= 1:
 
        for t in two_list:
            m = t -a
            if m in items:
                if m == a and items[a] >= 2:
                    count += 1
                    items[a] -= 1
                    items[m] -= 1
                    break
 
                elif m != a and items[m] >= 1 and items[a] >=1:
                    count += 1
                    items[a] -= 1
                    items[m] -= 1
                    break
print(count)

S = input()
S_list = []
for i in S:
    S_list.append(i)

w_count = S.count("W")
b_count = S.count("B")
c = 0

for i in range(len(S)):

    if S[i] == "B":
        c += w_count
    else:
        w_count -= 1

print(c)



Verdicts: Runtime Error

Accepted
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):
s = input()
ans = 0
numB = 0
for i in reversed(range(len(s))):
    if s[i] == 'B':
        ans += len(s) - 1 - i - numB
        numB += 1
        print(ans)

s = input()
ans = 0
numB = 0
for i in reversed(range(len(s))):
    if s[i] == 'B':
        ans += len(s) - 1 - i - numB
        numB += 1
print(ans)

Verdicts: Wrong Answer

Accepted
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):
import collections
 
n=int(input())
a=list(map(int,input().split()))
a.sort(reverse=True)
c=collections.Counter(a)
ans=0
for i in a:
  for j in range(31):
    if(2**j>i):
      k=2**j-i
      break
  if k in c.keys():
    if i==k and c[i]>1:
      c[i]-=2
      ans+=1
    elif i!=k and c[i]>0 and c[k]>0:
      c[i]-=1
      c[k]-=1
      ans+=1
print(ans)


s=input()
n=0
c=0
for i in range(len(s)):
  if s[i]=='W':
    n+=i-c
    c+=1
print(n)

Verdicts: Runtime Error

Accepted
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):
# -*- coding: utf-8 -*-


def main():
    """Function."""
    s = str(input())
    num = len(s)

    total = 0
    for _ in range(num//2+1):
        print(_)
        count = s.count("BW")
        if count == 0:
            break
        else:
            total += count
            s_list = list(s)

            for i in range(num):
                if s_list[i:i+2] == ["B", "W"]:
                    s_list[i:i+2] = ["W", "B"]
            print(s_list)

            s = "".join(s_list)

    print(total)


if __name__ == "__main__":
    main()


# -*- coding: utf-8 -*-


def main():
    """Function."""
    s = str(input())

    total = 0
    b_count = 0
    for i in range(len(s)):
        if s[i] == "B":
            b_count += 1
        if s[i] == "W":
            total += b_count

    print(total)


if __name__ == "__main__":
    main()


Verdicts: Wrong Answer

Accepted
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):
N = int(input().rstrip())
A = [int(s) for s in input().rstrip().split()]
A.sort()

squared = [2]
tmp = 2
while tmp < 2 * 10**9:
    tmp *= 2
    squared.append(tmp)

pairs = []
for i in range(N):
    for j in range(i+1, N):
        if A[i] + A[j] in squared:
            pairs.append([A[i], A[j]])

adopt = [format(i, 'b').rjust(len(pairs), '0') for i in range(2**len(pairs))]
max_pair = 0

for i in range(len(adopt)):
    num = []
    for j in range(len(pairs)):
        if adopt[i][j] == '1':
            num.append(pairs[j][0])
            num.append(pairs[j][1])
    if len(num) == len(set(num)) and len(num) > max_pair:
        max_pair = len(num)

print(max_pair // 2)

state = input().rstrip()
ans = 0
cnt = 0
for i, s in enumerate(state):
    if s == 'B':
        cnt += 1
    else:
        ans += cnt
print(ans)

Verdicts: Runtime Error

Accepted
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):
S = list(input())
cnt = 0
for i, a in enumerate(S):
  if a == 'W':
    cnt += i-1
print(cnt)

S = list(input())
cnt = call = 0
for i, a in enumerate(S):
  if a == 'W':
    cnt += i-call
    call += 1
print(cnt)

Verdicts: Wrong Answer

Accepted
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):
osero = input();
len = len(osero);
con_b = 0;
con = 0;
for(i =0; i<len, i++) {
	if(osero[i]='B') {
		con_b++;
	}
	if(osero[i] ='W') {
		con = con + con_b;
	}
}
print(con)

osero = input();
len = len(osero);
con_b = 0;
con = 0;
for i in range(0,len):
	if osero[i]=='B':
		con_b = con_b + 1;
	if osero[i] =='W':
		con = con + con_b;
print(con)

Verdicts: Runtime Error

Accepted
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):
S=list(input())
n=len(S)

def search(t):
    for i in range(t,n-1):
        if S[i]=='B' and S[i+1]=='W':
            S[i],S[i+1]='W','B'
            if t>0:
                return 1+search(t-1)
            else:
                return 1+search(1)
    return 0

print(search(0))


S=list(input())
n=len(S)
ans=0
b=0

for s in S:
    if s=='B':b+=1
    else:ans+=b
    
print(ans)

Verdicts: Runtime Error

Accepted
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):
s = input()
slist = list(s)
l = len(s)
n = 0
j = 1
start = 0
end = l-1

while j != 0:
  j = 0
  for i in range(start, end):
    if slist[i:i+2] == ['B','W']:
      slist[i:i+2] = ['W','B']
      n += 1
      j = 1
      end = i
  start += 1
#  end -= 1

print(n)

s = input()
slist = list(s)
l = len(s)
n = 0
j = 1
start = 0
end = l-1

while j != 0:
  j = 0
  for i in range(start, end):
    if slist[i:i+2] == ['B','W']:
      slist[i:i+2] = ['W','B']
      n += 1
      j = 1
#      end = i+1
  start += 1
  end -= 1

print(n)

S = input()
cnt = 0
ans = 0
left = 0
for i in range(len(S)):
    if S[i] == 'W':
        cnt += S[left:i].count('B')
        ans += cnt
        left = i
print(ans)

Verdicts: Wrong Answer

Wrong Answer

Accepted
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):
N, As = int(input()), list(map(int, input().split()))
maxA, ans = max(As), 1
while True:
    if pow(ans, maxA) - 1 > N:
        break
    ans += 1
print(ans)

ans, w_idx = 0, 0
for i, s in enumerate(input()):
    if s != 'W':
        continue
    ans += i - w_idx
    w_idx += 1
print(ans)

Verdicts: Runtime Error

Accepted