Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    N, M = map(int, input().split())
    l = []
    for _ in range(N):
        a, b = map(int, input().split())
        if a > M:
            continue
        l.append((a,b))
    l.sort(key=lambda x: x[0])
    t = {}
    i = 0
    r = 0
    for d in range(1, M+1):
        while i < len(l):
            a, b = l[i]
            if a <= d:
                if b in t:
                    t[b] += 1
                else:
                    t[b] = 1
            else:
                break
            i += 1
        if not t:
            continue
        m = max(t)
        if t[m] == 1:
            t.pop(m)
        else:
            t[m] -= 1
        r += m
    return r
print(main())


Fixed submission:
import heapq
def main():
    N, M = map(int, input().split())
    l = []
    for _ in range(N):
        a, b = map(int, input().split())
        if a > M:
            continue
        l.append((a,b))
    l.sort(key=lambda x: x[0])
    t = []
    i = 0
    r = 0
    for d in range(1, M+1):
        while i < len(l):
            a, b = l[i]
            if a <= d:
                heapq.heappush(t, -b)
            else:
                break
            i += 1
        if not t:
            continue
        r -= heapq.heappop(t)
    return r
print(main())

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    N, M = map(int, input().split())
    l = []
    for _ in range(N):
        a, b = map(int, input().split())
        if a > M:
            continue
        l.append((a,b))
    l.sort(key=lambda x: x[0])
    t = {}
    i = 0
    r = 0
    for d in range(1, M+1):
        while i < len(l):
            a, b = l[i]
            if a <= d:
                if b in t:
                    t[b] += 1
                else:
                    t[b] = 1
            else:
                break
            i += 1
        if not t:
            continue
        m = max(t)
        if t[m] == 1:
            t.pop(m)
        else:
            t[m] -= 1
        r += m
    return r
print(main())


Fixed submission:
import heapq
def main():
    N, M = map(int, input().split())
    l = []
    for _ in range(N):
        a, b = map(int, input().split())
        if a > M:
            continue
        l.append((a,b))
    l.sort(key=lambda x: x[0])
    t = []
    i = 0
    r = 0
    for d in range(1, M+1):
        while i < len(l):
            a, b = l[i]
            if a <= d:
                heapq.heappush(t, -b)
            else:
                break
            i += 1
        if not t:
            continue
        r -= heapq.heappop(t)
    return r
print(main())
Buggy python submission (verdict: Time Limit Exceeded):

def main():
    L = input()
    n = len(L)
    t = []
    mod = 10 ** 9 + 7
    for i, v in enumerate(L):
        if v == '1':
            t.append(i)
    r = 1
    for i in reversed(t):
        r *= 2
        r += 3 ** (n - i - 1)
        r %= mod
    print(r % mod)
main()


Fixed submission:

def main():
    L = input()
    n = len(L)
    t = []
    mod = 10 ** 9 + 7
    for i, v in enumerate(L):
        if v == '1':
            t.append(i)
    r = 1
    p = 1
    for i, v in enumerate(reversed(L)):
        p %= mod
        if v == '1':
            r *= 2
            r += p
            r %= mod
        p *= 3
    print(r % mod)
main()

Buggy python submission (verdict: Time Limit Exceeded):

def main():
    L = input()
    n = len(L)
    t = []
    mod = 10 ** 9 + 7
    for i, v in enumerate(L):
        if v == '1':
            t.append(i)
    r = 1
    for i in reversed(t):
        r *= 2
        r += 3 ** (n - i - 1)
    print(r % mod)
main()


Fixed submission:

def main():
    L = input()
    n = len(L)
    t = []
    mod = 10 ** 9 + 7
    for i, v in enumerate(L):
        if v == '1':
            t.append(i)
    r = 1
    p = 1
    for i, v in enumerate(reversed(L)):
        p %= mod
        if v == '1':
            r *= 2
            r += p
            r %= mod
        p *= 3
    print(r % mod)
main()

Buggy python submission (verdict: Time Limit Exceeded):

def main():
    L = input()
    n = len(L)
    t = []
    mod = 10 ** 9 + 7
    for i, v in enumerate(L):
        if v == '1':
            t.append(i)
    r = 1
    for i in reversed(t):
        r *= 2
        r += 3 ** (n - i - 1)
    print(r % mod)
main()


Fixed submission:

def main():
    L = input()
    n = len(L)
    t = []
    mod = 10 ** 9 + 7
    for i, v in enumerate(L):
        if v == '1':
            t.append(i)
    r = 1
    p = 1
    for i, v in enumerate(reversed(L)):
        p %= mod
        if v == '1':
            r *= 2
            r += p
            r %= mod
        p *= 3
    print(r % mod)
main()
Buggy python submission (verdict: Runtime Error):
r, d, x = map(int, input().split())
for i in range(10):
	x = r * x - d
    print(x)

Fixed submission:
r, d, x = map(int, input().split())
for i in range(10):
    x = r * x - d
    print(x)
Buggy python submission (verdict: Time Limit Exceeded):
import heapq
def main():
    N, M = map(int, input().split())
    A = list(map(int, input().split()))
    heapq.heapify(A)
    for _ in range(M):
        b, c = map(int, input().split())
        for i in range(b):
            if A[0] < c:
                heapq.heappushpop(A, c)
            else:
                break
    return sum(A)
print(main())



Fixed submission:
import heapq
def main():
    N, M = map(int, input().split())
    A = list(map(int, input().split()))
    B = [(1, -i) for i in A]
    heapq.heapify(A)
    for _ in range(M):
        b, c = map(int, input().split())
        B.append((b,-c))
    B.sort(key=lambda x: x[1])
    t = 0
    i = 0
    tl = []
    while t < N:
        tl.extend([-B[i][1]] * B[i][0])
        t += B[i][0]
        i += 1
    return sum(tl[:(N)])
print(main())

Buggy python submission (verdict: Time Limit Exceeded):
import heapq
def main():
    N, M = map(int, input().split())
    A = list(map(int, input().split()))
    heapq.heapify(A)
    for _ in range(M):
        b, c = map(int, input().split())
        for i in range(b):
            if A[0] < c:
                heapq.heappushpop(A, c)
            else:
                break
    return sum(A)
print(main())



Fixed submission:
import heapq
def main():
    N, M = map(int, input().split())
    A = list(map(int, input().split()))
    B = [(1, -i) for i in A]
    heapq.heapify(A)
    for _ in range(M):
        b, c = map(int, input().split())
        B.append((b,-c))
    B.sort(key=lambda x: x[1])
    t = 0
    i = 0
    tl = []
    while t < N:
        tl.extend([-B[i][1]] * B[i][0])
        t += B[i][0]
        i += 1
    return sum(tl[:(N)])
print(main())
Buggy python submission (verdict: Runtime Error):
import math
def main():
    N, K = map(int, input().split())
    l = [0] * (math.ceil(math.log2(K)) + 1)
    t = 2
    for i in range(len(l)):
        l[i] = t * 1/2
        t = l[i]
    p = 0
    for i in range(1, min(K, N+1)):
        p += l[math.ceil(math.log2(K/i))]
    p += max(N-K + 1, 0)
    p /= N
    return p

print(main())


Fixed submission:
import math
def main():
    N, K = map(int, input().split())
    l = [0] * (math.ceil(math.log2(K)) + 1)
    t = 2
    for i in range(len(l)):
        l[i] = t * 1/2
        t = l[i]
    p = 0
    for i in range(1, min(K, N+1)):
        p += l[math.ceil(math.log2(K/i))]
    p += max(N-K + 1, 0)
    p /= N
    return p

print(main())
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    N = int(input())
    d = {}
    for _ in range(N-1):
        u, v, w = map(int, input().split())
        w %= 2
        if u in d:
            d[u].append((v, w))
        else:
            d[u] = [(v,w)]
        if v in d:
            d[v].append((u, w))
        else:
            d[v] = [(u,w)]
    cur = [1]
    nextp = []
    l = [0] * N
    v = set([1])
    while v != set(range(1,N+1)):
        for i in cur:
            for j, k in d[i]:
                if j not in v:
                    if k:
                        l[j-1] = 1 - l[i-1]
                    else:
                        l[j-1] = l[i-1]
                    v.add(j)
                    nextp.append(j)
        cur = nextp
        nextp = []
    return l
l = main()
for i in l:
    print(i)



Fixed submission:
def main():
    N = int(input())
    d = {}
    for _ in range(N-1):
        u, v, w = map(int, input().split())
        w %= 2
        if u in d:
            d[u].append((v, w))
        else:
            d[u] = [(v,w)]
        if v in d:
            d[v].append((u, w))
        else:
            d[v] = [(u,w)]
    cur = [1]
    nextp = []
    l = [0] * N
    v = set(range(1, N+1))
    while v:
        for i in cur:
            v.remove(i)
            for j, k in d[i]:
                if j in v:
                    l[j-1] = 1 - l[i-1] if k else l[i-1]
                    nextp.append(j)
        cur = nextp
        nextp = []
    return l
l = main()
for i in l:
    print(i)

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    N = int(input())
    d = {}
    for _ in range(N-1):
        u, v, w = map(int, input().split())
        w %= 2
        if u in d:
            d[u].append((v, w))
        else:
            d[u] = [(v,w)]
        if v in d:
            d[v].append((u, w))
        else:
            d[v] = [(u,w)]
    cur = [1]
    nextp = []
    l = [0] * N
    v = set([1])
    while v != set(range(1,N+1)):
        for i in cur:
            for j, k in d[i]:
                if j not in v:
                    if k:
                        l[j-1] = 1 - l[i-1]
                    else:
                        l[j-1] = l[i-1]
                    v.add(j)
                    nextp.append(j)
        cur = nextp
        nextp = []
    return l
l = main()
for i in l:
    print(i)



Fixed submission:
def main():
    N = int(input())
    d = {}
    for _ in range(N-1):
        u, v, w = map(int, input().split())
        w %= 2
        if u in d:
            d[u].append((v, w))
        else:
            d[u] = [(v,w)]
        if v in d:
            d[v].append((u, w))
        else:
            d[v] = [(u,w)]
    cur = [1]
    nextp = []
    l = [0] * N
    v = set(range(1, N+1))
    while v:
        for i in cur:
            v.remove(i)
            for j, k in d[i]:
                if j in v:
                    l[j-1] = 1 - l[i-1] if k else l[i-1]
                    nextp.append(j)
        cur = nextp
        nextp = []
    return l
l = main()
for i in l:
    print(i)
Buggy python submission (verdict: Runtime Error):
import bisect
def main():
    N = int(input())
    A = list(map(int, input().split()))
    A.sort()
    i = bisect.bisect_left(A, 0)
    j = bisect.bisect_right(A, 0)
    if i % 2 == 0:
        print(sum([abs(i) for i in A]))
    else:
        if i != j:
            print(sum([abs(i) for i in A]))
        elif i == N:
            print(sum([abs(i) for i in A]) - 2 * A[-1])
        else:
            if A[i] > A[i+1]:
                print(sum([abs(i) for i in A]) - 2 * A[i+1])
            else:
                print(sum([abs(i) for i in A]) - 2 * A[i])
main()


Fixed submission:
import bisect
def main():
    N = int(input())
    A = list(map(int, input().split()))
    A.sort()
    i = bisect.bisect_left(A, 0)
    j = bisect.bisect_right(A, 0)
    if i % 2 == 0:
        print(sum([abs(i) for i in A]))
    else:
        if i != j:
            print(sum([abs(i) for i in A]))
        elif i == N:
            print(sum([abs(i) for i in A]) - 2 * abs(A[-1]))
        else:
            if abs(A[i-1]) > A[i]:
                print(sum([abs(i) for i in A]) - 2 * abs(A[i]))
            else:
                print(sum([abs(i) for i in A]) - 2 * abs(A[i-1]))
main()
Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
h = list(map(int, input().split()))
m = [0] * n
m[0] = 0
for i in range(1, n):
    m[i] = min(m[j] + abs(h[j] - h[i]) for j in range(max(0, i-k),i))
print(m[-1])


Fixed submission:
def main():
    n, k = map(int, input().split())
    h = list(map(int, input().split()))
    m = [0] * n
    m[0] = 0
    for i in range(1, n):
        m[i] = min(m[j] + abs(h[j] - h[i]) for j in range(max(0, i-k),i))
    print(m[-1])

main()

Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
h = list(map(int, input().split()))
m = [0] * n
m[0] = 0
for i in range(1, n):
    m[i] = min(m[j] + abs(h[j] - h[i]) for j in range(max(0, i-k),i))
print(m[n-1])


Fixed submission:
def main():
    n, k = map(int, input().split())
    h = list(map(int, input().split()))
    m = [0] * n
    m[0] = 0
    for i in range(1, n):
        m[i] = min(m[j] + abs(h[j] - h[i]) for j in range(max(0, i-k),i))
    print(m[-1])

main()

Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
h = list(map(int, input().split()))
m = [0] * n
m[0] = 0
for i in range(1, n):
    t = k if i >= k else i
    m[i] = min(m[i - j - 1] + abs(h[i - j - 1] - h[i]) for j in range(t))
print(m[n-1])


Fixed submission:
def main():
    n, k = map(int, input().split())
    h = list(map(int, input().split()))
    m = [0] * n
    m[0] = 0
    for i in range(1, n):
        m[i] = min(m[j] + abs(h[j] - h[i]) for j in range(max(0, i-k),i))
    print(m[-1])

main()

Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
h = list(map(int, input().split()))
m = [0] * n
m[0] = 0
for i in range(1, n):
    m[i] = float('inf')
    t = k if i >= k else i
    for j in range(t):
        m[i] = min(m[i], m[i - j - 1] + abs(h[i - j - 1] - h[i]))
print(m[n-1])


Fixed submission:
def main():
    n, k = map(int, input().split())
    h = list(map(int, input().split()))
    m = [0] * n
    m[0] = 0
    for i in range(1, n):
        m[i] = min(m[j] + abs(h[j] - h[i]) for j in range(max(0, i-k),i))
    print(m[-1])

main()
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    n, m = map(int, input().split())
    w = [0] * n
    v = [0] * n
    for i in range(n):
        wt, vt = list(map(int, input().split()))
        w[i] = wt
        v[i] = vt
    l = [0] * (m + 1)
    for i in range(n):
        for j in range(m, -1, -1):
            l[j] = max(v[i] + l[j-w[i]], l[j]) if j - w[i] >= 0 else l[j]
    print(l[-1])
main()


Fixed submission:
def main():
    n, m = map(int, input().split())
    w = [0] * n
    v = [0] * n
    for i in range(n):
        w[i], v[i] = list(map(int, input().split()))
    l = [0] * (m + 1)
    for i in range(n):
        for j in range(m, w[i] - 1, -1):
            x = v[i] + l[j-w[i]]
            if x > l[j]:
                l[j] = x
    print(l[-1])
main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    n, m = map(int, input().split())
    w = [0] * n
    v = [0] * n
    for i in range(n):
        wt, vt = list(map(int, input().split()))
        w[i] = wt
        v[i] = vt
    l = [0] * (m + 1)
    for i in range(n):
        l= [max(v[i] + l[j-w[i]], l[j]) if j - w[i] >= 0 else l[j] for j in range(m+1)]
    print(l[-1])
main()


Fixed submission:
def main():
    n, m = map(int, input().split())
    w = [0] * n
    v = [0] * n
    for i in range(n):
        w[i], v[i] = list(map(int, input().split()))
    l = [0] * (m + 1)
    for i in range(n):
        for j in range(m, w[i] - 1, -1):
            x = v[i] + l[j-w[i]]
            if x > l[j]:
                l[j] = x
    print(l[-1])
main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    n, m = map(int, input().split())
    w = [0] * n
    v = [0] * n
    for i in range(n):
        wt, vt = list(map(int, input().split()))
        w[i] = wt
        v[i] = vt
    l = [[0] * (m + 1) for _ in range(n)]
    for i in range(n):
        for j in range(m+1):
            if j - w[i] >= 0:
                l[i][j] = max(v[i] + l[i-1][j-w[i]], l[i-1][j])
            else:
                l[i][j] = l[i-1][j]
    print(l[-1][-1])
main()


Fixed submission:
def main():
    n, m = map(int, input().split())
    w = [0] * n
    v = [0] * n
    for i in range(n):
        w[i], v[i] = list(map(int, input().split()))
    l = [0] * (m + 1)
    for i in range(n):
        for j in range(m, w[i] - 1, -1):
            x = v[i] + l[j-w[i]]
            if x > l[j]:
                l[j] = x
    print(l[-1])
main()
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    n, m = map(int, input().split())
    w = [0] * n
    v = [0] * n
    for i in range(n):
        w[i], v[i] = list(map(int, input().split()))
    t = sum(v) + 1
    l = [m + 1] * (t + 1) 
    for i in range(n):
        for j in range(t, v[i] - 1, -1):
            k = l[j - v[i]] + w[i]
            if j == v[i] and w[i] < l[j]:
                l[j] = w[i]
            elif k < l[j]:
                l[j] = k
    for i in range(t, 0, -1):
        if l[i] <= m:
            print(i)
            break
main()


Fixed submission:
def main():
    n, m = map(int, input().split())
    w = [0] * n
    v = [0] * n
    for i in range(n):
        w[i], v[i] = list(map(int, input().split()))
    t = sum(v)
    l = [m + 1] * (t + 1)
    l[0] = 0
    for i in range(n):
        for j in range(t, v[i] - 1, -1):
            k = l[j - v[i]] + w[i]
            if k < l[j]:
                l[j] = k
    for i in range(t, 0, -1):
        if l[i] <= m:
            print(i)
            break
main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    n, m = map(int, input().split())
    w = [0] * n
    v = [0] * n
    for i in range(n):
        w[i], v[i] = list(map(int, input().split()))
    t = sum(v) + 1
    l = [float('inf')] * (t + 1) 
    for i in range(n):
        for j in range(t, v[i] - 1, -1):
            if j == v[i]:
                l[j] = min(l[j], w[i])
            elif l[j - v[i]] + w[i] < l[j]:
                l[j] = l[j - v[i]] + w[i]
    for i in range(t, 0, -1):
        if l[i] <= m:
            print(i)
            break
main()


Fixed submission:
def main():
    n, m = map(int, input().split())
    w = [0] * n
    v = [0] * n
    for i in range(n):
        w[i], v[i] = list(map(int, input().split()))
    t = sum(v)
    l = [m + 1] * (t + 1)
    l[0] = 0
    for i in range(n):
        for j in range(t, v[i] - 1, -1):
            k = l[j - v[i]] + w[i]
            if k < l[j]:
                l[j] = k
    for i in range(t, 0, -1):
        if l[i] <= m:
            print(i)
            break
main()
Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(3000)
def main():
    N, M = map(int, input().split())
    d = {}
    for _ in range(M):
        x, y = map(int, input().split())
        if x in d:
            d[x].append(y)
        else:
            d[x] = [y]
    l = {}
    m = 0
    for i in d:
        m = max(m, dfs(i, d, l))
    print(m)
def dfs(node, d, l):
    if node in l:
        return l[node]
    if node not in d:
        return 0
    a = 1 + max(dfs(i, d, l) for i in d[node])
    l[node] = a
    return a

main()





Fixed submission:
import sys
sys.setrecursionlimit(1000000)
def main():
    N, M = map(int, input().split())
    d = {}
    for _ in range(M):
        x, y = map(int, input().split())
        if x in d:
            d[x].append(y)
        else:
            d[x] = [y]
    l = {}
    m = 0
    for i in d:
        m = max(m, dfs(i, d, l))
    print(m)
def dfs(node, d, l):
    if node in l:
        return l[node]
    if node not in d:
        return 0
    a = 1 + max(dfs(i, d, l) for i in d[node])
    l[node] = a
    return a

main()
Buggy python submission (verdict: Runtime Error):
from functools import lru_cache
import sys
sys.setrecursionlimit(100000000)
N = int(input())
def main():
    a = list(map(int, input().split()))
    d = {0:0, 1:0, 2:0, 3:0}
    for i in a:
        d[i] += 1
    print(dfs(d[1],d[2],d[3]))
@lru_cache(maxsize=None)
def dfs(a, b, c):
    if a + b + c == 0:
        return 0
    t1 = t2 = t3 = 0
    total = a + b + c
    if a > 0:
        t1 = (a/total) * dfs(a-1, b, c)
    if b > 0:
        t2 = (b/total) * dfs(a+1, b-1, c)
    if c > 0:
        t3 = (c/total) * dfs(a, b+1, c-1)
    return N/total + t1 + t2 + t3
main()



Fixed submission:
def main():
    N = int(input())
    p = list(map(float, input().split()))
    a = [[0] * (N + 1) for _ in range(N)]
    a[0][1] = p[0]
    a[0][0] = 1 - p[0]
    for i in range(1, N):
        a[i][0] = a[i - 1][0] * (1 - p[i])
        for j in range(1, i + 2):
            a[i][j] = a[i - 1][j - 1] * p[i] + a[i - 1][j]* (1 - p[i])
    print(sum(a[-1][(N+1)//2:]))
main()
Buggy python submission (verdict: Time Limit Exceeded):
from functools import lru_cache
import sys
sys.setrecursionlimit(100000000)
N = int(input())
def main():
    a = list(map(int, input().split()))
    d = {0:0, 1:0, 2:0, 3:0}
    for i in a:
        d[i] += 1
    print(dfs(d[1],d[2],d[3]))
@lru_cache(maxsize=None)
def dfs(a, b, c):
    if a + b + c == 0:
        return 0
    t1 = t2 = t3 = 0
    total = a + b + c
    if a > 0:
        t1 = (a/total) * dfs(a-1, b, c)
    if b > 0:
        t2 = (b/total) * dfs(a+1, b-1, c)
    if c > 0:
        t3 = (c/total) * dfs(a, b+1, c-1)
    return N/total + t1 + t2 + t3
main()



Fixed submission:
N = int(input())
def main():
    a = list(map(int, input().split()))
    d = {0:0, 1:0, 2:0, 3:0}
    for i in a:
        d[i] += 1
    d1 = d[1]
    d123 = d[1] + d[2] + d[3]
    d23 = d[2] + d[3]
    d3 = d[3]
    d2 = d[2]
    l = [[[0] * (d123 + 1) for _ in range(d23 + 1)] for _ in range(d3 + 1)]
    for i in range(d3 + 1):
        for j in range(d23 + 1):
            for k in range(d123 + 1):
                if i + j + k == 0:
                    continue
                if i + j + k > d123:
                    continue
                if i + j > d23:
                    continue
                total = i + j + k
                a = b = c = 0
                if k > 0:
                    a = k * l[i][j][k-1]
                if j > 0:
                    b = j * l[i][j-1][k + 1]
                if i > 0:
                    c = i * l[i-1][j + 1][k]
                l[i][j][k] = (a + b + c + N)/total
    print(l[d3][d2][d1])
main()

Buggy python submission (verdict: Runtime Error):
from functools import lru_cache
N = int(input())
def main():
    a = list(map(int, input().split()))
    d = {0:0, 1:0, 2:0, 3:0}
    for i in a:
        d[i] += 1
    print(dfs(d[1],d[2],d[3]))
@lru_cache(maxsize=None)
def dfs(a, b, c):
    if a + b + c == 0:
        return 0
    t1 = t2 = t3 = 0
    total = a + b + c
    if a > 0:
        t1 = (a/total) * dfs(a-1, b, c)
    if b > 0:
        t2 = (b/total) * dfs(a+1, b-1, c)
    if c > 0:
        t3 = (c/total) * dfs(a, b+1, c-1)
    return N/total + t1 + t2 + t3
main()



Fixed submission:
N = int(input())
def main():
    a = list(map(int, input().split()))
    d = {0:0, 1:0, 2:0, 3:0}
    for i in a:
        d[i] += 1
    d1 = d[1]
    d123 = d[1] + d[2] + d[3]
    d23 = d[2] + d[3]
    d3 = d[3]
    d2 = d[2]
    l = [[[0] * (d123 + 1) for _ in range(d23 + 1)] for _ in range(d3 + 1)]
    for i in range(d3 + 1):
        for j in range(d23 + 1):
            for k in range(d123 + 1):
                if i + j + k == 0:
                    continue
                if i + j + k > d123:
                    continue
                if i + j > d23:
                    continue
                total = i + j + k
                a = b = c = 0
                if k > 0:
                    a = k * l[i][j][k-1]
                if j > 0:
                    b = j * l[i][j-1][k + 1]
                if i > 0:
                    c = i * l[i-1][j + 1][k]
                l[i][j][k] = (a + b + c + N)/total
    print(l[d3][d2][d1])
main()
Buggy python submission (verdict: Time Limit Exceeded):
from functools import lru_cache
import sys
sys.setrecursionlimit(10**6)
N, K = map(int, input().split())
a = tuple(map(int, input().split()))

def main():
    if dfs(K):
        print('First')
    else:
        print('Second')
@lru_cache(maxsize=None)
def dfs(n):
    if n < a[0]:
        return False
    for i in a:
        if not dfs(n-i):
            return True
    return False

main()


Fixed submission:
N, K = map(int, input().split())
a = tuple(map(int, input().split()))

def main():
    l = [False] * (K+1)
    for i in range(a[0] -1, K+1):
        l[i] = any(not l[i-j] if i >= j else False for j in a)
    if l[-1]:
        print('First')
    else:
        print('Second')


main()