Buggy python submission (verdict: Runtime Error):
def checkFunction(c):
    count = 0

    while c[-1] == 'W':
        c = c[:-1]
    while True:
        # print(count, c)
        if not ('WR' in c):
            return count
        while c[0] == 'R':
            c = c[1:]
        if c.index('R') == len(c) - 1:
            return count + 1
        else:
            c = c.replace('WR', 'RR',1)[:-1]
            count += 1

N = int(input())
c= input()

print(checkFunction(c))



Fixed submission:

def check(N, c):
    RinRight = c.count('R')
    WinLeft = 0
    r = RinRight
    for i in range(N):
        if c[i] == 'R':
            RinRight -= 1
        else: # c[i] == 'W'
            WinLeft +=1
        r = min(r, max(RinRight,WinLeft))

    return r


N = int(input())
c= input()
print(check(N,c))

Buggy python submission (verdict: Runtime Error):
def checkFunction(c):
    count = 0

    while True:
        print(count, c)
        if not ('WR' in c):
            return count
        while c[0] == 'R':
            c = c[1:]
        while c[-1] == 'W':
            c = c[:-1]

        if c.index('R') == len(c) - 1:
            return count + 1
        else:
            c = c.replace('WR', 'RR',1)[:-1]
            count += 1

N = int(input())
c= input()

print(checkFunction(c))


Fixed submission:

def check(N, c):
    RinRight = c.count('R')
    WinLeft = 0
    r = RinRight
    for i in range(N):
        if c[i] == 'R':
            RinRight -= 1
        else: # c[i] == 'W'
            WinLeft +=1
        r = min(r, max(RinRight,WinLeft))

    return r


N = int(input())
c= input()
print(check(N,c))

Buggy python submission (verdict: Runtime Error):
def checkFunction(c):
    
    if not ('WR' in c):
        return 0
    while c[0] == 'R':
        c = c[1:]
    while c[-1] == 'W':
        c = c[:-1]

    if c.index('R') + 1 != len(c):
        c2 = c.replace('WR', 'RR',1)[:-1]
        return checkFunction(c2) + 1
    return 1


N = int(input())
c= input()

print(checkFunction(c))


Fixed submission:

def check(N, c):
    RinRight = c.count('R')
    WinLeft = 0
    r = RinRight
    for i in range(N):
        if c[i] == 'R':
            RinRight -= 1
        else: # c[i] == 'W'
            WinLeft +=1
        r = min(r, max(RinRight,WinLeft))

    return r


N = int(input())
c= input()
print(check(N,c))

Buggy python submission (verdict: Runtime Error):
def checkFunction(c):
    
    if (not 'WR' in c):
        return 0
    while True:
        if c[0] == 'R':
            c = c[1:]
        else:
            break
    while True:
        if c[-1] == 'W':
            c = c[:-1]
        else:
            break

    if c.index('R') + 1 != len(c):
        c2 = c.replace('WR', 'RR',1)[:-1]
        return checkFunction(c2) + 1
    return 1


N = int(input())
c= input()

print(checkFunction(c))


Fixed submission:

def check(N, c):
    RinRight = c.count('R')
    WinLeft = 0
    r = RinRight
    for i in range(N):
        if c[i] == 'R':
            RinRight -= 1
        else: # c[i] == 'W'
            WinLeft +=1
        r = min(r, max(RinRight,WinLeft))

    return r


N = int(input())
c= input()
print(check(N,c))

Buggy python submission (verdict: Runtime Error):
def checkFunction(c):
    
    if (not 'WR' in c):
        return 0
    while True:
        if c[0] == 'R':
            c = c[1:]
        else:
            break
    while True:
        if c[-1] == 'W':
            c = c[:-1]
        else:
            break

    if c.index('R') + 1 != len(c):
        c2 = c.replace('WR', 'RR',1)[:-1]
        return checkFunction(c2) + 1
    return 1


N = int(input())
c= input()

print(checkFunction(c))



Fixed submission:

def check(N, c):
    RinRight = c.count('R')
    WinLeft = 0
    r = RinRight
    for i in range(N):
        if c[i] == 'R':
            RinRight -= 1
        else: # c[i] == 'W'
            WinLeft +=1
        r = min(r, max(RinRight,WinLeft))

    return r


N = int(input())
c= input()
print(check(N,c))

Buggy python submission (verdict: Runtime Error):
def checkFunction(c):
    # print(c)
    while True:
        if c[0] == 'R':
            c = c[1:]
        else:
            break
    while True:
        if c[-1] == 'W':
            c = c[:-1]
        else:
            break
    if (not 'WR' in c):
        return 0
    if c.index('R') + 1 != len(c):
        c2 = c.replace('WR', 'RR',1)[:-1]
        return checkFunction(c2) + 1
    return 1


N = int(input())
c= input()

print(checkFunction(c))


Fixed submission:

def check(N, c):
    RinRight = c.count('R')
    WinLeft = 0
    r = RinRight
    for i in range(N):
        if c[i] == 'R':
            RinRight -= 1
        else: # c[i] == 'W'
            WinLeft +=1
        r = min(r, max(RinRight,WinLeft))

    return r


N = int(input())
c= input()
print(check(N,c))

Buggy python submission (verdict: Runtime Error):
import re

def checkFunction(c):
    # print(c)
    c = re.sub('^R+','',c)
    if (not 'WR' in c):
        return 0
    if c.index('R') + 1 != len(c):
        c2 = c.replace('WR', 'RR',1)[:-1]
        return checkFunction(c2) + 1
    return 1


N = int(input())
c= input()

print(checkFunction(c))


Fixed submission:

def check(N, c):
    RinRight = c.count('R')
    WinLeft = 0
    r = RinRight
    for i in range(N):
        if c[i] == 'R':
            RinRight -= 1
        else: # c[i] == 'W'
            WinLeft +=1
        r = min(r, max(RinRight,WinLeft))

    return r


N = int(input())
c= input()
print(check(N,c))

Buggy python submission (verdict: Time Limit Exceeded):
import re

def checkFunction(c):
    # print(c)
    c = re.sub('W+$','',c)
    c = re.sub('^R+','',c)
    if (not 'WR' in c):
        return 0
    if c.index('R') + 1 != len(c):
        c2 = c.replace('WR', 'RR',1)[:-1]
        return checkFunction(c2) + 1
    return 1


N = int(input())
c= input()

print(checkFunction(c))

Fixed submission:

def check(N, c):
    RinRight = c.count('R')
    WinLeft = 0
    r = RinRight
    for i in range(N):
        if c[i] == 'R':
            RinRight -= 1
        else: # c[i] == 'W'
            WinLeft +=1
        r = min(r, max(RinRight,WinLeft))

    return r


N = int(input())
c= input()
print(check(N,c))

Buggy python submission (verdict: Time Limit Exceeded):
import re

def checkFunction(c):
    # print(c)
    c = re.sub('W+$','',c)
    c = re.sub('^R+','',c)
    if (not 'WR' in c):
        return 0
    if c.index('WR') + 2 != len(c):
        c2 = c.replace('WR', 'RR',1)[:-1]
        return checkFunction(c2) + 1
    return 1


N = int(input())
c= input()

print(checkFunction(c))


Fixed submission:

def check(N, c):
    RinRight = c.count('R')
    WinLeft = 0
    r = RinRight
    for i in range(N):
        if c[i] == 'R':
            RinRight -= 1
        else: # c[i] == 'W'
            WinLeft +=1
        r = min(r, max(RinRight,WinLeft))

    return r


N = int(input())
c= input()
print(check(N,c))

Buggy python submission (verdict: Time Limit Exceeded):
import re

def checkFunction(c):
    c = re.sub('W+$','',c)
    if (not 'WR' in c):
        return 0
    if c.index('WR') + 2 != len(c):
        c2 = c.replace('WR', 'RR',1)[:-1]
        return checkFunction(c2) + 1
    return 1

N = int(input())
c= input()

print(checkFunction(c))

Fixed submission:

def check(N, c):
    RinRight = c.count('R')
    WinLeft = 0
    r = RinRight
    for i in range(N):
        if c[i] == 'R':
            RinRight -= 1
        else: # c[i] == 'W'
            WinLeft +=1
        r = min(r, max(RinRight,WinLeft))

    return r


N = int(input())
c= input()
print(check(N,c))

Buggy python submission (verdict: Runtime Error):
import re

def checkFunction(c):
    print(c)
    c = re.sub('W+$','',c)
    if (not 'WR' in c):
        return 0
    if c.index('WR') + 2 != len(c):
        c2 = c.replace('WR', 'RR',1)[:-1]
        return checkFunction(c2) + 1
    return 1


N = int(input())
c= input()

print(checkFunction(c))

Fixed submission:

def check(N, c):
    RinRight = c.count('R')
    WinLeft = 0
    r = RinRight
    for i in range(N):
        if c[i] == 'R':
            RinRight -= 1
        else: # c[i] == 'W'
            WinLeft +=1
        r = min(r, max(RinRight,WinLeft))

    return r


N = int(input())
c= input()
print(check(N,c))