ZhenlongDai/ACPR huggingface dataset:
Problem: p02597
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
import sys
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0

n = int(readline())

s = readline().rstrip().decode('utf-8')


res = s.count("R")
ans = min(res,len(s)-res)
count = 0
res = 0
for i in range(n-1,-1,-1):
    if count and s[i] == "W":
        res += count
        count = 0
    elif s[i] == "R":
        count += 1

ans = min(ans,res)

print(ans)

Failing test case input:
8
RWWRWRRW

Expected output:
2


Actual output:
3


Fixed submission (verdict: Accepted):
import sys
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0

n = int(readline())

s = readline().rstrip().decode('utf-8')

l = 0
r = n-1
ans = 0
while l < r:
    if s[l] == "W" and s[r] == "R":
        ans += 1
        l += 1
        r -= 1
    if s[l] == "R":
        l += 1
    if s[r] == "W":
        r -= 1

print(ans)

Problem: p02597
Buggy submission (Python (3.8.2), verdict: Wrong Answer):









N = int(input())
S = input()




def calculate(n, s):
    arr = list(s)

    RNum = arr.count("R")

    leftW = 0
    rightR = RNum

    result = []
    for i in range(n):
        if arr[i] == "R":
            rightR -= 1
        if arr[i] == "W":
            leftW += 1

        if (leftW == 0) and arr[i] == "R":
            result.append(0)
            continue

        if (rightR == 0) and arr[i] == "W":
            result.append(0)
            continue

        result.append(max(leftW, rightR))

    print(min(result))


calculate(N, S)


Failing test case input:
8
RWWQWWRR

Expected output:
2


Actual output:
0


Fixed submission (verdict: Accepted):









N = int(input())
S = input()

def calculate(n, s):
    arr = list(s)

    wNum = arr.count("W")
    RNum = arr.count("R")

    if wNum == 0 or RNum == 0:
        print(0)
        return

    leftW = 0
    rightR = RNum



    result = []
    for i in range(n):
        if arr[i] == "R":
            rightR -= 1
        if arr[i] == "W":
            leftW += 1

        result.append(max(leftW, rightR))

    print(min(result))


calculate(N, S)

Problem: p02597
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n = int(input())
clist = input()

rs = clist.count("R")
ws = clist.count("W")

sort_rs = rs - clist[0:rs-1].count("R")

ans = 10**7

if rs < ans:
    ans = rs
if ws < ans:
    ans = ws
if sort_rs < ans:
    ans = sort_rs
print(ans)

Failing test case input:
8
RRRRVWWW

Expected output:
0


Actual output:
1


Fixed submission (verdict: Accepted):
n = int(input())
clist = input()

rs = clist.count("R")
ws = clist.count("W")

sort_rs = rs - clist[0:rs].count("R")
ans = rs
if ws < ans:
    ans = ws

if sort_rs < ans:
    ans = sort_rs
print(ans)
Problem: p02597
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n = int(input())
c = list(input())

r = 0
cnt = 0
for i in range(n):
    if c[i] == "R" :
        r += 1
    else :
        cnt = i
        break

print(c.count("R")-r)


Failing test case input:
8
WRRWWRRW

Expected output:
2


Actual output:
4


Fixed submission (verdict: Accepted):
n = int(input())
c = list(input())
w = 0
r = c.count("R")
ans = r
for i in range(n) :
    if c[i] == "W" :
        w += 1
    else :
        r -= 1
    if ans > max(w,r) :
        ans = max(w,r)

print(ans)

Problem: p02597
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n=int(input())
c=list(input())
l,r=0,n-1
ans=0
while l<r:
    while c[l]!='W':
        l+=1
        if l>n-1:
            break
    while c[r]!='R' or r>=0:
        r-=1
        if r<0:
            break
    if l<r:
        ans+=1
        l+=1
        r-=1
print(ans)

Failing test case input:
8
RWRRVRWW

Expected output:
1


Actual output:
0


Fixed submission (verdict: Accepted):
n=int(input())
c=list(input())
l,r=0,n-1
ans=0
while l<r:
    while c[l]!='W':
        l+=1
        if l>n-1:
            break
    while c[r]!='R':
        r-=1
        if r<0:
            break
    if l<r:
        ans+=1
        l+=1
        r-=1
print(ans)

Problem: p02597
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n = int(input())
c_str = input()
c_list = list(c_str)

cnt = 0
flag = 1
w_pos = 0
r_pos = 0
range_start = 0
range_end = n

while flag:
    for i in range(range_start, range_end):
        if c_list[i] == "W":
            w_pos = i
            range_start = i
            break
        if i == n-1:
            w_pos = n-1 
    for j in reversed(range(range_start, range_end)):
      if c_list[j] == "R":
        r_pos = j
        range_end = j
        break
    if w_pos < r_pos:
        c_list[w_pos] = "R"
        c_list[r_pos] = "W"
        cnt += 1
    else:
      flag = 0

print(cnt)

Failing test case input:
8
RWWRXRWR

Expected output:
2


Actual output:
3


Fixed submission (verdict: Accepted):
n = int(input())
c_str = input()
c_list = list(c_str)

cnt = 0
flag = 1
w_pos = 0
r_pos = 0
range_start = 0
range_end = n

while flag:
    for i in range(range_start, range_end):
        if c_list[i] == "W":
            w_pos = i
            range_start = i
            break
        if i == range_end-1:
            w_pos = range_end-1 
    for j in reversed(range(range_start, range_end)):
      if c_list[j] == "R":
        r_pos = j
        range_end = j
        break
      if j == range_start:
        r_pos = range_start 
    if w_pos < r_pos:
        c_list[w_pos] = "R"
        c_list[r_pos] = "W"
        cnt += 1
    else:
      flag = 0

print(cnt)
Problem: p02597
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
def solve(ls):
    n = len(ls)
    ls = [int(x == 'R') for x in ls]  
    num_w = sum(ls)
    num_r = n - num_w
    if num_r == 0:
        return 0
    
    left_w = 0
    right_r = num_r
    for i in range(n):
        if ls[i] == 0:
            left_w += 1
        else:
            right_r -= 1
        if left_w == right_r:
            return right_r


def main(istr, ostr):
    n, = list(map(int, istr.readline().strip().split()))
    s = istr.readline().strip()
    result = solve(s)
    print(result, file=ostr)


if __name__ == "__main__":
    import sys

    main(sys.stdin, sys.stdout)


Failing test case input:
4
RUWW

Expected output:
0


Actual output:
2


Fixed submission (verdict: Accepted):



def solve(ls):
    n = len(ls)
    num_w = len([x for x in ls if x == "W"])
    num_r = n - num_w
    left_w = 0
    right_r = num_r
    result = num_r
    for i in range(n):
        if ls[i] == 'W':
            left_w += 1
        else:
            right_r -= 1
        result = min(result, max(left_w, right_r))
    return result


def main(istr, ostr):
    (n,) = list(map(int, istr.readline().strip().split()))
    s = istr.readline().strip()
    result = solve(s)
    print(result, file=ostr)


if __name__ == "__main__":
    import sys

    main(sys.stdin, sys.stdout)

Problem: p02597
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
import sys
N = int(input())
c = input()
ans = 0
exchange = 0
for i in range(N):
    if c[i] == "W":
        exchange = i
        break
else:
    print(0)
    sys.exit()

for i in range(N):
    
    
    
    if N-i < exchange:
        if c[-(i+1)] =="R":
            
            
            
            
            c = c[:exchange]+"R"+c[exchange+1:]
            print("newc=",c)
            c = c[:-(i+1)]+"W"+c[N-i:]
            
            ans += 1
            for k in range(exchange+1,N):
                if c[k] == "W":
                    exchange = k
                    break
            else:
                break
    else:
        break
print(ans)

Failing test case input:
8
WRWWYRRR

Expected output:
3


Actual output:
0


Fixed submission (verdict: Accepted):
import sys
N = int(input())
c = input()
ans = 0
exchange = 0
for i in range(N):
    if c[i] == "W":
        exchange = i
        break
else:
    print(0)
    sys.exit()

for i in range(N):
    if N-i > exchange:
        if c[-(i+1)] =="R":
            
            
            
            
            
            
            
            
            ans += 1
            for k in range(exchange+1,N-(i+1)):
                if c[k] == "W":
                    exchange = k
                    break
            else:
                break
    else:
        break
print(ans)
Problem: p02597
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
import itertools
import functools
import math
from collections import Counter
from itertools import combinations
import re

def main_chk():
    N=int(input())
    C=input()

    chk = N - 1
    cnt = 0

    for i in range(N):
        if C[i] == 'W':
            for x in reversed(range(i,chk+1)):
                if C[x] == 'R':
                    chk = x
                    break
            if chk <= i:
                break
            else:
                cnt = cnt + 1
                chk = chk - 1

    print(cnt)

main_chk()


Failing test case input:
8
WWRRWWRR

Expected output:
2


Actual output:
3


Fixed submission (verdict: Accepted):
import itertools
import functools
import math
from collections import Counter
from itertools import combinations
import re

def main_chk():
    N=int(input())
    C=input()

    chk = N - 1
    cnt = 0

    for i in range(N):
        if C[i] == 'W':
            p = chk
            chk = i
            for x in range(N-i):
                if C[p-x] == 'R':
                    chk = p - x
                    break
            if chk <= i:
                break
            else:
                cnt = cnt + 1
                chk = chk - 1
                if chk <= i + 1:
                    break

    print(cnt)

main_chk()

Problem: p02597
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
import itertools
import functools
import math
from collections import Counter
from itertools import combinations
import re

def main_chk():
    N=int(input())
    C=input()

    chk = N - 1
    cnt = 0

    for i in range(N):
        if C[i] == 'W':
            for x in reversed(range(i+1,chk+1)):
                if C[x] == 'R':
                    chk = x
                    break
            if chk <= i:
                break
            else:
                cnt = cnt + 1
                chk = chk - 1

    print(cnt)

main_chk()


Failing test case input:
8
RWWQWWRR

Expected output:
2


Actual output:
3


Fixed submission (verdict: Accepted):
import itertools
import functools
import math
from collections import Counter
from itertools import combinations
import re

def main_chk():
    N=int(input())
    C=input()

    chk = N - 1
    cnt = 0

    for i in range(N):
        if C[i] == 'W':
            p = chk
            chk = i
            for x in range(N-i):
                if C[p-x] == 'R':
                    chk = p - x
                    break
            if chk <= i:
                break
            else:
                cnt = cnt + 1
                chk = chk - 1
                if chk <= i + 1:
                    break

    print(cnt)

main_chk()
Problem: p02597
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
N=int(input())
C=input()
from collections import Counter
count=Counter(C)

countR=count["R"]
countW=count["W"]
missR=0
missW=0
for i in range(N):
    now=C[i]
    if now=="W" and i<N-countW:
        missW+=1
    if now=="R" and i>=N-countR:
        missR+=1

X=min(missW, missR)

ans=min(missW, missR)+abs(missR-missW)

print(ans)


Failing test case input:
2
RR

Expected output:
0

Actual output:
2


Fixed submission (verdict: Accepted):
N=int(input())
C=input()
from collections import Counter
count=Counter(C)

countR=count["R"]
countW=count["W"]
missR=0
missW=0
for i in range(N):
    now=C[i]
    if now=="W" and i<N-countW:
        missW+=1
    if now=="R" and i>countR:
        missR+=1

X=min(missW, missR)

ans=min(missW, missR)+abs(missR-missW)

print(ans)

Problem: p02597
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
from collections import Counter
import sys
n = int(input())
c = input()
s = Counter(c)
if s['W'] == 0 or s['R'] == 0 or c.index('R') == 0 and c.index('W') == s['R']:
  print('0')
  sys.exit()
r = s['R']
las_pos=0
count = 0
for i, v in enumerate(c):
  if v == 'R':
    if i - las_pos < r:
      r = r - (i - las_pos + 1)
      count += (i - las_pos)
      las_pos = i
    else:
      count += r
      break
print(count)

Failing test case input:
8
RWRRUWRW

Expected output:
1


Actual output:
2


Fixed submission (verdict: Accepted):
import sys
from collections import Counter
n = int(input())
c = list(input())
s = Counter(c)
if s['R'] == 0 or s['W'] == 0:
  print('0')
  sys.exit()
pos_w=0
pos_r=n-1
count = 0
for i in range(pos_w, n):
  if c[i] != 'W':
    continue
  pos_w = i
  for j in range(pos_r, -1, -1):
    if c[j] != 'R':
      continue
    pos_r = j
    if pos_w > pos_r:
      print(count)
      sys.exit()
    c[i] = 'R'
    c[j] = 'W'
    count += 1
    break

Problem: p02597
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n = int(input())
c = input()

wcount = c.count('R')
count = 0

for i in range(n):
    if c[i] == 'W' and i >= wcount:
        count += 1
print(count)


Failing test case input:
8
WRWRVWRR

Expected output:
2


Actual output:
1


Fixed submission (verdict: Accepted):
n = int(input())
c = input()

count = c.count('R')
ans = 0

for i in range(n):
    if c[i] == 'R' and i >= count:
        ans += 1
print(ans)
Problem: p02597
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n = int(input())
c_str = input()
c_list = list(c_str)

cnt = 0
flag = 1
w_pos = 0
r_pos = 0
range_start = 0
range_end = n

while flag:
    for i in range(range_start, range_end):
        if c_list[i] == "W":
            w_pos = i
            range_start = i
            break
        if i == range_end-1:
            w_pos = range_end-1 
    for j in reversed(range(range_start, range_end)):
      if c_list[j] == "R":
        r_pos = j
        range_end = j
        break
      if j == range_start-1:
        r_pos = range_start-1 
    if w_pos < r_pos:
        c_list[w_pos] = "R"
        c_list[r_pos] = "W"
        cnt += 1
    else:
      flag = 0

print(cnt)

Failing test case input:
8
RRWRWWWR

Expected output:
1


Actual output:
4


Fixed submission (verdict: Accepted):
n = int(input())
c_str = input()
c_list = list(c_str)

cnt = 0
flag = 1
w_pos = 0
r_pos = 0
range_start = 0
range_end = n

while flag:
    for i in range(range_start, range_end):
        if c_list[i] == "W":
            w_pos = i
            range_start = i
            break
        if i == range_end-1:
            w_pos = range_end-1 
    for j in reversed(range(range_start, range_end)):
      if c_list[j] == "R":
        r_pos = j
        range_end = j
        break
      if j == range_start:
        r_pos = range_start 
    if w_pos < r_pos:
        c_list[w_pos] = "R"
        c_list[r_pos] = "W"
        cnt += 1
    else:
      flag = 0

print(cnt)

Problem: p02597
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
N = int(input())

stones = input()
print(stones)
a = stones.count('W')
b = stones.count('R')

left_side =stones.count('W', 0, b)

print(left_side) 

Failing test case input:
8
RRWRWWWR

Expected output:
1


Actual output:
RRWRWWWR
1


Fixed submission (verdict: Accepted):
N = int(input())

stones = input()

a = stones.count('W')
b = stones.count('R')
 
left_side =stones.count('W', 0, b)
 
print(left_side)

Problem: p02597
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n = int(input())
c = list(input())
w = c.count('W')
w2 = c[:w].count('W')
print(w2)

Failing test case input:
8
WRWWYRRR

Expected output:
3


Actual output:
2


Fixed submission (verdict: Accepted):
n = int(input())
c = list(input())
r = c.count('R')
r2 = c[:r].count('R')
print(r - r2)

Problem: p02597
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
s = input()
R_num = s.count("R")
s[:R_num].count("W")


Failing test case input:
8
RWRWWRWR

Expected output:
2


Actual output:

Fixed submission (verdict: Accepted):
s = input()
s = input()

R_num = s.count("R")
print(s[:R_num].count("W"))
Problem: p02597
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
def main():
    n = int(input())
    c = list(input())
    r = 0
    w = 0
    for i in range(n):
        if c[i] == "R":
            r += 1
        else:
            w += 1
    print(r, w)

    count = 0
    for i in range(r):
        if c[i] == "W":
            count += 1
    print(count)


if __name__ == '__main__':
    main()


Failing test case input:
8
WRWWYRRR

Expected output:
3


Actual output:
4 4
3


Fixed submission (verdict: Accepted):
def main():
    n = int(input())
    c = list(input())
    r = 0
    w = 0
    for i in range(n):
        if c[i] == "R":
            r += 1
        else:
            w += 1

    count = 0
    for i in range(r):
        if c[i] == "W":
            count += 1
    print(count)


if __name__ == '__main__':
    main()

Problem: p02597
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
import sys

def IS(): return sys.stdin.readline().rstrip()
def II(): return int(IS())
def MII(): return list(map(int, IS().split()))
from bisect import bisect_left
from collections import deque

def main():
    N = II()
    cc = list(IS())
    cc_rev = cc[::-1]
    cnt = 0
    indexs = []
    for i, c in enumerate(cc):
        if c == 'W':
            indexs.append(i)
    indexs = deque(indexs)
    if cc.count('W') == 0:
        print(0)
        return 0
    for i, c in enumerate(cc_rev):
        if c == 'R':
            if indexs:
                idx = indexs.popleft()
                if i >= idx:
                    cc[idx] = 'R'
                    cnt += 1
    print(cnt)

if __name__ == '__main__':
    main()

Failing test case input:
4
RQWW

Expected output:
0


Actual output:
1


Fixed submission (verdict: Accepted):
import sys

def IS(): return sys.stdin.readline().rstrip()
def II(): return int(IS())
def MII(): return list(map(int, IS().split()))
from bisect import bisect_left
from collections import deque

def main():
    n = II()
    cc = list(IS())
    cc_rev = cc[::-1]
    cnt = 0
    indexs = []
    for i, c in enumerate(cc):
        if c == 'W':
            indexs.append(i)
    indexs = deque(indexs)
    if cc.count('W') == 0:
        print(0)
        return 0
    
    for i, c in enumerate(cc_rev):
        if c == 'R':
            if indexs:
                idx = indexs.popleft()
                if idx < (n-i-1):
                    cc[idx] = 'R'
                    cnt += 1
    print(cnt)

if __name__ == '__main__':
    main()

Problem: p02597
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
N = int(input())
c = list(input())
w = c.count("W")
wr = c[w:].count("W")

print(w - wr)


Failing test case input:
8
WRWWYRRR

Expected output:
3


Actual output:
2


Fixed submission (verdict: Accepted):
N = int(input())
c = list(input())
w = c.count("W")
r = c.count("R")
wr = c[len(c) - w:].count("W")

print(min(r, w - wr))
Problem: p02597
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n = int(input())
c = list(input())

if 'R' not in c or 'W' not in c:
    print(0)
    exit()

left, right = 0, len(c) - 1
cnt = 0

while left < right:

    if left > 0 and c[left-1] == c[left+1] == 'R' and c[left] == 'W':
        c[left] = 'R'

    elif right < len(c) - 1 and c[right-1] == c[right+1] == 'W' and c[right] == 'R':
        c[right] = 'W'

    elif c[left] is 'W' and c[right] is 'R':
        c[left] = 'R'
        c[right] = 'W'
    else:
        left += 1
        right -= 1
        continue

    left += 1
    right -= 1

    cnt += 1


print(cnt)

Failing test case input:
8
WRWRVWRR

Expected output:
2


Actual output:
3


Fixed submission (verdict: Accepted):
n = int(input())
c = list(input())

if 'R' not in c or 'W' not in c:
    print(0)
    exit()

left, right = 0, len(c) - 1
cnt = 0

while left < right:

    if c[left] == c[right] == 'W':
        right -= 1
        continue

    elif c[right] == c[left] == 'R':
        left += 1
        continue

    elif c[left+1] == 'R' and c[left] == 'W':
        c[left] = 'R'
        left += 1

    elif  c[right-1] == 'W' and c[right] == 'R':
        c[right] = 'W'
        right -= 1

    elif c[left] is 'W' and c[right] is 'R':
        c[left] = 'R'
        c[right] = 'W'

    else:
        left += 1
        right -= 1
        continue

    left += 1
    right -= 1

    cnt += 1

print(cnt)

Problem: p02597
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n = input()
s = input()
L = 0
r = len(s)

cnt = 0
while True:
    L = s.find('W')
    if L == -1:
        break
    r = s.rfind('R')
    if r == -1:
        break

    s = s[L + 1:r]

    cnt += 1

if L != -1:
    cnt += L + 1

print(cnt)

Failing test case input:
8
WWRRWRRW

Expected output:
2


Actual output:
3


Fixed submission (verdict: Accepted):
n = input()
s = input()
L = 0
r = len(s)

cnt = 0
while True:
    L = s.find('W')
    if L == -1:
        break
    r = s.rfind('R')
    if r == -1:
        break

    if (L > r):
        break

    s = s[L + 1:r].lstrip('R').rstrip('W')

    cnt += 1

if L != -1 and L < r:
    cnt += L + 1

print(cnt)

Problem: p02597
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
N = int(input())
S = input()
A = int(S.count("R"))
if A == N:
  print(A)
  exit()
s = S[:A]
B = int(s.count("R"))
print(A-B)

Failing test case input:
2
RR

Expected output:
0

Actual output:
2


Fixed submission (verdict: Accepted):
N = int(input())
S = input()
A = int(S.count("R"))
if A == N:
  print(0)
  exit()
s = S[:A]
B = int(s.count("R"))
print(A-B)

Problem: p02597
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n = int(input())

c = list(input())

w_count = c.count("W")
r_count = c.count("R")

right_center = c[w_count:]
right_w_count = right_center.count("W")

print(w_count - right_w_count)


Failing test case input:
8
WRRWXWRR

Expected output:
2


Actual output:
1


Fixed submission (verdict: Accepted):
n = int(input())

c = list(input())

w_count = c.count("W")
r_count = c.count("R")

right_center = c[r_count:]
right_w_count = right_center.count("W")

print(w_count - right_w_count)
Problem: p02597
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n = int(input())
s = input()
res = 0
tem = s.find('WR')
if tem == -1:
    print(res)
else:
    i, j = 0, len(s)-1
    while i<=j:
        while i <= j and s[i] != 'W': i+=1
        while i <= j and s[j] != 'R':j -= 1
        if s[i] == 'W' and s[j] == 'R':
            res += 1
            i += 1
            j -= 1
    print(res)



Failing test case input:
8
WRRRWWWR

Expected output:
1


Actual output:
2


Fixed submission (verdict: Accepted):
n = int(input())
s = input()
res = 0
tem = s.find('WR')
if tem == -1:
    print(res)
else:
    i, j = 0, len(s)-1
    while i<j:
        while i < j and s[i] != 'W': i+=1
        while i < j and s[j] != 'R':j -= 1
        if s[i] == 'W' and s[j] == 'R':
            res += 1
            i += 1
            j -= 1
    print(res)

Problem: p02597
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n=int(input())
s=input()
l=[0]
for i in range(n):
    l.append(l[i]+(s[i]=="R"))
ans=n
print(l)
for i in range(n+1):
    ans=min(ans,abs(l[i]-i)+abs(l[-1]-l[i]))
    
    if i==l[-1]:
        ans=min(ans,abs(l[i]-i))
        
print(ans)

Failing test case input:
8
RWRWWRRW

Expected output:
2


Actual output:
[0, 1, 1, 2, 2, 2, 3, 4, 4]
2


Fixed submission (verdict: Accepted):
n=int(input())
s=input()
l=[0]
for i in range(n):
    l.append(l[i]+(s[i]=="R"))
ans=n

for i in range(n+1):
    ans=min(ans,abs(l[i]-i)+abs(l[-1]-l[i]))
    
    if i==l[-1]:
        ans=min(ans,abs(l[i]-i))
        
print(ans)

Problem: p02597
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
N = int(input())
c = list(input())
ans = 0
cnt = c.count("W")
ans = c[N-4:].count("R")
if cnt != 0:
    print(ans)
else:
    print(0)

Failing test case input:
4
RRSW

Expected output:
0


Actual output:
2


Fixed submission (verdict: Accepted):
N = int(input())
c = list(input())
ans = 0
cnt = c.count("W")
ans = c[N-cnt:].count("R")
if cnt != 0:
    print(ans)
else:
    print(0)

Problem: p02597
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
num = int(input())
stn = list(input())
num_W = stn.count('W')
num_R = stn.count('R')
cnt = 0

if num_W >= num_R:
    for i in range(num_R):
        if stn[i] == "W":
            cnt += 1

else:
    for i in range(num_W):
        if stn[-i] == "R":
            cnt += 1

print(cnt)

Failing test case input:
4
WRTR

Expected output:
1


Actual output:
0


Fixed submission (verdict: Accepted):
num = int(input())
stn = list(input())
num_W = stn.count('W')
num_R = stn.count('R')
cnt = 0

if num_W >= num_R:
    for i in range(num_R):
        if stn[i] == "W":
            cnt += 1

else:
    for i in range(num_W):
        if stn[-i-1] == "R":
            cnt += 1

print(cnt)
Problem: p02597
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
n = int(input())
a = input()
red = 0
for i in range(n):
  if a[i] == 'R':
    red += 1
ans = 0
for i in range(n-red):
  if a[i] == 'W':
    ans += 1
print(ans)

Failing test case input:
8
WRWSWRWR

Expected output:
2


Actual output:
3


Fixed submission (verdict: Accepted):
n = int(input())
a = input()
red = 0
for i in range(n):
  if a[i] == 'R':
    red += 1
ans = 0
for i in range(red):
  if a[i] == 'W':
    ans += 1
print(ans)

Problem: p02597
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
input()
s = input()

def find_cost(s):
    counter, i, j = 0, 0, len(s)-1
    while i < j:
        while s[i] != 'W' and i < j:
                i += 1
        while s[j] != 'R' and i < j:
                j -= 1
        s = list(s)
        s[i], s[j] = s[j], s[i]
        s = "".join(s)
        counter += 1
        i += 1
        j -= 1

    for i in range(0, len(s) - 2):
        if s[i] == 'W' and s[i + 1] == 'R':
            counter += 1

    print(counter)


find_cost(s)

Failing test case input:
4
RQWW

Expected output:
0


Actual output:
1


Fixed submission (verdict: Accepted):
input()
s = input()

def find_cost(s):
    counter, i, j = 0, 0, len(s)-1
    while i < j:
        while i < len(s) and s[i] != 'W':
                i += 1
        while j >= 0 and s[j] != 'R':
                j -= 1
        if i < j:
            
            s[i], s[j] = s[j], s[i]
            
            counter += 1
        i += 1
        j -= 1

    

    for i in range(0, len(s) - 2):
        if s[i] == 'W' and s[i + 1] == 'R':
            counter += 1

    print(counter)

s = list(s)
find_cost(s)

Problem: p02597
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
N = int(input())
A = list(input())
a = 0
B = []
for i in range(N):
    if A[i] == 'W':
        a += 1
    B.append(a)
if a >= N - a:
    ans = min(N - a, B[N - a])
else:
    ans = min(a, B[a])
print(ans)

Failing test case input:
8
RRWWWRRW

Expected output:
2


Actual output:
3


Fixed submission (verdict: Accepted):
N = int(input())
A = list(input())
a = 0
B = []
for i in range(N):
    if A[i] == 'W':
        a += 1
    B.append(a)
ans = min(B[N - a - 1], a, N - a)
print(ans)

Problem: p02597
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
N = int(input())

stones = input()
print(stones)
a = stones.count('W')
b = stones.count('R')

left_side =stones.count('W', 0, a)
print(left_side) 

Failing test case input:
8
WWRRWRWR

Expected output:
2


Actual output:
WWRRWRWR
2


Fixed submission (verdict: Accepted):
N = int(input())

stones = input()

a = stones.count('W')
b = stones.count('R')
 
left_side =stones.count('W', 0, b)
 
print(left_side)
Problem: p02597
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
num = int(input())
wr = str(input())

i_counts = []
r_num = wr.count("R")

for i in range(num):
  rw_count = r_num
  wr_count = 0
  if wr[i] == "W":
    wr_count += 1
  else:
    rw_count -= 1

  i_count = max(wr_count, rw_count)
  i_counts.append(i_count)

  ans = min(i_counts)

print(ans)

Failing test case input:
8
WRRRWWWR

Expected output:
1


Actual output:
3


Fixed submission (verdict: Accepted):
num = int(input())
wr = str(input())

r_num = wr.count("R")
i_counts = [r_num]
rw_count = r_num
wr_count = 0
for i in range(num):
  if wr[i] == "W":
    wr_count += 1
  else:
    rw_count -= 1
  i_count = max(wr_count, rw_count)
  i_counts.append(i_count)

ans = min(i_counts)

print(ans)

Problem: p02597
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
N=int(input())
A=input()
ans=0
lindex=0
rindex=N-1
flag=0
while(1):
    if lindex>=rindex:
        break
    if flag==0:
        if A[lindex]=="W":
            flag=1
        else:
            lindex+=1

    elif flag==1:
        if A[rindex]=="R":
            flag=2
        else:
            rindex-=1
    
    else:
        ans+=1
        flag=0
        lindex+=1
        rindex-=1
if flag==1:
    ans+=1
print(ans)

Failing test case input:
8
WRRRWWRW

Expected output:
1


Actual output:
2


Fixed submission (verdict: Accepted):
N=int(input())
A=input()
ans=0
lindex=0
rindex=N-1
flag=0
while(1):
    if lindex>=rindex:
        break
    if flag==0:
        if A[lindex]=="W":
            flag=1
        else:
            lindex+=1

    elif flag==1:
        if A[rindex]=="R":
            flag=2
        else:
            rindex-=1
    
    else:
        ans+=1
        flag=0
        lindex+=1
        rindex-=1


print(ans)

Problem: p02597
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):

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


print(c.count("R")-c[:2].count("R"))


Failing test case input:
8
WRWRWRRW

Expected output:
2


Actual output:
3


Fixed submission (verdict: Accepted):

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


print(c.count("R")-c[:c.count("R")].count("R"))

Problem: p02597
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
N = int(input())
c = input()

x =[0] * N

ww = 0
rr = 0
for i, cc in enumerate(c):
    if cc == "R":
        x[i] = 1
        rr += 1
    else:
        ww += 1

cmd = 0
for i in range(rr):
    if x[i] == 0:
        cmd += 1

for j in range(rr+1, len(x)):
    if x[i] == 1:
        cmd += 1

print(cmd)




Failing test case input:
8
RRWRVWRW

Expected output:
1


Actual output:
4


Fixed submission (verdict: Accepted):
N = int(input())
c = input()

x =[0] * N

ww = 0
rr = 0
for i, cc in enumerate(c):
    if cc == "R":
        x[i] = 1
        rr += 1
    else:
        ww += 1

cmd = 0
for i in range(rr):
    if x[i] == 0:
        cmd += 1

cmd2 = 0
for j in range(rr+1, len(x)):
    if x[j] == 1:
        cmd2 += 1


print(max(cmd, cmd2))
Problem: p02597
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
N = int(input())
S = list(input().strip())

l = 0
r = len(S)-1
ans = 0
while l < r:
    if S[l] == 'W' and S[r] == 'R':
        ans += 1
    l += 1
    r -= 1
    while l < len(S) and S[l] != 'W':
        l += 1
    while r >= 0 and S[r] != 'R':
        r -= 1

print(ans)

Failing test case input:
8
RRWWWWRR

Expected output:
2


Actual output:
1


Fixed submission (verdict: Accepted):
N = int(input())
S = list(input().strip())

l = 0
r = N-1
ans = 0
while l < r:
    if S[l] == 'W' and S[r] == 'R':
        ans += 1
        l += 1
        r -= 1
    while l < N and S[l] != 'W':
        l += 1
    while r >= 0 and S[r] != 'R':
        r -= 1

print(ans)

Problem: p02597
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n=int(input())
c=input()
r=c.count('R')
w=c.count('W')
rch=c[:r].count('W')
wch=c[r:].count('R')
print(min(rch,wch))
print(r,w,rch,wch)

Failing test case input:
8
WRWWRWRR

Expected output:
3

Actual output:
3
4 4 3 3


Fixed submission (verdict: Accepted):
n=int(input())
c=input()
r=c.count('R')
w=c.count('W')
rch=c[:r].count('W')
wch=c[r:].count('R')
print(min(rch,wch))

Problem: p02597
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n = int(input())
red = []
white = []
s = input()

for i in range(n):
    if s[i] == "R":
        red.append(i)
    else:
        white.append(i)

roop_min_num = min(len(red), len(white))

res = 0
for i in range(roop_min_num):
    if white[i] < red[-i]:
        res += 1
print(res)


Failing test case input:
4
WRUR

Expected output:
1


Actual output:
2


Fixed submission (verdict: Accepted):
n = int(input())
red = []
white = []
s = input()

for i in range(n):
    if s[i] == "R":
        red.append(i)
    else:
        white.append(i)

roop_min_num = min(len(red), len(white))

res = 0
for i in range(roop_min_num):
    if white[i] < red[-i - 1]:
        res += 1
print(res)

Problem: p02597
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
def solve():
    N = int(input())
    S = input()
    C = [c for c in S]

    left = 0
    right = len(C) -1
    while left < right and C[left] == 'R':
        left += 1
    while left < right and C[right] == 'W':
        right -= 1

    ans = 0
    while left < right:
        while left < right and C[left] == 'R':
            left += 1
        while left < right and C[right] == 'W':
            right -= 1
        C[left] = 'R'
        C[right] = 'W'
        ans += 1
        left += 1
        right -= 1
    print(ans)

if __name__ == "__main__":
    solve()

Failing test case input:
8
RRWRVWRW

Expected output:
1


Actual output:
2


Fixed submission (verdict: Accepted):
def solve():
    N = int(input())
    S = input()
    C = [c for c in S]

    left = 0
    right = len(C) -1
    ans = 0
    while left < right:
        while left < right and C[left] == 'R':
            left += 1
        while left < right and C[right] == 'W':
            right -= 1
        if left < right:
            C[left] = 'R'
            C[right] = 'W'
            ans += 1
            left += 1
            right -= 1
    print(ans)

if __name__ == "__main__":
    solve()
Problem: p02597
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
from collections import Counter
import sys
n = int(input())
c = input()
s = Counter(c)
if s['W'] == 0 or s['R'] == 0 or c.index('R') == 0 and c.index('W') == s['R']:
  print('0')
  sys.exit()
r = s['R']
las_pos=0
count = 0
for i, v in enumerate(c):
  if v == 'R':
    if i - las_pos <= r:
      r = r - (i - las_pos + 1)
      count += (i - las_pos)
      las_pos = i
    else:
      count += r
      break
  if r == 0:
    break
print(count)

Failing test case input:
4
RRUW

Expected output:
0


Actual output:
1


Fixed submission (verdict: Accepted):
import sys
from collections import Counter
n = int(input())
c = list(input())
s = Counter(c)
if s['R'] == 0 or s['W'] == 0:
  print('0')
  sys.exit()
pos_w=0
pos_r=n-1
count = 0
for i in range(pos_w, n):
  if c[i] != 'W':
    continue
  pos_w = i
  for j in range(pos_r, -1, -1):
    if c[j] != 'R':
      continue
    pos_r = j
    if pos_w > pos_r:
      print(count)
      sys.exit()
    c[i] = 'R'
    c[j] = 'W'
    count += 1
    break

Problem: p02597
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
N=int(input())
C=input()
from collections import Counter
count=Counter(C)

countR=count["R"]
countW=count["W"]
missR=0
missW=0
for i in range(N):
    now=C[i]
    if now=="W" and i>=N-countW:
        missW+=1
    if now=="R" and i<countR:
        missR+=1

X=min(missW, missR)
if X!=0:
    ans=min(missW, missR)+abs(missR-missW)
else:
    ans=0
print(ans)

Failing test case input:
8
WWWRRRRW

Expected output:
3


Actual output:
1


Fixed submission (verdict: Accepted):
N=int(input())
C=input()
from collections import Counter
count=Counter(C)

countR=count["R"]
countW=count["W"]
missR=0
missW=0
for i in range(N):
    now=C[i]
    if now=="W" and i<N-countW:
        missW+=1
    if now=="R" and i>countR:
        missR+=1

X=min(missW, missR)

ans=min(missW, missR)+abs(missR-missW)

print(ans)

Problem: p02597
Buggy submission (Python (3.8.2), verdict: Wrong Answer):







n = int(input())
c = input()

wcount = c.count("W")
rcount = c.count("R")
check = 0

num = min(wcount, rcount)

if wcount < rcount:
    for i in range(wcount):
        if c[i] == "R":
            check += 1

else:
    for i in range(n - rcount, n):
        if c[i] == "W":
            check += 1

print(num - check)


Failing test case input:
8
WRWWXRRR

Expected output:
3


Actual output:
2


Fixed submission (verdict: Accepted):







n = int(input())
c = input()

wcount = c.count("W")
rcount = c.count("R")
check = 0

num = min(wcount, rcount)

if rcount < wcount:
    for i in range(rcount):
        if c[i] == "R":
            check += 1

else:
    for i in range(n - wcount, n):
        if c[i] == "W":
            check += 1

print(num - check)
Problem: p02597
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n = input()
s = input()
L = 0
r = len(s)

cnt = 0
while True:
    L = s.find('W')
    if L == -1:
        break
    r = s.rfind('R')
    if r == -1:
        break

    if (L > r):
        break

    s = s[L + 1:r].lstrip('R').rstrip('W')

    cnt += 1

if L != -1 and L > r:
    cnt += L + 1

print(cnt)

Failing test case input:
4
RTWW

Expected output:
0


Actual output:
3


Fixed submission (verdict: Accepted):
n = input()
s = input()
L = 0
r = len(s)

cnt = 0
while True:
    L = s.find('W')
    if L == -1:
        break
    r = s.rfind('R')
    if r == -1:
        break

    if (L > r):
        break

    s = s[L + 1:r].lstrip('R').rstrip('W')

    cnt += 1

if L != -1 and L < r:
    cnt += L + 1

print(cnt)

Problem: p02597
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n = input()
s = input()
L = 0
r = len(s)

cnt = 0
while True:
    L = s.find('W')
    if L == -1:
        break
    r = s.rfind('R')
    if r == -1:
        break

    if (L > r):
        break

    s = s[L + 1:r].lstrip('R').rstrip('L')

    cnt += 1

if L != -1 and L > r:
    cnt += L + 1

print(cnt)

Failing test case input:
8
RRWRTWRW

Expected output:
1


Actual output:
3


Fixed submission (verdict: Accepted):
n = input()
s = input()
L = 0
r = len(s)

cnt = 0
while True:
    L = s.find('W')
    if L == -1:
        break
    r = s.rfind('R')
    if r == -1:
        break

    if (L > r):
        break

    s = s[L + 1:r].lstrip('R').rstrip('W')

    cnt += 1

if L != -1 and L < r:
    cnt += L + 1

print(cnt)

Problem: p02597
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n = int(input())
s = [_ for _ in input()]

l, r = 0, n-1
if not('R' in s):
    print(0)
    exit()

if not('W' in s):
    print('0')
    exit()

ans = 0
while 1:
    while s[l] == 'R':
        l += 1

    while s[r] == 'W' and l <= r:
        r -= 1

    s[l] = 'r'
    s[r] = 'w'
    l += 1
    r -= 1

    
    if l > r:
        if l == r:
            ans += 1
        break
    
    ans += 1
print(ans)



Failing test case input:
8
RRWWRWRW

Expected output:
2


Actual output:
1


Fixed submission (verdict: Accepted):
n = int(input())
s = [_ for _ in input()]

l, r = 0, n-1
if not('R' in s):
    print(0)
    exit()

if not('W' in s):
    print('0')
    exit()

ans = 0
while 1:
    while s[l] == "R":
        l += 1
    while s[r] == "W" and l != r:
        r -= 1

    if l != r:
        s[l], s[r] = s[r], s[l]
        ans += 1
        
    if l == r:
        break

print(ans)
Problem: p02597
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
def abc174d():
    n = int(input())
    s = input()
    cnt = s.count('R')
    if cnt == len(s):
        print(0)
        return
    start = 0
    while s[start] == 'R':
        start += 1
        cnt -= 1
    ans = cnt
    for i in range(start, cnt):
        if s[i] == 'R':
            ans -= 1
    print(ans)
abc174d()

Failing test case input:
8
RWWRWWRR

Expected output:
2


Actual output:
3


Fixed submission (verdict: Accepted):
def abc174d():
    n = int(input())
    s = input()
    cnt = s.count('R')
    if cnt == len(s):
        print(0)
        return
    start = 0
    while s[start] == 'R':
        start += 1
        cnt -= 1
    ans = cnt
    for i in range(start, start+cnt):
        if s[i] == 'R':
            ans -= 1
    print(ans)
abc174d()
Problem: p00027
Buggy submission (Python3, verdict: Wrong Answer):
lis=[0 for i in range(7)]
lis[0]="Wednesday"
lis[1]="Thursday"
lis[2]="Friday"
lis[3]="Saturday"
lis[4]="Sunday"
lis[5]="Monday"
lis[6]="Tuesday"
while 1:
    date=0
    x,y=map(int,input().split())
    if x!=0 and y!=0:
        for i in range(1,x):
            if i==4 or i==6 or i==9 or i==11:
                date=date+30
            elif i==2:
                date =date+29
            else:
                date=date+31
        print(date)
        k=(date+y)%7
        print(date+y)
        print(lis[k])
    else:
        break

Failing test case input:
5 1
1 7
0 0

Expected output:
Saturday
Wednesday


Actual output:
121
122
Saturday
0
7
Wednesday


Fixed submission (verdict: Accepted):
lis=[0 for i in range(7)]
lis[0]="Wednesday"
lis[1]="Thursday"
lis[2]="Friday"
lis[3]="Saturday"
lis[4]="Sunday"
lis[5]="Monday"
lis[6]="Tuesday"
while 1:
    date=0
    x,y=map(int,input().split())
    if x!=0 and y!=0:
        for i in range(1,x):
            if i==4 or i==6 or i==9 or i==11:
                date=date+30
            elif i==2:
                date =date+29
            else:
                date=date+31
        k=(date+y)%7
        print(lis[k])
    else:
        break

Problem: p00027
Buggy submission (Python3, verdict: Wrong Answer):
day = ['Wednes','Thurs','Fri','Satur','Sun','Mon','Tues']
month = [0,31,60,91,121,152,182,213,244,274,305,335]
m,d=map(int,input().split())
print(day[(month[m-1]+d)%7]+'day')


Failing test case input:
4 3
3 14
0 0

Expected output:
Saturday
Sunday


Actual output:
Saturday


Fixed submission (verdict: Accepted):
while 1:
	day = ['Wednes','Thurs','Fri','Satur','Sun','Mon','Tues']
	month = [0,31,60,91,121,152,182,213,244,274,305,335]
	m,d=map(int,input().split())
	if m == 0:
		break
	print(day[(month[m-1]+d)%7]+'day')

Problem: p00027
Buggy submission (Python3, verdict: Wrong Answer):
lis=[0 for i in range(7)]
lis[0]="Wednesday"
lis[1]="Thursday"
lis[2]="Friday"
lis[3]="Saturday"
lis[4]="Sunday"
lis[5]="Monday"
lis[6]="Tuesday"
while 1:
    date=0
    x,y=map(int,input().split())
    if x!=0 and y!=0:
        for i in range(1,x):
            if i==(4 or 6 or 9 or 11):
                date=date+30
            elif i==2:
                date =date+29
            else:
                date=date+31
        k=(date+y)%7
        print(lis[k])
    else:
        break

Failing test case input:
6 2
7 17
0 0

Expected output:
Wednesday
Saturday


Actual output:
Wednesday
Sunday


Fixed submission (verdict: Accepted):
lis=[0 for i in range(7)]
lis[0]="Wednesday"
lis[1]="Thursday"
lis[2]="Friday"
lis[3]="Saturday"
lis[4]="Sunday"
lis[5]="Monday"
lis[6]="Tuesday"
while 1:
    date=0
    x,y=map(int,input().split())
    if x!=0 and y!=0:
        for i in range(1,x):
            if i==4 or i==6 or i==9 or i==11:
                date=date+30
            elif i==2:
                date =date+29
            else:
                date=date+31
        k=(date+y)%7
        print(lis[k])
    else:
        break
Problem: p00027
Buggy submission (Python3, verdict: Wrong Answer):
lis=[0 for i in range(7)]
lis[0]="Wednesday"
lis[1]="Thursday"
lis[2]="Friday"
lis[3]="Saturday"
lis[4]="Sunday"
lis[5]="Monday"
lis[6]="Tuesday"
while 1:
    date=0
    x,y=map(int,input().split())
    if x!=0 and y!=0:
        for i in range(1,x):
            if x==1 or 3 or 5 or 7 or 8 or 10 or 12 :
                date += 31
            elif x==2:
                date +=29
            else:
                date+=30
        k=(date+y)%7
        print(lis[k])
    else:
        break

Failing test case input:
1 2
4 23
0 0

Expected output:
Friday
Friday


Actual output:
Friday
Sunday


Fixed submission (verdict: Accepted):
lis=[0 for i in range(7)]
lis[0]="Wednesday"
lis[1]="Thursday"
lis[2]="Friday"
lis[3]="Saturday"
lis[4]="Sunday"
lis[5]="Monday"
lis[6]="Tuesday"
while 1:
    date=0
    x,y=map(int,input().split())
    if x!=0 and y!=0:
        for i in range(1,x):
            if i==4 or i==6 or i==9 or i==11:
                date=date+30
            elif i==2:
                date =date+29
            else:
                date=date+31
        k=(date+y)%7
        print(lis[k])
    else:
        break

Problem: p00027
Buggy submission (Python3, verdict: Wrong Answer):
while 1:
	day = ['Wednes','Thurs','Fri','Satur','Sun','Mon','Tues']
	month = [0,31,60,91,121,152,182,213,244,274,305,335]
	try: m,d=map(int,input().split())
	except: break
	print(day[(month[m-1]+d)%7]+'day')


Failing test case input:
2 2
2 11
0 0

Expected output:
Monday
Wednesday


Actual output:
Monday
Wednesday
Tuesday


Fixed submission (verdict: Accepted):
while 1:
	day = ['Wednes','Thurs','Fri','Satur','Sun','Mon','Tues']
	month = [0,31,60,91,121,152,182,213,244,274,305,335]
	m,d=map(int,input().split())
	if m == 0:
		break
	print(day[(month[m-1]+d)%7]+'day')

Problem: p00027
Buggy submission (Python3, verdict: Wrong Answer):
import datetime

date_list = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]

while True:
    m, d = map(int, input().split())
    if m == 0 and d == 0:
        break
    print(date_list[datetime.date(204, m, d).weekday()])



Failing test case input:
2 1
1 7
0 0

Expected output:
Sunday
Wednesday


Actual output:
Wednesday
Saturday


Fixed submission (verdict: Accepted):
import datetime

date_list = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]

while True:
    m, d = map(int, input().split())
    if m == 0 and d == 0:
        break
    print(date_list[datetime.date(2004, m, d).weekday()])
Problem: p00027
Buggy submission (Python3, verdict: Wrong Answer):
from datetime import date
week=["Monday","Trueday","Wednesday","Thursday","Friday","Saturday","Sunday"]
while True:
    a,b=map(int,input().split())
    if a==0:
        break
    print(week[date(2004,a,b).weekday()])

Failing test case input:
5 4
2 17
0 0

Expected output:
Tuesday
Tuesday


Actual output:
Trueday
Trueday


Fixed submission (verdict: Accepted):
from datetime import date
week=["Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"]
while True:
    a,b=map(int,input().split())
    if a==0:
        break
    print(week[date(2004,a,b).weekday()])

Problem: p00027
Buggy submission (Python3, verdict: Wrong Answer):
def day(x,y):
	start=0
	if x==2 or x==8 :
		start=0
	elif x==3 or x==11:
		start=1
	elif x==6:
		start=2
	elif x==9 or x==12:
		start=3
	elif x==1 or x==4:
		start=4
	else:
		start=6
	day=(start+y)%7
	if day==1:
		return "Sunday"
	elif day==2:
		return "Monday"
	elif day==3:
		return "Tuesday"
	elif day==4:
		return "Wednesday"
	elif day==5:
		return "Thursday"
	elif day==6:
		return "Friday"
	else:
		return "Saturday"


while True:	
	x,y=map(int,input().split())
	if x==y==0:
		break
	print(day(x,y))

Failing test case input:
6 2
7 17
0 0

Expected output:
Wednesday
Saturday


Actual output:
Wednesday
Monday


Fixed submission (verdict: Accepted):
def day(x,y):
	start=0
	if x==2 or x==8 :
		start=0
	elif x==3 or x==11:
		start=1
	elif x==6:
		start=2
	elif x==9 or x==12:
		start=3
	elif x==1 or x==4 or x==7:
		start=4
	elif x==10:
		start=5
	elif x==5:
		start=6 



	day=(start+y)%7
	if day==1:
		return "Sunday"
	elif day==2:
		return "Monday"
	elif day==3:
		return "Tuesday"
	elif day==4:
		return "Wednesday"
	elif day==5:
		return "Thursday"
	elif day==6:
		return "Friday"
	else:
		return "Saturday"


while True:	
	x,y=map(int,input().split())
	if x==y==0:
		break
	print(day(x,y))

Problem: p00027
Buggy submission (Python3, verdict: Wrong Answer):
import sys

DoD = ["Thursday", "Friday", "Saturday", "Sunday", "Monday", "Tuesday", "Wednesday"]


def getPNoD(n):
  if n == 1:
    return 0
  elif n == 3:
    return 29
  elif (n % 2 == 0 and n < 8) or (n % 2 == 0 and n >= 8):
    return 31 + getPNoD(n-1)
  else:
    return 30 + getPNoD(n-1)


for line in sys.stdin:
  m, d = [int(i) for i in line.split()]
  if m == 0:
    break
  n = getPNoD(m) + d - 1
  print(DoD[n % 7])

Failing test case input:
4 7
3 16
0 0

Expected output:
Wednesday
Tuesday


Actual output:
Sunday
Saturday


Fixed submission (verdict: Accepted):
import sys

DoD = ["Thursday", "Friday", "Saturday", "Sunday", "Monday", "Tuesday", "Wednesday"]


def getPNoD(n):
  if n == 1:
    return 0
  elif n == 3:
    return 29 + getPNoD(n-1)
  elif (n % 2 == 0 and n <= 8) or (n % 2 != 0 and n > 8):
    return 31 + getPNoD(n-1)
  else:
    return 30 + getPNoD(n-1)


for line in sys.stdin:
  m, d = [int(i) for i in line.split()]
  if m == 0:
    break
  n = getPNoD(m) + d - 1
  print(DoD[n % 7])