alexjercan/bugnet huggingface dataset:
Problem p02582 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
// #include<iostream>

#define ll long long
#define uint unsigned int
#define ld long double
#define SAM                                                                    \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define RFOR(i, a, b) for (int i = a; i > b; --i)
#define mod 1000000007
#define mxn 200005
#define pb push_back
#define pii pair<int, int>
#define f first
#define s second
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()

using namespace std;

/*mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int power(int a,int n)
{
    a %= mod;
    if(n == 1) return a;
    if(n == 0) return 1;
    if(n%2) return (a*(power((a*a)%mod,n/2)%mod))%mod;           //n is odd
    return power((a*a)%mod,n/2)%mod;                             //n is even
}

const int inf = (int) 1e18;

int inverse(int x)
{
    return power(x,mod-2)%mod;     //Fermat's little theorem
}*/

int main() {
  SAM;
  string s;
  cin >> s;

  if (s[0] == 'R' && s[1] == 'R' && s[2] == 'R') {
    cout << "3";
    return 0;
  }

  if ((s[0] == 'R' && s[1] == 'R') || (s[1] == 'R' && s[2] == 'R')) {
    cout << "2";
    return 0;
  }

  if (s[0] == 'R' || s[1] == 'R' || s[2] == 'R') {
    cout << "1";
    return 0;
  }

  cout << "0";

  return 0;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
// #include<iostream>

#define ll long long
#define uint unsigned int
#define ld long double
#define SAM                                                                    \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define RFOR(i, a, b) for (int i = a; i > b; --i)
#define mod 1000000007
#define mxn 200005
#define pb push_back
#define pii pair<int, int>
#define f first
#define s second
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()

using namespace std;

/*mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int power(int a,int n)
{
    a %= mod;
    if(n == 1) return a;
    if(n == 0) return 1;
    if(n%2) return (a*(power((a*a)%mod,n/2)%mod))%mod;           //n is odd
    return power((a*a)%mod,n/2)%mod;                             //n is even
}

const int inf = (int) 1e18;

int inverse(int x)
{
    return power(x,mod-2)%mod;     //Fermat's little theorem
}*/

int main() {
  SAM;
  string s;
  cin >> s;
  int count = 0;
  vector<int> v;
  FOR(i, 0, 3) {
    if (s[i] == 'R')
      count++;
    if (s[i] == 'S') {
      v.pb(count);
      count = 0;
    }
  }
  int m = *max_element(all(v));
  cout << m;

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

#include <bits/stdc++.h>
#include <iostream>
#include <vector>
using namespace std;
int main() {
  string s;
  getline(cin, s);
  vector<int> count;
  int c = 0;
  ;
  for (int i = 0; i < 3; i++) {
    if (s[i] == 'R') {
      c++;
    } else {
      count.push_back(c);
      c = 0;
    }
    count.push_back(c);
  }
  sort(count.begin(), count.end(), greater<int>());
  cout << count[0];
  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
#include <iostream>
#include <vector>
using namespace std;
int main() {
  string s;
  getline(cin, s);
  vector<int> count;
  int c = 0;
  ;
  for (int i = 0; i < 3; i++) {
    if (s[i] == 'R') {
      c++;
    } else {
      count.push_back(c);
      c = 0;
    }
  }
  sort(count.begin(), count.end(), greater<int>());
  cout << count[0];
  return 0;
}
Problem p02582 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  int c = 0, ans = 0;
  for (int i = 0; i < s.length(); i++) {

    if (s[i] == 'R')
      c++;
    else
      c = 0;
    ans = max(ans, c);
  }
  cout << ans;
}


Error: -6
*** stack smashing detected ***: terminated


Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  char s[3];
  int c = 0;
  for (int i = 1; i <= 3; i++) {
    cin >> s[i];
    if (s[i] == 'R') {
      c++;
    }
    if (s[1] == 'R' && s[3] == 'R') {
      c = 1;
    }
  }
  cout << c;
}
Problem p02582 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
  vector<ll> v;
  ll count = 0, flag = 1;
  string s;
  cin >> s;
  ll len = s.length();
  // cout<<len;
  for (ll i = 0; i < len; i++) {
    if (s[i] == 'R') {
      count++;
      flag = 0;
      continue;
    }
    if (flag == 0) {
      v.push_back(count);
      count = 0;
      flag = 1;
    }
  }
  if (flag == 0)
    v.push_back(count);

  sort(v.begin(), v.end(), greater<>());
  if (v.empty())
    cout << 0;
  else
    cout << v[0];
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
  vector<ll> v;
  ll count = 0, flag = 1;
  string s;
  cin >> s;
  ll len = s.length();
  cout << len;
  for (ll i = 0; i < len; i++) {
    if (s[i] == 'R') {
      count++;
      flag = 0;
      continue;
    }
    if (flag == 0) {
      v.push_back(count);
      count = 0;
      flag = 1;
    }
  }
  if (flag == 0)
    v.push_back(count);

  sort(v.begin(), v.end(), greater<>());
  cout << v[0];
}
Problem p02582 (C++) — buggy submission, verdict: Runtime Error

#include <cstring>
#include <iostream>
using namespace std;

int main() {
  char wea[10];
  int c = 0;
  cin >> wea;
  if (wea[0] == 'R') {
    c = 1;
  } else {
    c = 0;
  }
  for (int i = 1; i <= 2; i++) {
    if (wea[i] == 'R' and wea[i - 1] == 'R') {
      c += 1;
    } else if (wea[i] == 'R' and wea[i - 1] == 'S') {
      c = 1;
    }
  }
  cout << c;
  return 0;
}

Error: WA

Fixed submission:

#include <cstring>
#include <iostream>

using namespace std;

int main() {
  char wea[3];
  int c = 0;
  cin >> wea;

  for (int i = 0; i <= 2; i++) {
    if (i >= 2) {
      if (wea[i - 1] == 'R' and wea[i] == 'R') {
        c += 1;
      }
    } else {
      if (wea[i] == 'R') {
        c += 1;
      }
    }
  }

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

#include <iostream>
#include <string>
using namespace std;
int main() {
  string s;
  cin >> s;
  int count = 0, j = 0;
  for (int i = 0; i < s.length(); i++) {
    if (s.at(i) == 'R') {
      j++;
    } else {
      if (count < j) {
        count = j;
        j = 0;
      }
    }
  }
  if (count < j) {
    count = j;
    j = 0;
  }
  cout << count;
}

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


Fixed submission:

#include <iostream>
#include <string>
using namespace std;
int main() {
  string s;
  cin >> s;
  int count = 0, j = 0;
  for (int i = 0; i <= s.length(); i++) {
    if (s.at(i) == 'R') {
      j++;
    } else {
      if (count < j) {
        count = j;
        j = 0;
      }
    }
  }
  cout << count;
}
Problem p02582 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  string a;
  cin >> a;
  if (a == "SSS") {
    cout << 0 << endl;
  } else if (a == "RRR") {
    cout << 3 << endl;
  } else if (a == "RRS" || a == "SRR") {
    cout << 2 << endl;
  } else
    cout << 1 << endl;
}


Error: WA

Fixed submission:

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

int main() {
  string a;
  cin >> a;
  if (a == "SSS") {
    cout << 0 << endl;
    return 9;
  } else if (a == "RRR") {
    cout << 3 << endl;
    return 0;
  } else if (a == "RRS" && a == "SRR") {
    cout << 2 << endl;
    return 0;
  } else
    cout << 1 << endl;
}
Problem p02582 (C++) — buggy submission, verdict: Runtime Error

using namespace std;
#include <iostream>
#include <string>

int main() {
  string weather;
  cin >> weather;
  int max = 0;
  int count = 0;

  for (int i = 0; i < weather.length(); i++) {
    if (i == 0) {
      if (weather[i] == 'R') {
        count = 1;
        max = 1;
      }
    } else {
      if (weather[i] == 'R') {
        count += 1;
        if (max < count)
          max = count;
      } else
        count = 0;
    }
  }

  cout << max;
  return 0;
}


Error: WA

Fixed submission:

using namespace std;
#include <iostream>
#include <string>

int main() {
  string weather;
  cin >> weather;
  int count = 0;

  for (int i = 0; i < weather.length(); i++) {
    if (i == 0) {
      if (weather[i] == 'R')
        count = 1;
    } else {
      if (weather[i] == 'R')
        count += 1;
      else
        count = 0;
    }
  }
  return count;
}
Problem p02582 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#include <iomanip>

using namespace std;
#define ll long long int
#define mod 1000000007
#define vec vector<long long int>
#define fi first
#define se second
#define pb push_back
int main() {
  string a;
  cin >> a;
  int count = 0;
  int i = 0;
  while (i < 3) {
    if (a[i] == 'R') {
      count++;
    }
    i++;
  }
  if (count == 2) {
    if (a[0] == 'R' && a[2] == 'R') {
      count = 1;
    }
  }
  cout << count;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#include <iomanip>

using namespace std;
#define ll long long int
#define mod 1000000007
#define vec vector<long long int>
#define fi first
#define se second
#define pb push_back
int main() {
  string a;
  cin >> a;
  int count = 0;
  int i = 0;
  while (i < 3) {
    if (a[i] == 'R') {
      count++;
    }
  }
  if (count == 2) {
    if (a[0] == 'R' && a[2] == 'R') {
      count = 1;
    }
  }
  cout << count;
}
Problem p02582 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;

int main() {
  string s;
  cin >> s;
  bool a = s[0] == 'R';
  bool b = s[1] == 'R';
  bool c = s[2] == 'R';
  if (a and b and c) {
    cout << 3;
  } else if ((a and b) or (b and c)) {
    cout << 2;
  } else if (a or b or c) {
    cout << 1;
  } else {
    cout << 0;
  }
}

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


Fixed submission:

#include <iostream>
#include <string>
using namespace std;

int main() {
  string s;
  if (s.at(0) == 'R' && s.at(1) == 'R' && s.at(2) == 'R') {
    cout << "3";
  } else if (s.at(0) == 'R' && s.at(1) == 'R' && s.at(2) == 'S' ||
             s.at(0) == 'S' && s.at(1) == 'R' && s.at(2) == 'R') {
    cout << "2";
  } else if (s.at(0) == 'R' && s.at(1) == 'S' && s.at(2) == 'R' ||
             s.at(0) == 'R' && s.at(1) == 'S' && s.at(2) == 'S' ||
             s.at(0) == 'S' && s.at(1) == 'R' && s.at(2) == 'S' ||
             s.at(0) == 'R' && s.at(1) == 'S' && s.at(2) == 'R' ||
             s.at(0) == 'S' && s.at(1) == 'S' && s.at(2) == 'R') {
    cout << "1";
  } else {
    cout << "0";
  }
}
Problem p02582 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
// pratt3000

#define mcqn                                                                   \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(nullptr);                                                            \\
  cout.tie(nullptr);
#define test                                                                   \\
  int t;                                                                       \\
  cin >> t;                                                                    \\
  while (t--)
#define ll long long
#define lli long long int
#define PI 3.1415926
#define fori(i, a, b) for (long long i = a; i < b; i++)
#define M ((int)1e9 + 7)
#define deb(x) cout << #x << "=" << x << endl;

long long expo(long long x, long long y) {
  long long res = 1;
  while (y) {
    if (y % 2)
      res = (res * x % M) % M;
    x = (x * x) % M;
    y /= 2;
  }
  return res;
}
long long add(long long a, long long b) { return (a % M + b % M + M) % M; }
long long sub(long long a, long long b) { return (a % M - b % M + M) % M; }
long long mul(long long a, long long b) { return ((a % M) * (b % M) + M) % M; }

using namespace std;

int main() {

  string s;
  cin >> s;

  int count = 0;
  int max = 0;

  fori(i, 0, 3) {
    if (s[i] == 'S')
      count = 0;
    else {
      count++;
    }
    if (max <= count)
      max = count;
  }
  cout << max << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
// pratt3000

#define mcqn                                                                   \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(nullptr);                                                            \\
  cout.tie(nullptr);
#define test                                                                   \\
  int t;                                                                       \\
  cin >> t;                                                                    \\
  while (t--)
#define ll long long
#define lli long long int
#define PI 3.1415926
#define fori(i, a, b) for (long long i = a; i < b; i++)
#define M ((int)1e9 + 7)
#define deb(x) cout << #x << "=" << x << endl;

long long expo(long long x, long long y) {
  long long res = 1;
  while (y) {
    if (y % 2)
      res = (res * x % M) % M;
    x = (x * x) % M;
    y /= 2;
  }
  return res;
}
long long add(long long a, long long b) { return (a % M + b % M + M) % M; }
long long sub(long long a, long long b) { return (a % M - b % M + M) % M; }
long long mul(long long a, long long b) { return ((a % M) * (b % M) + M) % M; }

using namespace std;

int main() {
  while (1) {
    string s;
    cin >> s;
    int count = 0;
    fori(i, 0, 3) {
      if (s[i] == 'S')
        count = 0;
      else {
        count++;
      }
    }
    cout << count << endl;
  }
}
Problem p02582 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <list>
#include <map>
#include <vector>
using namespace std;

int main(void) {
  string S;
  cin >> S;

  int ans = 0;
  for (int i = 0; i < 3; ++i) {
    if (S[i] == 'R')
      ++ans;
  }
  if (ans == 2 && S[1] == 'S')
    ans = 1;

  cout << ans;
  return 0;
}


Error: WA

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <list>
#include <map>
#include <vector>
using namespace std;

int main(void) {
  char S[3];
  cin >> S;

  int ans = 0;
  for (int i = 0; i < 3; ++i) {
    if (S[i] == 'R')
      ++ans;
  }
  if (ans == 2 && S[1] == 'S')
    ans = 1;

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

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

int main() {
  int N;
  cin >> N;
  vector<int> vec(N);
  for (int i = 0; i < N; ++i)
    cin >> vec[i];
  sort(vec.begin(), vec.end());

  int ans = 0;

  for (int i = 0; i < N; ++i) {
    for (int j = 0; j < i; ++j) {
      for (int k = 0; k < j; ++k) {
        if (vec[k] != vec[j] and vec[i] != vec[j] and
            vec[k] + vec[j] > vec[i]) {
          ans++;
        }
      }
    }
  }

  cout << ans << endl;

  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  int n, result = 0;

  cin >> n;

  vector<int> l(n);

  for (int i = 0; i < l.size(); i++) {
    cin >> l.at(i);
  }
  sort(l.begin(), l.end());

  for (int i = 0; i < (l.size() - 2); i++) {
    for (int j = i + 1; j < (l.size() - 1); j++) {
      for (int t = j + 1; t < l.size(); t++) {
        if ((l.at(t) != l.at(j)) and (l.at(t) != l.at(i)) and
            (l.at(j) != l.at(i)) and (l.at(t) < l.at(i) + l.at(j))) {
          result++;
        }
      }
    }
  }

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

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

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

  vector<int> leng;
  for (auto m : L) {
    leng.push_back(m.first);
  }

  long ans = 0;
  int lim;
  if (leng.size() >= 3) {
    for (size_t i = 0; i < leng.size() - 2; i++) {
      for (size_t j = i + 1; j < leng.size() - 1; j++) {
        lim = leng[i] + leng[j];
        for (size_t k = j + 1; k < leng.size(); k++) {
          if (leng[k] >= lim) {
            break;
          }
          ans += L[leng[i]] * L[leng[j]] * L[leng[k]];
        }
      }
    }
  }
  cout << ans << endl;
}

Error: TLE

Fixed submission:

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

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

  vector<int> leng;
  for (auto m : L) {
    leng.push_back(m.first);
  }

  long ans = 0;
  int lim;
  for (size_t i = 0; i < leng.size() - 2; i++) {
    for (size_t j = i + 1; j < leng.size() - 1; j++) {
      lim = leng[i] + leng[j];
      for (size_t k = j + 1; k < leng.size(); k++) {
        if (leng[k] >= lim) {
          break;
        }
        ans += L[leng[i]] * L[leng[j]] * L[leng[k]];
      }
    }
  }
  cout << ans << endl;
}
Problem p02583 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define forna(i, a, n) for (int i = a; i < n; i++)
typedef long long int lli;
using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  lli t, n, first, second, third, a, b, c;
  string s;
  // cin>>t;
  // while(t--){
  cin >> n;
  lli v[n];
  // vector<int>v;
  forna(i, 0, n) { cin >> v[i]; } // m[ar[i]]++;}
  if (n < 3) {
    cout << 0;
    return 0;
  }
  // for(auto x:m) v.push_back(x.first);
  sort(v, v + n);
  lli tot = 0;
  forna(i, 0, n) {
    // first=m[v[i]];
    a = v[i]; // second=m[v[i+1]];
    // lli sum=v[i]+v[i+1];
    forna(j, i + 1, n) {
      // second=m[v[j]];
      b = v[j];
      forna(k, j + 1, n) {
        // third=m[v[k]];
        c = v[k];
        // if(c>a+b) break;
        if (a + b > c && b + c > a && a + c > b && a != b && a != c && b != c) {
          tot++;
        }
      }
    }
  }
  cout << tot << endl;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define forna(i, a, n) for (int i = a; i < n; i++)
typedef long long int lli;
using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  lli t, n, first, second, third, a, b, c;
  string s;
  // cin>>t;
  // while(t--){
  cin >> n;
  lli ar[n];
  unordered_map<int, int> m;
  vector<int> v;
  forna(i, 0, n) {
    cin >> ar[i];
    m[ar[i]]++;
  }
  if (n < 3) {
    cout << 0;
    return 0;
  }
  for (auto x : m)
    v.push_back(x.first);
  sort(v.begin(), v.end());
  lli tot = 0;
  forna(i, 0, v.size() - 2) {
    first = m[v[i]];
    a = v[i]; // second=m[v[i+1]];
    // lli sum=v[i]+v[i+1];
    forna(j, i + 1, v.size() - 1) {
      second = m[v[j]];
      b = v[j];
      forna(k, j + 1, v.size()) {
        third = m[v[k]];
        c = v[k];
        if (c > a + b)
          break;
        if (a + b > c && b + c > a && a + c > b) {
          tot += first * second * third;
        }
      }
    }
  }
  cout << tot << endl;
}
Problem p02583 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int n;
  cin >> n;
  int count = 0;

  vector<int> l(n);
  for (int i = 0; i < n; i++) {
    cin >> l.at(i);
  }
  sort(l.begin(), l.end());

  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.at(i) + l.at(j) > l.at(k) && l.at(i) < l.at(j) &&
            l.at(j) < l.at(k)) {
          count++;
        }
      }
    }
  }
  cout << count << endl;
}

Error: WA

Fixed submission:

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

int main() {
  int n = 5;
  cin >> n;
  int count = 0;

  vector<int> l(n);
  l = {4, 4, 9, 7, 5};
  for (int i = 0; i < n; i++) {
    cin >> l.at(i);
  }
  sort(l.begin(), l.end());

  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      for (int k = i + j + 1; k < n; k++) {
        if (l.at(i) + l.at(j) > l.at(k) && l.at(i) < l.at(j) &&
            l.at(j) < l.at(k)) {
          count++;
        }
      }
    }
  }
  cout << count << endl;
}
Problem p02583 (C++) — buggy submission, verdict: Time Limit Exceeded

#include "bits/stdc++.h"

#define rep(i, n) for (int i = 0; i < n; i++)
#define vv(Type, Name, n, m, d) vector<vector<Type>> Name(n, vector<Type>(m, d))
#define P pair
using namespace std;
using ll = long long;

int main(void) {

  ios::sync_with_stdio(false);
  cin.tie(0);

  int n;
  cin >> n;

  vector<int> a(n);
  rep(i, n) cin >> a[i];

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

  int ans = 0;
  for (int i = 0; i < n - 2; i++) {
    for (int j = i + 1; j < n - 1; j++) {
      if (a[i] == a[j])
        continue;
      int k = j + 1;
      for (; k < n; k++)
        if (a[j] != a[k])
          break;
      int cnt = lower_bound(a.begin() + k, a.end(), a[i] + a[j]) - a.begin();
      ans += cnt - k;
    }
  }

  cout << ans << endl;

  return 0;
}


Error: TLE

Fixed submission:

#include "bits/stdc++.h"

#define rep(i, n) for (int i = 0; i < n; i++)
#define vv(Type, Name, n, m, d) vector<vector<Type>> Name(n, vector<Type>(m, d))
#define P pair
using namespace std;
using ll = long long;

int main(void) {

  ios::sync_with_stdio(false);
  cin.tie(0);

  int n;
  cin >> n;

  vector<int> a(n);
  rep(i, n) cin >> a[i];

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

  int ans = 0;
  for (int i = 0; i < a.size() - 2; i++) {
    for (int j = i + 1; j < a.size() - 1; j++) {
      if (a[i] == a[j])
        continue;
      int k = j + 1;
      for (; k < a.size(); k++)
        if (a[j] != a[k])
          break;
      int cnt = lower_bound(a.begin() + k, a.end(), a[i] + a[j]) - a.begin();
      ans += cnt - k;
    }
  }

  cout << ans << endl;

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

#include <bits/stdc++.h>
#define int long long
using namespace std;
int Size = 1e14;

int check(int a, int b, int c) {

  if (a + b > c)
    return 1;
  else
    return 0;
}

int32_t main() {

  int n, a;
  cin >> n;

  vector<int> vec;

  for (int i = 0; i < n; i++) {
    cin >> a;
    // if(fre[a]==0)
    vec.push_back(a);
  }

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

  int cnt = 0, mx = 0;
  int range = vec.size();

  for (int i = 0; i < range - 2; i++) {

    for (int j = i + 1; j < range - 1; j++) {

      // if(vec[i]==vec[j]) continue;

      for (int k = j + 1; k < range; k++) {

        // if(vec[j]==vec[k]) continue;

        int a = vec[i];
        int b = vec[j];
        int c = vec[k];

        // cout<<a<<" "<<b<<" "<<c<<endl;

        if (check(a, b, c) == 1 and a != b and b != c and a != c) {
          cnt++;
        }
      }
    }
  }

  cout << cnt << endl;

  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define int long long
using namespace std;
int Size = 1e14;

int check(int a, int b, int c) {

  if (a + b > c)
    return 1;
  else
    return 0;
}

int32_t main() {

  int n, a;
  cin >> n;

  vector<int> vec;

  for (int i = 0; i < n; i++) {
    cin >> a;
    vec.push_back(a);
  }

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

  int cnt = 0;

  for (int i = 0; i < vec.size() - 2; i++) {

    for (int j = i + 1; j < vec.size() - 1; j++) {

      if (vec[i] == vec[j])
        continue;

      for (int k = j + 1; k < vec.size(); k++) {

        if (vec[j] == vec[k])
          continue;

        int a = vec[i];
        int b = vec[j];
        int c = vec[k];

        // cout<<a<<" "<<b<<" "<<c<<endl;

        if (check(a, b, c) == 1)
          cnt++;
      }
    }
  }

  cout << cnt << endl;

  return 0;
}