Problem:


Score : 100 points

Problem Statement

There is a set A = \{ a_1, a_2, \ldots, a_N \} consisting of N positive integers.
Taro and Jiro will play the following game against each other.

Initially, we have a pile consisting of K stones.
The two players perform the following operation alternately, starting from Taro:

Choose an element x in A, and remove exactly x stones from the pile.

A player loses when he becomes unable to play.
Assuming that both players play optimally, determine the winner.

Constraints

All values in input are integers.

1 \leq N \leq 100

1 \leq K \leq 10^5

1 \leq a_1 < a_2 < \cdots < a_N \leq K

Input

Input is given from Standard Input in the following format:

N K
a_1 a_2 \ldots a_N

Output

If Taro will win, print First; if Jiro will win, print Second.

Sample Input 1

2 4
2 3

Sample Output 1

First

If Taro removes three stones, Jiro cannot make a move.
Thus, Taro wins.

Sample Input 2

2 5
2 3

Sample Output 2

Second

Whatever Taro does in his operation, Jiro wins, as follows:

If Taro removes two stones, Jiro can remove three stones to make Taro unable to make a move.

If Taro removes three stones, Jiro can remove two stones to make Taro unable to make a move.

Sample Input 3

2 7
2 3

Sample Output 3

First

Taro should remove two stones. Then, whatever Jiro does in his operation, Taro wins, as follows:

If Jiro removes two stones, Taro can remove three stones to make Jiro unable to make a move.

If Jiro removes three stones, Taro can remove two stones to make Jiro unable to make a move.

Sample Input 4

3 20
1 2 3

Sample Output 4

Second

Sample Input 5

3 21
1 2 3

Sample Output 5

First

Sample Input 6

1 100000
1

Sample Output 6

Second



Sample input:
2 4
2 3


Sample output:
First

Submission status: Wrong Answer

Solution code:
# @author 

import sys

class KStones:
    def solve(self):
        n, k = [int(_) for _ in input().split()]
        a = [int(_) for _ in input().split()]
        dp = [0] * (k + 1) # can we win with i remaining ?
        for i in range(min(a), k + 1):
            dp[i] = int(any(not dp[i - x] for x in a))
        
        print("First" if dp[k] else "Second")

solver = KStones()
input = sys.stdin.readline

solver.solve()

Submission status: Wrong Answer

Solution code:
N,K = map(int, input().split())
A = list(map(int, input().split()))
A.sort()

dp = [0] * (K+1)
for a in A:
    for i in range(K+1):
        if dp[i] == 0:
            if i+a <= K:
                dp[i+a] = 1

if dp[K] == 1:
    print('First')
else:
    print('Second')

Submission status: Wrong Answer

Solution code:
n,k = map(int,input().split())
A = [int(i) for i in input().split()]

dp = ["Secocd"]+["First"]*k
for i in range(1,k+1):
    win = "Second"
    for a in A:
        if i-a >= 0 and dp[i-a] == "Second":
            win = "First"
    dp[i] = win
print(dp[k])

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
a_s = list(map(int, input().split()))
dp = ["Second"] * (k + 1)
for i in range(k + 1):
    if dp[i] == "Second":
        for a in a_s:
            ii = i + a
            if ii <= k:
                dp[ii] = "First"
print(dp)

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
a = list(map(int, input().split()))

dp = [False]*(k+1)
for i in range(1, k):
    flag = False
    for ai in a:
        if i-ai >= 0 and  not dp[i-ai]:
            flag = True
            break
    dp[i] = flag

if dp[-1]:
    print("First")
else:
    print("Second")

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
A = [int(i) for i in input().split()]

dp = [None] * (K + 1)  # Firstの勝ちの時にTrue
dp[0] = False
for k in range(1, K + 1):
    for a in A:
        if a <= k:
            dp[k] = not dp[k - a]
            break
    if dp[k] is None:
        dp[k] = False

print('First' if dp[-1] else 'Second')

Submission status: Wrong Answer

Solution code:
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
sys.setrecursionlimit(1000000)
mod = 1000000007


#A
def A():
    n,k = LI()
    a = LI()
    dp = [-1 for i in range(k+1)]
    for i in range(min(a)):
        dp[i] = 1
    for i in range(k):
        for j in range(n):
            if dp[i] != -1:
                if i+a[j] <= k:
                    if dp[i+a[j]] == -1:
                        dp[i+a[j]] = 1-dp[i]
                    elif dp[i+a[j]] != 1-dp[i]:
                        if i+a[j] - max(a) >= min(a):
                            dp[i+a[j]] = 1-dp[i]
    if dp[k]:
        print("Second")
    else:
        print("First")
#B
def B():
    return

#C
def C():
    return

#D
def D():
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == "__main__":
    A()

Submission status: Wrong Answer

Solution code:
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007

#A
def A():
    """
    N個の足場があります。足場には1,2,…,Nと番号が振られています。 
    各i (1≤i≤N) について、足場 i の高さは hi です。
    最初、足場 1 にカエルがいます。 カエルは次の行動を何回か繰り返し、足場 N まで辿り着こうとしています。
    足場 i にいるとき、足場 i+1 または i+2 へジャンプする。
    このとき、ジャンプ先の足場を j とすると、コスト |hi−hj| を支払う。
    カエルが足場 N に辿り着くまでに支払うコストの総和の最小値を求めてください。

    制約
        入力はすべて整数である。
    2≤N≤10**5
    1≤hi≤10**4
    """
    n = II()
    h = LI()
    dp = [0 for i in range(n)]
    dp[1] = abs(h[0] - h[1])
    for i in range(2,n):
        dp[i] = min(dp[i - 1] + abs(h[i - 1] - h[i]), dp[i - 2] + abs(h[i - 2] - h[i]))
    print(dp[n-1])
    return

#B
def B():
    n, K = LI()
    h = LI()
    dp = [float("INF") for i in range(n + K + 1)]
    dp[0] = 0
    for i in range(n):
        for k in range(1, K + 1):
            if i + k >= n:
                break
            dp[i + k] = min(dp[i + k], dp[i] + abs(h[i] - h[i + k]))
    print(dp[n-1])
    return

#C
def C():
    n = II()
    abc = LIR(n)
    dp = [0 for i in range(3 * n + 1)]
    dp[0] = abc[0][0]
    dp[1] = abc[0][1]
    dp[2] = abc[0][2]
    for i in range(1,n):
        dp[3 * i] = max(dp[3 * i], dp[3 * (i - 1) + 1] + abc[i][0], dp[3 * (i - 1) + 2] + abc[i][0])
        dp[3 * i + 1] = max(dp[3 * i + 1], dp[3 * (i - 1) + 2] + abc[i][1], dp[3 * (i - 1)] + abc[i][1])
        dp[3 * i + 2] = max(dp[3 * i + 2], dp[3 * (i - 1) + 1] + abc[i][2], dp[3 * (i - 1)] + abc[i][2])
    dp[3 * n] = max(dp)
    print(dp[3*n])

    return

#D
def D():
    """N個の品物があります。 品物には 1,2,…,Nと番号が振られています。 
    各 i (1≤i≤N) について、品物i の重さはwi で、価値はvi です。
    太郎君は、N 個の品物のうちいくつかを選び、ナップサックに入れて持ち帰ることにしました。 
    ナップサックの容量は W であり、持ち帰る品物の重さの総和は W以下でなければなりません。
    太郎君が持ち帰る品物の価値の総和の最大値を求めてください
    
    入力はすべて整数である。
    1≤N≤100
    1≤W≤10**5
    1≤wi≤W
    1≤vi≤10**9"""
    n, w = LI()
    wv = LIR(n)
    dp = [[0 for k in range(w + 1)] for i in range(n + 2)]
    for i in range(1,n + 1):
        for j in range(w + 1):
            if j < wv[i-1][0]:
                dp[i + 1][j] = dp[i][j]
            else:
                dp[i + 1][j] = max(dp[i][j], dp[i][j - wv[i - 1][0]] + wv[i - 1][1])
    print(dp[n+1][w])

    
    return

#E
def E():
    """N個の品物があります。 品物には 1,2,…,Nと番号が振られています。 
    各 i (1≤i≤N) について、品物i の重さはwi で、価値はvi です。
    太郎君は、N 個の品物のうちいくつかを選び、ナップサックに入れて持ち帰ることにしました。 
    ナップサックの容量は W であり、持ち帰る品物の重さの総和は W以下でなければなりません。
    太郎君が持ち帰る品物の価値の総和の最大値を求めてください
    
    入力はすべて整数である。
    1≤N≤100
    1≤W≤10**9
    1≤wi≤W
    1≤vi≤10**3"""
    n, w = LI()
    wv = LIR(n)
    dp = [[float("INF") for i in range(10 ** 5 + 1)] for k in range(n + 1)]
    dp[0][0] = 0
    for i in range(n):
        for k in range(10 ** 5 + 1):
            if k < wv[i][1]:
                dp[i + 1][k] = dp[i][k]
            else:
                dp[i + 1][k] = min(dp[i][k], dp[i][k - wv[i][1]] + wv[i][0])
    ans = 0
    for i in range(10 ** 5 + 1):
        if dp[n][i] <= w:
            ans = i
    print(ans)

    return

#F
def F():
    s = S()
    t = S()
    dp = [[0 for i in range(len(t)+1)] for k in range(len(s)+1)]
    for i in range(len(s)):
        for j in range(len(t)):
            if s[i] == t[j]:
                dp[i + 1][j + 1] = dp[i][j] + 1
            else:
                if dp[i][j + 1] < dp[i + 1][j]:
                    dp[i + 1][j + 1] = dp[i + 1][j]
                else:
                    dp[i + 1][j + 1] = dp[i][j + 1]
    ss = len(s)
    tt = len(t)
    ans = ""
    si = ss
    ti = tt
    while si > 0 and ti > 0:
        if dp[si][ti] == dp[si - 1][ti]:
            si -= 1
        elif dp[si][ti] == dp[si][ti - 1]:
            ti -= 1
        else:
            si -= 1
            ti -= 1
            ans = s[si]+ans


    print(ans)
    return

#G
def G():
    n, m = LI()
    xy = LIR_(m)
    edge = [[] for i in range(n)]
    for x,y in xy:
        edge[x].append(y)
    dp = [0 for i in range(n)]
    def ans(dp, i):
        #print(dp, i)
        if dp[i] != 0:
            return dp[i]
        else:
            if len(edge[i]) == 0:
                return 0
            ansb = 0
            for k in edge[i]:
                #print(dp, k , i)
                ansb = max(ansb, ans(dp, k) + 1)
                dp[i] = max(ansb, dp[i])
                #print(dp)
            return ansb
            
    for i in range(n):
        dp[i] = ans(dp, i)
    print(max(dp))
    return

#H
def H():
    h, w = LI()
    a = SR(h)
    dp = [[0 for i in range(w)] for k in range(h)]
    for i in range(w):
        if a[0][i] == "#":
            break
        dp[0][i] = 1
    for i in range(h):
        if a[i][0] == "#":
            break
        dp[i][0] = 1
    for i in range(1,w):
        for k in range(1, h):
            #print(i,k, dp)
            if a[k - 1][i] == ".":
                if a[k][i - 1] == ".":
                    dp[k][i] = dp[k - 1][i] + dp[k][i - 1] % mod
                else:
                    dp[k][i] = dp[k - 1][i]
            else:
                if a[k][i - 1] == ".":
                    dp[k][i] = dp[k][i - 1]
    print(dp[h-1][w-1] % mod)

    return

#I
def I():
    n = II()
    p = LF()
    dp = [[0 for k in range(n+1)] for i in range(n+1)]
    dp[1][1] = p[0]
    dp[1][0] = 1-p[0]
    for i in range(2,n+1):
        for k in range(i + 1):
            if k == 0:
                
                dp[i][k] = dp[i-1][k] * (1 - p[i-1])
            else:
                dp[i][k] = dp[i - 1][k - 1] * p[i - 1] + dp[i - 1][k] * (1 - p[i - 1])
    #print(dp)
    print(sum(dp[n][n//2+1:]))
    return 
#J
def J():
    n = II()
    a = LI()


#K
def K():
    n, k = LI()
    an = LI()
    dp = [0 for i in range(k + 1)]
    dp[0] = 1
    ans = ["First","Second"]
    for i in range(1, k + 1):
        if i in an:
            dp[i] = 0
        else:
            for num, a in enumerate(an):
                if a > i:
                    break
                if dp[i - a] == 1:
                    dp[i] = 0
                    break
            else:
                dp[i] = 1

    print(ans[dp[k]])

#L

#M
#N
# O
# P
# Q
# R
# S
# T
# U
# V
# W
# X
# Y
# Z


#Solve
if __name__ == '__main__':
    K()

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
n,k = map(int,input().split())
a = tuple(map(int,input().split()))

dp = [True] + [False]*k
for i in range(1,k+1):
    judge = False
    for j in range(n):
        if i-a[j] >= 0 and dp[i-a[j]]:
            judge = True
    dp[i] = judge
if dp[k]:
    print('First')
else:
    print('Second')

Submission status: Wrong Answer

Solution code:
import os
from io import BytesIO

input = BytesIO(os.read(0, os.fstat(0).st_size)).readline

n, k = map(int, input().split())
a = [int(i) for i in input().split()]

dp = [False] * (k + 1)

for ai in a:
    dp[ai] = True

for i in xrange(max(a) + 1, k + 1):
    dp[i] = any(not dp[i - ai] for ai in a)

os.write(1, 'First' if dp[k] else 'Second')

Submission status: Wrong Answer

Solution code:
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

N, K = map(int, input().split())
S = list(map(int, input().split()))
dp = [0]*(K+1)

for i in range(K+1):
    if dp[i] == 0:
        for s in S:
            if i+s > K:
                continue
            else:
                dp[i+s] = 1
    print(dp)
if dp[K]:
    print("First")
else:
    print("Second")

Submission status: Wrong Answer

Solution code:
N,K = map(int,input().split())
A = list(map(int,input().split()))

dp = [0] * (K+1)

for i in range(0,K+1):
    if dp[i] == 0:
        for j in A:
            if i + j > K:
                break
            dp[i + j] = 1

print('first' if dp[K] else 'second')

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
a = list(map(int, input().split()))

dp = [0] * (k+1)

for i in range(1, k+1):
    for j in range(n):
        if i - a[j] >= 0 and dp[i-a[j]] == 0:
            dp[i] = 1

print(dp[k])

Submission status: Wrong Answer

Solution code:
N,K=[int(x) for x in raw_input().split()]
A=[int(x) for x in raw_input().split()]
B=[-1 for i in range(K+1)]
F=[]
n=0
for i in range(A[0]):
    B[i]=0
    F.append(i)
    n+=1
for i in range(A[0],K+1):
    if sum([B[ max(i-a,0) ] for a in A ]) == N:
        B[i]=0
    else:
        B[i]=1
print ["Second","First","bug"][B[K]]

Submission status: Wrong Answer

Solution code:
print('First')

Submission status: Wrong Answer

Solution code:
n,k = [int(x) for x in input().split(' ')]
a = [int(x) for x in input().split(' ')]
dp = [False]*(k + 1)
for i in range(min(a), k + 1):
  dp[i] = any(not dp[i - j] for j in a)
print('First' if dp[k] else 'Second')

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
a = list(map(int,input().split()))

if K % (max(a) + min(a)) < min(a):
    print("Second")
else:
    print("First")

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
a = list(map(int,input().split()))

if K % (max(a) + min(a)) < min(a) - 1:
    print("Second")
else:
    print("First")

Submission status: Wrong Answer

Solution code:
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
judge = -1
while A[0] + A[N - 1] <= K + A[0]:
    K -= A[0]
    judge *= -1

if judge == 1:
    print("First")
else:
    print("Second")

Submission status: Time Limit Exceeded

Solution code:
N, K = map(int, input().split())
A = list(map(int, input().split()))
dp = [False] * (K+1)

for i in range(K+1):
    for j in range(N):
        if i - A[j] >= 0 :
            dp[i] = dp[i] | (not dp[i-A[j]])

if dp[K]:
    print('First')
else:
    print('Second')

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
n, k = map(int, input().split())
a_list = list(map(int, input().split()))
dp = [False]*(k+1)

for i in range(1,k+1):
  for j in range(n):
    if i-a_list[j] >= 0:
      dp[i] |= not(dp[i-a_list[j]])


if dp[k]:
  print('First')
else:
  print('Second')

Submission status: Time Limit Exceeded

Solution code:
n, k = map(int, input().split())
a_list = list(map(int, input().split()))
dp = [False]*(k+1)

for i in range(1,k+1):
  for j in range(n):
    if i-a_list[j] >= 0:
      dp[i] |= not(dp[i-a_list[j]])


if dp[k]:
  print('First')
else:
  print('Second')

Submission status: Time Limit Exceeded

Solution code:
#入力を受け取る
N,K=map(int,input().split())
a=list(map(int,input().split()))
#grundy[k]:=山にk(1≤k≤K)個石がある時のgrundy数
grundy=[0]*(K+1)
#DP(動的計画法)の考えかたを用いてGrundy数を求める
for j in range(K+1):
    s=set()
    for i in range(N):
        if a[i]<=j:
            s.add(grundy[j-a[i]])
    #mex()の動作
    g=0
    while g in s:g+=1 
    grundy[j]=g
if grundy[K]:print("First")
else:print("Second")

Submission status: Time Limit Exceeded

Solution code:
N,K=map(int,input().split())
a=list(map(int,input().split()))
grundy=[0]*(K+1)
for j in range(K+1):
    s=set()
    for i in range(N):
        if a[i]<=j:
            s.add(grundy[j-a[i]])
        g=0
        while g in s:g+=1
        grundy[j]=g
if grundy[K]:print("First")
else:print("Second")

Submission status: Time Limit Exceeded

Solution code:
#入力を受け取る
N,K=map(int,input().split())
a=list(map(int,input().split()))
#DPの配列(少し余裕を持たせる)、Falseで初期化
DP=[False]*(K+10)
for i in range(1,K+1):
    for j in range(N):
        if i-a[j]>=0:
            DP[i] |= ~DP[i-a[j]] # ~は否定の意味(ビット反転)
            #ORなので, 一つでもFalseがあればTrueがはいる
if DP[K]:print("First")
else: print("Second")

Submission status: Time Limit Exceeded

Solution code:
import sys
readline = sys.stdin.readline

N,K = map(int,readline().split())
A = list(map(int,readline().split()))

# dp[i] = 石の残り数がiの時の勝敗
# i個の状態から遷移できる場所に負けが存在したら、それを相手に回すことが出来るため勝ち
# i個の状態から遷移できる場所に勝ちが存在したら、それを相手に回す必要はないので更新なし

dp = [False] * (K + 1)
for i in range(1, K + 1): # 石がi個の状態
  for j in range(len(A)): # それを相手に回す元が存在するかチェック
    if i - A[j] >= 0 and not dp[i -A[j]]:
      dp[i] = True

print(("Second","First")[dp[K]])

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(1000000)

n,k = list(map(int,input().split()))
a = list(map(int,input().split()))
dp = [-1]*100001
# dp[100000] = 0

def mex(l):
    l=list(set(l))
    d={}
    for i in l:
        d[i] = 1
    x=len(l)
    for i in range(0,len(l)):
        try :
            d[i] = d[i] + 1
        except:
            x=i
            break
    return x

def grundy(a,k):
    h = min(a)
    if k<h:
        return 0
    if k==h:
        return 1

    if dp[k]!=-1:
        return dp[k]
    
    dp[k] = mex([grundy(a,k-i) for i in a if k-i>=0])
    return dp[k]

if grundy(a,k) == 0:
    print("Second")
else:
    print("First")



# n=int(input())

# dp = [-1]*(1000001)
# dp[1] = 1

# for i in range(2,n):
#     if dp[i]!=-1:
#         break
#     x=min(6,i)
#     m=0
#     for j in range(1,x):
#         m=m+dp[i-j]
#     dp[i]=m
# print(dp[i])

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(1000000)

n,k = list(map(int,input().split()))
a = list(map(int,input().split()))
dp = [-1]*100001
dp[100000] = 0

def mex(l):
    l=list(set(l))
    d={}
    for i in l:
        d[i] = 1
    x=len(l)
    for i in range(0,len(l)):
        try :
            d[i] = d[i] + 1
        except:
            x=i
            break
    return x

def grundy(a,k):
    h = min(a)
    if k<h:
        return 0
    if k==h:
        return 1

    if dp[k]!=-1:
        return dp[k]
    
    dp[k] = mex([grundy(a,k-i) for i in a if k-i>=0])
    return dp[k]

if grundy(a,k) == 0:
    print("Second")
else:
    print("First")



# n=int(input())

# dp = [-1]*(1000001)
# dp[1] = 1

# for i in range(2,n):
#     if dp[i]!=-1:
#         break
#     x=min(6,i)
#     m=0
#     for j in range(1,x):
#         m=m+dp[i-j]
#     dp[i]=m
# print(dp[i])

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(1000000)

n,k = list(map(int,input().split()))
a = list(map(int,input().split()))
dp = [-1]*100001
dp[100000] = 0

def mex(l):
    l=list(set(l))
    d={}
    for i in l:
        d[i] = 1
    x=len(l)
    for i in range(0,len(l)):
        try :
            d[i] = d[i] + 1
        except:
            x=i
            break
    return x

def grundy(a,k):
    h = min(a)
    if k<h:
        return 0
    if k==h:
        return 1

    if dp[k]!=-1:
        return dp[k]
    
    dp[k] = mex([grundy(a,k-i) for i in a if k-i>=0])
    return dp[k]

if grundy(a,k) == 0:
    print("Second")
else:
    print("First")

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(1000000)

n,k = list(map(int,input().split()))
a = list(map(int,input().split()))
dp = [-1]*100001
dp[100000] = 0

def mex(l):
    l=list(set(l))
    l.sort()
    x=len(l)
    for i in range(0,x):
        if i!=l[i]:
            x=i
            break
    return x

def grundy(a,k):
    h = min(a)
    if k<h:
        return 0
    if k==h:
        return 1

    if dp[k]!=-1:
        return dp[k]
    
    dp[k] = mex([grundy(a,k-i) for i in a if k-i>=0])
    return dp[k]

if grundy(a,k) == 0:
    print("Second")
else:
    print("First")

Submission status: Time Limit Exceeded

Solution code:
n,k = map(int,input().split())
a = list(map(int,input().split()))
dp = [False]*(k+1)
for i in range(1,k+1):
    for j in range(n):
        if i-a[j]<0:
            break
        if dp[i-a[j]]==False:
            dp[i] = True
if dp[k]==True:
    print("First")
else:
    print("Second")

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(10**7)

N, K = map(int, input().split())
A = [int(i) for i in input().split()]
    
def func():
    for i in range(1, K+1):
        for j in range(N):
            if i - A[j] >= 0:
                dp[i] |= ~dp[i - A[j]]
                
dp = [0 for i in range(K+1)]
func()
if dp[K]: print("First")
else: print("Second")

Submission status: Time Limit Exceeded

Solution code:
n,k=map(int,input().split())
a=list(map(int,input().split()))
dp=[False for i in range(k+1)]
for i in range(k+1):
    for j in range(n):
        if i-a[j]>=0:
            dp[i]|=(dp[i-a[j]]^(True))
if dp[k]:
    print("First")
else:
    print("Second")

Submission status: Time Limit Exceeded

Solution code:
#dp[i]denotes who will win if i stones left
import sys
sys.setrecursionlimit(10**6)
def f(i):
	global xi
	if(i<m):
		return 2
	if(i in xi):
		return xi[i]
	done=0
	for j in hashi:
		if(j<=i):
			if(f(i-j)==2):
				xi[i]=1
				done=1
				return 1
	if(done==0):
		xi[i]=2
	return 2
l=input().split()
n=int(l[0])
k=int(l[1])
l=input().split()
li=[int(i) for i in l]
hashi=dict()
for i in li:
	hashi[i]=1
m=min(li)
xi=dict()
if(f(k)==1):
	print("First")
else:
	print("Second")

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline

n, k = map(int, input().split())
A = list(map(int, input().split()))
dp = [0]*(k+1)
for i in range(k+1):
  for a in A:
    if i-a >= 0:
      dp[i] |= not dp[i-a]
result = dp[k]
if result:
  print("First")
else:
  print("Second")

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline

n, k = map(int, input().split())
A = list(map(int, input().split()))
dp = [0]*(k+1)
for i in range(k+1):
  for a in A:
    if i-a >= 0:
      dp[i] |= ~dp[i-a]
result = dp[k]
if result:
  print("First")
else:
  print("Second")

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

N, K = map(int, input().split())
A = [int(i) for i in input().split()]
dp = np.zeros(K + 1, np.bool)

for i in range(1, K + 1):
    for j in range(N):
        if i >= A[j]:
            dp[i] |= dp[i - A[j]] ^ True
# print(dp)
print('First' if dp[K] else 'Second')

Submission status: Time Limit Exceeded

Solution code:
N,K=map(int,input().split())
A=set(map(int,input().split()))
import numpy as np
a=np.array([1 if i in A else 0 for i in range(1,K+1)])
d=np.zeros(K+1)
for i in range(K):
    if d[i]==0:
        d[i+1:]+=a[:K-i]
print(['Second','First'][d[K]>0])

Submission status: Time Limit Exceeded

Solution code:
n,k=map(int,input().split())
a=list(map(int,input().split()))
dp=[0]*(2*k+1)
for i in range(k+1):
    for j in a:dp[i+j]|=~dp[i]
if dp[k]:
    print('First')
else:
    print('Second')

Submission status: Time Limit Exceeded

Solution code:
n,k=map(int,input().split())
a=list(map(int,input().split()))
dp=[False]*(k+1)
for i in range(k+1):
    for j in range(n):
        if i-a[j]>=0:
            dp[i]|=not dp[i-a[j]]
if dp[k]:
    print('First')
else:
    print('Second')

Submission status: Time Limit Exceeded

Solution code:
from sys import setrecursionlimit
setrecursionlimit(1<<30)
def f(k,p):
    if k==0:
        return p^1
    if k<0:
        return p
    if d[k][p]==-1:
        d[k][p]=p if any(f(k-i,p^1)==p for i in a) else p^1
    return d[k][p]
n,k=map(int,raw_input().split())
d=[[-1]*2 for _ in xrange(k+1)]
a=map(int,raw_input().split())
print 'First' if f(k,0)==0 else 'Second'

Submission status: Time Limit Exceeded

Solution code:
from sys import setrecursionlimit
setrecursionlimit(1<<30)
def f(k,p,d):
    if k==0:
        return p^1
    if k<0:
        return p
    if (k,p) not in d:
        d[k,p]=p if any(f(k-i,p^1,d)==p for i in a) else p^1
    return d[k,p]
n,k=map(int,raw_input().split())
a=map(int,raw_input().split())
print 'First' if f(k,0,{})==0 else 'Second'

Submission status: Time Limit Exceeded

Solution code:
from sys import setrecursionlimit
setrecursionlimit(1<<30)
def f(k,p):
    if k==0:
        return p^1
    if k<0:
        return p
    if d[k][p]==-1:
        d[k][p]=p if any(f(k-i,p^1)==p for i in a) else p^1
    return d[k][p]
n,k=map(int,raw_input().split())
a=map(int,raw_input().split())
d=[[-1]*2 for _ in xrange(k+1)]
print 'First' if f(k,0)==0 else 'Second'

Submission status: Time Limit Exceeded

Solution code:
from sys import setrecursionlimit
setrecursionlimit(1<<30)
def f(k,p,d):
    if k==0:
        return p^1
    if k<0:
        return p
    if (k,p) not in d:
        d[k,p]=p if any(f(k-i,p^1,d)==p for i in a) else p^1
    return d[k,p]
n,k=map(int,raw_input().split())
a=map(int,raw_input().split())
print 'First' if f(k,0,{})==0 else 'Second'

Submission status: Time Limit Exceeded

Solution code:
N, K = map(int, input().split())
A = list(map(int, input().split()))

dp = [False] * (K + 1)

for i in range(K + 1):
    for j in range(N):
        if i - A[j] >= 0:
            dp[i] |= not dp[i - A[j]]

if dp[K]:
    print('First')
else:
    print('Second')

# print(dp)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sat Apr 25 18:20:35 2020
"""

import sys
import numpy as np

sys.setrecursionlimit(10 ** 9)
#def input():
#    return sys.stdin.readline()[:-1]
mod = 10**9+7

#N = int(input())
N, K = map(int,input().split())
A = np.array(list(map(int,input().split())))

dp = [i <= K for i in range(K + A[-1]+1)]
for i in range(K, -1, -1):
    for a in A:
        if dp[a+i]:
            dp[i] = False
            break

#    print(i, dp[i],A+i,dp[A+i])
#print(dp)

if dp[0]:
    ans = 'Second'
else:
    ans = 'First'
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N,K=map(int,input().split())
A=list(map(int,input().split()))

DP=[False]*(K+1)
for i in range(1,K+1):
    for j in range(0,N):
        if A[j]<=i:
            DP[i]=DP[i] or not DP[i-A[j]]
        else:
            break

if DP[K]:
    print('First')
else:
    print('Second')

Submission status: Time Limit Exceeded

Solution code:
N, K, *A = map(int, open(0).read().split())

dp = [False] * (K + 1)
for i in range(1, K + 1):
    if dp[i]:
        continue

    for a in A:
        if i - a >= 0:
            dp[i] |= not dp[i - a]

if dp[K]:
    print("First")
else:
    print("Second")

Submission status: Time Limit Exceeded

Solution code:
N, K, *A = map(int, open(0).read().split())

dp = [False] * (K + 1)
for i in range(1, K + 1):
    for a in A:
        if i - a >= 0:
            dp[i] |= not dp[i - a]

if dp[K]:
    print("First")
else:
    print("Second")

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
n,k=map(int,input().split())
a=np.array(list(map(int,input().split())))
dp=np.full(k+1,False)
calted=np.full(k+1,False)
# dp[i]:残り石i個で自分のターンになった時、勝てるならTrue
# dp[0]=False,dp[a]=True,求めるのはdp[k]
mi=np.min(a)
ma=np.max(a)
dp[a]=True
calted[a]=True
# dp[i]={dp[i-a]の中にFalseがあればTrue、すべてTrueならFalse}
for i in range(mi+1,k+1):
      if calted[i]:
            continue
      il=i-a
      f=np.prod(dp[il[il>=0]])
      if f == 0:
            dp[i]=True
      else:
            dp[i]=False
print('First' if dp[k] else 'Second')

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
n,k=map(int,input().split())
a=np.array(list(map(int,input().split())))
dp=np.full(k+1,False)
calted=np.full(k+1,False)
# dp[i]:残り石i個で自分のターンになった時、勝てるならTrue
# dp[0]=False,dp[a]=True,求めるのはdp[k]
mi=np.min(a)
ma=np.max(a)
dp[a]=True
calted[a]=True
# dp[i]={dp[i-a]の中にFalseがあればTrue、すべてTrueならFalse}
for i in range(mi+1,k+1):
      if calted[i]:
            continue
      il=i-a
      li=[j for j in il if j>=0]
      f=np.prod(dp[il])
      if f == 0:
            dp[i]=True
      else:
            dp[i]=False
print('First' if dp[k] else 'Second')
#print(dp)

Submission status: Time Limit Exceeded

Solution code:
n, k = map(int, input().split())
A = list(map(int, input().split()))
# dp[i] i個の石で手番の時の勝ち負け
dp = [0]*(k+1)
# 貰う
for i in range(1, k+1):
    for j in range(n):
        if i-A[j] < 0:
            continue
        dp[i] = max(dp[i], 1 if dp[i-A[j]] == 0 else 0)
print('First' if dp[k] else 'Second')

Submission status: Time Limit Exceeded

Solution code:
# ヒント　dp[i]=(石の個数がi個の時直後の手番の人が勝てるか？)
n,k=map(int,input().split())
a=list(map(int,input().split()))
dp=[0]*(k+1)
for i in range(1,k+1):
    for j in range(n):
        if i-a[j]>=0 and dp[i-a[j]]==0:
            dp[i]=1
print("First" if dp[k] else "Second")

Submission status: Time Limit Exceeded

Solution code:
N,K = map(int,input().split())
A = list(map(int,input().split()))

dp = [False]*(K+1)

for i in range(K+1):
    for j in range(N):
        if i-A[j]>=0 and dp[i-A[j]] == False:
            dp[i] = True

        
if dp[K]:
    print("First")
else:
    print("Second")

Submission status: Time Limit Exceeded

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, islice
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce, lru_cache
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7

N, K = MAP()
a = LIST()

@lru_cache(maxsize=None)
def judge(n):
    if n < 0:
        return 1

    ret = 0
    for x in a:
        if judge(n-x) == 0:
            ret = 1
    return ret

ans = judge(K)
if ans:
    print("First")
else:
    print("Second")