alexjercan/bugnet huggingface dataset:
Problem p02640 (C++) — buggy submission, verdict: Runtime Error

// #include<bits/stdc++.h>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;
typedef double db;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pair<int, int>> vii;
const double pi = 2 * acos(0);

#define pf printf
#define sf scanf
#define pb(a) push_back(a)
#define mp make_pair
#define fi first
#define se second
#define for0(i, n) for (int i = 0; i < n; i++)
#define for1(i, n) for (int i = 1; i <= n; i++)
#define forab(i, a, b) for (int i = a; i <= b; i++)
#define lcm(a, b) ((a) * ((b) / gcd(a, b)))
#define sq(a) (a) * (a)
#define nw "\\n"
#define abs(x) fabs(x)
#define pcase(z, x) cout << "Case " << z << ": " << x << "\\n"
int main() {
  int i, j, x, y, t, ck = 0;
  cin >> x >> y;
  for (i = x, j = 0; i >= 0; i--, j++) {
    t = 2 * i + 4 * j;
    // cout<<t<<nw;
    if (t == y) {
      ck = 1;
      break;
    }
  }
  pf(ck ? "Yes" : "No");
  return 0;
}

Error: WA

Fixed submission:

// #include<bits/stdc++.h>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;
typedef double db;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pair<int, int>> vii;
const double pi = 2 * acos(0);

#define pf printf
#define sf scanf
#define pb(a) push_back(a)
#define mp make_pair
#define fi first
#define se second
#define for0(i, n) for (int i = 0; i < n; i++)
#define for1(i, n) for (int i = 1; i <= n; i++)
#define forab(i, a, b) for (int i = a; i <= b; i++)
#define lcm(a, b) ((a) * ((b) / gcd(a, b)))
#define sq(a) (a) * (a)
#define nw "\\n"
#define abs(x) fabs(x)
#define pcase(z, x) cout << "Case " << z << ": " << x << "\\n"
int main() {
  int x, y, ck = 0;
  cin >> x >> y;
  if (x == 1 && (y == 2 || y == 4)) {
    pf("Yes");
    return 0;
  }
  while (1) {
    if (x == 0 || y <= 0)
      break;
    y -= 4;
    x--;
    if (y / x == 2) {
      ck = 1;
      break;
    }
  }
  pf(ck ? "Yes" : "No");

  return 0;
}
Problem p02640 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const long double pi = 3.14159265358979323846;
#define x first
#define y second

int main() {
  cin.tie(0);
  cin.sync_with_stdio(0);
  ll t = 1;
  // cin>>t;
  while (t--) {
    ll x, y;
    cin >> x >> y;
    if (y % x == 0 && y / x == 4)
      cout << "Yes";
    else if (y % x == 0 && y / x == 2)
      cout << "Yes";
    else if (y > x * 4 || y < x * 2)
      cout << "No";
    else {
      while (x && y) {
        y -= 4;
        x--;
        if (!x)
          break;
        if (!y)
          break;
        if (y % x == 0 && y / x == 2) {
          cout << "Yes";
          return 0;
        }
      }
      cout << "No";
    }
  }
  return 0;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const long double pi = 3.14159265358979323846;
#define x first
#define y second

int main() {
  cin.tie(0);
  cin.sync_with_stdio(0);
  ll t = 1;
  // cin>>t;
  while (t--) {
    ll x, y;
    cin >> x >> y;
    if (y % x == 0 && y / x == 4)
      cout << "Yes";
    else if (y % x == 0 && y / x == 2)
      cout << "Yes";
    else if (y > x * 4 || y < x * 2)
      cout << "No";
    else {
      while (x && y) {
        y -= 4;
        x--;
        if (y % x == 0 && y / x == 2) {
          cout << "Yes";
          return 0;
        }
      }
      cout << "No";
    }
  }
  return 0;
}
Problem p02640 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  bool flag = false;
  for (int l = 0; l <= n; l++) {
    if (((l * 2) + ((n - l) * 4)) == k) {
      flag = true;
      break;
    }
  }
  flag ? cout << "Yes\\n" : cout << "No\\n";
  // main();
  return 0;
}


Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  bool flag = false;
  for (int l = 0; l <= n; l++) {
    if (((l * 2) + ((n - l) * 4)) == k) {
      flag = true;
      break;
    }
  }
  flag ? cout << "Yes\\n" : cout << "No\\n";
  main();
  return 0;
}
Problem p02640 (C++) — buggy submission, verdict: Time Limit Exceeded

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

map<pair<int, int>, bool> memo;
bool solve(int x, int y) {
  auto p = make_pair(x, y);
  if (memo.count(p))
    return memo[p];
  if (x == 0)
    return y == 0;
  if (x < 0)
    return false;
  memo[p] = solve(x - 1, y - 2) or solve(x - 1, y - 4);
  return memo[p];
}

int main() {
  int x, y;

  cin >> x >> y;

  bool ok = solve(x, y);
  if (ok)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}


Error: TLE

Fixed submission:

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

bool solve(int x, int y) {
  if (x == 0)
    return y == 0;
  if (x < 0)
    return false;
  return solve(x - 1, y - 2) or solve(x - 1, y - 4);
}

int main() {
  int x, y;

  cin >> x >> y;

  bool ok = solve(x, y);
  if (ok)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}
Problem p02640 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;

const char nl = '\\n';

void solve() {
  int animals, legs;
  cin >> animals >> legs;
  bool ans = false;
  if (legs % 2 == 0) {
    int twosneeded = legs / 2;
    if (twosneeded == animals) {
      ans = true;
    } else if (twosneeded > animals) {
      ans = twosneeded - animals <= animals;
    }
  }
  cout << (ans ? "Yes" : "No") << nl;
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(nullptr);
  solve();
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;

const char nl = '\\n';

bool bt(int animals, int legs, unordered_map<int, bool> dp) {
  if (dp.find(legs) == dp.end()) {
    if (legs == 0 && animals == 0) {
      dp[legs] = true;
    } else if (legs == 0 || animals == 0) {
      dp[legs] = false;
    } else
      dp[legs] = bt(animals - 1, legs - 4, dp) || bt(animals - 1, legs - 2, dp);
  }
  return dp[legs];
}

void solve() {
  unordered_map<int, bool> m;
  int animals, legs;
  cin >> animals >> legs;
  cout << (bt(animals, legs, m) ? "Yes" : "No") << nl;
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(nullptr);
  solve();
  return 0;
}
Problem p02640 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;
int main() {
  int X, Y, a = 0;
  cin >> X >> Y;
  for (int i = 0; i <= X; i++) {
    if (2 * (X - i) + 4 * i == Y)
      a++;
    if (a != 0)
      break;
  }
  if (a == 0)
    cout << "No" << endl;
  else
    cout << "Yes" << endl;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  int X, Y, a = 0;
  for (int i = 0; i <= X; i++) {
    if (2 * (X - i) + 4 * i == Y)
      a++;
  }
  if (a == 0)
    cout << "No" << endl;
  else
    cout << "Yes" << endl;
}
Problem p02640 (C++) — buggy submission, verdict: Time Limit Exceeded

#pragma GCC optimize("O3")
#include "bits/stdc++.h"
using namespace std;
#define I_AM_SPEED                                                             \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define printclock                                                             \\
  cerr << "Time : " << (double)clock() / (double)CLOCKS_PER_SEC << " sec\\n";
#define meme(a, v) memset((a), (v), sizeof(a))
#define mp(a, b) make_pair(a, b)
#define eb(a) emplace_back(a)
#define anal '\\n'
#define mod 1000000007
// const double PI = acos(-1.0);
typedef long long ll;

//_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-

//_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-

int main() {
  I_AM_SPEED;

  //_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-

  int x, y;
  cin >> x >> y;

  int minl = 2 * x, maxl = 4 * x;
  if (y < minl || maxl < y || (y & 1)) {
    cout << "No";
    return 0;
  }

  if ((y / 2 - x) >= 0) {
    cout << "Yes";
  } else {
    cout << "No";
  }

  //_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-

  return 0;
}


Error: TLE

Fixed submission:

#pragma GCC optimize("O3")
#include "bits/stdc++.h"
using namespace std;
#define I_AM_SPEED                                                             \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define printclock                                                             \\
  cerr << "Time : " << (double)clock() / (double)CLOCKS_PER_SEC << " sec\\n";
#define meme(a, v) memset((a), (v), sizeof(a))
#define mp(a, b) make_pair(a, b)
#define eb(a) emplace_back(a)
#define anal '\\n'
#define mod 1000000007
// const double PI = acos(-1.0);
typedef long long ll;

//_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-

//_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-

int main() {
  I_AM_SPEED;

  //_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-

  int x, y;
  cin >> x >> y;

  int cra = 0, tur = 0;
  int minl = 2 * x, maxl = 4 * x;
  if (minl > y || maxl < y) {
    cout << "No";
    return 0;
  }
  if (minl == y) {
    cout << " Yes";
    return 0;
  }
  y -= minl;
  while (y % 4 != 0) {
    y += 2;
    minl -= 2;
  }
  if (y % 4 == 0) {
    cout << "Yes";
  } else {
    cout << "No";
  }

  //_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-

  return 0;
}
Problem p02640 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define endl '\\n'
#define db double
#define ld long double
#define ll long long
#define ull unsigned long long
#define sqr(x) (x) * (x)
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) ((a / gcd(a, b)) * b)
#define pf(x) push_front(x)
#define pb(x) push_back(x)
#define eb(x) emplace_back(x)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)x.size()
#define debug(x) cerr << #x << " = " << (x) << endl
#define unsyncIO                                                               \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0)

const ld PI = acos((ld)-1);
const int MOD = 1e9 + 7;
const ll INF = 1e18;

using namespace std;

int main() {
  // freopen("/home/taalpatar_shepai/Documents/my_codes/out.txt", "w", stdout);
  int x, y;
  cin >> x >> y;
  if (y <= (x * 4) && y >= (x * 2) && y % 2 == 0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define endl '\\n'
#define db double
#define ld long double
#define ll long long
#define ull unsigned long long
#define sqr(x) (x) * (x)
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) ((a / gcd(a, b)) * b)
#define pf(x) push_front(x)
#define pb(x) push_back(x)
#define eb(x) emplace_back(x)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)x.size()
#define debug(x) cerr << #x << " = " << (x) << endl
#define unsyncIO                                                               \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0)

const ld PI = acos((ld)-1);
const int MOD = 1e9 + 7;
const ll INF = 1e18;

using namespace std;

int main() {
  // freopen("/home/taalpatar_shepai/Documents/my_codes/out.txt", "w", stdout);
  int x, y;
  cin >> x >> y;
  if (x == 1 && y == 2 || x == 1 && y == 4) {
    cout << "Yes" << endl;
    return 0;
  }
  if (y > (x * 4)) {
    cout << "No" << endl;
  } else {
    y -= 2;
    x--;
    if (y % x == 0) {
      cout << "Yes" << endl;
    } else
      cout << "No" << endl;
  }

  return 0;
}
Problem p02640 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int x = 0, y = 0;
  cin >> x >> y;

  for (int i = 0; i <= x; i++) {
    if (2 * i + 4 * (x - i) == y) {
      cout << "Yes" << endl;
      return 0;
    }
  }

  cout << "No" << endl;
}

Error: TLE

Fixed submission:

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

int x, y;
bool found = false;

void dfs(int depth, int total) {
  if (depth == x) {
    if (total == y)
      found = true;
    return;
  }

  dfs(depth + 1, total + 2);
  dfs(depth + 1, total + 4);
}

int main() {
  cin >> x >> y;

  dfs(0, 0);

  if (found)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}
Problem p02640 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define U(i, a, b) for (int i = (a); i <= (b); ++i)
#define D(i, a, b) for (int i = (a); i >= (b); --i)
using namespace std;
int gi() {
  int f = 1, x = 0;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-')
      f = -f;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return f * x;
}
typedef long long LL;
typedef pair<int, int> pi;

int main() {
  int x, y;
  cin >> x >> y;
  for (int many = 0; many <= x; ++many) {
    int left = (y - many * 2);
    if (left >= 0 && (x - many) * 4 == left)
      return puts("Yes"), 0;
  }
  puts("No");
  return 0;
}

Error: 4

Fixed submission:

#include <bits/stdc++.h>
#define U(i, a, b) for (int i = (a); i <= (b); ++i)
#define D(i, a, b) for (int i = (a); i >= (b); --i)
using namespace std;
int gi() {
  int f = 1, x = 0;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-')
      f = -f;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return f * x;
}
typedef long long LL;
typedef pair<int, int> pi;

int main() {
  int x, y;
  cin >> x >> y;
  for (int many = 0; many <= x; ++many) {
    int left = (y - many * 2);
    if (left >= 0 && (x - many) * 4 == left)
      return puts("Yes");
  }
  puts("No");
  return 0;
}
Problem p02640 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <set>
#include <string.h>
#include <unordered_map>
#include <vector>
using namespace std;

#define int long long

void fastio() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
}

int32_t main() {
  fastio();
  int a, b;
  cin >> a >> b;
  int n = a + 1;
  int arr[n];
  int k = 2 * a;
  for (int i = 0; i < n; i++) {
    arr[i] = k;
    k = k + 2;
  }
  if (binary_search(arr, arr + n, b))
    cout << "Yes";
  else
    cout << "No";
  return 0;
}

Error: -11

Fixed submission:

#include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <set>
#include <string.h>
#include <unordered_map>
#include <vector>
using namespace std;

#define int long long

void fastio() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
}

int32_t main() {
  fastio();
  int a, b;
  cin >> a >> b;
  int n = 2 * a;
  int arr[n];
  for (int i = a; i <= 4 * a; ++i) {
    arr[i] = 2 * i;
  }
  if (binary_search(arr, arr + n, b))
    cout << "Yes";
  else
    cout << "No";
  return 0;
}
Problem p02640 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define MOD1 1000000007
#define MOD2 1000000009
#define ll long long int
#define li long int
#define fi first
#define se second
#define ffl fflush(stdout);
#define whT                                                                    \\
  int t;                                                                       \\
  cin >> t;                                                                    \\
  while (t--)
int main() {
  int x, y;
  cin >> x >> y;
  if (y % 2 != 0) {
    cout << "No";
  } else if (x * 4 == y || x * 2 == y) {
    cout << "Yes";
  } else {
    int b = ((y - (2 * x)) / 2);
    if (b >= 0 && b <= x)
      cout << "Yes";
    else
      cout << "No";
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define MOD1 1000000007
#define MOD2 1000000009
#define ll long long int
#define li long int
#define fi first
#define se second
#define ffl fflush(stdout);
#define whT                                                                    \\
  int t;                                                                       \\
  cin >> t;                                                                    \\
  while (t--)
bool ff(int a, int b, int s, int w) {
  if (w == 0)
    return true;
  if (w < 0 || s <= 0)
    return false;
  bool incl = ff(a, b, s - 1, w - a);
  bool excl = ff(a, b, s - 1, w - b);
  return incl || excl;
}
int main() {
  int x, y;
  cin >> x >> y;
  if (y % 2 != 0) {
    cout << "No";
  } else if (x * 4 == y || x * 2 == y) {
    cout << "Yes";
  } else {
    if (ff(2, 4, x, y))
      cout << "Yes";
    else
      cout << "No";
  }
  return 0;
}
Problem p02640 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define rep(i, n) for (long long i = 0; i < (int)(n); i++)
#define put(i) cout << fixed << i << endl
using namespace std;
using ll = long long;

ll x, y;

int main() {
  cin >> x >> y;

  for (long long i = 0; i <= x; i++) {
    if (2 * i + 4 * (x - i) == y) {
      put("Yes");
      return 0;
    }
  }
  put("No");
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (long long i = 0; i < (int)(n); i++)
#define put(i) cout << fixed << i << endl
using namespace std;
using ll = long long;

ll x, y;

ll f(ll pon = 0, ll deep = 0) {
  if (deep > x)
    return 0;
  if (pon == y)
    return 1;
  if (pon > y)
    return 0;
  return f(pon + 2, deep + 1) + f(pon + 4, deep + 1);
}

int main() {
  cin >> x >> y;

  put((f() ? "Yes" : "No"));
}
Problem p02640 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#include <iostream>
int main(void) {
  int x, y, z;
  std::cin >> x >> y;
  std::string ans = "No";

  for (int i = 0; i < x + 1; i++) {
    z = x - i;
    if (i * 2 + 4 * z == y) {
      ans = "Yes";
    }
  }

  std::cout << ans;
  return 0;
}

Error: -8

Fixed submission:

#include <bits/stdc++.h>
#include <iostream>

int main() {
  int x, y;
  std::cin >> x >> y;
  for (int i = 0; i < x; i++) {
    if ((x / i) % y == 0) {
      std::cout << "Yes";
      exit(0);
    } else {
    }
  }
  std::cout << "No";
  return 0;
}
Problem p02640 (C++) — buggy submission, verdict: Runtime Error

#include <cmath>
#include <iostream>
using namespace std;

void find1(int X, int Y) {
  if (X < 0 || Y < 0)
    cout << "No";
  else {
    double a, b;
    b = ((4 * X) - Y);
    a = b / 2;
    // cout<<a;
    if (a < 0 || X - a < 0 || !(abs(a - (int)a) == 0))
      cout << "No";
    else
      cout << "Yes";
  }
}
int main() {
  int X, Y;
  cin >> X >> Y;
  find1(X, Y);
  return 0;
}


Error: WA

Fixed submission:

#include <iostream>

using namespace std;

bool find1(int X, int Y) {
  int a = 0;
  a = (int)((4 * X) - Y) / 2;
  if (a < 0 || X - a < 0)
    cout << "No";
  else
    cout << "Yes";
}
int main() {
  int X, Y;
  cin >> X >> Y;
  bool b = find1(X, Y);
  return 0;
}
Problem p02640 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>

#define ll long long
#define US unsigned
#define UINT unsigned int

using namespace std;

int main() {
  int X, Y;
  cin >> X >> Y;
  int two, four, ans;
  int c;
  for (c = 0; c <= X; c++) {
    two = c;
    four = X - c;
    ans = two * 2 + four * 4;
    if (ans == Y) {
      cout << "Yes" << endl;
      return 0;
    }
  }

  cout << "No" << endl;

  return 0;
}

Error: 1

Fixed submission:

#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <iostream>
#include <random>
#include <string>
#include <strstream>
#include <vector>

// #include "D:\\Code\\C++\\Headers\\zle_CSV.h"

#define ll long long
#define US unsigned
#define UINT unsigned int
#define e18 1000000000000000000
#define e9 1000000000
using namespace std;

int main() {
  int X, Y;
  cin >> X >> Y;
  int two, four, ans;
  for (int c = 0; c < X; c++) {
    two = c;
    four = X - c;
    ans = two * 2 + four * 4;
    if (ans == Y) {
      cout << "Yes";
      return 1;
    }
  }

  cout << "No";
  return 0;
}
Problem p02640 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int X, Y;
  cin >> X >> Y;
  bool a = false;
  for (int i = 0; i <= X; i++) {
    if (((2 * i) + (4 * (X - i))) == Y) {
      a = true;
      break;
    }
  }
  if (a) {
    cout << "Yes"
         << "\\n";
  } else {
    cout << "No"
         << "\\n";
  }
  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, l;
  cin >> n >> l;
  if (n > l || l < 2) {
    cout << "No"
         << "\\n";
  } else {
    while (n != 0) {
      if (l >= 4) {
        l -= 4;
        n--;
      } else if (l < 4 && l >= 2) {
        l -= 2;
        n--;
      }
    }
    if (l != 0) {
      cout << "No"
           << "\\n";
    } else {
      cout << "Yes"
           << "\\n";
    }
  }

  return 0;
}
Problem p02640 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

bool fun2(int X, int Y) {
  int i, j;
  for (i = 0; i <= X; i++) {
    j = X - i;
    if (i * 2 + j * 4 == Y)
      return true;
  }
  return false;
}

void Sol2() {
  int X, Y;
  cin >> X >> Y;
  vector<int> dp(101, 1);

  // bool ret = fun(X, Y,dp);
  bool ret = fun2(X, Y);

  if (ret)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

int main() {
#define endl '\\n'
  std::ios::sync_with_stdio(false);
  std::cin.tie(NULL);
  std::cout.tie(0);
  // Sol1();
  Sol2();
  // Sol3();
  // Sol4();
  // Sol5();
  // Sol6();
  // cin.get();
}


Error: 0

Fixed submission:


#include <algorithm>
#include <iostream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;

bool fun(int X, int Y, vector<int> &dp) {
  if (Y == 0)
    return true;
  if (X == 0)
    return false;

  if (!dp[Y])
    return false;
  if (fun(X - 1, Y - 4, dp)) {
    return true;
  }
  if (fun(X - 1, Y - 2, dp)) {
    return true;
  }
  dp[Y] = false;
  return false;
}

void Sol2() {
  int X, Y;
  cin >> X >> Y;
  vector<int> dp(101, 1);

  bool ret = fun(X, Y, dp);
  if (ret)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

int main() {
  // Sol1();
  Sol2();
  // Sol3();
  // Sol4();
  // Sol5();
  // Sol6();
  // cin.get();
}