Language: C++

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<cstdlib>
#include<string>
#include<queue>
#include<map>
#include<vector>
#include<ctime>

#define int long long
#define R register
#define IL inline
#define Rf(a,b,c) for(R int (a)=(b);(a)<=(c);++(a))
#define Tf(a,b,c) for(R int (a)=(b);(a)>=(c);--(a))
#define MP make_pair
#define PA pair<int,int>
#define MES(a,b) memset((a),(b),sizeof((a)))
#define MEC(a,b) memcpy((a),(b),sizeof((b)))
#define D double

using namespace std;

const int N=4e3+5;

int n,ans,s[N],a[N];

IL int read() {
    int x=0,f=1;char ch=getchar();
    while(ch>'9'||ch<'0'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x*=10;x+=(ch-'0');ch=getchar();}
    return x*f;
}
IL void write(int x) {
    if(x<0) putchar('-'),x=-x;
    if(x>9) write(x/10);
    putchar(x%10+'0');
}

signed main()
{
	n=read();
	Rf(i,1,n) {
		a[i]=read();
		s[a[i]]++;
	}
	Rf(i,1,N-5) s[i]+=s[i-1];
	Rf(i,1,n-1) Rf(j,i+1,n) {
		R int A=a[i]+a[j]-1,B=abs(a[i]-a[j]);
		R int tmp=s[A]-s[B];
		if(a[i]>B) tmp--;
		if(a[j]>B) tmp--;
		ans+=max(0,tmp);
	}
	write(ans/3);
    return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:45:12: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   45 |         Rf(i,1,n) {
      |            ^
a.cc:16:30: note: in definition of macro 'Rf'
   16 | #define Rf(a,b,c) for(R int (a)=(b);(a)<=(c);++(a))
      |                              ^
a.cc:49:12: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   49 |         Rf(i,1,N-5) s[i]+=s[i-1];
      |            ^
a.cc:16:30: note: in definition of macro 'Rf'
   16 | #define Rf(a,b,c) for(R int (a)=(b);(a)<=(c);++(a))
      |                              ^
a.cc:50:12: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   50 |         Rf(i,1,n-1) Rf(j,i+1,n) {
      |            ^
a.cc:16:30: note: in definition of macro 'Rf'
   16 | #define Rf(a,b,c) for(R int (a)=(b);(a)<=(c);++(a))
      |                              ^
a.cc:50:24: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   50 |         Rf(i,1,n-1) Rf(j,i+1,n) {
      |                        ^
a.cc:16:30: note: in definition of macro 'Rf'
   16 | #define Rf(a,b,c) for(R int (a)=(b);(a)<=(c);++(a))
      |                              ^
a.cc:51:23: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   51 |                 R int A=a[i]+a[j]-1,B=abs(a[i]-a[j]);
      |                       ^
a.cc:51:37: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   51 |                 R int A=a[i]+a[j]-1,B=abs(a[i]-a[j]);
      |                                     ^
a.cc:52:23: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   52 |                 R int tmp=s[A]-s[B];
      |                       ^~~
a.cc:55:25: error: no matching function for call to 'max(int, long long int&)'
   55 |                 ans+=max(0,tmp);
      |                      ~~~^~~~~~~
In file included from /usr/include/c++/14/string:51,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
a.cc:55:25: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
   55 |                 ans+=max(0,tmp);
      |                      ~~~^~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61,
                 from a.cc:5:
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   template argument deduction/substitution failed:
a.cc:55:25: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   55 |                 ans+=max(0,tmp);
      |                      ~~~^~~~~~~