alexjercan/bugnet huggingface dataset:
Problem p02583 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstdio>

int main() {
  unsigned N, answer = 0;
  scanf("%u", &N);
  unsigned L[N];
  for (int i = 0; i < N; ++i) {
    scanf("%u", L + i);
  }
  for (unsigned i = 0; i + 2 < N; i++) {
    for (unsigned j = i + 1; j + 1 < N; j++) {
      for (unsigned k = j + 1; k < N; k++) {
        if (L[i] != L[j] && L[k] != L[j] && L[i] != L[k] &&
            L[i] + L[j] > L[k] && L[i] + L[k] > L[j] && L[k] + L[j] > L[i])
          answer++;
      }
    }
  }
  printf("%u\\n", answer);
  return 0;
}

Error: TLE

Fixed submission:

#include <cstdio>

int main() {
  unsigned N, answer = 0;
  scanf("%u", &N);
  unsigned L[N];
  for (int i = 0; i < N; ++i) {
    scanf("%u", L + i);
  }
  for (unsigned i = 0; i < N - 2; i++) {
    for (unsigned j = i + 1; j < N - 1; j++) {
      for (unsigned k = j + 1; k < N; k++) {
        if (L[i] != L[j] && L[k] != L[j] && L[i] != L[k] &&
            L[i] + L[j] > L[k] && L[i] + L[k] > L[j] && L[k] + L[j] > L[i])
          answer++;
      }
    }
  }
  printf("%u\\n", answer);
  return 0;
}
Problem p02583 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int n;
vector<int> v;

int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    int nr;
    cin >> nr;
    v.push_back(nr);
  }
  if (n < 3) {
    cout << 0;
    return 0;
  }

  sort(v.begin(), v.end());
  v.push_back(0);
  int total = 0, lastj = 0, lasti = 0;
  for (int i = 0; i < v.size() - 3; i++) {
    if (i > 0) {
      if (v[i] == v[i - 1]) {
        total += lasti;
        continue;
      } else {
        lasti = 0;
      }
    }
    for (int j = i + 1; j < v.size() - 2; j++)
      if (v[i] != v[j]) {
        if (v[j] == v[j - 1]) {
          total += lastj;
          lasti += lastj;
          continue;
        }
        int st = j + 1, dr = v.size() - 2;
        while (v[st] == v[st - 1] && st <= dr)
          st++;
        if (st > dr) {
          lastj = 0;
          continue;
        }
        int ini_st = st;

        while (st < dr) {
          int mij = (st + dr) / 2;
          if (v[i] + v[j] > v[mij])
            st = mij + 1;
          else
            dr = mij;
        }
        while (v[i] + v[j] <= v[st])
          st--;

        total += max(0, st - ini_st + 1);
        lastj = max(0, st - ini_st + 1);
        lasti += lastj;
      }
  }

  cout << total;
  return 0;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int n;
vector<int> v;

int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    int nr;
    cin >> nr;
    v.push_back(nr);
  }

  sort(v.begin(), v.end());
  v.push_back(0);
  int total = 0, lastj = 0, lasti = 0;
  for (int i = 0; i < v.size() - 3; i++) {
    if (i > 0) {
      if (v[i] == v[i - 1]) {
        total += lasti;
        continue;
      } else {
        lasti = 0;
      }
    }
    for (int j = i + 1; j < v.size() - 2; j++)
      if (v[i] != v[j]) {
        if (v[j] == v[j - 1]) {
          total += lastj;
          lasti += lastj;
          continue;
        }
        int st = j + 1, dr = v.size() - 2;
        while (v[st] == v[st - 1] && st <= dr)
          st++;
        if (st > dr) {
          lastj = 0;
          continue;
        }
        int ini_st = st;

        while (st < dr) {
          int mij = (st + dr) / 2;
          if (v[i] + v[j] > v[mij])
            st = mij + 1;
          else
            dr = mij;
        }
        while (v[i] + v[j] <= v[st])
          st--;

        total += max(0, st - ini_st + 1);
        lastj = max(0, st - ini_st + 1);
        lasti += lastj;
      }
  }

  cout << total;
  return 0;
}
Problem p02583 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int N;
  int a[110];
  cin >> N;
  //  cout << N;
  for (int i = 0; i < N; i++) {
    cin >> a[i];
    //    cout << a[i];
  }
  sort(a, a + N, greater<int>());
  int mycount = 0;
  for (int i = 0; i < N - 2; i++) {
    for (int j = i + 1; j < N - 1; j++) {
      for (int k = j + 1; k < N; k++)
        if (a[i] < (a[j] + a[k])) {
          if (a[i] != a[j] && a[i] != a[k] && a[j] != a[k]) {
            mycount++;
            //          cout << a[i] << " " << a[j] << " " << a[k] << endl;
          }
        }
    }
  }
  cout << mycount << endl;
  return 0;
}

Error: -11

Fixed submission:

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

int main() {
  int N;
  int a[1000000000];
  cin >> N;
  cout << N;
  for (int i = 0; i < N; i++) {
    cin >> a[i];
    cout << a[i];
  }
  sort(a, a + N, greater<int>());
  int mycount = 0;
  for (int i = N - 1; i < 0; i--) {
    for (int j = 0; j < N - 2; j++) {
      if (a[i] > (a[j] + a[j + 1]))
        mycount++;
    }
  }
  cout << mycount << endl;
  return 0;
}
Problem p02583 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAX = 1e5 + 10;
ll l[200];
int solve() {
  int n = 0, m = 0;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> l[i];
  }
  // if (n<3) return cout<<m<<endl,0;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; ++j) {
      for (int k = j + 1; k < n; ++k) {
        if (l[i] != l[j] && l[j] != l[k] && l[i] != l[k]) {
          if ((l[i] + l[j] > l[k]) && (l[i] + l[k] > l[j]) &&
              (l[k] + l[j] > l[i]))
            m++;
        }
      }
    }
  }
  cout << m << endl;
  return 0;
}
int main() {
  int _ = 1;
  //    cin>>_;
  while (_--) {
    solve();
  }
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAX = 1e5 + 10;
ll l[200];
int solve() {
  int n = 0, m = 0;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> l[i];
  }
  if (n < 3)
    return cout << m << endl, 0;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; ++j) {
      for (int k = j + 1; k < n; ++k) {
        if (l[i] != l[j] && l[j] != l[k] && l[i] != l[k]) {
          if ((l[i] + l[j] > l[k]) && (l[i] + l[k] > l[j]) &&
              (l[k] + l[j] > l[i]))
            m++;
        }
      }
    }
  }
  cout << m << endl;
}
int main() {
  int _ = 1;
  //    cin>>_;
  while (_--) {
    solve();
  }
}
Problem p02583 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

typedef uint64_t u64;
typedef int64_t i64;
typedef uint32_t u32;
typedef int32_t i32;
typedef uint16_t u16;
typedef int16_t i16;
typedef uint8_t u8;
typedef int8_t i8;

using namespace std;

#define rep(idx, N) for (u64 idx = 0; idx < N; idx++)

int main() {
  u32 n;
  cin >> n;

  vector<u64> l(n);

  rep(i, n) { cin >> l[i]; }

  sort(l.begin(), l.end());

  u64 ans = 0;

  if (n < 3) {
    cout << 0;
    return 0;
  }

  for (u32 i = 0; i < n - 2; i++) {
    for (u32 j = i + 1; j < n - 1; j++) {
      for (u32 k = j + 1; k < n; k++) {
        if ((l[i] != l[j] && l[k] != l[j])) {
          if (l[k] < l[i] + l[j]) {
            // cout << l[i] << " " << l[j] << " " << l[k] << endl;
            ans++;
          } else {
            break;
          }
        }
      }
    }
  }

  cout << ans;

  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

typedef uint64_t u64;
typedef int64_t i64;
typedef uint32_t u32;
typedef int32_t i32;
typedef uint16_t u16;
typedef int16_t i16;
typedef uint8_t u8;
typedef int8_t i8;

using namespace std;

#define rep(idx, N) for (u64 idx = 0; idx < N; idx++)

int main() {
  u32 n;
  cin >> n;

  vector<u64> l(n);

  rep(i, n) { cin >> l[i]; }

  sort(l.begin(), l.end());

  u64 ans = 0;

  for (u32 i = 0; i < n - 2; i++) {
    for (u32 j = i + 1; j < n - 1; j++) {
      for (u32 k = j + 1; k < n; k++) {
        if ((l[i] != l[j] && l[k] != l[j])) {
          if (l[k] < l[i] + l[j]) {
            // cout << l[i] << " " << l[j] << " " << l[k] << endl;
            ans++;
          } else {
            break;
          }
        }
      }
    }
  }

  cout << ans;

  return 0;
}
Problem p02583 (C++) — buggy submission, verdict: Time Limit Exceeded

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

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

  vector<int> L(N);
  for (int i = 0; i < N; i++) {
    cin >> L.at(i);
  }

  int count = 0;

  for (int i = 0; i < N; i++) {
    for (int j = 1; j < N; j++) {
      if (i >= j)
        continue;
      for (int k = 2; k < N; k++) {
        if (j >= k)
          continue;
        vector<int> vec(3);
        vec.at(0) = L.at(i);
        vec.at(1) = L.at(j);
        vec.at(2) = L.at(k);

        sort(vec.begin(), vec.end());
        if (vec.at(0) == vec.at(1) || vec.at(1) == vec.at(2))
          continue;

        if (vec.at(0) < vec.at(1) + vec.at(2)) {
          if (vec.at(1) < vec.at(2) + vec.at(0)) {
            if (vec.at(2) < vec.at(0) + vec.at(1)) {
              count++;
            }
          }
        }
      }
    }
  }
  cout << count << endl;
}

Error: TLE

Fixed submission:

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

vector<int> f(vector<int> x) {
  int n = x.size();
  sort(x.begin(), x.end());

  vector<int> B(x.at(n - 1) + 1);
  int N = B.size();
  for (int i = 0; i < n; i++) {
    B.at(x.at(i))++;
  }
  vector<int> C;
  for (int i = 0; i < N; i++) {
    if (B.at(i)) {
      C.push_back(i);
    }
  }
  return C;
}

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

  vector<int> L(N);
  for (int i = 0; i < N; i++) {
    cin >> L.at(i);
  }

  int count = 0;

  for (int i = 0; i < N; i++) {
    for (int j = 1; j < N; j++) {
      if (i >= j)
        continue;
      for (int k = 2; k < N; k++) {
        if (j >= k)
          continue;
        vector<int> vec(3);
        vec.at(0) = L.at(i);
        vec.at(1) = L.at(j);
        vec.at(2) = L.at(k);

        vec = f(vec);
        if (vec.size() != 3)
          continue;

        if (vec.at(0) < vec.at(1) + vec.at(2)) {
          if (vec.at(1) < vec.at(2) + vec.at(0)) {
            if (vec.at(2) < vec.at(0) + vec.at(1)) {
              count++;
            }
          }
        }
      }
    }
  }
  cout << count << endl;
}
Problem p02583 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
/* function */
/* main */
int main() {
  int N;
  cin >> N;
  set<int> s;
  map<int, int> mp;
  for (int i = 0; i < N; i++) {
    int x;
    cin >> x;
    s.insert(x);
    mp[x]++;
  }
  vector<int> a;
  for (int si : s)
    a.push_back(si);
  int cnt = 0;
  int len = a.size();
  for (int i = 0; i < len - 2; i++) {
    for (int j = i + 1; j < len - 1; j++) {
      for (int k = j + 1; k < len; k++) {
        int s = a[i], t = a[j], u = a[k];
        if ((abs(s - t) < u) && (u < (s + t))) {
          cnt += mp[s] * mp[t] * mp[u];
        }
      }
    }
  }
  cout << cnt << '\\n';
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
/* function */
/* main */
int main() {
  int N;
  cin >> N;
  vector<int> a(101, 0);
  for (int i = 0; i < N; i++) {
    int x;
    cin >> x;
    a[x]++;
  }
  int cnt = 0;
  int len = 101;
  for (int i = 0; i < len - 2; i++) {
    if (a[i] == 0)
      continue;
    for (int j = i + 1; j < len - 1; j++) {
      if (a[j] == 0)
        continue;
      for (int k = j + 1; k < len; k++) {
        if (a[k] == 0)
          continue;
        int s = i, t = j, u = k;
        if ((abs(s - t) < u) && (u < (s + t))) {
          cnt += a[i] * a[j] * a[k];
        }
      }
    }
  }
  cout << cnt << '\\n';
}
Problem p02583 (C++) — buggy submission, verdict: Time Limit Exceeded

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

using namespace std;

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

  vector<uint32_t> Li(N);

  for (size_t i = 0; i < N; ++i) {
    cin >> Li[i];
  }
  sort(Li.begin(), Li.end());

  uint32_t ans = 0;
  for (size_t i = 0; i < N; ++i) {
    uint32_t a = Li[i];
    for (size_t j = 0; j < i; ++j) {
      uint32_t b = Li[j];
      for (size_t k = 0; k < j; ++k) {
        uint32_t c = Li[k];
        if (a != c and b != c and a != b and c + b > a)
          ans++;
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Error: TLE

Fixed submission:

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

using namespace std;

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

  vector<uint32_t> Li(N);

  for (size_t i = 0; i < N; ++i) {
    cin >> Li[i];
  }
  sort(Li.begin(), Li.end());

  uint32_t ans = 0;
  for (size_t i = 0; i < N - 2; ++i) {
    uint32_t a = Li[i];
    for (size_t j = i + 1; j < N - 1; ++j) {
      uint32_t b = Li[j];
      for (size_t k = j + 1; k < N; ++k) {
        uint32_t c = Li[k];
        if (a != c && b != c && a != b && a + b > c)
          ans++;
      }
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02583 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int n, count = 0;
  int L[n];
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> L[i];
  }
  if (n < 3) {
    cout << count << endl;
  } else {
    for (int i = 0; i < n - 2; i++) {
      for (int j = 1; j < n - 1; j++) {
        for (int k = 2; k < n; k++) {
          if (L[i] != L[j] && L[j] != L[k] && L[k] != L[i]) {
            if (i < j && j < k) {
              if (L[i] + L[j] > L[k] && L[j] + L[k] > L[i] &&
                  L[k] + L[i] > L[j]) {
                count++;
              }
            }
          }
        }
      }
    }
    cout << count << endl;
  }
  return 0;
}

Error: -11

Fixed submission:

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

int main() {
  int n, count = 0;
  int L[n];
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> L[i];
  }
  if (n < 3) {
    cout << count << endl;
  } else {
    for (int i = 0; i < n - 2; i++) {
      for (int j = 1; j < n - 1; j++) {
        for (int k = 2; k < n; k++) {
          if (L[i] != L[j] && L[j] != L[k] && L[k] != L[i]) {
            if (i < j && j < k && i < k) {
              if (L[i] + L[j] > L[k] && L[j] + L[k] > L[i] &&
                  L[k] + L[i] > L[j]) {
                count++;
              }
            }
          }
        }
      }
    }
    cout << count << endl;
  }
  return 0;
}
Problem p02583 (C++) — buggy submission, verdict: Time Limit Exceeded

#include "bits/stdc++.h"
using namespace std;
using ll = long long;

int main() {
  int n;
  cin >> n;
  vector<ll> l(n);
  for (int i = 0; i < n; i++) {
    cin >> l[i];
  }

  int ans = 0;
  for (int i = 0; i < n - 2; i++) {
    for (int j = i + 1; j < n - 1; j++) {
      for (int k = j + 1; k < n; k++) {
        if (l[i] != l[j] && l[j] != l[k] && l[k] != l[i] &&
            l[i] + l[j] > l[k] && l[j] + l[k] > l[i] && l[k] + l[i] > l[j]) {
          ans++;
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include "bits/stdc++.h"
using namespace std;
using ll = long long;

int main() {
  int n;
  cin >> n;
  vector<ll> l(n);
  for (int i = 0; i < n; i++) {
    cin >> l[i];
  }
  vector<ll> l1(0);
  l1.push_back(l[0]);
  for (int i = 1; i < n; i++) {
    bool f = true;
    for (int j = i; i >= 0; i--) {
      if (l[i] == l[j]) {
        f = false;
      }
    }
    if (f == true) {
      l1.push_back(l[i]);
    }
  }
  int ans = 0;
  for (int i = 0; i < n - 2; i++) {
    for (int j = i + 1; j < n - 1; j++) {
      for (int k = j + 1; k < n; k++) {
        if (l1[i] + l1[j] > l1[k] && l1[j] + l1[k] > l1[i] &&
            l1[k] + l1[i] > l[j]) {
          ans++;
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02583 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  int cnt = 0;
  for (int i = 0; i < N; i++)
    cin >> A[i];
  sort(A.begin(), A.end());
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < i; j++) {
      for (int k = 0; k < j; k++) {
        if ((A[i] != A[j]) && (A[j] != A[k]) && (A[k] != A[i])) {
          if (A[k] + A[j] > A[i]) {
            cnt++;
          }
        }
      }
    }
  }
  cout << cnt << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  int cnt = 0;
  for (int i = 0; i < N; i++)
    cin >> A[i];
  sort(A.begin(), A.end());
  if (N < 3) {
    cout << 0;
    return -1;
  } else {
    for (int i = 0; i < N; i++) {
      for (int j = i + 1; j < N; j++) {
        for (int k = j + 1; k < N; k++) {
          if ((A[i] != A[j]) && (A[j] != A[k]) && (A[k] != A[i])) {
            if (A[i] + A[j] > A[k]) {
              cnt++;
            }
          }
        }
      }
    }
  }
  cout << cnt << endl;
  return 0;
}
Problem p02583 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cstdint>
#include <iostream>
#include <set>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

int main() {
  int64_t N;
  cin >> N;
  if (N < 3) {
    cout << 0 << endl;
    return 0;
  }
  vector<int64_t> bars(N);
  for (int64_t n = 0; n < N; ++n) {
    cin >> bars[n];
  }
  sort(bars.begin(), bars.end());
  int64_t res = 0;
  for (size_t i = 0; i < N - 2; ++i) {
    for (size_t j = i + 1; j < N - 1; ++j) {
      if (bars[i] == bars[j])
        continue;
      for (size_t k = j + 1; k < N; ++k) {
        if (bars[j] == bars[k])
          continue;
        if (bars[i] + bars[j] > bars[k]) {
          ++res;
        }
      }
    }
  }

  cout << res << endl;

  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <cstdint>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>

using namespace std;

int main() {
  int64_t N;
  cin >> N;
  if (N < 3) {
    cout << 0 << endl;
    return 0;
  }
  map<int64_t, int64_t> bar_cnt;
  set<int64_t> bar_set;
  for (int64_t n = 0; n < N; ++n) {
    int64_t L;
    cin >> L;
    bar_set.insert(L);
    ++bar_cnt[L];
  }
  vector<int64_t> bars(bar_set.begin(), bar_set.end());
  int64_t res = 0;
  size_t size = bars.size();
  for (size_t i = 0; i < size - 2; ++i) {
    for (size_t j = i + 1; j < size - 1; ++j) {
      for (size_t k = j + 1; k < size; ++k) {
        if (bars[i] + bars[j] > bars[k]) {
          res += bar_cnt[bars[i]] * bar_cnt[bars[j]] * bar_cnt[bars[k]];
        }
      }
    }
  }

  cout << res << endl;

  return 0;
}
Problem p02583 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> L(N);
  for (int i = 0; i < N; i++) {
    cin >> L[i];
  }
  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 || j == k || k == i)
          continue;
        if (L[i] < L[j] && L[j] < L[k]) {
          if (max({L[i], L[j], L[k]}) <
              L[i] + L[j] + L[k] - max({L[i], L[j], L[k]})) {
            count++;
          }
        }
      }
    }
  }
  cout << count << endl;
}

Error: -6
terminate called after throwing an instance of 'std::out_of_range'
  what():  vector::_M_range_check: __n (which is 0) >= this->size() (which is 0)


Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> L;
  int count = 0;
  int max;
  for (int i = 0; i < N; i++) {
    cin >> L.at(i);
    for (int j = 0; j < N; j++) {
      cin >> L.at(j);
      for (int k = 0; k < N; k++) {
        cin >> L.at(k);
        if (L.at(i) != L.at(j) && L.at(j) != L.at(k) && L.at(k) != L.at(i)) {
          max = L.at(i);
          if (max < L.at(j)) {
            max = L.at(j);
          }
          if (max < L.at(k)) {
            max = L.at(k);
          }
          cout << max;
          return 0;
          if (max + max <= L.at(i) + L.at(j) + L.at(k)) {
            count++;
          }
        }
      }
    }
  }
  cout << count << endl;
}
Problem p02583 (C++) — buggy submission, verdict: Runtime Error

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

int main() {

  int N;
  cin >> N;

  vector<int> L(N);

  for (int i = 0; i < N; i++) {
    cin >> L[i];
  }

  sort(L.begin(), L.end());

  int cnt = 0;
  int tmpcnt = 0;

  for (int i = 0; i < L.size(); i++) {
    if (i >= 1) {
      if (L[i] == L[i - 1]) {
        cnt += tmpcnt;
        continue;
      }
    }
    tmpcnt = 0;
    for (int j = i + 1; j < L.size(); j++) {
      if (L[i] == L[j]) {
        continue;
      }
      for (int k = j + 1; k < L.size(); k++) {
        if (L[k] >= L[i] + L[j]) {
          break;
        } else if (L[j] != L[k]) {
          tmpcnt++;
        }
      }
    }
    cnt += tmpcnt;
  }
  cout << cnt << endl;

  return 0;
}


Error: 0

Fixed submission:

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

int main() {

  int N;
  cin >> N;

  vector<int> L(N);

  for (int i = 0; i < N; i++) {
    cin >> L[i];
  }

  sort(L.begin(), L.end());

  int cnt = 0;
  int tmpcnt = 0;

  for (int i = 0; i < L.size() - 2; i++) {
    if (i >= 1) {
      if (L[i] == L[i - 1]) {
        cnt += tmpcnt;
        continue;
      }
    }
    tmpcnt = 0;
    for (int j = i + 1; j < L.size() - 1; j++) {
      if (L[i] == L[j]) {
        continue;
      }
      for (int k = j + 1; k < L.size(); k++) {
        if (L[k] >= L[i] + L[j]) {
          break;
        } else if (L[j] != L[k]) {
          tmpcnt++;
        }
      }
    }
    cnt += tmpcnt;
  }
  cout << cnt << endl;

  return 0;
}