Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
n,l= map(int,input().split())
if l == -1:
    count = 0
    for i in range(n):
        count += l
        l += 1
    print(count)
elif l < 0:
    count = 0
  for i in range(n-1):
        count += l
        l += 1
    print(count)
else:
    print(((2*l+n)*(n-1))//2)

Fixed submission:
n,l= map(int,input().split())
li = []
for i in range(n):
    li.append(l)
    l += 1
ans = 0
li_min = float('inf')
for i in range(len(li)):
    li_min = min(abs(li[i]),li_min)
for i in range(len(li)):
    if li_min == abs(li[i]):
        li[i] = 0
print(sum(li))
Buggy python submission (verdict: Time Limit Exceeded):
n,m = map(int,input().split())
a = [0] * m
for i in range(m):
    a[i] = int(input())
 
MOD = 10 ** 9 + 7
dp = [0] * (n + 1)
dp[0] = 1
 
for i in range(1, n + 1):
    if i in a:
        continue
    x = dp[i - 1]
    if i > 1:
        x += dp[i - 2]
    dp[i] = x % MOD
ans = dp[n]
print(ans)

Fixed submission:
N, M = [int(x) for x in input().split()]
a = set(int(input()) for _ in range(M))
 
MOD = 10 ** 9 + 7
dp = [0] * (N + 1)
dp[0] = 1
 
for i in range(1, N + 1):
  if i in a:
    continue
  x = dp[i - 1]
  if i > 1:
    x += dp[i - 2]
  dp[i] = x % MOD
 
ans = dp[N]
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
K, S = map(int, input().split())
count = 0
for i in range(K+1):
    for j in range(K+1):
        for k in range(K+1):
            if i+j+k == S:
                count += 1
print(count)


Fixed submission:
K, S = map(int, input().split())
count = 0
for i in range(K+1):
    for j in range(K+1):
            if 0<=S-i-j<=K:
                count += 1
print(count)
Buggy python submission (verdict: Runtime Error):
S = input()
c = 0
cmax = 0
for c in S:
  if c == "R":
    c += 1
    if cmax < c:
      cmax = c
  else:
    c = 0
print(cmax)

Fixed submission:
S = input()
cnt = 0
cmax = 0
for c in S:
  if c == "R":
    cnt += 1
    if cmax < cnt:
      cmax = cnt
  else:
    cnt = 0
print(cmax)
Buggy python submission (verdict: Time Limit Exceeded):
import math
N = int(input())

for i in range(1, N + 1):
  max_num = math.ceil(math.sqrt(i)) + 1
  count = 0
  for x in range(1, max_num):
    for y in range(1, max_num):
      for z in range(1, max_num):
        val = x * x + y * y + z * z + x * y + y * z + z * x
        if val == i:
          count += 1
        if val > i:
          break
  print(count)

Fixed submission:
N = int(input())

ans = [0] * 10001
for x in range(1, 100):
  for y in range(1, 100):
    for z in range(1, 100):
      val = x * x + y * y + z * z + x * y + y * z + z * x
      if val < len(ans):
        ans[val] += 1

for i in range(1, N + 1):
  print(ans[i])
Buggy python submission (verdict: Runtime Error):

def q4():
    N = int(input())
    arr = prime_factorize(N)
    if not arr:
        print(0)
        return

    ans_count = 0
    count = 1

    min_val = min(arr)
    while arr:
        if arr.count(min_val) < count:
            arr = list(filter(lambda a: a != min_val, arr))
            count = 1
            if not arr:
                break
            min_val = min(arr)
            continue
        arr = arr[count:]
        ans_count += 1
        count += 1
    print(ans_count)


q4()


Fixed submission:

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a


def q4():
    N = int(input())
    arr = prime_factorize(N)
    if not arr:
        print(0)
        return

    ans_count = 0
    count = 1

    min_val = min(arr)
    while arr:
        if arr.count(min_val) < count:
            arr = list(filter(lambda a: a != min_val, arr))
            count = 1
            if not arr:
                break
            min_val = min(arr)
            continue
        arr = arr[count:]
        ans_count += 1
        count += 1
    print(ans_count)


q4()

Buggy python submission (verdict: Runtime Error):

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a


def q4():
    N = int(input())
    arr = prime_factorize(N)

    ans_count = 0
    count = 1
    min_val = min(arr)
    while arr:
        if arr.count(min_val) < count:
            arr = list(filter(lambda a: a != min_val, arr))
            count = 1
            if not arr:
                break
            min_val = min(arr)
            continue
        arr = arr[count:]
        ans_count += 1
        count += 1
    print(ans_count)


q4()

Fixed submission:

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a


def q4():
    N = int(input())
    arr = prime_factorize(N)
    if not arr:
        print(0)
        return

    ans_count = 0
    count = 1

    min_val = min(arr)
    while arr:
        if arr.count(min_val) < count:
            arr = list(filter(lambda a: a != min_val, arr))
            count = 1
            if not arr:
                break
            min_val = min(arr)
            continue
        arr = arr[count:]
        ans_count += 1
        count += 1
    print(ans_count)


q4()
Buggy python submission (verdict: Runtime Error):

N, M = map(int, readline().split())

print(N * (N - 1) / 2 + M * (M - 1) /2)

Fixed submission:
N, M = map(int, input().split())
 
print(int(N * (N - 1) / 2 + M * (M - 1) /2))
Buggy python submission (verdict: Runtime Error):
S = input()
N = len(S)

def isp(s):
  n = len(s)
  for i in range(n // 2 - 1):
    if s[i] != s[n - 1 - i]:
      return False
  return True

if isp(S) and isp(S[0:(N - 1) / 3]):
  print("Yes")
else:
  print("No")

Fixed submission:
S = input()
N = len(S)
 
def isp(s):
  n = len(s)
  for i in range(n // 2):
    if s[i] != s[n - 1 - i]:
      return False
  return True
 
if isp(S) and isp(S[0:(N - 1) // 2]):
  print("Yes")
else:
  print("No")
Buggy python submission (verdict: Runtime Error):
_ = int(input())
X = list(map(int, input().split()))

t = []
for i in range(min(X), max(X)):
  s = 0
  for x in X:
    s += (x - i) * (x - i)
  t.append(s)

print(min(t))

Fixed submission:
_ = int(input())
X = list(map(int, input().split()))

t = []
for i in range(min(X), max(X) + 1):
  s = 0
  for x in X:
    s += (x - i) * (x - i)
  t.append(s)

print(min(t))
Buggy python submission (verdict: Runtime Error):
S = input()

cnt = 0
for i in range(S // 2):
  if S[i] != S[len(S) - 1 - i]:
    cnt += 1
print(cnt)

Fixed submission:
S = input()

cnt = 0
for i in range(len(S) // 2):
  if S[i] != S[len(S) - 1 - i]:
    cnt += 1
print(cnt)
Buggy python submission (verdict: Runtime Error):
s = input()
if s % 2 == 1:
  print("No")
  exit(0)
if s[:len(s) // 2 - 1] == s[len(s) // 2:]:
  print("Yes")
else:
  print("No")

Fixed submission:
_ = input()
s = input()
if len(s) % 2 == 1:
  print("No")
  exit(0)
if s[:len(s) // 2] == s[len(s) // 2:]:
  print("Yes")
else:
  print("No")
Buggy python submission (verdict: Runtime Error):
a, b = [int(i) for i in input().split()]
print(max(0, a - 2 * b)

Fixed submission:
a, b = [int(i) for i in input().split()]
print(max(0, a - 2 * b))
Buggy python submission (verdict: Runtime Error):
A,B=map(int,input().split())
print(math.ceil((B-1)/(A-1)))

Fixed submission:
import math
A,B=map(int,input().split())
print(math.ceil((B-1)/(A-1)))
Buggy python submission (verdict: Runtime Error):
N, K = [int(x) for x in input().split(' ')]
if K == 1:
    print(0)
    return
min = 1
max = N - (K - 1)
print(max - min)


Fixed submission:
N, K = [int(x) for x in input().split(' ')]
if K == 1:
    print(0)
else:
    min = 1
    max = N - (K - 1)
    print(max - min)
Buggy python submission (verdict: Time Limit Exceeded):
def q1():
    _, A, B, C, D = [int(x) - 1 for x in input().split(' ')]
    S = input()
    if "##" in S[A:D + 1]:
        return False
    if C < D:
        return True
    for b in range(B, D + 1):
        if S[b] == '#':
            continue
        s = S[:b] + '#' + S[b + 1:]
        if not "##" in s[A: C + 1]:
            return True
    return False

print('Yes' if q1() else 'No')

Fixed submission:
def q1():
    _, A, B, C, D = [int(x) - 1 for x in input().split(' ')]
    S = input()
    if "##" in S[A:D + 1]:
        return False
    if C < D:
        return True
    for b in range(B, D + 1):
        if S[b] == '#':
            continue
        if (S[b - 1] != "#" and S[b + 1] != "#"):
            return True
    return False

print('Yes' if q1() else 'No')
Buggy python submission (verdict: Runtime Error):
h, w = [int(i) for i in input().split()]
_, _ = input()

print(h * w - (h + w - 1))

Fixed submission:
h, w = [int(i) for i in input().split()]
h1, w1 = [int(i) for i in input().split()]
 
print(h * w - (h * w1 + w * h1 - h1 * w1))
Buggy python submission (verdict: Runtime Error):
s = input()
if len(S) == 2:
  print(s)
else:
  print(s[2]+s[1]+s[0])

Fixed submission:
s = input()
if len(s) == 2:
  print(s)
else:
  print(s[2]+s[1]+s[0])
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())

for h in range(1, 3501):
  for n in range(1, 3501):
    a = (4 * h * n) - N * h - N * n
    if a == 0:
      continue
    w = (N * h * n) / a
    if w.is_integer() and 0 < w:
      print(h, n, int(w))
      exit(0)

Fixed submission:
N = int(input())

for h in range(1, 3501):
  for n in range(1, 3501):
    a = (4 * h * n) - N * h - N * n
    if a <= 0:
      continue
    w = (N * h * n) / a
    if w.is_integer() and 0 < w:
      print(h, n, int(w))
      exit(0)
Buggy python submission (verdict: Time Limit Exceeded):
n,x,m = map(int,input().split())
set_a = set()
a = []
while len(a)<n:
    if x in a:break
    set_a.add(x)
    a.append(x)
    x = x**2%m

ans = sum(a[:min(n,len(a))])
n -= len(a)
if n<1:
    print(ans)
    exit()

i = a.index(x)
l = len(a)-i
ans += sum(a[i:]) * (n//l)
n %= l
ans += sum(a[i:i+n])
print(ans)



Fixed submission:
n,x,m = map(int,input().split())
set_a = set()
a = []
while len(a)<n:
    if x in a:break
    set_a.add(x)
    a.append(x)
    x = x**2%m

ans = sum(a[:min(n,len(a))])
n -= len(a)
if n<1:
    print(ans)
    exit()

i = a.index(x)
l = len(a)-i
ans += sum(a[i:]) * (n//l)
n %= l
ans += sum(a[i:i+n])
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
h,w = map(int,input().split())
ch,cw = map(int,input().split())
ch -= 1
cw -= 1
dh,dw = map(int,input().split())
dh -= 1
dw -= 1
s = [input() for i in range(h)]

reach = [[False]*w for i in range(h)]
reach[ch][cw] = True

import heapq
q = [[0,ch,cw]]
heapq.heapify(q)

ans = -1
while q:
    cnt,cx,cy = heapq.heappop(q)
    reach[cx][cy] = True
    if cx==dh and cy==dw:
        ans = cnt
        break

    for dx,dy in [[0,1],[0,-1],[1,0],[-1,0]]:
        if not(0<=cx+dx<h and 0<=cy+dy<w):continue
        if s[cx+dx][cy+dy]=='.':
            if not reach[cx+dx][cy+dy]:
                heapq.heappush(q,[cnt,cx+dx,cy+dy])

    for dx in range(-2,3):
        for dy in range(-2,3):
            if [dx,dy] in [[0,0],[0,1],[0,-1],[1,0],[-1,0]]:continue
            if not(0<=cx+dx<h and 0<=cy+dy<w):continue
            if not reach[cx+dx][cy+dy] and s[cx+dx][cy+dy]=='.':
                heapq.heappush(q,[cnt+1,cx+dx,cy+dy])

    

print(ans)



Fixed submission:
h,w = map(int,input().split())
ch,cw = map(int,input().split())
ch -= 1
cw -= 1
dh,dw = map(int,input().split())
dh -= 1
dw -= 1
s = [input() for i in range(h)]

cost = [[-1]*w for i in range(h)]

from collections import deque
q = [[0,ch,cw]]
q = deque(q)

ans = -1
while q:
    cnt,cx,cy = q.popleft()
    if cost[cx][cy]<0:
        cost[cx][cy]=cnt
        for dx in range(-2,3):
            for dy in range(-2,3):
                if 0<=cx+dx<h and 0<=cy+dy<w and s[cx+dx][cy+dy]=='.':
                    if cost[cx+dx][cy+dy]<0:
                        if [dx,dy] in [[1,0],[-1,0],[0,1],[0,-1]]:
                            q.appendleft([cnt,cx+dx,cy+dy])
                        else:
                            q.append([cnt+1,cx+dx,cy+dy])

print(cost[dh][dw])
Buggy python submission (verdict: Time Limit Exceeded):
k = int(input())
n = 0
for i in range(1,10**6):
    n = n*10+7
    if n%k==0:
        print(i)
        exit()
print(-1)

Fixed submission:
k = int(input())
n = 0
for i in range(1,10**6):
    n = (n*10+7)%k
    if n%k==0:
        print(i)
        exit()
print(-1)
Buggy python submission (verdict: Time Limit Exceeded):
n,k = map(int,input().split())
a = list(map(int,input().split()))
x = 1
for i in range(n):
    if i<k:
        x *= a[i]
    else:
        c = x//a[i-k]*a[i]
        print('Yes' if c>x else 'No')
        x = c

Fixed submission:
n,k = map(int,input().split())
a = list(map(int,input().split()))
for i in range(n):
    if i>=k:
        print('Yes' if a[i-k]<a[i] else 'No')
Buggy python submission (verdict: Runtime Error):
n = 26
d = int(input())
c = list(map(int,input().split()))
s = [[] for i in range(n)]
for i in range(d):
    s[i] = list(map(int,input().split()))
a = 0
last = [0]*n
ans = []
for i in range(d):
    t = int(input())-1
    a += s[i][t]
    last[t] = i+1
    for j in range(n):
        a -= c[j]*(i-last[j]+1)
    ans.append(a)
for i in ans:
    print(i)


Fixed submission:
n = 26
d = int(input())
c = list(map(int,input().split()))
s = [[] for i in range(d)]
for i in range(d):
    s[i] = list(map(int,input().split()))
a = 0
last = [0]*n
for i in range(d):
    t = int(input())-1
    a += s[i][t]
    last[t] = i+1
    for j in range(n):
        a -= c[j]*(i-last[j]+1)
    print(a)

Buggy python submission (verdict: Runtime Error):
d = int(input())
c = list(map(int,input().split()))
s = [[] for i in range(26)]
for i in range(d):
    s[i] = list(map(int,input().split()))
ans = 0
last = [0]*26
for i in range(d):
    t = int(input())-1
    ans += s[i][t]
    last[t] = i+1
    for j in range(26):
        ans -= c[j]*(i-last[j]+1)
    print(ans)


Fixed submission:
n = 26
d = int(input())
c = list(map(int,input().split()))
s = [[] for i in range(d)]
for i in range(d):
    s[i] = list(map(int,input().split()))
a = 0
last = [0]*n
for i in range(d):
    t = int(input())-1
    a += s[i][t]
    last[t] = i+1
    for j in range(n):
        a -= c[j]*(i-last[j]+1)
    print(a)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int,input().split()))
c = 0
for i in a:
    c ^= i

c = format(c,'b').zfill(30)

buf = []
for i in a:
    s = format(i,'b').zfill(30)
    ans = list(c)
    for j in range(len(s)):
        x = (int(ans[j])+int(s[j]))%2
        ans[j] = str(x)
    x = ''.join(ans)
    buf.append(int(x,2))
print(*buf)

Fixed submission:
n = int(input())
a = list(map(int,input().split()))
c = 0
for i in a:
    c ^= i

buf = []
for i in a:
    buf.append(c^i)
    
print(*buf)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int,input().split()))
c = 0
for i in a:
    c ^= i

c = format(c,'b').zfill(50)

buf = []
for i in a:
    s = format(i,'b').zfill(50)
    ans = list(c)
    for j in range(len(s)):
        x = (int(ans[j])+int(s[j]))%2
        ans[j] = str(x)
    x = ''.join(ans)
    buf.append(int(x,2))
print(*buf)

Fixed submission:
n = int(input())
a = list(map(int,input().split()))
c = 0
for i in a:
    c ^= i

buf = []
for i in a:
    buf.append(c^i)
    
print(*buf)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int,input().split()))
c = 0
for i in a:
    c ^= i

c = format(c,'b').zfill(30)[::-1]

buf = []
for i in a:
    s = format(i,'b')[::-1]
    ans = list(c)
    for j in range(len(s)):
        x = (int(ans[j])+int(s[j]))%2
        ans[j] = str(x)
    x = ''.join(ans)
    buf.append(int(x[::-1],2))
print(*buf)



Fixed submission:
n = int(input())
a = list(map(int,input().split()))
c = 0
for i in a:
    c ^= i

buf = []
for i in a:
    buf.append(c^i)
    
print(*buf)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int,input().split()))
c = [0]*31
for i in a:
    s = format(i,'b')[::-1]
    for i in range(len(s)):
        c[i] += int(s[i])

buf = []
for i in a:
    s = format(i,'b').zfill(31)[::-1]
    ans = ''
    for i in range(31):
        ans +=  str((c[i]-int(s[i]))%2)
    ans = ans[::-1]
    buf.append(int(ans,2))

print(*buf)


Fixed submission:
n = int(input())
a = list(map(int,input().split()))
c = 0
for i in a:
    c ^= i

buf = []
for i in a:
    buf.append(c^i)
    
print(*buf)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int,input().split()))
c = [0]*50
for i in a:
    s = format(i,'b')[::-1]
    for i in range(len(s)):
        c[i] += int(s[i])

buf = []
for i in a:
    s = format(i,'b').zfill(50)[::-1]
    ans = ''
    for i in range(50):
        ans +=  str((c[i]-int(s[i]))%2)
    ans = ans[::-1]
    buf.append(int(ans,2))

print(*buf)


Fixed submission:
n = int(input())
a = list(map(int,input().split()))
c = 0
for i in a:
    c ^= i

buf = []
for i in a:
    buf.append(c^i)
    
print(*buf)
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = sorted(list(map(int,input().split())))

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

if a[0] in a[1:]:
    ans = 0
else:
    ans = 1

import sympy
div = set([a[0]])
for i in a[1:]:
    x = set(sympy.divisors(i))
    if not x&div:
        ans += 1
    div.add(i)
print(ans)
        

Fixed submission:
n = int(input())
a = sorted(list(map(int,input().split())))
m = max(a)+1
c = [0]*m
for x in a:
    for i in range(x,m,x):
        if c[i]<2:c[i]+=1
ans = 0
for i in a:
    if c[i]==1:
        ans += 1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n,k = map(int,input().split())
a = list(map(int,input().split()))

for _ in range(k):
    r = [0]*(n+1)
    for i in range(n):
        r[max(i-a[i],0)] += 1
        r[min(i+a[i]+1,n)] -= 1
    for i in range(n-1):
        r[i+1] += r[i]
    a = r
    if a.count(n)==n:
        break
print(*a[:-1])


Fixed submission:
n,k = map(int,input().split())
a = list(map(int,input().split()))

for _ in range(k):
    r = [0]*(n+1)
    for i in range(n):
        r[max(i-a[i],0)] += 1
        r[min(i+a[i]+1,n)] -= 1
    for i in range(n-1):
        r[i+1] += r[i]
    a = r
    if a.count(n)==n:
        break
print(*a[:-1])
Buggy python submission (verdict: Runtime Error):
a,b,n = map(int,input().split())
n%b==0:n-=1
print((a*n)//b-a*(n//b))

Fixed submission:
a,b,n = map(int,input().split())
if n%b==0:n-=1
x = max((n//b)*b-1,n%b)
print(((a*x)//b)-(a*(x//b)))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = list(input())
ans = 0
r = []
g = []
b = []
for i in range(n):
    if s[i]=='R':r.append(i)
    elif s[i]=='G':g.append(i)
    else:b.append(i)
for i in r:
    for j in g:
        for k in b:
            x,y,z = sorted([i,j,k])
            if y-x!=z-y:
                ans += 1
print(ans)

Fixed submission:
n = int(input())
s = list(input())
ans = 0
r = []
g = []
b = []
for i in range(n):
    if s[i]=='R':r.append(i)
    elif s[i]=='G':g.append(i)
    else:b.append(i)
ans = len(r)*len(g)*len(b)
d = 0
for i in range(n-2):
    for j in range(i,n-1):
        k = j+j-i
        if k < n and s[i] != s[j] and s[k] != s[i] and s[k]!=s[j]:
            d+=1
print(ans-d)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = list(input())
ans = 0
for k in range(n):
    for j in range(k):
        for i in range(j):
            if s[i]!=s[k] and s[j]!=s[k] and s[i] !=s[j] and j-i!=k-j:
                ans += 1
print(ans)

Fixed submission:
n = int(input())
s = list(input())
ans = 0
r = []
g = []
b = []
for i in range(n):
    if s[i]=='R':r.append(i)
    elif s[i]=='G':g.append(i)
    else:b.append(i)
ans = len(r)*len(g)*len(b)
d = 0
for i in range(n-2):
    for j in range(i,n-1):
        k = j+j-i
        if k < n and s[i] != s[j] and s[k] != s[i] and s[k]!=s[j]:
            d+=1
print(ans-d)
Buggy python submission (verdict: Time Limit Exceeded):
h,w = map(int,input().split())
s = [input() for _ in range(h)]
dp = [[-1]*w for i in range(h)]
dp[0][0] = 1 if s[0][0]=='#' else 0
q = [[0,0]]
while q:
    x,y = q.pop()
    a = 1 if s[x][y]=='#' else 0
    if x+1<h:
        if dp[x+1][y]<0:dp[x+1][y] = dp[x][y]+a
        else:dp[x+1][y] = min(dp[x][y]+a,dp[x+1][y])
        q.append([x+1,y])
    if y+1<w:
        if dp[x][y+1]<0:dp[x][y+1] = dp[x][y]+a
        else:dp[x][y+1] = min(dp[x][y]+a,dp[x][y+1])
        q.append([x,y+1])

print(dp[h-1][w-1])



Fixed submission:
h,w = map(int,input().split())
s = [input() for _ in range(h)]
dp = [[float('inf')]*w for i in range(h)]
dp[0][0] = 1 if s[0][0]=='#' else 0
for x in range(h):
    for y in range(w):
        if x+1<h:
            a = 1 if s[x][y]=='.' and s[x+1][y]=='#' else 0
            dp[x+1][y] = min(dp[x][y]+a,dp[x+1][y])
        if y+1<w:
            a = 1 if s[x][y]=='.' and s[x][y+1]=='#' else 0
            dp[x][y+1] = min(dp[x][y]+a,dp[x][y+1])

print(dp[h-1][w-1])

Buggy python submission (verdict: Time Limit Exceeded):
h,w = map(int,input().split())
s = [input() for _ in range(h)]
dp = [[-1]*w for i in range(h)]
dp[0][0] = 1 if s[0][0]=='#' else 0
q = [[0,0]]
while q:
    x,y = q.pop()
    a = 1 if s[x][y]=='#' else 0
    if x+1<h:
        if dp[x+1][y]<0:dp[x+1][y] = dp[x][y]+a
        else:dp[x+1][y] = min(dp[x][y]+a,dp[x+1][y])
        q.append([x+1,y])
    if y+1<w:
        if dp[x][y+1]<0:dp[x][y+1] = dp[x][y]+a
        else:dp[x][y+1] = min(dp[x][y]+a,dp[x][y+1])
        q.append([x,y+1])

print(dp[h-1][w-1])



Fixed submission:
h,w = map(int,input().split())
s = [input() for _ in range(h)]
dp = [[float('inf')]*w for i in range(h)]
dp[0][0] = 1 if s[0][0]=='#' else 0
for x in range(h):
    for y in range(w):
        if x+1<h:
            a = 1 if s[x][y]=='.' and s[x+1][y]=='#' else 0
            dp[x+1][y] = min(dp[x][y]+a,dp[x+1][y])
        if y+1<w:
            a = 1 if s[x][y]=='.' and s[x][y+1]=='#' else 0
            dp[x][y+1] = min(dp[x][y]+a,dp[x][y+1])

print(dp[h-1][w-1])

Buggy python submission (verdict: Time Limit Exceeded):
h,w = map(int,input().split())
s = [input() for _ in range(h)]
dp = [[float('inf')]*w for i in range(h)]
dp[0][0] = 1 if s[0][0]=='#' else 0
q = [[0,0]]
while q:
    x,y = q.pop()
    a = 1 if s[x][y]=='#' else 0
    if x+1<h:
        dp[x+1][y] = min(dp[x][y]+a,dp[x+1][y])
        q.append([x+1,y])
    if y+1<w:
        dp[x][y+1] = min(dp[x][y]+a,dp[x][y+1])
        q.append([x,y+1])
print(dp[h-1][w-1])



Fixed submission:
h,w = map(int,input().split())
s = [input() for _ in range(h)]
dp = [[float('inf')]*w for i in range(h)]
dp[0][0] = 1 if s[0][0]=='#' else 0
for x in range(h):
    for y in range(w):
        if x+1<h:
            a = 1 if s[x][y]=='.' and s[x+1][y]=='#' else 0
            dp[x+1][y] = min(dp[x][y]+a,dp[x+1][y])
        if y+1<w:
            a = 1 if s[x][y]=='.' and s[x][y+1]=='#' else 0
            dp[x][y+1] = min(dp[x][y]+a,dp[x][y+1])

print(dp[h-1][w-1])
Buggy python submission (verdict: Runtime Error):
n,a,b = map(int,input().split())
cnt = 0
ball = ''
while cnt<n:
    ball += 'b'*a
    ball += 'r'*b
    cnt += a+b
print(ball.count('b',0,n))

Fixed submission:
n,a,b = map(int,input().split())
print((n//(a+b))*a+min(n%(a+b),a))