Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):

import math

input1 = int(input())

if input1 == 2:
    print(2)

else:

    for b in range(100000):
        result = 0
        X = input1 + b
        for a in range(int(math.sqrt(X))):
            if X % (a + 2) == 0:
                result += 1
                break
            else:
                result += 0
        if result == 0:
            break

print(X)



Fixed submission:
# coding cell (SUBMIT ONLY THIS CELL)

import math

X = int(input())
temp = False

if X == 2:
    print(2)
    exit()

if X % 2 == 0:
    X += 1

while temp == False:

    for i in range(int(math.sqrt(X) // 2)):
        if X % (2 * (i + 1) + 1) != 0:
            temp = True
        else:
            temp = False
            break

    X += 2        
    
print(X - 2)

Buggy python submission (verdict: Runtime Error):
input1 = int(input())

from sympy import nextprime
print(nextprime(input1))


Fixed submission:
# coding cell (SUBMIT ONLY THIS CELL)

import math

X = int(input())
temp = False

if X == 2:
    print(2)
    exit()

if X % 2 == 0:
    X += 1

while temp == False:

    for i in range(int(math.sqrt(X) // 2)):
        if X % (2 * (i + 1) + 1) != 0:
            temp = True
        else:
            temp = False
            break

    X += 2        
    
print(X - 2)
Buggy python submission (verdict: Time Limit Exceeded):
input1= input()
A = int(input1.split()[0])
B = int(input1.split()[1])


C = A * B

for i in range(C):
    while A%(i+2) == 0 and B%(i+2) == 0:
        C = C / (i+2)
        A = A / (i+2)
        B = B / (i+2)



print(int(C))

Fixed submission:
import math

input1= input()
A = int(input1.split()[0])
B = int(input1.split()[1])


C = A * B
C_sqrt_int = int(math.sqrt(C))

for i in range(C_sqrt_int):
    while A%(i+2) == 0 and B%(i+2) == 0:
        C = C / (i+2)
        A = A / (i+2)
        B = B / (i+2)


print(int(C))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())

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

count = 0
S = 0
while count <= N:
    for i in range(S,N):
        try:
            if line[i] == i + 1:
                S = i
            else:
                line.pop(i)
                break
        except:
            break
    count += 1


if len(line) == 0:
    print(-1)
else:
    print(N - len(line))

Fixed submission:
N = int(input())
line = list(map(int,input().split()))

checkNum = 1
howMany = 0

for j in range(N):
    if line[j] == checkNum:
        checkNum += 1
    else:
        howMany += 1

# print(line)
# print(checkNum)
# print(howMany)

if checkNum == 1:
    print("-1")
else:
    print(howMany)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())

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

count = 0
while count <= N:
    for i in range(N):
        try:
            if line[i] == i + 1:
                True
            else:
                line.pop(i)
                break
        except:
            break
    count += 1


if len(line) == 0:
    print(-1)
else:
    print(N - len(line))

Fixed submission:
N = int(input())
line = list(map(int,input().split()))

checkNum = 1
howMany = 0

for j in range(N):
    if line[j] == checkNum:
        checkNum += 1
    else:
        howMany += 1

# print(line)
# print(checkNum)
# print(howMany)

if checkNum == 1:
    print("-1")
else:
    print(howMany)

Buggy python submission (verdict: Time Limit Exceeded):
input1 = input()
input2 = input()
N = int(input1)
list_an = input2.split()
list_an = list(map(int,list_an))

list_an_sub = []


total = 0

def check():
    check_total = 0
    for i in range(len(list_an)):
        if list_an[i] == i+1:
            check_total += 0
        else:
            check_total += 1
    if check_total == 0:
        return 1
    if check_total == 0:
        return 0
                

while check() is None:
    for i in range(len(list_an)):
        if i <= len(list_an):
            if list_an[i] == i+1:
                total += 0
            else:
                del(list_an[i])
                total += 1
                break
        else:
            break
   
if list_an == []:
    print(-1)
else:
    print(total)

Fixed submission:
N = int(input())
line = list(map(int,input().split()))

checkNum = 1
howMany = 0

for j in range(N):
    if line[j] == checkNum:
        checkNum += 1
    else:
        howMany += 1

# print(line)
# print(checkNum)
# print(howMany)

if checkNum == 1:
    print("-1")
else:
    print(howMany)
Buggy python submission (verdict: Runtime Error):
input1 = input()
A1 = int(input1.split([0]))
A2 = int(input1.split([1]))
A3 = int(input1.split([2]))

if A1+A2+A3 > 21:
    print("bust")
else:
    print("win")

Fixed submission:
input1 = input()
A1 = int(input1.split()[0])
A2 = int(input1.split()[1])
A3 = int(input1.split()[2])

if A1+A2+A3 > 21:
    print("bust")
else:
    print("win")
Buggy python submission (verdict: Time Limit Exceeded):
import queue
import collections

N = int(input())
Ss = []
for i in range(N):
    Ss.append(input())

c = collections.Counter(Ss)
mc = c.most_common()
_, prev = mc[0]
q = queue.PriorityQueue()
for k, v in mc:
    if prev != v:
        break
    q.put(k)
    prev = v

while not(q.empty()):
    print(q.get())


Fixed submission:
import queue
import collections

N = int(input())
Ss = [input() for i in range(N)]

mc = collections.Counter(Ss).most_common()
_, prev = mc[0]
q = queue.PriorityQueue()
for k, v in mc:
    if prev != v:
        break
    q.put(k)
    prev = v

while not(q.empty()):
    print(q.get())
Buggy python submission (verdict: Time Limit Exceeded):
from scipy.misc import comb

N, K = map(int, input().split())
As = sorted(list(map(int, input().split())))

upper = 0
lower = 0
for i in range(N - K + 1):
    c = comb(K + i - 1, i, exact=True)
    upper = (upper + (As[K + i - 1] * c)) % (10 ** 9 + 7)
    lower = (lower + (As[N - K - i] * c)) % (10 ** 9 + 7)
print(((upper - lower) % (10 ** 9 + 7) + 10 ** 9 + 7) % (10 ** 9 + 7))

Fixed submission:
# from scipy.misc import comb

def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

N, K = map(int, input().split())
As = sorted(list(map(int, input().split())))

mod = 10**9+7 #出力の制限
# N = 10**4
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

upper = 0
lower = 0
for i in range(N - K + 1):
    # c = comb(K + i - 1, i, exact=True)
    c = cmb(K + i - 1, i, mod)
    upper = (upper + (As[K + i - 1] * c)) % (10 ** 9 + 7)
    lower = (lower + (As[N - K - i] * c)) % (10 ** 9 + 7)
print(((upper - lower) % (10 ** 9 + 7) + 10 ** 9 + 7) % (10 ** 9 + 7))

Buggy python submission (verdict: Runtime Error):
from scipy.special import comb

N, K = map(int, input().split())
As = sorted(list(map(int, input().split())))

upper = 0
lower = 0
for i in range(N - K + 1):
    c = comb(K + i - 1, i, exact=True)
    upper = (upper + (As[K + i - 1] * c)) % (10 ** 9 + 7)
    lower = (lower + (As[N - K - i] * c)) % (10 ** 9 + 7)
print(((upper - lower) % (10 ** 9 + 7) + 10 ** 9 + 7) % (10 ** 9 + 7))

Fixed submission:
# from scipy.misc import comb

def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

N, K = map(int, input().split())
As = sorted(list(map(int, input().split())))

mod = 10**9+7 #出力の制限
# N = 10**4
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

upper = 0
lower = 0
for i in range(N - K + 1):
    # c = comb(K + i - 1, i, exact=True)
    c = cmb(K + i - 1, i, mod)
    upper = (upper + (As[K + i - 1] * c)) % (10 ** 9 + 7)
    lower = (lower + (As[N - K - i] * c)) % (10 ** 9 + 7)
print(((upper - lower) % (10 ** 9 + 7) + 10 ** 9 + 7) % (10 ** 9 + 7))
Buggy python submission (verdict: Runtime Error):
import math


A, B = map(int, input().split())
lcm = A * B / math.gcd(A, B)
print(int(lcm))

Fixed submission:
import fractions


A, B = map(int, input().split())
lcm = A * B / fractions.gcd(A, B)
print(int(lcm))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
v = list(map(int, input().split()))
v_odd = v[0::2]
v_even = v[1::2]
chars_odd = list(set(v_odd))
chars_even = list(set(v_even))
odd_cnt = [[0, '_']]
for char in chars_odd:
    cnt_odd = v_odd.count(char)
    odd_cnt.append([cnt_odd, char])
odd_cnt.sort(reverse=True)
even_cnt = [[0, '_']]
for char in chars_even:
    cnt_even = v_even.count(char)
    even_cnt.append([cnt_even, char])
even_cnt.sort(reverse=True)
if odd_cnt[0][1] == even_cnt[0][1]:
    res = max(odd_cnt[0][0] + even_cnt[1][0], odd_cnt[1][0] + even_cnt[0][0])
else:
    res = odd_cnt[0][0] + even_cnt[0][0]
print(n - res)

Fixed submission:
n = int(input())
v = list(map(int, input().split()))
v_odd = v[0::2]
v_even = v[1::2]
chars_odd = list(set(v_odd))
cnt_odd = dict()
for char in chars_odd:
    cnt_odd[char] = 0
for char in v_odd:
    cnt_odd[char] += 1
odd_cnt = sorted(cnt_odd.items(), key=lambda x:x[1], reverse=True)
odd_cnt.append(('_', 0))

chars_even = list(set(v_even))
cnt_even = dict()
for char in chars_even:
    cnt_even[char] = 0
for char in v_even:
    cnt_even[char] += 1
even_cnt = sorted(cnt_even.items(), key=lambda x:x[1], reverse=True)
even_cnt.append(('_', 0))

if odd_cnt[0][0] == even_cnt[0][0]:
    res = max(odd_cnt[0][1] + even_cnt[1][1], odd_cnt[1][1] + even_cnt[0][1])
else:
    res = odd_cnt[0][1] + even_cnt[0][1]
print(n - res)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
a = list(map(int, input().split()))
cnt = 0
S = 0
for i in range(100000):
    tmp = a.count(i + 1)
    S += tmp
    if tmp > i + 1:
        cnt += tmp - i - 1
    elif tmp < i + 1:
        cnt += tmp
cnt += N - S
print(cnt)


Fixed submission:
N = int(input())
a = list(map(int, input().split()))
tmp = 1
cnt = 0
S = 0
a.sort()
a.append(0)
for i in range(N):
    if a[i] == a[i + 1]:
        tmp += 1
    else:
        if tmp > a[i]:
            cnt += tmp - a[i]
        elif tmp < a[i]:
            cnt += tmp
        tmp = 1
print(cnt)
Buggy python submission (verdict: Time Limit Exceeded):
N , K = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
cnt = []
while len(A) > 0:
    temp = A[0]
    i_cnt = 0
    while A[0] == temp:
        i_cnt += 1
        del A[0]
        if len(A) == 0:
            break
    cnt.append(i_cnt)
cnt.sort()
result = 0
for i in range(len(cnt) - K):
    result += cnt[i]
print(result)

Fixed submission:
N , K = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
A.append(0)
cnt = []
i_cnt = 1
for i in range(N):
    if A[i] == A[i + 1]:
        i_cnt += 1
    else:
        cnt.append(i_cnt)
        i_cnt = 1
cnt.sort()
result = 0
for i in range(len(cnt) - K):
    result += cnt[i]
print(result)

Buggy python submission (verdict: Time Limit Exceeded):
N , K = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
cnt = []
while len(A) > 0:
    temp = A[0]
    cnt.append(A.count(temp))
    for j in range(cnt[-1]):
        A.remove(temp)
cnt.sort()
result = 0
for i in range(len(cnt) - K):
    result += cnt[i]
print(result)

Fixed submission:
N , K = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
A.append(0)
cnt = []
i_cnt = 1
for i in range(N):
    if A[i] == A[i + 1]:
        i_cnt += 1
    else:
        cnt.append(i_cnt)
        i_cnt = 1
cnt.sort()
result = 0
for i in range(len(cnt) - K):
    result += cnt[i]
print(result)
Buggy python submission (verdict: Runtime Error):
N = int(input())
l = 2
r = 1
for i in range(N - 1):
    L = l + r
    l = r
    r = L
print(L)

Fixed submission:
N = int(input())
if N == 1:
    print(1)
else:
    l = 2
    r = 1
    for i in range(N - 1):
        L = l + r
        l = r
        r = L
    print(L)
Buggy python submission (verdict: Runtime Error):
S = input().strip()
T = input().strip()
rS = []
for i in range(len(S)):
    rS.append(S[i])
for i in range(len(rS) - len(T)):
    eq = True
    for j in range(len(T)):
        if not(rS[- i - j - 1] == T[- j - 1] or rS[- i - j - 1] == "?"):
            eq = not(eq)
            break
    if eq:
        for j in range(len(T)):
            rS[- i - j - 1] = T[- j - 1]
        break
if eq:
    for i in range(len(rS)):
        if rS[i] == "?":
            rS[i] = "a"
    for i in range(len(rS)):
        print(rS[i], end='')
    print("")
else:
    print("UNRESTORABLE")

Fixed submission:
S = input().strip()
T = input().strip()
rS = []
if len(S) >= len(T):
    for i in range(len(S)):
        rS.append(S[i])
    for i in range(len(rS) - len(T), -1, -1):
        eq = True
        for j in range(len(T)):
            if not(rS[i + j] == T[j] or rS[i + j] == "?"):
                eq = not(eq)
                break
        if eq:
            for j in range(len(T)):
                rS[i + j] = T[j]
            break
    if eq:
        for i in range(len(rS)):
            if rS[i] == "?":
                rS[i] = "a"
        for i in range(len(rS)):
            print(rS[i], end='')
        print("")
    else:
        print("UNRESTORABLE")
else:
    print("UNRESTORABLE")

Buggy python submission (verdict: Runtime Error):
S = input().strip()
T = input().strip()
rS = []
for i in range(len(S)):
    rS.append(S[i])
for i in range(len(rS) - len(T), -1, -1):
    eq = True
    for j in range(len(T)):
        if not(rS[i + j] == T[j] or rS[i + j] == "?"):
            eq = not(eq)
            break
    if eq:
        for j in range(len(T)):
            rS[i + j] = T[j]
        break
if eq:
    for i in range(len(rS)):
        if rS[i] == "?":
            rS[i] = "a"
    for i in range(len(rS)):
        print(rS[i], end='')
    print("")
else:
    print("UNRESTORABLE")

Fixed submission:
S = input().strip()
T = input().strip()
rS = []
if len(S) >= len(T):
    for i in range(len(S)):
        rS.append(S[i])
    for i in range(len(rS) - len(T), -1, -1):
        eq = True
        for j in range(len(T)):
            if not(rS[i + j] == T[j] or rS[i + j] == "?"):
                eq = not(eq)
                break
        if eq:
            for j in range(len(T)):
                rS[i + j] = T[j]
            break
    if eq:
        for i in range(len(rS)):
            if rS[i] == "?":
                rS[i] = "a"
        for i in range(len(rS)):
            print(rS[i], end='')
        print("")
    else:
        print("UNRESTORABLE")
else:
    print("UNRESTORABLE")
Buggy python submission (verdict: Time Limit Exceeded):
import math
import bisect
#[int(x) for x in input().split()]
#map(int,input().split())
#for _ in range(int(input())):
n=int(input())
l=[int(x) for x in input().split()]
p=1
M=10**18
f=0
for i in range(n):
	p*=l[i]

if p>M:
	print(-1)
	f=1
	
if f==0:
	print(p)



Fixed submission:
import math
import bisect
#[int(x) for x in input().split()]
#map(int,input().split())
#for _ in range(int(input())):
n=int(input())
l=[int(x) for x in input().split()]
p=1
M=10**18
f=0
if 0 in l:
	print(0)
else:	
	for i in range(n):
		p*=l[i]
		if p>M:
			print(-1)
			f=1
			break
	if f==0:
		print(p)
Buggy python submission (verdict: Runtime Error):
import math
import bisect
#[int(x) for x in input().split()]
#map(int,input().split())
#for _ in range(int(input())):
a,b=input().split()
a=int(a)
b=b.split('.')
b=int(b)

print(int(((a*b)/100)))

Fixed submission:
import math
import bisect
#[int(x) for x in input().split()]
#map(int,input().split())
#for _ in range(int(input())):
a,b=input().split()
a=int(a)
b=list(b.split("."))
b=''.join(b)
b=int(b)

print(a*b//100)
Buggy python submission (verdict: Runtime Error):
#[int(x) for x in input().split()]
#map(int,input().split())
#for _ in range(int(input())):
x=input()
l=list(x)
c=0
for i in range(len(l)):
	if l[i]=='?':
		if i-1<0:
			if l[i+1]=='D':
				l[i]='P'
			elif l[i+1]=='?':
				l[i]='P'
			else:
				l[i]='D'
		elif l[i-1]=='P':
			l[i]='D'
		elif i+1<len(l):
			if l[i+1]=='D':
				l[i]='P'
			elif l[i+1]=='?':
				l[i]='P'
			else:
				l[i]='D'
		else:
			l[i]='D'
print(''.join(l))


Fixed submission:
#[int(x) for x in input().split()]
#map(int,input().split())
#for _ in range(int(input())):
x=input()
l=list(x)
c=0
for i in range(len(l)):
	if l[i]=='?':
		if i-1<0:
			if i+1<len(l):
				if l[i+1]=='D':
					l[i]='P'
				elif l[i+1]=='?':
					l[i]='P'
				else:
					l[i]='D'
			else:
				l[i]='D'
		elif l[i-1]=='P':
			l[i]='D'
		elif i+1<len(l):
			if l[i+1]=='D':
				l[i]='P'
			elif l[i+1]=='?':
				l[i]='P'
			else:
				l[i]='D'
		else:
			l[i]='D'
print(''.join(l))
Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int,raw_input().split())
d={}
for i in xrange(m):
	x,y=map(int,raw_input().split())
	if x in d:
		d[x].append(y)
	else:
		d[x]=[y]
	if y in d:
		d[y].append(x)
	else:
		d[y]=[x]

parent=[0]*(n+1)
bfs=[1]
visited=set([1])
while len(bfs)!=0:
	x=bfs.pop(0)
	visited.add(x)
	for i in d[x]:
		if i not in visited:
			bfs.append(i)
			parent[i]=x
			visited.add(i)


if len(visited)==n:
	print('Yes')
	for i in xrange(2,n+1):
		print(parent[i])
else:
	print('No')




Fixed submission:
n,m=map(int,input().split())
d={}
for i in range(m):
	x,y=map(int,input().split())
	if x in d:
		d[x].append(y)
	else:
		d[x]=[y]
	if y in d:
		d[y].append(x)
	else:
		d[y]=[x]

parent=[0]*(n+1)
bfs=[1]
visited=set([1])
while len(bfs)!=0:
	x=bfs.pop(0)
	visited.add(x)
	for i in d[x]:
		if i not in visited:
			bfs.append(i)
			parent[i]=x
			visited.add(i)


if len(visited)==n:
	print('Yes')
	for i in range(2,n+1):
		print(parent[i])
else:
	print('No')

Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int,input().split())
d={}
for i in range(m):
	x,y=map(int,input().split())
	if x in d:
		d[x].append(y)
	else:
		d[x]=[y]
	if y in d:
		d[y].append(x)
	else:
		d[y]=[x]

parent=[0]*(n+1)
bfs=[1]
visited=set([1])
while len(bfs)!=0:
	x=bfs.pop(0)
	visited.add(x)
	for i in d[x]:
		if i not in visited:
			bfs.append(i)
			parent[i]=x
			visited.add(i)


if len(visited)==n:
	print('Yes')
	for i in range(2,n+1):
		print(parent[i])
else:
	print('No')




Fixed submission:
n,m=map(int,input().split())
d={}
for i in range(m):
	x,y=map(int,input().split())
	if x in d:
		d[x].append(y)
	else:
		d[x]=[y]
	if y in d:
		d[y].append(x)
	else:
		d[y]=[x]

parent=[0]*(n+1)
bfs=[1]
visited=set([1])
while len(bfs)!=0:
	x=bfs.pop(0)
	visited.add(x)
	for i in d[x]:
		if i not in visited:
			bfs.append(i)
			parent[i]=x
			visited.add(i)


if len(visited)==n:
	print('Yes')
	for i in range(2,n+1):
		print(parent[i])
else:
	print('No')
Buggy python submission (verdict: Runtime Error):
from sys import stdin, stdout
cnt=0
def check(a,b):
    global cnt
    for i in range(len(a)):
        cnt-=a[i][0]
        if cnt<0:
            return False
        cnt+=a[i][1]

    for i in range(len(b)):
        cnt-=b[i][0]
        if cnt<0:
            return False
        cnt+=b[i][1]
    if cnt==0:
        return True
    return False

a=[]
b=[]
for i in range(int(input())):
    s=stdin.readline().strip()
    #print(s)
    ans=''
    for j in range(len(s)):
        if s[j]=='(':
            ans+='('
        else:
            if len(ans)==0:
                ans+=')'
                continue
            if ans[-1]=='(':
                ans=ans[:-1]
            else:
                ans+=')'
    L=0
    for j in range(len(ans)):
        if ans[j]==')':
            L+=1
        else:
            break
    R=len(ans)-L
    if L<R:
        a.append((L,R))
    else:
        b.append((L,R))

    a.sort()
    b.sort(key=lambda x:x[1],reverse=True)
    #print(a,b)
if check(a,b):
    print('Yes')
else:
    print('No')


Fixed submission:
#int(input())
#int(x) for x in input().split()
#map(int,input().split())
x=input()
y=input()
if x==y[:-1]:
	print('Yes')
else:
	print('No')
Buggy python submission (verdict: Time Limit Exceeded):
import math
from collections import Counter
n=int(input())
l=[int(x) for x in input().split()]
f1=[]
f2=[]
for i in range(1,len(l)+1):
	f1.append(i-l[i-1])
	f2.append(l[i-1]+i)

c=0
for i in range(len(l)):
	c+=f1.count(f2[i])
print(c)




Fixed submission:
n=int(input())
l=[int(x) for x in input().split()]
f1={}
f2={}
for i in range(1,len(l)+1):
	if i-l[i-1] in f1:
		f1[i-l[i-1]]+=1
	else:
		f1[i-l[i-1]]=1
	if l[i-1]+i in f2:
		f2[l[i-1]+i]+=1
	else:
		f2[l[i-1]+i]=1

c=0
#print(f1)
#print(f2)
for u,v in f1.items():
	c+=f2.get(u,0)*v
print(c)
Buggy python submission (verdict: Time Limit Exceeded):
n,k=map(int,input().split())
l=[int(x) for x in input().split()]
dp=[0 for i in range(k+1)]
dp[0]=1
for i in range(len(l)):
	p=[0]*(k+1)
	for j in range(k-1,-1,-1):
		li= j+1
		ri=j+min(l[i],k-j)+1
		if li<=ri:
			p[j+1]+=dp[j]
		if ri<=k:
			p[j+min(l[i],k-j)+1]-=dp[j]
		'''for o in range(j+1,j+min(l[i],k-j)+1):
			dp[o]+=dp[j]'''
	su=0
	for i in range(k+1):
		su+=p[i]
		dp[i]+=su
print(dp[k]%(10**9+7))
#print(dp[0][n-1])

Fixed submission:
n,k=map(int,input().split())
l=[int(x) for x in input().split()]
dp=[0 for i in range(k+1)]
dp[0]=1
M=10**9+7
for i in range(len(l)):
	p=[0]*(k+1)
	for j in range(k-1,-1,-1):
		li= j+1
		ri=j+min(l[i],k-j)+1
		if li<=ri:
			p[j+1]+=dp[j]
		if ri<=k:
			p[j+min(l[i],k-j)+1]-=dp[j]
		'''for o in range(j+1,j+min(l[i],k-j)+1):
			dp[o]+=dp[j]'''
	su=0
	for i in range(k+1):
		su=(su+p[i])%M
		dp[i]=(dp[i]+su)%M
print(dp[k]%(10**9+7))
#print(dp[0][n-1])
Buggy python submission (verdict: Time Limit Exceeded):
n,k=map(int,input().split())
P=list(map(int,input().split()))
for i in range(n):
	P[i]-=1
C=list(map(int,input().split()))
ANS=-float('inf')
for i in range(n):
    snp=P[i]
    r=C[snp]
    L=[r]
    c=0
    np=P[snp]
    while True:
        if c==k-1:
            ANS=max(max(L),ANS)
            break
        if np==snp:
            y=k%(c+1)
            m=k//(c+1)
            if y==0:
                ANS=max(max(L),max(L)+(m-1)*L[-1],ANS)
                break
            else:
                ANS=max(max(L),max(max(L[:y]),0)+m*L[-1],ANS)
                break
        r+=C[np]
        L.append(r)
        np=P[np]
        c+=1
print(ANS)


Fixed submission:
n,k=map(int,input().split())
P=list(map(int,input().split()))
for i in range(n):
	P[i]-=1
C=list(map(int,input().split()))
ANS=-float('inf')
for i in range(n):
    snp=P[i]
    r=C[snp]
    L=[r]
    c=0
    np=P[snp]
    while True:
        if c==k-1:
            ANS=max(max(L),ANS)
            break
        if np==snp:
            y=k%(c+1)
            m=k//(c+1)
            if y==0:
                ANS=max(max(L),max(L)+(m-1)*L[-1],ANS)
                break
            else:
                #print(m,y)
                #print(L)
                ANS=max(max(L),max(max(L[:y]),0)+m*L[-1],ANS)
                break
        r+=C[np]
        L.append(r)
        np=P[np]
        c+=1
print(ANS)
Buggy python submission (verdict: Runtime Error):
x,n=map(int,input().split())
if n==0:
    print(x)
else:
    P=list(map(int,input().split()))
    N=[i for i in range(1,101)]

    for p in P:
        N.pop(N.index(p))

    L=[]
    for a in N:
        l=abs(a-x)
        L.append(l)
    
    m=L.index(min(L))
    print(N[m])

Fixed submission:
x,n=map(int,input().split())
if n==0:
    print(x)
else:
    P=list(map(int,input().split()))
    N=[i for i in range(0,102)]

    for p in P:
        N.pop(N.index(p))

    L=[]
    for a in N:
        l=abs(a-x)
        L.append(l)
    
    m=L.index(min(L))
    print(N[m])

Buggy python submission (verdict: Runtime Error):
x,n=map(int,input().split())
if n==0:
    print(x)
else:
    P=list(map(int,input().split()))
    N=[i for i in range(1,101)]

    for p in P:
        N.pop(N.index(p))

    L=[]
    for i in range(n):
        l=abs(N[i]-x)
        L.append(l)
    m=L.index(min(L))
    print(N[m])

Fixed submission:
x,n=map(int,input().split())
if n==0:
    print(x)
else:
    P=list(map(int,input().split()))
    N=[i for i in range(0,102)]

    for p in P:
        N.pop(N.index(p))

    L=[]
    for a in N:
        l=abs(a-x)
        L.append(l)
    
    m=L.index(min(L))
    print(N[m])