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

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

using namespace std;
#define X first
#define Y second
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;

#define debug(x) cerr << #x << " = " << (x) << endl;
template <typename T> ostream &operator<<(ostream &o, vector<T> &v) {
  for (auto &x : v)
    o << x << ' ';
  return o;
}

int n, k;
int arr[110];
int memo[100100];
int dp(int k) {
  int &res = memo[k];
  if (res != -1)
    return res;
  if (k == 0)
    return res = 0;
  for (int i = 0; i < n; i++) {
    if (arr[i] <= k) {
      if (dp(k) == 0)
        return res = 1;
    }
  }
  return res = 0;
}

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

  cin >> n >> k;
  for (int i = 0; i < n; i++)
    cin >> arr[i];
  memset(memo, -1, sizeof memo);
  if (dp(k))
    cout << "First" << endl;
  else
    cout << "Second" << endl;
}


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

using namespace std;
#define X first
#define Y second
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;

#define debug(x) cerr << #x << " = " << (x) << endl;
template <typename T> ostream &operator<<(ostream &o, vector<T> &v) {
  for (auto &x : v)
    o << x << ' ';
  return o;
}

int n, k;
int arr[110];
int memo[100100];
int dp(int k) {
  int &res = memo[k];
  if (res != -1)
    return res;
  if (k == 0)
    return res = 0;
  for (int i = 0; i < n; i++) {
    if (arr[i] <= k) {
      if (dp(k - arr[i]) == 0)
        return res = 1;
    }
  }
  return res = 0;
}

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

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

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
int n, k;
int v[102];
int dp[100002];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> k;
  for (int i = 1; i <= n; ++i)
    cin >> v[i];
  // 2 = losing state, 1 = winning state
  for (int i = 0; i < k; ++i) {
    if (dp[i] == 0)
      dp[i] = 2;
    for (int j = 1; j <= n; ++j) {
      if (dp[i + v[j]] == 1 || i + v[j] > k)
        continue;
      dp[i + v[j]] = 3 - dp[i];
    }
  }
  if (dp[k] == 1)
    cout << "First";
  else
    cout << "Second";
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
int n, k;
int v[102];
int dp[100002];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> k;
  for (int i = 1; i <= n; ++i)
    cin >> v[i];
  // 2 = losing state, 1 = winning state
  for (int i = 0; i < k; ++i) {
    if (dp[i] == 0)
      dp[i] = 2;
    for (int j = 1; j <= n; ++j) {
      if (i + v[j] > k || dp[i + v[j]] == 1)
        continue;
      dp[i + v[j]] = 3 - dp[i];
    }
  }
  if (dp[k] == 1)
    cout << "First";
  else
    cout << "Second";
  return 0;
}
Problem p03170 (C++)

Buggy submission (status: Runtime Error):
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(vec) vec.begin(), vec.end()
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
const ll mod = 1e9 + 7;
const int inf = 1 << 30;

bool dp[110];

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  rep(i, k + 1) {
    rep(j, n) {
      if (i - a[j] >= 0)
        dp[i] |= (!dp[i - a[j]]);
    }
  }
  if (dp[k])
    cout << "First" << endl;
  else
    cout << "Second" << endl;
}

Fixed submission:
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(vec) vec.begin(), vec.end()
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
const ll mod = 1e9 + 7;
const int inf = 1 << 30;

bool dp[100010];

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  rep(i, k + 1) {
    rep(j, n) {
      if (i - a[j] >= 0)
        dp[i] |= (!dp[i - a[j]]);
    }
  }
  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;
int main() {
  int n, k;

  cin >> n >> k;
  vector<int> v(n), dp(k + 1);
  for (int i = 0; i < n; i++)
    cin >> v[i];
  for (int i = 0; i <= k; i++) {
    if (!dp[i])
      for (auto x : v)
        dp[i + x] = 1;
  }
  cout << (dp[k] ? "First" : "Second");
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;

  cin >> n >> k;
  vector<int> v(n), dp(k + 1);
  for (int i = 0; i < n; i++)
    cin >> v[i];
  for (int i = 0; i <= k; i++) {
    if (!dp[i])
      for (auto x : v)
        if (i + x <= k)
          dp[i + x] = 1;
  }
  cout << (dp[k] ? "First" : "Second");
  return 0;
}
Problem p03170 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>

using namespace std;

int dp[100006];
int arr[106];
int n;
int fun(int k) {

  if (k == 0)
    return 0;

  if (dp[k] != -1)
    return dp[k];
  int ans = 0;

  for (int i = 0; i < n; i++) {
    if (arr[i] <= k)
      ans |= (!fun(k - arr[i]));
  }
  // cout<<k<<" "<<ans<<endl;
  return dp[n] = ans;
}

int main() {

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

  for (int i = 0; i < k; i++)
    dp[i + 1] = -1;

  if (fun(k) == 0)
    cout << "Second" << endl;
  else
    cout << "First" << endl;
  return 0;
}

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

using namespace std;

int dp[100006];
int arr[106];
int n;
int fun(int k) {

  if (k == 0)
    return 0;

  if (dp[k] != -1)
    return dp[k];
  int ans = 0;

  for (int i = 0; i < n; i++) {
    if (arr[i] <= k)
      ans |= (!fun(k - arr[i]));
  }
  // cout<<k<<" "<<ans<<endl;
  return dp[k] = ans;
}

int main() {

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

  for (int i = 0; i < k; i++)
    dp[i + 1] = -1;

  if (fun(k) == 0)
    cout << "Second" << endl;
  else
    cout << "First" << endl;
  return 0;
}
Problem p03170 (C++)

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

using namespace std;
struct _ {
  ios_base::Init i;
  _() { ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); }
} _;

int dx[] = {-1, 0, 1, 0, -1, -1, 1, 1};
int dy[] = {0, 1, 0, -1, -1, 1, 1, -1};

int main() {

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

  vector<bool> dp(k + 1, false);
  dp[a[0]] = true;

  for (int i = a[0] + 1; i <= k; i++) {
    for (auto j : a) {
      if (dp[i - j] == false) {
        dp[i] = true;
        break;
      }
    }
  }

  cout << (dp[k] ? "First" : "Second");
  return 0;
}

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

using namespace std;
struct _ {
  ios_base::Init i;
  _() { ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); }
} _;

int dx[] = {-1, 0, 1, 0, -1, -1, 1, 1};
int dy[] = {0, 1, 0, -1, -1, 1, 1, -1};

int main() {

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

  vector<bool> dp(k + 1, false);
  dp[a[0]] = true;

  for (int i = a[0] + 1; i <= k; i++) {
    for (auto j : a) {
      if (i >= j and dp[i - j] == false) {
        dp[i] = true;
        break;
      }
    }
  }

  cout << (dp[k] ? "First" : "Second");
  return 0;
}
Problem p03170 (C++)

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

int main(int argc, char const *argv[]) {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll t = 1;
  // cin>>t;
  while (t--) {
    int n, k;
    cin >> n >> k;
    ll arr[n];
    for (int i = 0; i < n; i++) {
      cin >> arr[i];
    }
    sort(arr, arr + n);
    ll dp[k + 1];
    dp[0] = 1;
    for (int i = 1; i < arr[0]; i++) {
      dp[i] = 1;
    }
    dp[arr[0]] = 0;
    for (int i = arr[0] + 1; i <= k; i++) {
      vector<int> res;
      for (int j = 0; j < n; j++) {
        if (arr[j] > i) {
          break;
        } else {
          res.push_back(dp[i - arr[j]]);
        }
      }
      if (find(res.begin(), res.end(), 1) != res.end()) {
        dp[i] = 0;
      } else
        dp[i] = 1;
    }
    if (dp[k] == 0) {
      cout << "First" << endl;
    } else
      cout << "Second" << endl;
  }
  return 0;
}


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

int main(int argc, char const *argv[]) {

  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll t = 1;
  // cin>>t;
  while (t--) {
    int n, k;
    cin >> n >> k;
    ll arr[n];
    for (int i = 0; i < n; i++) {
      cin >> arr[i];
    }
    sort(arr, arr + n);
    ll dp[k + 1];
    dp[0] = 1;
    for (int i = 1; i < arr[0]; i++) {
      dp[i] = 1;
    }
    dp[arr[0]] = 0;
    for (int i = arr[0] + 1; i <= k; i++) {
      vector<int> res;
      for (int j = 0; j < n; j++) {
        if (arr[j] > i) {
          break;
        } else {
          res.push_back(dp[i - arr[j]]);
        }
      }
      if (find(res.begin(), res.end(), 1) != res.end()) {
        dp[i] = 0;
      } else
        dp[i] = 1;
    }
    if (dp[k] == 0) {
      cout << "First" << endl;
    } else
      cout << "Second" << endl;
  }
  return 0;
}
Problem p03170 (C++)

Buggy submission (status: Runtime Error):
#include <iomanip>
#include <iostream>
#include <map>
#include <vector>
using namespace std;
#define MOD 1000000007

int N, K;
int a[100];
int dp[100001];

int dfs(int x) {
  if (dp[x] != -1)
    return dp[x];

  for (int i = 0; i < N; i++) {
    dp[x - a[i]] = dfs(x - a[i]);
    if (dp[x - a[i]] == 0) {
      dp[x] = 1;
      return 1;
    }
  }
  dp[x] = 0;
  return 0;
}

int main() {
  cin >> N >> K;
  for (int i = 0; i < N; i++)
    cin >> a[i];

  fill_n(dp, K + 1, -1);
  for (int i = 0; i < a[0]; i++)
    dp[i] = 0;

  cout << (dfs(K) ? "First" : "Second") << endl;
  return 0;
}

Fixed submission:
#include <iomanip>
#include <iostream>
#include <map>
#include <vector>
using namespace std;
#define MOD 1000000007

int N, K;
int a[100];
int dp[100001];

int dfs(int x) {
  if (dp[x] != -1)
    return dp[x];

  for (int i = 0; i < N; i++) {
    if (x - a[i] < 0)
      continue;
    dp[x - a[i]] = dfs(x - a[i]);
    if (dp[x - a[i]] == 0) {
      dp[x] = 1;
      return 1;
    }
  }
  dp[x] = 0;
  return 0;
}

int main() {
  cin >> N >> K;
  for (int i = 0; i < N; i++)
    cin >> a[i];

  fill_n(dp, K + 1, -1);
  for (int i = 0; i < a[0]; i++)
    dp[i] = 0;

  cout << (dfs(K) ? "First" : "Second") << endl;
  return 0;
}
Problem p03170 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
typedef pair<bool, int> pbi;
int arr[105];
map<pbi, bool> mp;
bool play(bool turn, int n, int k) {
  if (k == 0)
    return turn;
  pbi temp = pbi(turn, k);
  auto it = mp.begin();
  if ((it = mp.find(temp)) != mp.end())
    return it->second;
  bool flag = turn;
  for (int i = 0; i < n; ++i) {
    if (k >= arr[i]) {
      if (!turn)
        flag |= play(!turn, n, k - arr[i]);
      else
        flag &= play(!turn, n, k - arr[i]);
    }
    if ((!turn && flag) || (turn && !flag))
      break;
  }
  return mp[temp] = flag;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  for (int i = 0; i < n; ++i) {
    cin >> arr[i];
  }
  if (play(0, n, k))
    cout << "First\n";
  else
    cout << "Second\n";
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef pair<bool, int> pbi;
int arr[105];
struct hasher {
  size_t operator()(const pbi &temp) const {
    return hash<bool>()(temp.first) ^ hash<int>()(temp.second);
  }
};
unordered_map<pbi, bool, hasher> mp;
bool play(bool turn, int n, int k) {
  if (k == 0)
    return turn;
  pbi temp = pbi(turn, k);
  auto it = mp.begin();
  if ((it = mp.find(temp)) != mp.end())
    return it->second;
  bool flag = turn;
  for (int i = 0; i < n; ++i) {
    if (k >= arr[i]) {
      if (!turn)
        flag |= play(!turn, n, k - arr[i]);
      else
        flag &= play(!turn, n, k - arr[i]);
    }
    if ((!turn && flag) || (turn && !flag))
      break;
  }
  return mp[temp] = flag;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  for (int i = 0; i < n; ++i) {
    cin >> arr[i];
  }
  if (play(0, n, k))
    cout << "First\n";
  else
    cout << "Second\n";
  return 0;
}
Problem p03170 (C++)

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

#define rep(i, n) for (int i = 0; i < (n); i++)
#define ll long long

using namespace std;

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  rep(i, n) { cin >> a[i]; }

  int dp[101];
  memset(dp, 0, sizeof(dp));

  dp[0] = -1;
  for (int i = 1; i <= k; i++) {
    bool f = true;
    rep(j, n) {
      if (i >= a[j]) {
        if (dp[i - a[j]] == -1) {
          dp[i] = a[j];
          f = false;
          break;
        }
      }
    }
    if (f)
      dp[i] = -1;
    // rep(i, k+1)cout<<dp[i]<<' ';cout<<endl;
  }

  if (dp[k] != -1)
    cout << "First" << endl;
  else
    cout << "Second" << endl;

  return 0;
}

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

#define rep(i, n) for (int i = 0; i < (n); i++)
#define ll long long

using namespace std;

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  rep(i, n) { cin >> a[i]; }

  int dp[100001];
  memset(dp, 0, sizeof(dp));

  dp[0] = -1;
  for (int i = 1; i <= k; i++) {
    bool f = true;
    rep(j, n) {
      if (i >= a[j]) {
        if (dp[i - a[j]] == -1) {
          dp[i] = a[j];
          f = false;
          break;
        }
      }
    }
    if (f)
      dp[i] = -1;
    // rep(i, k+1)cout<<dp[i]<<' ';cout<<endl;
  }

  if (dp[k] != -1)
    cout << "First" << endl;
  else
    cout << "Second" << endl;

  return 0;
}
Problem p03170 (C++)

Buggy submission (status: Runtime Error):

#include "bits/stdc++.h"
#define fast                                                                   \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(NULL);                                                               \
  cout.tie(NULL)
#define f(i, a, b) for (i = a; i < b; i++)
using namespace std;

int n, k, ar[105], dp[100005][2], mn;

int fun(int rem, int x) {
  int i;
  if (rem < mn)
    return dp[rem][x] = x ^ 1;
  if (dp[rem][x] != -1)
    return dp[rem][x];

  dp[rem][x] = x ^ 1;

  f(i, 0, n) {
    if (x)
      dp[rem][x] = max(dp[rem][x], fun(rem - ar[i], x ^ 1));
    else
      dp[rem][x] = min(dp[rem][x], fun(rem - ar[i], x ^ 1));
  }
  return dp[rem][x];
}

int main() {
  fast;
  int i;
  cin >> n >> k;
  f(i, 0, n) cin >> ar[i];
  mn = *min_element(ar, ar + n);
  memset(dp, -1, sizeof(dp));
  (fun(k, 1)) ? cout << "First" : cout << "Second";
}

Fixed submission:

#include "bits/stdc++.h"
#define fast                                                                   \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(NULL);                                                               \
  cout.tie(NULL)
#define f(i, a, b) for (i = a; i < b; i++)
using namespace std;

int n, k, ar[105], dp[100005][2], mn;

int fun(int rem, int x) {
  int i;
  if (rem < mn)
    return dp[rem][x] = x ^ 1;
  if (dp[rem][x] != -1)
    return dp[rem][x];

  dp[rem][x] = x ^ 1;

  f(i, 0, n) {
    if (ar[i] <= rem) {
      if (x)
        dp[rem][x] |= fun(rem - ar[i], x ^ 1);
      else
        dp[rem][x] &= fun(rem - ar[i], x ^ 1);
    }
  }
  return dp[rem][x];
}

int main() {
  fast;
  int i;
  cin >> n >> k;
  f(i, 0, n) cin >> ar[i];
  mn = *min_element(ar, ar + n);
  memset(dp, -1, sizeof(dp));
  (fun(k, 1)) ? cout << "First" : cout << "Second";
}
Problem p03170 (C++)

Buggy submission (status: Runtime Error):
#include <cstdio>
#include <cstring>
#define N 110
using namespace std;

int n, k;
int dp[N][2];
int a[N];

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;
}

signed 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) == true)
    puts("First");
  else
    puts("Second");
}


Fixed submission:
#include <cstdio>
#include <cstring>
#define N 100010
using namespace std;

int n, k;
int dp[N][2];
int a[N];

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;
}

signed 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) == true)
    puts("First");
  else
    puts("Second");
}
Problem p03170 (C++)

Buggy submission (status: Runtime Error):
/** e==m*pow(c,2) **/
#include <bits/stdc++.h>
using namespace std;
#define DEBUG 0
#define LL long long
#define int long long
// #define OFFLINE 2585
#define pii pair<int, int>
#define SQR(n) (n * n)
#define pb push_back
// #define endl '\n'
#define yes cout << "YES" << endl
#define no cout << "NO" << endl
#define INF 100000000000
#define PI (acos(0.0) * 2.0)
#define time_start clock_t tStart = clock()
#define time_end (double)(clock() - tStart) / CLOCKS_PER_SEC
#define maxn 100009
// #pragma GCC diagnostic warning "-std=c++11"
#define check(n, i) (int)(bool(!((n) & (1 << (i)))))
#define set(n, i) (((n) | (1 << (i))))
#define mod 100000007

#define dbg(a) cout << #a << " = " << a << endl;

void faster(void) {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
}

int lcm(int a, int b) { return (a * b) / __gcd(a, b); }

int32_t main() {
#ifdef ONPC
  freopen("in.txt", "r", stdin);
  freopen("out.txt", "w", stdout);
#endif
  faster();
  bool dp[100009];
  memset(dp, 0, sizeof(dp));
  int n, k, i, j, ara[105];
  cin >> n >> k;
  for (i = 0; i < n; i++)
    cin >> ara[i];
  for (i = 0; i <= k; i++) {
    for (j = 0; j < n; j++) {
      // cout<<i<<' '<<dp[i]<<' '<<j<<' '<<ara[j]<<endl;
      // if(dp[i+ara[j]]==1) continue;
      // else if(dp[i]==0) dp[i+ara[j]]=1;
      dp[i + ara[j]] = max((int)dp[i] ^ 1, (int)dp[i + ara[j]]);
    }
  }
  if (DEBUG)
    for (i = 0; i <= k; i++)
      cout << i << ' ' << dp[i] << endl;
  cout << (dp[k] ? "First" : "Second") << endl;
  return 0;
}


Fixed submission:
/** e==m*pow(c,2) **/
#include <bits/stdc++.h>
using namespace std;
#define DEBUG 0
#define LL long long
#define int long long
// #define OFFLINE 2585
#define pii pair<int, int>
#define SQR(n) (n * n)
#define pb push_back
// #define endl '\n'
#define yes cout << "YES" << endl
#define no cout << "NO" << endl
#define INF 100000000000
#define PI (acos(0.0) * 2.0)
#define time_start clock_t tStart = clock()
#define time_end (double)(clock() - tStart) / CLOCKS_PER_SEC
#define maxn 100009
// #pragma GCC diagnostic warning "-std=c++11"
#define check(n, i) (int)(bool(!((n) & (1 << (i)))))
#define set(n, i) (((n) | (1 << (i))))
#define mod 100000007

#define dbg(a) cout << #a << " = " << a << endl;

void faster(void) {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
}

int lcm(int a, int b) { return (a * b) / __gcd(a, b); }

int32_t main() {
#ifdef ONPC
  freopen("in.txt", "r", stdin);
  freopen("out.txt", "w", stdout);
#endif
  faster();
  bool dp[100009];
  memset(dp, 0, sizeof(dp));
  int n, k, i, j, ara[105];
  cin >> n >> k;
  for (i = 0; i < n; i++)
    cin >> ara[i];
  for (i = 0; i <= k; i++) {
    for (j = 0; j < n; j++) {
      // cout<<i<<' '<<dp[i]<<' '<<j<<' '<<ara[j]<<endl;
      // if(dp[i+ara[j]]==1) continue;
      // else if(dp[i]==0) dp[i+ara[j]]=1;
      if (i + ara[j] <= k)
        dp[i + ara[j]] = max((int)dp[i] ^ 1, (int)dp[i + ara[j]]);
    }
  }
  if (DEBUG)
    for (i = 0; i <= k; i++)
      cout << i << ' ' << dp[i] << endl;
  cout << (dp[k] ? "First" : "Second") << endl;
  return 0;
}
Problem p03170 (C++)

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

#define MAX 100005

int who[MAX];

int main() {
  int n, k, lm = MAX;

  cin >> n >> k;

  int a[n];

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

    if (a[i] < lm)
      lm = a[i];
  }

  for (int i = 0; i < lm; i++)
    who[i] = 2;

  for (int i = lm; i <= k; i++) {
    for (int j = 0; j < n; j++) {
      if (who[i - a[j]] == 2) {
        who[i] = 1;
        break;
      }
    }

    if (who[i] == 0)
      who[i] = 2;
  }

  if (who[k] == 1)
    cout << "First";
  else
    cout << "Second";
}


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

#define MAX 100005

int who[MAX];

int main() {
  int n, k, lm = MAX;

  cin >> n >> k;

  int a[n];

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

    if (a[i] < lm)
      lm = a[i];
  }

  for (int i = 0; i < lm; i++)
    who[i] = 2;

  for (int i = lm; i <= k; i++) {
    for (int j = 0; j < n; j++) {
      if (i - a[j] < 0)
        continue;
      if (who[i - a[j]] == 2) {
        who[i] = 1;
        break;
      }
    }

    if (who[i] == 0)
      who[i] = 2;
  }

  if (who[k] == 1)
    cout << "First";
  else
    cout << "Second";
}
Problem p03170 (C++)

Buggy submission (status: Runtime Error):

// ~/SolverToBe/Developers/Corvus
// ~/sudo apt-get verdict Accpeted

#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cstring>
#include <functional>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <memory.h>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
const int N = 105, M = 1000005;
const ll MOD = 1e9 + 7;
const double eps = 1e-9;

int n, k, a[N], dp[2][100005];

int calc(int i, int rem) {
  if (rem == 0)
    return i ^ 1;
  int &r = dp[i][rem];
  if (r != -1)
    return r;
  r = i ^ 1;
  for (int j = 0; j < n; j++)
    if (rem >= a[i] && calc(i ^ 1, rem - a[j]) == i) {
      r = i;
      break;
    }
  return r;
}

int main() {
  scanf("%d%d", &n, &k);
  for (int i = 0; i < n; i++)
    scanf("%d", a + i);
  memset(dp, -1, sizeof dp);
  printf("%s\n", calc(0, k) == 0 ? "First" : "Second");
  return 0;
}

Fixed submission:

// ~/SolverToBe/Developers/Corvus
// ~/sudo apt-get verdict Accpeted

#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cstring>
#include <functional>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <memory.h>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
const int N = 105, M = 1000005;
const ll MOD = 1e9 + 7;
const double eps = 1e-9;

int n, k, a[N], dp[2][100005];

int calc(int i, int rem) {
  if (rem == 0)
    return i ^ 1;
  int &r = dp[i][rem];
  if (r != -1)
    return r;
  r = i ^ 1;
  for (int j = 0; j < n; j++)
    if (rem >= a[j] && calc(i ^ 1, rem - a[j]) == i) {
      r = i;
      break;
    }
  return r;
}

int main() {
  scanf("%d%d", &n, &k);
  for (int i = 0; i < n; i++)
    scanf("%d", a + i);
  memset(dp, -1, sizeof dp);
  printf("%s\n", calc(0, k) == 0 ? "First" : "Second");
  return 0;
}
Problem p03170 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(x) (x).begin(), (x).end()
using namespace std;
const int INF = 1145141919, MOD = 1e9 + 7;
const long long LINF = 8931145141919364364, LMOD = 998244353;
inline long long mod(long long n, long long m) { return (n % m + m) % m; }
// const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};

int n, k;
int a[110];
// dp[i][j]:=i残してjに回したときの勝敗
int dp[100010][2];
int dfs(int num, int who) {
  // cout<<num<<endl;
  if (dp[num][who] != -1)
    return dp[num][who];
  int ret = (who + 1) % 2;
  bool flg = 1;
  rep(i, n) {
    if (num - a[i] >= 0) {
      int tmp = dfs(num - a[i], (who + 1) % 2);
      if (tmp == who)
        ret = tmp;
      flg = 0;
    }
  }
  if (flg) {
    dp[num][who] = (who + 1) % 2;
    return dp[num][who];
  }
  return ret;
}
int main() {
  cin >> n >> k;
  rep(i, n) cin >> a[i];
  if (n == 1) {
    cout << (k / a[0] % 2 ? "First" : "Second") << endl;
    return 0;
  }
  rep(i, 100010) rep(j, 2) dp[i][j] = -1;
  cout << (dfs(k, 0) ? "Second" : "First") << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(x) (x).begin(), (x).end()
using namespace std;
const int INF = 1145141919, MOD = 1e9 + 7;
const long long LINF = 8931145141919364364, LMOD = 998244353;
inline long long mod(long long n, long long m) { return (n % m + m) % m; }
// const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};

int n, k;
int a[110];
// dp[i][j]:=i残してjに回したときの勝敗
int dp[100010][2];
int dfs(int num, int who) {
  // cout<<num<<endl;
  if (dp[num][who] != -1)
    return dp[num][who];
  int ret = (who + 1) % 2;
  bool flg = 1;
  rep(i, n) {
    if (num - a[i] >= 0) {
      int tmp = dfs(num - a[i], (who + 1) % 2);
      if (tmp == who)
        ret = tmp;
      flg = 0;
    }
  }
  dp[num][who] = ret;
  return dp[num][who];
}
int main() {
  cin >> n >> k;
  rep(i, n) cin >> a[i];
  if (n == 1) {
    cout << (k / a[0] % 2 ? "First" : "Second") << endl;
    return 0;
  }
  rep(i, 100010) rep(j, 2) dp[i][j] = -1;
  cout << (dfs(k, 0) ? "Second" : "First") << endl;
  return 0;
}
Problem p03170 (C++)

Buggy submission (status: Runtime Error):
#include "bits/stdc++.h"
using namespace std;
int f[101], a[101];
int n, m;
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++)
    scanf("%d", &a[i]);
  for (int i = 1; i <= m; i++) {
    for (int j = 1; j <= n; j++) {
      if (a[j] <= i && !f[i - a[j]]) {
        f[i] = 1;
        break;
      } else if (a[j] <= i && f[i - a[j]])
        f[i] = 0;
    }
    // printf("**%d %d\n",i,f[i]);
  }
  if (f[m] == 1)
    printf("First");
  else
    printf("Second");
}

Fixed submission:
#include "bits/stdc++.h"
using namespace std;
int f[100001], a[101];
int n, m;
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++)
    scanf("%d", &a[i]);
  for (int i = 1; i <= m; i++) {
    for (int j = 1; j <= n; j++) {
      if (a[j] <= i && !f[i - a[j]]) {
        f[i] = 1;
        break;
      } else if (a[j] <= i && f[i - a[j]])
        f[i] = 0;
    }
    // printf("**%d %d\n",i,f[i]);
  }
  if (f[m] == 1)
    printf("First");
  else
    printf("Second");
}
Problem p03170 (C++)

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

using namespace std;

#define gcd __gcd
#define F first
#define B begin()
#define E end()
#define ln length()
#define sz size()
#define S second
#define em empty()
#define mp make_pair
#define pb push_back
#define pq priority_queue
#define um unordered_map
#define us unordered_set
#define lb lower_bound
#define ub upper_bound
#define smin(a, b) a = min(a, b)
#define smax(a, b) a = max(a, b)
#define sbits(a) __builtin_popcount(a)
#define lcm(a, b) ((a * b) / gcd(a, b))
#define nani(x) cerr << #x << " is " << x << endl;
#define adde(g, u, v) g[u].pb(v), g[v].pb(u);
#define addew(g, u, v, w) g[u].pb({v, w}), g[v].pb({u, w});
#define fast ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define inf 10000000000
#define mod 1000000007

typedef long long ll;

const int N = 1e5 + 5;

int A[105];
bool dp[N];

int main() {
  fast;

  // freopen("input.txt", "r", stdin);
  // freopen("output.txt", "w", stdout);

  int n, k;
  cin >> n >> k;

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

  for (int i = 0; i <= k; i++) {
    int z = !dp[i];
    for (int x = 0; x < n; x++) {
      if (i + A[x] <= k && !dp[i + A[x]])
        dp[i + A[i]] |= z;
    }
  }

  if (dp[k])
    cout << "First";
  else
    cout << "Second";

  return 0;
}


Fixed submission:
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

#define gcd __gcd
#define F first
#define B begin()
#define E end()
#define ln length()
#define sz size()
#define S second
#define em empty()
#define mp make_pair
#define pb push_back
#define pq priority_queue
#define um unordered_map
#define us unordered_set
#define lb lower_bound
#define ub upper_bound
#define smin(a, b) a = min(a, b)
#define smax(a, b) a = max(a, b)
#define sbits(a) __builtin_popcount(a)
#define lcm(a, b) ((a * b) / gcd(a, b))
#define nani(x) cerr << #x << " is " << x << endl;
#define adde(g, u, v) g[u].pb(v), g[v].pb(u);
#define addew(g, u, v, w) g[u].pb({v, w}), g[v].pb({u, w});
#define fast ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define inf 10000000000
#define mod 1000000007

typedef long long ll;

const int N = 1e5 + 5;

int A[105];
bool dp[N];

int main() {
  fast;

  // freopen("input.txt", "r", stdin);
  // freopen("output.txt", "w", stdout);

  int n, k;
  cin >> n >> k;

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

  for (int i = 0; i <= k; i++) {
    int z = !dp[i];
    for (int x = 0; x < n; x++) {
      if (i + A[x] <= k && !dp[i + A[x]])
        dp[i + A[x]] |= z;
    }
  }

  if (dp[k])
    cout << "First";
  else
    cout << "Second";

  return 0;
}
Problem p03170 (C++)

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

int stones(vector<int> &v, int k) {
  int dp[k + 1];
  memset(dp, 0, sizeof(dp));

  for (int i = 1; i <= k; i++) {
    for (int x : v) {
      if (i < x)
        continue;
      if (dp[i - x] == 0)
        dp[i] = 1;
      // if taro starts with k ans removing some value
      // dp[i-ai] = 1 then other person will win from that k.
    }
  }
  return dp[k];
}

void solve() {
  int n, k;
  cin >> n >> k;
  vector<int> v;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    v.push_back(x);
  }

  if (stones(v, k) == 1)
    cout << "First";
  else
    cout << "Second";
}
int main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  solve();

  return 0;
}

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

int stones(vector<int> &v, int k) {
  int dp[k + 1];
  memset(dp, 0, sizeof(dp));

  for (int i = 1; i <= k; i++) {
    for (int x : v) {
      if (i < x)
        continue;
      if (dp[i - x] == 0)
        dp[i] = 1;
      // if taro starts with k ans removing some value
      // dp[i-ai] = 1 then other person will win from that k.
    }
  }
  return dp[k];
}

void solve() {
  int n, k;
  cin >> n >> k;
  vector<int> v;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    v.push_back(x);
  }

  if (stones(v, k) == 1)
    cout << "First";
  else
    cout << "Second";
}
int main() {
  //  #ifndef ONLINE_JUDGE
  //   freopen("input.txt", "r", stdin);
  //   freopen("output.txt", "w", stdout);
  // #endif
  solve();

  return 0;
}
Problem p03170 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
const int N = 1e2 + 9;
const int K = 1e5 + 9;

int n, k;
int a[N];
bool dp[K]; // 石の個数が k 個なら first は必ず負ける

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

  fill(&dp[0], &dp[K], true);
  for (int s = 0; s <= k; s++) {
    for (int i = 1; i <= n; i++) {
      if (dp[s])
        dp[s + a[i]] = false;
    }
  }

  cout << (dp[k] ? "Second" : "First") << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
const int N = 1e2 + 9;
const int K = 1e6;

int n, k;
int a[N];
bool dp[K]; // 石の個数が k 個なら first は必ず負ける

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

  fill(&dp[0], &dp[K], true);
  for (int s = 0; s <= k; s++) {
    for (int i = 1; i <= n; i++) {
      if (dp[s])
        dp[s + a[i]] = false;
    }
  }

  cout << (dp[k] ? "Second" : "First") << endl;
}
Problem p03170 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<long>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvb = vector<vector<bool>>;
using vvc = vector<vector<char>>;
using vvl = vector<vector<long>>;
using pii = pair<int, int>;
using pil = pair<int, long>;
using pll = pair<long, long>;
#define fix20 cout << fixed << setprecision(20)
#define YES cout << "Yes" << endl
#define NO cout << "No" << endl
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, s, t) for (int i = s; i < t; i++)
#define RNG(i, s, t, u) for (int i = s; i < t; i += u)
#define MOD 1000000007
#define all(vec) vec.begin(), vec.end()

vi dp(100010, -1);

int dfs(vi &a, int i) {
  if (dp[i] != -1)
    return dp[i];
  if (i < a[0])
    return dp[i] = 0;
  int ret = 0;
  for (int v : a) {
    ret |= (1 - dfs(a, i - v));
  }
  return dp[i] = ret;
}

int main() {
  int n, k;
  cin >> n >> k;
  vi a(n);
  rep(i, n) cin >> a[i];
  sort(all(a));
  if (dfs(a, k) == 1)
    cout << "First" << endl;
  else
    cout << "Second" << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<long>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvb = vector<vector<bool>>;
using vvc = vector<vector<char>>;
using vvl = vector<vector<long>>;
using pii = pair<int, int>;
using pil = pair<int, long>;
using pll = pair<long, long>;
#define fix20 cout << fixed << setprecision(20)
#define YES cout << "Yes" << endl
#define NO cout << "No" << endl
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, s, t) for (int i = s; i < t; i++)
#define RNG(i, s, t, u) for (int i = s; i < t; i += u)
#define MOD 1000000007
#define all(vec) vec.begin(), vec.end()

vi dp(100010, -1);

int dfs(vi &a, int i) {
  if (dp[i] != -1)
    return dp[i];
  if (i < a[0])
    return dp[i] = 0;
  int ret = 0;
  for (int v : a) {
    if (i - v < 0)
      continue;
    ret |= (1 - dfs(a, i - v));
  }
  return dp[i] = ret;
}

int main() {
  int n, k;
  cin >> n >> k;
  vi a(n);
  rep(i, n) cin >> a[i];
  sort(all(a));
  if (dfs(a, k) == 1)
    cout << "First" << endl;
  else
    cout << "Second" << endl;
}
Problem p03170 (C++)

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

int const MX = 100009;
int N, K, a[MX], dp[MX][2];
// dp[k][p] = can player p win with k stones if so 1 else 2
int const lose = 2, win = 1;
void read_input() {
  cin >> N >> K;
  for (int i = 1; i <= N; ++i) {
    cin >> a[i];
  }
}

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

  for (int i = 0; i < a[0]; ++i) {
    dp[i][0] = dp[i][1] = 0;
  }

  for (int k = 0; k <= K; ++k) {
    for (int p = 0; p <= 1; ++p) {
      for (int i = 1; i <= N; ++i) {
        int n = a[i];
        if (n > k)
          dp[k][p] = lose; // lose
        if (dp[k - n][1 - p] == lose) {
          dp[k][p] = win;
          break;
        }
      }
      if (dp[k][p] == 0)
        dp[k][p] = lose;
    }
  }
  if (dp[K][0] == win)
    cout << "First" << endl;
  else
    cout << "Second" << endl;
}


Fixed submission:
#include <bits/stdc++.h>
#define endl '\n'
using namespace std;

int const MX = 100009;
int N, K, a[MX], dp[MX][2];
// dp[k][p] = can player p win with k stones if so 1 else 2
int const lose = 2, win = 1;
void read_input() {
  cin >> N >> K;
  for (int i = 1; i <= N; ++i) {
    cin >> a[i];
  }
}

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

  for (int i = 0; i < a[0]; ++i) {
    dp[i][0] = dp[i][1] = 0;
  }

  for (int k = 0; k <= K; ++k) {
    for (int p = 0; p <= 1; ++p) {
      for (int i = 1; i <= N; ++i) {
        int n = a[i];
        if (n > k) {
          continue;
        }
        if (dp[k - n][1 - p] == lose) {
          dp[k][p] = win;
          break;
        }
      }
      if (dp[k][p] == 0)
        dp[k][p] = lose;
    }
  }
  if (dp[K][0] == win)
    cout << "First" << endl;
  else
    cout << "Second" << endl;
}
Problem p03170 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define pb push_back
#define all(x) x.begin(), x.end()
#define ff first
#define ss second
#define mod 1000000007
using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n, k;
  cin >> n >> k;
  vector<int> a(n), dp(k + 1, 0);

  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  for (int i = 0; i <= k; ++i) {
    for (auto j : a) {
      if (j >= i && !dp[i - j])
        dp[i] = 1;
    }
  }
  if (dp[k])
    cout << "First";
  else
    cout << "Second";
  // cerr<< '\n' << "Time elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << "
  // ms\n" ;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define pb push_back
#define all(x) x.begin(), x.end()
#define ff first
#define ss second
#define mod 1000000007
using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n, k;
  cin >> n >> k;
  vector<int> a(n), dp(k + 1, 0);

  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  for (int i = 0; i <= k; ++i) {
    for (auto j : a) {
      if (i >= j && !dp[i - j])
        dp[i] = 1;
    }
  }
  if (dp[k])
    cout << "First";
  else
    cout << "Second";
  // cerr<< '\n' << "Time elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << "
  // ms\n" ;
  return 0;
}
Problem p03170 (C++)

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

#define IOS                                                                    \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(0);                                                                  \
  cout.tie(0);                                                                 \
  cin.exceptions(cin.failbit);
#define int long long int // Comment when Unnecessary
#define ll long long
#define sz(a) (int)((a).size())
#define all(a) a.begin(), a.end()
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define trav(a, x) for (auto &a : x)
#define pii pair<int, int>
#define vi vector<int>
#define F first
#define S second
#define endl "\n" // Remove on Interactive

const int N = 300009;
const int mod = 1000000007;

int32_t main() {
  IOS;
  int n, k;
  cin >> n >> k;
  vi a(n);
  rep(i, 0, n) { cin >> a[i]; }
  vector<bool> dp(n, false);
  rep(i, 1, k + 1) {
    trav(it, a) {
      if ((i - it) >= 0) {
        if (dp[i - it] == false)
          dp[i] = true;
      }
    }
  }
  if (dp[k]) {
    cout << "First\n";
  } else {
    cout << "Second\n";
  }
  return 0;
}

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

#define IOS                                                                    \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(0);                                                                  \
  cout.tie(0);                                                                 \
  cin.exceptions(cin.failbit);
#define int long long int // Comment when Unnecessary
#define ll long long
#define sz(a) (int)((a).size())
#define all(a) a.begin(), a.end()
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define trav(a, x) for (auto &a : x)
#define pii pair<int, int>
#define vi vector<int>
#define F first
#define S second
#define endl "\n" // Remove on Interactive

const int N = 300009;
const int mod = 1000000007;

int32_t main() {
  IOS;
  int n, k;
  cin >> n >> k;
  vi a(n);
  rep(i, 0, n) { cin >> a[i]; }
  vector<bool> dp(k + 1, false);
  rep(i, 1, k + 1) {
    trav(it, a) {
      if ((i - it) >= 0) {
        if (dp[i - it] == false)
          dp[i] = true;
      }
    }
  }
  if (dp[k]) {
    cout << "First\n";
  } else {
    cout << "Second\n";
  }
  return 0;
}
Problem p03170 (C++)

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

#define rep(i, n) for (ll i = 0; i < n; ++i)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
typedef pair<int, int> P;

const int INF = 1001001001;
const long double PI = (acos(-1));
const int mod = 1e9 + 7;
const int vx[4] = {0, 1, 0, -1};
const int vy[4] = {1, 0, -1, 0};

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

  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  rep(i, n) { cin >> a[i]; }
  vector<bool> dp(150, false);
  rep(i, k + 1) {
    rep(j, n) {
      if (i - a[j] >= 0 && dp[i - a[j]] == false)
        dp[i] = true;
    }
  }
  if (dp[k])
    cout << "First" << endl;
  else
    cout << "Second" << endl;
  cout << endl;
  return 0;
}


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

#define rep(i, n) for (ll i = 0; i < n; ++i)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
typedef pair<int, int> P;

const int INF = 1001001001;
const long double PI = (acos(-1));
const int mod = 1e9 + 7;
const int vx[4] = {0, 1, 0, -1};
const int vy[4] = {1, 0, -1, 0};

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

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

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

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  vector<int> v(n);
  vector<bool> vu(k + 1);
  for (int i = 0; i < n; ++i)
    cin >> v[i];
  for (int i = 0; i <= k; ++i) {
    if (!vu[i]) {
      for (int k : v)
        vu[i + k] = true;
    }
  }
  if (vu[k])
    cout << "First";
  else
    cout << "Second";
  return 0;
}

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

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  vector<int> v(n);
  vector<bool> vu(2 * k + 1);
  for (int i = 0; i < n; ++i)
    cin >> v[i];
  for (int i = 0; i <= k; ++i) {
    if (!vu[i]) {
      for (int k : v)
        vu[i + k] = true;
    }
  }
  if (vu[k])
    cout << "First";
  else
    cout << "Second";
  return 0;
}
Problem p03170 (C++)

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

using namespace std;
bool recursive(int N, int K, vector<int> &a, bool turn,
               vector<vector<int>> &table) {
  if (table[K][turn] != -1)
    return table[K][turn];
  if (K < a[0]) {
    table[K][turn] = !turn;
    return !turn;
  } else {
    for (int i = 0; i < N; ++i) {
      bool result = recursive(N, K - a[i], a, !turn, table);
      if (result == turn) {
        table[K][turn] = turn;
        return turn;
      }
    }
    table[K][turn] = !turn;
    return !turn;
  }
}

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> a(N, 0);
  for (int i = 0; i < N; ++i)
    cin >> a[i];
  vector<vector<int>> table(K + 1, vector<int>(2, -1));
  bool result = recursive(N, K, a, false, table);
  if (result)
    cout << "Second";
  else
    cout << "First";
}


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

using namespace std;
bool recursive(int N, int K, vector<int> &a, bool turn,
               vector<vector<int>> &table) {
  if (table[K][turn] != -1)
    return table[K][turn];
  if (K < a[0]) {
    table[K][turn] = !turn;
    return !turn;
  } else {
    for (int i = 0; i < N; ++i) {
      if (K - a[i] < 0)
        break;
      bool result = recursive(N, K - a[i], a, !turn, table);
      if (result == turn) {
        table[K][turn] = turn;
        return turn;
      }
    }
    table[K][turn] = !turn;
    return !turn;
  }
}

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> a(N, 0);
  for (int i = 0; i < N; ++i)
    cin >> a[i];
  vector<vector<int>> table(K + 1, vector<int>(2, -1));
  bool result = recursive(N, K, a, false, table);
  if (result)
    cout << "Second";
  else
    cout << "First";
}
Problem p03170 (C++)

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

bool dp[100011];

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  for (int i = 0; i < k; ++i) {
    for (int j = 0; j < n; ++j) {
      if (!dp[i])
        dp[i + a[j]] = true;
    }
  }
  if (dp[k]) {
    cout << "First" << endl;
  } else {
    cout << "Second" << endl;
  }
  return 0;
}


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

bool dp[200011];

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  for (int i = 0; i < k; ++i) {
    for (int j = 0; j < n; ++j) {
      if (!dp[i])
        dp[i + a[j]] = true;
    }
  }
  if (dp[k]) {
    cout << "First" << endl;
  } else {
    cout << "Second" << endl;
  }
  return 0;
}