qyliang/CodeNanoFix huggingface dataset:
Buggy code:
import math
def make_prime_list(num):
    if num < 2:
        return []
    prime_list = [i for i in range(num + 1)]
    prime_list[1] = 0
    num_sqrt = math.sqrt(num)

    for prime in prime_list:
        if prime == 0:
            continue
        if prime > num_sqrt:
            break
        
        for non_prime in range(2 * prime, num, prime):
            prime_list[non_prime] = 0
    return [prime for prime in prime_list if prime != 0]

def prime_factorization(num):
    if num <= 1:
        return False
    else:
        num_sqrt = math.floor(math.sqrt(num))
        prime_list = make_prime_list(num_sqrt)

        dict_counter = {}
        for prime in prime_list:
            while num % prime == 0:
                if prime in dict_counter:
                    dict_counter[prime] += 1
                else:
                    dict_counter[prime] = 1
                num //= prime
        if num != 1:
            if num in dict_counter:
                dict_counter[num] += 1
            else:
                dict_counter[num] = 1
        return dict_counter




if __name__ == '__main__':
    N, P = map(int, input().split())

    d = prime_factorization(P)

    cnt = 1

    for key, value in d.items():
        if value >= N:
            cnt *= key

    print(cnt)


Fixed code:
import math
def make_prime_list(num):
    if num < 2:
        return []
    prime_list = [i for i in range(num + 1)]
    prime_list[1] = 0
    num_sqrt = math.sqrt(num)

    for prime in prime_list:
        if prime == 0:
            continue
        if prime > num_sqrt:
            break
        
        for non_prime in range(2 * prime, num, prime):
            prime_list[non_prime] = 0
    return [prime for prime in prime_list if prime != 0]

def prime_factorization(num):
    if num <= 1:
        return {1 : 1}
    else:
        num_sqrt = math.floor(math.sqrt(num))
        prime_list = make_prime_list(num_sqrt)

        dict_counter = {}
        for prime in prime_list:
            while num % prime == 0:
                if prime in dict_counter:
                    dict_counter[prime] += 1
                else:
                    dict_counter[prime] = 1
                num //= prime
        if num != 1:
            if num in dict_counter:
                dict_counter[num] += 1
            else:
                dict_counter[num] = 1
        return dict_counter




if __name__ == '__main__':
    N, P = map(int, input().split())

    d = prime_factorization(P)

    cnt = 1

    for key, value in d.items():
        while value >= N :
            cnt *= key
            value -= N
    if N == 1:
        print(P)
    else:
        print(cnt)
Buggy code:
# -*- coding: utf-8 -*-
import collections
import math

N, P = map(int, input().split())

insuList=[]
warukazu = 2
while (warukazu <= math.sqrt(P) +1):
  if P % warukazu == 0:
    P = P / warukazu
    insuList.append(warukazu)
  else:
    warukazu+=1
insuList.append(P)

ans=1
c=collections.Counter(insuList)
for key in c.keys():
  while c[key] >= N:
    ans=ans*key
    c[key] -= N

print(ans)

Fixed code:
# -*- coding: utf-8 -*-
import collections
import math

N, P = map(int, input().split())

insuList=[]
warukazu = 2
while (warukazu <= math.sqrt(P) +1):
  if P % warukazu == 0:
    P = P / warukazu
    insuList.append(warukazu)
  else:
    warukazu+=1
insuList.append(P)

ans=1
c=collections.Counter(insuList)
for key in c.keys():
  while c[key] >= N:
    ans=ans*key
    c[key] -= N

print(int(ans))
Buggy code:
n,p = map(int,input().split())

i = 2
factors = []
factor_sub = set()
if p > 1:
    while i * i <= p:
        if p % i:
            i += 1
        else:
            p //=i
            factors.append(i)
            factor_sub.add(i)
    if p > 1:
        factors.append(p)
    if len(factors) < n:
        print('1')
    else:
        ans = 1
        for c in factor_sub:
            temp = factors.count(c)
            while temp >= n:
                ans *= c
                temp -= n
        print(int(ans))
else:
    print('1')

Fixed code:
n,p = map(int,input().split())

i = 2
factors = []
factor_sub = set()
if n == 1:
    print(p)
elif p > 1:
    while i * i <= p:
        if p % i:
            i += 1
        else:
            p //=i
            factors.append(i)
            factor_sub.add(i)
    if p > 1:
        factors.append(p)
    if len(factors) < n:
        print('1')
    else:
        ans = 1
        for c in factor_sub:
            temp = factors.count(c)
            while temp >= n:
                ans *= c
                temp -= n
        print(int(ans))
else:
    print('1')
Buggy code:
n,p=map(int,input().split())

i=2
gcd=1
p=1024*1024*1024
if(n>40):
    print(1)
elif(n==1):
    print(p)
else:
    while((i**n)<=p):
        if(p%(i**n)==0):
            #print(i)
            gcd*=i
            p/=(i**n)
            i-=1
        i+=1
        
    print(gcd)

Fixed code:
n,p=map(int,input().split())

i=2
gcd=1
if(n>40):
    print(1)
elif(n==1):
    print(p)
else:
    while((i**n)<=p):
        if(p%(i**n)==0):
            #print(i)
            gcd*=i
            p/=(i**n)
            i-=1
        i+=1
        
    print(gcd)
Buggy code:
N,P = list(map(int,input().split()))
mylist = []
roop  = int((10**12)**(1/N))

def primes(n):
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    return [i for i in range(n + 1) if is_prime[i]]

Primelis = primes(roop)
if N ==1:
    print(P)
else:
    for i in Primelis:
        if P%(i**N)==0:
            mylist.append(i)
            P = P/(i**N)
    ans = 1
    L = len(mylist)
    for i in range(L):
        ans = ans*mylist[i]
    print(ans)


Fixed code:
N,P = list(map(int,input().split()))
mylist = []
roop  = int((10**12)**(1/N))

def primes(n):
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    return [i for i in range(n + 1) if is_prime[i]]

flag = 0
tmp = 1
if N ==1:
    print(P)
else:
    Primelis = primes(roop)
    for i in Primelis:
        flag = 0
        tmp = 1
        while flag==0:
            if P%(i**N)==0:
                P = P/(i**N)
                tmp = tmp*i
            else:
                mylist.append(tmp)
                flag = 1
    ans = 1
    L = len(mylist)
    for i in range(L):
        ans = ans*mylist[i]
    print(ans)
Buggy code:
def e(n,p):
  i = 2
  ans = 1
  while i * i <= n:
    b = 0
    while n % i == 0:
      n /= i
      b += 1
    else:
      ans *= i**(b//p)
    i += 1
  return ans
  
n,p = map(int, input().split())

a = e(p,n)
print(a)

Fixed code:
def e(n,p):
  i = 2
  ans = 1
  if p == 1:
    return n
  else:
    while i * i <= n:
      b = 0
      while n % i == 0:
        n /= i
        b += 1
      else:
        ans *= i**(b//p)
      i += 1
    return ans
  
n,p = map(int, input().split())

a = e(p,n)
print(a)
Buggy code:
def prime_factors(n):
    i = 2
    factors = []
    while i * i <= n:
        if n % i:
            i += 1
        else:
            n //= i
            factors.append(i)
    if n > 1:
        factors.append(n)
    return factors

N,p=map(int, input().split(" "))
tmp=prime_factors(p)

d={}
count=1
#result=[]
for i in tmp:
    if i in d:
        if d[i]==N-1:
            d[i]=0
            #result.append(i)
            count*=i
        else:
            d[i]+=1
    else:
        d[i]=1
print(count)


Fixed code:
def prime_factors(n):
    i = 2
    factors = []
    while i * i <= n:
        if n % i:
            i += 1
        else:
            n //= i
            factors.append(i)
    if n > 1:
        factors.append(n)
    return factors

N,p=map(int, input().split(" "))
tmp=prime_factors(p)

d={}
count=1
#result=[]
if N==1:
    print(p)
else:
    for i in tmp:
        if i in d:
            if d[i]==N-1:
                d[i]=0
                #result.append(i)
                count*=i
            else:
                d[i]+=1
        else:
            d[i]=1
    print(count)
Buggy code:
from math import sqrt
n, p = map(int, input().split())
a = []
for i in range(2, int(sqrt(p))+1):
    tmp = 0
    while p % i == 0:
        p //= i
        tmp += 1
    if tmp >= n:
        tmp //= n
        a.append(i*tmp)

ans = 1
for i in a:
    ans *= i

print(ans)


Fixed code:
from math import sqrt
n, p = map(int, input().split())
a = []

if n == 1:
    print(p)
    exit()

for i in range(2, int(sqrt(p))+10):
    tmp = 0
    while p % i == 0:
        p //= i
        tmp += 1
    if tmp >= n:
        tmp //= n
        a.append(i**tmp)

ans = 1
for i in a:
    ans *= i

print(ans)
Buggy code:
from collections import Counter

def prime_decomposition(n):
    i = 2
    table = []
    while i * i <= n:
        while n % i == 0:
            n /= i
            table.append(i)
        i += 1
    if n > 1:
        table.append(n)
    return table

N, P = [int(a) for a in input().strip().split()]

facs = prime_decomposition(P)
facc = Counter(facs)

common = 1
for fac in facc:
    if facc[fac] >= N:
        common = common * fac

print(common)



Fixed code:
from collections import Counter

def prime_decomposition(n):
    i = 2
    table = []
    while i * i <= n:
        while n % i == 0:
            n /= i
            table.append(i)
        i += 1
    if n > 1:
        table.append(int(n))
    return table

N, P = [int(a) for a in input().strip().split()]

facs = prime_decomposition(P)
facc = Counter(facs)

common = 1
for fac in facc.keys():
    count = facc[fac]
    while count >= N:
        common = common*fac
        count -= N

print(int(common))
Buggy code:
n,p=map(int,input().split())
ans=1
def prime_factors(p):
    i = 2
    factors = []
    while i * i <= p:
        if p % i:
            i += 1
        else:
            p //= i
            factors.append(i)
    if n > 1:
        factors.append(p)
    return factors
primelist=prime_factors(p)
set=list(set(primelist))
for i in set:
    if primelist.count(i)//n>=1:
      ans=ans*(i**(primelist.count(i)//n))
    else:
      pass
print(ans)


Fixed code:
n,p=map(int,input().split())
ans=1
flag=0
if n==1:
  print(p)
  flag+=1
def prime_factors(p):
    i = 2
    factors = []
    while i * i <= p:
        if p % i:
            i += 1
        else:
            p //= i
            factors.append(i)
    if n > 1:
        factors.append(p)
    return factors
primelist=prime_factors(p)
set=list(set(primelist))
for i in set:
    if primelist.count(i)//n>=1:
      ans=ans*(i**(primelist.count(i)//n))
    else:
      pass
if flag==0:
  print(ans)
Buggy code:
def main():
    n, p = map(int, input().split())
    x = 1

    print(list(get_prime_factors(p)))

    for f, c in get_prime_factors(p):
        if c >= n:
            x *= f * (c // n)

    print(x)

def get_prime_factors(p):
    f = 2

    while f * f<= p:
        c = 0
        while True:
            m, r = divmod(p, f)
            if r != 0:
                break
            c += 1
            p //= f
        if c != 0:
            yield f, c

        f += 1

    if p != 1:
        yield p, 1

main()


Fixed code:
def main():
    n, p = map(int, input().split())
    x = 1

    for f, c in get_prime_factors(p):
        if c >= n:
            x *= f ** (c // n)

    print(x)

def get_prime_factors(p):
    f = 2

    while f * f <= p:
        c = 0
        while True:
            m, r = divmod(p, f)
            if r != 0:
                break
            c += 1
            p = m

        if c != 0:
            yield f, c

        f += 1

    if p != 1:
        yield p, 1

main()
Buggy code:
N,P=list(map(int,input().split()))
 
root=P**(1/N)
x=round(root)
 
if n==1:
    print(p)
else:
	for i in range(x):
		if P%((x-i)**N)==0:
			print(x-i)
			break

Fixed code:
N,P=list(map(int,input().split()))

root=P**(1/N)
x=round(root)

for i in range(x):
	if P%((x-i)**N)==0:
		print(x-i)
		break
Buggy code:
import math
from collections import Counter
n, p = [int(_) for _ in input().split()]

def isprime_alpha(n):
    if n == 1:
        return True
    elif n == 2:
        return True
    elif n == 3:
        return True
    elif n % 2 == 0 or n % 3 == 0:
        return False
    else:
        for j in range(5, math.ceil(n ** (1/2))+1):
            if n % j == 0:
                return False
        return True

def factor(n, fac_list):
    if isprime_alpha(n):
        fac_list.append(n)
        return fac_list
    else:
        for i in range(2, math.ceil(n ** (1/2))+1):
            if n % i == 0:
                fac_list.append(i)
                return factor(n // i, fac_list)

list = []
list_result = factor(p, list)
print(list_result)
counter_dict = Counter(list_result)
print(counter_dict)

result = 1
for key, value in counter_dict.items():
    if value % n != 0:
        value -= value % n
    for j in range(value // n):
        result *= key

print(result)

Fixed code:
import math
from collections import Counter
n, p = [int(_) for _ in input().split()]

def isprime_alpha(n):
    if n == 1:
        return True
    elif n == 2:
        return True
    elif n == 3:
        return True
    elif n % 2 == 0 or n % 3 == 0:
        return False
    else:
        for j in range(5, math.ceil(n ** (1/2))+1):
            if n % j == 0:
                return False
        return True

def factor(n, fac_list):
    if isprime_alpha(n):
        fac_list.append(n)
        return fac_list
    else:
        for i in range(2, math.ceil(n ** (1/2))+1):
            if n % i == 0:
                fac_list.append(i)
                return factor(n // i, fac_list)

list = []
list_result = factor(p, list)
counter_dict = Counter(list_result)

result = 1
for key, value in counter_dict.items():
    if value % n != 0:
        value -= value % n
    for j in range(value // n):
        result *= key

print(result)
Buggy code:
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)

Fixed code:
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)
Buggy code:
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)
	

Fixed code:
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)
Buggy code:
s=list(input())
ans=0
ch=0
for x in range(len(s)):
  if s[x]=='W':
    ans+=(x-ch)
    
print(ans)

Fixed code:
s=list(input())
ans=0
ch=0
for x in range(len(s)):
  if s[x]=='W':
    ans+=(x-ch)
    ch+=1
    
print(ans)
Buggy code:
s = input()

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

Fixed code:
s = input()
 
cw = 0
ans = 0
for i in range(len(s)):
  if s[i] == 'W':
    ans += i-cw
    cw += 1
    
print(ans)
Buggy code:
S = input()
ans = 0
count = 0
for i in S:
    print(i)
    if i == 'B':
        count += 1
    elif i == 'W':
        ans += count
print(ans)


Fixed code:
S = input()
ans = 0
count = 0
for i in S:
    if i == 'B':
        count += 1
    elif i == 'W':
        ans += count
print(ans)
Buggy code:
import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import *
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
# sys.setrecursionlimit(int(pow(10, 2)))
#sys.stdin = open("input.txt", "r")
# sys.stdout = open("output.txt", "w")
mod = int(pow(10, 9) + 7)
mod2 = 998244353
def data(): return sys.stdin.readline().strip()
def out(*var, end="\n"): sys.stdout.write(' '.join(map(str, var))+end)
def l(): return list(sp())
def sl(): return list(ssp())
def sp(): return map(int, data().split())
def ssp(): return map(str, data().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]





# @lru_cache(None)
s=list(input())
k=0
i=0
while(i+1<len(s)):
    if(s[i]=="B" and s[i+1]=="W"):
        s[i],s[i+1]=s[i+1],s[i]
        k+=1
    i+=1
print(k)


Fixed code:
import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import *
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
# sys.setrecursionlimit(int(pow(10, 2)))
#sys.stdin = open("input.txt", "r")
# sys.stdout = open("output.txt", "w")
mod = int(pow(10, 9) + 7)
mod2 = 998244353
def data(): return sys.stdin.readline().strip()
def out(*var, end="\n"): sys.stdout.write(' '.join(map(str, var))+end)
def l(): return list(sp())
def sl(): return list(ssp())
def sp(): return map(int, data().split())
def ssp(): return map(str, data().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]





# @lru_cache(None)
s=list(input())
A=[]
for i in range(len(s)):
    if(s[i]=="W"):
        A.append(i)
k=0
i=0
for x in A:
    k+=(x-i)
    i+=1
print(k)
Buggy code:
S = input().strip()

count = 0
suma = 0
for i in S:
  if i=="W":
    suma += count
  else:
    count += 1


Fixed code:
S = input().strip()

count = 0
suma = 0
for i in S:
  if i=="W":
    suma += count
  else:
    count += 1
print(suma)
Buggy code:
s = str(input())
n = len(s)
count = 0
max_W = 0

for i in range(n):
    if s[i] == 'W':
        count += i
        max_W = i

if max_W == s.count('W') - 1 or s.count('W') == 0 or s.count('W') == n:
    print(0)
    exit()

print(count)

Fixed code:
s = str(input())
n = len(s)
distance = 0
count = 0
max_W = 0

for i in range(n):
    if s[i] == 'W':
        distance += (i - count)
        count += 1
        max_W = i

if s.count('W') == 0 or s.count('W') == n:
    print(0)
    exit()

print(distance)
Buggy code:
# -*- coding: utf-8 -*-

s=input()

cnt=0
cum=0

for i in range(len(s)):
    if s[i]=='W':
        cnt+=1
        cum+=i
print(cum-int((cnt+1)*cnt/2))


Fixed code:
# -*- coding: utf-8 -*-

s=input()

cnt=0
cum=0

for i in range(len(s)):
    if s[i]=='W':
        cnt+=1
        cum+=i
print(cum-int((cnt-1)*cnt/2))
Buggy code:
S = input()

count_white = 0
ans = [0] * len(S)

for i in range(len(S)):
    if S[i] == "W":
        if count_white == 0:
            ans[count_white] = i
            count_white += 1
        else:
            print(count_white)
            ans[count_white] = i - ans[count_white-1]
            count_white += 1
print(sum(ans))

Fixed code:
S = input()

count_white = 0
ans = [0] * len(S)

for i in range(len(S)):
    if S[i] == "W":
        ans[i] = i -count_white
        count_white += 1
print(sum(ans))
Buggy code:
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def LS(): return list(map(list, input().split()))
def S(): return list(input().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = 1e10

#solve
def solve():
    s = S()
    s = s[::-1]
    tmp = 0
    f = 0
    ans = 0
    for i in s:
        if i == "w":
            ans += tmp
            tmp = 0
            f = 1
        else:
            tmp += f
    print(ans+tmp)
    return


#main
if __name__ == '__main__':
    solve()


Fixed code:
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def LS(): return list(map(list, input().split()))
def S(): return list(input().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = 1e10

#solve
def solve():
    s = S()
    ans = 0
    w = 0
    for i, si in enumerate(s):
        if si == "W":
            ans += i-w
            w += 1
    print(ans)

    return


#main
if __name__ == '__main__':
    solve()
Buggy code:
import re

s = input()
a = [m.start() for m in re.finditer("W", s)]

ans = 0
for i, e in enumerate(a):
    ans += e - (i + 1)

print(ans)


Fixed code:
import re

s = input()
a = [m.start() for m in re.finditer("W", s)]

ans = 0
for i, e in enumerate(a):
    ans += e - i

print(ans)
Buggy code:
a,b,s=0,input(),0
for i in range(len(s)):a+=i*(s[i]=="W");b+=1
print(a-((b*(b-1))//2))

Fixed code:
a,s,b=0,input(),0
for i in range(len(s)):a+=i*(s[i]=="W");b+=(s[i]=="W")
print(a-((b*(b-1))//2))
Buggy code:
S = input()
white = 0
total = 0
for i in range len(S):
    if S[i] == "W":
        total += (i - white)
        white += 1
        
print(total)


Fixed code:
S = input()

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

print(total)
Buggy code:
s = list(input())

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

Fixed code:
s = list(input())
count = 0
ans = 0
for i in range(len(s)):
    if s[i] =="W":
        ans += i-count
        count +=1
print(ans)
Buggy code:
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)

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

num = 0
count = 0
for i in range(len(txt)):
    if txt_list[i] == 'W':
        count += i-num 
        num += 1

print(txt_list, count)

Fixed code:
txt = input()
txt_list = list(txt)

num = 0
count = 0
for i in range(len(txt)):
    if txt_list[i] == 'W':
        count += i-num 
        num += 1

print(count)
Buggy code:
"""AtCoder"""

S = input()

ans = 1
tmp = 1

for i in range(len(S)):
    if S[i] == 'W':
        ans += i - tmp + 1
        tmp = i + 1

print(ans)


Fixed code:
"""AtCoder"""

S = input()

ans = 0
tmp = 0

for i in range(len(S)):
    if S[i] == 'W':
        ans += i - tmp
        tmp += 1

print(ans)