Buggy python submission (verdict: Time Limit Exceeded):
import sys
input=sys.stdin.readline

def main():
  def dp(i):
    for a,b in AB:
      C[i]=min(C[i],C[i-a if i>a else 0]+b)

  H,N=map(int,input().split())
  AB=[list(map(int,input().split())) for _ in range(N)]
  C=[0]+[10**8]*H

  for i in range(1,H+1):
    dp(i)

  print(C[H])

if __name__=='__main__':
	main()


Fixed submission:
import sys
input=sys.stdin.readline

def main():
  def dp(i):
    for a,b in AB:
      T=C[i-a if i>a else 0]+b
      C[i]=T if T<C[i] else C[i]

  H,N=map(int,input().split())
  AB=[list(map(int,input().split())) for _ in range(N)]
  C=[0]+[10**8]*H

  for i in range(1,H+1):
    dp(i)

  print(C[H])

if __name__=='__main__':
	main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input=sys.stdin.readline

def main():
  def dp(i):
    for a,b in AB:
      C[i]=min(C[i],C[i-a if i>a else 0]+b)

  H,N=map(int,input().split())
  AB=[list(map(int,input().split())) for _ in range(N)]
  C=[0]+[10**8]*H

  for i in range(1,H+1):
    dp(i)

  print(C[H])

if __name__=='__main__':
	main()


Fixed submission:
import sys
input=sys.stdin.readline

def main():
  def dp(i):
    for a,b in AB:
      T=C[i-a if i>a else 0]+b
      C[i]=T if T<C[i] else C[i]

  H,N=map(int,input().split())
  AB=[list(map(int,input().split())) for _ in range(N)]
  C=[0]+[10**8]*H

  for i in range(1,H+1):
    dp(i)

  print(C[H])

if __name__=='__main__':
	main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input=sys.stdin.readline

def dp(i):
  for a,b in AB:
    T=C[i-a if i>a else 0]+b
    C[i]=T if T<C[i] else C[i]

H,N=map(int,input().split())
AB=[list(map(int,input().split())) for _ in range(N)]
C=[0]+[10**8]*H

for i in range(1,H+1):
  dp(i)

print(C[H])


Fixed submission:
import sys
input=sys.stdin.readline

def main():
  def dp(i):
    for a,b in AB:
      T=C[i-a if i>a else 0]+b
      C[i]=T if T<C[i] else C[i]

  H,N=map(int,input().split())
  AB=[list(map(int,input().split())) for _ in range(N)]
  C=[0]+[10**8]*H

  for i in range(1,H+1):
    dp(i)

  print(C[H])

if __name__=='__main__':
	main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input=sys.stdin.readline

def dp(i):
  for a,b in AB:
    C[i]=min(C[i],C[i-a if i>a else 0]+b)

H,N=map(int,input().split())
AB=[list(map(int,input().split())) for _ in range(N)]
C=[0]+[10**8]*H

for i in range(1,H+1):
  dp(i)

print(C[H])


Fixed submission:
import sys
input=sys.stdin.readline

def main():
  def dp(i):
    for a,b in AB:
      T=C[i-a if i>a else 0]+b
      C[i]=T if T<C[i] else C[i]

  H,N=map(int,input().split())
  AB=[list(map(int,input().split())) for _ in range(N)]
  C=[0]+[10**8]*H

  for i in range(1,H+1):
    dp(i)

  print(C[H])

if __name__=='__main__':
	main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
  def dp(i):
    for a,b in AB:
      C[i]=min(C[i],C[i-a if i>a else 0]+b)

  H,N=map(int,input().split())
  AB=[list(map(int,input().split())) for _ in range(N)]
  C=[0]+[10**8]*H

  for i in range(1,H+1):
    dp(i)

  print(C[H])

if __name__=='__main__':
  main()


Fixed submission:
import sys
input=sys.stdin.readline

def main():
  def dp(i):
    for a,b in AB:
      T=C[i-a if i>a else 0]+b
      C[i]=T if T<C[i] else C[i]

  H,N=map(int,input().split())
  AB=[list(map(int,input().split())) for _ in range(N)]
  C=[0]+[10**8]*H

  for i in range(1,H+1):
    dp(i)

  print(C[H])

if __name__=='__main__':
	main()

Buggy python submission (verdict: Time Limit Exceeded):
def dp(i):
  for a,b in AB:
    C[i]=min(C[i],C[i-a if i>a else 0]+b)

H,N=map(int,input().split())
AB=[list(map(int,input().split())) for _ in range(N)]
C=[0]+[10**8]*H

for i in range(1,H+1):
  dp(i)

print(C[H])


Fixed submission:
import sys
input=sys.stdin.readline

def main():
  def dp(i):
    for a,b in AB:
      T=C[i-a if i>a else 0]+b
      C[i]=T if T<C[i] else C[i]

  H,N=map(int,input().split())
  AB=[list(map(int,input().split())) for _ in range(N)]
  C=[0]+[10**8]*H

  for i in range(1,H+1):
    dp(i)

  print(C[H])

if __name__=='__main__':
	main()