Problem p02608 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
using str = string;
using ll = long long;
#define REP(i, n) for (int i = 0; i < int(n); i++)
#define RREP(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define FOR(i, f, t) for (int i = int(f); i <= int(t); i++)
#define RFOR(i, f, t) for (int i = int(f); i >= int(t); i--)
#define ALL(vec) (vec).begin(), (vec).end()
#define ASORT(vec) sort(ALL(vec))
#define DSORT(vec) sort(ALL(vec), greater<int>());
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define YES(ans)                                                               \
  if (ans)                                                                     \
    cout << "YES" << endl;                                                     \
  else                                                                         \
    cout << "NO" << endl;
#define Yes(ans)                                                               \
  if (ans)                                                                     \
    cout << "Yes" << endl;                                                     \
  else                                                                         \
    cout << "No" << endl;
#define yes(ans)                                                               \
  if (ans)                                                                     \
    cout << "yes" << endl;                                                     \
  else                                                                         \
    cout << "no" << endl;

int main() {
  int n, s;
  cin >> n;
  REP(i, n) {
    s = 0;
    for (int j = 0; j < 100; j++) {
      for (int k = j; k < 100; k++) {
        for (int l = k; l < 100; l++) {
          if ((j + k + 2) * (j + k + 2) + (k + l + 2) * (k + l + 2) +
                  (l + j + 2) * (l + j + 2) ==
              2 * (i + 1)) {
            if ((j != k) && (k != l)) {
              s = s + 6;
            } else if ((j != k) || (k != l)) {
              s = s + 3;
            } else {
              s = s + 1;
            }
          }
        }
      }
    }
    cout << s << endl;
  }
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using str = string;
using ll = long long;
#define REP(i, n) for (int i = 0; i < int(n); i++)
#define RREP(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define FOR(i, f, t) for (int i = int(f); i <= int(t); i++)
#define RFOR(i, f, t) for (int i = int(f); i >= int(t); i--)
#define ALL(vec) (vec).begin(), (vec).end()
#define ASORT(vec) sort(ALL(vec))
#define DSORT(vec) sort(ALL(vec), greater<int>());
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define YES(ans)                                                               \
  if (ans)                                                                     \
    cout << "YES" << endl;                                                     \
  else                                                                         \
    cout << "NO" << endl;
#define Yes(ans)                                                               \
  if (ans)                                                                     \
    cout << "Yes" << endl;                                                     \
  else                                                                         \
    cout << "No" << endl;
#define yes(ans)                                                               \
  if (ans)                                                                     \
    cout << "yes" << endl;                                                     \
  else                                                                         \
    cout << "no" << endl;

int main() {
  int n, s;
  cin >> n;
  REP(i, n) {
    s = 0;
    for (int j = 0; j < 58; j++) {
      for (int k = j; k < 82; k++) {
        for (int l = k; l < 100; l++) {
          if ((j + k + 2) * (j + k + 2) + (k + l + 2) * (k + l + 2) +
                  (l + j + 2) * (l + j + 2) ==
              2 * (i + 1)) {
            if ((j != k) && (k != l)) {
              s = s + 6;
            } else if ((j != k) || (k != l)) {
              s = s + 3;
            } else {
              s = s + 1;
            }
          }
        }
      }
    }
    cout << s << endl;
  }
}