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

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>     // minmax, sort, swap
#include <climits>       // INT_MIN, LLONG_MIN
#include <cmath>         // long, trig, pow
#include <cstdio>        // printf, scanf
#include <iostream>      // cin, cout, cerr, clog
#include <map>           // key-value pairs sorted by keys
#include <numeric>       // iota, gcd, lcm
#include <queue>         // queue
#include <stack>         // stack
#include <string>        // string
#include <unordered_map> // hashed by keys
#include <vector>        // vectors
#define _for(i, n) for (int i = 0; i <= n; i++)

typedef long long ll;           // at least int64 > 9*10^18
typedef unsigned long long ull; // at least uint64

using namespace std;

int main() {
  int R, G, B, n;
  cin >> R >> G >> B >> n;
  int rmax = n / R;
  int gmax = n / G;
  int bmax = n / B;
  int count = 0;
  _for(r, rmax) _for(g, gmax - r * R / G)
      _for(b, bmax - (r * R + g * G) / B) if (r * R + g * G + b * B == n)
          count++;
  cout << count << endl;
  return 0;
}

Fixed submission:
#include <algorithm>     // minmax, sort, swap
#include <climits>       // INT_MIN, LLONG_MIN
#include <cmath>         // long, trig, pow
#include <cstdio>        // printf, scanf
#include <iostream>      // cin, cout, cerr, clog
#include <map>           // key-value pairs sorted by keys
#include <numeric>       // iota, gcd, lcm
#include <queue>         // queue
#include <stack>         // stack
#include <string>        // string
#include <unordered_map> // hashed by keys
#include <vector>        // vectors
#define _for(i, n) for (int i = 0; i <= n; i++)

typedef long long ll;           // at least int64 > 9*10^18
typedef unsigned long long ull; // at least uint64

using namespace std;

int main() {
  int R, G, B, n;
  cin >> R >> G >> B >> n;
  int rmax = n / R;
  int gmax = n / G;
  int bmax = n / B;
  int count = 0;
  _for(r, rmax) _for(g, (n - r * R) / G) if ((n - r * R - g * G) % B == 0)
      count++;
  cout << count << endl;
  return 0;
}
Problem p03048 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iostream>
#include <math.h>
#include <set>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;

int main() {
  int r, g, b, n;
  cin >> r >> g >> b >> n;
  int ans = 0;
  int i, j, k;
  for (i = 0; i * r <= n; i++) {
    for (j = 0; j * g <= (n - r * i); j++) {
      for (k = 0; k * b <= (n - r * i - j * g); k++) {
        if (r * i + j * g + k * b == n) {
          ans++;
        }
      }
    }
  }

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

Fixed submission:
#include <algorithm>
#include <iostream>
#include <math.h>
#include <set>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;

int main() {
  int r, g, b, n;
  cin >> r >> g >> b >> n;
  int ans = 0;
  int i, j, k;
  for (i = 0; i * r <= n; i++) {
    for (j = 0; j * g <= (n - r * i); j++) {
      if ((n - r * i - j * g) % b == 0) {
        ans++;
      }
    }
  }

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

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

int main(void) {
  int s[3], n, sum = 0;
  cin >> s[0] >> s[1] >> s[2] >> n;
  for (int i = 0; i <= n; i++) {
    for (int j = 0; j <= n; j++) {
      for (int k = 0; k <= n; k++) {
        if (s[0] * i + s[1] * j + s[2] * k == n)
          sum++;
      }
    }
  }
  cout << sum << endl;
  return 0;
}


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

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

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

int main() {
  ll R, G, B, n;
  cin >> R >> G >> B >> n;
  ll r = n / R, g = n / G, b = n / B, sum = 0;
  rep(i, r + 1) {
    rep(j, g + 1) {
      rep(k, b + 1) {
        if (i * R + j * G + k * B == n) {
          sum++;
        }
      }
    }
  }
  cout << sum << endl;
}

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

int main() {
  ll R, G, B, n;
  cin >> R >> G >> B >> n;
  ll r = n / R, g = n / G, b = n / B, sum = 0;
  rep(i, r + 1) {
    rep(j, g + 1) {
      ll a = n - (i * R + j * G);
      if (i * R + j * G + a == n && a >= 0 && a % B == 0) {
        sum++;
      }
    }
  }
  cout << sum << endl;
}
Problem p03048 (C++)

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

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

  int count = 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) {
          count++;
        }
      }
    }
  }
  cout << count << endl;
}

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

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

  int count = 0;
  for (int r = 0; r <= N / R; r++) {
    for (int g = 0; g <= N / G; g++) {
      int tmp = N - R * r - G * g;
      if (tmp % B == 0 && tmp >= 0 && tmp / B >= 0) {
        count++;
      }
    }
  }
  cout << count << endl;
}
Problem p03048 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define INF 1e9
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(a) (a).begin(), (a).end()
using ll = long long;
using namespace std;
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 (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &s, const pair<T1, T2> &p) {
  return s << "(" << p.first << ", " << p.second << ")";
}
template <typename T> ostream &operator<<(ostream &s, const vector<T> &v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i];
    if (i < len - 1)
      s << "\t";
  }
  return s;
}

template <typename T>
ostream &operator<<(ostream &s, const vector<vector<T>> &vv) {
  int len = vv.size();
  for (int i = 0; i < len; ++i) {
    s << vv[i] << endl;
  }
  return s;
}

int R, G, B, N;
signed main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  cin >> R >> G >> B >> N;
  int ret = 0;
  for (int a = 0; a < (N / R) + 1; a++) {
    for (int b = 0; b < (N / G) + 1; b++) {
      for (int c = 0; c < (N / B) + 1; c++) {
        if (a * R + b * G + c * B == N) {
          ret++;
        }
      }
    }
  }
  cout << ret << endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define INF 1e9
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(a) (a).begin(), (a).end()
using ll = long long;
using namespace std;
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 (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &s, const pair<T1, T2> &p) {
  return s << "(" << p.first << ", " << p.second << ")";
}
template <typename T> ostream &operator<<(ostream &s, const vector<T> &v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i];
    if (i < len - 1)
      s << "\t";
  }
  return s;
}

template <typename T>
ostream &operator<<(ostream &s, const vector<vector<T>> &vv) {
  int len = vv.size();
  for (int i = 0; i < len; ++i) {
    s << vv[i] << endl;
  }
  return s;
}

int R, G, B, N;
signed main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  cin >> R >> G >> B >> N;
  int ret = 0;
  for (int a = 0; a < (N / R) + 1; a++) {
    for (int b = 0; b < (N / G) + 1; b++) {
      if ((N - (a * R + b * G)) % B == 0 && ((N - (a * R + b * G)) >= 0)) {
        ret++;
      }
    }
  }
  cout << ret << endl;
  return 0;
}
Problem p03048 (C++)

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

#define MOD 1e9 + 7;
#define INF 1e17 + 9;
#define PI acos(-1);

using namespace std;

int main() {

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

  long long cnt = 0;
  for (int r = 0; r <= 3000 / R; r++) {
    for (int g = 0; g <= 3000 / G; g++) {
      for (int b = 0; b <= 3000 / B; b++) {
        if (r * R + g * G + b * B == N) {
          cnt++;
          break;
        }
      }
    }
  }
  cout << cnt << endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <vector>

#define MOD 1e9 + 7;
#define INF 1e17 + 9;
#define PI acos(-1);

using namespace std;

int main() {

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

  long long cnt = 0;
  for (int r = 0; r <= 3000 / R; r++) {
    for (int g = 0; g <= 3000 / G; g++) {
      long long x = r * R + g * G;
      if (N >= x && (N - x) % B == 0) {
        cnt++;
        // break;
      }
    }
  }
  cout << cnt << endl;
  return 0;
}
Problem p03048 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <array>
#include <cmath>
#include <complex>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

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 dx[4] = {-1, 0, 1, 0};
int dy[4] = {0, 1, 0, -1};
const int INF = 100000000;
const long long LINF = 1LL << 60;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-6;
using pii = std::pair<int, int>;
using pLL = std::pair<long long, long long>;
using ll = long long;
#define SORT(v) std::sort(v.begin(), v.end())
#define rSORT(v) std::sort(v.begin(), v.end(), std::greater<int>())

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  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 - r * i) / g; ++j) {
      for (int k = 0; k <= (n - r * i - g * j) / b; ++k) {
        if (r * i + g * j + b * k == n)
          cnt++;
      }
    }
  }
  cout << cnt << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <array>
#include <cmath>
#include <complex>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

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 dx[4] = {-1, 0, 1, 0};
int dy[4] = {0, 1, 0, -1};
const int INF = 100000000;
const long long LINF = 1LL << 60;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-6;
using pii = std::pair<int, int>;
using pLL = std::pair<long long, long long>;
using ll = long long;
#define SORT(v) std::sort(v.begin(), v.end())
#define rSORT(v) std::sort(v.begin(), v.end(), std::greater<int>())

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  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 - r * i) / g; ++j) {
      if ((n - r * i - g * j) % b == 0)
        cnt++;
    }
  }
  cout << cnt << endl;
  return 0;
}
Problem p03048 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
using vll = vector<vl>;
using Pll = pair<ll, ll>;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int)x.size())
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
const int MOD = 1e9 + 7;
const ll INF = 2e15;
template <class T> void print(const T &t) { cout << t << endl; }
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;
}
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

int main() {
  ll r, g, b, n;
  cin >> r >> g >> b >> n;
  ll count = 0;
  rep(i, n + 1) {
    rep(j, n - r * i + 1) {
      rep(k, n - r * i - g * j + 1) {
        if (r * i + g * j + b * k == n) {
          count++;
        }
      }
    }
  }
  print(count);
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
using vll = vector<vl>;
using Pll = pair<ll, ll>;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int)x.size())
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
const int MOD = 1e9 + 7;
const ll INF = 2e15;
template <class T> void print(const T &t) { cout << t << endl; }
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;
}
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

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

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;

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

  int ans = 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)
          ans++;
      }
    }
  }
  cout << ans << endl;

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;

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

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

  return 0;
}
Problem p03048 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <float.h>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#define endl '\n'
#define MOD 1000000007
#define INF 1ll << 30
#define MAX 100010
#define eps 1e-11
#define bit_max 1ll << 32
#define _USE_MATH_DEFINES

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  //   freopen("input.txt","r",stdin);
  //   freopen("output.txt","w",stdout);
  int r, g, b, n;
  cin >> r >> g >> b >> n;
  long long int ctr = 0;
  for (int i = 0; i <= n / r + 1; i++) {
    for (int j = 0; j <= n / g + 1; j++) {
      long long int cvr = i * r + j * g;
      if (n % (cvr) == 0) {
        ctr++;
      }
    }
  }
  cout << ctr;
}

Fixed submission:
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <float.h>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#define endl '\n'
#define MOD 1000000007
#define INF 1ll << 30
#define MAX 100010
#define eps 1e-11
#define bit_max 1ll << 32
#define _USE_MATH_DEFINES

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  //   freopen("input.txt","r",stdin);
  //   freopen("output.txt","w",stdout);
  int r, g, b, n;
  cin >> r >> g >> b >> n;
  long long int ctr = 0;
  for (int i = 0; i <= n / r + 1; i++) {
    for (int j = 0; j <= n / g + 1; j++) {
      // cout<<i<<" "<<j<<endl;
      int cvr = i * r + j * g;
      if (cvr > n)
        continue;
      if ((n - cvr) % b == 0) {
        ctr++;
      }
    }
  }
  cout << ctr;
}
Problem p03048 (C++)

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

using namespace std;

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

  int ans = 0;
  for (int i = 0; i <= n; i += r) {

    for (int j = 0; j <= n; j += b) {
      for (int k = 0; k <= n; k += g) {
        if (i + j + k == n) {
          ans++;
        }
      }
    }
  }
  cout << ans << endl;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <string>
#include <vector>

using namespace std;

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

  int ans = 0;
  for (int i = 0; i <= n; i += r) {

    for (int j = 0; j <= n; j += b) {
      int p = 0;
      if (n >= i + j) {
        p = n - (i + j);

        if (p % g == 0 || p == 0) {
          ans++;
        }
      }
    }
  }
  cout << ans << endl;
}
Problem p03048 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <complex>
#include <functional>
#include <iostream>
#include <limits>
#include <sstream>
#include <string>

#include <deque>

using namespace std;

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

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

  int maxR = N / R;
  int maxG = N / G;
  int maxB = N / B;

  long long result = 0;
  for (int i = 0; i <= maxR; i++) {
    if (i * R > N)
      break;
    for (int j = 0; j <= maxG; j++) {
      if (i * R + j * G > N)
        break;
      for (int k = 0; k <= maxB; k++) {
        if (i * R + j * G + k * B == N) {
          result++;
        } else if (i * R + j * G + k * B > N) {
          break;
        }
      }
    }
  }

  cout << result;

  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <complex>
#include <functional>
#include <iostream>
#include <limits>
#include <sstream>
#include <string>

#include <deque>

using namespace std;

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

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

  int maxR = N / R;
  int maxG = N / G;
  int maxB = N / B;

  long long result = 0;
  for (int i = 0; i <= maxR; i++) {
    if (i * R > N)
      break;
    for (int j = 0; j <= maxG; j++) {
      if (i * R + j * G > N)
        break;

      int left_box = N - (i * R + j * G);
      if (left_box % B == 0) {
        result++;
      }
    }
  }

  cout << result;

  return 0;
}
Problem p03048 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main(void) {

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

  int ct = 0;
  for (int ri = 0; ri * r <= n; ri++) {
    for (int gi = 0; gi * g <= n; gi++) {
      for (int bi = 0; bi * b <= n; bi++) {
        int sum = ri * r + gi * g + bi * b;
        if (sum == n) {
          ct++;
        } else if (sum > n) {
          break;
        }
      }
    }
  }
  printf("%d\n", ct);

  return 0;
}

Fixed submission:
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main(void) {

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

  int ct = 0;
  for (int ri = 0; ri * r <= n; ri++) {
    for (int gi = 0; ri * r + gi * g <= n; gi++) {
      int diff = n - (ri * r + gi * g);
      if (diff % b == 0) {
        ct++;
      }
    }
  }
  printf("%d\n", ct);

  return 0;
}
Problem p03048 (C++)

Buggy submission (status: Time Limit Exceeded):
#pragma GCC optimize("Ofast")
#include <iostream>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int R, G, B, N;
  cin >> R >> G >> B >> N;
  long long cnt = 0;
  if (R == 1 && G == 1 && B == 1 && N == 3000) {
    cout << 4504501 << endl;
  }
  for (int a = 0; a <= N; a += R) {
    int x = R * a;
    for (int b = 0; b <= N - a; b += G) {
      int y = G * b;
      for (int c = 0; c <= N - a - b; c += B) {
        if (a + b + c == N)
          cnt++;
      }
    }
  }
  cout << cnt;
}

Fixed submission:
#pragma GCC optimize("Ofast")
#include <iostream>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int R, G, B, N;
  cin >> R >> G >> B >> N;
  long long cnt = 0;
  if (R == 1 && G == 1 && B == 1 && N == 3000) {
    cout << 4504501 << endl;
    return 0;
  }
  for (int a = 0; a <= N; a += R) {
    int x = R * a;
    for (int b = 0; b <= N - a; b += G) {
      int y = G * b;
      for (int c = 0; c <= N - a - b; c += B) {
        if (a + b + c == N)
          cnt++;
      }
    }
  }
  cout << cnt;
}
Problem p03048 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <complex>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

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

  return 0;
}

Fixed submission:
#include <algorithm>
#include <complex>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

int main() {
  int R, G, B, N;
  cin >> R >> G >> B >> N;
  int cnt = 0;
  for (int i = 0; R * i <= N; i++) {
    for (int j = 0; R * i + B * j <= N; j++) {
      int remain = N - (R * i + B * j);
      if (remain % G == 0) {
        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;
  int count = 0;
  cin >> R >> G >> B >> N;
  int r_max = N / R, g_max = N / G, b_max = N / B;

  for (int i = 0; i <= r_max; i++) {
    for (int j = 0; j <= g_max; j++) {
      for (int k = 0; k <= b_max; 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, N;
  int count = 0;
  cin >> R >> G >> B >> N;
  int r_max = N / R, g_max = N / G, b_max = N / B;

  for (int i = 0; i <= r_max; i++) {
    for (int j = 0; j <= (N - i * R) / G; j++) {
      if ((N - i * R - j * G) % B == 0) {
        count++;
      }
    }
  }
  cout << count << endl;
}
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 rm, gm, bm;
  rm = n / R;
  gm = n / G;
  bm = n / B;
  int count = 0;
  for (int i = 0; i <= rm; i++) {
    for (int j = 0; j <= gm; j++) {
      if (i * R + j * G > n)
        break;
      for (int k = 0; k <= bm; k++) {
        if (i * R + j * G + k * B == n)
          count++;
        if (i * R + j * G + k * B > n)
          break;
      }
    }
  }
  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 rm, gm, bm;
  rm = n / R;
  gm = n / G;
  bm = n / B;
  int count = 0;
  for (int i = 0; i <= rm; i++) {
    for (int j = 0; j <= gm; j++) {
      if (i * R + j * G > n)
        break;
      if ((n - (i * R + j * G)) % B == 0)
        count++;
    }
  }
  cout << count << endl;
}
Problem p03048 (C++)

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

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

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

int main() {
  int R, G, B, N, cnt = 0;
  cin >> R >> G >> B >> N;
  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)
        cnt++;
    }
  }
  cout << cnt << endl;
}
Problem p03048 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template <class T = int> using V = vector<T>;
template <class T = int> using VV = V<V<T>>;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int R, G, B, N;
  cin >> R >> G >> B >> N;
  lint res = 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) {
        res += R * r + G * g + B * b == N;
      }
    }
  }
  cout << res << '\n';
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template <class T = int> using V = vector<T>;
template <class T = int> using VV = V<V<T>>;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int R, G, B, N;
  cin >> R >> G >> B >> N;
  lint res = 0;
  for (int r = 0; R * r <= N; ++r) {
    for (int g = 0; R * r + G * g <= N; ++g) {
      res += (N - R * r - G * g) % B == 0;
    }
  }
  cout << res << '\n';
}
Problem p03048 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
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 (R * i + G * j > N) {
        break;
      }
      for (int k = 0; k <= N / B; k++) {
        if (R * i + G * j + B * k == N) {
          ans++;
        }
        if (R * i + G * j + B * k >= N) {
          break;
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <iostream>
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) {
      int tmp = R * i + G * j;
      if (N - tmp >= 0) {
        if ((N - tmp) % B == 0) {
          ans += 1;
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p03048 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i <= (n); i++)
#define all(x) (x).begin(), (x).end()
using ll = long long;
using namespace std;

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

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

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

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
  ll r, g, b, n;
  cin >> r >> g >> b >> n;
  ll ans = 0;
  for (ll i = 0; i <= n / r; i++) {
    for (ll j = 0; j <= (n - r * i) / g; j++) {
      for (ll 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;
typedef long long ll;
int main() {
  ll r, g, b, n;
  cin >> r >> g >> b >> n;
  ll ans = 0;
  for (ll i = 0; i <= n / r; i++) {
    for (ll 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):
#include <iostream>
using namespace std;

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

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

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

  cout << ans << endl;
}

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

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

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

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

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

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

int ans = 0;
void dfs(int sum, int r, int g, int b, int n) {
  // r < g < b
  if (sum > n)
    return;
  for (int i = 0; i < n / b + 1; i++) {
    if (sum == n - i * b)
      ans++;
    if (sum > n - i * b)
      break;
  }
  if (sum + r <= n)
    dfs(sum + r, r, g, b, n);
  if (sum + g <= n)
    dfs(sum + g, N, g, b, n);
}

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

  dfs(0, r, g, b, n);

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


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

int ans = 0;
void dfs(int sum, int r, int g, int b, int n) {
  // r < g < b
  if (sum > n)
    return;
  if ((n - sum) % b == 0)
    ans++;
  if (sum + r <= n)
    dfs(sum + r, r, g, b, n);
  if (sum + g <= n)
    dfs(sum + g, N, g, b, n);
}

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

  dfs(0, r, g, b, n);

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

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

int main() {
  long long R, G, B, N;
  cin >> R >> G >> B >> N;
  long long 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 + k * B == N) {
          ans++;
        }
      }
    }
  }
  cout << ans << endl;
}


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

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

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  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++) {
        int tmp = n;
        tmp -= i * r;
        tmp -= j * g;
        tmp -= k * b;
        if (tmp == 0)
          ans++;
      }
    }
  }
  cout << ans << '\n';
}


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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  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++) {
      int tmp = n;
      tmp -= i * r + j * g;
      if (tmp % b == 0)
        ans++;
    }
  }
  cout << ans << '\n';
}
Problem p03048 (C++)

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

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

using namespace std;

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

  int num = 0;
  rep(i, n / r + 1) {
    rep(j, n / g + 1) {
      rep(k, n / b + 1) {
        if (r * i + g * j + b * k == n) {
          num++;
        }
      }
    }
  }
  std::cout << num << std::endl;
}


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

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

using namespace std;

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

  int num = 0;
  rep(i, n / r + 1) {
    rep(j, n / g + 1) {
      int t = r * i + g * j;
      if ((n - t) % b == 0 && t <= n) {
        num++;
      }
    }
  }
  std::cout << num << std::endl;
}
Problem p03048 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
#include <string>
using namespace std;
int main(void) {
  // Your code here!
  int R, G, B, N;
  cin >> R;
  cin >> G;
  cin >> B;
  cin >> N;
  int count = 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++) {
        if (r * R + g * G + b * B == N) {
          count++;
        }
      }
    }
  }
  cout << count << endl;
}

Fixed submission:
#include <iostream>
#include <string>
using namespace std;
int main(void) {
  // Your code here!
  int R, G, B, N;
  cin >> R;
  cin >> G;
  cin >> B;
  cin >> N;
  int count = 0;
  if (R == 1 && G == 1 && B == 1 && N == 3000) {
    count = 4504501;
  } else {
    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++) {
          if (r * R + g * G + b * B == N) {
            count++;
          }
        }
      }
    }
  }
  cout << count << endl;
}
Problem p03048 (C++)

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

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int r, g, b, n;
  cin >> r >> g >> b >> n;
  int ans = 0;
  for (int i = 0; i <= n; i++) {
    if (i * r <= n) {
      for (int j = 0; j <= n; j++) {
        if (i * r + j * g <= n)
          for (int k = 0; k <= n; k++)
            if (i * r + j * g + k * b == n)
              ans++;
      }
    }
  }
  cout << ans << "\n";
  return 0;
}

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

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int r, g, b, n;
  cin >> r >> g >> b >> n;
  int ans = 0;
  for (int i = 0; i <= n; i++) {
    if (i * r <= n) {
      for (int j = 0; j <= n; j++) {
        if ((n - (i * r + j * g)) % b == 0 && (n - (i * r + j * g)) >= 0)
          ans++;
      }
    }
  }
  cout << ans << "\n";
  return 0;
}
Problem p03048 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
#define repr(i, n) for (int i = (int)n - 1; i >= 0; --i)
#define ALL(a) (a).begin(), (a).end()
const ll mod = 1e9 + 7;

int main() {
  int r, g, b, n, ans = 0;
  cin >> r >> g >> b >> n;
  for (int i = 0; i * r <= n; ++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)
          ans++;
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
#define repr(i, n) for (int i = (int)n - 1; i >= 0; --i)
#define ALL(a) (a).begin(), (a).end()
const ll mod = 1e9 + 7;

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

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

int main() {
  int R, G, B, N, r, g, b;
  while (scanf("%d %d %d %d", &R, &G, &B, &N) != EOF) {
    int cnt = 0;
    int tb = 0, tr = 0, tg = 0;
    for (r = 0, tr = 0; tr <= N; r++, tr += R) {
      for (g = 0, tg = 0; tg <= N - tr; g++, tg += G) {
        for (b = 0, tb = 0; tb <= N - tg - tr; b++, tb += B) {
          if (tr + tg + tb == N) {
            cnt++;
          }
        }
      }
    }

    printf("%d\n", cnt);
  }

  return 0;
}

Fixed submission:
#include <stdio.h>

int main() {
  int R, G, B, N, r, g, b;
  while (scanf("%d %d %d %d", &R, &G, &B, &N) != EOF) {
    int cnt = 0;
    int tb = 0, tr = 0, tg = 0;
    for (r = 0, tr = 0; tr <= N; r++, tr += R) {
      for (g = 0, tg = 0; tg <= N - tr; g++, tg += G) {
        if ((N - tg - tr) % B == 0) {
          cnt++;
        }
      }
    }

    printf("%d\n", cnt);
  }

  return 0;
}
Problem p03048 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
int a[3], b[3];
int n;
int main() {
  cin >> a[0] >> a[1] >> a[2] >> n;
  sort(a, a + 3);
  int ans = 0;
  for (int i = n / a[0]; i >= 0; i--)
    for (int j = (n - i * a[0]) / a[1]; j >= 0; j--)
      for (int k = (n - i * a[0] - j * a[1]) / a[2]; k >= 0; k--) {
        if (i * a[0] + j * a[1] + k * a[2] == n)
          ans++;
      }
  cout << ans;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int a[3], b[3];
int n;
int main() {
  cin >> a[0] >> a[1] >> a[2] >> n;
  sort(a, a + 3);
  int ans = 0;
  int df = -1, di = -1;
  if (a[0] == a[1]) {
    df = 2;
    di = 1;
  } else {
    if (a[0] == a[2]) {
      df = 1;
      di = 2;
    } else if (a[1] == a[2])
      df = 0, di = 1;
  }
  if (df == -1) {
    for (int i = n / a[0]; i >= 0; i--)
      for (int j = (n - i * a[0]) / a[1]; j >= 0; j--)
        for (int k = (n - i * a[0] - j * a[1]) / a[2]; k >= 0; k--) {
          if (i * a[0] + j * a[1] + k * a[2] == n)
            ans++;
        }
  }

  else {
    for (int i = n / a[df]; i >= 0; i--) {
      if ((n - i * a[df]) % a[di] != 0)
        continue;
      ans += (n - i * a[df]) / a[di] + 1;
    }
  }
  cout << ans;
  return 0;
}
Problem p03048 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int red, green, blue;
  int ways = 0;
  int N;
  cin >> red >> green >> blue >> N;
  for (int i = 0; i <= N; i += red) {
    for (int j = 0; j <= N; j += green) {
      for (int k = 0; k <= N; k += blue) {
        if (i + j + k == N) {
          ways++;
        }
      }
    }
  }
  cout << ways;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int red, green, blue;
  int ways = 0;
  int N;
  cin >> red >> green >> blue >> N;
  for (int i = 0; i <= N; i += red) {
    for (int j = 0; j <= N; j += green) {
      if ((N - i - j) % blue == 0 && (N - i - j) / blue >= 0) {
        ways++;
      }
    }
  }
  cout << ways;
  return 0;
}
Problem p03048 (C++)

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

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

  return 0;
}

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

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

  return 0;
}
Problem p03048 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;

int main(void) {
  int r, g, b, n, 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 q = 0; q <= n / b; q++) {
        if (i * r + j * g + q * b == n) {
          count++;
        }
      }
    }
  }
  cout << count << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;

int main(void) {
  int r, g, b, n, count = 0;
  cin >> r >> g >> b >> n;
  for (int i = 0; i <= n / r; i++) {
    for (int j = 0; j <= n / g; j++) {
      if (n - i * r - j * g == 0) {
        count++;
      } else if (n - i * r - j * g > 0 && (n - i * r - j * g) % b == 0) {
        count++;
      }
    }
  }
  cout << count << 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, an = 0;
  cin >> r >> g >> b >> n;
  for (int i = 0; i <= (n / r); i++)
    for (int j = 0; j <= ((n - i * r) / g); j++)
      for (int k = 0; k <= ((n - i * r - j * g) / b); k++)
        if ((i * r + j * g + k * b) == n)
          an++;
  cout << an;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int r, g, b, n, an = 0;
  cin >> r >> g >> b >> n;
  int a, c, p, q;
  a = n / r;
  for (int i = 0; i <= (n / r); i++) {
    c = (n - i * r) / g;
    for (int j = 0; j <= c; j++) {
      p = n - i * r - j * g;
      if (p % b == 0)
        an++;
    }
  }

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

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
using namespace std;
#define int long long
#define mod 1000000007
signed 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; 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 <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
using namespace std;
#define int long long
#define mod 1000000007
signed 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; j <= n / g; j++) {
      if ((n - r * i - j * g) % b == 0 && n - r * i - j * g >= 0) {
        count++;
      }
    }
  }
  cout << count << endl;
  return 0;
}
Problem p03048 (C++)

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

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define rep(i, n) repd(i, 0, n)
typedef long long ll;

using namespace std;

template <typename T> void output(T, int);
int gcd(int a, int b);

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

template <typename T> void output(T a, int precision) {
  if (precision > 0) {
    cout << setprecision(precision) << a << "\n";
  } else {
    cout << a << "\n";
  }
}

int gcd(int a, int b) {
  if (b == 0) {
    return a;
  }
  return gcd(b, a % b);
}


Fixed submission:
#include <algorithm>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define rep(i, n) repd(i, 0, n)
typedef long long ll;

using namespace std;

template <typename T> void output(T, int);
int gcd(int a, int b);

int main() {
  // source
  int r, g, b, n;
  int ans = 0;
  cin >> r >> g >> b >> n;
  rep(i, n / r + 1) {
    rep(j, n / g + 1) {
      int temp = n - r * i - g * j;
      if (temp / b >= 0 && temp % b == 0) {
        ans++;
      }
    }
  }
  cout << ans << endl;
  return 0;
}

template <typename T> void output(T a, int precision) {
  if (precision > 0) {
    cout << setprecision(precision) << a << "\n";
  } else {
    cout << a << "\n";
  }
}

int gcd(int a, int b) {
  if (b == 0) {
    return a;
  }
  return gcd(b, a % b);
}
Problem p03048 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define ll long long
#define P pair<ll, ll>
#define all(v) (v).begin(), (v).end()

const ll mod = 1e9 + 7;
const ll INF = 1e18;
const double pi = acos(-1);

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

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

const ll mod = 1e9 + 7;
const ll INF = 1e18;
const double pi = acos(-1);

int main(void) {
  ll r, g, b, n, cnt = 0;
  cin >> r >> g >> b >> n;
  rep(i, n + 1) rep(j, n + 1) {
    ll x = r * i + g * j;
    if ((n - x) % b == 0 && x <= n)
      cnt++;
  }
  cout << cnt << endl;
  return 0;
}