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

Buggy submission (status: Time Limit Exceeded):
#include <iostream>

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

  scanf("%d %d %d %d", &R, &G, &B, &N);

  int r, g, b, cnt;

  cnt = 0;

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

  printf("%d", cnt);

  return 0;
}

Fixed submission:
#include <iostream>

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

  scanf("%d %d %d %d", &R, &G, &B, &N);

  int r, g, b, cnt;

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

  printf("%d", cnt);

  return 0;
}
Problem p03048 (Python)

Buggy submission (status: Time Limit Exceeded):
R, G, B, N = map(int, input().split())

ans = 0
for i in range(N // R + 1):
    N_R = N - i * R
    for j in range(N_R // G + 1):
        N_RG = N_R - j * G
        for k in range(N_RG // B + 1):
            N_RGB = N_RG - k * B
            if N_RGB == 0:
                ans += 1
print(ans)


Fixed submission:
R, G, B, N = map(int, input().split())

ans = 0
for i in range(N // R + 1):
    for j in range((N - i * R) // G + 1):
        if (N - i * R - j * G) % B == 0:
            ans += 1
print(ans)
Problem p03048 (Python)

Buggy submission (status: Time Limit Exceeded):
R, G, B, N = map(int, input().split())

ans = 0
for i in range(int(N / R) + 1):
    for j in range(int((N - i * R) / G) + 1):
        if (N - (i * R + j * G)) % B == 0 and (N - (i * R + j * G)) >= 0:
            ans += 1
print(ans)


Fixed submission:
R, G, B, N = map(int, input().split())

ans = 0
for i in range(int(N / R) + 1):
    for j in range(int((N - i * R) / G) + 1):
        if (N - (i * R + j * G)) % B == 0:
            ans += 1
print(ans)
Problem p03048 (Python)

Buggy submission (status: Time Limit Exceeded):
R, G, B, N = map(int, input().split())
LIM = 3003
ans = 0
for r in range(LIM):
    for g in range(LIM):
        if R * r + G * g > N:
            break
        Bb = N - R * r - G * g
        if Bb % B == 0:
            ans += 1
print(ans)


Fixed submission:
def solve():
    R, G, B, N = map(int, input().split())
    LIM = 3001
    ans = 0
    for r in range(LIM):
        for g in range(LIM):
            if R * r + G * g > N:
                break
            Bb = N - R * r - G * g
            if Bb % B == 0:
                ans += 1
    return ans


print(solve())
Problem p03048 (Python)

Buggy submission (status: Time Limit Exceeded):
R, G, B, N = map(int, input().split())

res = 0

for i in range(N // R + 1):
    for j in range(N // G + 1):
        b = N - R * i - G * j
        if b >= 0 and b % B == 0:
            res += 1

print(res)


Fixed submission:
R, G, B, N = map(int, input().split())

res = 0

for i in range(N // R + 1):
    for j in range((N - R * i) // G + 1):
        b = N - R * i - G * j
        if b >= 0 and b % B == 0:
            res += 1

print(res)
Problem p03048 (Python)

Buggy submission (status: Time Limit Exceeded):
# from time import perf_counter


def main():
    r, g, b, n = list(map(int, input().split()))
    count = 0
    x1, x2, x3 = sorted([r, g, b], reverse=True)
    # print(x1, x2, x3)
    for i in range(n // x1 + 1):
        for j in range((n - i) // x2 + 1):
            for k in range((n - i - j) // x3 + 1):
                # print(f'{r}*{i} + {g}*{j} + {b}*{k} = {r*i+g*j+k+b*k}')
                if x1 * i + x2 * j + x3 * k == n:
                    count += 1

    print(count)


if __name__ == "__main__":
    # s = perf_counter()
    main()
    # e = perf_counter()
    # print('process:', e - s)


Fixed submission:
# from time import perf_counter


def main():
    r, g, b, n = list(map(int, input().split()))
    count = 0
    x1, x2, x3 = sorted([r, g, b], reverse=True)
    # print(x1, x2, x3)
    for i in range(n // x1 + 1):
        for j in range((n - i) // x2 + 1):
            rest = n - (x1 * i) - (x2 * j)
            # print(f'{x1}*{i} + {x2}*{j} = {n - rest}')
            if rest == 0:
                # print(f'{x1}*{i} + {x2}*{j} + {x3}*0 = {n}')
                count += 1
            else:
                # print(f'{x1}*{i} + {x2}*{j} + {x3}*? = {n}')
                count += 1 if rest > 0 and rest % x3 == 0 else 0
            # for k in range((n - i - j) // x3 + 1):
            # print(f'{r}*{i} + {g}*{j} + {b}*{k} = {r*i+g*j+k+b*k}')
            #    if x1 * i + x2 * j + x3 * k == n:
            #        count += 1

    print(count)


if __name__ == "__main__":
    # s = perf_counter()
    main()
    # e = perf_counter()
    # print('process:', e - s)
Problem p03048 (Python)

Buggy submission (status: Time Limit Exceeded):
r, g, b, n = map(int, input().split())

ans = 0
for i in range(n // r + 1):
    for j in range(n // g + 1):
        m = r * i + g * j
        if m <= n and (n - m) % b == 0:
            ans += 1

print(ans)


Fixed submission:
r, g, b, n = map(int, input().split())

ans = 0
for i in range(n // r + 1):
    for j in range(n // g + 1):
        m = r * i + g * j
        if m <= n and (n - m) % b == 0:
            ans += 1
        elif m > n:
            break

print(ans)
Problem p03048 (Python)

Buggy submission (status: Time Limit Exceeded):
#!/usr/bin/env python3
import sys

read = sys.stdin.buffer.read
# input = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
a, b, c, n = map(int, input().split())
ans = 0
for i in range(3001):
    for j in range(3001):
        if n <= i * a + j * b and (n - i * a - j * b) % c == 0:
            ans += 1
print(ans)


Fixed submission:
#!/usr/bin/env python3
import sys

read = sys.stdin.buffer.read
# input = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
a, b, c, n = map(int, input().split())
ans = 0
for i in range(3001):
    for j in range(3001):
        if n >= i * a + j * b and (n - i * a - j * b) % c == 0:
            ans += 1
print(ans)
Problem p03048 (Python)

Buggy submission (status: Time Limit Exceeded):
r, g, b, n = map(int, input().split())
ans = 0
nr = n // r
ng = n // g
for i in range(nr + 1):
    for j in range(ng + 1):
        tmp = n - i * r - j * g
        if tmp % b == 0 and tmp >= 0:
            ans += 1
print(ans)


Fixed submission:
r, g, b, n = map(int, input().split())
ans = 0
nr = n // r
ng = n // g
for i in range(nr + 1):
    for j in range(ng + 1):
        tmp = n - i * r - j * g
        if tmp >= 0 and tmp % b == 0:
            ans += 1
print(ans)
Problem p03048 (Python)

Buggy submission (status: Time Limit Exceeded):
r, g, b, n = map(int, input().split())
c = sorted([r, g, b])[::-1]
ans = 0
for i in range(n // c[0] + 1):
    for j in range((n - i * r) // c[1] + 1):
        x = n - i * c[0] - j * c[1]
        if x >= 0 and x % c[2] == 0:
            ans += 1
print(ans)


Fixed submission:
r, g, b, n = map(int, input().split())
c = sorted([r, g, b])[::-1]
ans = 0
for i in range(n // c[0] + 1):
    x = n - i * c[0]
    for j in range(x // c[1] + 1):
        y = x - j * c[1]
        if y < 0:
            break
        elif y % c[2] == 0:
            ans += 1
print(ans)
Problem p03048 (Python)

Buggy submission (status: Time Limit Exceeded):
R, G, B, N = map(int, input().split())
ans = 0

for r in range(min(3000, 3000 // R) + 1):
    for g in range(min(3000, 3000 // G) + 1):
        v = R * r + G * g
        if N >= v and (N - v) % B == 0:
            ans += 1

print(ans)


Fixed submission:
R, G, B, N = map(int, input().split())
ans = 0

for r in range(min(3000, 3000 // R) + 1):
    if R * r <= N:
        for g in range(min(3000, 3000 // G) + 1):
            v = R * r + G * g
            if N >= v and (N - v) % B == 0:
                ans += 1

print(ans)
Problem p03048 (Python)

Buggy submission (status: Time Limit Exceeded):
R, G, B, N = map(int, input().split())
ans = 0
for r in range(3001):
    if R * r > N:
        break
    for g in range(3001):
        if R * r + G * g > N:
            break
        elif (N - (R * r + G * g)) % B == 0:
            ans += 1
print(ans)


Fixed submission:
R, G, B, N = map(int, input().split())
ans = 0
for r in range(N // R + 1):
    for g in range((N - R * r) // G + 1):
        if (N - (R * r + G * g)) % B == 0:
            ans += 1
print(ans)
Problem p03048 (C++)

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

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

  for (int i = 0; i <= N / R; 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 (Python)

Buggy submission (status: Time Limit Exceeded):
R, G, B, N = map(int, input().split())

counter = 0
for r in range((N // R) + 1):
    for g in range(((N - (r * R)) // G) + 1):
        w_b_sum = N - ((R * r) + (G * g))

        if w_b_sum % B == 0 and w_b_sum >= 0 and w_b_sum == N - ((R * r) + (G * g)):
            # print(r, g, (w_b_sum // B))
            counter += 1
print(counter)


Fixed submission:
R, G, B, N = map(int, input().split())

counter = 0
for r in range((N // R) + 1):
    for g in range(((N - (r * R)) // G) + 1):
        w_b_sum = N - ((R * r) + (G * g))

        if w_b_sum % B == 0 and w_b_sum >= 0:
            # print(r, g, (w_b_sum // B))
            counter += 1
print(counter)
Problem p03048 (Python)

Buggy submission (status: Time Limit Exceeded):
r, g, b, n = map(int, input().split())

cnt = 0
for i in range(3001):
    for j in range(3001):
        x = n - (r * i + g * j)
        if x < 0:
            continue
        if x % b == 0:
            cnt += 1

print(cnt)


Fixed submission:
r, g, b, n = map(int, input().split())

cnt = 0
for i in range(int(n // r) + 1):
    r_num = r * i
    for j in range(int((n - r_num) // g) + 1):
        g_num = g * j
        b_num = n - r_num - g_num
        if b_num >= 0 and b_num % b == 0:
            cnt += 1

print(cnt)
Problem p03048 (C++)

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

using namespace std;

int R, G, B, N;

int main() {
  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++;
          break;
        }
      }
    }
  }

  cout << ans << endl;
}

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

using namespace std;

int R, G, B, N;

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

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

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

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

using namespace std;

int main() {
  int r, g, b, n;
  cin >> r >> g >> b >> n;
  long long 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 (i * r + j * g + k * b == n)
          count++;
  cout << count << endl;
}

Fixed submission:
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main() {
  int r, g, b, n;
  cin >> r >> g >> b >> n;
  long long count = 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 and n - i * r - j * g >= 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 < n; i++)
#define ll long long

// const int INF = 1e8;
typedef pair<int, int> P;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
queue<P> que;

int main(void) {
  int a, b, c, n;
  cin >> a >> b >> c >> n;
  ll sum = 0;
  for (int i = 0; i * a <= n; i++) {
    for (int j = 0; i * a + j * b <= n; j++) {
      for (int k = 0; i * a + j * b + k * c <= n; k++) {
        if (i * a + j * b + k * c == n) {
          sum += 1;
        }
      }
    }
  }
  cout << sum << endl;
}

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

// const int INF = 1e8;
typedef pair<int, int> P;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
queue<P> que;

int main(void) {
  int a, b, c, n;
  cin >> a >> b >> c >> n;
  ll sum = 0;
  for (int i = 0; i * a <= n; i++) {
    for (int j = 0; i * a + j * b <= n; j++) {
      int t = n - i * a - j * b;
      int d = t / c;
      if (d * c == t) {
        sum += 1;
        // cout << i <<" "<< j <<" "<< t/c << endl;
      }
    }
  }
  cout << sum << endl;
}
Problem p03048 (C++)

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

using namespace std;

typedef long long int llint;
typedef pair<int, int> pii;
typedef pair<llint, llint> pll;
typedef vector<int> vi;
typedef vector<llint> vl;
typedef vector<pii> vii;
typedef vector<pll> vll;

#define ci cin
#define co cout
#define en endl
#define ln cout << '\n'
#define rep(i, n) for (int i = 0; i < n; i++)
#define outl(x) cout << (x) << '\n'
#define pb push_back
#define fi first
#define se second
#define MOD 1000000007

template <typename Tn> Tn gcd(Tn a, Tn b) { return (b ? gcd(b, a % b) : a); }

template <typename Tn> Tn lcm(Tn a, Tn b) { return a / gcd(a, b) * b; }

string IntToString(int number) {
  stringstream ss;
  ss << number;
  return ss.str();
}

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

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

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

    for (int j = 0; j * g <= n - sumr; j++) {
      int sumg = j * g + sumr;

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

  co << cnt << en;

  return 0;
}


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

using namespace std;

typedef long long int llint;
typedef pair<int, int> pii;
typedef pair<llint, llint> pll;
typedef vector<int> vi;
typedef vector<llint> vl;
typedef vector<pii> vii;
typedef vector<pll> vll;

#define ci cin
#define co cout
#define en endl
#define ln cout << '\n'
#define rep(i, n) for (int i = 0; i < n; i++)
#define outl(x) cout << (x) << '\n'
#define pb push_back
#define fi first
#define se second
#define MOD 1000000007

template <typename Tn> Tn gcd(Tn a, Tn b) { return (b ? gcd(b, a % b) : a); }

template <typename Tn> Tn lcm(Tn a, Tn b) { return a / gcd(a, b) * b; }

string IntToString(int number) {
  stringstream ss;
  ss << number;
  return ss.str();
}

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

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

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

    for (int j = 0; j * g <= n - sumr; j++) {
      int sumg = j * g + sumr;

      if ((n - sumg) % b == 0)
        cnt++;
    }
  }

  co << cnt << en;

  return 0;
}
Problem p03048 (C++)

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

using ll = long long;

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

  int ans = 0;
  for (int rr = 0; rr < N / R + 1; rr++) {
    for (int gg = 0; gg < (N - R * rr) / G + 1; gg++) {
      for (int bb = 0; bb < (N - R * rr - G * gg) / B + 1; bb++) {
        if ((R * rr + G * gg + B * bb) == N)
          ans++;
      }
    }
  }
  cout << ans << endl;
}


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

using ll = long long;

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

  int ans = 0;
  for (int rr = 0; rr < N / R + 1; rr++) {
    for (int gg = 0; gg < (N - R * rr) / G + 1; gg++) {
      if ((N - R * rr - G * gg) % B == 0)
        ans++;
    }
  }
  cout << ans << 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 just_count = 0;
  for (int i = 0; i * R <= N; i++) {
    for (int j = 0; j * G <= N; j++) {
      for (int k = 0; k * B <= N; k++) {
        if (i * R + j * G + k * B == N) {
          just_count++;
        }
      }
    }
  }
  cout << just_count << endl;
}


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

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

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#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;
  for (int i = 0; i <= (3000 / R); i++) {     // iはRの数
    for (int j = 0; j <= (3000 / G); j++) {   // G
      for (int k = 0; k <= (3000 / B); k++) { // B
        if ((R * i) + (G * j) + (B * k) == N) {
          ans++;
        } else {
          continue;
        }
      }
    }
  }
  cout << ans << endl;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#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;
  for (int i = 0; i <= 3000; i++) { // iはRの数
    for (int j = 0; j <= 3000; j++) {
      int k = R * i + G * j;
      if (N >= k && (N - k) % B == 0) {
        ans++;
      }
    }
  }
  cout << ans << endl;
}
Problem p03048 (C++)

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

int main() {
  int R, G, B, N, ct, r, g, b;
  cin >> R >> G >> B >> N;
  ct = 0;
  for (r = 0; r * R <= N; r++) {
    for (g = 0; g * G <= N - r * R; g++) {
      ct = ((N - r * R + g * G) % b == 0) ? ct + 1 : ct;
    }
  }
  cout << ct << endl;
  return 0;
}

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

int main() {
  int R, G, B, N, ct, r, g, b;
  cin >> R >> G >> B >> N;
  ct = 0;
  for (r = 0; r * R <= N; r++) {
    for (g = 0; g * G <= N - r * R; g++) {
      ct = ((N - r * R - g * G) % B == 0) ? ct + 1 : ct;
    }
  }
  cout << ct << 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 answer = 0;
  for (int i = 0; i * R <= N; i++) {
    for (int j = 0; j * G <= N; j++) {
      for (int k = 0; k * B <= N; k++) {
        if (i * R + j * G + k * B == N) {
          answer++;
        }
      }
    }
  }
  cout << answer << endl;
}

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 i = 0; i * R <= N; i++) {
    for (int j = 0; j * G <= N; j++) {
      if ((N - i * R - j * G) >= 0 && (N - i * R - j * G) % B == 0) {
        answer++;
      }
    }
  }
  cout << answer << endl;
}
Problem p03048 (Python)

Buggy submission (status: Runtime Error):
def inpl():
    return list(map(int, input().split()))


def gcd(a, b):
    # greatest common divisor
    la = max(a, b)
    sm = min(a, b)
    if la % sm == 0:
        return sm
    else:
        return gcd(sm, la - sm)


def lcm(a, b):
    # least common multiple
    return a * b // gcd(a, b)


R, G, B, N = inpl()
ans = 0
for r in range(N // R + 1):
    rest = N - r * R
    for i in range(B):
        if (G * i) % B == rest % B:
            x = i
            break
    else:
        # print(r)
        continue
    if rest - G * x < 0:
        continue
    ans += (rest - G * x) // lcm(B, G) + 1
    # print(r, rest, x, ans)

print(ans)


Fixed submission:
def inpl():
    return list(map(int, input().split()))


def gcd(a, b):
    # greatest common divisor
    la = max(a, b)
    sm = min(a, b)
    if la % sm == 0:
        return sm
    else:
        return gcd(sm, la - sm)


def lcm(a, b):
    # least common multiple
    return a * b // gcd(a, b)


import sys

sys.setrecursionlimit(5000)


R, G, B, N = inpl()
ans = 0
for r in range(N // R + 1):
    rest = N - r * R
    for i in range(B):
        if (G * i) % B == rest % B:
            x = i
            break
    else:
        # print(r)
        continue
    if rest - G * x < 0:
        continue
    ans += (rest - G * x) // lcm(B, G) + 1
    # print(r, rest, x, ans)

print(ans)
Problem p03048 (C++)

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

#define LIM_S 200002
#define LIM_N 200001

char str[LIM_S];

int R, G, B, N;
int A[LIM_N];

void receive_input() {
  fgets(str, sizeof(str), stdin);
  sscanf(str, "%d %d %d %d", &R, &G, &B, &N);
}

void initialize() {}

int main(void) {
  receive_input();
  initialize();

  int r, g, b;
  int ans = 0;

  for (r = N / R; 0 <= r; r--) {
    for (g = N / G; 0 <= g; g--) {
      for (b = N / B; 0 <= b; b--) {
        // printf("%d %d %d %d\n", r, g, b, N);
        if (r * R + g * G + b * B == N) {
          ans++;
          // printf("!!\n");
        }
      }
    }
  }

  printf("%d\n", ans);

  return 0;
}


Fixed submission:
#include <algorithm>
#include <stdio.h>

#define LIM_S 200002
#define LIM_N 200001

char str[LIM_S];

int R, G, B, N;
int A[LIM_N];

void receive_input() {
  fgets(str, sizeof(str), stdin);
  sscanf(str, "%d %d %d %d", &R, &G, &B, &N);
}

void initialize() {}

int main(void) {
  receive_input();
  initialize();

  int r, g, b;
  int ans = 0;

  for (r = N / R; 0 <= r; r--) {
    for (g = N / G; 0 <= g; g--) {
      int x = N - (r * R + g * G);
      int b = x / B;
      if (x >= 0 && x % B == 0) {
        // printf("%d %d %d :%d\n", r, g, b, x);
        ans++;
      }
    }
  }

  printf("%d\n", ans);

  return 0;
}
Problem p03048 (C++)

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

typedef long long int ll;

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

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

typedef long long int ll;

int main() {
  int R, G, B, N;
  cin >> R >> G >> B >> N;
  long long 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 << i << '/' << j << '/' << k << endl;*/
        }
        if (i * R + j * G + k * B > N) {
          break;
        }
        if (i * R + j * G + (k + 100) * B < N) {
          k += 99;
        }
      }
    }
  }
  cout << ans << endl;
}
Problem p03048 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, ini, n) for (int i = ini; i < n; i++)
#define _rep(i, ini, n) for (int i = ini; i >= n; i--)
#define ToEnd(a) a.begin(), a.end()
uint64_t MOD = 1000000007;

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

  int64_t ans = 0;
  rep(r, 0, N / R + 1) {
    rep(g, 0, (N - r * R) / G + 1) {
      rep(b, 0, (N - r * R - g * G) / B + 1) {
        if (r * R + g * G + b * B == N)
          ans++;
      }
    }
  }

  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, ini, n) for (int i = ini; i < n; i++)
#define _rep(i, ini, n) for (int i = ini; i >= n; i--)
#define ToEnd(a) a.begin(), a.end()
uint64_t MOD = 1000000007;

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

  int64_t ans = 0;
  rep(r, 0, N / R + 1) {
    rep(g, 0, (N - r * R) / G + 1) {
      if ((N - r * R - g * G) % B == 0)
        ans++;
    }
  }

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

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
#include <vector>

using namespace std;

int main() {
  int R, G, B, N;
  cin >> R >> G >> B >> N;
  int ans = 0;
  vector<int> cnt;

  for (int i = 0; i <= N; i++) {
    int sum = 0;
    if (i * R > N)
      break;

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

      sum = i * R;
      sum += j * G;
      cnt.push_back(sum);
    }
  }

  for (int i = 0; i < cnt.size(); i++) {
    for (int j = 0; j <= N; j++) {
      if (cnt[i] + j * B > N)
        break;

      if (cnt[i] + j * B == N) {
        ans++;
        break;
      }
    }
  }

  cout << ans << endl;
}

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

using namespace std;

int main() {
  int R, G, B, N;
  cin >> R >> G >> B >> N;
  int ans = 0;
  vector<int> cnt;

  for (int i = 0; i <= N; i++) {
    int sum = 0;
    if (i * R > N)
      break;

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

      sum = i * R;
      sum += j * G;
      cnt.push_back(sum);
    }
  }

  for (int i = 0; i < cnt.size(); i++) {
    if ((N - cnt[i]) % 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;
  cin >> R >> G >> B >> N;

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

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

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

  int res = 0;
  for (int i = 0; i <= N / R; i++) {
    for (int j = 0; j <= N / G; j++) {
      int t = R * i + G * j;
      if (N >= t && (N - t) % B == 0)
        res++;
    }
  }
  cout << res << endl;
  return 0;
}
Problem p03048 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iomanip>
#include <iostream>
typedef long long ll;
using namespace std;
const ll INF = 1e9;
const ll MOD = 1e9 + 7;
#define repi(i, n, init) for (ll i = init; i < (n); i++)

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

Fixed submission:
#include <iomanip>
#include <iostream>
typedef long long ll;
using namespace std;
const ll INF = 1e9;
const ll MOD = 1e9 + 7;
#define repi(i, n, init) for (ll i = init; i < (n); i++)

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

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

using namespace std;
typedef long long ll;

#define REP(i, n) for (ll i = 0; i < (n); i++)
#define REPR(i, n) for (ll i = (n); i >= 0; i--)
#define FOR(i, m, n) for (ll i = (m); i < (n); i++)
#define FORR(i, m, n) for (ll i = (m); i >= (n); i--)
#define INF 1e9
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((ll)(x).size())
#define SORT(x) sort((x).begin(), (x).end())
#define dump(x) cerr << #x << " = " << (x) << endl
#define debug(x)                                                               \
  cerr << #x << " = " << (x) << " (L" << __LINE__ << ")"                       \
       << " " << __FILE__ << endl

int main(int argc, char const *argv[]) {
  ll r, g, b, n;
  ll res = 0;
  cin >> r >> g >> b >> n;
  for (ll i = 0; i <= n / r; i++) {
    for (ll j = 0; j <= (n - i * r) / g; j++) {
      if (i * r + j * g > n)
        break;
      for (ll k = 0; k <= (n - i * r - j * g) / b; k++) {
        if (i * r + j * g + k * b == n)
          res++;
        else if (i * r + j * g + k * b > n)
          break;
      }
    }
  }
  cout << res << endl;
  return 0;
}


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

using namespace std;
typedef long long ll;

#define REP(i, n) for (ll i = 0; i < (n); i++)
#define REPR(i, n) for (ll i = (n); i >= 0; i--)
#define FOR(i, m, n) for (ll i = (m); i < (n); i++)
#define FORR(i, m, n) for (ll i = (m); i >= (n); i--)
#define INF 1e9
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((ll)(x).size())
#define SORT(x) sort((x).begin(), (x).end())
#define dump(x) cerr << #x << " = " << (x) << endl
#define debug(x)                                                               \
  cerr << #x << " = " << (x) << " (L" << __LINE__ << ")"                       \
       << " " << __FILE__ << endl

int main(int argc, char const *argv[]) {
  ll r, g, b, n;
  ll res = 0;
  cin >> r >> g >> b >> n;
  for (ll i = 0; i <= n / r; i++) {
    for (ll j = 0; j <= (n - i * r) / g; j++) {
      ll k = (n - i * r - j * g) / b;
      if (i * r + j * g + k * b == n) {
        // dump(i);
        // dump(j);
        // dump(k);
        res++;
      }
    }
  }
  cout << res << 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, a = 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) {
          a++;
        }
      }
    }
  }
  cout << a << endl;
}

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

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

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

using namespace std;

int main(void) {
  int r, g, b, n;
  int ans = 0;
  int o, p, q;

  cin >> r >> g >> b >> n;
  o = n / r + 1;
  p = n / g + 1;
  q = n / b + 1;

  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 - g * j) / b + 1; k++) {
        if (i * r + j * g + k * b == n) {
          ans += 1;
        }
      }
    }
  }

  cout << ans << endl;

  return 0;
}

Fixed submission:
#pragma GCC optimize("Ofast")

#include <algorithm>
#include <iostream>
#include <string>
#include <utility>
#include <vector>

using namespace std;

int main(void) {
  int r, g, b, n;
  int ans = 0;
  int o, p, q;

  cin >> r >> g >> b >> n;
  o = n / r + 1;
  p = n / g + 1;
  q = n / b + 1;

  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 - g * j) / b + 1; k++) {
        if (i * r + j * g + k * b == n) {
          ans += 1;
        }
      }
    }
  }

  cout << ans << 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;
  cin >> G;
  cin >> B;
  cin >> N;

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

  return 0;
}


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

using namespace std;

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

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

  return 0;
}
Problem p03048 (C++)

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

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

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

int main() {
  int ans = 0, R, G, B, N;
  cin >> R >> G >> B >> N;
  for (int i = 0; i < N / R + 1; i++) {
    if (i * R > N) {
      break;
    }
    for (int j = 0; j < N / G + 1; j++) {
      if (i * R + j * G > N) {
        break;
      }
      if (R * i + G * j <= N and (N - R * i - G * j) % B == 0) {
        ans++;
      }
    }
  }
  cout << ans << 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 ans = 0;
  for (int i = 0; i <= (n + r - 1) / r; i++) {
    for (int q = 0; q <= (n + g - 1) / g; q++) {
      for (int p = 0; p <= (n + b - 1) / b; p++) {
        if (i * r + q * g + p * 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 i = 0; i <= 3000; i++) {
    for (int q = 0; q <= 3000; q++) {
      int as = n - r * i - q * g;
      if (as >= 0 && as % b == 0) {
        ans++;
      }
    }
  }
  cout << ans << endl;
}
Problem p03048 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <stdio.h>
int main() {
  int i, j, k;
  int r, g, b, n;
  int xp, cnt = 0;
  scanf("%d%d%d%d", &r, &g, &b, &n);
  for (i = 0; i <= n; i++) {
    for (j = 0; j <= n; j++) {
      for (k = 0; k <= n; k++) {
        xp = (i * r) + (j * g) + (k * b);
        if (n == xp)
          cnt++;
      }
    }
  }
  printf("%d\n", cnt);
  return 0;
}


Fixed submission:
#include <stdio.h>
int main() {
  int i, j, k;
  int r, g, b, n;
  int xp, cnt = 0;
  scanf("%d%d%d%d", &r, &g, &b, &n);
  for (i = 0; i <= 3000; i++) {
    for (j = 0; j <= 3000; j++) {
      if ((n - (i * r) - (j * g)) >= 0 && (n - (i * r) - (j * g)) % b == 0) {
        cnt++;
      }
    }
  }
  printf("%d\n", cnt);
  return 0;
}
Problem p03048 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <bitset>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef pair<long long, long long> P;
typedef long long int64;
typedef long long lint;
#define REP(i, n) for (long long(i) = 0; (i) < (n); ++i)
#define FOR(i, a, b) for (long long(i) = (a); (i) < (b); ++i)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define FST first
#define SND second

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

Fixed submission:
#include <algorithm>
#include <bitset>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef pair<long long, long long> P;
typedef long long int64;
typedef long long lint;
#define REP(i, n) for (long long(i) = 0; (i) < (n); ++i)
#define FOR(i, a, b) for (long long(i) = (a); (i) < (b); ++i)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define FST first
#define SND second

signed main() {
  int r, g, b, n;
  cin >> r >> g >> b >> n;
  int res = 0;
  REP(i, n / r + 1) {
    REP(j, n / g + 1) {
      int tmp = i * r + j * g;
      if (tmp > n)
        break;
      if ((n - tmp) % b == 0)
        res++;
    }
  }
  cout << res << 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 P = N / R + 1;
  int Q = N / G + 1;
  int S = N / B + 1;
  int Ans = 0;
  for (int r = 0; r <= P; r++) {
    for (int g = 0; g <= Q; g++) {
      if (r * R + g * G > N) {
        break;
      }
      for (int b = 0; b <= S; b++) {
        if (r * R + g * G + b * B == N) {
          Ans++;
        }
        if (r * R + g * G + b * B > N) {
          break;
        }
      }
    }
  }
  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 P = N / R + 1;
  int Q = N / G + 1;
  int S = N / B + 1;
  int Ans = 0;
  for (int r = 0; r <= P; r++) {
    for (int g = 0; g <= Q; g++) {
      if (r * R + g * G > N) {
        break;
      }
      if ((N - r * R - g * G) % B == 0) {
        Ans++;
      }
    }
  }
  cout << Ans << endl;
}
Problem p03048 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define MAX 100000
const long long INF = 1145141919, MOD = 1e9 + 7;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const double EPS = 1e-9; // 許容誤差。問題によって変える
// typedef complex<double> P;  // Point
// typedef vector<P> VP; //単純多角形
// #define X real()
// #define Y imag()
// #define LE(n,m) ((n) < (m) + EPS)
// #define GE(n,m) ((n) + EPS > (m))
// #define EQ(n,m) (abs((n)-(m)) < EPS)
// namespace std{
//     bool operator < (const P a, const P b){
//         return a.X != b.X ? a.X <b.X : a.Y < b.Y;
//     }
// }
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
// 外積cross(a,b) = |a||b|sinθ
// double cross(const P& a, const P& b) {
//  return imag(conj(a)*b);
//}
// 内積dot(a,b) = |a||b|cosθ
// double dot(const P& a, const P& b) {
// return real(conj(a)*b);
//}
// Line
// struct L : public vector<P> {
// L(const P &a, const P &b) {
// push_back(a); push_back(b);
//}
//};
// 円
// struct C{
//  P p; double r;
//  C(const P &p, double r) : p(p), r(r) { }
//};
int main() {
  int r, g, b, n;
  cin >> r >> g >> b >> n;
  int count = 0;
  for (int i = 0; i <= n / r; i++) {
    int m = n - i * r;
    for (int j = 0; j <= m / g; j++) {
      int s = m - j * g;
      for (int l = 0; l <= s / b; l++) {
        if (l * b == s)
          count++;
      }
    }
  }
  cout << count << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define MAX 100000
const long long INF = 1145141919, MOD = 1e9 + 7;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const double EPS = 1e-9; // 許容誤差。問題によって変える
// typedef complex<double> P;  // Point
// typedef vector<P> VP; //単純多角形
// #define X real()
// #define Y imag()
// #define LE(n,m) ((n) < (m) + EPS)
// #define GE(n,m) ((n) + EPS > (m))
// #define EQ(n,m) (abs((n)-(m)) < EPS)
// namespace std{
//     bool operator < (const P a, const P b){
//         return a.X != b.X ? a.X <b.X : a.Y < b.Y;
//     }
// }
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
// 外積cross(a,b) = |a||b|sinθ
// double cross(const P& a, const P& b) {
//  return imag(conj(a)*b);
//}
// 内積dot(a,b) = |a||b|cosθ
// double dot(const P& a, const P& b) {
// return real(conj(a)*b);
//}
// Line
// struct L : public vector<P> {
// L(const P &a, const P &b) {
// push_back(a); push_back(b);
//}
//};
// 円
// struct C{
//  P p; double r;
//  C(const P &p, double r) : p(p), r(r) { }
//};
int main() {
  int r, g, b, n;
  cin >> r >> g >> b >> n;
  int count = 0;
  for (int i = 0; i <= n / r; i++) {
    int m = n - i * r;
    for (int j = 0; j <= m / g; j++) {
      int s = m - j * g;
      if (s % b == 0)
        count++;
    }
  }
  cout << count << endl;
  return 0;
}
Problem p03048 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <bitset>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <utility>
#include <vector>
#define ll long long
using namespace std;
using p = pair<ll, ll>;
ll dx[4] = {-1, 0, 1, 0};
ll dy[4] = {0, 1, 0, -1};

int main(void) {
  ll a, b, c, n;
  cin >> a >> b >> c >> n;
  ll ans = 0;
  for (ll i = 0; i <= 4000; i++) {
    for (ll j = 0; j <= 4000; j++) {
      for (ll k = 0; k <= 4000; k++) {
        if (a * i + b * j + c * k == n)
          ans++;
        if (a * i + b * j + c * k > n)
          break;
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <bitset>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <utility>
#include <vector>
#define ll long long
using namespace std;
using p = pair<ll, ll>;
ll dx[4] = {-1, 0, 1, 0};
ll dy[4] = {0, 1, 0, -1};

int main(void) {
  ll a, b, c, n;
  cin >> a >> b >> c >> n;
  ll ans = 0;
  for (ll i = 0; i <= n / a; i++) {
    for (ll j = 0; j <= n / b; j++) {
      if ((n - a * i - b * j) % c == 0 && n - a * i - b * j >= 0) {
        // cout << i << " " << j << " " << n-a*i-b*j << endl;
        ans++;
      }
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p03048 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iostream>

#define long long long

using namespace std;

int main() {

  int r, g, b, N;

  cin >> r >> g >> b >> N;

  int maxv = max(max(r, g), b);

  int minc = N / maxv;

  int count = 0;

  for (int i = 0; i <= N; i++) {
    for (int j = 0; j <= N; j++) {
      for (int k = 0; k <= N; k++) {
        if (i + j + k >= minc) {
          if (i * r + j * g + k * b > N) {
            break;
          } else if (i * r + j * g + k * b == N)
            count++;
        }
      }
    }
  }

  cout << count << endl;

  return 0;
}

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

#define long long long

using namespace std;

int main() {

  int r, g, b, N;

  cin >> r >> g >> b >> N;

  int maxv = max(max(r, g), b);

  int minc = N / maxv;

  int count = 0;

  for (int i = 0; i <= N; i++) {
    for (int j = 0; j <= N; j++) {
      if (N >= i * r + j * g && (N - i * r - j * g) % b == 0)
        count++;
    }
  }

  cout << count << endl;

  return 0;
}
Problem p03048 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <bits/stdc++.h>
#include <cmath>
#include <iostream>
#include <queue>
#include <sstream>
#include <stdexcept>
#include <stdio.h>
#include <string>
#include <vector>
#define cinf(n, x)                                                             \
  for (int i = 0; i < n; i++)                                                  \
    cin >> x[i];
#define pi pair<int, int>
using namespace std;
using ll = long long;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int R, G, B, n;
  int ans = 0;
  cin >> R >> G >> B >> n;
  for (int r = 0; r <= n / R; r++) {
    for (int g = 0; g <= n / G; g++) {
      if (r * R + g * G > n)
        break;
      for (int b = 0; b <= n / B; b++) {
        if (r * R + g * G + b * B > n)
          break;
        else if (r * R + g * G + B * b == n)
          ans++;
      }
    }
  }
  cout << ans << endl;
}

Fixed submission:
#include <algorithm>
#include <bits/stdc++.h>
#include <cmath>
#include <iostream>
#include <queue>
#include <sstream>
#include <stdexcept>
#include <stdio.h>
#include <string>
#include <vector>
#define cinf(n, x)                                                             \
  for (int i = 0; i < n; i++)                                                  \
    cin >> x[i];
#define pi pair<int, int>
using namespace std;
using ll = long long;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int R, G, B, n;
  int ans = 0;
  cin >> R >> G >> B >> n;
  for (int r = 0; r <= n / R; r++) {
    for (int g = 0; g <= n / G; g++) {
      if (n >= g * G + r * R) {
        int x = n - G * g - r * R;
        if (x % B == 0)
          ans++;
      }
    }
  }
  cout << ans << endl;
}
Problem p03048 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>

using namespace std;

int main(void) {
  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;
  return 0;
}

Fixed submission:
#include <iostream>

using namespace std;

int main(void) {
  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 b = N - r - g;
      if (b >= 0 && b % 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() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int R, G, B, N;

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

  int ball[3] = {R, G, B};
  sort(ball, ball + 3);

  int answer = 0;

  for (int i = 0; N >= ball[2] * i; i++) {
    for (int j = 0; N >= ball[2] * i + ball[1] * j; j++) {
      for (int k = 0; N >= ball[2] * i + ball[1] * j + ball[0] * k; k++) {
        if (N == ball[2] * i + ball[1] * j + ball[0] * k) {
          answer++;
        }
      }
    }
  }

  cout << answer << "\n";

  return 0;
}


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 ball[3] = {R, G, B};
  sort(ball, ball + 3);

  int answer = 0;

  for (int i = 0; N >= ball[2] * i; i++) {
    for (int j = 0; N >= ball[2] * i + ball[1] * j; j++) {
      if ((N - ball[2] * i - ball[1] * j) % ball[0] == 0) {
        answer++;
      }
    }
  }

  cout << answer << "\n";

  return 0;
}