Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
C = list(input())
import copy
D = []
flag = 0
ans = 0

for p in range(N):
    if C[p] == "R":
        D += ["0"]
    else:
        D += ["1"]



def change(x,y):
    global ans
    hoge = copy.deepcopy(D[x])
    D[x] = D[y]
    D[y] = hoge
    ans += 1

def color(x):
    global ans
    ans += 1
    if D[x] == "0":
        D[x] = "1"
    elif D[x] == "1":
        D[x] = "0"

while flag == 0:

    for r in range(N):
        if int("".join(D),2) == 2**r-1:
            flag = 1

    if flag == 0:
        for q in range(N):
            if D[q] == "1":
                for s in range(N):
                    if D[N-s-1] =="0" :
                        if q < N-s-1:
                            change(q,N-s-1)
                        break
            else:
                continue
            break
print(ans)


Fixed submission:
N = int(input())
C = list(input())
import copy
D = []
flag = 0
ans = 0
keisan = 0

for p in range(N):
    if C[p] == "R":
        D += ["0"]
    else:
        D += ["1"]



def change(x,y):
    global ans
    hoge = copy.deepcopy(D[x])
    D[x] = D[y]
    D[y] = hoge
    ans += 1

def color(x):
    global ans
    ans += 1
    if D[x] == "0":
        D[x] = "1"
    elif D[x] == "1":
        D[x] = "0"

zero = D.count("0")
ichi = D.count("1")

for p in range(zero):
    if D[p] == "1":
        ans += 1


"""
while flag == 0:

    for r in range(N):
        if int("".join(D),2) == 2**r-1:
            flag = 1

    if flag == 0:
        for q in range(N):
            if D[q] == "1":
                for s in range(N):
                    keisan += 1
                    if D[N-s-1] =="0" :
                        if q < N-s-1:
                            change(q,N-s-1)
                        break
            else:
                continue
            break
"""
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
C = list(input())
import copy
D = []
flag = 0
ans = 0

for p in range(N):
    if C[p] == "R":
        D += ["0"]
    else:
        D += ["1"]



def change(x,y):
    global ans
    hoge = copy.deepcopy(D[x])
    D[x] = D[y]
    D[y] = hoge
    ans += 1

def color(x):
    global ans
    ans += 1
    if D[x] == "0":
        D[x] = "1"
    elif D[x] == "1":
        D[x] = "0"

while flag == 0:
    for q in range(N):
        if D[q] == "1":
            for s in range(N):
                if D[N-s-1] =="0" :
                    if q < N-s-1:
                        change(q,N-s-1)
                    break
        else:
            continue
        break

    for r in range(N):
        if int("".join(D),2) == 2**r-1:
            flag = 1

print(ans)


Fixed submission:
N = int(input())
C = list(input())
import copy
D = []
flag = 0
ans = 0
keisan = 0

for p in range(N):
    if C[p] == "R":
        D += ["0"]
    else:
        D += ["1"]



def change(x,y):
    global ans
    hoge = copy.deepcopy(D[x])
    D[x] = D[y]
    D[y] = hoge
    ans += 1

def color(x):
    global ans
    ans += 1
    if D[x] == "0":
        D[x] = "1"
    elif D[x] == "1":
        D[x] = "0"

zero = D.count("0")
ichi = D.count("1")

for p in range(zero):
    if D[p] == "1":
        ans += 1


"""
while flag == 0:

    for r in range(N):
        if int("".join(D),2) == 2**r-1:
            flag = 1

    if flag == 0:
        for q in range(N):
            if D[q] == "1":
                for s in range(N):
                    keisan += 1
                    if D[N-s-1] =="0" :
                        if q < N-s-1:
                            change(q,N-s-1)
                        break
            else:
                continue
            break
"""
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
C = list(input())
import copy
D = []
flag = 0
ans = 0

for p in range(N):
    if C[p] == "R":
        D += ["0"]
    else:
        D += ["1"]



def change(x,y):
    global ans
    hoge = copy.deepcopy(D[x])
    D[x] = D[y]
    D[y] = hoge
    ans += 1

def color(x):
    global ans
    ans += 1
    if D[x] == "0":
        D[x] = "1"
    elif D[x] == "1":
        D[x] = "0"

while flag == 0:
    for q in range(N):
        if D[q] == "1":
            for s in range(N):
                if D[N-s-1] =="0" and q < N-s-1:
                    change(q,N-s-1)
                    break
                
    for r in range(N):
        if int("".join(D),2) == 2**r-1:
            flag = 1

print(ans)


Fixed submission:
N = int(input())
C = list(input())
import copy
D = []
flag = 0
ans = 0
keisan = 0

for p in range(N):
    if C[p] == "R":
        D += ["0"]
    else:
        D += ["1"]



def change(x,y):
    global ans
    hoge = copy.deepcopy(D[x])
    D[x] = D[y]
    D[y] = hoge
    ans += 1

def color(x):
    global ans
    ans += 1
    if D[x] == "0":
        D[x] = "1"
    elif D[x] == "1":
        D[x] = "0"

zero = D.count("0")
ichi = D.count("1")

for p in range(zero):
    if D[p] == "1":
        ans += 1


"""
while flag == 0:

    for r in range(N):
        if int("".join(D),2) == 2**r-1:
            flag = 1

    if flag == 0:
        for q in range(N):
            if D[q] == "1":
                for s in range(N):
                    keisan += 1
                    if D[N-s-1] =="0" :
                        if q < N-s-1:
                            change(q,N-s-1)
                        break
            else:
                continue
            break
"""
print(ans)