Buggy python submission (verdict: Runtime Error):


ball_num = int(input())
num_data = list(map(int, input().split()))

ans = 0

def check_beki(num1, num2):
    data = num1 + num2
    while 1:
        data1 = data % 2
        data = int(data / 2)
        if data1 == 1:
            return 0
        elif num1 + num2 >= 1 and data == 1:
            return 1

def check_ans(ans_list, tasu_flg):
    global ans
    ans_kari = 0
    for i in range(len(ans_list)):
        if check_beki(ans_list[i], 0) and tasu_flg[i] == 1:
            ans_kari += 1
    if ans_kari > ans:
        ans = ans_kari

def check(index, ans_list_ori, tasu_flg_ori):
    global ball_num, num_data
    ans_list = ans_list_ori.copy()
    tasu_flg = tasu_flg_ori.copy()

    # if len(ans_list) >= tree_num:
    #     return

    # print(check_beki(3, 5))

    if index < ball_num:
        for j in range(len(ans_list)):
            # print(ans_list[j], num_data[index])
            if check_beki(ans_list[j], num_data[index]) and tasu_flg[j] == 0:
                # print('yyy')
                ans_list[j] += num_data[index]
                tasu_flg[j] = 1
                check(index+1, ans_list, tasu_flg)
                tasu_flg[j] = 0
                ans_list[j] -= num_data[index]
            # 新しく木を使う場合
            ans_list.append(num_data[index])
            tasu_flg.append(0)
            check(index+1, ans_list, tasu_flg)
            tasu_flg.pop(-1)
            ans_list.pop(-1)
    else:
        # 以前よりも最少の気で作れたら最小値の更新
        check_ans(ans_list, tasu_flg)


def main():
    global num_data
    check(1, [num_data[0]], [0])

    print(ans)



if __name__ == '__main__':
    main()

Fixed submission:
data = list(input())

count = 0
# i = 0
# while 1:
count_b = 0
for i in range(len(data)):
    # print(i)
    if data[i] == 'W':
        count += count_b
        # count += 1
        # data[i], data[i+1] = 'B', 'W'
        # break
    else:
        count_b += 1
    # else:
    #     break
print(count)

Buggy python submission (verdict: Time Limit Exceeded):
data = list(input())[::-1]

count = 0
i = 0
# while 1:
for i in range(len(data)):
    # print(i)
    if data[i] == 'W':
        count += data[i+1:].count('B')
        # count += 1
        # data[i], data[i+1] = 'B', 'W'
        # break
    # else:
    #     break
print(count)


Fixed submission:
data = list(input())

count = 0
# i = 0
# while 1:
count_b = 0
for i in range(len(data)):
    # print(i)
    if data[i] == 'W':
        count += count_b
        # count += 1
        # data[i], data[i+1] = 'B', 'W'
        # break
    else:
        count_b += 1
    # else:
    #     break
print(count)

Buggy python submission (verdict: Time Limit Exceeded):
data = list(input())[::-1]

count = 0
i = 0
while 1:
    for i in range(len(data)-1):
        if data[i] == 'W' and data[i + 1] == 'B':
            count += 1
            data[i], data[i+1] = 'B', 'W'
            break
    else:
        break
print(count)


Fixed submission:
data = list(input())

count = 0
# i = 0
# while 1:
count_b = 0
for i in range(len(data)):
    # print(i)
    if data[i] == 'W':
        count += count_b
        # count += 1
        # data[i], data[i+1] = 'B', 'W'
        # break
    else:
        count_b += 1
    # else:
    #     break
print(count)