Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
h=[]
h.append("P")

n,x=map(int,input().split(" "))

for i in range(1,n+1):
  h.append("B"+h[i-1]+"P"+h[i-1]+"B")
  #print (h[i])
  
taberu=h[n][0:x]
print(taberu.count("P"))

Fixed submission:
#解答参照した
n,x=map(int,input().split(" "))

P=[1]
M=[1]

for i in range(1,n):
  P.append(2*P[i-1]+1)
  M.append(2*M[i-1]+3)
  
def F(n,x):
  if n==0:
    return 0 if x<=0 else 1
  elif x<=1:
    return 0
  elif 1<x<=M[n-1]+1:
    return F(n-1,x-1)
  elif x==M[n-1]+2:
    return P[n-1]+1
  elif M[n-1]+2<x<2*M[n-1]+3:
    return P[n-1]+1+F(n-1,x-2-M[n-1])
  elif x==2*M[n-1]+3:
    return 2*P[n-1]+1
  else:
    return P[n-1]+1+F(n-1,x-2-M[n-1])
    #print("OH!"+str(n))
    
print (F(n,x))
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
cc=0
answer=0

while cc<=n:
  #length=len(str(cc))
  n3=str(cc).count("3")
  n5=str(cc).count("5")
  n7=str(cc).count("7")
  
  if len(str(cc))==n3+n5+n7 and min(n3,n5,n7)!=0:
    #print(cc,n3,n5,n7,answer)
    answer=answer+1
    
  cc=cc+1
  
print(answer)





Fixed submission:
#解答より
N=int(input())

def dfs(s):
  if int(s)>N:
    return 0
  if all (s.count(c)>0 for c in "753"):
    ret=1
  else:
    ret=0
    
  for c in "753":
    ret=ret+dfs(s+c)
  
  return ret

print (dfs("0"))
Buggy python submission (verdict: Time Limit Exceeded):
aa=[]
a=int(input())
for i in range(0,a):
  aa.append(input().split(" "))

bb=[]
for j in range(0,a):
  bb.append(input().split(" "))
  
pattern=[]
zentai=[]
chouhuku=0

for m in range(0,a**a):
  for n in range(0,a):
    pattern.append(m//(a**n)%a)
  
  for w in range(0,a):
    if pattern.count(pattern[w])>=2:
      chouhuku=1
  
  if chouhuku==0:
    zentai.append(pattern)
  pattern=[]
  chouhuku=0


score=0
max=0

for ww in zentai:
  for z in range(0,a):
    if aa[z][0]<bb[int(ww[z])][0] and aa[z][1]<bb[int(ww[z])][1]:
      score=score+1

  if max<=score:
    max=score
  score=0

print(max)


Fixed submission:
#解答確認後
n=int(input())
aa=[[int(i) for i in input().split()] for i in range(n)]
bb=[[int(i) for i in input().split()] for i in range(n)]

#print(aa)
#print(bb)

import operator
aa.sort(key=operator.itemgetter(1),reverse=True)
bb.sort()
  
#print(aa)
#print(bb)

answer=0
for b in bb:
  xb,yb=b
  for a in aa:
    xa,ya=a
    if xa<xb and ya<yb:
      answer=answer+1
      aa. remove (a)
      #print(aa)
      #print(bb)
      #print(answer)
      break
      
print(answer)

Buggy python submission (verdict: Time Limit Exceeded):
aa=[]
a=int(input())
for i in range(0,a):
  aa.append(input().split(" "))

bb=[]
for j in range(0,a):
  bb.append(input().split(" "))

#print(aa)
#print(bb)
  
pattern=[]
zentai=[]
chouhuku=0

for m in range(0,a**a):
  for n in range(0,a):
    pattern.append(m//(a**n)%a)
    
  #print(pattern)
  
  for w in range(0,a):
    if pattern.count(pattern[w])>=2:
      chouhuku=1
  
  if chouhuku==0:
    zentai.append(pattern)
  pattern=[]
  chouhuku=0
  
#print(zentai)

score=0
max=0

for ww in zentai:
  for z in range(0,a):
    if aa[z][0]<bb[int(ww[z])][0] and aa[z][1]<bb[int(ww[z])][1]:
      score=score+1
  #print(ww)
  #print ("score="+str(score))
  if max<=score:
    max=score
  score=0

print(max)


Fixed submission:
#解答確認後
n=int(input())
aa=[[int(i) for i in input().split()] for i in range(n)]
bb=[[int(i) for i in input().split()] for i in range(n)]

#print(aa)
#print(bb)

import operator
aa.sort(key=operator.itemgetter(1),reverse=True)
bb.sort()
  
#print(aa)
#print(bb)

answer=0
for b in bb:
  xb,yb=b
  for a in aa:
    xa,ya=a
    if xa<xb and ya<yb:
      answer=answer+1
      aa. remove (a)
      #print(aa)
      #print(bb)
      #print(answer)
      break
      
print(answer)
Buggy python submission (verdict: Time Limit Exceeded):
N,M = map(int,input().split())
lst = [list(map(int,input().split())) for _ in range(M)]

L1,R1 = lst[0]
common = 0
for i in range(L1,R1+1):

    count = 0
    for j in range(1,M):
        Lj,Rj = lst[j]   
        if i < Lj or i > Rj:
            break
        else:
            count += 1

    if count == M-1:
        common += 1

print(common)

Fixed submission:
N,M = map(int,input().split())
maxL = 1
minR = 100000
for i in range(M):
    Li,Ri = map(int,input().split())
    maxL = max(maxL,Li)
    minR = min(minR,Ri)
        
if minR - maxL >= 0:
    print(minR-maxL+1)
else:
    print(0)
Buggy python submission (verdict: Time Limit Exceeded):
N,M = map(int,input().split())
A = list(map(int,input().split()))

for i in range(M):
    B,C = map(int,input().split())
    A = A + [C] * B

A.sort(reverse=True)
A_max = A[0:N]

print(sum(A_max))

Fixed submission:
N,M = map(int,input().split())
A = list(map(int,input().split()))
BC = [list(map(int,input().split())) for _ in range(M)]

A.sort()
S_BC = sorted(BC,key=lambda x:x[1],reverse=True)

index = 0
flag = 0
for Bj,Cj in S_BC:
    for k in range(Bj):
        if len(A) >= index+1:
            if A[index] < Cj:
                A[index] = Cj
                index += 1
            else:
                flag = 1
                break
        else:
            flag = 1
            break
        
    if flag == 1:
        break

print(sum(A))

Buggy python submission (verdict: Time Limit Exceeded):
N,M = map(int,input().split())
A = list(map(int,input().split()))
BC = [list(map(int,input().split())) for _ in range(M)]

A.sort()

for i,j in BC:

    for k in range(i):
        if A[k] < j:
            A[k] = j
        else:
            break

    A.sort()

print(sum(A))


Fixed submission:
N,M = map(int,input().split())
A = list(map(int,input().split()))
BC = [list(map(int,input().split())) for _ in range(M)]

A.sort()
S_BC = sorted(BC,key=lambda x:x[1],reverse=True)

index = 0
flag = 0
for Bj,Cj in S_BC:
    for k in range(Bj):
        if len(A) >= index+1:
            if A[index] < Cj:
                A[index] = Cj
                index += 1
            else:
                flag = 1
                break
        else:
            flag = 1
            break
        
    if flag == 1:
        break

print(sum(A))
Buggy python submission (verdict: Runtime Error):
n = input()
h = list(map(int,input().split()))

total = 0
maxN = 0
for num in h:
  if  num >= maxN:
    total += 1
  
  maxN = max(maxN,num)

print(total)

Fixed submission:
a, b = map(int, input().split())

total = 0

if a >= b :
    total = a
    a -= 1
else:
    total = b
    b -=  1

if a>= b :
    total = total + a
else:
    total = total + b

print(total)

Buggy python submission (verdict: Runtime Error):
number = input()

height = list(map(int,input().split()))

total = 1
flag = True
    
for i in range(1,len(height)):

    for j in range(i):
        if height[i] >= height[j]:
            flag = True
        else:
            flag = False
    
    if flag:
        total += 1

print(total)


Fixed submission:
a, b = map(int, input().split())

total = 0

if a >= b :
    total = a
    a -= 1
else:
    total = b
    b -=  1

if a>= b :
    total = total + a
else:
    total = total + b

print(total)

Buggy python submission (verdict: Runtime Error):
number = input()

height = list(map(int,input().split()))

total = 1
flag = True
    
for i in range(1,len(height)):

    for j in range(i):
        if height[i] >= height[j]:
            flag = True
        else:
            flag = False
    
    if flag:
        total += 1

print(total)


Fixed submission:
a, b = map(int, input().split())

total = 0

if a >= b :
    total = a
    a -= 1
else:
    total = b
    b -=  1

if a>= b :
    total = total + a
else:
    total = total + b

print(total)
Buggy python submission (verdict: Time Limit Exceeded):
import re
N,Q = map(int,input().split())
S = input()
for i in range(Q):
    l,r = map(int,input().split())
    print(len(re.findall('AC',S[l-1:r])))

Fixed submission:
N,Q = map(int,input().split())
S = input()
lst = [0] * (N+1)
before = ''
count = 0
for i in range(len(S)-1):
    if S[i:i+2] == 'AC':
        count += 1
    lst[i+2] = count
for i in range(Q):
    l,r = map(int,input().split())
    print(lst[r]-lst[l])

Buggy python submission (verdict: Time Limit Exceeded):
import re
N,Q = map(int,input().split())
S = input()
pattern = re.compile(r'AC')

for i in range(Q):
    l,r = map(int,input().split())
    total = 0
    flag = 0
    for j in S[l-1:r]:
        if j == 'A':
            flag = 1
        elif j == 'C' and flag == 1:
            total += 1
        else:
            flag = 0
    
    print(total)

Fixed submission:
N,Q = map(int,input().split())
S = input()
lst = [0] * (N+1)
before = ''
count = 0
for i in range(len(S)-1):
    if S[i:i+2] == 'AC':
        count += 1
    lst[i+2] = count
for i in range(Q):
    l,r = map(int,input().split())
    print(lst[r]-lst[l])

Buggy python submission (verdict: Time Limit Exceeded):
import re
N,Q = map(int,input().split())
S = input()
pattern = re.compile(r'AC')
for i in range(Q):
    l,r = map(int,input().split())
    print(len(pattern.findall(S[l-1:r])))

Fixed submission:
N,Q = map(int,input().split())
S = input()
lst = [0] * (N+1)
before = ''
count = 0
for i in range(len(S)-1):
    if S[i:i+2] == 'AC':
        count += 1
    lst[i+2] = count
for i in range(Q):
    l,r = map(int,input().split())
    print(lst[r]-lst[l])
Buggy python submission (verdict: Time Limit Exceeded):
N,M = map(int,input().split())
store = [list(map(int,input().split())) for _ in range(N)]

for i in range(N):
    tmp = store[i]
    v = store[i][0]
    j = i - 1
    while j >= 0 and store[j][0] > v:
        store[j+1] = store[j]
        j -= 1
    store[j+1] = tmp

sumQ = 0
sumP = 0
for k in range(N):
    p = store[k][0]
    q = store[k][1]
    sumQ = sumQ + q
    sumP = sumP + p * q
    if M < sumQ:
        print(sumP-(sumQ-M)*p)
        break
    elif M == sumQ:
        print(sumP)
        break


Fixed submission:
N,M = map(int,input().split())
store = [list(map(int,input().split())) for _ in range(N)]

A = sorted(store)

sumQ = 0
sumP = 0
for k in range(N):
    p = A[k][0]
    q = A[k][1]
    sumQ = sumQ + q
    sumP = sumP + p * q
    if M < sumQ:
        print(sumP-(sumQ-M)*p)
        break
    elif M == sumQ:
        print(sumP)
        break
Buggy python submission (verdict: Runtime Error):
read r
echo $((3*r*r))

Fixed submission:
r = int(input())
print(3*r**2)

Buggy python submission (verdict: Runtime Error):
read r
echo $((3**r*r))


Fixed submission:
r = int(input())
print(3*r**2)
Buggy python submission (verdict: Runtime Error):
a=int(input())
tl=[]
xl=[]
yl=[]
for i in range(a):
  t,x,y=map(int,input().split())
  tl.append(t)
  xl.append(x)
  yl.append(y)

#print(tl)
for i range(a):
  if (xl[i]+yl[i] > tl[i]):
    print("No")
    exit()
print("Yes")

Fixed submission:
a,b=map(int,input().split())
if a*b % 2==0:
  print("Even")
else:
  print("Odd")
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = [int(input()) for _ in range(N)]
m1,m2,_ = sorted(A)[::-1]

for i in A:
    if m1 == i:
        print(m2)
    else:
        print(m1)

Fixed submission:
N = int(input())
A = [int(input()) for _ in range(N)]
m1,m2,*_ = sorted(A)[::-1]

for i in A:
    if m1 == i:
        print(m2)
    else:
        print(m1)

Buggy python submission (verdict: Time Limit Exceeded):
def maxprint(A,i):
    a = list(A)
    a.pop(i)
    print(max(a))

N = int(input())
A = tuple(int(input()) for _ in range(N))


for i in range(N):
    maxprint(A,i)

Fixed submission:
N = int(input())
A = [int(input()) for _ in range(N)]
m1,m2,*_ = sorted(A)[::-1]

for i in A:
    if m1 == i:
        print(m2)
    else:
        print(m1)
Buggy python submission (verdict: Runtime Error):
# -*- coding:utf-8 -*-

def cmb(n, r):
    if n == 0 or r == 0:
        return 1
    a = b = 1
    for i in range(1, r + 1):
        a *= i
    for i in range(n-r+1,n+1):
        b *= i
    return b//a

N = list(map(int,input().split()))
M = 10**9 + 7
red = N[0]-N[1]
for i in range(1,N[1]+1):
    x = cmb(red + 1, i) * cmb(N[1] - 1,i-1)
    print(x%M)


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

a = list(input())
dic = {}
for x in a:
    dic.setdefault(x, 0)
    dic[x] += 1
if (len(dic) == 2):
    if(dic[a[0]]==2):
        print("Yes")
    else:
        print("No")
else:
    print("No")

Buggy python submission (verdict: Runtime Error):
# -*- coding:utf-8 -*-

def cmb(n, r):
    if n == 0 or r == 0:
        return 1
    a = b = 1
    for i in range(1, r + 1):
        print(r,i)
        a *= i
    for i in range(n-r+1,n+1):
        b *= i
    return b//a

N = list(map(int,input().split()))
M = 10**9 + 7
red = N[0]-N[1]
for i in range(1,N[1]+1):
    x = cmb(red + 1, i) * cmb(N[1] - 1,i-1)
    print(x%M)


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

a = list(input())
dic = {}
for x in a:
    dic.setdefault(x, 0)
    dic[x] += 1
if (len(dic) == 2):
    if(dic[a[0]]==2):
        print("Yes")
    else:
        print("No")
else:
    print("No")
Buggy python submission (verdict: Runtime Error):
N = list(map(int,input().split()))
M = 10**9 + 7
red = N[0] - N[1]
x = red+1
print(x)
for i in range(2,N[1]+1):
    x *= (red+2-i)*(N[1]-i+1)/(i*(i-1))
    print(int(x%M))

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

def cmb(n, r):
    if n == 0 or r == 0:
        return 1
    if n < r:
        return 0
    a = b = 1
    r = min(n-r,r)
    for i in range(1, r + 1):
        a *= i
    for i in range(n-r+1,n+1):
        b *= i
    return b//a

N = list(map(int,input().split()))
M = 10**9 + 7
red = N[0]-N[1]
for i in range(1,N[1]+1):
    x = cmb(red + 1, i) * cmb(N[1] - 1,i-1)
    print(x%M)

Buggy python submission (verdict: Runtime Error):
N = list(map(int,input().split()))
M = 10**9 + 7
red = N[0] - N[1]
x=1
for i in range(1,N[1]+1):
    x *= (red+2-i)*(N[1]-i)//(i*(i-1))
    print(x%M)

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

def cmb(n, r):
    if n == 0 or r == 0:
        return 1
    if n < r:
        return 0
    a = b = 1
    r = min(n-r,r)
    for i in range(1, r + 1):
        a *= i
    for i in range(n-r+1,n+1):
        b *= i
    return b//a

N = list(map(int,input().split()))
M = 10**9 + 7
red = N[0]-N[1]
for i in range(1,N[1]+1):
    x = cmb(red + 1, i) * cmb(N[1] - 1,i-1)
    print(x%M)

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding:utf-8 -*-

def cmb(n, r):
    if n == 0 or r == 0:
        return 1
    a = b = 1
    for i in range(1, r + 1):
        a *= i
    for i in range(n-r+1,n+1):
        b *= i
    return b//a

N = list(map(int,input().split()))
M = 10**9 + 7
red = N[0]-N[1]
for i in range(1,N[1]+1):
    x = cmb(red + 1, i) * cmb(N[1] - 1,i-1)
    print(x%M)


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

def cmb(n, r):
    if n == 0 or r == 0:
        return 1
    if n < r:
        return 0
    a = b = 1
    r = min(n-r,r)
    for i in range(1, r + 1):
        a *= i
    for i in range(n-r+1,n+1):
        b *= i
    return b//a

N = list(map(int,input().split()))
M = 10**9 + 7
red = N[0]-N[1]
for i in range(1,N[1]+1):
    x = cmb(red + 1, i) * cmb(N[1] - 1,i-1)
    print(x%M)

Buggy python submission (verdict: Runtime Error):
def combination(n, m):
    if (n == 0 or m == 0):
        return 1
    a = b = 1
    for i in range(1,m+1):
        a *= i
    for i in range(n-m+1,n+1):
        b *= i
    return b/a

N = list(map(int,input().split()))
M = 1000000007
red = N[0]-N[1]
for i in range(N[1]):
    x = combination(red + 1, i+1) * combination(N[1] - 1, i)
    print(int(x%M))

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

def cmb(n, r):
    if n == 0 or r == 0:
        return 1
    if n < r:
        return 0
    a = b = 1
    r = min(n-r,r)
    for i in range(1, r + 1):
        a *= i
    for i in range(n-r+1,n+1):
        b *= i
    return b//a

N = list(map(int,input().split()))
M = 10**9 + 7
red = N[0]-N[1]
for i in range(1,N[1]+1):
    x = cmb(red + 1, i) * cmb(N[1] - 1,i-1)
    print(x%M)
Buggy python submission (verdict: Time Limit Exceeded):
def main():
	N = int(input())
	A = list(map(int, input().split()))
	ans = ["0"]*N
	mat = [[1 for _ in range(N)] for _ in range(N)]
	for i in range(N):
		for j in range(1, N, 2):
			mat[i][(i+j)%N] = -1
	for i in range(N):
		this_ans = 0
		for j in range(N):
			this_ans += mat[i][j]*A[j]
		ans[i] = str(this_ans)
	print(" ".join(ans))


if __name__ == '__main__':
	main()

Fixed submission:
def main():
	N = int(input())
	A = list(map(int, input().split()))
	ans = ["0"]*N
	this_ans = 0
	offset = [1, -1]
	for i in range(N):
		this_ans += A[i]*offset[i%2]
	ans[0] = str(this_ans)
	for i in range(N-1):
		this_ans = A[i] - int(ans[i])//2
		ans[i+1] = str(this_ans*2)
	print(" ".join(ans))


if __name__ == '__main__':
	main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
	N = int(input())
	A = list(map(int, input().split()))
	ans = ["0"]*N
	mat = [[1 for _ in range(N)] for _ in range(N)]
	for i in range(N):
		for j in range(1, N, 2):
			mat[i][(i+j)%N] = -1
	for i in range(N):
		this_ans = 0
		for j in range(N):
			this_ans += mat[i][j]*A[j]
		ans[i] = str(this_ans)
	print(" ".join(ans))


if __name__ == '__main__':
	main()

Fixed submission:
def main():
	N = int(input())
	A = list(map(int, input().split()))
	ans = ["0"]*N
	this_ans = 0
	offset = [1, -1]
	for i in range(N):
		this_ans += A[i]*offset[i%2]
	ans[0] = str(this_ans)
	for i in range(N-1):
		this_ans = A[i] - int(ans[i])//2
		ans[i+1] = str(this_ans*2)
	print(" ".join(ans))


if __name__ == '__main__':
	main()
Buggy python submission (verdict: Runtime Error):
def main():
	N, K = map(int, input().split())
	DIV = 10**9+7
	size = N
	fact = [0]*size
	inverse = [0]*size
	inv_cal = [0]*size
	fact[:2] = [1, 1]
	inverse[:2] = [1, 1]
	inv_cal[:2] = [0, 1]

	for i in range(2, size):
		fact[i] = (fact[i-1]*i%DIV)
		inv_cal[i] = (-inv_cal[DIV%i]*(DIV//i))%DIV
		inverse[i] = inverse[i-1]*inv_cal[i]%DIV

	def C(n, r):
		ans = fact[n]*inverse[r]%DIV
		return ans*inverse[n-r]%DIV

	for i in range(K):
		ans = (C(N-K+1, i+1)*C(K-1, i))%DIV
		print(ans)


if __name__ == '__main__':
	main()

Fixed submission:
def main():
	N, K = map(int, input().split())
	DIV = 10**9+7
	size = 2001
	fact = [0]*size
	inverse = [0]*size
	inv_cal = [0]*size
	fact[:2] = [1, 1]
	inverse[:2] = [1, 1]
	inv_cal[:2] = [0, 1]

	for i in range(2, size):
		fact[i] = (fact[i-1]*i%DIV)
		inv_cal[i] = (-inv_cal[DIV%i]*(DIV//i))%DIV
		inverse[i] = inverse[i-1]*inv_cal[i]%DIV

	def C(n, r):
		ans = fact[n]*inverse[r]%DIV
		return ans*inverse[n-r]%DIV

	for i in range(K):
		ans = 0
		if i+1 <= N-K+1:
			ans = (C(N-K+1, i+1)*C(K-1, i))%DIV
		print(ans)


if __name__ == '__main__':
	main()
Buggy python submission (verdict: Time Limit Exceeded):
def main():
	N, K = map(int, input().split())
	DIV = 10**9+7
	sqrtn = int(N**0.5)
	ans = 1
	s = []
	for i in range(1, sqrtn+1):
		s.append(i)
		if i < N//i:
			s.append(N//i)
	s.sort()

	r = []
	for i in range(len(s)-1):
		left = N//s[i+1]
		right = N//s[i]
		r.append(right-left)
	r.append(1)

	m = len(s)
	mp = {}
	for i in range(m):
		mp[s[i]] = i

	dp = [[0 for _ in range(m)] for _ in range(K+1)]
	dp[0][mp[N]] = 1
	for i in range(K):
		for j in range(m-2, -1, -1):
			dp[i][j] += dp[i][j+1]
			dp[i][j] %= DIV
		for j in range(m):
			nj = mp[N//s[j]]
			dp[i+1][j] += dp[i][nj]*r[j]%DIV
			dp[i+1][j] %= DIV

	ans = 0
	for j in range(m):
		ans += dp[K][j]
		ans %= DIV
	print(ans)


if __name__ == '__main__':
	main()

Fixed submission:
def main():
	N, K = map(int, input().split())
	DIV = 10**9+7
	sqrtn = int(N**0.5)
	ans = 1
	s = []
	for i in range(1, sqrtn+1):
		s.append(i)
		if i < N//i:
			s.append(N//i)
	s.sort()

	r = []
	for i in range(len(s)-1):
		left = N//s[i+1]
		right = N//s[i]
		r.append(right-left)
	r.append(1)

	m = len(s)
	mp = {}
	for i in range(m):
		mp[s[i]] = i

	dp = [[0 for _ in range(m)] for _ in range(K+1)]
	dp[0][mp[N]] = 1
	for i in range(K):
		for j in range(m-2, -1, -1):
			dp[i][j] += dp[i][j+1]
			dp[i][j] %= DIV
		for j in range(m):
			nj = mp[N//s[j]]
			dp[i+1][j] += dp[i][nj]*r[j]%DIV
			dp[i+1][j] %= DIV

	ans = 0
	for j in range(m):
		ans += dp[K][j]
		ans %= DIV
	print(ans)


if __name__ == '__main__':
	main()
Buggy python submission (verdict: Time Limit Exceeded):
def main():
	N, M = map(int, input().split())
	S = list(map(int, input().split()))
	T = list(map(int, input().split()))
	S.append(0)
	T.append(0)
	MOD = 10**9+7

	dp0 = [[0 for _ in range(M+2)] for _ in range(N+2)]
	dp1 = [[0 for _ in range(M+2)] for _ in range(N+2)]
	dp0[0][0] = 1
	for i in range(N+1):
		for j in range(M+1):
			dp0[i+1][j] += dp0[i][j]%MOD
			dp0[i+1][j] %= MOD
			dp1[i][j] += dp0[i][j]%MOD
			dp1[i][j] %= MOD
			dp1[i][j+1] += dp1[i][j]%MOD
			dp1[i][j+1] %= MOD

			if S[i] == T[j]:
				dp0[i+1][j+1] += dp1[i][j]
				dp0[i+1][j+1] %= MOD
	print(dp1[N][M])


if __name__ == '__main__':
	main()

Fixed submission:
def main():
	N, M = map(int, input().split())
	S = list(map(int, input().split()))
	T = list(map(int, input().split()))
	S.append(0)
	T.append(0)
	MOD = 10**9+7

	dp0 = [[0 for _ in range(M+2)] for _ in range(N+2)]
	dp1 = [[0 for _ in range(M+2)] for _ in range(N+2)]
	dp0[0][0] = 1
	for i in range(N+1):
		for j in range(M+1):
			dp0[i+1][j] += dp0[i][j]
			dp0[i+1][j] %= MOD
			dp1[i][j] += dp0[i][j]
			dp1[i][j] %= MOD
			dp1[i][j+1] += dp1[i][j]
			dp1[i][j+1] %= MOD

			if S[i] == T[j]:
				dp0[i+1][j+1] += dp1[i][j]
				dp0[i+1][j+1] %= MOD
	print(dp1[N][M])


if __name__ == '__main__':
	main()
Buggy python submission (verdict: Time Limit Exceeded):
def main():
	H, W = map(int, input().split())
	S = [""]*H
	for i in range(H):
		S[i] = input()
	r = [[0 for _ in range(W)] for _ in range(H)]
	c = [[0 for _ in range(W)] for _ in range(H)]
	for i in range(H):
		for j in range(W):
			if S[i][j] == "#":
				continue
			r[i][j] = r[i][j-1]+1 if j > 0 else 1
		for j in range(W-2, -1, -1):
			if r[i][j+1] == 0 or r[i][j] == 0:
				continue
			r[i][j] = r[i][j+1]

	for j in range(W):
		for i in range(H):
			if S[i][j] == "#":
				continue
			c[i][j] = c[i-1][j]+1 if i > 0 else 1
		for i in range(H-2, -1, -1):
			if c[i+1][j] == 0 or c[i][j] == 0:
				continue
			c[i][j] = c[i+1][j]

	ans = 0
	for j in range(W):
		for i in range(H):
			ans = max(ans, c[i][j]+r[i][j]-1)
	print(ans)


if __name__ == '__main__':
	main()

Fixed submission:
def main():
	H, W = map(int, input().split())
	S = [""]*H
	for i in range(H):
		S[i] = input()
	r = [[0 for _ in range(W)] for _ in range(H)]
	c = [[0 for _ in range(W)] for _ in range(H)]
	for i in range(H):
		for j in range(W):
			if S[i][j] == "#":
				continue
			r[i][j] = r[i][j-1]+1 if j > 0 else 1
		for j in range(W-2, -1, -1):
			if r[i][j+1] == 0 or r[i][j] == 0:
				continue
			r[i][j] = r[i][j+1]

	for j in range(W):
		for i in range(H):
			if S[i][j] == "#":
				continue
			c[i][j] = c[i-1][j]+1 if i > 0 else 1
		for i in range(H-2, -1, -1):
			if c[i+1][j] == 0 or c[i][j] == 0:
				continue
			c[i][j] = c[i+1][j]

	ans = 0
	for j in range(W):
		for i in range(H):
			ans = max(ans, c[i][j]+r[i][j]-1)
	print(ans)


if __name__ == '__main__':
	main()
Buggy python submission (verdict: Time Limit Exceeded):
def main():
	N = int(input())
	A = list(map(int, input().split()))
	ans = 0
	for i in range(N):
		this_gcd = A[i-1] if i > 0 else A[i+1]
		for j in range(N):
			if i == j:
				continue
			this_gcd = gcd(this_gcd, A[j])
		ans = max(ans, this_gcd)
	print(ans)


def gcd(a, b):
	if a < b:
		a, b = b, a
	if b == 0:
		return a
	c = a % b
	return gcd(b, c)

if __name__ == '__main__':
    main()

Fixed submission:
def main():
	N = int(input())
	A = list(map(int, input().split()))
	dp_l = [0]*(N+2)
	dp_r = [0]*(N+2)

	for i in range(N):
		dp_l[i+1] = gcd(dp_l[i], A[i])

	for i in range(N-1, 0, -1):
		dp_r[i] = gcd(dp_r[i+1], A[i])

	ans = 1
	for i in range(1, N+1):
		this_ans=gcd(dp_l[i-1], dp_r[i])
		ans = max(ans, this_ans)

	print(ans)



def gcd(a, b):
	if a < b:
		a, b = b, a
	if b == 0:
		return a
	c = a % b
	return gcd(b, c)

if __name__ == '__main__':
    main()