import std.stdio;
import std.string;
import std.conv;
import std.algorithm;
import std.range;

void main() {
	int n;
	scanf("%d\n", &n);
	auto ls = readln.chomp.split.to!(long[]);
	ls.sort!"a<b";
	long[2*1000+1] cache;
	foreach(ref x; cache) {
		x = -1;
	}
	foreach(i, l; ls) {
		cache[l] = i;
	}
	long t = 0;
	foreach(ref x; cache) {
		if (x == -1) {
			x = t;
		}
		else {
			t = x;
		}
	}
	size_t cnt = 0;
	foreach(i, a; ls) {
		foreach(j, b; ls[i+1..$]) {
			cnt += max(cache[a+b-1]-j-i-1, 0);
		}
	}
	cnt.write;
}
