Language: C++

#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
#define boost ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define rando mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define fi first
#define se second
#define debug(x) cerr << " - " << #x << ": " << x << endl;
#define debugs(x, y) cerr << " - " << #x << ": " << x << " " << #y << ": " << y << endl;
#define debugii(x) cerr << " - " << #x << ": " << x.fi<<","<<x.se << endl;
#define sep() cerr << "--------------------" << endl;
#define all(x) (x).begin(),(x).end()
#define sz(x) (ll)x.size()
#define ld long double
#define ll long long
#define int ll
#define ii pair<int,int>
#define v vector<int>
#define vii vector<ii>
#define vv vector<vector<int> >
#define mp make_pair
#define INF 1000000000
#define pb push_back
#define EPS 1e-9
const int MOD = 1000000007; // 998244353
int id[10000];
int32_t main(){
	boost;
	int n;
	cin>>n;
	v vec(n);
	for (int i = 0; i < n; ++i)
		cin>>vec[i];
	sort(all(vec));
	v search;
	set<int> uni;
	for(auto it:vec)uni.insert(it);
	int k=0;
	for(auto it:uni)id[it]=k++,search.pb(it);
	set<ii> vis;
	int ans=0;
	for (int i = n-1; i >=2 ; i--)
	{
		for (int j = i-1; j >= 1; j--)
		{
			if(vis.find(ii(vec[i],vec[j]))!=vis.end())continue;
			int s=vec[i]-vec[j]+1;
			int f=1;
			if((j>0&&vec[j-1]==vec[j])||((j<(n-1))&&(vec[j+1]==vec[j])))f=0;
			int idx=lower_bound(search.begin(),search.end(),s)-search.begin();
			if(idx>(id[vec[j]]-f)||search[idx]<s)continue;
			vis.insert(ii(vec[i],vec[j]));
			ans+=(id[vec[j]]-idx+(1-f));

		}
	}
	cout<<ans;
	return 0;
}
//long long
//array bounds
//special cases
//binary search	#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
#define boost ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define rando mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define fi first
#define se second
#define debug(x) cerr << " - " << #x << ": " << x << endl;
#define debugs(x, y) cerr << " - " << #x << ": " << x << " " << #y << ": " << y << endl;
#define debugii(x) cerr << " - " << #x << ": " << x.fi<<","<<x.se << endl;
#define sep() cerr << "--------------------" << endl;
#define all(x) (x).begin(),(x).end()
#define sz(x) (ll)x.size()
#define ld long double
#define ll long long
#define int ll
#define ii pair<int,int>
#define v vector<int>
#define vii vector<ii>
#define vv vector<vector<int> >
#define mp make_pair
#define INF 1000000000
#define pb push_back
#define EPS 1e-9
const int MOD = 1000000007; // 998244353
int id[10000];
int32_t main(){
	boost;
	int n;
	cin>>n;
	v vec(n);
	for (int i = 0; i < n; ++i)
		cin>>vec[i];
	sort(all(vec));
	v search;
	set<int> uni;
	for(auto it:vec)uni.insert(it);
	int k=0;
	for(auto it:uni)id[it]=k++,search.pb(it);
	set<ii> vis;
	int ans=0;
	for (int i = n-1; i >=2 ; i--)
	{
		for (int j = i-1; j >= 1; j--)
		{
			if(vis.find(ii(vec[i],vec[j]))!=vis.end())continue;
			int s=vec[i]-vec[j]+1;
			int f=1;
			if((j>0&&vec[j-1]==vec[j])||((j<(n-1))&&(vec[j+1]==vec[j])))f=0;
			int idx=lower_bound(search.begin(),search.end(),s)-search.begin();
			if(idx>(id[vec[j]]-f)||search[idx]<s)continue;
			vis.insert(ii(vec[i],vec[j]));
			ans+=(id[vec[j]]-idx+(1-f));

		}
	}
	cout<<ans;
	return 0;
}
//long long
//array bounds
//special cases
//binary search	

Compiler output:
a.cc:87:11: error: redefinition of 'const long long int MOD'
   87 | const int MOD = 1000000007; // 998244353
      |           ^~~
a.cc:25:11: note: 'const long long int MOD' previously defined here
   25 | const int MOD = 1000000007; // 998244353
      |           ^~~
a.cc:88:5: error: redefinition of 'long long int id [10000]'
   88 | int id[10000];
      |     ^~
a.cc:26:5: note: 'long long int id [10000]' previously declared here
   26 | int id[10000];
      |     ^~
a.cc:89:9: error: redefinition of 'int32_t main()'
   89 | int32_t main(){
      |         ^~~~
a.cc:27:9: note: 'int32_t main()' previously defined here
   27 | int32_t main(){
      |         ^~~~