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

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define SORT(a) sort(a.begin(), a.end())
#define RSORT(a) sort(a.rbegin(), a.rend())
#define REP(i, n) for (int i = 0; i < n; i++)
#define RREP(i, n) for (int i = n; 0 <= i; i--)
#define FOR(i, start, end) for (int i = start; i < end; i++)
#define FORSTEP(i, start, end, step) for (int i = start; i < end; i += step)
#define RFOR(i, start, end) for (int i = start; end <= i; i--)
#define ALL(a) a.begin(), a.end()
#define MOD(a) a %= 1000000007
typedef long long ll;
const int INF32 = 2147483647;
const ll INF64 = 9223372036854775807;
using namespace std;
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

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

  int R, G, B, N;
  cin >> R >> G >> B >> N;

  int ans = 0;
  REP(i, N / R + 1) {
    REP(j, N / G + 1) {
      if (R * i + G * j > N) {
        continue;
      }
      REP(k, N / B + 1) {
        int sum = R * i + G * j + B * k;
        if (sum == N)
          ans++;
      }
    }
  }

  std::cout << ans << std::endl;

  return 0;
}

Fixed submission:
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define SORT(a) sort(a.begin(), a.end())
#define RSORT(a) sort(a.rbegin(), a.rend())
#define REP(i, n) for (int i = 0; i < n; i++)
#define RREP(i, n) for (int i = n; 0 <= i; i--)
#define FOR(i, start, end) for (int i = start; i < end; i++)
#define FORSTEP(i, start, end, step) for (int i = start; i < end; i += step)
#define RFOR(i, start, end) for (int i = start; end <= i; i--)
#define ALL(a) a.begin(), a.end()
#define MOD(a) a %= 1000000007
typedef long long ll;
const int INF32 = 2147483647;
const ll INF64 = 9223372036854775807;
using namespace std;
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

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

  int R, G, B, N;
  cin >> R >> G >> B >> N;

  int ans = 0;
  REP(i, N / R + 1) {
    REP(j, N / G + 1) {
      int k = N - (R * i + G * j);

      if (k % B == 0 && k >= 0)
        ans++;
    }
  }

  std::cout << ans << std::endl;

  return 0;
}
Problem p03048 (C++)

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

int main() {
  int R, G, B, N;
  std::cin >> R >> G >> B >> N;

  int ans = 0;
  for (size_t i = 0; i < N + 1; i++) {
    for (size_t j = 0; j < N + 1; j++) {
      for (size_t k = 0; k < N + 1; k++) {
        if (R * i + B * j + G * k == N) {
          ans++;
        } else if (R * i + B * j + G * k > N) {
          break;
        }
      }
    }
  }

  std::cout << ans << '\n';
}


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

int main() {
  int R, G, B, N;
  std::cin >> R >> G >> B >> N;

  if (R + G + B == 3) {
    std::cout << (N + 2) * (N + 1) / 2 << '\n';
    return 0;
  }

  int ans = 0;
  for (size_t i = 0; i < N + 1; i++) {
    for (size_t j = 0; j < N + 1; j++) {
      for (size_t k = 0; k < N + 1; k++) {
        if (R * i + B * j + G * k == N) {
          ans++;
        } else if (R * i + B * j + G * k > N) {
          break;
        }
      }
    }
  }

  std::cout << ans << '\n';
}
Problem p03048 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define printArr(harry, tam) range(tam) cout << harry[i] << " \n"[i == tam - 1];
#define range(n) for (int i = 0; i < n; i++)
#define forn(x, n) for (int x = 0; x < n; x++)
#define maxn "100000"
#define mod "1000000007"
#define md(x) ((((x) % mod) + mod) % mod)
#define sc scanf
#define pr printf
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define prt(x) cout << (#x) << " is " << (x) << endl
#define EPS 1e-9
#define INF INT_MAX
#define INFd 1e9

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef vector<int> vi;

// Trace dinamico
template <typename T> void trace(T a) { cout << a << "\n"; }
template <typename T, typename... Args> void trace(T a, Args... args) {
  cout << a << " ";
  trace(args...);
}

// DP debug
int recNum = 0;
void prTabs() { range(recNum) cout << "    "; }
template <typename... Args> void recInit(Args... args) {
  prTabs();
  trace("rec(", args..., ")");
  recNum++;
}
template <typename T> void recEnd(T a) {
  prTabs();
  trace("->", a);
  recNum--;
}
int r, g, b, n;
// vector<int> g[maxn];
int li[9000010];

int main() {
  sc("%d %d %d %d\n", &r, &g, &b, &n);
  for (int i = 0; i < 3001; i++) {
    for (int j = 0; j < 3001; j++) {
      li[i * r + j * g]++;
    }
  }
  int r = 0;
  for (int i = 0; i < 3001; i++) {
    int t = b * i;
    if (t <= n) {
      r += li[n - t];
    }
  }
  pr("%d\n", r);

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define printArr(harry, tam) range(tam) cout << harry[i] << " \n"[i == tam - 1];
#define range(n) for (int i = 0; i < n; i++)
#define forn(x, n) for (int x = 0; x < n; x++)
#define maxn "100000"
#define mod "1000000007"
#define md(x) ((((x) % mod) + mod) % mod)
#define sc scanf
#define pr printf
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define prt(x) cout << (#x) << " is " << (x) << endl
#define EPS 1e-9
#define INF INT_MAX
#define INFd 1e9

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef vector<int> vi;

// Trace dinamico
template <typename T> void trace(T a) { cout << a << "\n"; }
template <typename T, typename... Args> void trace(T a, Args... args) {
  cout << a << " ";
  trace(args...);
}

// DP debug
int recNum = 0;
void prTabs() { range(recNum) cout << "    "; }
template <typename... Args> void recInit(Args... args) {
  prTabs();
  trace("rec(", args..., ")");
  recNum++;
}
template <typename T> void recEnd(T a) {
  prTabs();
  trace("->", a);
  recNum--;
}
int r, g, b, n;
// vector<int> g[maxn];
int li[18000010];

int main() {
  sc("%d %d %d %d\n", &r, &g, &b, &n);
  for (int i = 0; i < 3001; i++) {
    for (int j = 0; j < 3001; j++) {
      li[i * r + j * g]++;
    }
  }
  int r = 0;
  for (int i = 0; i < 3001; i++) {
    int t = b * i;
    if (t <= n) {
      r += li[n - t];
    }
  }
  pr("%d\n", r);

  return 0;
}
Problem p03048 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define mfill(x, y) memset(x, y, sizeof(x))
#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define eprintf(...) 42
#endif
#define y0 y12345
#define y1 y54321
typedef unsigned long ul;
typedef long long ll;
// typedef pair<int, int> mpair;
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
using namespace std;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m, r, g, b;
  cin >> r >> g >> b >> n;
  int cou = 0;
  rep(i, 3001) {
    if (i * r > n)
      break;
    rep(j, 3001) {
      if (i * r + j * g > n)
        break;
      rep(k, 3001) {
        if (i * r + j * g + k * b == n) {
          cou++;
        } else if (i * r + j * g + k * b > n) {
          break;
        }
      }
    }
  }
  cout << cou << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define mfill(x, y) memset(x, y, sizeof(x))
#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define eprintf(...) 42
#endif
#define y0 y12345
#define y1 y54321
typedef unsigned long ul;
typedef long long ll;
// typedef pair<int, int> mpair;
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
using namespace std;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m, r, g, b;
  cin >> r >> g >> b >> n;
  int cou = 0;
  rep(i, 3001) {
    if (i * r > n)
      break;
    rep(j, 3001) {
      if (i * r + j * g > n)
        break;
      for (int k = (n - i * r - j * g) / b; k < 3001; k++) {
        if (i * r + j * g + k * b == n) {
          cou++;
        } else if (i * r + j * g + k * b > n) {
          break;
        }
      }
    }
  }
  cout << cou << endl;
  return 0;
}
Problem p03048 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <string>
#include <vector>

using namespace std;

int main() {

  int R, G, B, N, count = 0;

  cin >> R >> G >> B >> N;

  for (int i = 0; R * i <= N; i++) {
    for (int j = 0; G * j <= N; j++) {
      for (int k = 0; B * k <= N; k++) {
        if (R * i + G * j + B * k == N) {
          count++;
        }
      }
    }
  }

  cout << count;

  return 0;
}


Fixed submission:
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <string>
#include <vector>

using namespace std;

int main() {

  int R, G, B, N, count = 0;

  cin >> R >> G >> B >> N;

  for (int i = 0; R * i <= N; i++) {
    for (int j = 0; G * j <= N; j++) {
      if ((N - R * i - G * j) % B == 0 && N - R * i - G * j >= 0) {
        count++;
      }
    }
  }

  cout << count;

  return 0;
}
Problem p03048 (C++)

Buggy submission (status: Time Limit Exceeded):

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

int main() {
  int R, G, B, N;
  int ans = 0;
  cin >> R >> G >> B >> N;
  for (int i = 0; i <= N / R; i++)
    for (int j = 0; j <= (N - R * i) / G; j++)
      for (int k = 0; k <= (N - R * i - G * j) / B; k++)
        if (R * i + G * j + B * k == N)
          ans++;
  cout << ans << endl;
}


Fixed submission:

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

int main() {
  int R, G, B, N;
  int ans = 0;
  cin >> R >> G >> B >> N;
  for (int i = 0; i <= N / R; i++)
    for (int j = 0; j <= (N - R * i) / G; j++)
      if ((N - (R * i + G * j)) % B == 0)
        ans++;
  cout << ans << endl;
}
Problem p03048 (C++)

Buggy submission (status: Time Limit Exceeded):
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
#define rep(i, a, b) for (int i = (a); i < (b); i++)
using namespace std;
typedef long long int ll;
typedef complex<double> com;
typedef pair<ll, ll> P;
const int mod = 1e9 + 7;
const int MOD = 998244353;
const int inf = 2e9;

int main() {
  int r, g, b, n;
  cin >> r >> g >> b >> n;
  int ans = 0;
  rep(i, 0, n / r + 2) rep(j, 0, n / g + 2) rep(k, 0, n / b + 2) {
    if (i * r + j * g + b * k == n)
      ans++;
  }
  printf("%d", ans);
  return 0;
}


Fixed submission:
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
#define rep(i, a, b) for (int i = (a); i < (b); i++)
using namespace std;
typedef long long int ll;
typedef complex<double> com;
typedef pair<ll, ll> P;
const int mod = 1e9 + 7;
const int MOD = 998244353;
const int inf = 2e9;

int main() {
  int r, g, b, n;
  cin >> r >> g >> b >> n;
  int ans = 0;
  rep(i, 0, n + 1) rep(j, 0, n + 1) {
    int k = n - i * r - j * g;
    if (k >= 0 && k % b == 0)
      ans++;
  }
  printf("%d", ans);
  return 0;
}
Problem p03048 (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()
#define MOD 1000000007
#define PB push_back
#define MP make_pair
using namespace std;
typedef long long ll;
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll div_ceil(ll, ll);

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

int main() {
  int R, G, B, N;
  std::cin >> R >> G >> B >> N;
  int count = 0;
  REP(i, N / R + 1) {
    REP(j, (N - R * i) / G + 1) {
      REP(k, (N - R * i - G * j) / B + 1) {
        if (i * R + j * G + k * B == N) {
          count++;
        }
      }
    }
  }
  std::cout << count << '\n';
}

ll div_ceil(ll a, ll b) {
  ll quotient = a / b;
  ll remainder = a % b;
  if (remainder == 0) {
    return quotient;
  } else {
    return quotient + 1;
  }
}


Fixed submission:
#include <bits/stdc++.h>
#define REP(i, N) for (int i = 0; i < (N); ++i)
#define ALL(x) (x).begin(), (x).end()
#define MOD 1000000007
#define PB push_back
#define MP make_pair
using namespace std;
typedef long long ll;
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll div_ceil(ll, ll);

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

int main() {
  int R, G, B, N;
  std::cin >> R >> G >> B >> N;
  int count = 0;
  REP(r, N / R + 1) {
    REP(g, (N - R * r) / G + 1) {
      if ((N - R * r - G * g) % B == 0)
        count++;
    }
  }
  std::cout << count << '\n';
}

ll div_ceil(ll a, ll b) {
  ll quotient = a / b;
  ll remainder = a % b;
  if (remainder == 0) {
    return quotient;
  } else {
    return quotient + 1;
  }
}
Problem p03048 (C++)

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

int main() {
  int R, G, B, N;
  cin >> R >> G >> B >> N;
  int answer = 0;

  for (int r = 0; r < int(N / R) + 1; r++) {
    for (int g = 0; g < int(N / G) + 1; g++) {
      if (r * R + g * G > N) {
        break;
      }
      for (int b = 0; b < int(N / B) + 1; b++) {
        if (r * R + g * G + b * B > N) {
          break;
        }
        if (r * R + g * G + b * B == N) {
          answer++;
        }
      }
    }
  }
  cout << answer << endl;

  return 0;
}

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

int main() {
  int R, G, B, N;
  cin >> R >> G >> B >> N;
  int answer = 0;

  for (int r = 0; r < int(N / R) + 1; r++) {
    for (int g = 0; g < int(N / G) + 1; g++) {
      if (r * R + g * G > N) {
        break;
      }
      if ((N - r * R - g * G) % B == 0) {
        answer++;
      }
    }
  }
  cout << answer << endl;

  return 0;
}
Problem p03048 (C++)

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

int main() {
  int R, G, B;
  cin >> R >> G >> B;
  int N;
  cin >> N;
  int count = 0;
  for (int i = 0; i * R <= N; i++) {
    for (int j = 0; j * G + i * R <= N; j++) {
      for (int k = 0; k * B + j * G + i * R <= N; k++) {
        if (i * R + j * G + k * B == N) {
          count++;
        }
      }
    }
  }
  cout << count << endl;
}

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

int main() {
  int R, G, B;
  cin >> R >> G >> B;
  int N;
  cin >> N;
  int count = 0;
  for (int i = 0; i * R <= N; i++) {
    for (int j = 0; j * G + i * R <= N; j++) {
      int sum = N - j * G - i * R;
      if (sum % B == 0) {
        count++;
      }
    }
  }
  cout << count << endl;
}
Problem p03048 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <iostream>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

constexpr long long MOD = 1000000007;

int main() {
  int R, G, B, N;
  std::cin >> R >> G >> B >> N;
  int ans = 0;
  int r = N / R;
  for (int i = 0; i <= r; ++i) {
    int n = N - R * i;
    int g = n / G;
    for (int j = 0; j <= g; ++j) {
      int n1 = n - G * j;
      int b = n1 / B;
      for (int k = 0; k <= b; ++k) {
        int n2 = n1 - B * k;
        if (n2 == 0) {
          ++ans;
        }
      }
    }
  }
  std::cout << ans << std::endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <iostream>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

constexpr long long MOD = 1000000007;

int main() {
  int R, G, B, N;
  std::cin >> R >> G >> B >> N;
  int ans = 0;
  int r = N / R;
  for (int i = 0; i <= r; ++i) {
    int n = N - R * i;
    int g = n / G;
    for (int j = 0; j <= g; ++j) {
      int n1 = n - G * j;
      if (n1 % B == 0)
        ++ans;
    }
  }
  std::cout << ans << std::endl;
  return 0;
}
Problem p03048 (C++)

Buggy submission (status: Time Limit Exceeded):
#define _USE_NATH_DEFINES
#include <algorithm>
#include <bitset>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <vector>

using namespace std;
#define REP(i, m, n) for (int i = (int)m; i < (int)n; ++i)
#define rep(i, n) REP(i, 0, n)
using ll = long long;
#define EPS 1e-9
const int INF = 1050000000;
const long long LINF = 1LL << 60;
const ll MOD = 1e9 + 7;
const int MINF = -1050000000;

int main() {

  int r, g, b, n;
  cin >> r >> g >> b >> n;
  int cnt = 0;
  for (int i = 0; i <= n / r; ++i) {
    for (int j = 0; j <= n / g; ++j) {
      for (int k = 0; k <= n / b; ++k) {
        if (i * r + j * g + k * b == n)
          cnt++;
      }
    }
  }
  cout << cnt << endl;
  return 0;
}


Fixed submission:
#define _USE_NATH_DEFINES
#include <algorithm>
#include <bitset>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <vector>

using namespace std;
#define REP(i, m, n) for (int i = (int)m; i < (int)n; ++i)
#define rep(i, n) REP(i, 0, n)
using ll = long long;
#define EPS 1e-9
const int INF = 1050000000;
const long long LINF = 1LL << 60;
const ll MOD = 1e9 + 7;
const int MINF = -1050000000;

int main() {

  int r, g, b, n;
  cin >> r >> g >> b >> n;
  int cnt = 0;
  for (int i = 0; i <= n / r; ++i) {
    for (int j = 0; j <= n / g; ++j) {
      if (((n - i * r - j * g) % b) == 0 && n >= (i * r + j * g))
        cnt++;
    }
  }
  cout << cnt << endl;
  return 0;
}
Problem p03048 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int R, G, B, N;
  cin >> R >> G >> B >> N;
  int count = 0;
  for (int i = 0; i <= N / R; i++) {
    for (int j = 0; G * j <= N - R * i; j++) {
      for (int k = 0; B * k <= N - R * i - G * j; k++) {
        int sum = i * R + j * G + k * B;
        if (sum == N) {
          count++;
        }
      }
    }
  }
  cout << count << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int R, G, B, N;
  cin >> R >> G >> B >> N;
  int count = 0;
  for (int i = 0; i <= N / R; i++) {
    for (int j = 0; G * j <= N - R * i; j++) {
      int k = N - R * i - G * j;
      if (k >= 0 && k % B == 0) {
        count++;
      }
    }
  }
  cout << count << endl;
}
Problem p03048 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iostream>
#include <numeric>
#include <set>
#include <string>
#include <vector>

using namespace std;

int main() {
  int r, g, b, n;
  cin >> r >> g >> b >> n;
  int counter = 0;
  for (size_t i = 0; i <= n / r; i++) {
    for (size_t j = 0; j <= n / g; j++) {
      for (size_t k = 0; k <= n / b; k++) {
        if ((i * r + j * g + k * b) == n)
          counter++;
      }
    }
  }
  cout << counter << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <numeric>
#include <set>
#include <string>
#include <vector>

using namespace std;

int main() {
  int r, g, b, n;
  cin >> r >> g >> b >> n;
  int counter = 0;
  for (size_t i = 0; i <= n / r; i++) {
    for (size_t j = 0; j <= n / g; j++) {
      int z = (n - (i * r + j * g)) / b;
      if (0 <= z && z <= (n / b) && z * b + j * g + i * r == n)
        counter++;
    }
  }
  cout << counter << endl;
  return 0;
}
Problem p03048 (C++)

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

int main() {
  int P, Q, R, N;
  cin >> P >> Q >> R >> N;
  int count = 0;
  int x = N / P + 1;
  for (int i = 0; i < x; i++) {
    for (int j = 0; j < (N - P * i) / Q + 1 && i + j < N + 1; j++) {
      for (int k = 0; k < (N - P * i - Q * j) / R + 1 && i + j + k < N + 1;
           k++) {
        if (P * i + Q * j + R * k == N) {
          count++;
          break;
        }
      }
    }
  }
  cout << count << endl;
}


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

int main() {
  int P, Q, R, N;
  cin >> P >> Q >> R >> N;
  int count = 0;
  int x = N / P + 1;
  for (int i = 0; i < x; i++) {
    for (int j = 0; j < (N - P * i) / Q + 1 && i + j < N + 1; j++) {
      int B = N - P * i - Q * j;
      if (B % R == 0 && B >= 0)
        count++;
    }
  }
  cout << count << endl;
}
Problem p03048 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;

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

  int r, g, b, n;
  cin >> r >> g >> b >> n;

  int res = 0;

  for (int i = 0; i <= (n + r - 1) / r; ++i) {
    for (int j = 0; j <= (n + g - 1) / g; ++j) {
      for (int k = 0; k <= (n + b - 1) / b; ++k) {
        if (r * i + g * j + b * k == n)
          ++res;
      }
    }
  }

  cout << res << endl;

  return 0;
}

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

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

  int r, g, b, n;
  cin >> r >> g >> b >> n;

  int res = 0;

  for (int i = 0; i <= (n + r - 1) / r; ++i) {
    for (int j = 0; j <= (n + g - 1) / g; ++j) {
      if ((n - (r * i + g * j)) >= 0 && ((n - (r * i + g * j)) % b == 0)) {
        ++res;
      }
    }
  }

  cout << res << endl;

  return 0;
}
Problem p03048 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <sstream>
#include <stdio.h>
#include <vector>
#define FORi(N) for (int i = 0; i < N; ++i)
#define FORj(N) for (int j = 0; j < N; ++j)
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
ll gcd(ll m, ll n) {
  if (n == 0)
    return abs(m);
  return (gcd(n, m % n));
}
void putYN(bool b) {
  if (b) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
}

int main() {
  ll R, G, B, N;
  cin >> R >> G >> B >> N;
  ll num = 0;
  for (int r = 0; r <= N; r += R) {
    for (int g = 0; g <= N; g += G) {
      if (r + g > N)
        break;
      for (int b = 0; b <= N; b += B) {
        if (r + g + b > N)
          break;
        if (r + g + b == N)
          num++;
      }
    }
  }
  cout << num << endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <sstream>
#include <stdio.h>
#include <vector>
#define FORi(N) for (int i = 0; i < N; ++i)
#define FORj(N) for (int j = 0; j < N; ++j)
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
ll gcd(ll m, ll n) {
  if (n == 0)
    return abs(m);
  return (gcd(n, m % n));
}
void putYN(bool b) {
  if (b) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
}

int main() {
  ll R, G, B, N;
  cin >> R >> G >> B >> N;
  ll num = 0;
  for (int r = 0; r <= N; r += R) {
    for (int g = 0; g <= N; g += G) {
      if (r + g > N)
        break;
      if ((N - (r + g)) % B == 0)
        num++;
      /*for(int b=0;b<=N;b+=B){
        if(r+g+b>N)break;
        if(r+g+b==N)num++;
      }*/
    }
  }
  cout << num << endl;
  return 0;
}
Problem p03048 (C++)

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

int main() {
  int R, G, B, n;
  cin >> R >> G >> B >> n;
  int ans = 0;
  for (int r = 0; r <= n / R; r++) {
    for (int g = 0; g <= n / G; g++) {
      for (int b = 0; b <= n / B; b++) {
        if (r * R + g * G + b * B == n)
          ans++;
      }
    }
  }
  cout << ans << endl;
}

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

int main() {
  int R, G, B, n;
  cin >> R >> G >> B >> n;
  int ans = 0;
  for (int r = 0; r <= 3000; r++) {
    for (int g = 0; g <= 3000; g++) {
      int b = r * R + g * G;
      if (n >= b && (n - b) % B == 0)
        ans++;
    }
  }
  cout << ans << endl;
}
Problem p03048 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
typedef long long ll;
#define REP(i, a) for (int i = 0; i < (a); i++)
using namespace std;

int main() {
  int r, g, b, n;
  cin >> r >> g >> b >> n;
  int cnt = 0;
  for (int i = 0; i <= n / r; i++) {
    for (int j = 0; i * r + j * g <= n; j++) {
      for (int k = 0; i * r + j * g + k * b <= n; k++) {
        if (i * r + j * g + k * b == n) {
          cnt++;
          break;
        }
      }
    }
  }
  cout << cnt << endl;
}

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

int main() {
  int r, g, b, n;
  cin >> r >> g >> b >> n;
  int cnt = 0;
  for (int i = 0; i <= n / r; i++) {
    for (int j = 0; i * r + j * g <= n; j++) {
      if ((n - i * r - j * g) % b == 0) {
        cnt++;
      }
    }
  }
  cout << cnt << endl;
}
Problem p03048 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
using namespace std;
int main(void) {
  int R, G, B, N, count;
  count = 0;

  cin >> R >> G >> B >> N;

  for (int r = 0; r * R <= N; r = r + 1) {
    for (int g = 0; r * R + g * G <= N; g = g + 1) {
      for (int b = 0; r * R + g * G + b * B <= N; b = b + 1) {
        if (r * R + g * G + b * B == N) {
          count = count + 1;
          // cout << r << g << b <<endl;
        }
      }
    }
  }

  cout << count << endl;
}


Fixed submission:
#include <iostream>
using namespace std;
int main(void) {
  int R, G, B, N, count;
  count = 0;

  cin >> R >> G >> B >> N;

  for (int r = 0; r * R <= N; r = r + 1) {
    for (int g = 0; r * R + g * G <= N; g = g + 1) {

      if (((N - (r * R + g * G)) % B) == 0 &&
          ((N - (r * R + g * G)) % B) >= 0) {
        count = count + 1;
      }
    }
  }

  cout << count << endl;
}
Problem p03048 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;
typedef long long ll;

#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= (ll)(b); i++)
#define FORD(i, a, b) for (ll i = a; i >= (ll)(b); i--)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define D()
#define INF 1000000000000
#define MOD 10000007
#define MAXR 100000
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define INITA(a, i, j, v)                                                      \
  for (ll k = i; k <= j; k++) {                                                \
    a[k] = v;                                                                  \
  }

int main() {
  int r, g, b, n;
  cin >> r >> g >> b >> n;
  int res = 0;
  FOR(i, 0, n / r + 1) {
    FOR(j, 0, n - r * i) {
      FOR(k, 0, n - r * i - g * j) {
        if (r * i + g * j + b * k == n) {
          res++;
        }
      }
    }
  }
  cout << res << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;
typedef long long ll;

#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= (ll)(b); i++)
#define FORD(i, a, b) for (ll i = a; i >= (ll)(b); i--)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define D()
#define INF 1000000000000
#define MOD 10000007
#define MAXR 100000
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define INITA(a, i, j, v)                                                      \
  for (ll k = i; k <= j; k++) {                                                \
    a[k] = v;                                                                  \
  }

int main() {
  int r, g, b, n;
  cin >> r >> g >> b >> n;
  int res = 0;
  FOR(i, 0, n / r) {
    FOR(j, 0, (n - r * i) / g) {
      if ((n - r * i - g * j) % b == 0) {
        res++;
      }
    }
  }
  cout << res << endl;
  return 0;
}
Problem p03048 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(void) {
  int n, i, j, k, r, g, b, ans = 0;
  scanf("%d %d %d %d", &r, &g, &b, &n);

  for (i = 0; i * r <= n; i++) {
    for (j = 0; (i * r) + (j * g) <= n; j++) {
      for (k = 0; (i * r) + (j * g) + (k * b) <= n; k++) {
        if ((i * r) + (j * g) + (k * b) == n)
          ans++;
      }
    }
  }
  printf("%d", ans);
}

Fixed submission:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(void) {
  int n, i, j, k, r, g, b, ans = 0;
  scanf("%d %d %d %d", &r, &g, &b, &n);

  for (i = 0; i * r <= n; i++) {
    for (j = 0; (i * r) + (j * g) <= n; j++) {
      if ((n - (i * r) - (j * g)) % b == 0)
        ans++;
    }
  }
  printf("%d", ans);
}
Problem p03048 (C++)

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

int main() {
  vector<int> a(3);
  int n, count = 0;
  cin >> a[0] >> a[1] >> a[2] >> n;
  sort(a.begin(), a.end());
  for (int x = 0; x * a[0] <= n; x++) {
    for (int y = 0; x * a[0] + y * a[1] <= n; y++) {
      for (int z = 0; x * a[0] + y * a[1] + z * a[2] <= n; z++) {
        if (x * a[0] + y * a[1] + z * a[2] == n)
          count++;
      }
    }
  }
  cout << count << endl;
}

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

int main() {
  vector<int> a(3);
  int n, count = 0;
  cin >> a[0] >> a[1] >> a[2] >> n;
  sort(a.begin(), a.end());
  for (int x = 0; x * a[0] <= n; x++) {
    for (int y = 0; x * a[0] + y * a[1] <= n; y++) {
      if ((n - x * a[0] - y * a[1]) % a[2] == 0)
        count++;
    }
  }
  cout << count << endl;
}
Problem p03048 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)                                                              \
  ;                                                                            \
  for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
int main() {
  int r, g, b, n;
  cin >> r >> g >> b >> n;
  int ans = 0;
  for (int i = 0; i < n / r + 1; i++) {
    for (int j = 0; j < (n - i * r) / g + 1; j++) {
      for (int k = 0; k < (n - i * r - j * g) / b + 1; k++) {
        if (r * i + g * j + b * k == n)
          ans++;
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)                                                              \
  ;                                                                            \
  for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
int main() {
  int r, g, b, n;
  cin >> r >> g >> b >> n;
  int ans = 0;
  for (int i = 0; i < n / r + 1; i++) {
    for (int j = 0; j < (n - i * r) / g + 1; j++) {
      if ((n - r * i - g * j) % b == 0)
        ans++;
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p03048 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
using namespace std;

int main() {
  int r, g, b, n;
  cin >> r >> g >> b >> n;

  int cnt = 0;

  REP(i, n / r + 1) {
    REP(j, n / g + 1) {
      REP(k, n / b + 1) {
        if (n == (r * i + g * j + b * k))
          cnt++;
        else if (n < (r * i + g * j + b * k))
          break;
      }
    }
  }
  cout << cnt << endl;
}


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

int main() {
  int r, g, b, n;
  cin >> r >> g >> b >> n;

  int cnt = 0;

  REP(i, 3001) {
    REP(j, 3001) {
      int num = n - (r * i + g * j);
      if (num % b == 0 && 0 <= num / b && num / b <= 3001)
        cnt++;
    }
  }
  cout << cnt << endl;
}
Problem p03048 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep1(i, n) for (int i = 1; i <= n; i++)
#define rep2(i, n) for (int i = 0; i <= n; i++)
#define repr(i, a, n) for (int i = a; i < n; i++)
#define all(a) a.begin(), a.end()
#define P pair<long long, long long>
#define double long double
#define vector2(a, b, c)                                                       \
  vector<vector<int>> a(b /*縦！w*/, vector<int>(c /*横！w*/))
#define INF 1e10
#define MOD 1e9 + 7
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;
}
using Graph = vector<vector<int>>;
struct edge {
  int from, to, cost;
};
signed main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  int ans = 0;
  rep2(i, 3000) for (int j = 0; i + j <= 3000; j++) {
    for (int k = 0; i + j + k <= 3000; k++) {
      if (i * a + j * b + k * c == d)
        ans++;
    }
  }
  cout << ans << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep1(i, n) for (int i = 1; i <= n; i++)
#define rep2(i, n) for (int i = 0; i <= n; i++)
#define repr(i, a, n) for (int i = a; i < n; i++)
#define all(a) a.begin(), a.end()
#define P pair<long long, long long>
#define double long double
#define vector2(a, b, c)                                                       \
  vector<vector<int>> a(b /*縦！w*/, vector<int>(c /*横！w*/))
#define INF 1e10
#define MOD 1e9 + 7
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;
}
using Graph = vector<vector<int>>;
struct edge {
  int from, to, cost;
};
signed main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  int ans = 0;
  rep2(i, 3000) for (int j = 0; i + j <= 3000; j++) {
    if ((d - i * a - j * b) % c == 0 && d - i * a - j * b >= 0)
      ans++;
  }
  cout << ans << endl;
}
Problem p03048 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define REP(i, a, n) for (int i = a; i < n; i++) //(i, 0, n)でi=0~n-1までn回
#define REPn(i, a, n) for (int i = a; i <= n; i++) //(i, 1, n)でi=1~nまでn回
#define sortv(v) sort(v.begin(), v.end());
#define sortg(v) sort(v.begin(), v.end(), greater<>());
#define rev(v) reverse(v.begin(), v.end()); // 逆順に並べ替え

int main() {
  int R, G, B, n, cnt = 0;
  cin >> R >> G >> B >> n;
  REP(b, 0, 1 + n / B) {
    REP(g, 0, 1 + (n - B * b) / G) {
      REP(r, 0, 1 + (n - B * b - G * g) / R) {
        if (R * r + G * g + B * b == n)
          cnt++;
      }
    }
  }
  cout << cnt << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define REP(i, a, n) for (int i = a; i < n; i++) //(i, 0, n)でi=0~n-1までn回
#define REPn(i, a, n) for (int i = a; i <= n; i++) //(i, 1, n)でi=1~nまでn回
#define sortv(v) sort(v.begin(), v.end());
#define sortg(v) sort(v.begin(), v.end(), greater<>());
#define rev(v) reverse(v.begin(), v.end()); // 逆順に並べ替え

int main() {
  int R, G, B, n, cnt = 0;
  cin >> R >> G >> B >> n;
  REP(r, 0, 1 + n / R) {
    REP(g, 0, 1 + (n - R * r) / G) {
      if ((n - R * r - G * g) % B == 0 && (n - R * r - G * g) >= 0)
        cnt++;
    }
  }
  cout << cnt << endl;
}
Problem p03048 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
int main() {
  auto R = 0;
  auto G = 0;
  auto B = 0;
  auto N = 0;
  int num = 0;
  std::cin >> R >> G >> B >> N;
  for (int i = 0; i <= N / R; i++) {
    if (R * i > N) {
      break;
    }
    for (int j = 0; j <= N / G; j++) {
      if (R * i + G * j > N) {
        break;
      }
      for (int k = 0; k <= N / B; k++) {
        if (R * i + G * j + B * k == N) {
          num++;
        }
      }
    }
  }
  std::cout << num;
}


Fixed submission:
#include <iostream>
int main() {
  auto R = 0;
  auto G = 0;
  auto B = 0;
  auto N = 0;
  int num = 0;
  std::cin >> R >> G >> B >> N;
  for (int i = 0; i <= N / R; i++) {
    if (R * i > N) {
      break;
    }
    for (int j = 0; j <= N / G; j++) {
      if (R * i + G * j > N) {
        break;
      }
      int kari = N - R * i - G * j;
      if (kari >= 0 && kari % B == 0) {
        num++;
      }
    }
  }
  std::cout << num;
}
Problem p03048 (C++)

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

int main() {
  int R, G, B, N;
  cin >> R >> G >> B >> N;
  long long sum = 0;
  for (int r = 0; r * R <= N; r++) {
    for (int g = 0; g * G <= N; g++) {
      for (int b = 0; b * B <= N; b++) {
        if (r * R + g * G + b * B == N)
          sum++;
      }
    }
  }
  cout << sum << endl;
}

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

int main() {
  int R, G, B, N;
  cin >> R >> G >> B >> N;
  long long sum = 0;
  for (int r = 0; r * R <= N; r++) {
    for (int g = 0; g * G <= N; g++) {
      int k = N - r * R - g * G;
      if (k % B == 0 && 0 <= k)
        sum++;
    }
  }
  cout << sum << endl;
}
Problem p03048 (C++)

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

int main() {

  int R, G, B, N;
  int sum, pair;
  cin >> R >> G >> B >> N;

  vector<int> v;
  v.push_back(R);
  v.push_back(G);
  v.push_back(B);

  sort(v.begin(), v.end());

  R = v[2];
  G = v[1];
  B = v[0];

  for (int r = 0; r <= N / R; r++) {
    for (int g = 0; g <= (N - R * r) / G; g++) {
      for (int b = 0; b <= (N - R * r - G * g) / B; b++) {
        sum = R * r + G * g + B * b;
        if (sum == N) {
          pair++;
        }
      }
    }
  }
  cout << pair;
  // cout << R << G << B;

  return 0;
}

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

int main() {

  int R, G, B, N;
  int sum, pair;
  cin >> R >> G >> B >> N;

  vector<int> v;
  v.push_back(R);
  v.push_back(G);
  v.push_back(B);

  sort(v.begin(), v.end());

  R = v[2];
  G = v[1];
  B = v[0];

  for (int r = 0; r <= N / R; r++) {
    for (int g = 0; g <= (N - R * r) / G; g++) {
      if ((N - R * r - G * g) % B == 0)
        pair++;
    }
  }
  cout << pair;
  // cout << R << G << B;

  return 0;
}
Problem p03048 (C++)

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

#define INF 1e9
using namespace std;

int main() {

  int R, G, B, N;
  cin >> R >> G >> B >> N;

  int ans = 0;

  for (int i = 0; i <= N / R; ++i) {
    for (int j = 0; j <= N / G; ++j) {
      for (int k = 0; k <= N / B; ++k) {
        if (R * i + G * j + B * k == N) {
          ++ans;
        }
      }
    }
  }

  cout << ans << endl;
}

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

#define INF 1e9
using namespace std;

int main() {

  int R, G, B, N;
  cin >> R >> G >> B >> N;

  int ans = 0;

  for (int i = 0; i <= N / R; ++i) {
    for (int j = 0; j <= N / G; ++j) {
      if ((N - R * i - G * j) % B == 0 && (N - R * i - G * j) / B >= 0) {
        ++ans;
      }
    }
  }

  cout << ans << endl;
}
Problem p03048 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>
typedef long long ll;
static const int mod = 1e9;
using namespace std;

int main() {
  int r, g, b, n;
  int count = 0;
  cin >> r >> g >> b >> n;
  for (int i = 0; i <= n / r + 1; ++i) {
    for (int j = 0; j <= n / g + 1; ++j) {
      for (int k = 0; k <= n / b + 1; ++k) {
        if (r * i + g * j + b * k == n)
          ++count;
        else if (r * i + g * j + b * k > n)
          break;
      }
    }
  }
  cout << count << endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>
typedef long long ll;
static const int mod = 1e9;
using namespace std;

int main() {
  int r, g, b, n;
  int count = 0;
  cin >> r >> g >> b >> n;
  for (int i = 0; i <= n / r + 1; ++i) {
    for (int j = 0; j <= n / g + 1; ++j) {
      if ((n - r * i - g * j) / b >= 0 && (n - r * i - g * j) % b == 0)
        ++count;
    }
  }
  cout << count << endl;
  return 0;
}
Problem p03048 (C++)

Buggy submission (status: Time Limit Exceeded):
/*
diverta 2019 Programming Contest A
*/
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>

int main() {
  int R, G, B, n, ans = 0;
  std::cin >> R >> G >> B >> n;
  int r, g, b;
  for (r = 0; r <= n; r += R) {
    for (g = 0; r + g <= n; g += G) {
      for (b = 0; r + g + b <= n; b += B) {
        if (r + b + g == n)
          ans++;
      }
    }
  }

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

Fixed submission:
/*
diverta 2019 Programming Contest A
*/
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>

int main() {
  int R, G, B, n, ans = 0;
  std::cin >> R >> G >> B >> n;
  int r, g, b;
  for (r = 0; r <= n; r += R) {
    for (g = 0; r + g <= n; g += G) {
      if ((n - r - g) % B == 0)
        ans++;
    }
  }

  std::cout << ans << std::endl;
  return 0;
}
Problem p03048 (C++)

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

lint gcd(lint x, lint y) {
  if (x == 0) {
    return y;
  } else {
    return gcd(y % x, x);
  }
}

lint lcm(lint x, lint y) { return x / gcd(x, y) * y; }

lint C(lint n, lint k) {
  if (n == k) {
    return 1;
  } else if (n < k) {
    return 0;
  } else if (k == 0) {
    return 1;
  } else if (k == 1) {
    return n;
  } else
    return C(n - 1, k - 1) + C(n - 1, k);
}

int main() {
  int R, G, B, N;
  cin >> R >> G >> B >> N;

  lint ans = 0;
  for (int r = 0; r * R <= N; r++) {
    for (int g = 0; r * R + g * G <= N; g++) {
      for (int b = 0; r * R + g * G + b * B <= N; b++) {
        if (r * R + g * G + b * B == N) {
          ans++;
        }
      }
    }
  }

  cout << ans << endl;
  return 0;
}

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

lint gcd(lint x, lint y) {
  if (x == 0) {
    return y;
  } else {
    return gcd(y % x, x);
  }
}

lint lcm(lint x, lint y) { return x / gcd(x, y) * y; }

lint C(lint n, lint k) {
  if (n == k) {
    return 1;
  } else if (n < k) {
    return 0;
  } else if (k == 0) {
    return 1;
  } else if (k == 1) {
    return n;
  } else
    return C(n - 1, k - 1) + C(n - 1, k);
}

int main() {
  int R, G, B, N;
  cin >> R >> G >> B >> N;

  lint ans = 0;
  for (int r = 0; r * R <= N; r++) {
    for (int g = 0; r * R + g * G <= N; g++) {
      if ((N - r * R - g * G) % B == 0 && N - r * R + g * G >= 0) {
        ans++;
      }
    }
  }

  cout << ans << endl;
  return 0;
}
Problem p03048 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i, a, b) for (ll i = (a), __last_##i = (b); i < __last_##i; i++)
#define RFOR(i, a, b) for (ll i = (b)-1, __last_##i = (a); i >= __last_##i; i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, 0, n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) {
  REP(i, v.size()) {
    if (i)
      os << " ";
    os << v[i];
  }
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<vector<T>> &v) {
  REP(i, v.size()) {
    if (i)
      os << endl;
    os << v[i];
  }
  return os;
}

int main() {
  // Write Your Code Below
  int r, g, b, n;
  cin >> r >> g >> b >> n;
  int ans = 0;
  for (int i = 0; i < n / r + 1; i++) {
    for (int j = 0; j < n / g + 1; j++) {
      for (int k = 0; k < n / b + 1; k++) {
        if (i * r + j * g + k * b == n) {
          ans++;
        }
      }
    }
  }
  cout << ans << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i, a, b) for (ll i = (a), __last_##i = (b); i < __last_##i; i++)
#define RFOR(i, a, b) for (ll i = (b)-1, __last_##i = (a); i >= __last_##i; i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, 0, n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) {
  REP(i, v.size()) {
    if (i)
      os << " ";
    os << v[i];
  }
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<vector<T>> &v) {
  REP(i, v.size()) {
    if (i)
      os << endl;
    os << v[i];
  }
  return os;
}

int main() {
  // Write Your Code Below
  int r, g, b, n;
  cin >> r >> g >> b >> n;
  int ans = 0;
  for (int i = 0; i < n / r + 1; i++) {
    for (int j = 0; j < n / g + 1; j++) {
      int rest = n - r * i - g * j;
      if (rest >= 0 && rest % b == 0) {
        ans++;
      }
    }
  }
  cout << ans << endl;
}
Problem p03048 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
using namespace std;

int main() {
  int R, G, B, N;
  int count = 0;

  cin >> R >> G >> B >> N;

  for (int i = 0; i <= N / R; i++) {
    for (int j = 0; j <= N / G; j++) {
      for (int k = 0; k <= N / B; k++) {
        if (R * i + G * j + B * k == N)
          count++;
      }
    }
  }
  cout << count << endl;

  return 0;
}

Fixed submission:
#include <iostream>
using namespace std;

int main() {
  int R, G, B, N;
  int count = 0;

  cin >> R >> G >> B >> N;

  for (int i = 0; i <= N / R; i++) {
    for (int j = 0; j <= (N - R * i) / G; j++) {
      if ((N - R * i - G * j) % B == 0)
        count++;
    }
  }
  cout << count << endl;

  return 0;
}