Problem p02584 (C++) — buggy submission, verdict: Runtime Error

/*
      Ashraful Islam Paran
      15-August-2020
      18:39:41
*/
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define f(i, x, n) for (int i = x; i < n; i++)
#define fb(i, x, n) for (int i = n - 1; i >= 0; i--)
#define w(t)                                                                   \\
  int t;                                                                       \\
  cin >> t;                                                                    \\
  while (t--)

typedef unsigned long long ull;
typedef vector<long long> vi;
#define ull unsigned long long
#define msi map<string, long long>
#define mii map<long long, long long>
const int MX = 2e5 + 5;
const int INF = 1e18;
#define pb push_back
#define endl "\\n"
#define yes cout << "YES\\n"
#define no cout << "NO\\n"
#define all(x) x.begin(), x.end()
#define ff first
#define ss second

int32_t main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#else
  // online submission
#endif
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);

  long long a, b, c, p, q;
  cin >> a >> b >> c;
  a = abs(a);
  if (abs(a / c) > b)
    cout << abs(a - (b * c));
  else {
    if (a < 0)
      a = -a;
    p = (a % c);
    q = abs(p - c);
    if (p < q) {
      if ((b - (a / c)) % 2 == 0)
        cout << p;
      else
        cout << q;
    } else {
      if ((b - (a / c)) % 2 == 0)
        cout << p;
      else
        cout << q;
    }
  }
  cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << "s\\n";
  return 0;
}

Error: WA

Fixed submission:

/*
      Ashraful Islam Paran
      15-August-2020
      18:32:12
*/
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define f(i, x, n) for (int i = x; i < n; i++)
#define fb(i, x, n) for (int i = n - 1; i >= 0; i--)
#define w(t)                                                                   \\
  int t;                                                                       \\
  cin >> t;                                                                    \\
  while (t--)

typedef unsigned long long ull;
typedef vector<long long> vi;
#define ull unsigned long long
#define msi map<string, long long>
#define mii map<long long, long long>
const int MX = 2e5 + 5;
const int INF = 1e18;
#define pb push_back
#define endl "\\n"
#define yes cout << "YES\\n"
#define no cout << "NO\\n"
#define all(x) x.begin(), x.end()
#define ff first
#define ss second

int32_t main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#else
  // online submission
#endif
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);

  int a[100001], b, c = 0, d = 0, e, f, m, n, p, y, z, t, i, j, k;
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a, a + n);
  for (i = 0; i < n - 2; i++) {
    for (j = i + 1; j < n - 1; j++) {
      for (k = j + 1; k < n; k++) {
        if (a[i] + a[j] > a[k] && a[i] != a[j] && a[j] != a[k])
          c++;
      }
    }
  }
  cout << c << endl;

  cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << "s\\n";
  return 0;
}