import java.util.Scanner; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int[] a = new int[n]; for (int i = 0; i < n; i++) { a[i] = sc.nextInt(); } sc.close(); long[][][] dp = new long[2000][2001][4]; for (int i = 0; i < n; i++) { for (int k = 1; k < 2000; k++) { dp[k][a[i]][0]++; if (a[i] - k - 10 > 0) { dp[k][a[i]][1] += dp[k][a[i] - k - 10][0]; } if (a[i] + k <= 2000) { dp[k][a[i]][2] += dp[k][a[i] + k][1]; } if (a[i] - k - 1 > 0) { dp[k][a[i]][3] += dp[k][a[i] - k - 1][2]; } } } long ans = 0; for (int i = 0; i < dp.length; i++) { for (int j = 0; j < dp[i].length; j++) { ans += dp[i][j][3]; } } System.out.println(ans); } }