unittest
{
	assert( [ "6", "2 3 3 1 3 1" ].parse.expand.solve == 3 );
	assert( [ "6", "5 2 4 2 8 8" ].parse.expand.solve == 0 );
	assert( [ "32", "3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3 2 3 8 4 6 2 6 4 3 3 8 3 2 7 9 5" ].parse.expand.solve == 22 );
}



import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	input.popFront;
	auto as = input.front.split.to!( long[] );
	return tuple( as );
}

auto solve( long[] as )
{
	auto bs = new long[ as.length ];
	long[ long ] cs;
	foreach( i, a; as )
	{
		bs[ i ] = i - as[ i ];
		cs[ i - as[ i ] ]++;
	}
	
	foreach( i, ref a; as )
	{
		a = i + as[ i ];
	}
	
	auto ans = 0L;
	foreach( a, b; lockstep( as, bs ) )
	{
		cs[ b ]--;
		if( a in cs ) ans += cs[ a ];
	}
	return ans;
}
