prithivMLmods/Coder-Stat huggingface dataset:
Problem p03170 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int dp[100009];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, k;
  cin >> n >> k;
  int arr[n + 1];
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    dp[arr[i]] = 1;
  }
  for (int i = 0; i < arr[0]; i++)
    dp[i] = 0;
  int flag = 0;
  for (int i = arr[0] + 1; i < k + 1; i++) {
    flag = 0;
    for (int j = 0; j < n; j++) {
      if (dp[i - arr[j]] == 0) {
        dp[i] = 1;
        flag = 1;
        break;
      }
    }
    if (flag == 0)
      dp[i] = 0;
  }
  string ans = (dp[k] == 1 ? "First\n" : "Second\n");
  cout << ans;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int dp[100009];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, k;
  cin >> n >> k;
  int arr[n + 1];
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    dp[arr[i]] = 1;
  }
  for (int i = 0; i < arr[0]; i++)
    dp[i] = 0;
  int flag = 0;
  for (int i = arr[0] + 1; i < k + 1; i++) {
    flag = 0;
    for (int j = 0; j < n; j++) {
      if (i - arr[j] >= 0 and dp[i - arr[j]] == 0) {
        dp[i] = 1;
        flag = 1;
        break;
      }
    }
    if (flag == 0)
      dp[i] = 0;
  }
  string ans = (dp[k] == 1 ? "First\n" : "Second\n");
  cout << ans;
}
Problem p03170 (C++)

Buggy submission (status: Runtime Error):
// 参考：https://blog.csdn.net/HQG_AC/article/details/85984085
// 记忆化优点：https://blog.csdn.net/u011639256/article/details/29389951
#include <bits/stdc++.h>
using namespace std;
const int maxn = 110;

int n, k;
int a[maxn], dp[maxn][2]; // dp[容量][人]记录是否能赢
// 记忆化搜索初始化必须可以实现判断是否记忆
// 记忆化好处：从上往下递归，但是不用吧中途的所有情况都记下来，只需要用到递归到的状态的值

bool dfs(int x, int y) {
  if (dp[x][y] >= 0)
    return dp[x][y];
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    if (x >= a[i])
      ans |= !dfs(
          x - a[i],
          !y); // 只要后面状态有一个是另一方必输则当前状态此人必赢，公式很妙
  }
  return dp[x][y] = ans;
}

signed main() {
  memset(dp, -1, sizeof dp);
  cin >> n >> k;
  for (int i = 1; i <= n; i++)
    cin >> a[i];
  if (dfs(k, 0))
    cout << "First" << endl;
  else
    cout << "Second" << endl;
  return 0;
}

Fixed submission:
// 参考：https://blog.csdn.net/HQG_AC/article/details/85984085
// 记忆化优点：https://blog.csdn.net/u011639256/article/details/29389951
#include <bits/stdc++.h>
using namespace std;
const int maxn = 110;

int n, k;
int a[maxn], dp[100005][2]; // dp[容量][人]记录是否能赢
// 记忆化搜索初始化必须可以实现判断是否记忆
// 记忆化好处：从上往下递归，但是不用吧中途的所有情况都记下来，只需要用到递归到的状态的值

bool dfs(int x, int y) {
  if (dp[x][y] >= 0)
    return dp[x][y];
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    if (x >= a[i])
      ans |= !dfs(
          x - a[i],
          !y); // 只要后面状态有一个是另一方必输则当前状态此人必赢，公式很妙
  }
  return dp[x][y] = ans;
}

signed main() {
  memset(dp, -1, sizeof dp);
  cin >> n >> k;
  for (int i = 1; i <= n; i++)
    cin >> a[i];
  if (dfs(k, 0))
    cout << "First" << endl;
  else
    cout << "Second" << endl;
  return 0;
}
Problem p03170 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int dp[100000 + 5];
int A[100 + 5];

int main(int argc, char const *argv[]) {
  int N, K;
  while (cin >> N >> K) {
    memset(dp, 0, sizeof(dp));
    for (int i = 0; i < N; i++) {
      cin >> A[i];
    }
    for (int i = A[0]; i <= K; i++) {
      for (int j = 0; j < N; j++) {
        if (i >= j && dp[i - A[j]] == 0) {
          dp[i] = 1;
          break;
        } else {
          dp[i] = 0;
        }
      }
    }
    if (dp[K]) {
      cout << "First" << endl;
    } else {
      cout << "Second" << endl;
    }
  }
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int dp[100000 + 5];
int A[100 + 5];

int main(int argc, char const *argv[]) {
  int N, K;
  while (cin >> N >> K) {
    memset(dp, 0, sizeof(dp));
    for (int i = 0; i < N; i++) {
      cin >> A[i];
    }
    for (int i = A[0]; i <= K; i++) {
      for (int j = 0; j < N; j++) {
        if (i >= A[j] && dp[i - A[j]] == 0) {
          dp[i] = 1;
          break;
        } else {
          dp[i] = 0;
        }
      }
    }
    if (dp[K]) {
      cout << "First" << endl;
    } else {
      cout << "Second" << endl;
    }
  }
  return 0;
}
Problem p03170 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
constexpr int MAXN = 107, MAXK = 1e1 + 7;

int n, k;
int lst[MAXN], dp[MAXK]{-1};

int winner(int rem) {
  if (dp[rem])
    return dp[rem];
  bool canwin = false;
  for (int i = 0; i != n; ++i)
    if (lst[i] <= rem && winner(rem - lst[i]) == -1) {
      canwin = true;
      break;
    }
  return dp[rem] = (canwin ? 1 : -1);
}

int main() {
#ifdef LOCAL
  freopen("data.txt", "r", stdin);
#endif
  scanf("%d%d", &n, &k);
  for (int i = 0; i != n; ++i)
    scanf("%d", &lst[i]);
  puts(winner(k) == 1 ? "First" : "Second");
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
constexpr int MAXN = 107, MAXK = 1e5 + 7;

int n, k;
int lst[MAXN], dp[MAXK]{-1};

int winner(int rem) {
  if (dp[rem])
    return dp[rem];
  bool canwin = false;
  for (int i = 0; i != n; ++i)
    if (lst[i] <= rem && winner(rem - lst[i]) == -1) {
      canwin = true;
      break;
    }
  return dp[rem] = (canwin ? 1 : -1);
}

int main() {
#ifdef LOCAL
  freopen("data.txt", "r", stdin);
#endif
  scanf("%d%d", &n, &k);
  for (int i = 0; i != n; ++i)
    scanf("%d", &lst[i]);
  puts(winner(k) == 1 ? "First" : "Second");
}
Problem p03170 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

int func(vector<int> arr, int n, int k, int minv) {
  vector<int> dp(k + 1, 1);

  for (int i = 0; i < minv; i++)
    dp[i] = 0;

  for (int i = minv; i <= k; i++) {
    for (int p = 0; p < n; p++) {
      int rem = i - arr[p];
      dp[i] = dp[i] & dp[rem];
      // if(dp[rem]==0) dp[i]=1;
    }
    dp[i] = !dp[i];
  }

  return dp[k];
}

int main() {

  int n, k;
  cin >> n >> k;
  vector<int> arr(n);
  for (int i = 0; i < n; i++)
    cin >> arr[i];
  int minv = *min_element(arr.begin(), arr.end());
  int ans = func(arr, n, k, minv);
  if (ans == 1)
    cout << " First " << endl;
  else
    cout << " Second " << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;

int func(vector<int> arr, int n, int k, int minv) {
  vector<int> dp(k + 1, 1);

  for (int i = 0; i < minv; i++)
    dp[i] = 0;

  for (int i = minv; i <= k; i++) {
    for (int p = 0; p < n; p++) {
      if (arr[p] <= i) {
        int rem = i - arr[p];
        dp[i] = dp[i] & dp[rem];
        // if(dp[rem]==0) dp[i]=1;
      }
    }
    dp[i] = !dp[i];
  }

  return dp[k];
}

int main() {

  int n, k;
  cin >> n >> k;
  vector<int> arr(n);
  for (int i = 0; i < n; i++)
    cin >> arr[i];
  int minv = *min_element(arr.begin(), arr.end());
  int ans = func(arr, n, k, minv);
  if (ans == 1)
    cout << " First " << endl;
  else
    cout << " Second " << endl;
}
Problem p03170 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  for (int i = 0; i < n; ++i)
    cin >> a[i];

  vector<bool> dp(n + 1);
  for (int stone = 0; stone <= k; ++stone) {
    for (int x : a) {
      if (stone >= x and dp[stone - x] == false) {
        dp[stone] = true;
      }
    }
  }
  cout << (dp[k] == true ? "First" : "Second");
}


Fixed submission:
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  for (int i = 0; i < n; ++i)
    cin >> a[i];

  vector<bool> dp(k + 1);
  for (int stone = 0; stone <= k; ++stone) {
    for (int x : a) {
      if (stone >= x and dp[stone - x] == false) {
        dp[stone] = true;
      }
    }
  }
  cout << (dp[k] == true ? "First" : "Second");
}
Problem p03170 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define faster                                                                 \
  cin.tie(0);                                                                  \
  ios_base::sync_with_stdio(0)
#define ll long long
// # setprecision doubt

int n, k;

int main() {
  int temp;
  cin >> n >> k;
  vector<int> arr;
  for (int i = 0; i < n; i++) {
    cin >> temp;
    arr.push_back(temp);
  }
  sort(arr.begin(), arr.end());
  vector<bool> dp(k + 1, 0);
  for (int i = 1; i <= k; i++) {
    for (int j = 0; j < n; j++) {
      if (i < arr[j] < 0)
        break;
      if (dp[i - arr[j]] == false) {
        // found a way to defeat a opponent
        // so i win
        dp[i] = true;
        break;
      }
    }
  }
  if (dp[k]) {
    cout << "First" << endl;
  } else {
    cout << "Second" << endl;
  }
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define faster                                                                 \
  cin.tie(0);                                                                  \
  ios_base::sync_with_stdio(0)
#define ll long long
// # setprecision doubt

int n, k;

int main() {
  int temp;
  cin >> n >> k;
  vector<int> arr;
  for (int i = 0; i < n; i++) {
    cin >> temp;
    arr.push_back(temp);
  }
  sort(arr.begin(), arr.end());
  vector<bool> dp(k + 1, 0);
  for (int i = 1; i <= k; i++) {
    for (int j = 0; j < n; j++) {
      if (i - arr[j] < 0)
        break;
      if (dp[i - arr[j]] == false) {
        // found a way to defeat a opponent
        // so i win
        dp[i] = true;
        break;
      }
    }
  }
  if (dp[k]) {
    cout << "First" << endl;
  } else {
    cout << "Second" << endl;
  }
}
Problem p03170 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define IOS                                                                    \
  ;                                                                            \
  ios::sync_with_stdio(0);                                                     \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define MX 110
#define FF                                                                     \
  freopen("input.in", "r", stdin);                                             \
  freopen("output.txt", "w", stdout);
int dp[MX][2];
int n;
int a[MX];
int f(int k, bool turn) {
  if (k == 0)
    return 0;
  if (dp[k][turn] != -1)
    return dp[k][turn];
  int ans = 0;
  for (int i = 0; i < n; i++) {
    if (k - a[i] < 0)
      break;
    else
      dp[k][turn] = ans |= !f(k - a[i], !turn);
  }
  return ans;
}
int main() {
  // FF;
  IOS;
  int k;
  cin >> n >> k;
  for (int i = 0; i < n; i++)
    cin >> a[i];
  memset(dp, -1, sizeof dp);
  if (f(k, 0))
    cout << "First";
  else
    cout << "Second";
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define IOS                                                                    \
  ;                                                                            \
  ios::sync_with_stdio(0);                                                     \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define MX 100001
#define FF                                                                     \
  freopen("input.in", "r", stdin);                                             \
  freopen("output.txt", "w", stdout);
int dp[MX][2];
int n;
int a[MX];
int f(int k, bool turn) {
  if (k == 0)
    return 0;
  if (dp[k][turn] != -1)
    return dp[k][turn];
  int ans = 0;
  for (int i = 0; i < n; i++) {
    if (k - a[i] < 0)
      break;
    else
      dp[k][turn] = ans |= !f(k - a[i], !turn);
  }
  return ans;
}
int main() {
  // FF;
  IOS;
  int k;
  cin >> n >> k;
  for (int i = 0; i < n; i++)
    cin >> a[i];
  memset(dp, -1, sizeof dp);
  if (f(k, 0))
    cout << "First";
  else
    cout << "Second";
}
Problem p03170 (C++)

Buggy submission (status: Runtime Error):
#include <iomanip>
#include <iostream>
#include <vector>
using namespace std;
int n, k;
vector<int> a;
int dp[10010]; // 石がx個残っている場合の勝ち負けを判断、0の場合負け

int main() {
  cin >> n >> k;
  a.resize(n);
  for (int i = 0; i < n; ++i)
    cin >> a[i];

  // dp[0] = 0; //残りの石が0個の場合負け

  for (int i = 0; i <= k; ++i) {
    for (int j = 0; j < n; ++j) {
      if (i - a[j] >= 0 && dp[i - a[j]] == 0) {
        dp[i] = 1;
      }
    }
  }
  if (dp[k])
    cout << "First" << endl;
  else
    cout << "Second" << endl;
  return 0;
}

Fixed submission:
#include <iomanip>
#include <iostream>
#include <vector>
using namespace std;
int n, k;
vector<int> a;
int dp[100010]; // 石がx個残っている場合の勝ち負けを判断、0の場合負け

int main() {
  cin >> n >> k;
  a.resize(n);
  for (int i = 0; i < n; ++i)
    cin >> a[i];

  // dp[0] = 0; //残りの石が0個の場合負け

  for (int i = 0; i <= k; ++i) {
    for (int j = 0; j < n; ++j) {
      if (i - a[j] >= 0 && dp[i - a[j]] == 0) {
        dp[i] = 1;
      }
    }
  }
  if (dp[k])
    cout << "First" << endl;
  else
    cout << "Second" << endl;
  return 0;
}
Problem p03170 (C++)

Buggy submission (status: Runtime Error):
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize ("unroll-loops")
// #pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define mod 998244353
#define fi first
#define se second
#define pii pair<int, int>
#define int long long
#define endl '\n'
#define pll pair<long long, long long>
#define LONGLONG_MAX 100000000000000
using namespace std;
template <typename T>
using ordered_set =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
long long power(long long a, long long b) {
  long long ans = 1;
  while (b > 0) {
    if (b & 1) {
      ans = (ans * a) % mod;
    }
    a = (a * a) % mod;
    b >>= 1;
  }
  return ans;
}
int dp[100005];
int fun(int i, int a[], int n) {
  if (i < 0)
    return 1;
  if (i == 0)
    return 0;
  if (dp[i] != -1)
    return dp[i];
  int ans = 0;
  for (int j = 0; j < n; j++) {
    if (fun(i - j, a, n) == 0) {
      ans = 1;
      break;
    }
  }
  return dp[i] = ans;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n, k;
  cin >> n >> k;
  int a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  memset(dp, -1, sizeof(dp));
  if (fun(k, a, n))
    cout << "First";
  else
    cout << "Second";
  return 0;
}

Fixed submission:
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize ("unroll-loops")
// #pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define mod 998244353
#define fi first
#define se second
#define pii pair<int, int>
#define int long long
#define endl '\n'
#define pll pair<long long, long long>
#define LONGLONG_MAX 100000000000000
using namespace std;
template <typename T>
using ordered_set =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
long long power(long long a, long long b) {
  long long ans = 1;
  while (b > 0) {
    if (b & 1) {
      ans = (ans * a) % mod;
    }
    a = (a * a) % mod;
    b >>= 1;
  }
  return ans;
}
int dp[100005];
int fun(int i, int a[], int n) {
  if (i < 0)
    return 1;
  if (i == 0)
    return 0;
  if (dp[i] != -1)
    return dp[i];
  int ans = 0;
  for (int j = 0; j < n; j++) {
    if (fun(i - a[j], a, n) == 0) {
      ans = 1;
      break;
    }
  }
  return dp[i] = ans;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n, k;
  cin >> n >> k;
  int a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  memset(dp, -1, sizeof(dp));
  if (fun(k, a, n))
    cout << "First";
  else
    cout << "Second";
  return 0;
}
Problem p03170 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define ll long long
using namespace std;

const int NM = 1e5;

int v[105];
bool dp[NM];

int main() {
  int n, k;
  cin >> n >> k;
  for (int i = 1; i <= n; i++)
    cin >> v[i];
  /// dp[i]=1, daca sunt i pietre si primul jucator castiga
  for (int j = 0; j <= k; j++)
    for (int i = 1; i <= n; i++)
      if (!dp[j])
        dp[j + v[i]] = 1;
  cout << (dp[k] ? "First" : "Second");
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define ll long long
using namespace std;

const int NM = 1e5;

int v[105];
bool dp[NM];

int main() {
  int n, k;
  cin >> n >> k;
  for (int i = 1; i <= n; i++)
    cin >> v[i];
  /// dp[i]=1, daca sunt i pietre si primul jucator castiga
  for (int j = 0; j <= k; j++)
    for (int i = 1; i <= n; i++)
      if (!dp[j] && j + v[i] <= k)
        dp[j + v[i]] = 1;
  cout << (dp[k] ? "First" : "Second");
  return 0;
}
Problem p03170 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define ii pair<int, int>
#define all(x) (x).begin(), (x).end()
#define INF 100000000000000000
#define modulo 1000000007
#define mod 998244353
#define int long long int
using namespace std;

int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  //   freopen("q.gir","r",stdin);
  //   fKreopen("q.cik","w",stdout);
  int n, k;
  cin >> n >> k;
  vector<bool> K(k + 1, false);
  vector<int> arr(n);
  for (int i = 0; i < n; i++)
    cin >> arr[i];
  for (int i = 0; i <= k; i++) {
    if (K[i] == false) {
      for (int j = 0; j < n; j++)
        K[i + arr[j]] = true;
    }
  }
  if (K[k])
    cout << "First";
  else
    cout << "Second";
}


Fixed submission:
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define ii pair<int, int>
#define all(x) (x).begin(), (x).end()
#define INF 100000000000000000
#define modulo 1000000007
#define mod 998244353
#define int long long int
using namespace std;

int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  //   freopen("q.gir","r",stdin);
  //   fKreopen("q.cik","w",stdout);
  int n, k;
  cin >> n >> k;
  vector<bool> K(5000000, false);
  vector<int> arr(n);
  for (int i = 0; i < n; i++)
    cin >> arr[i];
  for (int i = 0; i <= k; i++) {
    if (K[i] == false) {
      for (int j = 0; j < n; j++)
        K[i + arr[j]] = true;
    }
  }
  if (K[k])
    cout << "First";
  else
    cout << "Second";
}
Problem p03170 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int n, k, dp[105][2];
int a[105];
bool dfs(int k, int t) {
  if (dp[k][t] >= 0)
    return dp[k][t];
  int ans = 0;
  for (int i = 1; i <= n; i++)
    if (k >= a[i])
      ans |= !dfs(k - a[i], !t);
  return dp[k][t] = ans;
}
int main() {
  memset(dp, -1, sizeof(dp));
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++)
    scanf("%d", &a[i]);
  if (dfs(k, 0))
    puts("First");
  else
    puts("Second");
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int n, k, dp[1000005][2];
int a[10000005];
bool dfs(int k, int t) {
  if (dp[k][t] >= 0)
    return dp[k][t];
  int ans = 0;
  for (int i = 1; i <= n; i++)
    if (k >= a[i])
      ans |= !dfs(k - a[i], !t);
  return dp[k][t] = ans;
}
int main() {
  memset(dp, -1, sizeof(dp));
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++)
    scanf("%d", &a[i]);
  if (dfs(k, 0))
    puts("First");
  else
    puts("Second");
}
Problem p03170 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define ll long long
#define pll pair<ll, ll>
#define F first
#define S second
#define pb push_back
#define ld long double
#define vll vector<ll>
#define vpll vector<pll>
#define ppll pair<pll, ll>
ll M = 1000000007;
ll MAX = LONG_LONG_MAX;
template <typename T>
using ordered_set =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
ll power(ll a, ll m, ll mod) {
  ll ans = 1;
  while (m) {
    if (m % 2) {
      ans *= a;
      ans %= (mod);
    }
    a = (a * a) % (mod);
    m >>= 1;
  }
  return ans;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ll t = 1;
  //  cin>>t;
  while (t--) {
    ll n, i, j, k, x = INT_MAX, m, a;
    cin >> n >> k;
    vector<ll> v(n);
    vector<bool> dp(k + 1, 0);
    for (i = 0; i < n; i++) {
      cin >> a;
      v[i] = a;
      x = min(x, a);
      dp[a] = 1;
    }
    for (i = x + 1; i <= k; i++) {
      if (dp[i])
        continue;
      for (j = 0; j < n; j++) {
        if (dp[i - v[j]] == 0) {
          dp[i] = 1;
          break;
        }
      }
    }
    if (dp[k])
      cout << "First\n";
    else
      cout << "Second\n";
  }
}

Fixed submission:
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define ll long long
#define pll pair<ll, ll>
#define F first
#define S second
#define pb push_back
#define ld long double
#define vll vector<ll>
#define vpll vector<pll>
#define ppll pair<pll, ll>
ll M = 1000000007;
ll MAX = LONG_LONG_MAX;
template <typename T>
using ordered_set =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
ll power(ll a, ll m, ll mod) {
  ll ans = 1;
  while (m) {
    if (m % 2) {
      ans *= a;
      ans %= (mod);
    }
    a = (a * a) % (mod);
    m >>= 1;
  }
  return ans;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ll t = 1;
  //  cin>>t;
  while (t--) {
    ll n, i, j, k, x = INT_MAX, m, a;
    cin >> n >> k;
    vector<ll> v(n);
    vector<bool> dp(k + 1, 0);
    for (i = 0; i < n; i++) {
      cin >> a;
      v[i] = a;
      x = min(x, a);
      dp[a] = 1;
    }
    for (i = x + 1; i <= k; i++) {
      if (dp[i])
        continue;
      for (j = 0; j < n; j++) {
        if (i - v[j] < 0)
          break;
        if (dp[i - v[j]] == 0) {
          dp[i] = 1;
          break;
        }
      }
    }
    if (dp[k])
      cout << "First\n";
    else
      cout << "Second\n";
  }
}
Problem p03170 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define inf (long long)1e18
using namespace std;
int n, k, a[101];
bool dp[100001];
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 0; i < n; i++)
    scanf("%d", &a[i]);
  for (int i = 0; i < k; i++)
    if (!dp[i]) { // losing position
      for (int j = 0; j < n; j++)
        dp[i + a[j]] = true; // winning
      // removing a[j] stones will result in losing position (of opponent)
      // so you win (first player)
    }
  printf(dp[k] ? "First\n" : "Second\n");
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define inf (long long)1e18
using namespace std;
int n, k, a[101];
bool dp[100001];
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 0; i < n; i++)
    scanf("%d", &a[i]);
  for (int i = 0; i < k; i++)
    if (!dp[i]) { // losing position
      for (int j = 0; j < n; j++)
        if (i + a[j] <= k)
          dp[i + a[j]] = true; // winning
      // removing a[j] stones will result in losing position (of opponent)
      // so you win (first player)
    }
  printf(dp[k] ? "First\n" : "Second\n");
  return 0;
}
Problem p03170 (C++)

Buggy submission (status: Runtime Error):
/* ---------- STL Libraries ---------- */
// IO library
#include <cstdio>
#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>
#include <cmath>
#include <numeric>
#include <random>

// container library
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <unordered_map>
#include <vector>

/* ---------- Namespace ---------- */
using namespace std;

/* ---------- Type ---------- */
using ll = long long;
#define int ll
#define P pair<ll, ll>

/* ---------- Constants  */
const ll MOD = 1e9 + 7;
const int INF = 1LL << 55;

/* v-v-v-v-v-v-v-v-v Main Part v-v-v-v-v-v-v-v-v */
signed main() {
  int N, K;
  cin >> N >> K;
  int A[N];
  for (int i = 0; i < N; i++)
    cin >> A[i];
  sort(A, A + N);

  int dp[K + 1];
  fill(dp, dp + K + 1, 0);
  for (int i = 0; i < A[0]; i++) {
    dp[i] = -1;
  }

  for (int i = A[0]; i <= K; i++) {
    bool lose = true;
    for (int j = 0; j < N; j++) {
      if (i - A[j] >= 0 && dp[i - A[j]] == -1) {
        dp[i] = 1;
        lose = false;
        break;
      }
    }
    if (lose)
      A[i] = -1;
  }

  cout << (dp[K] == 1 ? "First" : "Second") << endl;

  return 0;
}

Fixed submission:
/* ---------- STL Libraries ---------- */
// IO library
#include <cstdio>
#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>
#include <cmath>
#include <numeric>
#include <random>

// container library
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <unordered_map>
#include <vector>

/* ---------- Namespace ---------- */
using namespace std;

/* ---------- Type ---------- */
using ll = long long;
#define int ll
#define P pair<ll, ll>

/* ---------- Constants  */
const ll MOD = 1e9 + 7;
const int INF = 1LL << 55;

/* v-v-v-v-v-v-v-v-v Main Part v-v-v-v-v-v-v-v-v */
signed main() {
  int N, K;
  cin >> N >> K;
  int A[N];
  for (int i = 0; i < N; i++)
    cin >> A[i];
  sort(A, A + N);

  int dp[K + 1];
  fill(dp, dp + K + 1, 0);
  for (int i = 0; i < A[0]; i++) {
    dp[i] = -1;
  }

  for (int i = A[0]; i <= K; i++) {
    bool lose = true;
    for (int j = 0; j < N; j++) {
      if (i - A[j] >= 0 && dp[i - A[j]] == -1) {
        dp[i] = 1;
        lose = false;
        break;
      }
    }
    if (lose)
      dp[i] = -1;
  }

  cout << (dp[K] == 1 ? "First" : "Second") << endl;

  return 0;
}
Problem p03170 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define rep(i, n) for (ll i = 0; i < n; i++)
#define rep1(i, n) for (ll i = 1; i <= n; i++)
#define mp make_pair
#define F first
#define S second
#define pf pop_front
#define IOS                                                                    \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0)
typedef long long ll;
const ll mod = 1e9 + 7;
const ll maxn = 305;
const ll inf = 1e9 + 7;
ll dp[maxn];
ll n, k;
ll a[maxn];
int main() {
  cin >> n >> k;
  memset(dp, 0, sizeof(dp));
  rep(i, n) cin >> a[i];
  for (int i = 0; i <= k; i++) {
    if (!dp[i])
      rep(j, n) {
        if (i + a[j] <= k)
          dp[i + a[j]] = 1;
      }
  }
  if (dp[k])
    cout << "First\n";
  else
    cout << "Second\n";
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define rep(i, n) for (ll i = 0; i < n; i++)
#define rep1(i, n) for (ll i = 1; i <= n; i++)
#define mp make_pair
#define F first
#define S second
#define pf pop_front
#define IOS                                                                    \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0)
typedef long long ll;
const ll mod = 1e9 + 7;
const ll maxn = 100005;
const ll inf = 1e9 + 7;
ll dp[maxn];
ll n, k;
ll a[maxn];
int main() {
  cin >> n >> k;
  memset(dp, 0, sizeof(dp));
  rep(i, n) cin >> a[i];
  for (int i = 0; i <= k; i++) {
    if (!dp[i])
      rep(j, n) {
        if (i + a[j] <= k)
          dp[i + a[j]] = 1;
      }
  }
  if (dp[k])
    cout << "First\n";
  else
    cout << "Second\n";
}
Problem p03170 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define ll long long int
const int MOD = 1e9 + 7;
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  int dp[k + 1];
  vector<int> v;
  for (int i = 0; i <= k; i++)
    dp[i] = 0;
  for (int i = 1; i <= n; i++) {
    int last_element;
    cin >> last_element;
    v.push_back(last_element);
  }
  for (int suppose_sum = 0; suppose_sum <= k; suppose_sum++) {
    for (int first_chosen :
         v) // lets us  suppose that sum is suppose_sum then if
    {       // first turn is given to firtst palyer(taro)
      if (!dp[suppose_sum -
              first_chosen]) // dp[i]=1 if taro wins and 0 if 2nd player wins
        dp[suppose_sum] = 1; // * first_chosen is the first value chosen by TARO
    }                        // we look at all possibilites of first_chosen
  } // and if for any first value we come to know that taro
  (dp[k]) ? (cout << "First")
          : (cout << "Second"); // wins then we update it as 0 bcoz taro is
                                // playing optimally
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define ll long long int
const int MOD = 1e9 + 7;
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  int dp[k + 1];
  vector<int> v;
  for (int i = 0; i <= k; i++)
    dp[i] = 0;
  for (int i = 1; i <= n; i++) {
    int last_element;
    cin >> last_element;
    v.push_back(last_element);
  }
  for (int suppose_sum = 0; suppose_sum <= k; suppose_sum++) {
    for (int first_chosen :
         v) // lets us  suppose that sum is suppose_sum then if
    {       // first turn is given to firtst palyer(taro)
      if (suppose_sum >= first_chosen &&
          !dp[suppose_sum -
              first_chosen]) // dp[i]=1 if taro wins and 0 if 2nd player wins
        dp[suppose_sum] = 1; // * first_chosen is the first value chosen by TARO
    }                        // we look at all possibilites of first_chosen
  } // and if for any first value we come to know that taro
  (dp[k]) ? (cout << "First")
          : (cout << "Second"); // wins then we update it as 0 bcoz taro is
                                // playing optimally
  return 0;
}
Problem p03170 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>

using namespace std;

const int N(109);

int n, m, k, ans;
int a[N];
int f[N][2];

int main() {
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i <= k; i++) {
    for (int j = 0; j < 2; j++) {
      for (int l = 1; l <= n; l++) {
        if (i >= a[l] && !f[i - a[l]][!j]) {
          f[i][j] = 1;
        }
      }
    }
  }
  if (f[k][0])
    cout << "First" << endl;
  else
    cout << "Second" << endl;
  return 0;
}

Fixed submission:
#include <iostream>

using namespace std;

const int N(109);

int n, m, k, ans;
int a[N];
int f[100005][2];

int main() {
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i <= k; i++) {
    for (int j = 0; j < 2; j++) {
      for (int l = 1; l <= n; l++) {
        if (i >= a[l] && !f[i - a[l]][!j]) {
          f[i][j] = 1;
        }
      }
    }
  }
  if (f[k][0])
    cout << "First" << endl;
  else
    cout << "Second" << endl;
  return 0;
}
Problem p03170 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define sf(n) scanf("%lld", &n)
#define sff(n, m) scanf("%lld %lld", &n, &m)
#define fastio                                                                 \
  ios::sync_with_stdio(0);                                                     \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define PLL pair<ll, ll>
#define mod 1000000007
#define mx 1000002
#define FILE freopen("input.txt", "r", stdin)

ll n;
ll a[102];
ll dp[102];

ll F(ll x) {
  if (dp[x] != -1)
    return dp[x];

  ll ret = 0;

  for (ll i = 1; i <= n; i++) {
    if (a[i] <= x)
      ret = ret | F(x - a[i]);
  }

  return dp[x] = !ret;
}

int main() {
  ll k;
  sff(n, k);

  for (ll i = 1; i <= n; i++) {
    sf(a[i]);
  }

  memset(dp, -1, sizeof dp);

  if (!F(k))
    cout << "First" << endl;
  else
    cout << "Second" << endl;

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define sf(n) scanf("%lld", &n)
#define sff(n, m) scanf("%lld %lld", &n, &m)
#define fastio                                                                 \
  ios::sync_with_stdio(0);                                                     \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define PLL pair<ll, ll>
#define mod 1000000007
#define mx 1000002
#define FILE freopen("input.txt", "r", stdin)

ll n;
ll a[102];
ll dp[mx];

ll F(ll x) {
  if (dp[x] != -1)
    return dp[x];

  ll ret = 0;

  for (ll i = 1; i <= n; i++) {
    if (a[i] <= x)
      ret = ret | F(x - a[i]);
  }

  return dp[x] = !ret;
}

int main() {
  ll k;
  sff(n, k);

  for (ll i = 1; i <= n; i++) {
    sf(a[i]);
  }

  memset(dp, -1, sizeof dp);

  if (!F(k))
    cout << "First" << endl;
  else
    cout << "Second" << endl;

  return 0;
}
Problem p03170 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int n, k;
int a[100];
int dp[100001][2];
// dp[number of remain stone][player id] = winner
// {player id : {First: 0, Second: 1}}
// {winner : {0: First, 1: Second, -1: unknown}}

int dfs(int stones, int player) {
  if (dp[stones][player] != -1)
    return dp[stones][player];
  bool win = false;
  for (int i = 0; i < n && (!win); i++) {
    if (dfs(stones - a[i], (player + 1) % 2) == player)
      win = true;
  }
  if (win)
    dp[stones][player] = player;
  else
    dp[stones][player] = (player + 1) % 2;
  return dp[stones][player];
}

int main() {
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i <= k; i++) {
    dp[i][0] = -1;
    dp[i][1] = -1;
  }
  for (int i = 0; i < a[0]; i++) {
    dp[i][0] = 1;
    dp[i][1] = 0;
  }
  cout << (dfs(k, 0) == 0 ? "First" : "Second") << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int n, k;
int a[100];
int dp[100001][2];
// dp[number of remain stone][player id] = winner
// {player id : {First: 0, Second: 1}}
// {winner : {0: First, 1: Second, -1: unknown}}

int dfs(int stones, int player) {
  if (dp[stones][player] != -1)
    return dp[stones][player];
  bool win = false;
  for (int i = 0; i < n && (!win); i++) {
    if (stones - a[i] >= 0) {
      if (dfs(stones - a[i], (player + 1) % 2) == player)
        win = true;
    }
  }
  if (win)
    dp[stones][player] = player;
  else
    dp[stones][player] = (player + 1) % 2;
  return dp[stones][player];
}

int main() {
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i <= k; i++) {
    dp[i][0] = -1;
    dp[i][1] = -1;
  }
  for (int i = 0; i < a[0]; i++) {
    dp[i][0] = 1;
    dp[i][1] = 0;
  }
  cout << (dfs(k, 0) == 0 ? "First" : "Second") << endl;
}
Problem p03170 (C++)

Buggy submission (status: Runtime Error):
#include <cstdio>
#include <iostream>

using namespace std;

int n, k;
int a[110];
bool f[10010];

int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; ++i)
    scanf("%d", &a[i]);
  for (int i = 1; i <= k; ++i)
    for (int j = 1; j <= n && a[j] <= i; ++j)
      if (!f[i - a[j]]) {
        f[i] = 1;
        break;
      }
  printf(f[k] ? "First" : "Second");
  return 0;
}

Fixed submission:
#include <cstdio>
#include <iostream>

using namespace std;

int n, k;
int a[110];
bool f[100010];

int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; ++i)
    scanf("%d", &a[i]);
  for (int i = 1; i <= k; ++i)
    for (int j = 1; j <= n && a[j] <= i; ++j)
      if (!f[i - a[j]]) {
        f[i] = 1;
        break;
      }
  printf(f[k] ? "First" : "Second");
  return 0;
}
Problem p03170 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long unsigned int ll;

// definition {{{ 1

// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x, y) scanf("%d%d", &x, &y)
#define Scd3(x, y, z) scanf("%d%d%d", &x, &y, &z)

#define Scll(x) scanf("%llu", &x)
#define Scll2(x, y) scanf("%llu%llu", &x, &y)
#define Scll3(x, y, z) scanf("%llu%llu%llu", &x, &y, &z)

#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2

// constants {{{ 2
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
// }}} 2

// systems {{{ 2
#define Rep(x, y) for (int x = 0; x < y; x++)
#define Repe(x, y, z) for (int x = z; x < y; x++)
// }}} 2

// output {{{ 2
#define YesNo(a) (a) ? printf("Yes\n") : printf("No\n");
// }}} 2

// }}} 1

int main() {

  int N, K, a[102];
  Scd2(N, K);
  Rep(i, N) Scd(a[i]);

  int dp[100002] = {};
  Rep(i, K + 1) {
    if (dp[i] == 0) {
      Rep(j, N) { dp[i + a[j]] = 1; }
    }
  }

  printf(dp[K] ? "First" : "Second");
  printf("\n");

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long unsigned int ll;

// definition {{{ 1

// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x, y) scanf("%d%d", &x, &y)
#define Scd3(x, y, z) scanf("%d%d%d", &x, &y, &z)

#define Scll(x) scanf("%llu", &x)
#define Scll2(x, y) scanf("%llu%llu", &x, &y)
#define Scll3(x, y, z) scanf("%llu%llu%llu", &x, &y, &z)

#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2

// constants {{{ 2
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
// }}} 2

// systems {{{ 2
#define Rep(x, y) for (int x = 0; x < y; x++)
#define Repe(x, y, z) for (int x = z; x < y; x++)
// }}} 2

// output {{{ 2
#define YesNo(a) (a) ? printf("Yes\n") : printf("No\n");
// }}} 2

// }}} 1

int main() {

  int N, K, a[102];
  Scd2(N, K);
  Rep(i, N) Scd(a[i]);

  int dp[200002] = {};
  Rep(i, K + 1) {
    if (dp[i] == 0) {
      Rep(j, N) { dp[i + a[j]] = 1; }
    }
  }

  printf(dp[K] ? "First" : "Second");
  printf("\n");

  return 0;
}
Problem p03170 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

int main() {
  int n, k;
  cin >> n >> k;
  int a[n];
  for (int i = 0; i < n; i++)
    cin >> a[i];
  sort(a, a + n);
  long long int dp[k + 1];
  dp[0] = 0;
  for (int i = 1; i <= k; i++) {
    if (i < a[0])
      dp[i] = 0;
    for (int j = 0; j <= n; j++) {
      if (j == n) {
        dp[i] = 0;
        break;
      }
      if (!dp[i - a[j]]) {
        dp[i] = 1;
        break;
      }
    }
  }
  if (dp[k] == 1)
    cout << "First";
  else
    cout << "Second";
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;

int main() {
  int n, k;
  cin >> n >> k;
  int a[n];
  for (int i = 0; i < n; i++)
    cin >> a[i];
  sort(a, a + n);
  long long int dp[k + 1];
  dp[0] = 0;
  for (int i = 1; i <= k; i++) {
    if (i < a[0])
      dp[i] = 0;
    else {
      for (int j = 0; j <= n; j++) {
        if (j == n) {
          dp[i] = 0;
          break;
        }
        if (i >= a[j]) {
          if (!dp[i - a[j]]) {
            dp[i] = 1;
            break;
          }
        } else
          break;
      }
    }
  }
  if (dp[k] == 1)
    cout << "First";
  else
    cout << "Second";
}
Problem p03170 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>

#define taskname ""
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define for0(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n)-1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

using namespace std;

typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
typedef vector<cd> vcd;
typedef vector<int> vi;

template <class T> using v2d = vector<vector<T>>;
template <class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template <class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

mt19937 rng(chrono::system_clock::now().time_since_epoch().count());

const int maxN = 1e2 + 10;
const int maxK = 1e5 + 10;

int n, k;
int a[maxN];

bool dp[maxK];

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> n >> k;
  for1(i, n) { cin >> a[i]; }
  for0(i, k) {
    for1(j, n) { dp[i + a[j]] |= !dp[i]; }
  }
  if (dp[k]) {
    cout << "First";
  } else {
    cout << "Second";
  }
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>

#define taskname ""
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define for0(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n)-1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

using namespace std;

typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
typedef vector<cd> vcd;
typedef vector<int> vi;

template <class T> using v2d = vector<vector<T>>;
template <class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template <class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

mt19937 rng(chrono::system_clock::now().time_since_epoch().count());

const int maxN = 1e2 + 10;
const int maxK = 1e5 + 10;

int n, k;
int a[maxN];

bool dp[maxK];

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> n >> k;
  for1(i, n) { cin >> a[i]; }
  for0(i, k) {
    for1(j, n) {
      if (i + a[j] <= k) {
        dp[i + a[j]] |= !dp[i];
      }
    }
  }
  if (dp[k]) {
    cout << "First";
  } else {
    cout << "Second";
  }
  return 0;
}
Problem p03170 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int i, j, k, n, imin = 0;
  int minn = INT_MAX;
  int maxx = INT_MIN;
  cin >> n >> k;
  int dp[k + 1];
  int arr[n];
  for (i = 0; i <= k; i++) {
    dp[i] = 1;
  }
  for (i = 0; i < n; i++) {
    cin >> arr[i];
    if (arr[i] < minn) {
      imin = i;
      minn = arr[i];
    }
    dp[arr[i]] = 0;
  }
  for (i = imin + 1; i <= k; i++) {
    if (dp[i] != 0) {
      for (j = 0; j < n; j++) {
        if (arr[j] >= i && dp[i - arr[j]] == 1) {
          dp[i] = 0;
          break;
        }
      }
    }
  }
  if (dp[k] == 0) {
    cout << "First";
  } else {
    cout << "Second";
  }
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int i, j, k, n, imin = 0;
  int minn = INT_MAX;
  int maxx = INT_MIN;
  cin >> n >> k;
  int dp[k + 1];
  int arr[n];
  for (i = 0; i <= k; i++) {
    dp[i] = 1;
  }
  for (i = 0; i < n; i++) {
    cin >> arr[i];
    if (arr[i] < minn) {
      imin = i;
      minn = arr[i];
    }
    dp[arr[i]] = 0;
  }
  for (i = imin + 1; i <= k; i++) {
    if (dp[i] != 0) {
      for (j = 0; j < n; j++) {
        if (i >= arr[j] && dp[i - arr[j]] == 1) {
          dp[i] = 0;
          break;
        }
      }
    }
  }
  if (dp[k] == 0) {
    cout << "First";
  } else {
    cout << "Second";
  }
}
Problem p03170 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

int main() {
  int n, k;
  cin >> n >> k;
  vector<bool> dp(k + 1, false);
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    dp[a[i]] = true;
  }

  for (int i = 0; i <= k; i++) {
    bool ok = false;
    for (int j = 0; j < n; i++) {
      if (i < a[j])
        break;
      if (!dp[i - a[j]]) {
        ok = true;
        break;
      }
    }
    dp[i] = ok;
  }
  if (dp[k]) {
    cout << "First" << endl;
  } else {
    cout << "Second" << endl;
  }
  return 0;
}

Fixed submission:
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

int main() {
  int n, k;
  cin >> n >> k;
  vector<bool> dp(k + 1, false);
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    dp[a[i]] = true;
  }

  for (int i = 0; i <= k; i++) {
    bool ok = false;
    for (int j = 0; j < n; j++) {
      if (i < a[j])
        break;
      if (!dp[i - a[j]]) {
        ok = true;
        break;
      }
    }
    dp[i] = ok;
  }
  if (dp[k]) {
    cout << "First" << endl;
  } else {
    cout << "Second" << endl;
  }
  return 0;
}
Problem p03170 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < n; i++)

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> A(n);
  rep(i, n) cin >> A[i];
  bool dp[101010] = {0};
  for (int i = 0; i < k + 1; i++) {
    if (dp[i])
      continue;
    for (int j = 0; j < n; j++) {
      dp[i + A[j]] = 1;
    }
  }
  cout << (dp[k] ? "First" : "Second") << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < n; i++)

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> A(n);
  rep(i, n) cin >> A[i];
  bool dp[201010] = {0};
  for (int i = 0; i < k + 1; i++) {
    if (dp[i])
      continue;
    for (int j = 0; j < n; j++) {
      dp[i + A[j]] = 1;
    }
  }
  cout << (dp[k] ? "First" : "Second") << endl;
  return 0;
}
Problem p03170 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define MP make_pair
#define PB push_back
#define ll int64_t
#define F first
#define S second
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
using namespace std;
ll modex(ll a, int b, ll p) {
  ll res = 1;
  a %= p;
  while (b > 0) {
    if (b & 1)
      res = (res * a) % p;
    a = (a * a) % p;
    b >>= 1;
  }
  return res;
}

int n;
int a[102];
int dp[2][102];

int win(int t, int k) {

  if (dp[t][k] != -1)
    return dp[t][k];

  int w = 1 - t;

  for (int i = 0; i < n; i++)
    if (a[i] <= k && win(1 - t, k - a[i]) == t)
      w = t;

  return dp[t][k] = w;
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);

  memset(dp, -1, sizeof dp);

  int k;
  cin >> n >> k;

  for (int i = 0; i < n; i++)
    cin >> a[i];

  int ans = win(0, k);

  if (ans == 0)
    cout << "First\n";
  else
    cout << "Second\n";

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define MP make_pair
#define PB push_back
#define ll int64_t
#define F first
#define S second
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
using namespace std;
ll modex(ll a, int b, ll p) {
  ll res = 1;
  a %= p;
  while (b > 0) {
    if (b & 1)
      res = (res * a) % p;
    a = (a * a) % p;
    b >>= 1;
  }
  return res;
}

int n;
int a[102];
int dp[2][100005];

int win(int t, int k) {

  if (dp[t][k] != -1)
    return dp[t][k];

  int w = 1 - t;

  for (int i = 0; i < n; i++)
    if (a[i] <= k && win(1 - t, k - a[i]) == t)
      w = t;

  return dp[t][k] = w;
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);

  memset(dp, -1, sizeof dp);

  int k;
  cin >> n >> k;

  for (int i = 0; i < n; i++)
    cin >> a[i];

  int ans = win(0, k);

  if (ans == 0)
    cout << "First\n";
  else
    cout << "Second\n";

  return 0;
}