Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p03087 (python)

Fixed submission:
N, Q = map(int, input().split())
S = input()
L = [list(map(int, input().split())) for _ in range(Q)]
t, I = 0, [0]
for i in range(1, N):
  if S[i-1]=="A":
    if S[i]=="C":
      t += 1
  I.append(t)
for l in L:
  print(I[l[1]-1]-I[l[0]-1])

Buggy submission (verdict: Runtime Error):
N,Q = map(int,input().split())
S = input()
X = [list(map(int, input().split())) for _ in range(Q)]
L =[0]*(N+1)
for i in range(N):
  if S[i]=="A" and S[i+1]=="C":
    L[i+1] = L[i]+1 
  else:
    L[i+1] = L[i]
for x in X:
  print(L[x[1]-1]-L[x[0]-1])
Problem p03136 (python)

Fixed submission:
n = int(input())
list = [int(i) for i in input().split()]

max = max(list)
sum = sum(list)

if sum > 2*max:
  print("Yes")
else:
  print("No")

Buggy submission (verdict: Runtime Error):
input()
L = map(int, input().split())
print("Yes" if sum(L)>2*max(L) else "No")
Problem p03239 (python)

Fixed submission:
N, T = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(N)]
Y = [x for x in X if x[1]<=T]
Z = [y[0] for y in Y]
print("TLE" if Y==[] else min(Z))

Buggy submission (verdict: Runtime Error):
N, T = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(N)]
Y = [X[i] if X[i][1]<=T for i in range(N)]
print(Y)
Problem p03280 (python)

Fixed submission:
a, b = map(int, input().split())
print((a-1)*(b-1))

Buggy submission (verdict: Runtime Error):
a, b = map(int, input().solit())
print((a-1)*(b-1))
Problem p03292 (python)

Fixed submission:
A_1, A_2, A_3 = (int(x) for x in input().split())
list = [A_1, A_2, A_3]
new_list = sorted(list)
print(new_list[2] - new_list[0])

Buggy submission (verdict: Runtime Error):
A_1 = int(input())
A_2 = int(input())
A_3 = int(input())

list = [A_1, A_2, A_3]
new_list = sorted(list)
print(new_list[2] - new_list[0])
Problem p03543 (python)

Fixed submission:
a, b, c, d = input()
print("Yes" if a==b==c or b==c==d else "No")

Buggy submission (verdict: Runtime Error):
a, b, c, d = input()
print("Yes" if a==b==c or b==c==f else "No")
Problem p02969 (python)

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

Buggy submission (verdict: Runtime Error):
print(3*(int(input()**2)))
Problem p03385 (python)

Fixed submission:
a= str(input())
if a=='abc':
	print("Yes")
elif a=='acb':
	print("Yes")
elif a=='bac':
	print("Yes")
elif a=='bca':
	print("Yes")
elif a== 'cab':
	print("Yes")
elif a=='cba':
	print("Yes")
else:
	print("No")

Buggy submission (verdict: Runtime Error):
x,y,z=map(int,input().split())
a=max(x,y,z)
b=min(x,y,z)
c=x+y+z-a-b
if (a-b)%2==0:
	d=(a-b)/2
	if (a-c)%2==0:
		print(int((a-c)/2+d))
	else:
		print(int((a-1-c)/2+d+2))
else:
	e=(a-b-1)/2
	if (a-c)%2==0:
		print(int((a-c)/2+2+e))
	else:
		print(int((a-1-c)/2+1+e))
Problem p03501 (python)

Fixed submission:
x,y,z=map(int,input().split())
print(min(x*y,z))

Buggy submission (verdict: Runtime Error):
x,y,z=map(int,input().split())
print(x,y,z)
a[0]=z
a[1]=x*y
print(min(a))
Problem p03693 (python)

Fixed submission:
a = list(map(int, input().split()))
x=a[0]*100+a[1]*10+a[2]
if x%4==0:
	print("YES")
else:
	print("NO")

Buggy submission (verdict: Runtime Error):
a = list(map(int, input().split()))
x=a[0]*100+a[1]*10+a[2]
if x%4=0:
	print("YES")
else:
	print("NO")
Problem p02665 (python)

Fixed submission:
#!/usr/bin/env python3
 
import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
 
n = I()
a = LI()
if n == 0:
    if a[0] == 1 or a[0] == 0:
        print(1)
        quit()
    else:
        print(-1)
        quit()
for i in range(n):
    if a[i] > 2**i - 1:
        print(-1)
        quit()
if a[-1] > 2**n:
    print(-1)
    quit()

lst = [1]
for i in range(1, n+1):
    l = lst[-1] - a[i-1]
    if l <= 0:
        print(-1)
        quit()
    lst.append(2*l)
if lst[-1] - a[-1] < 0:
    print(-1)
    quit()

i = n-1
tmp = a[-1]
ans = 0
lst2 = [a[-1]]
while i >= 0:
    tmp += a[i]
    tmp = min(tmp, 2**i)
    lst2.append(tmp)
    i -= 1
lst2 = lst2[::-1]
for i in range(n+1):
    ans += min(lst[i], lst2[i])
print(ans)

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3
 
import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
 
n = I()
a = LI()

for i in range(n):
    if a[i] > 2**i - 1:
        print(-1)
        quit()
if a[-1] > 2**(n+1):
    print(-1)
    quit()
if n == 0:
    if a[0] == 1:
        print(0)
        quit()
    else:
        if a[1] == 2:
            print(3)
            quit()
        elif a[1] == 1:
            print(2)
            quit()
lst = [1]
for i in range(1, n+1):
    l = lst[-1] - a[i-1]
    if l <= 0:
        print(-1)
        quit()
    lst.append(2*l)
i = n-1
tmp = a[-1]
ans = 0
lst2 = [a[-1]]
while i >= 0:
    tmp += a[i]
    tmp = min(tmp, 2**i)
    lst2.append(tmp)
    i -= 1
lst2 = lst2[::-1]
for i in range(n+1):
    ans += min(lst[i], lst2[i])
print(ans)
Problem p02686 (python)

Fixed submission:
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
s = [input() for _ in range(n)]
x = [] #(の方が多いもの
y = [] #)の方が多いもの
for i in range(n):
    cnt1 = 0
    cnt2 = 0
    for j in range(len(s[i])):
        if s[i][j] == '(':
            cnt1 += 1
        else:
            cnt2 += 1
    if cnt1 - cnt2 > 0:
        x.append([cnt2, cnt1, s[i]])
    else:
        y.append([cnt1, cnt2, s[i]])
x.sort() #)が少ない順
y.sort(reverse=True) #(が多い順
tmp = 0
que = deque()
for i, j, k in x:
    for l in k:
        if l == '(':
            tmp += 1
        else:
            if tmp > 0:
                tmp -= 1
            else:
                print('No')
                quit()
for i, j, k in y:
    for l in k:
        if l == '(':
            tmp += 1
        else:
            if tmp > 0:
                tmp -= 1
            else:
                print('No')
                quit()
if tmp != 0:
    print('No')
else:
    print('Yes')

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
s = [input() for _ in range(n)]
x = []
for i in range(n):
    cnt = 0
    for j in range(len(s[i])):
        if s[i][j] == '(':
            cnt += 1
        else:
            cnt -= 1
    x.append((cnt, s[i]))
x.sort(reverse=True)
x = deque(x)
tmp = deque()
stack = []
flag = False
while x:
    _, v = x.popleft()
    if v[0] == '(':
        flag = True
    if not flag:
        tmp.append(v)
    else:
        while tmp:
            _, u = tmp.popleft()
            for i in u:
                if i == '(':
                    stack.append('(')
                else:
                    if stack:
                        stack.pop()
                    else:
                        print('No')
                        quit()
        for i in v:
            if i == '(':
                stack.append('(')
            else:
                if stack:
                    stack.pop()
                else:
                    print('No')
                    quit()
if stack:
    print('No')
else:
    print('Yes')
Problem p02721 (python)

Fixed submission:
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n,k,c = LI()
s = input()
l,r = [0]*k, [0]*k
i = 0
cnt = 0
while i < n:
    if s[i] == 'o':
        if cnt >= k:
            quit()
        l[cnt] = i
        cnt += 1
        i += c
    i += 1
i = n-1
cnt = k-1
while i >= 0:
    if s[i] == 'o':
        if cnt < 0:
            quit()
        r[cnt] = i
        cnt -= 1
        i -= c
    i -= 1
for i in range(k):
    if l[i] == r[i]:
        print(l[i]+1)

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n,k,c = LI()
s = input()
t = []
for i in range(n):
    if s[i] == 'o':
        t.append(1)
    else:
        t.append(0)

r = [False]*n
l = [False]*n
flag = True
for i in range(n):
    if flag and t[i] == 1:
        flag = False
        l[i] = True
        cnt = 0
        continue
    elif not flag and cnt == c-1:
        flag = True
    cnt += 1

flag = True
for i in range(n)[::-1]:
    if flag and t[i] == 1:
        flag = False
        r[i] = True
        cnt = 0
        continue
    elif not flag and cnt == c-1:
        flag = True
    cnt += 1

for i in range(n):
    if r[i] and l[i]:
        print(i+1)
Problem p02727 (python)

Fixed submission:
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

x, y, a, b, c = LI()
p = LI()
q = LI()
r = LI()

p.sort(reverse=1)
q.sort(reverse=1)
r.sort(reverse=1)
r = list(accumulate(r))
ans = 0
h = []
s = sum(p[:x])
s += sum(q[:y])
for i in p[:x]:
    heappush(h, i)
for i in q[:y]:
    heappush(h, i)
ans = s
for i in range(c):
    if len(h) > 0:
        f = heappop(h)
    else:
        break
    s -= f
    tmp = s + r[i]
    ans = max(ans, tmp)
print(ans)

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

x, y, a, b, c = LI()
p = LI()
q = LI()
r = LI()

p.sort(reverse=1)
q.sort(reverse=1)
r.sort(reverse=1)
r = list(accumulate(r))
ans = 0
h = []
s = sum(p[:x])
s += sum(q[:y])
for i in p[:x]:
    heappush(h, i)
for i in q[:y]:
    heappush(h, i)
ans = s
for i in range(c):
    f = heappop(h)
    s -= f
    tmp = s + r[i]
    ans = max(ans, tmp)
print(ans)
Problem p02997 (python)

Fixed submission:
#!/usr/bin/env python3
#ABC131 E
import sys
import math

N, K = map(int,input().split())

if K > (N - 1)*(N - 2) // 2:
    print(-1)
    exit()

print((N - 1)*(N - 2) // 2 + (N - 1) - K)
for i in range(N - 1):
    print(1,i+2)
s = 2
t = 3
for i in range((N - 1)*(N - 2) // 2 - K):
    print(s,t)
    t += 1
    if t > N:
        s += 1
        t = s + 1

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3
#ABC131 E
import sys
import math
import networkx as nx

N, K = map(int,input().split())

if K > (N - 1)*(N - 2) // 2:
    print(-1)
    exit()

print((N - 1)*(N - 2) // 2 + (N - 1) - K)
for i in range(N - 1):
    print(1,i+2)
k = 2
for i in range(N,2,-1):
    if (i - 1)*(i - 2)//2 == K:
        break
    for j in range(k,N):
        print(k,j+1)
    k += 1
Problem p03006 (python)

Fixed submission:
#!/usr/bin/env python3
#diverta B

import sys

def main():
	N = int(input())
	xy = []
	for i in range(N):
		x, y = map(int, input().split(" "))
		xy.append((x, y))

	if N == 1:
		print(1)
		sys.exit()

	re = {}
	for i, val in enumerate(xy):
		x, y = val
		for j, vol in enumerate(xy):
			if i == j:
				continue
			nx, ny = vol
			p = nx - x
			q = ny -y
			if (p, q) in re:
				re[(p, q)] += 1
			else:
				re[(p, q)] = 1


	ans = N - max(re.values())

	print(ans)


if __name__ == "__main__":
	main()

Buggy submission (verdict: Runtime Error):
N = int(input())

a = [list(map(int,input().split())) for _ in range(N)]
def count(a1,a2,n,a):
    count = [0 for i in range(len(a) - n)]
    #print(count)
    x1 = a1[0]
    y1 = a1[1]
    x2 = a2[0]
    y2 = a2[1]
    if x1 != x2:
        #print(1)
        for j in range(len(a)-n):
            #print(a[j][1] - ((y1 - y2)/(x1 - x2))*(a[j][0] - x1) - y1)
            if (a[j][1] - ((y1 - y2)/(x1 - x2))*(a[j][0] - x1) - y1) == 0:
                count[j] += 1
    else:
        for j in range(n,len(a)):
            if a[j][0] == x1:
                count[j] += 1
    if len(count) != 0:
        return max(count)
    else:
        return 0
if N == 1 or N == 2:
    print(1)
    exit()
ans = []
for i in range(N):
    for j in range(i+1,N):
        ans.append(count(a[i],a[j],j+1,a))
        #print(count(a[i],a[j],j+1,a))
print(int(N//2) + 1 - max(ans))
Problem p03048 (python)

Fixed submission:
import re
         
a,b,c,n = list(map(int,re.split(" ",input())))
N = n
s = []
s.append(a)
s.append(b)
s.append(c)
s.sort()
a,b,c = s
#print(a,b,c)
ans = 0
for i in range(int(N/c)+1):
  for j in range(int((N-i*c)/b)+1):
      if (N - i*c  - j*b)%a == 0:
        ans += 1
print(ans)

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3
#B
import numpy as np
import math
import re
     
a,b,c,n = list(map(int,re.split(" ",input())))
N = n
s = []
s.append(a)
s.append(b)
s.append(c)
s.sort()
a,b,c = s
#print(a,b,c)
ans = 0
for i in range(int(N/c)+1):
  for j in range(int((N-i*c)/b)+1):
	if (N - i*c  - j*b)%a == 0:
		ans += 1
print(ans)
Problem p03061 (python)

Fixed submission:
#!/usr/bin/env python3
#C
def gcd(a, b):
    while b > 0:
        a, b = b, a%b
    return a

N = int(input())
A = list(map(int,input().split()))
L=[0]*(N+2)
R=[0]*(N+2)
L[0] = A[0]
R[N-1] = A[N-1]
for i in range(1,N):
    L[i] = gcd(L[i-1],A[i])
for i in range(N-2,-1,-1):
    R[i] = gcd(R[i+1],A[i])

ans = 0
for i in range(N):
    ans = max(ans,gcd(L[i-1],R[i+1]))
print(ans)

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3
#C
import numpy as np
import math
import re
import functools
def gcd_list(x):
    return functools.reduce(math.gcd, x)

n = int(input())
a = input()
a = re.split(" ",a)
a = list(map(int,a))

m = 0
for i in range(n):
    s = []
    for j in range(n):
        if (j != i):
            s.append(a[j])
    x = gcd_list(s)
    if(x > m):
        m = x
print(m)

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3
#C
import numpy as np
import math
import re
import functools
def gcd_list(numbers):
    return functools.reduce(math.gcd, numbers)

n = int(input())
a = input()
a = re.split(" ",a)
a = list(map(int,a))

m = 0
for i in range(n):
    s = []
    for j in range(n):
        if j != i:
            s.append(a[j])
    x = gcd_list(s)
    if(x > m):
        m = x
print(m)

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3
#C
import numpy as np
import math
import re
from functools import reduce
def gcd_list(numbers):
    return reduce(math.gcd, numbers)
print(gcd_list([1]))
n = int(input())
a = input()
a = re.split(" ",a)
a = list(map(int,a))

m = 0
for i in range(n):
    s = []
    for j in range(n):
        if j != i:
            s.append(a[j])
    x = gcd_list(s)
    if(x > m):
        m = x
print(m)

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3
#C
import numpy as np
import math
import re
from functools import reduce

n = int(input())
a = input()
a = re.split(" ",a)
a = list(map(int,a))
def gcd_list(numbers):
    return reduce(math.gcd, numbers)

m = 0
for i in range(n):
    s = []
    for j in range(n):
        if j != i:
            s.append(a[j])
    x = gcd_list(s)
    if(x > m):
        m = x
print(m)

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3
#C
import numpy as np
import math
import re
from functools import reduce

n = int(input())

a = input()
a = re.split(" ",a)
a = list(map(int,a))
def gcd_list(numbers):
    return reduce(math.gcd, numbers)

m = 0
for i in range(n):
    s = []
    for j in range(n):
        if j != i:
            s.append(a[j])
    x = gcd_list(s)
    if(x > m):
        m = x
print(m)

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3
#C
import numpy as np
import math
import re
from functools import reduce

n = int(input())

a = input()
a = re.split(" ",a)
a = list(map(int,a))
def gcd_list(numbers):
    return reduce(math.gcd, numbers)

m = 0
for i in range(n):
    s = []
    for j in range(n):
        if j != i:
            s.append(a[j])
    x = gcd_list(s)
    if(x > m):
        m = x
print(m)
Problem p03086 (python)

Fixed submission:
#!/usr/bin/env python3

a = input()

l = ["A","T","G","C"]
count  = 0
max = 0
t = 0
for i in range(len(a)):
    for j in range(i,len(a)):
        if(a[j] not in l):
            count = 0
            break;
        else:
            count += 1
            if(max < count):
                max = count
    count = 0
print(max)

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

s = input()
n = len(s)
ans = 0
lst = ['A','T','G','C']
for i in range(n):
    if s[i] not in lst:
        continue
    for j in range(i+1,n):
        if s[j] not in lst:
            break
    ans = max(ans,j-i)
print(ans)
Problem p03096 (python)

Fixed submission:
#!/usr/bin/env python3
#AGC31 B

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
c = [I() for _ in range(n)]
dp1,dp2 = [0]*(n+1),[0]*(max(c)+1)
dp1[0] = 1
for i in range(n):
    if dp2[c[i]] == 0:
        dp1[i+1] = dp1[i]
        dp2[c[i]] = dp1[i]
        dp2[c[i]] %= mod
    else:
        if c[i] == c[i-1]:
            dp1[i+1] = dp1[i]
            continue
        dp1[i+1] += dp2[c[i]]
        dp1[i+1] += dp1[i]
        dp2[c[i]] += dp1[i]
        dp2[c[i]] %= mod
        dp1[i+1] %= mod
print(dp1[-1] % mod)

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3
#AGC31 B

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
c = [I() for _ in range(n)]
dp1,dp2 = [0]*(n+1),[0]*(max(c)+1)
dp1[0] = 1
for i in range(n):
    if dp2[c[i]] == 0:
        dp1[i+1] = dp1[i]
        dp2[c[i]] += dp1[i+1]
        dp2[c[i]] %= mod
    else:
        if c[i] == c[i-1]:
            dp1[i+1] = dp1[i]
            dp2[c[i]] += dp1[i+1]
            dp2[c[i]] %= mod
            continue
        dp1[i+1] += dp1[dp2[c[i]]+1]
        dp1[i+1] += dp1[i]
        dp2[c[i]] += dp1[i+1]
        dp2[c[i]] %= mod
        dp1[i+1] %= mod
print(dp1[-1] % mod)
Problem p03128 (python)

Fixed submission:
#!/usr/bin/env python3
#ABC118 D

import sys
import math
import bisect
from heapq import heappush, heappop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
mod = 10**9 + 7

M = [0,2,5,5,4,5,6,3,7,6]
n,m = map(int,input().split())
a = list(map(int,input().split()))
A = [[i,M[i]] for i in a]
A.sort(key = itemgetter(1))

#dp[i] := ちょうどマッチi本を使ってできる最大桁数
dp = [-float('inf')]*(n+1)
dp[0] = 0
for i in range(n):
    for j,k in A:
        if i + k < n+1:
            if dp[i] < 0:
                continue
            dp[i+k] = dp[i] + 1
A.sort(key = itemgetter(0),reverse = True)
ans = ''
k = n
while 1:
    for i,j in A:
        if k - j < 0:
            continue
        if dp[k-j] == dp[k]-1:
            ans += str(i)
            k -= j
            break
    else:
        break
print(ans)

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3
#ABC118 D

import sys
import math
import bisect
from heapq import heappush, heappop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
mod = 10**9 + 7

M = [0,2,5,5,4,5,6,3,7,6]
n,m = map(int,input().split())
a = list(map(int,input().split()))
A = [[i,M[i]] for i in a]
A.sort(key = itemgetter(1))

#dp[i] := ちょうどマッチi本を使ってできる最大桁数
dp = [-float('inf')]*(n+1)
dp[0] = 0
for i in range(n):
    for j,k in A:
        if i + k < n+1:
            if dp[i] < 0:
                continue
            dp[i+k] = dp[i] + 1
A.sort(key = itemgetter(0),reverse = True)
ans = ''
k = n
while 1:
    for i,j in A:
        if dp[k-j] == dp[k]-1:
            ans += str(i)
            k -= j
            break
    else:
        break
print(ans)