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

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define RI register int
typedef long long LL;

int fa[100005], vis[100005];
int Find(int x) { return x == fa[x] ? x : Find(fa[x]); }

int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  for (RI i = 1; i <= n; ++i)
    fa[i] = i;
  for (RI i = 1, x, y, z; i <= m; ++i)
    scanf("%d %d %d", &x, &y, &z), fa[Find(x)] = Find(y);
  int ans = 0;
  for (RI i = 1; i <= n; ++i)
    if (!vis[Find(i)])
      ++ans, vis[Find(i)] = 1;
  printf("%d\n", ans);
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define RI register int
typedef long long LL;

int fa[100005], vis[100005];
int Find(int x) { return x == fa[x] ? x : fa[x] = Find(fa[x]); }

int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  for (RI i = 1; i <= n; ++i)
    fa[i] = i;
  for (RI i = 1, x, y, z; i <= m; ++i)
    scanf("%d %d %d", &x, &y, &z), fa[Find(x)] = Find(y);
  int ans = 0;
  for (RI i = 1; i <= n; ++i)
    if (!vis[Find(i)])
      ++ans, vis[Find(i)] = 1;
  printf("%d\n", ans);
  return 0;
}
Problem p03045 (C++)

Buggy submission (status: Runtime Error):
#include <cstdlib>
#include <iostream>
#include <queue>
#include <stdio.h>
#include <vector>

typedef struct _xyz {
  int x;
  int y;
  int z;
} xyz;

typedef struct _node {
  std::vector<int> nbr; // zero-based numbering (node_arr[nbr]
} node;

int main(void) {
  int n, m;
  scanf("%d%d", &n, &m);
  xyz *xyz_arr = (xyz *)std::malloc(sizeof(xyz) * m);
  for (int i = 0; i < m; ++i) {
    scanf("%d%d%d", &xyz_arr[i].x, &xyz_arr[i].y, &xyz_arr[i].z);
  }

  node *node_arr = (node *)std::malloc(sizeof(node) * n);
  for (int i = 0; i < m; i++) {
    node_arr[xyz_arr[i].x - 1].nbr.push_back(xyz_arr[i].y - 1);
    node_arr[xyz_arr[i].y - 1].nbr.push_back(xyz_arr[i].x - 1);
  }

  int count;
  std::vector<bool> memo(n);
  count = 0;
  for (int i = 0; i < m; ++i) {
    if (!memo[i]) {
      /*
       * BFS
       */
      memo[i] = true;
      std::queue<int> q; // zero-based numbering
      q.push(i);
      while (!q.empty()) {
        int j = q.front();
        q.pop();
        for (auto itr = node_arr[j].nbr.begin(); itr != node_arr[j].nbr.end();
             ++itr) {
          if (!memo[*itr]) {
            memo[*itr] = true;
            q.push(*itr);
          } else {
            continue;
          }
        }
      }
      count++;
    } else if (node_arr[i].nbr.empty()) {
      count++;
    } else {
      continue;
    }
  }

  std::cout << count << std::endl;

  return EXIT_SUCCESS;
}

Fixed submission:
#include <cstdlib>
#include <iostream>
#include <queue>
#include <stdio.h>
#include <vector>

typedef struct _xyz {
  int x;
  int y;
  int z;
} xyz;

typedef struct _node {
  std::vector<int> nbr; // zero-based numbering (node_arr[nbr]
} node;

int main(void) {
  int n, m;
  scanf("%d%d", &n, &m);
  xyz *xyz_arr = (xyz *)std::malloc(sizeof(xyz) * m);
  for (int i = 0; i < m; ++i) {
    scanf("%d%d%d", &xyz_arr[i].x, &xyz_arr[i].y, &xyz_arr[i].z);
  }

  node *node_arr = (node *)std::malloc(sizeof(node) * n);
  for (int i = 0; i < m; i++) {
    node_arr[xyz_arr[i].x - 1].nbr.push_back(xyz_arr[i].y - 1);
    node_arr[xyz_arr[i].y - 1].nbr.push_back(xyz_arr[i].x - 1);
  }

  int count;
  std::vector<bool> memo(n);
  count = 0;
  for (int i = 0; i < n; ++i) {
    if (!memo[i]) {
      /*
       * BFS
       */
      memo[i] = true;
      std::queue<int> q; // zero-based numbering
      q.push(i);
      while (!q.empty()) {
        int j = q.front();
        q.pop();
        for (auto itr = node_arr[j].nbr.begin(); itr != node_arr[j].nbr.end();
             ++itr) {
          if (!memo[*itr]) {
            memo[*itr] = true;
            q.push(*itr);
          } else {
            continue;
          }
        }
      }
      count++;
    } else if (node_arr[i].nbr.empty()) {
      count++;
    } else {
      continue;
    }
  }

  std::cout << count << std::endl;

  return EXIT_SUCCESS;
}
Problem p03045 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
template <class T> inline bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
typedef long long ll;

vector<int> par;
vector<int> rnk;

// N個要素に対して、N個のノードを用意して初期化
void init(int N) {
  par.resize(N, 0);
  rnk.resize(N, 0);
  REP(i, N) {
    par[i] = i; // 最初は自分自身が親
    rnk[i] = 0;
  }
}

// 木の根（親）を求める
int find(int X) {
  if (par[X] == X) {
    return X;
  } else {
    return par[X] = find(par[X]);
  }
}

// XとYの属する集合を併合
void unite(int X, int Y) {
  X = find(X);
  Y = find(Y);
  if (X == Y)
    return;
  if (rnk[X] < rnk[Y]) {
    par[X] = Y;
  } else {
    par[Y] = X;
    if (rnk[X] == rnk[Y])
      rnk[X]++;
  }
}

// XとYが同じ集合に属するか否か
bool same(int X, int Y) { return find(X) == find(Y); }

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, M;
  cin >> N >> M;
  init(N);
  REP(i, M) {
    int x, y, z;
    cin >> x >> y >> z;
    unite(x, y);
  }
  REP(i, N) { find(i); }
  set<int> cnt;
  REP(i, N) { cnt.insert(par[i]); }
  int ans = cnt.size();
  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
template <class T> inline bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
typedef long long ll;

vector<int> par;
vector<int> rnk;

// N個要素に対して、N個のノードを用意して初期化
void init(int N) {
  par.resize(N, 0);
  rnk.resize(N, 0);
  REP(i, N) {
    par[i] = i; // 最初は自分自身が親
    rnk[i] = 0;
  }
}

// 木の根（親）を求める
int find(int X) {
  if (par[X] == X) {
    return X;
  } else {
    return par[X] = find(par[X]);
  }
}

// XとYの属する集合を併合
void unite(int X, int Y) {
  X = find(X);
  Y = find(Y);
  if (X == Y)
    return;
  if (rnk[X] < rnk[Y]) {
    par[X] = Y;
  } else {
    par[Y] = X;
    if (rnk[X] == rnk[Y])
      rnk[X]++;
  }
}

// XとYが同じ集合に属するか否か
bool same(int X, int Y) { return find(X) == find(Y); }

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, M;
  cin >> N >> M;
  init(N);
  REP(i, M) {
    int x, y, z;
    cin >> x >> y >> z;
    x--;
    y--;
    unite(x, y);
  }
  REP(i, N) { find(i); }
  set<int> cnt;
  REP(i, N) { cnt.insert(par[i]); }
  int ans = cnt.size();
  cout << ans << endl;
}
Problem p03045 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
const int INF = 1 << 30;
const ll MOD = 1e9 + 7;
const double EPS = 1e-9;

struct UnionFind {
  vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

  UnionFind(int N) : par(N) { // 最初は全てが根であるとして初期化
    for (int i = 0; i < N; i++)
      par[i] = i;
  }

  int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
    if (par[x] == x)
      return x;
    return par[x] = root(par[x]);
  }

  void unite(int x, int y) { // xとyの木を併合
    int rx = root(x);        // xの根をrx
    int ry = root(y);        // yの根をry
    if (rx == ry)
      return; // xとyの根が同じ(=同じ木にある)時はそのまま
    par[rx] =
        ry; // xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
  }

  bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
    int rx = root(x);
    int ry = root(y);
    return rx == ry;
  }
};

int main(int argc, const char *argv[]) {
  int N, M;
  cin >> N >> M;
  vector<int> X(M), Y(M);
  for (int i = 0; i < M; i++) {
    int Z;
    cin >> X[i] >> Y[i] >> Z;
  }

  UnionFind tree(N);
  for (int i = 0; i < M; i++) {
    tree.unite(X[i] - 1, Y[i] - 1);
  }

  set<int> parent;
  for (int i = 0; i <= N; i++) {
    parent.insert(tree.root(i));
  }

  cout << parent.size() << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
const int INF = 1 << 30;
const ll MOD = 1e9 + 7;
const double EPS = 1e-9;

struct UnionFind {
  vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

  UnionFind(int N) : par(N) { // 最初は全てが根であるとして初期化
    for (int i = 0; i < N; i++)
      par[i] = i;
  }

  int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
    if (par[x] == x)
      return x;
    return par[x] = root(par[x]);
  }

  void unite(int x, int y) { // xとyの木を併合
    int rx = root(x);        // xの根をrx
    int ry = root(y);        // yの根をry
    if (rx == ry)
      return; // xとyの根が同じ(=同じ木にある)時はそのまま
    par[rx] =
        ry; // xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
  }

  bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
    int rx = root(x);
    int ry = root(y);
    return rx == ry;
  }
};

int main(int argc, const char *argv[]) {
  int N, M;
  cin >> N >> M;
  vector<int> X(M), Y(M);
  for (int i = 0; i < M; i++) {
    int Z;
    cin >> X[i] >> Y[i] >> Z;
  }

  UnionFind tree(N);
  for (int i = 0; i < M; i++) {
    tree.unite(X[i] - 1, Y[i] - 1);
  }

  set<int> parent;
  for (int i = 0; i < N; i++) {
    parent.insert(tree.root(i));
  }

  cout << parent.size() << endl;
  return 0;
}
Problem p03045 (C++)

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

bool isEven(int x) {
  if (x % 2 == 0)
    return true;
  else
    return false;
}

class UnionFind {
public:
  vector<int> parent;

  UnionFind(int n) : parent(n) {
    for (int i = 0; i < n; i++) {
      parent[i] = i;
    }
  }

  int root(int x) {
    if (parent[x] == x)
      return x;
    return parent[x] = root(parent[x]);
  }

  void unite(int x, int y) {
    int rx = root(x);
    int ry = root(y);
    if (rx == ry)
      return;
    parent[rx] = ry;
  }

  bool same(int x, int y) {
    int rx = root(x);
    int ry = root(y);
    return rx == ry;
  }
};

int main() {
  int n, m;
  cin >> n >> m;
  int x[n];
  int y[n];
  int z[n];

  UnionFind card(n);
  int ans = n;

  for (int i = 0; i < m; i++) {
    cin >> x[i] >> y[i] >> z[i];
    if (!card.same(x[i] - 1, y[i] - 1)) {
      ans--;
    }
    card.unite(x[i] - 1, y[i] - 1);

    /*for(int i = 0; i < n; i++){
            cout << card.root(i) << " ";
    }
    cout << endl;*/
  }

  cout << ans << endl;

  return 0;
}

/*
class node {
        int number;
        int parent;

        node(int num) {
                this.number = num;
                this.parent = this;
        }

        void setNumber(int num) {
                this.number = num;
        }

        void setParent(int par) {
                this.parent =
        }

        int getParent() {
                return this.parent;
        }
};*/


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

bool isEven(int x) {
  if (x % 2 == 0)
    return true;
  else
    return false;
}

class UnionFind {
public:
  vector<int> parent;

  UnionFind(int n) : parent(n) {
    for (int i = 0; i < n; i++) {
      parent[i] = i;
    }
  }

  int root(int x) {
    if (parent[x] == x)
      return x;
    return parent[x] = root(parent[x]);
  }

  void unite(int x, int y) {
    int rx = root(x);
    int ry = root(y);
    if (rx == ry)
      return;
    parent[rx] = ry;
  }

  bool same(int x, int y) {
    int rx = root(x);
    int ry = root(y);
    return rx == ry;
  }
};

int main() {
  int n, m;
  cin >> n >> m;
  int x[m];
  int y[m];
  int z[m];

  UnionFind card(n);
  int ans = n;

  for (int i = 0; i < m; i++) {
    cin >> x[i] >> y[i] >> z[i];
    if (!card.same(x[i] - 1, y[i] - 1)) {
      ans--;
    }
    card.unite(x[i] - 1, y[i] - 1);

    /*for(int i = 0; i < n; i++){
            cout << card.root(i) << " ";
    }
    cout << endl;*/
  }

  cout << ans << endl;

  return 0;
}

/*
class node {
        int number;
        int parent;

        node(int num) {
                this.number = num;
                this.parent = this;
        }

        void setNumber(int num) {
                this.number = num;
        }

        void setParent(int par) {
                this.parent =
        }

        int getParent() {
                return this.parent;
        }
};*/
Problem p03045 (C++)

Buggy submission (status: Runtime Error):
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep1(i, n) for (int i = 1; i <= n; i++)
#define rep2(i, n) for (int i = 0; i <= n; i++)
#define repr(i, a, n) for (int i = a; i < n; i++)
#define all(a) a.begin(), a.end()
#define P pair<long long, long long>
#define do long double
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;
}
int INF = 1e10;
int MOD = 1e9 + 7;
struct Union {
  vector<int> par;
  Union(int n) { par = vector<int>(n, -1); }
  int find(int x) {
    if (par[x] < 0)
      return x;
    else
      return par[x] = find(par[x]);
  }
  bool same(int a, int b) { return find(a) == find(b); }
  int Size(int a) { return -par[find(a)]; }
  void unite(int a, int b) {
    a = find(a);
    b = find(b);
    if (a == b)
      return;
    if (Size(b) > Size(a))
      swap<int>(a, b);
    par[a] += par[b];
    par[b] = a;
  }
};
signed main() {
  int a, b;
  cin >> a >> b;
  int c[b][3];
  rep(i, b) rep(j, 3) cin >> c[i][j];
  Union d(a);
  rep(i, b) { d.unite(c[i][0] - 1, c[i][1] - 1); }
  vector<int> e(a);
  rep(i, b) { e[i] = d.find(i); }
  sort(all(e));
  e.erase(unique(all(e)), e.end());
  cout << e.size() << endl;
}


Fixed submission:
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep1(i, n) for (int i = 1; i <= n; i++)
#define rep2(i, n) for (int i = 0; i <= n; i++)
#define repr(i, a, n) for (int i = a; i < n; i++)
#define all(a) a.begin(), a.end()
#define P pair<long long, long long>
#define do long double
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;
}
int INF = 1e10;
int MOD = 1e9 + 7;
struct Union {
  vector<int> par;
  Union(int n) { par = vector<int>(n, -1); }
  int find(int x) {
    if (par[x] < 0)
      return x;
    else
      return par[x] = find(par[x]);
  }
  bool same(int a, int b) { return find(a) == find(b); }
  int Size(int a) { return -par[find(a)]; }
  void unite(int a, int b) {
    a = find(a);
    b = find(b);
    if (a == b)
      return;
    if (Size(b) > Size(a))
      swap<int>(a, b);
    par[a] += par[b];
    par[b] = a;
  }
};
signed main() {
  int a, b;
  cin >> a >> b;
  int c[b][3];
  rep(i, b) rep(j, 3) cin >> c[i][j];
  Union d(a);
  rep(i, b) { d.unite(c[i][0] - 1, c[i][1] - 1); }
  vector<int> e(a);
  rep(i, a) { e[i] = d.find(i); }
  sort(all(e));
  e.erase(unique(all(e)), e.end());
  cout << e.size() << endl;
}
Problem p03045 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
const ll MOD = 1000000007;
#define rep(i, a, b) for (ll i = a; i < b; i++)
#define range(i) (i).begin(), (i).end()
#define rrange(i) (i).rbegin(), (i).rend()
inline ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
inline constexpr int intpow(ll a, ll b) {
  if (b == 0)
    return 1;
  ll ans = intpow(a, b / 2);
  return ans * ans * (b & 1 ? a : 1);
}
inline constexpr int modpow(ll a, ll b) {
  if (b == 0)
    return 1;
  ll ans = intpow(a, b / 2);
  return ans * ans % MOD * (b & 1 ? a : 1) % MOD;
}
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;
}
const ll LINF = 0x1fffffffffffffff;

struct unionfind {
  vector<ll> d;
  unionfind(ll x) : d(x, -1) {}
  ll root(ll x) { return d[x] < 0 ? x : d[x] = root(d[x]); }
  ll size(ll x) { return -d[root(x)]; };
  bool unite(ll x, ll y) {
    x = root(x), y = root(y);
    if (x != y) {
      if (d[x] > d[y])
        swap(x, y);
      d[x] += d[y];
      d[y] = x;
    }
    return x != y;
  }
  bool find(ll x, ll y) { return root(x) == root(y); }
};
int main() {
  ll n, m;
  cin >> n >> m;
  unionfind uf(n);
  ll ans = n;
  rep(i, 0, m) {
    ll x, y, z;
    cin >> x, y, z;
    ans -= uf.unite(x - 1, y - 1);
  }
  cout << ans;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
const ll MOD = 1000000007;
#define rep(i, a, b) for (ll i = a; i < b; i++)
#define range(i) (i).begin(), (i).end()
#define rrange(i) (i).rbegin(), (i).rend()
inline ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
inline constexpr int intpow(ll a, ll b) {
  if (b == 0)
    return 1;
  ll ans = intpow(a, b / 2);
  return ans * ans * (b & 1 ? a : 1);
}
inline constexpr int modpow(ll a, ll b) {
  if (b == 0)
    return 1;
  ll ans = intpow(a, b / 2);
  return ans * ans % MOD * (b & 1 ? a : 1) % MOD;
}
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;
}
const ll LINF = 0x1fffffffffffffff;

struct unionfind {
  vector<ll> d;
  unionfind(ll x) : d(x, -1) {}
  ll root(ll x) { return d[x] < 0 ? x : d[x] = root(d[x]); }
  ll size(ll x) { return -d[root(x)]; };
  bool unite(ll x, ll y) {
    x = root(x), y = root(y);
    if (x != y) {
      if (d[x] > d[y])
        swap(x, y);
      d[x] += d[y];
      d[y] = x;
    }
    return x != y;
  }
  bool find(ll x, ll y) { return root(x) == root(y); }
};
int main() {
  ll n, m;
  cin >> n >> m;
  unionfind uf(n);
  ll ans = n;
  rep(i, 0, m) {
    ll x, y, z;
    cin >> x >> y >> z;
    ans -= uf.unite(x - 1, y - 1);
  }
  cout << ans;
}
Problem p03045 (C++)

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

using namespace std;

class unionFind {
  int nodeSize;
  vector<int> parent;

public:
  unionFind(int n) : nodeSize(n) { parent = vector<int>(n + 1, -1); }

  int getRoot(int a) {
    if (parent[a] < 0) {
      return a;
    }
    return parent[a] = getRoot(parent[a]);
  }

  bool isSameParent(int a, int b) { return getRoot(a) == getRoot(b); }

  bool isRoot(int a) {
    if (parent[a] < 0) {
      return true;
    }
    return false;
  }

  void unite(int a, int b) {
    if (isSameParent(a, b)) {
      return;
    }
    int aParent = getRoot(a);
    int bParent = getRoot(b);

    if (abs(parent[aParent]) > abs(parent[bParent])) {
      parent[aParent] += parent[bParent];
      parent[bParent] = aParent;
    } else {
      parent[bParent] += parent[bParent];
      parent[aParent] = bParent;
    }
  }
};

int main() {
  int n, m;
  cin >> n >> m;

  vector<int> x(m), y(m), z(m);
  for (int i = 0; i < m; i++) {
    cin >> x[i] >> y[i] >> z[i];
  }

  unionFind uf(n);

  for (int i = 0; i < m; i++) {
    uf.unite(x[i], y[i]);
  }

  int ans = 0;
  for (int i = 1; i <= n; i++) {
    if (uf.isRoot(i)) {
      ans++;
    }
  }

  cout << ans << endl;

  return 0;
}

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

using namespace std;

class unionFind {
  int nodeSize;
  vector<int> parent;

public:
  unionFind(int n) : nodeSize(n) { parent = vector<int>(n + 1, -1); }

  int getRoot(int a) {
    if (parent[a] < 0) {
      return a;
    }
    return parent[a] = getRoot(parent[a]);
  }

  bool isSameParent(int a, int b) { return getRoot(a) == getRoot(b); }

  bool isRoot(int a) {
    if (parent[a] < 0) {
      return true;
    }
    return false;
  }

  void unite(int a, int b) {
    if (isSameParent(a, b)) {
      return;
    }
    int aParent = getRoot(a);
    int bParent = getRoot(b);

    if (abs(parent[aParent]) > abs(parent[bParent])) {
      parent[aParent] += parent[bParent];
      parent[bParent] = aParent;
    } else {
      parent[bParent] += parent[aParent];
      parent[aParent] = bParent;
    }
  }
};

int main() {
  int n, m;
  cin >> n >> m;

  vector<int> x(m), y(m), z(m);
  for (int i = 0; i < m; i++) {
    cin >> x[i] >> y[i] >> z[i];
  }

  unionFind uf(n);

  for (int i = 0; i < m; i++) {
    uf.unite(x[i], y[i]);
  }

  int ans = 0;
  for (int i = 1; i <= n; i++) {
    if (uf.isRoot(i)) {
      ans++;
    }
  }

  cout << ans << endl;

  return 0;
}
Problem p03045 (C++)

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

#define rep(i, n) for (int i = 0; i < (n); i++)
#define repp(i, l, r) for (int i = (l); i < (r); i++)
#define per(i, n) for (int i = ((n)-1); i >= 0; i--)
#define perr(i, l, r) for (int i = ((r)-1); i >= (l); i--)
#define all(x) (x).begin(), (x).end()
#define MOD 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000
#define SP << " " <<
#define CYES cout << "Yes" << endl
#define CNO cout << "No" << endl

typedef long long LL;
typedef long double LD;

class UnionFind {
private:
  vector<int> node;

public:
  UnionFind(int n) {
    node = vector<int>(n);
    rep(i, n) node[i] = i;
  }
  int root(int x) {
    if (node[x] == x)
      return x;
    else
      node[x] = root(node[x]);
  }
  bool uni(int x, int y) {
    x = root(x);
    y = root(y);
    if (x == y)
      return false;
    node[y] = x;
    return true;
  }
};

int main() {
  int n, m;
  cin >> n >> m;
  UnionFind uf(n);
  int x, y, z;
  int ans = n;
  rep(i, m) {
    cin >> x >> y >> z;
    if (uf.uni(x - 1, y - 1))
      ans--;
  }
  cout << ans << endl;
  return 0;
}


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

#define rep(i, n) for (int i = 0; i < (n); i++)
#define repp(i, l, r) for (int i = (l); i < (r); i++)
#define per(i, n) for (int i = ((n)-1); i >= 0; i--)
#define perr(i, l, r) for (int i = ((r)-1); i >= (l); i--)
#define all(x) (x).begin(), (x).end()
#define MOD 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000
#define SP << " " <<
#define CYES cout << "Yes" << endl
#define CNO cout << "No" << endl

typedef long long LL;
typedef long double LD;

class UnionFind {
private:
  vector<int> node;

public:
  UnionFind(int n) {
    node = vector<int>(n);
    rep(i, n) node[i] = i;
  }
  int root(int x) {
    if (node[x] == x)
      return x;
    else
      return node[x] = root(node[x]);
  }
  bool uni(int x, int y) {
    x = root(x);
    y = root(y);
    if (x == y)
      return false;
    node[y] = x;
    return true;
  }
};

int main() {
  int n, m;
  cin >> n >> m;
  UnionFind uf(n);
  int x, y, z;
  int ans = n;
  rep(i, m) {
    cin >> x >> y >> z;
    if (uf.uni(x - 1, y - 1))
      ans--;
  }
  cout << ans << endl;
  return 0;
}
Problem p03047 (Python)

Buggy submission (status: Runtime Error):
N, K = map(int, input())

print(N - K + 1)


Fixed submission:
N, K = map(int, input().split())

print(N - K + 1)
Problem p03047 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int, int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define eps 1e-10
#define MAXN 1005
#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template <class T> void read(T &res) {
  res = 0;
  T f = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-')
      f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    res = res * 10 + c - '0';
    c = getchar();
  }
  res *= f;
}
template <class T> void out(T x) {
  if (x < 0) {
    x = -x;
    putchar('-');
  }
  if (x >= 10) {
    out(x / 10);
  }
  putchar('0' + x % 10);
}
int N, K;
void Solve() {
  read(N);
  read(K);
  out(N - K + 1);
  enter;
}
int main() {
#ifdef ivorysi
  freopen("f1.in", "r", stdin);
#endif
  Solve();
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int, int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define eps 1e-10
#define MAXN 1005
// #define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template <class T> void read(T &res) {
  res = 0;
  T f = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-')
      f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    res = res * 10 + c - '0';
    c = getchar();
  }
  res *= f;
}
template <class T> void out(T x) {
  if (x < 0) {
    x = -x;
    putchar('-');
  }
  if (x >= 10) {
    out(x / 10);
  }
  putchar('0' + x % 10);
}
int N, K;
void Solve() {
  read(N);
  read(K);
  out(N - K + 1);
  enter;
}
int main() {
#ifdef ivorysi
  freopen("f1.in", "r", stdin);
#endif
  Solve();
  return 0;
}
Problem p03047 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
using namespace std;

int main() {
  int x, y, z, n;
  int count = 0;
  cin >> x >> y >> z >> n;
  int x_c = 0;
  int y_c = 0;
  while (true) {
    y_c = 0;
    if (n - x_c * x < 0)
      break;
    while (true) {
      if (n - x_c * x - y_c * y < 0)
        break;
      if ((n - x_c * x - y_c * y) % z == 0)
        count++;
      y_c++;
    }
    x_c++;
  }
  cout << count << endl;
  return 0;
}


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

int main() {
  int x, y;
  cin >> x >> y;
  cout << x - y + 1 << endl;
  return 0;
}
Problem p03047 (C++)

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

int main() {
  int n, k;
  cin >> n >> k;
  int mother = 1, child = 1;
  for (int i = n; i >= n - k + 1; i--) {
    child *= i;
  }
  for (int i = 1; i <= k; i++) {
    mother *= i;
  }

  cout << child / mother << endl;
}

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

int main() {
  int n, k;
  cin >> n >> k;
  cout << n - k + 1 << endl;
}
Problem p03047 (C++)

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

using namespace std;

int main() {
  int N, K;
  cin >> N >> K;

  int a = 1;
  int b = 1;

  for (int i = 0; i < K; i++) {
    a *= N - i;
  }

  for (int j = 0; j < K; j++) {
    b *= K - j;
  }

  int ans = a / b;

  cout << ans << endl;

  return 0;
}


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

using namespace std;

int main() {
  int N, K;
  cin >> N >> K;

  int ans = N - K + 1;

  cout << ans << endl;

  return 0;
}
Problem p03047 (C++)

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

using namespace std;

int main() {

  int N = 0, K = 0;

  cin >> N >> K;

  int P = 1, R = 1;

  for (int i = 0; i < N; ++i) {
    P = (N - i) * P;
    R = (K - i) * R;
  }

  int ans = P / R;

  cout << ans << endl;

  return 0;
}

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

using namespace std;

int main() {

  int N = 0, K = 0;

  cin >> N >> K;

  int P = 1, R = 1;

  int ans = N - K + 1;

  cout << ans << endl;

  return 0;
}
Problem p03047 (C++)

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

using namespace std;

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

  int N, K;
  cin >> N >> K;

  int pattern = 0;

  for (int l = 1; l <= N; l++) {
    if (l + (K - 1) <= N) {
      pattern++;
    }
  }

  cout << pattern << endl;

  return 1;
}


Fixed submission:
#include <iostream>

using namespace std;

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

  int N, K;
  cin >> N >> K;

  int pattern = 0;

  for (int l = 1; l <= N; l++) {
    if (l + (K - 1) <= N) {
      pattern++;
    }
  }

  cout << pattern << endl;

  return 0;
}
Problem p03047 (C++)

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

using namespace std;

#define int long long int
#define ld long double
#define F first
#define S second
#define P pair<int, int>
#define V vector
#define pb push_back
#define db(...) __f(#__VA_ARGS__, __VA_ARGS__)

template <typename Arg1> void __f(const char *name, Arg1 &&arg1) {
  cerr << name << " : " << arg1 << '\n';
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&...args) {
  const char *comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}

const int N = 100005;

int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  freopen("debug.txt", "w", stderr);
#endif
  // int t;cin>>t;while(t--)
  {
    int i, j, k, n, m, ans = 0, cnt = 0, sum = 0;
    cin >> n >> k;
    cout << n - k + 1;
  }
}

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

using namespace std;

#define int long long int
#define ld long double
#define F first
#define S second
#define P pair<int, int>
#define V vector
#define pb push_back
#define db(...) __f(#__VA_ARGS__, __VA_ARGS__)

template <typename Arg1> void __f(const char *name, Arg1 &&arg1) {
  cerr << name << " : " << arg1 << '\n';
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&...args) {
  const char *comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}

const int N = 100005;

int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  // int t;cin>>t;while(t--)
  {
    int i, j, k, n, m, ans = 0, cnt = 0, sum = 0;
    cin >> n >> k;
    cout << n - k + 1;
  }
}
Problem p03047 (Python)

Buggy submission (status: Runtime Error):
N, K = map(int, input())
print(N - (K - 1))


Fixed submission:
N, K = map(int, input().split())
print(N - (K - 1))
Problem p03047 (C++)

Buggy submission (status: Runtime Error):
#include "stdio.h"
int main() {
  int K, N;
  scanf("%d %d", N, K);
  printf("%d", N - K + 1);

  return 0;
}

Fixed submission:
#include "stdio.h"
int main() {
  int K, N, a;
  scanf("%d %d", &N, &K);
  a = N - K + 1;
  printf("%d", a);

  return 0;
}
Problem p03048 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1000000007;

int main() {
  ll R, G, B, N;
  cin >> R >> G >> B >> N;
  ll ans = 0;
  ll r = N / R;
  for (ll i = r; i >= 0; i--) {
    ll n = N - i * R;
    if (n == 0) {
      ans++;
      continue;
    } else {
      ll g = n / G;
      for (ll j = g; j >= 0; j--) {
        ll m = n - j * G;
        if (m == 0) {
          ans++;
          continue;
        } else {
          ll b = m / B;
          for (ll k = b; k >= 0; k--) {
            ll o = m - k * B;
            if (o == 0) {
              ans++;
              continue;
            }
          }
        }
      }
    }
  }
  cout << ans << "\n";
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1000000007;

int main() {
  ll R, G, B, N;
  cin >> R >> G >> B >> N;
  ll ans = 0;
  ll r = N / R;
  for (ll i = r; i >= 0; i--) {
    ll n = N - i * R;
    if (n == 0) {
      ans++;
      continue;
    } else {
      ll g = n / G;
      for (ll j = g; j >= 0; j--) {
        ll m = n - j * G;
        if (m == 0) {
          ans++;
          continue;
        } else if (m % B == 0) {
          ans++;
        }
      }
    }
  }
  cout << ans << "\n";
  return 0;
}
Problem p03048 (C++)

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

int R, G, B, N;
string S;
vector<ll> vec(100000);

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

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

int R, G, B, N;
string S;
vector<ll> vec(100000);

int main() {
  int 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 && (N - (i * R + j * G)) % B == 0) {
        // cout<<i<<" "<<j<<endl;
        count++;
      }
    }
  }
  cout << count << endl;
}
Problem p03048 (C++)

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

Fixed submission:
#include <stdio.h>
int main() {
  int r, g, b, n;
  int ans = 0;
  int i, j, k;
  scanf("%d%d%d%d", &r, &g, &b, &n);
  // printf ("%d %d %d %d\n",r,g,b,n);
  for (i = 0; i <= (n / r) + 10; ++i) {
    for (j = 0; j <= (n / g) + 10; ++j) {
      int p = n - i * r - g * j;
      if (p % b == 0 && p / b >= 0)
        ans++;
    }
  }
  printf("%d\n", ans);
  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, r, g, b, sum = 0;
  vector<int> rgb(3);
  cin >> rgb.at(0) >> rgb.at(1) >> rgb.at(2) >> N;
  sort(rgb.begin(), rgb.end());
  R = rgb.at(0);
  G = rgb.at(1);
  B = rgb.at(2);
  for (int r = 0; r < N / R + 1; r++) {
    int N1 = (N - R * r) / G;
    for (int g = 0; g < N1 + 1; g++) {
      int N2 = (N - R * r - G * g) / B;
      for (int b = 0; b < N2 + 1; b++) {
        if (R * r + G * g + B * b == N) {
          sum++;
        }
      }
    }
  }
  cout << sum << endl;
}

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

int main() {
  int R, G, B, N, r, g, b, sum = 0;
  vector<int> rgb(3);
  cin >> rgb.at(0) >> rgb.at(1) >> rgb.at(2) >> N;
  sort(rgb.begin(), rgb.end());
  R = rgb.at(0);
  G = rgb.at(1);
  B = rgb.at(2);
  for (int r = 0; r < N / R + 1; r++) {
    int N1 = (N - R * r) / G;
    for (int g = 0; g < N1 + 1; g++) {
      if ((N - R * r - G * g) % B == 0)
        sum++;
    }
  }
  cout << sum << endl;
}
Problem p03048 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define LONGLONGMAX 9223372036854775807
#define LONGLONGMIN -9223372036854775807
#define INTMAX 32767
#define INTMIN -32767
#define ROUNDUP(divisor, dividend) (divisor + (dividend - 1)) / dividend
int r, g, b, n;
int main() {
  cin >> r >> g >> b >> n;
  int c = 0;
  for (size_t i = 0; i <= ROUNDUP(n, r); i++) {
    for (size_t l = 0; l <= ROUNDUP(n, g); l++) {
      for (size_t m = 0; m <= ROUNDUP(n, b); m++) {
        if (i * r + l * g + m * b == n) {
          c++;
        }
      }
    }
  }
  cout << c << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define LONGLONGMAX 9223372036854775807
#define LONGLONGMIN -9223372036854775807
#define INTMAX 32767
#define INTMIN -32767
#define ROUNDUP(divisor, dividend) (divisor + (dividend - 1)) / dividend
int r, g, b, n;
int main() {
  cin >> r >> g >> b >> n;
  int c = 0;
  for (int i = 0; i <= n; i++) {
    for (int l = 0; l <= n; l++) {
      if ((n - (i * r + l * g)) % b == 0 &&
          i * r + l * g + floor((n - (i * r + l * g)) / b) * b == n &&
          (n - (i * r + l * g)) >= 0) {
        c++;
      }
    }
  }
  cout << c << endl;
}
Problem p03048 (C++)

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

using namespace std;

int main(int argc, char *argv[]) {
  int R, G, B, N;
  cin >> R >> G >> B >> N;

  int ret = 0;
  for (int i = 0; i <= N / R; ++i) {
    int rest = N - i * R;
    if (rest < 0)
      continue;
    for (int j = 0; j <= rest / G; ++j) {
      int rest2 = rest - j * G;
      if (rest2 < 0)
        break;
      for (int k = 0; k <= rest2 / B; ++k) {
        int rest3 = rest2 - k * B;
        if (rest3 == 0) {
          ++ret;
          if (rest3 < 0)
            break;
        }
      }
    }
  }

  cout << ret << endl;

  return 0;
}

Fixed submission:
#include <iostream>

using namespace std;

int main(int argc, char *argv[]) {
  int R, G, B, N;
  cin >> R >> G >> B >> N;

  int ret = 0;
  for (int i = 0; i <= N / R; ++i) {
    int rest = N - i * R;
    if (rest < 0)
      continue;
    for (int j = 0; j <= rest / G; ++j) {
      int rest2 = rest - j * G;
      if (rest2 < 0)
        break;
      if (rest2 % B == 0)
        ++ret;
    }
  }

  cout << ret << endl;

  return 0;
}
Problem p03048 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iostream>
#include <math.h>
#define ll long long int
#define FOR(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define REP1(i, n) FOR(i, 1, n)

using namespace std;

int main() {
  int R, G, B, N;
  cin >> R >> G >> B >> N;
  int ans = 0;
  REP(r, N / R + 1) {
    if (r * R > N)
      break;
    REP(g, N / G + 1) {
      if (r * R + g * G > N)
        break;
      REP(b, N / B + 1) {
        if (r * R + g * G + b * B > N)
          break;
        if (r * R + g * G + b * B == N)
          ans++;
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <math.h>
#define ll long long int
#define FOR(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define REP1(i, n) FOR(i, 1, n)

using namespace std;

int main() {
  int R, G, B, N;
  cin >> R >> G >> B >> N;
  int ans = 0;
  REP(r, N / R + 1) {
    if (r * R > N)
      break;
    REP(g, N / G + 1) {
      if (r * R + g * G > N)
        break;
      if ((N - (r * R + g * 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() {
  int r, g, b, n;
  int cnt = 0;
  cin >> r >> g >> b >> n;
  if (g > r && g > b) {
    int tmp = g;
    g = r;
    r = tmp;
  }
  if (b > g && b > r) {
    int tmp = b;
    b = r;
    r = tmp;
  }
  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) {
          cnt++;
          break;
        }
      }
    }
  }
  cout << cnt << endl;
  return 0;
}

Fixed submission:
#include <iostream>

using namespace std;

int main() {
  int r, g, b, n;
  int cnt = 0;
  cin >> r >> g >> b >> n;
  if (g > r && g > b) {
    int tmp = g;
    g = r;
    r = tmp;
  }
  if (b > g && b > r) {
    int tmp = b;
    b = r;
    r = tmp;
  }
  for (int i = 0; i <= n / r; i++) {
    for (int j = 0; j <= n / g; j++) {
      if (r * i + g * j > n) {
        break;
      }
      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;

#define INF 100000000
#define ll long long
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPP(i, m, n) for (int i = m; i < n; i++)
#define de cout << "debug" << endl;

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

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

#define INF 100000000
#define ll long long
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPP(i, m, n) for (int i = m; i < n; i++)
#define de cout << "debug" << endl;

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

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

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

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

int main(void) {
  int r, g, b, n;
  cin >> r;
  cin >> g;
  cin >> b;
  cin >> n;
  int cnt = 0;
  for (int i = 0; i < n / r + 1; i++) {
    for (int j = 0; j < (n - i * r) / g + 1; j++) {
      if ((n - i * r - j * g) % b == 0)
        cnt++;
    }
  }
  cout << cnt << 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 r = 0; R * r <= N; r++) {
    for (int g = 0; R * r + G * g <= N; g++) {
      for (int b = 0; R * r + G * g + B * b <= N; b++) {
        if (R * r + G * g + B * b == N) {
          ans++;
          ans %= (int)(1e+9) + 7;
        }
      }
    }
  }

  cout << ans << endl;

  return 0;
}


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

using namespace std;

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

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

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

  cout << ans << endl;

  return 0;
}
Problem p03048 (C++)

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

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

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

int main() {
  int R, G, B, N;
  cin >> R >> G >> B >> N;
  int ans = 0;
  for (int i = 0; i <= N / R; ++i) {
    for (int j = 0; j <= N / G; ++j) {
      if ((N - R * i - G * j) % B == 0 && (N - R * i - G * j) / B >= 0)
        ans++;
    }
  }
  cout << ans << endl;
  return 0;
}
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 RR = N / R + 1;
  int GG = N / G + 1;
  int BB = N / B + 1;
  int count = 0;

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

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

int main() {
  int R, G, B, N;
  cin >> R >> G >> B >> N;
  int RR = N / R + 1;
  int GG = N / G + 1;
  int BB = N / B + 1;
  int count = 0;

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

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

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

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

int main() {
  int r, g, b, n, ans = 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) {
        ans++;
      }
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p03048 (C++)

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

int main() {
  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++) {
        // cout << i << j << k << endl;
        int ri = r * i;
        int gj = g * j;
        int bk = b * k;
        ll clac = ri + gj + bk;
        if (n == clac) {
          ans++;
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}

/*
やっほい！
　　　　　　　やほほい！
　　　　+　　 　*
　　　 ∧∧　　. ∧∞∧　*
*　ヽ(=´ω｀)人(´ω｀*)ﾉ
　.～（ O x.） （ 　 O)～　+
。*　 　∪　　　　∪
*/

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

int main() {
  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++){
          //cout << i << j << k << endl;
          int ri = r*i;
          int gj = g*j;
          int bk = b*k;
          ll clac = ri+gj+bk;
          if(n == clac){
              ans++;
          }*/
      if ((n - (i * r + j * g)) % b == 0) {
        ans++;
      }
    }
  }
  cout << ans << endl;
  return 0;
}

/*
やっほい！
　　　　　　　やほほい！
　　　　+　　 　*
　　　 ∧∧　　. ∧∞∧　*
*　ヽ(=´ω｀)人(´ω｀*)ﾉ
　.～（ O x.） （ 　 O)～　+
。*　 　∪　　　　∪
*/
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 r, g, b, count = 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) {
          count++;
        }
      }
    }
  }
  cout << count << endl;
  return 0;
}

Fixed submission:
#include <iostream>

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

  int r, g, b, count = 0;
  for (r = 0; r * R <= N; r++) {
    for (g = 0; r * R + g * G <= N; 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 <bits/stdc++.h>
using namespace std;

int main() {
  int r, g, b, n, i, j, k, ans = 0;
  cin >> r >> g >> b >> n;

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

  cout << ans << endl;
}


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

int main() {
  int r, g, b, n, i, j, k, ans = 0;
  cin >> r >> g >> b >> n;

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

  cout << ans << endl;
}