Nina received an odd New Year's present from a student: a set of $n$ unbreakable sticks. Each stick has a length, $\boldsymbol{l}$, and the length of the $i^{\mbox{th}}$ stick is $\boldsymbol{l_{i-1}}$. Deciding to turn the gift into a lesson, Nina asks her students the following:

How many ways can you build a square using exactly $\boldsymbol{6}$ of these unbreakable sticks? 

Note: Two ways are distinct if they use at least one different stick. As there are $\left(\begin{matrix}n\\ 6\end{matrix}\right)$ choices of sticks, we must determine which combinations of sticks can build a square.

Input Format

The first line contains an integer, $n$, denoting the number of sticks. The second line contains $n$ space-separated integers $l_0,l_1,\ldots,l_{n-2},l_{n-1}$ describing the length of each stick in the set.

Constraints

$6\leq n\leq3000$
$1\leq l_i\leq10^7$

Output Format

On a single line, print an integer representing the number of ways that $\boldsymbol{6}$ unbreakable sticks can be used to make a square.

Sample Input 0

8
4 5 1 5 1 9 4 5 

Sample Output 0

3

Sample Input 1

6
1 2 3 4 5 6 

Sample Output 1

0    

Explanation

Sample 0 

Given $8$ sticks ($l=4,5,1,5,1,9,4,5$), the only possible side length for our square is $5$. We can build square $\mbox{S}$ in $3$ different ways:

$S=\{l_0,l_1,l_2,l_3,l_4,l_6\}=\{4,5,1,5,1,4\}$ 

$S=\{l_0,l_1,l_2,l_4,l_6,l_7\}=\{4,5,1,1,4,5\}$

$S=\{l_0,l_2,l_3,l_4,l_6,l_7\}=\text{{4,1,5,1,4,5}\}$

In order to build a square with side length $5$ using exactly $\boldsymbol{6}$ sticks, $l_{0},l_{2},l_{4},$ and $l_{6}$ must always build two of the sides. For the remaining two sides, you must choose $2$ of the remaining $3$ sticks of length $5$ ($l_1,l_3,$ and $l_{7}$).

Sample 1 

We have to use all $\boldsymbol{6}$ sticks, making the largest stick length ($\boldsymbol{6}$) the minimum side length for our square. No combination of the remaining sticks can build $3$ more sides of length $\boldsymbol{6}$ (total length of all other sticks is $1+2+3+4+5=15$ and we need at least length $3*6=18$), so we print $\mbox{0}$.

Difficulty: MEDIUM_HARD
Tags: Dynamic programming
Skill types: Dynamic programming

Starter code:

Solutions:
import math
import os
import random
import re
import sys
import collections

def choose(n, k):
	if k > n:
		return 0
	k = min(k, n - k)
	(num, den) = (1, 1)
	for i in range(k):
		num *= n - i
		den *= i + 1
	return num // den

def squareCount(l):
	counter = collections.Counter(l)
	l = tuple(counter.keys())
	choose2 = collections.Counter()
	choose3 = collections.Counter()
	choose4 = collections.Counter()
	le = len(l)
	for n in counter:
		count = counter[n]
		if count >= 2:
			choose2[n] = choose(count, 2)
			if count >= 3:
				choose3[n] = choose(count, 3)
				if count >= 4:
					choose4[n] = choose(count, 4)
	t1 = 0
	t2 = 0
	for i in range(le):
		if counter[2 * l[i]] >= 2 and counter[l[i]] >= 4:
			t1 += choose4[l[i]] * choose2[2 * l[i]]
		if counter[l[i]] >= 2:
			for j in range(i + 1, le):
				if counter[l[j]] >= 2 and counter[l[i] + l[j]] >= 2:
					t2 += choose2[l[i]] * choose2[l[j]] * choose2[l[i] + l[j]]
	doubles = collections.Counter()
	for i in range(le):
		if counter[l[i]] >= 2 and counter[2 * l[i]] >= 2:
			doubles[2 * l[i]] = choose2[l[i]]
	pairs = collections.Counter()
	mpairs = collections.Counter()
	for i in range(le):
		for j in range(i + 1, le):
			if counter[l[i] + l[j]] >= 2:
				pairs[l[i] + l[j]] += counter[l[i]] * counter[l[j]]
				mpairs[l[i] + l[j]] += counter[l[i]] ** 2 * counter[l[j]] ** 2
	t3 = sum((pairs[s] * doubles[s] * choose2[s] for s in doubles if s in pairs))
	t4 = sum(((pairs[s] ** 2 - mpairs[s]) * choose2[s] for s in pairs)) // 2
	CD = collections.Counter()
	for d in range(le):
		if counter[l[d]] >= 3:
			for c in range(le):
				if l[c] < l[d]:
					CD[l[d] - l[c]] += choose3[l[d]] * counter[l[c]]
	s1 = 0
	s2 = 0
	s4 = 0
	for a in range(le):
		for b in range(a + 1, le):
			s1 += 2 * CD[l[a] + l[b]] * counter[l[a]] * counter[l[b]]
			if counter[l[a] + 2 * l[b]] >= 3:
				s2 += 2 * choose3[l[a] + 2 * l[b]] * counter[l[a]] * counter[l[b]] ** 2
			if counter[2 * l[a] + l[b]] >= 3:
				s2 += 2 * choose3[2 * l[a] + l[b]] * counter[l[b]] * counter[l[a]] ** 2
			if counter[l[b]] >= 2 and counter[l[a] + 2 * l[b]] >= 3:
				s4 += counter[l[a]] * choose2[l[b]] * choose3[l[a] + 2 * l[b]]
			if counter[l[a]] >= 2 and counter[2 * l[a] + l[b]] >= 3:
				s4 += counter[l[b]] * choose2[l[a]] * choose3[2 * l[a] + l[b]]
	s = (s1 - s2) // 6
	s3 = 0
	for a in range(le):
		if counter[l[a]] >= 3 and counter[3 * l[a]] >= 3:
			s3 += choose3[l[a]] * choose3[3 * l[a]]
	return t1 + t2 + t3 + t4 + s + s3 + s4
n = int(input())
l = list(map(int, input().rstrip().split()))
print(squareCount(l))


import math
import os
import random
import re
import sys

def choose2(n):
	return n * (n - 1) // 2

def choose3(n):
	return n * (n - 1) * (n - 2) // 6
n = int(input())
l = list(map(int, input().rstrip().split()))
d = {}
for stick in l:
	d[stick] = d.get(stick, 0) + 1
max_num = max(l)
mp_2 = [0] * (max_num + 1)
mp_2p = [0] * (max_num + 1)
mp_3 = [0] * (max_num + 1)
flatten = list(sorted(d.items()))
for (i, (stick1, cnt1)) in enumerate(flatten):
	for (sum3, sum3_cnt) in flatten[i + 1:]:
		if sum3_cnt < 3:
			continue
		rstick = stick1
		if sum3 > rstick * 3:
			break
		if cnt1 >= 3 and rstick * 3 == sum3:
			mp_3[sum3] += choose3(cnt1)
		missing_stick = sum3 - rstick
		mp_3[sum3] += cnt1 * mp_2[missing_stick]
		if rstick * 2 >= sum3:
			continue
		missing_stick -= rstick
		missing_one_cnt = d.get(missing_stick, 0) if missing_stick < rstick else 0
		if missing_one_cnt > 0 and cnt1 >= 2:
			mp_3[sum3] += choose2(cnt1) * missing_one_cnt
	for (stick2, cnt2) in flatten[:i]:
		sum_pair = stick1 + stick2
		if sum_pair > max_num:
			continue
		if sum_pair in d:
			mp_2p[sum_pair] += cnt1 * cnt2 * mp_2[sum_pair]
			if cnt1 >= 2 and cnt2 >= 2:
				mp_2p[sum_pair] += choose2(cnt1) * choose2(cnt2)
		mp_2[sum_pair] += cnt1 * cnt2
	if stick1 * 2 <= max_num and cnt1 >= 2:
		mp_2[stick1 * 2] = choose2(cnt1)
	if cnt1 >= 4 and stick1 * 2 in d:
		mp_2p[stick1 * 2] += cnt1 * (cnt1 - 1) * (cnt1 - 2) * (cnt1 - 3) // 24
res = 0
for (length, num_long) in d.items():
	if num_long >= 2:
		res += mp_2p[length] * choose2(num_long)
	if num_long >= 3:
		res += mp_3[length] * choose3(num_long)
print(res)


import math
import os
import random
import re
import sys
import collections

def choose(n, k):
	if k > n:
		return 0
	k = min(k, n - k)
	(num, den) = (1, 1)
	for i in range(k):
		num *= n - i
		den *= i + 1
	return num // den

def squareCount(l):
	counter = collections.Counter(l)
	l = tuple(counter.keys())
	choose2 = collections.Counter()
	choose3 = collections.Counter()
	choose4 = collections.Counter()
	le = len(l)
	for n in counter:
		count = counter[n]
		if count >= 2:
			choose2[n] = choose(count, 2)
			if count >= 3:
				choose3[n] = choose(count, 3)
				if count >= 4:
					choose4[n] = choose(count, 4)
	t1 = 0
	t2 = 0
	for i in range(le):
		if counter[2 * l[i]] >= 2 and counter[l[i]] >= 4:
			t1 += choose4[l[i]] * choose2[2 * l[i]]
		if counter[l[i]] >= 2:
			for j in range(i + 1, le):
				if counter[l[j]] >= 2 and counter[l[i] + l[j]] >= 2:
					t2 += choose2[l[i]] * choose2[l[j]] * choose2[l[i] + l[j]]
	doubles = collections.Counter()
	for i in range(le):
		if counter[l[i]] >= 2 and counter[2 * l[i]] >= 2:
			doubles[2 * l[i]] = choose2[l[i]]
	pairs = collections.Counter()
	mpairs = collections.Counter()
	for i in range(le):
		for j in range(i + 1, le):
			if counter[l[i] + l[j]] >= 2:
				pairs[l[i] + l[j]] += counter[l[i]] * counter[l[j]]
				mpairs[l[i] + l[j]] += counter[l[i]] ** 2 * counter[l[j]] ** 2
	t3 = sum((pairs[s] * doubles[s] * choose2[s] for s in doubles if s in pairs))
	t4 = sum(((pairs[s] ** 2 - mpairs[s]) * choose2[s] for s in pairs)) // 2
	CD = collections.Counter()
	for d in range(le):
		if counter[l[d]] >= 3:
			for c in range(le):
				if l[c] < l[d]:
					CD[l[d] - l[c]] += choose3[l[d]] * counter[l[c]]
	s1 = 0
	s2 = 0
	s4 = 0
	for a in range(le):
		for b in range(a + 1, le):
			s1 += 2 * CD[l[a] + l[b]] * counter[l[a]] * counter[l[b]]
			if counter[l[a] + 2 * l[b]] >= 3:
				s2 += 2 * choose3[l[a] + 2 * l[b]] * counter[l[a]] * counter[l[b]] ** 2
			if counter[2 * l[a] + l[b]] >= 3:
				s2 += 2 * choose3[2 * l[a] + l[b]] * counter[l[b]] * counter[l[a]] ** 2
			if counter[l[b]] >= 2 and counter[l[a] + 2 * l[b]] >= 3:
				s4 += counter[l[a]] * choose2[l[b]] * choose3[l[a] + 2 * l[b]]
			if counter[l[a]] >= 2 and counter[2 * l[a] + l[b]] >= 3:
				s4 += counter[l[b]] * choose2[l[a]] * choose3[2 * l[a] + l[b]]
	s = (s1 - s2) // 6
	s3 = 0
	for a in range(le):
		if counter[l[a]] >= 3 and counter[3 * l[a]] >= 3:
			s3 += choose3[l[a]] * choose3[3 * l[a]]
	return t1 + t2 + t3 + t4 + s + s3 + s4
n = int(input())
l = list(map(int, input().rstrip().split()))
print(squareCount(l))


import collections
import math
import os
import random
import re
import sys

def choose(n, k):
	if k > n:
		return 0
	k = min(k, n - k)
	(num, den) = (1, 1)
	for i in range(k):
		num *= n - i
		den *= i + 1
	return num // den

def squareCount(l):
	counter = collections.Counter(l)
	l = tuple(counter.keys())
	choose2 = collections.Counter()
	choose3 = collections.Counter()
	choose4 = collections.Counter()
	le = len(l)
	for n in counter:
		count = counter[n]
		if count >= 2:
			choose2[n] = choose(count, 2)
			if count >= 3:
				choose3[n] = choose(count, 3)
				if count >= 4:
					choose4[n] = choose(count, 4)
	t1 = 0
	t2 = 0
	for i in range(le):
		if counter[2 * l[i]] >= 2 and counter[l[i]] >= 4:
			t1 += choose4[l[i]] * choose2[2 * l[i]]
		if counter[l[i]] >= 2:
			for j in range(i + 1, le):
				if counter[l[j]] >= 2 and counter[l[i] + l[j]] >= 2:
					t2 += choose2[l[i]] * choose2[l[j]] * choose2[l[i] + l[j]]
	doubles = collections.Counter()
	for i in range(le):
		if counter[l[i]] >= 2 and counter[2 * l[i]] >= 2:
			doubles[2 * l[i]] = choose2[l[i]]
	pairs = collections.Counter()
	mpairs = collections.Counter()
	for i in range(le):
		for j in range(i + 1, le):
			if counter[l[i] + l[j]] >= 2:
				pairs[l[i] + l[j]] += counter[l[i]] * counter[l[j]]
				mpairs[l[i] + l[j]] += counter[l[i]] ** 2 * counter[l[j]] ** 2
	t3 = sum((pairs[s] * doubles[s] * choose2[s] for s in doubles if s in pairs))
	t4 = sum(((pairs[s] ** 2 - mpairs[s]) * choose2[s] for s in pairs)) // 2
	CD = collections.Counter()
	for d in range(le):
		if counter[l[d]] >= 3:
			for c in range(le):
				if l[c] < l[d]:
					CD[l[d] - l[c]] += choose3[l[d]] * counter[l[c]]
	s1 = 0
	s2 = 0
	s4 = 0
	for a in range(le):
		for b in range(a + 1, le):
			s1 += 2 * CD[l[a] + l[b]] * counter[l[a]] * counter[l[b]]
			if counter[l[a] + 2 * l[b]] >= 3:
				s2 += 2 * choose3[l[a] + 2 * l[b]] * counter[l[a]] * counter[l[b]] ** 2
			if counter[2 * l[a] + l[b]] >= 3:
				s2 += 2 * choose3[2 * l[a] + l[b]] * counter[l[b]] * counter[l[a]] ** 2
			if counter[l[b]] >= 2 and counter[l[a] + 2 * l[b]] >= 3:
				s4 += counter[l[a]] * choose2[l[b]] * choose3[l[a] + 2 * l[b]]
			if counter[l[a]] >= 2 and counter[2 * l[a] + l[b]] >= 3:
				s4 += counter[l[b]] * choose2[l[a]] * choose3[2 * l[a] + l[b]]
	s = (s1 - s2) // 6
	s3 = 0
	for a in range(le):
		if counter[l[a]] >= 3 and counter[3 * l[a]] >= 3:
			s3 += choose3[l[a]] * choose3[3 * l[a]]
	return t1 + t2 + t3 + t4 + s + s3 + s4
n = int(input())
l = list(map(int, input().rstrip().split()))
print(squareCount(l))


import collections
import math
import os
import random
import re
import sys

def choose(n, k):
	if k > n:
		return 0
	k = min(k, n - k)
	(num, den) = (1, 1)
	for i in range(k):
		num *= n - i
		den *= i + 1
	return num // den

def squareCount(l):
	counter = collections.Counter(l)
	l = tuple(counter.keys())
	choose2 = collections.Counter()
	choose3 = collections.Counter()
	choose4 = collections.Counter()
	le = len(l)
	for n in counter:
		count = counter[n]
		if count >= 2:
			choose2[n] = choose(count, 2)
			if count >= 3:
				choose3[n] = choose(count, 3)
				if count >= 4:
					choose4[n] = choose(count, 4)
	t1 = 0
	t2 = 0
	for i in range(le):
		if counter[2 * l[i]] >= 2 and counter[l[i]] >= 4:
			t1 += choose4[l[i]] * choose2[2 * l[i]]
		if counter[l[i]] >= 2:
			for j in range(i + 1, le):
				if counter[l[j]] >= 2 and counter[l[i] + l[j]] >= 2:
					t2 += choose2[l[i]] * choose2[l[j]] * choose2[l[i] + l[j]]
	doubles = collections.Counter()
	for i in range(le):
		if counter[l[i]] >= 2 and counter[2 * l[i]] >= 2:
			doubles[2 * l[i]] = choose2[l[i]]
	pairs = collections.Counter()
	mpairs = collections.Counter()
	for i in range(le):
		for j in range(i + 1, le):
			if counter[l[i] + l[j]] >= 2:
				pairs[l[i] + l[j]] += counter[l[i]] * counter[l[j]]
				mpairs[l[i] + l[j]] += counter[l[i]] ** 2 * counter[l[j]] ** 2
	t3 = sum((pairs[s] * doubles[s] * choose2[s] for s in doubles if s in pairs))
	t4 = sum(((pairs[s] ** 2 - mpairs[s]) * choose2[s] for s in pairs)) // 2
	CD = collections.Counter()
	for d in range(le):
		if counter[l[d]] >= 3:
			for c in range(le):
				if l[c] < l[d]:
					CD[l[d] - l[c]] += choose3[l[d]] * counter[l[c]]
	s1 = 0
	s2 = 0
	s4 = 0
	for a in range(le):
		for b in range(a + 1, le):
			s1 += 2 * CD[l[a] + l[b]] * counter[l[a]] * counter[l[b]]
			if counter[l[a] + 2 * l[b]] >= 3:
				s2 += 2 * choose3[l[a] + 2 * l[b]] * counter[l[a]] * counter[l[b]] ** 2
			if counter[2 * l[a] + l[b]] >= 3:
				s2 += 2 * choose3[2 * l[a] + l[b]] * counter[l[b]] * counter[l[a]] ** 2
			if counter[l[b]] >= 2 and counter[l[a] + 2 * l[b]] >= 3:
				s4 += counter[l[a]] * choose2[l[b]] * choose3[l[a] + 2 * l[b]]
			if counter[l[a]] >= 2 and counter[2 * l[a] + l[b]] >= 3:
				s4 += counter[l[b]] * choose2[l[a]] * choose3[2 * l[a] + l[b]]
	s = (s1 - s2) // 6
	s3 = 0
	for a in range(le):
		if counter[l[a]] >= 3 and counter[3 * l[a]] >= 3:
			s3 += choose3[l[a]] * choose3[3 * l[a]]
	return t1 + t2 + t3 + t4 + s + s3 + s4
n = int(input())
l = list(map(int, input().rstrip().split()))
print(squareCount(l))


import collections
import math
import os
import random
import re
import sys

def choose(n, k):
	if k > n:
		return 0
	k = min(k, n - k)
	(num, den) = (1, 1)
	for i in range(k):
		num *= n - i
		den *= i + 1
	return num // den

def squareCount(l):
	counter = collections.Counter(l)
	l = tuple(counter.keys())
	choose2 = collections.Counter()
	choose3 = collections.Counter()
	choose4 = collections.Counter()
	le = len(l)
	for n in counter:
		count = counter[n]
		if count >= 2:
			choose2[n] = choose(count, 2)
			if count >= 3:
				choose3[n] = choose(count, 3)
				if count >= 4:
					choose4[n] = choose(count, 4)
	t1 = 0
	t2 = 0
	for i in range(le):
		if counter[2 * l[i]] >= 2 and counter[l[i]] >= 4:
			t1 += choose4[l[i]] * choose2[2 * l[i]]
		if counter[l[i]] >= 2:
			for j in range(i + 1, le):
				if counter[l[j]] >= 2 and counter[l[i] + l[j]] >= 2:
					t2 += choose2[l[i]] * choose2[l[j]] * choose2[l[i] + l[j]]
	doubles = collections.Counter()
	for i in range(le):
		if counter[l[i]] >= 2 and counter[2 * l[i]] >= 2:
			doubles[2 * l[i]] = choose2[l[i]]
	pairs = collections.Counter()
	mpairs = collections.Counter()
	for i in range(le):
		for j in range(i + 1, le):
			if counter[l[i] + l[j]] >= 2:
				pairs[l[i] + l[j]] += counter[l[i]] * counter[l[j]]
				mpairs[l[i] + l[j]] += counter[l[i]] ** 2 * counter[l[j]] ** 2
	t3 = sum((pairs[s] * doubles[s] * choose2[s] for s in doubles if s in pairs))
	t4 = sum(((pairs[s] ** 2 - mpairs[s]) * choose2[s] for s in pairs)) // 2
	CD = collections.Counter()
	for d in range(le):
		if counter[l[d]] >= 3:
			for c in range(le):
				if l[c] < l[d]:
					CD[l[d] - l[c]] += choose3[l[d]] * counter[l[c]]
	s1 = 0
	s2 = 0
	s4 = 0
	for a in range(le):
		for b in range(a + 1, le):
			s1 += 2 * CD[l[a] + l[b]] * counter[l[a]] * counter[l[b]]
			if counter[l[a] + 2 * l[b]] >= 3:
				s2 += 2 * choose3[l[a] + 2 * l[b]] * counter[l[a]] * counter[l[b]] ** 2
			if counter[2 * l[a] + l[b]] >= 3:
				s2 += 2 * choose3[2 * l[a] + l[b]] * counter[l[b]] * counter[l[a]] ** 2
			if counter[l[b]] >= 2 and counter[l[a] + 2 * l[b]] >= 3:
				s4 += counter[l[a]] * choose2[l[b]] * choose3[l[a] + 2 * l[b]]
			if counter[l[a]] >= 2 and counter[2 * l[a] + l[b]] >= 3:
				s4 += counter[l[b]] * choose2[l[a]] * choose3[2 * l[a] + l[b]]
	s = (s1 - s2) // 6
	s3 = 0
	for a in range(le):
		if counter[l[a]] >= 3 and counter[3 * l[a]] >= 3:
			s3 += choose3[l[a]] * choose3[3 * l[a]]
	return t1 + t2 + t3 + t4 + s + s3 + s4
n = int(input())
l = list(map(int, input().rstrip().split()))
print(squareCount(l))


import collections
import math
import os
import random
import re
import sys

def choose(n, k):
	if k > n:
		return 0
	k = min(k, n - k)
	(num, den) = (1, 1)
	for i in range(k):
		num *= n - i
		den *= i + 1
	return num // den

def squareCount(l):
	counter = collections.Counter(l)
	l = tuple(counter.keys())
	choose2 = collections.Counter()
	choose3 = collections.Counter()
	choose4 = collections.Counter()
	le = len(l)
	for n in counter:
		count = counter[n]
		if count >= 2:
			choose2[n] = choose(count, 2)
			if count >= 3:
				choose3[n] = choose(count, 3)
				if count >= 4:
					choose4[n] = choose(count, 4)
	t1 = 0
	t2 = 0
	for i in range(le):
		if counter[2 * l[i]] >= 2 and counter[l[i]] >= 4:
			t1 += choose4[l[i]] * choose2[2 * l[i]]
		if counter[l[i]] >= 2:
			for j in range(i + 1, le):
				if counter[l[j]] >= 2 and counter[l[i] + l[j]] >= 2:
					t2 += choose2[l[i]] * choose2[l[j]] * choose2[l[i] + l[j]]
	doubles = collections.Counter()
	for i in range(le):
		if counter[l[i]] >= 2 and counter[2 * l[i]] >= 2:
			doubles[2 * l[i]] = choose2[l[i]]
	pairs = collections.Counter()
	mpairs = collections.Counter()
	for i in range(le):
		for j in range(i + 1, le):
			if counter[l[i] + l[j]] >= 2:
				pairs[l[i] + l[j]] += counter[l[i]] * counter[l[j]]
				mpairs[l[i] + l[j]] += counter[l[i]] ** 2 * counter[l[j]] ** 2
	t3 = sum((pairs[s] * doubles[s] * choose2[s] for s in doubles if s in pairs))
	t4 = sum(((pairs[s] ** 2 - mpairs[s]) * choose2[s] for s in pairs)) // 2
	CD = collections.Counter()
	for d in range(le):
		if counter[l[d]] >= 3:
			for c in range(le):
				if l[c] < l[d]:
					CD[l[d] - l[c]] += choose3[l[d]] * counter[l[c]]
	s1 = 0
	s2 = 0
	s4 = 0
	for a in range(le):
		for b in range(a + 1, le):
			s1 += 2 * CD[l[a] + l[b]] * counter[l[a]] * counter[l[b]]
			if counter[l[a] + 2 * l[b]] >= 3:
				s2 += 2 * choose3[l[a] + 2 * l[b]] * counter[l[a]] * counter[l[b]] ** 2
			if counter[2 * l[a] + l[b]] >= 3:
				s2 += 2 * choose3[2 * l[a] + l[b]] * counter[l[b]] * counter[l[a]] ** 2
			if counter[l[b]] >= 2 and counter[l[a] + 2 * l[b]] >= 3:
				s4 += counter[l[a]] * choose2[l[b]] * choose3[l[a] + 2 * l[b]]
			if counter[l[a]] >= 2 and counter[2 * l[a] + l[b]] >= 3:
				s4 += counter[l[b]] * choose2[l[a]] * choose3[2 * l[a] + l[b]]
	s = (s1 - s2) // 6
	s3 = 0
	for a in range(le):
		if counter[l[a]] >= 3 and counter[3 * l[a]] >= 3:
			s3 += choose3[l[a]] * choose3[3 * l[a]]
	return t1 + t2 + t3 + t4 + s + s3 + s4
n = int(input())
l = list(map(int, input().rstrip().split()))
print(squareCount(l))


import collections
import math
import os
import random
import re
import sys

def choose(n, k):
	if k > n:
		return 0
	k = min(k, n - k)
	(num, den) = (1, 1)
	for i in range(k):
		num *= n - i
		den *= i + 1
	return num // den

def squareCount(l):
	counter = collections.Counter(l)
	l = tuple(counter.keys())
	choose2 = collections.Counter()
	choose3 = collections.Counter()
	choose4 = collections.Counter()
	le = len(l)
	for n in counter:
		count = counter[n]
		if count >= 2:
			choose2[n] = choose(count, 2)
			if count >= 3:
				choose3[n] = choose(count, 3)
				if count >= 4:
					choose4[n] = choose(count, 4)
	t1 = 0
	t2 = 0
	for i in range(le):
		if counter[2 * l[i]] >= 2 and counter[l[i]] >= 4:
			t1 += choose4[l[i]] * choose2[2 * l[i]]
		if counter[l[i]] >= 2:
			for j in range(i + 1, le):
				if counter[l[j]] >= 2 and counter[l[i] + l[j]] >= 2:
					t2 += choose2[l[i]] * choose2[l[j]] * choose2[l[i] + l[j]]
	doubles = collections.Counter()
	for i in range(le):
		if counter[l[i]] >= 2 and counter[2 * l[i]] >= 2:
			doubles[2 * l[i]] = choose2[l[i]]
	pairs = collections.Counter()
	mpairs = collections.Counter()
	for i in range(le):
		for j in range(i + 1, le):
			if counter[l[i] + l[j]] >= 2:
				pairs[l[i] + l[j]] += counter[l[i]] * counter[l[j]]
				mpairs[l[i] + l[j]] += counter[l[i]] ** 2 * counter[l[j]] ** 2
	t3 = sum((pairs[s] * doubles[s] * choose2[s] for s in doubles if s in pairs))
	t4 = sum(((pairs[s] ** 2 - mpairs[s]) * choose2[s] for s in pairs)) // 2
	CD = collections.Counter()
	for d in range(le):
		if counter[l[d]] >= 3:
			for c in range(le):
				if l[c] < l[d]:
					CD[l[d] - l[c]] += choose3[l[d]] * counter[l[c]]
	s1 = 0
	s2 = 0
	s4 = 0
	for a in range(le):
		for b in range(a + 1, le):
			s1 += 2 * CD[l[a] + l[b]] * counter[l[a]] * counter[l[b]]
			if counter[l[a] + 2 * l[b]] >= 3:
				s2 += 2 * choose3[l[a] + 2 * l[b]] * counter[l[a]] * counter[l[b]] ** 2
			if counter[2 * l[a] + l[b]] >= 3:
				s2 += 2 * choose3[2 * l[a] + l[b]] * counter[l[b]] * counter[l[a]] ** 2
			if counter[l[b]] >= 2 and counter[l[a] + 2 * l[b]] >= 3:
				s4 += counter[l[a]] * choose2[l[b]] * choose3[l[a] + 2 * l[b]]
			if counter[l[a]] >= 2 and counter[2 * l[a] + l[b]] >= 3:
				s4 += counter[l[b]] * choose2[l[a]] * choose3[2 * l[a] + l[b]]
	s = (s1 - s2) // 6
	s3 = 0
	for a in range(le):
		if counter[l[a]] >= 3 and counter[3 * l[a]] >= 3:
			s3 += choose3[l[a]] * choose3[3 * l[a]]
	return t1 + t2 + t3 + t4 + s + s3 + s4
n = int(input())
l = list(map(int, input().rstrip().split()))
print(squareCount(l))


import collections
import math
import os
import random
import re
import sys

def choose(n, k):
	if k > n:
		return 0
	k = min(k, n - k)
	(num, den) = (1, 1)
	for i in range(k):
		num *= n - i
		den *= i + 1
	return num // den

def squareCount(l):
	counter = collections.Counter(l)
	l = tuple(counter.keys())
	choose2 = collections.Counter()
	choose3 = collections.Counter()
	choose4 = collections.Counter()
	le = len(l)
	for n in counter:
		count = counter[n]
		if count >= 2:
			choose2[n] = choose(count, 2)
			if count >= 3:
				choose3[n] = choose(count, 3)
				if count >= 4:
					choose4[n] = choose(count, 4)
	t1 = 0
	t2 = 0
	for i in range(le):
		if counter[2 * l[i]] >= 2 and counter[l[i]] >= 4:
			t1 += choose4[l[i]] * choose2[2 * l[i]]
		if counter[l[i]] >= 2:
			for j in range(i + 1, le):
				if counter[l[j]] >= 2 and counter[l[i] + l[j]] >= 2:
					t2 += choose2[l[i]] * choose2[l[j]] * choose2[l[i] + l[j]]
	doubles = collections.Counter()
	for i in range(le):
		if counter[l[i]] >= 2 and counter[2 * l[i]] >= 2:
			doubles[2 * l[i]] = choose2[l[i]]
	pairs = collections.Counter()
	mpairs = collections.Counter()
	for i in range(le):
		for j in range(i + 1, le):
			if counter[l[i] + l[j]] >= 2:
				pairs[l[i] + l[j]] += counter[l[i]] * counter[l[j]]
				mpairs[l[i] + l[j]] += counter[l[i]] ** 2 * counter[l[j]] ** 2
	t3 = sum((pairs[s] * doubles[s] * choose2[s] for s in doubles if s in pairs))
	t4 = sum(((pairs[s] ** 2 - mpairs[s]) * choose2[s] for s in pairs)) // 2
	CD = collections.Counter()
	for d in range(le):
		if counter[l[d]] >= 3:
			for c in range(le):
				if l[c] < l[d]:
					CD[l[d] - l[c]] += choose3[l[d]] * counter[l[c]]
	s1 = 0
	s2 = 0
	s4 = 0
	for a in range(le):
		for b in range(a + 1, le):
			s1 += 2 * CD[l[a] + l[b]] * counter[l[a]] * counter[l[b]]
			if counter[l[a] + 2 * l[b]] >= 3:
				s2 += 2 * choose3[l[a] + 2 * l[b]] * counter[l[a]] * counter[l[b]] ** 2
			if counter[2 * l[a] + l[b]] >= 3:
				s2 += 2 * choose3[2 * l[a] + l[b]] * counter[l[b]] * counter[l[a]] ** 2
			if counter[l[b]] >= 2 and counter[l[a] + 2 * l[b]] >= 3:
				s4 += counter[l[a]] * choose2[l[b]] * choose3[l[a] + 2 * l[b]]
			if counter[l[a]] >= 2 and counter[2 * l[a] + l[b]] >= 3:
				s4 += counter[l[b]] * choose2[l[a]] * choose3[2 * l[a] + l[b]]
	s = (s1 - s2) // 6
	s3 = 0
	for a in range(le):
		if counter[l[a]] >= 3 and counter[3 * l[a]] >= 3:
			s3 += choose3[l[a]] * choose3[3 * l[a]]
	return t1 + t2 + t3 + t4 + s + s3 + s4
n = int(input())
l = list(map(int, input().rstrip().split()))
print(squareCount(l))


import collections
import math
import os
import random
import re
import sys

def choose(n, k):
	if k > n:
		return 0
	k = min(k, n - k)
	(num, den) = (1, 1)
	for i in range(k):
		num *= n - i
		den *= i + 1
	return num // den

def squareCount(l):
	counter = collections.Counter(l)
	l = tuple(counter.keys())
	choose2 = collections.Counter()
	choose3 = collections.Counter()
	choose4 = collections.Counter()
	le = len(l)
	for n in counter:
		count = counter[n]
		if count >= 2:
			choose2[n] = choose(count, 2)
			if count >= 3:
				choose3[n] = choose(count, 3)
				if count >= 4:
					choose4[n] = choose(count, 4)
	t1 = 0
	t2 = 0
	for i in range(le):
		if counter[2 * l[i]] >= 2 and counter[l[i]] >= 4:
			t1 += choose4[l[i]] * choose2[2 * l[i]]
		if counter[l[i]] >= 2:
			for j in range(i + 1, le):
				if counter[l[j]] >= 2 and counter[l[i] + l[j]] >= 2:
					t2 += choose2[l[i]] * choose2[l[j]] * choose2[l[i] + l[j]]
	doubles = collections.Counter()
	for i in range(le):
		if counter[l[i]] >= 2 and counter[2 * l[i]] >= 2:
			doubles[2 * l[i]] = choose2[l[i]]
	pairs = collections.Counter()
	mpairs = collections.Counter()
	for i in range(le):
		for j in range(i + 1, le):
			if counter[l[i] + l[j]] >= 2:
				pairs[l[i] + l[j]] += counter[l[i]] * counter[l[j]]
				mpairs[l[i] + l[j]] += counter[l[i]] ** 2 * counter[l[j]] ** 2
	t3 = sum((pairs[s] * doubles[s] * choose2[s] for s in doubles if s in pairs))
	t4 = sum(((pairs[s] ** 2 - mpairs[s]) * choose2[s] for s in pairs)) // 2
	CD = collections.Counter()
	for d in range(le):
		if counter[l[d]] >= 3:
			for c in range(le):
				if l[c] < l[d]:
					CD[l[d] - l[c]] += choose3[l[d]] * counter[l[c]]
	s1 = 0
	s2 = 0
	s4 = 0
	for a in range(le):
		for b in range(a + 1, le):
			s1 += 2 * CD[l[a] + l[b]] * counter[l[a]] * counter[l[b]]
			if counter[l[a] + 2 * l[b]] >= 3:
				s2 += 2 * choose3[l[a] + 2 * l[b]] * counter[l[a]] * counter[l[b]] ** 2
			if counter[2 * l[a] + l[b]] >= 3:
				s2 += 2 * choose3[2 * l[a] + l[b]] * counter[l[b]] * counter[l[a]] ** 2
			if counter[l[b]] >= 2 and counter[l[a] + 2 * l[b]] >= 3:
				s4 += counter[l[a]] * choose2[l[b]] * choose3[l[a] + 2 * l[b]]
			if counter[l[a]] >= 2 and counter[2 * l[a] + l[b]] >= 3:
				s4 += counter[l[b]] * choose2[l[a]] * choose3[2 * l[a] + l[b]]
	s = (s1 - s2) // 6
	s3 = 0
	for a in range(le):
		if counter[l[a]] >= 3 and counter[3 * l[a]] >= 3:
			s3 += choose3[l[a]] * choose3[3 * l[a]]
	return t1 + t2 + t3 + t4 + s + s3 + s4
n = int(input())
l = list(map(int, input().rstrip().split()))
print(squareCount(l))


import collections
import math
import os
import random
import re
import sys

def choose(n, k):
	if k > n:
		return 0
	k = min(k, n - k)
	(num, den) = (1, 1)
	for i in range(k):
		num *= n - i
		den *= i + 1
	return num // den

def squareCount(l):
	counter = collections.Counter(l)
	l = tuple(counter.keys())
	choose2 = collections.Counter()
	choose3 = collections.Counter()
	choose4 = collections.Counter()
	le = len(l)
	for n in counter:
		count = counter[n]
		if count >= 2:
			choose2[n] = choose(count, 2)
			if count >= 3:
				choose3[n] = choose(count, 3)
				if count >= 4:
					choose4[n] = choose(count, 4)
	t1 = 0
	t2 = 0
	for i in range(le):
		if counter[2 * l[i]] >= 2 and counter[l[i]] >= 4:
			t1 += choose4[l[i]] * choose2[2 * l[i]]
		if counter[l[i]] >= 2:
			for j in range(i + 1, le):
				if counter[l[j]] >= 2 and counter[l[i] + l[j]] >= 2:
					t2 += choose2[l[i]] * choose2[l[j]] * choose2[l[i] + l[j]]
	doubles = collections.Counter()
	for i in range(le):
		if counter[l[i]] >= 2 and counter[2 * l[i]] >= 2:
			doubles[2 * l[i]] = choose2[l[i]]
	pairs = collections.Counter()
	mpairs = collections.Counter()
	for i in range(le):
		for j in range(i + 1, le):
			if counter[l[i] + l[j]] >= 2:
				pairs[l[i] + l[j]] += counter[l[i]] * counter[l[j]]
				mpairs[l[i] + l[j]] += counter[l[i]] ** 2 * counter[l[j]] ** 2
	t3 = sum((pairs[s] * doubles[s] * choose2[s] for s in doubles if s in pairs))
	t4 = sum(((pairs[s] ** 2 - mpairs[s]) * choose2[s] for s in pairs)) // 2
	CD = collections.Counter()
	for d in range(le):
		if counter[l[d]] >= 3:
			for c in range(le):
				if l[c] < l[d]:
					CD[l[d] - l[c]] += choose3[l[d]] * counter[l[c]]
	s1 = 0
	s2 = 0
	s4 = 0
	for a in range(le):
		for b in range(a + 1, le):
			s1 += 2 * CD[l[a] + l[b]] * counter[l[a]] * counter[l[b]]
			if counter[l[a] + 2 * l[b]] >= 3:
				s2 += 2 * choose3[l[a] + 2 * l[b]] * counter[l[a]] * counter[l[b]] ** 2
			if counter[2 * l[a] + l[b]] >= 3:
				s2 += 2 * choose3[2 * l[a] + l[b]] * counter[l[b]] * counter[l[a]] ** 2
			if counter[l[b]] >= 2 and counter[l[a] + 2 * l[b]] >= 3:
				s4 += counter[l[a]] * choose2[l[b]] * choose3[l[a] + 2 * l[b]]
			if counter[l[a]] >= 2 and counter[2 * l[a] + l[b]] >= 3:
				s4 += counter[l[b]] * choose2[l[a]] * choose3[2 * l[a] + l[b]]
	s = (s1 - s2) // 6
	s3 = 0
	for a in range(le):
		if counter[l[a]] >= 3 and counter[3 * l[a]] >= 3:
			s3 += choose3[l[a]] * choose3[3 * l[a]]
	return t1 + t2 + t3 + t4 + s + s3 + s4
n = int(input())
l = list(map(int, input().rstrip().split()))
print(squareCount(l))


import collections
import math
import os
import random
import re
import sys

def choose(n, k):
	if k > n:
		return 0
	k = min(k, n - k)
	(num, den) = (1, 1)
	for i in range(k):
		num *= n - i
		den *= i + 1
	return num // den

def squareCount(l):
	counter = collections.Counter(l)
	l = tuple(counter.keys())
	choose2 = collections.Counter()
	choose3 = collections.Counter()
	choose4 = collections.Counter()
	le = len(l)
	for n in counter:
		count = counter[n]
		if count >= 2:
			choose2[n] = choose(count, 2)
			if count >= 3:
				choose3[n] = choose(count, 3)
				if count >= 4:
					choose4[n] = choose(count, 4)
	t1 = 0
	t2 = 0
	for i in range(le):
		if counter[2 * l[i]] >= 2 and counter[l[i]] >= 4:
			t1 += choose4[l[i]] * choose2[2 * l[i]]
		if counter[l[i]] >= 2:
			for j in range(i + 1, le):
				if counter[l[j]] >= 2 and counter[l[i] + l[j]] >= 2:
					t2 += choose2[l[i]] * choose2[l[j]] * choose2[l[i] + l[j]]
	doubles = collections.Counter()
	for i in range(le):
		if counter[l[i]] >= 2 and counter[2 * l[i]] >= 2:
			doubles[2 * l[i]] = choose2[l[i]]
	pairs = collections.Counter()
	mpairs = collections.Counter()
	for i in range(le):
		for j in range(i + 1, le):
			if counter[l[i] + l[j]] >= 2:
				pairs[l[i] + l[j]] += counter[l[i]] * counter[l[j]]
				mpairs[l[i] + l[j]] += counter[l[i]] ** 2 * counter[l[j]] ** 2
	t3 = sum((pairs[s] * doubles[s] * choose2[s] for s in doubles if s in pairs))
	t4 = sum(((pairs[s] ** 2 - mpairs[s]) * choose2[s] for s in pairs)) // 2
	CD = collections.Counter()
	for d in range(le):
		if counter[l[d]] >= 3:
			for c in range(le):
				if l[c] < l[d]:
					CD[l[d] - l[c]] += choose3[l[d]] * counter[l[c]]
	s1 = 0
	s2 = 0
	s4 = 0
	for a in range(le):
		for b in range(a + 1, le):
			s1 += 2 * CD[l[a] + l[b]] * counter[l[a]] * counter[l[b]]
			if counter[l[a] + 2 * l[b]] >= 3:
				s2 += 2 * choose3[l[a] + 2 * l[b]] * counter[l[a]] * counter[l[b]] ** 2
			if counter[2 * l[a] + l[b]] >= 3:
				s2 += 2 * choose3[2 * l[a] + l[b]] * counter[l[b]] * counter[l[a]] ** 2
			if counter[l[b]] >= 2 and counter[l[a] + 2 * l[b]] >= 3:
				s4 += counter[l[a]] * choose2[l[b]] * choose3[l[a] + 2 * l[b]]
			if counter[l[a]] >= 2 and counter[2 * l[a] + l[b]] >= 3:
				s4 += counter[l[b]] * choose2[l[a]] * choose3[2 * l[a] + l[b]]
	s = (s1 - s2) // 6
	s3 = 0
	for a in range(le):
		if counter[l[a]] >= 3 and counter[3 * l[a]] >= 3:
			s3 += choose3[l[a]] * choose3[3 * l[a]]
	return t1 + t2 + t3 + t4 + s + s3 + s4
n = int(input())
l = list(map(int, input().rstrip().split()))
print(squareCount(l))


import collections
import math
import os
import random
import re
import sys

def choose(n, k):
	if k > n:
		return 0
	k = min(k, n - k)
	(num, den) = (1, 1)
	for i in range(k):
		num *= n - i
		den *= i + 1
	return num // den

def squareCount(l):
	counter = collections.Counter(l)
	l = tuple(counter.keys())
	choose2 = collections.Counter()
	choose3 = collections.Counter()
	choose4 = collections.Counter()
	le = len(l)
	for n in counter:
		count = counter[n]
		if count >= 2:
			choose2[n] = choose(count, 2)
			if count >= 3:
				choose3[n] = choose(count, 3)
				if count >= 4:
					choose4[n] = choose(count, 4)
	t1 = 0
	t2 = 0
	for i in range(le):
		if counter[2 * l[i]] >= 2 and counter[l[i]] >= 4:
			t1 += choose4[l[i]] * choose2[2 * l[i]]
		if counter[l[i]] >= 2:
			for j in range(i + 1, le):
				if counter[l[j]] >= 2 and counter[l[i] + l[j]] >= 2:
					t2 += choose2[l[i]] * choose2[l[j]] * choose2[l[i] + l[j]]
	doubles = collections.Counter()
	for i in range(le):
		if counter[l[i]] >= 2 and counter[2 * l[i]] >= 2:
			doubles[2 * l[i]] = choose2[l[i]]
	pairs = collections.Counter()
	mpairs = collections.Counter()
	for i in range(le):
		for j in range(i + 1, le):
			if counter[l[i] + l[j]] >= 2:
				pairs[l[i] + l[j]] += counter[l[i]] * counter[l[j]]
				mpairs[l[i] + l[j]] += counter[l[i]] ** 2 * counter[l[j]] ** 2
	t3 = sum((pairs[s] * doubles[s] * choose2[s] for s in doubles if s in pairs))
	t4 = sum(((pairs[s] ** 2 - mpairs[s]) * choose2[s] for s in pairs)) // 2
	CD = collections.Counter()
	for d in range(le):
		if counter[l[d]] >= 3:
			for c in range(le):
				if l[c] < l[d]:
					CD[l[d] - l[c]] += choose3[l[d]] * counter[l[c]]
	s1 = 0
	s2 = 0
	s4 = 0
	for a in range(le):
		for b in range(a + 1, le):
			s1 += 2 * CD[l[a] + l[b]] * counter[l[a]] * counter[l[b]]
			if counter[l[a] + 2 * l[b]] >= 3:
				s2 += 2 * choose3[l[a] + 2 * l[b]] * counter[l[a]] * counter[l[b]] ** 2
			if counter[2 * l[a] + l[b]] >= 3:
				s2 += 2 * choose3[2 * l[a] + l[b]] * counter[l[b]] * counter[l[a]] ** 2
			if counter[l[b]] >= 2 and counter[l[a] + 2 * l[b]] >= 3:
				s4 += counter[l[a]] * choose2[l[b]] * choose3[l[a] + 2 * l[b]]
			if counter[l[a]] >= 2 and counter[2 * l[a] + l[b]] >= 3:
				s4 += counter[l[b]] * choose2[l[a]] * choose3[2 * l[a] + l[b]]
	s = (s1 - s2) // 6
	s3 = 0
	for a in range(le):
		if counter[l[a]] >= 3 and counter[3 * l[a]] >= 3:
			s3 += choose3[l[a]] * choose3[3 * l[a]]
	return t1 + t2 + t3 + t4 + s + s3 + s4
n = int(input())
l = list(map(int, input().rstrip().split()))
print(squareCount(l))


import collections
import math
import os
import random
import re
import sys

def choose(n, k):
	if k > n:
		return 0
	k = min(k, n - k)
	(num, den) = (1, 1)
	for i in range(k):
		num *= n - i
		den *= i + 1
	return num // den

def squareCount(l):
	counter = collections.Counter(l)
	l = tuple(counter.keys())
	choose2 = collections.Counter()
	choose3 = collections.Counter()
	choose4 = collections.Counter()
	le = len(l)
	for n in counter:
		count = counter[n]
		if count >= 2:
			choose2[n] = choose(count, 2)
			if count >= 3:
				choose3[n] = choose(count, 3)
				if count >= 4:
					choose4[n] = choose(count, 4)
	t1 = 0
	t2 = 0
	for i in range(le):
		if counter[2 * l[i]] >= 2 and counter[l[i]] >= 4:
			t1 += choose4[l[i]] * choose2[2 * l[i]]
		if counter[l[i]] >= 2:
			for j in range(i + 1, le):
				if counter[l[j]] >= 2 and counter[l[i] + l[j]] >= 2:
					t2 += choose2[l[i]] * choose2[l[j]] * choose2[l[i] + l[j]]
	doubles = collections.Counter()
	for i in range(le):
		if counter[l[i]] >= 2 and counter[2 * l[i]] >= 2:
			doubles[2 * l[i]] = choose2[l[i]]
	pairs = collections.Counter()
	mpairs = collections.Counter()
	for i in range(le):
		for j in range(i + 1, le):
			if counter[l[i] + l[j]] >= 2:
				pairs[l[i] + l[j]] += counter[l[i]] * counter[l[j]]
				mpairs[l[i] + l[j]] += counter[l[i]] ** 2 * counter[l[j]] ** 2
	t3 = sum((pairs[s] * doubles[s] * choose2[s] for s in doubles if s in pairs))
	t4 = sum(((pairs[s] ** 2 - mpairs[s]) * choose2[s] for s in pairs)) // 2
	CD = collections.Counter()
	for d in range(le):
		if counter[l[d]] >= 3:
			for c in range(le):
				if l[c] < l[d]:
					CD[l[d] - l[c]] += choose3[l[d]] * counter[l[c]]
	s1 = 0
	s2 = 0
	s4 = 0
	for a in range(le):
		for b in range(a + 1, le):
			s1 += 2 * CD[l[a] + l[b]] * counter[l[a]] * counter[l[b]]
			if counter[l[a] + 2 * l[b]] >= 3:
				s2 += 2 * choose3[l[a] + 2 * l[b]] * counter[l[a]] * counter[l[b]] ** 2
			if counter[2 * l[a] + l[b]] >= 3:
				s2 += 2 * choose3[2 * l[a] + l[b]] * counter[l[b]] * counter[l[a]] ** 2
			if counter[l[b]] >= 2 and counter[l[a] + 2 * l[b]] >= 3:
				s4 += counter[l[a]] * choose2[l[b]] * choose3[l[a] + 2 * l[b]]
			if counter[l[a]] >= 2 and counter[2 * l[a] + l[b]] >= 3:
				s4 += counter[l[b]] * choose2[l[a]] * choose3[2 * l[a] + l[b]]
	s = (s1 - s2) // 6
	s3 = 0
	for a in range(le):
		if counter[l[a]] >= 3 and counter[3 * l[a]] >= 3:
			s3 += choose3[l[a]] * choose3[3 * l[a]]
	return t1 + t2 + t3 + t4 + s + s3 + s4
n = int(input())
l = list(map(int, input().rstrip().split()))
print(squareCount(l))


import collections
import math
import os
import random
import re
import sys

def choose(n, k):
	if k > n:
		return 0
	k = min(k, n - k)
	(num, den) = (1, 1)
	for i in range(k):
		num *= n - i
		den *= i + 1
	return num // den

def squareCount(l):
	counter = collections.Counter(l)
	l = tuple(counter.keys())
	choose2 = collections.Counter()
	choose3 = collections.Counter()
	choose4 = collections.Counter()
	le = len(l)
	for n in counter:
		count = counter[n]
		if count >= 2:
			choose2[n] = choose(count, 2)
			if count >= 3:
				choose3[n] = choose(count, 3)
				if count >= 4:
					choose4[n] = choose(count, 4)
	t1 = 0
	t2 = 0
	for i in range(le):
		if counter[2 * l[i]] >= 2 and counter[l[i]] >= 4:
			t1 += choose4[l[i]] * choose2[2 * l[i]]
		if counter[l[i]] >= 2:
			for j in range(i + 1, le):
				if counter[l[j]] >= 2 and counter[l[i] + l[j]] >= 2:
					t2 += choose2[l[i]] * choose2[l[j]] * choose2[l[i] + l[j]]
	doubles = collections.Counter()
	for i in range(le):
		if counter[l[i]] >= 2 and counter[2 * l[i]] >= 2:
			doubles[2 * l[i]] = choose2[l[i]]
	pairs = collections.Counter()
	mpairs = collections.Counter()
	for i in range(le):
		for j in range(i + 1, le):
			if counter[l[i] + l[j]] >= 2:
				pairs[l[i] + l[j]] += counter[l[i]] * counter[l[j]]
				mpairs[l[i] + l[j]] += counter[l[i]] ** 2 * counter[l[j]] ** 2
	t3 = sum((pairs[s] * doubles[s] * choose2[s] for s in doubles if s in pairs))
	t4 = sum(((pairs[s] ** 2 - mpairs[s]) * choose2[s] for s in pairs)) // 2
	CD = collections.Counter()
	for d in range(le):
		if counter[l[d]] >= 3:
			for c in range(le):
				if l[c] < l[d]:
					CD[l[d] - l[c]] += choose3[l[d]] * counter[l[c]]
	s1 = 0
	s2 = 0
	s4 = 0
	for a in range(le):
		for b in range(a + 1, le):
			s1 += 2 * CD[l[a] + l[b]] * counter[l[a]] * counter[l[b]]
			if counter[l[a] + 2 * l[b]] >= 3:
				s2 += 2 * choose3[l[a] + 2 * l[b]] * counter[l[a]] * counter[l[b]] ** 2
			if counter[2 * l[a] + l[b]] >= 3:
				s2 += 2 * choose3[2 * l[a] + l[b]] * counter[l[b]] * counter[l[a]] ** 2
			if counter[l[b]] >= 2 and counter[l[a] + 2 * l[b]] >= 3:
				s4 += counter[l[a]] * choose2[l[b]] * choose3[l[a] + 2 * l[b]]
			if counter[l[a]] >= 2 and counter[2 * l[a] + l[b]] >= 3:
				s4 += counter[l[b]] * choose2[l[a]] * choose3[2 * l[a] + l[b]]
	s = (s1 - s2) // 6
	s3 = 0
	for a in range(le):
		if counter[l[a]] >= 3 and counter[3 * l[a]] >= 3:
			s3 += choose3[l[a]] * choose3[3 * l[a]]
	return t1 + t2 + t3 + t4 + s + s3 + s4
n = int(input())
l = list(map(int, input().rstrip().split()))
print(squareCount(l))


import collections
import math
import os
import random
import re
import sys

def choose(n, k):
	if k > n:
		return 0
	k = min(k, n - k)
	(num, den) = (1, 1)
	for i in range(k):
		num *= n - i
		den *= i + 1
	return num // den

def squareCount(l):
	counter = collections.Counter(l)
	l = tuple(counter.keys())
	choose2 = collections.Counter()
	choose3 = collections.Counter()
	choose4 = collections.Counter()
	le = len(l)
	for n in counter:
		count = counter[n]
		if count >= 2:
			choose2[n] = choose(count, 2)
			if count >= 3:
				choose3[n] = choose(count, 3)
				if count >= 4:
					choose4[n] = choose(count, 4)
	t1 = 0
	t2 = 0
	for i in range(le):
		if counter[2 * l[i]] >= 2 and counter[l[i]] >= 4:
			t1 += choose4[l[i]] * choose2[2 * l[i]]
		if counter[l[i]] >= 2:
			for j in range(i + 1, le):
				if counter[l[j]] >= 2 and counter[l[i] + l[j]] >= 2:
					t2 += choose2[l[i]] * choose2[l[j]] * choose2[l[i] + l[j]]
	doubles = collections.Counter()
	for i in range(le):
		if counter[l[i]] >= 2 and counter[2 * l[i]] >= 2:
			doubles[2 * l[i]] = choose2[l[i]]
	pairs = collections.Counter()
	mpairs = collections.Counter()
	for i in range(le):
		for j in range(i + 1, le):
			if counter[l[i] + l[j]] >= 2:
				pairs[l[i] + l[j]] += counter[l[i]] * counter[l[j]]
				mpairs[l[i] + l[j]] += counter[l[i]] ** 2 * counter[l[j]] ** 2
	t3 = sum((pairs[s] * doubles[s] * choose2[s] for s in doubles if s in pairs))
	t4 = sum(((pairs[s] ** 2 - mpairs[s]) * choose2[s] for s in pairs)) // 2
	CD = collections.Counter()
	for d in range(le):
		if counter[l[d]] >= 3:
			for c in range(le):
				if l[c] < l[d]:
					CD[l[d] - l[c]] += choose3[l[d]] * counter[l[c]]
	s1 = 0
	s2 = 0
	s4 = 0
	for a in range(le):
		for b in range(a + 1, le):
			s1 += 2 * CD[l[a] + l[b]] * counter[l[a]] * counter[l[b]]
			if counter[l[a] + 2 * l[b]] >= 3:
				s2 += 2 * choose3[l[a] + 2 * l[b]] * counter[l[a]] * counter[l[b]] ** 2
			if counter[2 * l[a] + l[b]] >= 3:
				s2 += 2 * choose3[2 * l[a] + l[b]] * counter[l[b]] * counter[l[a]] ** 2
			if counter[l[b]] >= 2 and counter[l[a] + 2 * l[b]] >= 3:
				s4 += counter[l[a]] * choose2[l[b]] * choose3[l[a] + 2 * l[b]]
			if counter[l[a]] >= 2 and counter[2 * l[a] + l[b]] >= 3:
				s4 += counter[l[b]] * choose2[l[a]] * choose3[2 * l[a] + l[b]]
	s = (s1 - s2) // 6
	s3 = 0
	for a in range(le):
		if counter[l[a]] >= 3 and counter[3 * l[a]] >= 3:
			s3 += choose3[l[a]] * choose3[3 * l[a]]
	return t1 + t2 + t3 + t4 + s + s3 + s4
n = int(input())
l = list(map(int, input().rstrip().split()))
print(squareCount(l))


import collections
import math
import os
import random
import re
import sys

def choose(n, k):
	if k > n:
		return 0
	k = min(k, n - k)
	(num, den) = (1, 1)
	for i in range(k):
		num *= n - i
		den *= i + 1
	return num // den

def squareCount(l):
	counter = collections.Counter(l)
	l = tuple(counter.keys())
	choose2 = collections.Counter()
	choose3 = collections.Counter()
	choose4 = collections.Counter()
	le = len(l)
	for n in counter:
		count = counter[n]
		if count >= 2:
			choose2[n] = choose(count, 2)
			if count >= 3:
				choose3[n] = choose(count, 3)
				if count >= 4:
					choose4[n] = choose(count, 4)
	t1 = 0
	t2 = 0
	for i in range(le):
		if counter[2 * l[i]] >= 2 and counter[l[i]] >= 4:
			t1 += choose4[l[i]] * choose2[2 * l[i]]
		if counter[l[i]] >= 2:
			for j in range(i + 1, le):
				if counter[l[j]] >= 2 and counter[l[i] + l[j]] >= 2:
					t2 += choose2[l[i]] * choose2[l[j]] * choose2[l[i] + l[j]]
	doubles = collections.Counter()
	for i in range(le):
		if counter[l[i]] >= 2 and counter[2 * l[i]] >= 2:
			doubles[2 * l[i]] = choose2[l[i]]
	pairs = collections.Counter()
	mpairs = collections.Counter()
	for i in range(le):
		for j in range(i + 1, le):
			if counter[l[i] + l[j]] >= 2:
				pairs[l[i] + l[j]] += counter[l[i]] * counter[l[j]]
				mpairs[l[i] + l[j]] += counter[l[i]] ** 2 * counter[l[j]] ** 2
	t3 = sum((pairs[s] * doubles[s] * choose2[s] for s in doubles if s in pairs))
	t4 = sum(((pairs[s] ** 2 - mpairs[s]) * choose2[s] for s in pairs)) // 2
	CD = collections.Counter()
	for d in range(le):
		if counter[l[d]] >= 3:
			for c in range(le):
				if l[c] < l[d]:
					CD[l[d] - l[c]] += choose3[l[d]] * counter[l[c]]
	s1 = 0
	s2 = 0
	s4 = 0
	for a in range(le):
		for b in range(a + 1, le):
			s1 += 2 * CD[l[a] + l[b]] * counter[l[a]] * counter[l[b]]
			if counter[l[a] + 2 * l[b]] >= 3:
				s2 += 2 * choose3[l[a] + 2 * l[b]] * counter[l[a]] * counter[l[b]] ** 2
			if counter[2 * l[a] + l[b]] >= 3:
				s2 += 2 * choose3[2 * l[a] + l[b]] * counter[l[b]] * counter[l[a]] ** 2
			if counter[l[b]] >= 2 and counter[l[a] + 2 * l[b]] >= 3:
				s4 += counter[l[a]] * choose2[l[b]] * choose3[l[a] + 2 * l[b]]
			if counter[l[a]] >= 2 and counter[2 * l[a] + l[b]] >= 3:
				s4 += counter[l[b]] * choose2[l[a]] * choose3[2 * l[a] + l[b]]
	s = (s1 - s2) // 6
	s3 = 0
	for a in range(le):
		if counter[l[a]] >= 3 and counter[3 * l[a]] >= 3:
			s3 += choose3[l[a]] * choose3[3 * l[a]]
	return t1 + t2 + t3 + t4 + s + s3 + s4
n = int(input())
l = list(map(int, input().rstrip().split()))
print(squareCount(l))


import collections
import math
import os
import random
import re
import sys

def choose(n, k):
	if k > n:
		return 0
	k = min(k, n - k)
	(num, den) = (1, 1)
	for i in range(k):
		num *= n - i
		den *= i + 1
	return num // den

def squareCount(l):
	counter = collections.Counter(l)
	l = tuple(counter.keys())
	choose2 = collections.Counter()
	choose3 = collections.Counter()
	choose4 = collections.Counter()
	le = len(l)
	for n in counter:
		count = counter[n]
		if count >= 2:
			choose2[n] = choose(count, 2)
			if count >= 3:
				choose3[n] = choose(count, 3)
				if count >= 4:
					choose4[n] = choose(count, 4)
	t1 = 0
	t2 = 0
	for i in range(le):
		if counter[2 * l[i]] >= 2 and counter[l[i]] >= 4:
			t1 += choose4[l[i]] * choose2[2 * l[i]]
		if counter[l[i]] >= 2:
			for j in range(i + 1, le):
				if counter[l[j]] >= 2 and counter[l[i] + l[j]] >= 2:
					t2 += choose2[l[i]] * choose2[l[j]] * choose2[l[i] + l[j]]
	doubles = collections.Counter()
	for i in range(le):
		if counter[l[i]] >= 2 and counter[2 * l[i]] >= 2:
			doubles[2 * l[i]] = choose2[l[i]]
	pairs = collections.Counter()
	mpairs = collections.Counter()
	for i in range(le):
		for j in range(i + 1, le):
			if counter[l[i] + l[j]] >= 2:
				pairs[l[i] + l[j]] += counter[l[i]] * counter[l[j]]
				mpairs[l[i] + l[j]] += counter[l[i]] ** 2 * counter[l[j]] ** 2
	t3 = sum((pairs[s] * doubles[s] * choose2[s] for s in doubles if s in pairs))
	t4 = sum(((pairs[s] ** 2 - mpairs[s]) * choose2[s] for s in pairs)) // 2
	CD = collections.Counter()
	for d in range(le):
		if counter[l[d]] >= 3:
			for c in range(le):
				if l[c] < l[d]:
					CD[l[d] - l[c]] += choose3[l[d]] * counter[l[c]]
	s1 = 0
	s2 = 0
	s4 = 0
	for a in range(le):
		for b in range(a + 1, le):
			s1 += 2 * CD[l[a] + l[b]] * counter[l[a]] * counter[l[b]]
			if counter[l[a] + 2 * l[b]] >= 3:
				s2 += 2 * choose3[l[a] + 2 * l[b]] * counter[l[a]] * counter[l[b]] ** 2
			if counter[2 * l[a] + l[b]] >= 3:
				s2 += 2 * choose3[2 * l[a] + l[b]] * counter[l[b]] * counter[l[a]] ** 2
			if counter[l[b]] >= 2 and counter[l[a] + 2 * l[b]] >= 3:
				s4 += counter[l[a]] * choose2[l[b]] * choose3[l[a] + 2 * l[b]]
			if counter[l[a]] >= 2 and counter[2 * l[a] + l[b]] >= 3:
				s4 += counter[l[b]] * choose2[l[a]] * choose3[2 * l[a] + l[b]]
	s = (s1 - s2) // 6
	s3 = 0
	for a in range(le):
		if counter[l[a]] >= 3 and counter[3 * l[a]] >= 3:
			s3 += choose3[l[a]] * choose3[3 * l[a]]
	return t1 + t2 + t3 + t4 + s + s3 + s4
n = int(input())
l = list(map(int, input().rstrip().split()))
print(squareCount(l))


import collections
import math
import os
import random
import re
import sys

def choose(n, k):
	if k > n:
		return 0
	k = min(k, n - k)
	(num, den) = (1, 1)
	for i in range(k):
		num *= n - i
		den *= i + 1
	return num // den

def squareCount(l):
	counter = collections.Counter(l)
	l = tuple(counter.keys())
	choose2 = collections.Counter()
	choose3 = collections.Counter()
	choose4 = collections.Counter()
	le = len(l)
	for n in counter:
		count = counter[n]
		if count >= 2:
			choose2[n] = choose(count, 2)
			if count >= 3:
				choose3[n] = choose(count, 3)
				if count >= 4:
					choose4[n] = choose(count, 4)
	t1 = 0
	t2 = 0
	for i in range(le):
		if counter[2 * l[i]] >= 2 and counter[l[i]] >= 4:
			t1 += choose4[l[i]] * choose2[2 * l[i]]
		if counter[l[i]] >= 2:
			for j in range(i + 1, le):
				if counter[l[j]] >= 2 and counter[l[i] + l[j]] >= 2:
					t2 += choose2[l[i]] * choose2[l[j]] * choose2[l[i] + l[j]]
	doubles = collections.Counter()
	for i in range(le):
		if counter[l[i]] >= 2 and counter[2 * l[i]] >= 2:
			doubles[2 * l[i]] = choose2[l[i]]
	pairs = collections.Counter()
	mpairs = collections.Counter()
	for i in range(le):
		for j in range(i + 1, le):
			if counter[l[i] + l[j]] >= 2:
				pairs[l[i] + l[j]] += counter[l[i]] * counter[l[j]]
				mpairs[l[i] + l[j]] += counter[l[i]] ** 2 * counter[l[j]] ** 2
	t3 = sum((pairs[s] * doubles[s] * choose2[s] for s in doubles if s in pairs))
	t4 = sum(((pairs[s] ** 2 - mpairs[s]) * choose2[s] for s in pairs)) // 2
	CD = collections.Counter()
	for d in range(le):
		if counter[l[d]] >= 3:
			for c in range(le):
				if l[c] < l[d]:
					CD[l[d] - l[c]] += choose3[l[d]] * counter[l[c]]
	s1 = 0
	s2 = 0
	s4 = 0
	for a in range(le):
		for b in range(a + 1, le):
			s1 += 2 * CD[l[a] + l[b]] * counter[l[a]] * counter[l[b]]
			if counter[l[a] + 2 * l[b]] >= 3:
				s2 += 2 * choose3[l[a] + 2 * l[b]] * counter[l[a]] * counter[l[b]] ** 2
			if counter[2 * l[a] + l[b]] >= 3:
				s2 += 2 * choose3[2 * l[a] + l[b]] * counter[l[b]] * counter[l[a]] ** 2
			if counter[l[b]] >= 2 and counter[l[a] + 2 * l[b]] >= 3:
				s4 += counter[l[a]] * choose2[l[b]] * choose3[l[a] + 2 * l[b]]
			if counter[l[a]] >= 2 and counter[2 * l[a] + l[b]] >= 3:
				s4 += counter[l[b]] * choose2[l[a]] * choose3[2 * l[a] + l[b]]
	s = (s1 - s2) // 6
	s3 = 0
	for a in range(le):
		if counter[l[a]] >= 3 and counter[3 * l[a]] >= 3:
			s3 += choose3[l[a]] * choose3[3 * l[a]]
	return t1 + t2 + t3 + t4 + s + s3 + s4
n = int(input())
l = list(map(int, input().rstrip().split()))
print(squareCount(l))


import collections
import math
import os
import random
import re
import sys

def choose(n, k):
	if k > n:
		return 0
	k = min(k, n - k)
	(num, den) = (1, 1)
	for i in range(k):
		num *= n - i
		den *= i + 1
	return num // den

def squareCount(l):
	counter = collections.Counter(l)
	l = tuple(counter.keys())
	choose2 = collections.Counter()
	choose3 = collections.Counter()
	choose4 = collections.Counter()
	le = len(l)
	for n in counter:
		count = counter[n]
		if count >= 2:
			choose2[n] = choose(count, 2)
			if count >= 3:
				choose3[n] = choose(count, 3)
				if count >= 4:
					choose4[n] = choose(count, 4)
	t1 = 0
	t2 = 0
	for i in range(le):
		if counter[2 * l[i]] >= 2 and counter[l[i]] >= 4:
			t1 += choose4[l[i]] * choose2[2 * l[i]]
		if counter[l[i]] >= 2:
			for j in range(i + 1, le):
				if counter[l[j]] >= 2 and counter[l[i] + l[j]] >= 2:
					t2 += choose2[l[i]] * choose2[l[j]] * choose2[l[i] + l[j]]
	doubles = collections.Counter()
	for i in range(le):
		if counter[l[i]] >= 2 and counter[2 * l[i]] >= 2:
			doubles[2 * l[i]] = choose2[l[i]]
	pairs = collections.Counter()
	mpairs = collections.Counter()
	for i in range(le):
		for j in range(i + 1, le):
			if counter[l[i] + l[j]] >= 2:
				pairs[l[i] + l[j]] += counter[l[i]] * counter[l[j]]
				mpairs[l[i] + l[j]] += counter[l[i]] ** 2 * counter[l[j]] ** 2
	t3 = sum((pairs[s] * doubles[s] * choose2[s] for s in doubles if s in pairs))
	t4 = sum(((pairs[s] ** 2 - mpairs[s]) * choose2[s] for s in pairs)) // 2
	CD = collections.Counter()
	for d in range(le):
		if counter[l[d]] >= 3:
			for c in range(le):
				if l[c] < l[d]:
					CD[l[d] - l[c]] += choose3[l[d]] * counter[l[c]]
	s1 = 0
	s2 = 0
	s4 = 0
	for a in range(le):
		for b in range(a + 1, le):
			s1 += 2 * CD[l[a] + l[b]] * counter[l[a]] * counter[l[b]]
			if counter[l[a] + 2 * l[b]] >= 3:
				s2 += 2 * choose3[l[a] + 2 * l[b]] * counter[l[a]] * counter[l[b]] ** 2
			if counter[2 * l[a] + l[b]] >= 3:
				s2 += 2 * choose3[2 * l[a] + l[b]] * counter[l[b]] * counter[l[a]] ** 2
			if counter[l[b]] >= 2 and counter[l[a] + 2 * l[b]] >= 3:
				s4 += counter[l[a]] * choose2[l[b]] * choose3[l[a] + 2 * l[b]]
			if counter[l[a]] >= 2 and counter[2 * l[a] + l[b]] >= 3:
				s4 += counter[l[b]] * choose2[l[a]] * choose3[2 * l[a] + l[b]]
	s = (s1 - s2) // 6
	s3 = 0
	for a in range(le):
		if counter[l[a]] >= 3 and counter[3 * l[a]] >= 3:
			s3 += choose3[l[a]] * choose3[3 * l[a]]
	return t1 + t2 + t3 + t4 + s + s3 + s4
n = int(input())
l = list(map(int, input().rstrip().split()))
print(squareCount(l))


import collections
import math
import os
import random
import re
import sys

def choose(n, k):
	if k > n:
		return 0
	k = min(k, n - k)
	(num, den) = (1, 1)
	for i in range(k):
		num *= n - i
		den *= i + 1
	return num // den

def squareCount(l):
	counter = collections.Counter(l)
	l = tuple(counter.keys())
	choose2 = collections.Counter()
	choose3 = collections.Counter()
	choose4 = collections.Counter()
	le = len(l)
	for n in counter:
		count = counter[n]
		if count >= 2:
			choose2[n] = choose(count, 2)
			if count >= 3:
				choose3[n] = choose(count, 3)
				if count >= 4:
					choose4[n] = choose(count, 4)
	t1 = 0
	t2 = 0
	for i in range(le):
		if counter[2 * l[i]] >= 2 and counter[l[i]] >= 4:
			t1 += choose4[l[i]] * choose2[2 * l[i]]
		if counter[l[i]] >= 2:
			for j in range(i + 1, le):
				if counter[l[j]] >= 2 and counter[l[i] + l[j]] >= 2:
					t2 += choose2[l[i]] * choose2[l[j]] * choose2[l[i] + l[j]]
	doubles = collections.Counter()
	for i in range(le):
		if counter[l[i]] >= 2 and counter[2 * l[i]] >= 2:
			doubles[2 * l[i]] = choose2[l[i]]
	pairs = collections.Counter()
	mpairs = collections.Counter()
	for i in range(le):
		for j in range(i + 1, le):
			if counter[l[i] + l[j]] >= 2:
				pairs[l[i] + l[j]] += counter[l[i]] * counter[l[j]]
				mpairs[l[i] + l[j]] += counter[l[i]] ** 2 * counter[l[j]] ** 2
	t3 = sum((pairs[s] * doubles[s] * choose2[s] for s in doubles if s in pairs))
	t4 = sum(((pairs[s] ** 2 - mpairs[s]) * choose2[s] for s in pairs)) // 2
	CD = collections.Counter()
	for d in range(le):
		if counter[l[d]] >= 3:
			for c in range(le):
				if l[c] < l[d]:
					CD[l[d] - l[c]] += choose3[l[d]] * counter[l[c]]
	s1 = 0
	s2 = 0
	s4 = 0
	for a in range(le):
		for b in range(a + 1, le):
			s1 += 2 * CD[l[a] + l[b]] * counter[l[a]] * counter[l[b]]
			if counter[l[a] + 2 * l[b]] >= 3:
				s2 += 2 * choose3[l[a] + 2 * l[b]] * counter[l[a]] * counter[l[b]] ** 2
			if counter[2 * l[a] + l[b]] >= 3:
				s2 += 2 * choose3[2 * l[a] + l[b]] * counter[l[b]] * counter[l[a]] ** 2
			if counter[l[b]] >= 2 and counter[l[a] + 2 * l[b]] >= 3:
				s4 += counter[l[a]] * choose2[l[b]] * choose3[l[a] + 2 * l[b]]
			if counter[l[a]] >= 2 and counter[2 * l[a] + l[b]] >= 3:
				s4 += counter[l[b]] * choose2[l[a]] * choose3[2 * l[a] + l[b]]
	s = (s1 - s2) // 6
	s3 = 0
	for a in range(le):
		if counter[l[a]] >= 3 and counter[3 * l[a]] >= 3:
			s3 += choose3[l[a]] * choose3[3 * l[a]]
	return t1 + t2 + t3 + t4 + s + s3 + s4
n = int(input())
l = list(map(int, input().rstrip().split()))
print(squareCount(l))


import math
import os
import random
import re
import sys
import collections

def choose(n, k):
	if k > n:
		return 0
	k = min(k, n - k)
	(num, den) = (1, 1)
	for i in range(k):
		num *= n - i
		den *= i + 1
	return num // den

def squareCount(l):
	counter = collections.Counter(l)
	l = tuple(counter.keys())
	choose2 = collections.Counter()
	choose3 = collections.Counter()
	choose4 = collections.Counter()
	le = len(l)
	for n in counter:
		count = counter[n]
		if count >= 2:
			choose2[n] = choose(count, 2)
			if count >= 3:
				choose3[n] = choose(count, 3)
				if count >= 4:
					choose4[n] = choose(count, 4)
	t1 = 0
	t2 = 0
	for i in range(le):
		if counter[2 * l[i]] >= 2 and counter[l[i]] >= 4:
			t1 += choose4[l[i]] * choose2[2 * l[i]]
		if counter[l[i]] >= 2:
			for j in range(i + 1, le):
				if counter[l[j]] >= 2 and counter[l[i] + l[j]] >= 2:
					t2 += choose2[l[i]] * choose2[l[j]] * choose2[l[i] + l[j]]
	doubles = collections.Counter()
	for i in range(le):
		if counter[l[i]] >= 2 and counter[2 * l[i]] >= 2:
			doubles[2 * l[i]] = choose2[l[i]]
	pairs = collections.Counter()
	mpairs = collections.Counter()
	for i in range(le):
		for j in range(i + 1, le):
			if counter[l[i] + l[j]] >= 2:
				pairs[l[i] + l[j]] += counter[l[i]] * counter[l[j]]
				mpairs[l[i] + l[j]] += counter[l[i]] ** 2 * counter[l[j]] ** 2
	t3 = sum((pairs[s] * doubles[s] * choose2[s] for s in doubles if s in pairs))
	t4 = sum(((pairs[s] ** 2 - mpairs[s]) * choose2[s] for s in pairs)) // 2
	CD = collections.Counter()
	for d in range(le):
		if counter[l[d]] >= 3:
			for c in range(le):
				if l[c] < l[d]:
					CD[l[d] - l[c]] += choose3[l[d]] * counter[l[c]]
	s1 = 0
	s2 = 0
	s4 = 0
	for a in range(le):
		for b in range(a + 1, le):
			s1 += 2 * CD[l[a] + l[b]] * counter[l[a]] * counter[l[b]]
			if counter[l[a] + 2 * l[b]] >= 3:
				s2 += 2 * choose3[l[a] + 2 * l[b]] * counter[l[a]] * counter[l[b]] ** 2
			if counter[2 * l[a] + l[b]] >= 3:
				s2 += 2 * choose3[2 * l[a] + l[b]] * counter[l[b]] * counter[l[a]] ** 2
			if counter[l[b]] >= 2 and counter[l[a] + 2 * l[b]] >= 3:
				s4 += counter[l[a]] * choose2[l[b]] * choose3[l[a] + 2 * l[b]]
			if counter[l[a]] >= 2 and counter[2 * l[a] + l[b]] >= 3:
				s4 += counter[l[b]] * choose2[l[a]] * choose3[2 * l[a] + l[b]]
	s = (s1 - s2) // 6
	s3 = 0
	for a in range(le):
		if counter[l[a]] >= 3 and counter[3 * l[a]] >= 3:
			s3 += choose3[l[a]] * choose3[3 * l[a]]
	return t1 + t2 + t3 + t4 + s + s3 + s4
n = int(input().strip())
l = list(map(int, input().rstrip().split()))
print(squareCount(l))


import collections
import math
import os
import random
import re
import sys

def choose(n, k):
	if k > n:
		return 0
	k = min(k, n - k)
	(num, den) = (1, 1)
	for i in range(k):
		num *= n - i
		den *= i + 1
	return num // den

def squareCount(l):
	counter = collections.Counter(l)
	l = tuple(counter.keys())
	choose2 = collections.Counter()
	choose3 = collections.Counter()
	choose4 = collections.Counter()
	le = len(l)
	for n in counter:
		count = counter[n]
		if count >= 2:
			choose2[n] = choose(count, 2)
			if count >= 3:
				choose3[n] = choose(count, 3)
				if count >= 4:
					choose4[n] = choose(count, 4)
	t1 = 0
	t2 = 0
	for i in range(le):
		if counter[2 * l[i]] >= 2 and counter[l[i]] >= 4:
			t1 += choose4[l[i]] * choose2[2 * l[i]]
		if counter[l[i]] >= 2:
			for j in range(i + 1, le):
				if counter[l[j]] >= 2 and counter[l[i] + l[j]] >= 2:
					t2 += choose2[l[i]] * choose2[l[j]] * choose2[l[i] + l[j]]
	doubles = collections.Counter()
	for i in range(le):
		if counter[l[i]] >= 2 and counter[2 * l[i]] >= 2:
			doubles[2 * l[i]] = choose2[l[i]]
	pairs = collections.Counter()
	mpairs = collections.Counter()
	for i in range(le):
		for j in range(i + 1, le):
			if counter[l[i] + l[j]] >= 2:
				pairs[l[i] + l[j]] += counter[l[i]] * counter[l[j]]
				mpairs[l[i] + l[j]] += counter[l[i]] ** 2 * counter[l[j]] ** 2
	t3 = sum((pairs[s] * doubles[s] * choose2[s] for s in doubles if s in pairs))
	t4 = sum(((pairs[s] ** 2 - mpairs[s]) * choose2[s] for s in pairs)) // 2
	CD = collections.Counter()
	for d in range(le):
		if counter[l[d]] >= 3:
			for c in range(le):
				if l[c] < l[d]:
					CD[l[d] - l[c]] += choose3[l[d]] * counter[l[c]]
	s1 = 0
	s2 = 0
	s4 = 0
	for a in range(le):
		for b in range(a + 1, le):
			s1 += 2 * CD[l[a] + l[b]] * counter[l[a]] * counter[l[b]]
			if counter[l[a] + 2 * l[b]] >= 3:
				s2 += 2 * choose3[l[a] + 2 * l[b]] * counter[l[a]] * counter[l[b]] ** 2
			if counter[2 * l[a] + l[b]] >= 3:
				s2 += 2 * choose3[2 * l[a] + l[b]] * counter[l[b]] * counter[l[a]] ** 2
			if counter[l[b]] >= 2 and counter[l[a] + 2 * l[b]] >= 3:
				s4 += counter[l[a]] * choose2[l[b]] * choose3[l[a] + 2 * l[b]]
			if counter[l[a]] >= 2 and counter[2 * l[a] + l[b]] >= 3:
				s4 += counter[l[b]] * choose2[l[a]] * choose3[2 * l[a] + l[b]]
	s = (s1 - s2) // 6
	s3 = 0
	for a in range(le):
		if counter[l[a]] >= 3 and counter[3 * l[a]] >= 3:
			s3 += choose3[l[a]] * choose3[3 * l[a]]
	return t1 + t2 + t3 + t4 + s + s3 + s4
n = int(input())
l = list(map(int, input().rstrip().split()))
print(squareCount(l))


import collections
import math
import os
import random
import re
import sys

def choose(n, k):
	if k > n:
		return 0
	k = min(k, n - k)
	(num, den) = (1, 1)
	for i in range(k):
		num *= n - i
		den *= i + 1
	return num // den

def squareCount(l):
	counter = collections.Counter(l)
	l = tuple(counter.keys())
	choose2 = collections.Counter()
	choose3 = collections.Counter()
	choose4 = collections.Counter()
	le = len(l)
	for n in counter:
		count = counter[n]
		if count >= 2:
			choose2[n] = choose(count, 2)
			if count >= 3:
				choose3[n] = choose(count, 3)
				if count >= 4:
					choose4[n] = choose(count, 4)
	t1 = 0
	t2 = 0
	for i in range(le):
		if counter[2 * l[i]] >= 2 and counter[l[i]] >= 4:
			t1 += choose4[l[i]] * choose2[2 * l[i]]
		if counter[l[i]] >= 2:
			for j in range(i + 1, le):
				if counter[l[j]] >= 2 and counter[l[i] + l[j]] >= 2:
					t2 += choose2[l[i]] * choose2[l[j]] * choose2[l[i] + l[j]]
	doubles = collections.Counter()
	for i in range(le):
		if counter[l[i]] >= 2 and counter[2 * l[i]] >= 2:
			doubles[2 * l[i]] = choose2[l[i]]
	pairs = collections.Counter()
	mpairs = collections.Counter()
	for i in range(le):
		for j in range(i + 1, le):
			if counter[l[i] + l[j]] >= 2:
				pairs[l[i] + l[j]] += counter[l[i]] * counter[l[j]]
				mpairs[l[i] + l[j]] += counter[l[i]] ** 2 * counter[l[j]] ** 2
	t3 = sum((pairs[s] * doubles[s] * choose2[s] for s in doubles if s in pairs))
	t4 = sum(((pairs[s] ** 2 - mpairs[s]) * choose2[s] for s in pairs)) // 2
	CD = collections.Counter()
	for d in range(le):
		if counter[l[d]] >= 3:
			for c in range(le):
				if l[c] < l[d]:
					CD[l[d] - l[c]] += choose3[l[d]] * counter[l[c]]
	s1 = 0
	s2 = 0
	s4 = 0
	for a in range(le):
		for b in range(a + 1, le):
			s1 += 2 * CD[l[a] + l[b]] * counter[l[a]] * counter[l[b]]
			if counter[l[a] + 2 * l[b]] >= 3:
				s2 += 2 * choose3[l[a] + 2 * l[b]] * counter[l[a]] * counter[l[b]] ** 2
			if counter[2 * l[a] + l[b]] >= 3:
				s2 += 2 * choose3[2 * l[a] + l[b]] * counter[l[b]] * counter[l[a]] ** 2
			if counter[l[b]] >= 2 and counter[l[a] + 2 * l[b]] >= 3:
				s4 += counter[l[a]] * choose2[l[b]] * choose3[l[a] + 2 * l[b]]
			if counter[l[a]] >= 2 and counter[2 * l[a] + l[b]] >= 3:
				s4 += counter[l[b]] * choose2[l[a]] * choose3[2 * l[a] + l[b]]
	s = (s1 - s2) // 6
	s3 = 0
	for a in range(le):
		if counter[l[a]] >= 3 and counter[3 * l[a]] >= 3:
			s3 += choose3[l[a]] * choose3[3 * l[a]]
	return t1 + t2 + t3 + t4 + s + s3 + s4
n = int(input())
l = list(map(int, input().rstrip().split()))
print(squareCount(l))


import collections
import math
import os
import random
import re
import sys

def choose(n, k):
	if k > n:
		return 0
	k = min(k, n - k)
	(num, den) = (1, 1)
	for i in range(k):
		num *= n - i
		den *= i + 1
	return num // den

def squareCount(l):
	counter = collections.Counter(l)
	l = tuple(counter.keys())
	choose2 = collections.Counter()
	choose3 = collections.Counter()
	choose4 = collections.Counter()
	le = len(l)
	for n in counter:
		count = counter[n]
		if count >= 2:
			choose2[n] = choose(count, 2)
			if count >= 3:
				choose3[n] = choose(count, 3)
				if count >= 4:
					choose4[n] = choose(count, 4)
	t1 = 0
	t2 = 0
	for i in range(le):
		if counter[2 * l[i]] >= 2 and counter[l[i]] >= 4:
			t1 += choose4[l[i]] * choose2[2 * l[i]]
		if counter[l[i]] >= 2:
			for j in range(i + 1, le):
				if counter[l[j]] >= 2 and counter[l[i] + l[j]] >= 2:
					t2 += choose2[l[i]] * choose2[l[j]] * choose2[l[i] + l[j]]
	doubles = collections.Counter()
	for i in range(le):
		if counter[l[i]] >= 2 and counter[2 * l[i]] >= 2:
			doubles[2 * l[i]] = choose2[l[i]]
	pairs = collections.Counter()
	mpairs = collections.Counter()
	for i in range(le):
		for j in range(i + 1, le):
			if counter[l[i] + l[j]] >= 2:
				pairs[l[i] + l[j]] += counter[l[i]] * counter[l[j]]
				mpairs[l[i] + l[j]] += counter[l[i]] ** 2 * counter[l[j]] ** 2
	t3 = sum((pairs[s] * doubles[s] * choose2[s] for s in doubles if s in pairs))
	t4 = sum(((pairs[s] ** 2 - mpairs[s]) * choose2[s] for s in pairs)) // 2
	CD = collections.Counter()
	for d in range(le):
		if counter[l[d]] >= 3:
			for c in range(le):
				if l[c] < l[d]:
					CD[l[d] - l[c]] += choose3[l[d]] * counter[l[c]]
	s1 = 0
	s2 = 0
	s4 = 0
	for a in range(le):
		for b in range(a + 1, le):
			s1 += 2 * CD[l[a] + l[b]] * counter[l[a]] * counter[l[b]]
			if counter[l[a] + 2 * l[b]] >= 3:
				s2 += 2 * choose3[l[a] + 2 * l[b]] * counter[l[a]] * counter[l[b]] ** 2
			if counter[2 * l[a] + l[b]] >= 3:
				s2 += 2 * choose3[2 * l[a] + l[b]] * counter[l[b]] * counter[l[a]] ** 2
			if counter[l[b]] >= 2 and counter[l[a] + 2 * l[b]] >= 3:
				s4 += counter[l[a]] * choose2[l[b]] * choose3[l[a] + 2 * l[b]]
			if counter[l[a]] >= 2 and counter[2 * l[a] + l[b]] >= 3:
				s4 += counter[l[b]] * choose2[l[a]] * choose3[2 * l[a] + l[b]]
	s = (s1 - s2) // 6
	s3 = 0
	for a in range(le):
		if counter[l[a]] >= 3 and counter[3 * l[a]] >= 3:
			s3 += choose3[l[a]] * choose3[3 * l[a]]
	return t1 + t2 + t3 + t4 + s + s3 + s4
n = int(input())
l = list(map(int, input().rstrip().split()))
print(squareCount(l))


import collections
import math
import os
import random
import re
import sys

def choose(n, k):
	if k > n:
		return 0
	k = min(k, n - k)
	(num, den) = (1, 1)
	for i in range(k):
		num *= n - i
		den *= i + 1
	return num // den

def squareCount(l):
	counter = collections.Counter(l)
	l = tuple(counter.keys())
	choose2 = collections.Counter()
	choose3 = collections.Counter()
	choose4 = collections.Counter()
	le = len(l)
	for n in counter:
		count = counter[n]
		if count >= 2:
			choose2[n] = choose(count, 2)
			if count >= 3:
				choose3[n] = choose(count, 3)
				if count >= 4:
					choose4[n] = choose(count, 4)
	t1 = 0
	t2 = 0
	for i in range(le):
		if counter[2 * l[i]] >= 2 and counter[l[i]] >= 4:
			t1 += choose4[l[i]] * choose2[2 * l[i]]
		if counter[l[i]] >= 2:
			for j in range(i + 1, le):
				if counter[l[j]] >= 2 and counter[l[i] + l[j]] >= 2:
					t2 += choose2[l[i]] * choose2[l[j]] * choose2[l[i] + l[j]]
	doubles = collections.Counter()
	for i in range(le):
		if counter[l[i]] >= 2 and counter[2 * l[i]] >= 2:
			doubles[2 * l[i]] = choose2[l[i]]
	pairs = collections.Counter()
	mpairs = collections.Counter()
	for i in range(le):
		for j in range(i + 1, le):
			if counter[l[i] + l[j]] >= 2:
				pairs[l[i] + l[j]] += counter[l[i]] * counter[l[j]]
				mpairs[l[i] + l[j]] += counter[l[i]] ** 2 * counter[l[j]] ** 2
	t3 = sum((pairs[s] * doubles[s] * choose2[s] for s in doubles if s in pairs))
	t4 = sum(((pairs[s] ** 2 - mpairs[s]) * choose2[s] for s in pairs)) // 2
	CD = collections.Counter()
	for d in range(le):
		if counter[l[d]] >= 3:
			for c in range(le):
				if l[c] < l[d]:
					CD[l[d] - l[c]] += choose3[l[d]] * counter[l[c]]
	s1 = 0
	s2 = 0
	s4 = 0
	for a in range(le):
		for b in range(a + 1, le):
			s1 += 2 * CD[l[a] + l[b]] * counter[l[a]] * counter[l[b]]
			if counter[l[a] + 2 * l[b]] >= 3:
				s2 += 2 * choose3[l[a] + 2 * l[b]] * counter[l[a]] * counter[l[b]] ** 2
			if counter[2 * l[a] + l[b]] >= 3:
				s2 += 2 * choose3[2 * l[a] + l[b]] * counter[l[b]] * counter[l[a]] ** 2
			if counter[l[b]] >= 2 and counter[l[a] + 2 * l[b]] >= 3:
				s4 += counter[l[a]] * choose2[l[b]] * choose3[l[a] + 2 * l[b]]
			if counter[l[a]] >= 2 and counter[2 * l[a] + l[b]] >= 3:
				s4 += counter[l[b]] * choose2[l[a]] * choose3[2 * l[a] + l[b]]
	s = (s1 - s2) // 6
	s3 = 0
	for a in range(le):
		if counter[l[a]] >= 3 and counter[3 * l[a]] >= 3:
			s3 += choose3[l[a]] * choose3[3 * l[a]]
	return t1 + t2 + t3 + t4 + s + s3 + s4
n = int(input())
l = list(map(int, input().rstrip().split()))
print(squareCount(l))


import collections
import math
import os
import random
import re
import sys

def choose(n, k):
	if k > n:
		return 0
	k = min(k, n - k)
	(num, den) = (1, 1)
	for i in range(k):
		num *= n - i
		den *= i + 1
	return num // den

def squareCount(l):
	counter = collections.Counter(l)
	l = tuple(counter.keys())
	choose2 = collections.Counter()
	choose3 = collections.Counter()
	choose4 = collections.Counter()
	le = len(l)
	for n in counter:
		count = counter[n]
		if count >= 2:
			choose2[n] = choose(count, 2)
			if count >= 3:
				choose3[n] = choose(count, 3)
				if count >= 4:
					choose4[n] = choose(count, 4)
	t1 = 0
	t2 = 0
	for i in range(le):
		if counter[2 * l[i]] >= 2 and counter[l[i]] >= 4:
			t1 += choose4[l[i]] * choose2[2 * l[i]]
		if counter[l[i]] >= 2:
			for j in range(i + 1, le):
				if counter[l[j]] >= 2 and counter[l[i] + l[j]] >= 2:
					t2 += choose2[l[i]] * choose2[l[j]] * choose2[l[i] + l[j]]
	doubles = collections.Counter()
	for i in range(le):
		if counter[l[i]] >= 2 and counter[2 * l[i]] >= 2:
			doubles[2 * l[i]] = choose2[l[i]]
	pairs = collections.Counter()
	mpairs = collections.Counter()
	for i in range(le):
		for j in range(i + 1, le):
			if counter[l[i] + l[j]] >= 2:
				pairs[l[i] + l[j]] += counter[l[i]] * counter[l[j]]
				mpairs[l[i] + l[j]] += counter[l[i]] ** 2 * counter[l[j]] ** 2
	t3 = sum((pairs[s] * doubles[s] * choose2[s] for s in doubles if s in pairs))
	t4 = sum(((pairs[s] ** 2 - mpairs[s]) * choose2[s] for s in pairs)) // 2
	CD = collections.Counter()
	for d in range(le):
		if counter[l[d]] >= 3:
			for c in range(le):
				if l[c] < l[d]:
					CD[l[d] - l[c]] += choose3[l[d]] * counter[l[c]]
	s1 = 0
	s2 = 0
	s4 = 0
	for a in range(le):
		for b in range(a + 1, le):
			s1 += 2 * CD[l[a] + l[b]] * counter[l[a]] * counter[l[b]]
			if counter[l[a] + 2 * l[b]] >= 3:
				s2 += 2 * choose3[l[a] + 2 * l[b]] * counter[l[a]] * counter[l[b]] ** 2
			if counter[2 * l[a] + l[b]] >= 3:
				s2 += 2 * choose3[2 * l[a] + l[b]] * counter[l[b]] * counter[l[a]] ** 2
			if counter[l[b]] >= 2 and counter[l[a] + 2 * l[b]] >= 3:
				s4 += counter[l[a]] * choose2[l[b]] * choose3[l[a] + 2 * l[b]]
			if counter[l[a]] >= 2 and counter[2 * l[a] + l[b]] >= 3:
				s4 += counter[l[b]] * choose2[l[a]] * choose3[2 * l[a] + l[b]]
	s = (s1 - s2) // 6
	s3 = 0
	for a in range(le):
		if counter[l[a]] >= 3 and counter[3 * l[a]] >= 3:
			s3 += choose3[l[a]] * choose3[3 * l[a]]
	return t1 + t2 + t3 + t4 + s + s3 + s4
n = int(input())
l = list(map(int, input().rstrip().split()))
print(squareCount(l))


import collections
import math
import os
import random
import re
import sys

def choose(n, k):
	if k > n:
		return 0
	k = min(k, n - k)
	(num, den) = (1, 1)
	for i in range(k):
		num *= n - i
		den *= i + 1
	return num // den

def squareCount(l):
	counter = collections.Counter(l)
	l = tuple(counter.keys())
	choose2 = collections.Counter()
	choose3 = collections.Counter()
	choose4 = collections.Counter()
	le = len(l)
	for n in counter:
		count = counter[n]
		if count >= 2:
			choose2[n] = choose(count, 2)
			if count >= 3:
				choose3[n] = choose(count, 3)
				if count >= 4:
					choose4[n] = choose(count, 4)
	t1 = 0
	t2 = 0
	for i in range(le):
		if counter[2 * l[i]] >= 2 and counter[l[i]] >= 4:
			t1 += choose4[l[i]] * choose2[2 * l[i]]
		if counter[l[i]] >= 2:
			for j in range(i + 1, le):
				if counter[l[j]] >= 2 and counter[l[i] + l[j]] >= 2:
					t2 += choose2[l[i]] * choose2[l[j]] * choose2[l[i] + l[j]]
	doubles = collections.Counter()
	for i in range(le):
		if counter[l[i]] >= 2 and counter[2 * l[i]] >= 2:
			doubles[2 * l[i]] = choose2[l[i]]
	pairs = collections.Counter()
	mpairs = collections.Counter()
	for i in range(le):
		for j in range(i + 1, le):
			if counter[l[i] + l[j]] >= 2:
				pairs[l[i] + l[j]] += counter[l[i]] * counter[l[j]]
				mpairs[l[i] + l[j]] += counter[l[i]] ** 2 * counter[l[j]] ** 2
	t3 = sum((pairs[s] * doubles[s] * choose2[s] for s in doubles if s in pairs))
	t4 = sum(((pairs[s] ** 2 - mpairs[s]) * choose2[s] for s in pairs)) // 2
	CD = collections.Counter()
	for d in range(le):
		if counter[l[d]] >= 3:
			for c in range(le):
				if l[c] < l[d]:
					CD[l[d] - l[c]] += choose3[l[d]] * counter[l[c]]
	s1 = 0
	s2 = 0
	s4 = 0
	for a in range(le):
		for b in range(a + 1, le):
			s1 += 2 * CD[l[a] + l[b]] * counter[l[a]] * counter[l[b]]
			if counter[l[a] + 2 * l[b]] >= 3:
				s2 += 2 * choose3[l[a] + 2 * l[b]] * counter[l[a]] * counter[l[b]] ** 2
			if counter[2 * l[a] + l[b]] >= 3:
				s2 += 2 * choose3[2 * l[a] + l[b]] * counter[l[b]] * counter[l[a]] ** 2
			if counter[l[b]] >= 2 and counter[l[a] + 2 * l[b]] >= 3:
				s4 += counter[l[a]] * choose2[l[b]] * choose3[l[a] + 2 * l[b]]
			if counter[l[a]] >= 2 and counter[2 * l[a] + l[b]] >= 3:
				s4 += counter[l[b]] * choose2[l[a]] * choose3[2 * l[a] + l[b]]
	s = (s1 - s2) // 6
	s3 = 0
	for a in range(le):
		if counter[l[a]] >= 3 and counter[3 * l[a]] >= 3:
			s3 += choose3[l[a]] * choose3[3 * l[a]]
	return t1 + t2 + t3 + t4 + s + s3 + s4
n = int(input())
l = list(map(int, input().rstrip().split()))
print(squareCount(l))


import collections
import math
import os
import random
import re
import sys

def choose(n, k):
	if k > n:
		return 0
	k = min(k, n - k)
	(num, den) = (1, 1)
	for i in range(k):
		num *= n - i
		den *= i + 1
	return num // den

def squareCount(l):
	counter = collections.Counter(l)
	l = tuple(counter.keys())
	choose2 = collections.Counter()
	choose3 = collections.Counter()
	choose4 = collections.Counter()
	le = len(l)
	for n in counter:
		count = counter[n]
		if count >= 2:
			choose2[n] = choose(count, 2)
			if count >= 3:
				choose3[n] = choose(count, 3)
				if count >= 4:
					choose4[n] = choose(count, 4)
	t1 = 0
	t2 = 0
	for i in range(le):
		if counter[2 * l[i]] >= 2 and counter[l[i]] >= 4:
			t1 += choose4[l[i]] * choose2[2 * l[i]]
		if counter[l[i]] >= 2:
			for j in range(i + 1, le):
				if counter[l[j]] >= 2 and counter[l[i] + l[j]] >= 2:
					t2 += choose2[l[i]] * choose2[l[j]] * choose2[l[i] + l[j]]
	doubles = collections.Counter()
	for i in range(le):
		if counter[l[i]] >= 2 and counter[2 * l[i]] >= 2:
			doubles[2 * l[i]] = choose2[l[i]]
	pairs = collections.Counter()
	mpairs = collections.Counter()
	for i in range(le):
		for j in range(i + 1, le):
			if counter[l[i] + l[j]] >= 2:
				pairs[l[i] + l[j]] += counter[l[i]] * counter[l[j]]
				mpairs[l[i] + l[j]] += counter[l[i]] ** 2 * counter[l[j]] ** 2
	t3 = sum((pairs[s] * doubles[s] * choose2[s] for s in doubles if s in pairs))
	t4 = sum(((pairs[s] ** 2 - mpairs[s]) * choose2[s] for s in pairs)) // 2
	CD = collections.Counter()
	for d in range(le):
		if counter[l[d]] >= 3:
			for c in range(le):
				if l[c] < l[d]:
					CD[l[d] - l[c]] += choose3[l[d]] * counter[l[c]]
	s1 = 0
	s2 = 0
	s4 = 0
	for a in range(le):
		for b in range(a + 1, le):
			s1 += 2 * CD[l[a] + l[b]] * counter[l[a]] * counter[l[b]]
			if counter[l[a] + 2 * l[b]] >= 3:
				s2 += 2 * choose3[l[a] + 2 * l[b]] * counter[l[a]] * counter[l[b]] ** 2
			if counter[2 * l[a] + l[b]] >= 3:
				s2 += 2 * choose3[2 * l[a] + l[b]] * counter[l[b]] * counter[l[a]] ** 2
			if counter[l[b]] >= 2 and counter[l[a] + 2 * l[b]] >= 3:
				s4 += counter[l[a]] * choose2[l[b]] * choose3[l[a] + 2 * l[b]]
			if counter[l[a]] >= 2 and counter[2 * l[a] + l[b]] >= 3:
				s4 += counter[l[b]] * choose2[l[a]] * choose3[2 * l[a] + l[b]]
	s = (s1 - s2) // 6
	s3 = 0
	for a in range(le):
		if counter[l[a]] >= 3 and counter[3 * l[a]] >= 3:
			s3 += choose3[l[a]] * choose3[3 * l[a]]
	return t1 + t2 + t3 + t4 + s + s3 + s4
n = int(input())
l = list(map(int, input().rstrip().split()))
print(squareCount(l))


import collections
import math
import os
import random
import re
import sys

def choose(n, k):
	if k > n:
		return 0
	k = min(k, n - k)
	(num, den) = (1, 1)
	for i in range(k):
		num *= n - i
		den *= i + 1
	return num // den

def squareCount(l):
	counter = collections.Counter(l)
	l = tuple(counter.keys())
	choose2 = collections.Counter()
	choose3 = collections.Counter()
	choose4 = collections.Counter()
	le = len(l)
	for n in counter:
		count = counter[n]
		if count >= 2:
			choose2[n] = choose(count, 2)
			if count >= 3:
				choose3[n] = choose(count, 3)
				if count >= 4:
					choose4[n] = choose(count, 4)
	t1 = 0
	t2 = 0
	for i in range(le):
		if counter[2 * l[i]] >= 2 and counter[l[i]] >= 4:
			t1 += choose4[l[i]] * choose2[2 * l[i]]
		if counter[l[i]] >= 2:
			for j in range(i + 1, le):
				if counter[l[j]] >= 2 and counter[l[i] + l[j]] >= 2:
					t2 += choose2[l[i]] * choose2[l[j]] * choose2[l[i] + l[j]]
	doubles = collections.Counter()
	for i in range(le):
		if counter[l[i]] >= 2 and counter[2 * l[i]] >= 2:
			doubles[2 * l[i]] = choose2[l[i]]
	pairs = collections.Counter()
	mpairs = collections.Counter()
	for i in range(le):
		for j in range(i + 1, le):
			if counter[l[i] + l[j]] >= 2:
				pairs[l[i] + l[j]] += counter[l[i]] * counter[l[j]]
				mpairs[l[i] + l[j]] += counter[l[i]] ** 2 * counter[l[j]] ** 2
	t3 = sum((pairs[s] * doubles[s] * choose2[s] for s in doubles if s in pairs))
	t4 = sum(((pairs[s] ** 2 - mpairs[s]) * choose2[s] for s in pairs)) // 2
	CD = collections.Counter()
	for d in range(le):
		if counter[l[d]] >= 3:
			for c in range(le):
				if l[c] < l[d]:
					CD[l[d] - l[c]] += choose3[l[d]] * counter[l[c]]
	s1 = 0
	s2 = 0
	s4 = 0
	for a in range(le):
		for b in range(a + 1, le):
			s1 += 2 * CD[l[a] + l[b]] * counter[l[a]] * counter[l[b]]
			if counter[l[a] + 2 * l[b]] >= 3:
				s2 += 2 * choose3[l[a] + 2 * l[b]] * counter[l[a]] * counter[l[b]] ** 2
			if counter[2 * l[a] + l[b]] >= 3:
				s2 += 2 * choose3[2 * l[a] + l[b]] * counter[l[b]] * counter[l[a]] ** 2
			if counter[l[b]] >= 2 and counter[l[a] + 2 * l[b]] >= 3:
				s4 += counter[l[a]] * choose2[l[b]] * choose3[l[a] + 2 * l[b]]
			if counter[l[a]] >= 2 and counter[2 * l[a] + l[b]] >= 3:
				s4 += counter[l[b]] * choose2[l[a]] * choose3[2 * l[a] + l[b]]
	s = (s1 - s2) // 6
	s3 = 0
	for a in range(le):
		if counter[l[a]] >= 3 and counter[3 * l[a]] >= 3:
			s3 += choose3[l[a]] * choose3[3 * l[a]]
	return t1 + t2 + t3 + t4 + s + s3 + s4
n = int(input())
l = list(map(int, input().rstrip().split()))
print(squareCount(l))
{'mode': 'full', 'isActive': False}


import collections
import math
import os
import random
import re
import sys

def choose(n, k):
	if k > n:
		return 0
	k = min(k, n - k)
	(num, den) = (1, 1)
	for i in range(k):
		num *= n - i
		den *= i + 1
	return num // den

def squareCount(l):
	counter = collections.Counter(l)
	l = tuple(counter.keys())
	choose2 = collections.Counter()
	choose3 = collections.Counter()
	choose4 = collections.Counter()
	le = len(l)
	for n in counter:
		count = counter[n]
		if count >= 2:
			choose2[n] = choose(count, 2)
			if count >= 3:
				choose3[n] = choose(count, 3)
				if count >= 4:
					choose4[n] = choose(count, 4)
	t1 = 0
	t2 = 0
	for i in range(le):
		if counter[2 * l[i]] >= 2 and counter[l[i]] >= 4:
			t1 += choose4[l[i]] * choose2[2 * l[i]]
		if counter[l[i]] >= 2:
			for j in range(i + 1, le):
				if counter[l[j]] >= 2 and counter[l[i] + l[j]] >= 2:
					t2 += choose2[l[i]] * choose2[l[j]] * choose2[l[i] + l[j]]
	doubles = collections.Counter()
	for i in range(le):
		if counter[l[i]] >= 2 and counter[2 * l[i]] >= 2:
			doubles[2 * l[i]] = choose2[l[i]]
	pairs = collections.Counter()
	mpairs = collections.Counter()
	for i in range(le):
		for j in range(i + 1, le):
			if counter[l[i] + l[j]] >= 2:
				pairs[l[i] + l[j]] += counter[l[i]] * counter[l[j]]
				mpairs[l[i] + l[j]] += counter[l[i]] ** 2 * counter[l[j]] ** 2
	t3 = sum((pairs[s] * doubles[s] * choose2[s] for s in doubles if s in pairs))
	t4 = sum(((pairs[s] ** 2 - mpairs[s]) * choose2[s] for s in pairs)) // 2
	CD = collections.Counter()
	for d in range(le):
		if counter[l[d]] >= 3:
			for c in range(le):
				if l[c] < l[d]:
					CD[l[d] - l[c]] += choose3[l[d]] * counter[l[c]]
	s1 = 0
	s2 = 0
	s4 = 0
	for a in range(le):
		for b in range(a + 1, le):
			s1 += 2 * CD[l[a] + l[b]] * counter[l[a]] * counter[l[b]]
			if counter[l[a] + 2 * l[b]] >= 3:
				s2 += 2 * choose3[l[a] + 2 * l[b]] * counter[l[a]] * counter[l[b]] ** 2
			if counter[2 * l[a] + l[b]] >= 3:
				s2 += 2 * choose3[2 * l[a] + l[b]] * counter[l[b]] * counter[l[a]] ** 2
			if counter[l[b]] >= 2 and counter[l[a] + 2 * l[b]] >= 3:
				s4 += counter[l[a]] * choose2[l[b]] * choose3[l[a] + 2 * l[b]]
			if counter[l[a]] >= 2 and counter[2 * l[a] + l[b]] >= 3:
				s4 += counter[l[b]] * choose2[l[a]] * choose3[2 * l[a] + l[b]]
	s = (s1 - s2) // 6
	s3 = 0
	for a in range(le):
		if counter[l[a]] >= 3 and counter[3 * l[a]] >= 3:
			s3 += choose3[l[a]] * choose3[3 * l[a]]
	return t1 + t2 + t3 + t4 + s + s3 + s4
n = int(input())
l = list(map(int, input().rstrip().split()))
print(squareCount(l))


import collections
import math
import os
import random
import re
import sys

def choose(n, k):
	if k > n:
		return 0
	k = min(k, n - k)
	(num, den) = (1, 1)
	for i in range(k):
		num *= n - i
		den *= i + 1
	return num // den

def squareCount(l):
	counter = collections.Counter(l)
	l = tuple(counter.keys())
	choose2 = collections.Counter()
	choose3 = collections.Counter()
	choose4 = collections.Counter()
	le = len(l)
	for n in counter:
		count = counter[n]
		if count >= 2:
			choose2[n] = choose(count, 2)
			if count >= 3:
				choose3[n] = choose(count, 3)
				if count >= 4:
					choose4[n] = choose(count, 4)
	t1 = 0
	t2 = 0
	for i in range(le):
		if counter[2 * l[i]] >= 2 and counter[l[i]] >= 4:
			t1 += choose4[l[i]] * choose2[2 * l[i]]
		if counter[l[i]] >= 2:
			for j in range(i + 1, le):
				if counter[l[j]] >= 2 and counter[l[i] + l[j]] >= 2:
					t2 += choose2[l[i]] * choose2[l[j]] * choose2[l[i] + l[j]]
	doubles = collections.Counter()
	for i in range(le):
		if counter[l[i]] >= 2 and counter[2 * l[i]] >= 2:
			doubles[2 * l[i]] = choose2[l[i]]
	pairs = collections.Counter()
	mpairs = collections.Counter()
	for i in range(le):
		for j in range(i + 1, le):
			if counter[l[i] + l[j]] >= 2:
				pairs[l[i] + l[j]] += counter[l[i]] * counter[l[j]]
				mpairs[l[i] + l[j]] += counter[l[i]] ** 2 * counter[l[j]] ** 2
	t3 = sum((pairs[s] * doubles[s] * choose2[s] for s in doubles if s in pairs))
	t4 = sum(((pairs[s] ** 2 - mpairs[s]) * choose2[s] for s in pairs)) // 2
	CD = collections.Counter()
	for d in range(le):
		if counter[l[d]] >= 3:
			for c in range(le):
				if l[c] < l[d]:
					CD[l[d] - l[c]] += choose3[l[d]] * counter[l[c]]
	s1 = 0
	s2 = 0
	s4 = 0
	for a in range(le):
		for b in range(a + 1, le):
			s1 += 2 * CD[l[a] + l[b]] * counter[l[a]] * counter[l[b]]
			if counter[l[a] + 2 * l[b]] >= 3:
				s2 += 2 * choose3[l[a] + 2 * l[b]] * counter[l[a]] * counter[l[b]] ** 2
			if counter[2 * l[a] + l[b]] >= 3:
				s2 += 2 * choose3[2 * l[a] + l[b]] * counter[l[b]] * counter[l[a]] ** 2
			if counter[l[b]] >= 2 and counter[l[a] + 2 * l[b]] >= 3:
				s4 += counter[l[a]] * choose2[l[b]] * choose3[l[a] + 2 * l[b]]
			if counter[l[a]] >= 2 and counter[2 * l[a] + l[b]] >= 3:
				s4 += counter[l[b]] * choose2[l[a]] * choose3[2 * l[a] + l[b]]
	s = (s1 - s2) // 6
	s3 = 0
	for a in range(le):
		if counter[l[a]] >= 3 and counter[3 * l[a]] >= 3:
			s3 += choose3[l[a]] * choose3[3 * l[a]]
	return t1 + t2 + t3 + t4 + s + s3 + s4
n = int(input())
l = list(map(int, input().rstrip().split()))
print(squareCount(l))


import collections
import math
import os
import random
import re
import sys

def choose(n, k):
	if k > n:
		return 0
	k = min(k, n - k)
	(num, den) = (1, 1)
	for i in range(k):
		num *= n - i
		den *= i + 1
	return num // den

def squareCount(l):
	counter = collections.Counter(l)
	l = tuple(counter.keys())
	choose2 = collections.Counter()
	choose3 = collections.Counter()
	choose4 = collections.Counter()
	le = len(l)
	for n in counter:
		count = counter[n]
		if count >= 2:
			choose2[n] = choose(count, 2)
			if count >= 3:
				choose3[n] = choose(count, 3)
				if count >= 4:
					choose4[n] = choose(count, 4)
	t1 = 0
	t2 = 0
	for i in range(le):
		if counter[2 * l[i]] >= 2 and counter[l[i]] >= 4:
			t1 += choose4[l[i]] * choose2[2 * l[i]]
		if counter[l[i]] >= 2:
			for j in range(i + 1, le):
				if counter[l[j]] >= 2 and counter[l[i] + l[j]] >= 2:
					t2 += choose2[l[i]] * choose2[l[j]] * choose2[l[i] + l[j]]
	doubles = collections.Counter()
	for i in range(le):
		if counter[l[i]] >= 2 and counter[2 * l[i]] >= 2:
			doubles[2 * l[i]] = choose2[l[i]]
	pairs = collections.Counter()
	mpairs = collections.Counter()
	for i in range(le):
		for j in range(i + 1, le):
			if counter[l[i] + l[j]] >= 2:
				pairs[l[i] + l[j]] += counter[l[i]] * counter[l[j]]
				mpairs[l[i] + l[j]] += counter[l[i]] ** 2 * counter[l[j]] ** 2
	t3 = sum((pairs[s] * doubles[s] * choose2[s] for s in doubles if s in pairs))
	t4 = sum(((pairs[s] ** 2 - mpairs[s]) * choose2[s] for s in pairs)) // 2
	CD = collections.Counter()
	for d in range(le):
		if counter[l[d]] >= 3:
			for c in range(le):
				if l[c] < l[d]:
					CD[l[d] - l[c]] += choose3[l[d]] * counter[l[c]]
	s1 = 0
	s2 = 0
	s4 = 0
	for a in range(le):
		for b in range(a + 1, le):
			s1 += 2 * CD[l[a] + l[b]] * counter[l[a]] * counter[l[b]]
			if counter[l[a] + 2 * l[b]] >= 3:
				s2 += 2 * choose3[l[a] + 2 * l[b]] * counter[l[a]] * counter[l[b]] ** 2
			if counter[2 * l[a] + l[b]] >= 3:
				s2 += 2 * choose3[2 * l[a] + l[b]] * counter[l[b]] * counter[l[a]] ** 2
			if counter[l[b]] >= 2 and counter[l[a] + 2 * l[b]] >= 3:
				s4 += counter[l[a]] * choose2[l[b]] * choose3[l[a] + 2 * l[b]]
			if counter[l[a]] >= 2 and counter[2 * l[a] + l[b]] >= 3:
				s4 += counter[l[b]] * choose2[l[a]] * choose3[2 * l[a] + l[b]]
	s = (s1 - s2) // 6
	s3 = 0
	for a in range(le):
		if counter[l[a]] >= 3 and counter[3 * l[a]] >= 3:
			s3 += choose3[l[a]] * choose3[3 * l[a]]
	return t1 + t2 + t3 + t4 + s + s3 + s4
n = int(input())
l = list(map(int, input().rstrip().split()))
print(squareCount(l))


import collections
import math
import os
import random
import re
import sys

def choose(n, k):
	if k > n:
		return 0
	k = min(k, n - k)
	(num, den) = (1, 1)
	for i in range(k):
		num *= n - i
		den *= i + 1
	return num // den

def squareCount(l):
	counter = collections.Counter(l)
	l = tuple(counter.keys())
	choose2 = collections.Counter()
	choose3 = collections.Counter()
	choose4 = collections.Counter()
	le = len(l)
	for n in counter:
		count = counter[n]
		if count >= 2:
			choose2[n] = choose(count, 2)
			if count >= 3:
				choose3[n] = choose(count, 3)
				if count >= 4:
					choose4[n] = choose(count, 4)
	t1 = 0
	t2 = 0
	for i in range(le):
		if counter[2 * l[i]] >= 2 and counter[l[i]] >= 4:
			t1 += choose4[l[i]] * choose2[2 * l[i]]
		if counter[l[i]] >= 2:
			for j in range(i + 1, le):
				if counter[l[j]] >= 2 and counter[l[i] + l[j]] >= 2:
					t2 += choose2[l[i]] * choose2[l[j]] * choose2[l[i] + l[j]]
	doubles = collections.Counter()
	for i in range(le):
		if counter[l[i]] >= 2 and counter[2 * l[i]] >= 2:
			doubles[2 * l[i]] = choose2[l[i]]
	pairs = collections.Counter()
	mpairs = collections.Counter()
	for i in range(le):
		for j in range(i + 1, le):
			if counter[l[i] + l[j]] >= 2:
				pairs[l[i] + l[j]] += counter[l[i]] * counter[l[j]]
				mpairs[l[i] + l[j]] += counter[l[i]] ** 2 * counter[l[j]] ** 2
	t3 = sum((pairs[s] * doubles[s] * choose2[s] for s in doubles if s in pairs))
	t4 = sum(((pairs[s] ** 2 - mpairs[s]) * choose2[s] for s in pairs)) // 2
	CD = collections.Counter()
	for d in range(le):
		if counter[l[d]] >= 3:
			for c in range(le):
				if l[c] < l[d]:
					CD[l[d] - l[c]] += choose3[l[d]] * counter[l[c]]
	s1 = 0
	s2 = 0
	s4 = 0
	for a in range(le):
		for b in range(a + 1, le):
			s1 += 2 * CD[l[a] + l[b]] * counter[l[a]] * counter[l[b]]
			if counter[l[a] + 2 * l[b]] >= 3:
				s2 += 2 * choose3[l[a] + 2 * l[b]] * counter[l[a]] * counter[l[b]] ** 2
			if counter[2 * l[a] + l[b]] >= 3:
				s2 += 2 * choose3[2 * l[a] + l[b]] * counter[l[b]] * counter[l[a]] ** 2
			if counter[l[b]] >= 2 and counter[l[a] + 2 * l[b]] >= 3:
				s4 += counter[l[a]] * choose2[l[b]] * choose3[l[a] + 2 * l[b]]
			if counter[l[a]] >= 2 and counter[2 * l[a] + l[b]] >= 3:
				s4 += counter[l[b]] * choose2[l[a]] * choose3[2 * l[a] + l[b]]
	s = (s1 - s2) // 6
	s3 = 0
	for a in range(le):
		if counter[l[a]] >= 3 and counter[3 * l[a]] >= 3:
			s3 += choose3[l[a]] * choose3[3 * l[a]]
	return t1 + t2 + t3 + t4 + s + s3 + s4
n = int(input())
l = list(map(int, input().rstrip().split()))
print(squareCount(l))


import collections
import math
import os
import random
import re
import sys

def choose(n, k):
	if k > n:
		return 0
	k = min(k, n - k)
	(num, den) = (1, 1)
	for i in range(k):
		num *= n - i
		den *= i + 1
	return num // den

def squareCount(l):
	counter = collections.Counter(l)
	l = tuple(counter.keys())
	choose2 = collections.Counter()
	choose3 = collections.Counter()
	choose4 = collections.Counter()
	le = len(l)
	for n in counter:
		count = counter[n]
		if count >= 2:
			choose2[n] = choose(count, 2)
			if count >= 3:
				choose3[n] = choose(count, 3)
				if count >= 4:
					choose4[n] = choose(count, 4)
	t1 = 0
	t2 = 0
	for i in range(le):
		if counter[2 * l[i]] >= 2 and counter[l[i]] >= 4:
			t1 += choose4[l[i]] * choose2[2 * l[i]]
		if counter[l[i]] >= 2:
			for j in range(i + 1, le):
				if counter[l[j]] >= 2 and counter[l[i] + l[j]] >= 2:
					t2 += choose2[l[i]] * choose2[l[j]] * choose2[l[i] + l[j]]
	doubles = collections.Counter()
	for i in range(le):
		if counter[l[i]] >= 2 and counter[2 * l[i]] >= 2:
			doubles[2 * l[i]] = choose2[l[i]]
	pairs = collections.Counter()
	mpairs = collections.Counter()
	for i in range(le):
		for j in range(i + 1, le):
			if counter[l[i] + l[j]] >= 2:
				pairs[l[i] + l[j]] += counter[l[i]] * counter[l[j]]
				mpairs[l[i] + l[j]] += counter[l[i]] ** 2 * counter[l[j]] ** 2
	t3 = sum((pairs[s] * doubles[s] * choose2[s] for s in doubles if s in pairs))
	t4 = sum(((pairs[s] ** 2 - mpairs[s]) * choose2[s] for s in pairs)) // 2
	CD = collections.Counter()
	for d in range(le):
		if counter[l[d]] >= 3:
			for c in range(le):
				if l[c] < l[d]:
					CD[l[d] - l[c]] += choose3[l[d]] * counter[l[c]]
	s1 = 0
	s2 = 0
	s4 = 0
	for a in range(le):
		for b in range(a + 1, le):
			s1 += 2 * CD[l[a] + l[b]] * counter[l[a]] * counter[l[b]]
			if counter[l[a] + 2 * l[b]] >= 3:
				s2 += 2 * choose3[l[a] + 2 * l[b]] * counter[l[a]] * counter[l[b]] ** 2
			if counter[2 * l[a] + l[b]] >= 3:
				s2 += 2 * choose3[2 * l[a] + l[b]] * counter[l[b]] * counter[l[a]] ** 2
			if counter[l[b]] >= 2 and counter[l[a] + 2 * l[b]] >= 3:
				s4 += counter[l[a]] * choose2[l[b]] * choose3[l[a] + 2 * l[b]]
			if counter[l[a]] >= 2 and counter[2 * l[a] + l[b]] >= 3:
				s4 += counter[l[b]] * choose2[l[a]] * choose3[2 * l[a] + l[b]]
	s = (s1 - s2) // 6
	s3 = 0
	for a in range(le):
		if counter[l[a]] >= 3 and counter[3 * l[a]] >= 3:
			s3 += choose3[l[a]] * choose3[3 * l[a]]
	return t1 + t2 + t3 + t4 + s + s3 + s4
n = int(input())
l = list(map(int, input().rstrip().split()))
print(squareCount(l))


import collections
import math
import os
import random
import re
import sys

def choose(n, k):
	if k > n:
		return 0
	k = min(k, n - k)
	(num, den) = (1, 1)
	for i in range(k):
		num *= n - i
		den *= i + 1
	return num // den

def squareCount(l):
	counter = collections.Counter(l)
	l = tuple(counter.keys())
	choose2 = collections.Counter()
	choose3 = collections.Counter()
	choose4 = collections.Counter()
	le = len(l)
	for n in counter:
		count = counter[n]
		if count >= 2:
			choose2[n] = choose(count, 2)
			if count >= 3:
				choose3[n] = choose(count, 3)
				if count >= 4:
					choose4[n] = choose(count, 4)
	t1 = 0
	t2 = 0
	for i in range(le):
		if counter[2 * l[i]] >= 2 and counter[l[i]] >= 4:
			t1 += choose4[l[i]] * choose2[2 * l[i]]
		if counter[l[i]] >= 2:
			for j in range(i + 1, le):
				if counter[l[j]] >= 2 and counter[l[i] + l[j]] >= 2:
					t2 += choose2[l[i]] * choose2[l[j]] * choose2[l[i] + l[j]]
	doubles = collections.Counter()
	for i in range(le):
		if counter[l[i]] >= 2 and counter[2 * l[i]] >= 2:
			doubles[2 * l[i]] = choose2[l[i]]
	pairs = collections.Counter()
	mpairs = collections.Counter()
	for i in range(le):
		for j in range(i + 1, le):
			if counter[l[i] + l[j]] >= 2:
				pairs[l[i] + l[j]] += counter[l[i]] * counter[l[j]]
				mpairs[l[i] + l[j]] += counter[l[i]] ** 2 * counter[l[j]] ** 2
	t3 = sum((pairs[s] * doubles[s] * choose2[s] for s in doubles if s in pairs))
	t4 = sum(((pairs[s] ** 2 - mpairs[s]) * choose2[s] for s in pairs)) // 2
	CD = collections.Counter()
	for d in range(le):
		if counter[l[d]] >= 3:
			for c in range(le):
				if l[c] < l[d]:
					CD[l[d] - l[c]] += choose3[l[d]] * counter[l[c]]
	s1 = 0
	s2 = 0
	s4 = 0
	for a in range(le):
		for b in range(a + 1, le):
			s1 += 2 * CD[l[a] + l[b]] * counter[l[a]] * counter[l[b]]
			if counter[l[a] + 2 * l[b]] >= 3:
				s2 += 2 * choose3[l[a] + 2 * l[b]] * counter[l[a]] * counter[l[b]] ** 2
			if counter[2 * l[a] + l[b]] >= 3:
				s2 += 2 * choose3[2 * l[a] + l[b]] * counter[l[b]] * counter[l[a]] ** 2
			if counter[l[b]] >= 2 and counter[l[a] + 2 * l[b]] >= 3:
				s4 += counter[l[a]] * choose2[l[b]] * choose3[l[a] + 2 * l[b]]
			if counter[l[a]] >= 2 and counter[2 * l[a] + l[b]] >= 3:
				s4 += counter[l[b]] * choose2[l[a]] * choose3[2 * l[a] + l[b]]
	s = (s1 - s2) // 6
	s3 = 0
	for a in range(le):
		if counter[l[a]] >= 3 and counter[3 * l[a]] >= 3:
			s3 += choose3[l[a]] * choose3[3 * l[a]]
	return t1 + t2 + t3 + t4 + s + s3 + s4
n = int(input())
l = list(map(int, input().rstrip().split()))
print(squareCount(l))


import collections
import math
import os
import random
import re
import sys

def choose(n, k):
	if k > n:
		return 0
	k = min(k, n - k)
	(num, den) = (1, 1)
	for i in range(k):
		num *= n - i
		den *= i + 1
	return num // den

def squareCount(l):
	counter = collections.Counter(l)
	l = tuple(counter.keys())
	choose2 = collections.Counter()
	choose3 = collections.Counter()
	choose4 = collections.Counter()
	le = len(l)
	for n in counter:
		count = counter[n]
		if count >= 2:
			choose2[n] = choose(count, 2)
			if count >= 3:
				choose3[n] = choose(count, 3)
				if count >= 4:
					choose4[n] = choose(count, 4)
	t1 = 0
	t2 = 0
	for i in range(le):
		if counter[2 * l[i]] >= 2 and counter[l[i]] >= 4:
			t1 += choose4[l[i]] * choose2[2 * l[i]]
		if counter[l[i]] >= 2:
			for j in range(i + 1, le):
				if counter[l[j]] >= 2 and counter[l[i] + l[j]] >= 2:
					t2 += choose2[l[i]] * choose2[l[j]] * choose2[l[i] + l[j]]
	doubles = collections.Counter()
	for i in range(le):
		if counter[l[i]] >= 2 and counter[2 * l[i]] >= 2:
			doubles[2 * l[i]] = choose2[l[i]]
	pairs = collections.Counter()
	mpairs = collections.Counter()
	for i in range(le):
		for j in range(i + 1, le):
			if counter[l[i] + l[j]] >= 2:
				pairs[l[i] + l[j]] += counter[l[i]] * counter[l[j]]
				mpairs[l[i] + l[j]] += counter[l[i]] ** 2 * counter[l[j]] ** 2
	t3 = sum((pairs[s] * doubles[s] * choose2[s] for s in doubles if s in pairs))
	t4 = sum(((pairs[s] ** 2 - mpairs[s]) * choose2[s] for s in pairs)) // 2
	CD = collections.Counter()
	for d in range(le):
		if counter[l[d]] >= 3:
			for c in range(le):
				if l[c] < l[d]:
					CD[l[d] - l[c]] += choose3[l[d]] * counter[l[c]]
	s1 = 0
	s2 = 0
	s4 = 0
	for a in range(le):
		for b in range(a + 1, le):
			s1 += 2 * CD[l[a] + l[b]] * counter[l[a]] * counter[l[b]]
			if counter[l[a] + 2 * l[b]] >= 3:
				s2 += 2 * choose3[l[a] + 2 * l[b]] * counter[l[a]] * counter[l[b]] ** 2
			if counter[2 * l[a] + l[b]] >= 3:
				s2 += 2 * choose3[2 * l[a] + l[b]] * counter[l[b]] * counter[l[a]] ** 2
			if counter[l[b]] >= 2 and counter[l[a] + 2 * l[b]] >= 3:
				s4 += counter[l[a]] * choose2[l[b]] * choose3[l[a] + 2 * l[b]]
			if counter[l[a]] >= 2 and counter[2 * l[a] + l[b]] >= 3:
				s4 += counter[l[b]] * choose2[l[a]] * choose3[2 * l[a] + l[b]]
	s = (s1 - s2) // 6
	s3 = 0
	for a in range(le):
		if counter[l[a]] >= 3 and counter[3 * l[a]] >= 3:
			s3 += choose3[l[a]] * choose3[3 * l[a]]
	return t1 + t2 + t3 + t4 + s + s3 + s4
n = int(input())
l = list(map(int, input().rstrip().split()))
print(squareCount(l))


import collections
import math
import os
import random
import re
import sys

def choose(n, k):
	if k > n:
		return 0
	k = min(k, n - k)
	(num, den) = (1, 1)
	for i in range(k):
		num *= n - i
		den *= i + 1
	return num // den

def squareCount(l):
	counter = collections.Counter(l)
	l = tuple(counter.keys())
	choose2 = collections.Counter()
	choose3 = collections.Counter()
	choose4 = collections.Counter()
	le = len(l)
	for n in counter:
		count = counter[n]
		if count >= 2:
			choose2[n] = choose(count, 2)
			if count >= 3:
				choose3[n] = choose(count, 3)
				if count >= 4:
					choose4[n] = choose(count, 4)
	t1 = 0
	t2 = 0
	for i in range(le):
		if counter[2 * l[i]] >= 2 and counter[l[i]] >= 4:
			t1 += choose4[l[i]] * choose2[2 * l[i]]
		if counter[l[i]] >= 2:
			for j in range(i + 1, le):
				if counter[l[j]] >= 2 and counter[l[i] + l[j]] >= 2:
					t2 += choose2[l[i]] * choose2[l[j]] * choose2[l[i] + l[j]]
	doubles = collections.Counter()
	for i in range(le):
		if counter[l[i]] >= 2 and counter[2 * l[i]] >= 2:
			doubles[2 * l[i]] = choose2[l[i]]
	pairs = collections.Counter()
	mpairs = collections.Counter()
	for i in range(le):
		for j in range(i + 1, le):
			if counter[l[i] + l[j]] >= 2:
				pairs[l[i] + l[j]] += counter[l[i]] * counter[l[j]]
				mpairs[l[i] + l[j]] += counter[l[i]] ** 2 * counter[l[j]] ** 2
	t3 = sum((pairs[s] * doubles[s] * choose2[s] for s in doubles if s in pairs))
	t4 = sum(((pairs[s] ** 2 - mpairs[s]) * choose2[s] for s in pairs)) // 2
	CD = collections.Counter()
	for d in range(le):
		if counter[l[d]] >= 3:
			for c in range(le):
				if l[c] < l[d]:
					CD[l[d] - l[c]] += choose3[l[d]] * counter[l[c]]
	s1 = 0
	s2 = 0
	s4 = 0
	for a in range(le):
		for b in range(a + 1, le):
			s1 += 2 * CD[l[a] + l[b]] * counter[l[a]] * counter[l[b]]
			if counter[l[a] + 2 * l[b]] >= 3:
				s2 += 2 * choose3[l[a] + 2 * l[b]] * counter[l[a]] * counter[l[b]] ** 2
			if counter[2 * l[a] + l[b]] >= 3:
				s2 += 2 * choose3[2 * l[a] + l[b]] * counter[l[b]] * counter[l[a]] ** 2
			if counter[l[b]] >= 2 and counter[l[a] + 2 * l[b]] >= 3:
				s4 += counter[l[a]] * choose2[l[b]] * choose3[l[a] + 2 * l[b]]
			if counter[l[a]] >= 2 and counter[2 * l[a] + l[b]] >= 3:
				s4 += counter[l[b]] * choose2[l[a]] * choose3[2 * l[a] + l[b]]
	s = (s1 - s2) // 6
	s3 = 0
	for a in range(le):
		if counter[l[a]] >= 3 and counter[3 * l[a]] >= 3:
			s3 += choose3[l[a]] * choose3[3 * l[a]]
	return t1 + t2 + t3 + t4 + s + s3 + s4
n = int(input())
l = list(map(int, input().rstrip().split()))
print(squareCount(l))


import collections
import math
import os
import random
import re
import sys

def choose(n, k):
	if k > n:
		return 0
	k = min(k, n - k)
	(num, den) = (1, 1)
	for i in range(k):
		num *= n - i
		den *= i + 1
	return num // den

def squareCount(l):
	counter = collections.Counter(l)
	l = tuple(counter.keys())
	choose2 = collections.Counter()
	choose3 = collections.Counter()
	choose4 = collections.Counter()
	le = len(l)
	for n in counter:
		count = counter[n]
		if count >= 2:
			choose2[n] = choose(count, 2)
			if count >= 3:
				choose3[n] = choose(count, 3)
				if count >= 4:
					choose4[n] = choose(count, 4)
	t1 = 0
	t2 = 0
	for i in range(le):
		if counter[2 * l[i]] >= 2 and counter[l[i]] >= 4:
			t1 += choose4[l[i]] * choose2[2 * l[i]]
		if counter[l[i]] >= 2:
			for j in range(i + 1, le):
				if counter[l[j]] >= 2 and counter[l[i] + l[j]] >= 2:
					t2 += choose2[l[i]] * choose2[l[j]] * choose2[l[i] + l[j]]
	doubles = collections.Counter()
	for i in range(le):
		if counter[l[i]] >= 2 and counter[2 * l[i]] >= 2:
			doubles[2 * l[i]] = choose2[l[i]]
	pairs = collections.Counter()
	mpairs = collections.Counter()
	for i in range(le):
		for j in range(i + 1, le):
			if counter[l[i] + l[j]] >= 2:
				pairs[l[i] + l[j]] += counter[l[i]] * counter[l[j]]
				mpairs[l[i] + l[j]] += counter[l[i]] ** 2 * counter[l[j]] ** 2
	t3 = sum((pairs[s] * doubles[s] * choose2[s] for s in doubles if s in pairs))
	t4 = sum(((pairs[s] ** 2 - mpairs[s]) * choose2[s] for s in pairs)) // 2
	CD = collections.Counter()
	for d in range(le):
		if counter[l[d]] >= 3:
			for c in range(le):
				if l[c] < l[d]:
					CD[l[d] - l[c]] += choose3[l[d]] * counter[l[c]]
	s1 = 0
	s2 = 0
	s4 = 0
	for a in range(le):
		for b in range(a + 1, le):
			s1 += 2 * CD[l[a] + l[b]] * counter[l[a]] * counter[l[b]]
			if counter[l[a] + 2 * l[b]] >= 3:
				s2 += 2 * choose3[l[a] + 2 * l[b]] * counter[l[a]] * counter[l[b]] ** 2
			if counter[2 * l[a] + l[b]] >= 3:
				s2 += 2 * choose3[2 * l[a] + l[b]] * counter[l[b]] * counter[l[a]] ** 2
			if counter[l[b]] >= 2 and counter[l[a] + 2 * l[b]] >= 3:
				s4 += counter[l[a]] * choose2[l[b]] * choose3[l[a] + 2 * l[b]]
			if counter[l[a]] >= 2 and counter[2 * l[a] + l[b]] >= 3:
				s4 += counter[l[b]] * choose2[l[a]] * choose3[2 * l[a] + l[b]]
	s = (s1 - s2) // 6
	s3 = 0
	for a in range(le):
		if counter[l[a]] >= 3 and counter[3 * l[a]] >= 3:
			s3 += choose3[l[a]] * choose3[3 * l[a]]
	return t1 + t2 + t3 + t4 + s + s3 + s4
n = int(input())
l = list(map(int, input().rstrip().split()))
print(squareCount(l))


import collections
import math
import os
import random
import re
import sys

def choose(n, k):
	if k > n:
		return 0
	k = min(k, n - k)
	(num, den) = (1, 1)
	for i in range(k):
		num *= n - i
		den *= i + 1
	return num // den

def squareCount(l):
	counter = collections.Counter(l)
	l = tuple(counter.keys())
	choose2 = collections.Counter()
	choose3 = collections.Counter()
	choose4 = collections.Counter()
	le = len(l)
	for n in counter:
		count = counter[n]
		if count >= 2:
			choose2[n] = choose(count, 2)
			if count >= 3:
				choose3[n] = choose(count, 3)
				if count >= 4:
					choose4[n] = choose(count, 4)
	t1 = 0
	t2 = 0
	for i in range(le):
		if counter[2 * l[i]] >= 2 and counter[l[i]] >= 4:
			t1 += choose4[l[i]] * choose2[2 * l[i]]
		if counter[l[i]] >= 2:
			for j in range(i + 1, le):
				if counter[l[j]] >= 2 and counter[l[i] + l[j]] >= 2:
					t2 += choose2[l[i]] * choose2[l[j]] * choose2[l[i] + l[j]]
	doubles = collections.Counter()
	for i in range(le):
		if counter[l[i]] >= 2 and counter[2 * l[i]] >= 2:
			doubles[2 * l[i]] = choose2[l[i]]
	pairs = collections.Counter()
	mpairs = collections.Counter()
	for i in range(le):
		for j in range(i + 1, le):
			if counter[l[i] + l[j]] >= 2:
				pairs[l[i] + l[j]] += counter[l[i]] * counter[l[j]]
				mpairs[l[i] + l[j]] += counter[l[i]] ** 2 * counter[l[j]] ** 2
	t3 = sum((pairs[s] * doubles[s] * choose2[s] for s in doubles if s in pairs))
	t4 = sum(((pairs[s] ** 2 - mpairs[s]) * choose2[s] for s in pairs)) // 2
	CD = collections.Counter()
	for d in range(le):
		if counter[l[d]] >= 3:
			for c in range(le):
				if l[c] < l[d]:
					CD[l[d] - l[c]] += choose3[l[d]] * counter[l[c]]
	s1 = 0
	s2 = 0
	s4 = 0
	for a in range(le):
		for b in range(a + 1, le):
			s1 += 2 * CD[l[a] + l[b]] * counter[l[a]] * counter[l[b]]
			if counter[l[a] + 2 * l[b]] >= 3:
				s2 += 2 * choose3[l[a] + 2 * l[b]] * counter[l[a]] * counter[l[b]] ** 2
			if counter[2 * l[a] + l[b]] >= 3:
				s2 += 2 * choose3[2 * l[a] + l[b]] * counter[l[b]] * counter[l[a]] ** 2
			if counter[l[b]] >= 2 and counter[l[a] + 2 * l[b]] >= 3:
				s4 += counter[l[a]] * choose2[l[b]] * choose3[l[a] + 2 * l[b]]
			if counter[l[a]] >= 2 and counter[2 * l[a] + l[b]] >= 3:
				s4 += counter[l[b]] * choose2[l[a]] * choose3[2 * l[a] + l[b]]
	s = (s1 - s2) // 6
	s3 = 0
	for a in range(le):
		if counter[l[a]] >= 3 and counter[3 * l[a]] >= 3:
			s3 += choose3[l[a]] * choose3[3 * l[a]]
	return t1 + t2 + t3 + t4 + s + s3 + s4
n = int(input())
l = list(map(int, input().rstrip().split()))
print(squareCount(l))


import collections
import math
import os
import random
import re
import sys

def choose(n, k):
	if k > n:
		return 0
	k = min(k, n - k)
	(num, den) = (1, 1)
	for i in range(k):
		num *= n - i
		den *= i + 1
	return num // den

def squareCount(l):
	counter = collections.Counter(l)
	l = tuple(counter.keys())
	choose2 = collections.Counter()
	choose3 = collections.Counter()
	choose4 = collections.Counter()
	le = len(l)
	for n in counter:
		count = counter[n]
		if count >= 2:
			choose2[n] = choose(count, 2)
			if count >= 3:
				choose3[n] = choose(count, 3)
				if count >= 4:
					choose4[n] = choose(count, 4)
	t1 = 0
	t2 = 0
	for i in range(le):
		if counter[2 * l[i]] >= 2 and counter[l[i]] >= 4:
			t1 += choose4[l[i]] * choose2[2 * l[i]]
		if counter[l[i]] >= 2:
			for j in range(i + 1, le):
				if counter[l[j]] >= 2 and counter[l[i] + l[j]] >= 2:
					t2 += choose2[l[i]] * choose2[l[j]] * choose2[l[i] + l[j]]
	doubles = collections.Counter()
	for i in range(le):
		if counter[l[i]] >= 2 and counter[2 * l[i]] >= 2:
			doubles[2 * l[i]] = choose2[l[i]]
	pairs = collections.Counter()
	mpairs = collections.Counter()
	for i in range(le):
		for j in range(i + 1, le):
			if counter[l[i] + l[j]] >= 2:
				pairs[l[i] + l[j]] += counter[l[i]] * counter[l[j]]
				mpairs[l[i] + l[j]] += counter[l[i]] ** 2 * counter[l[j]] ** 2
	t3 = sum((pairs[s] * doubles[s] * choose2[s] for s in doubles if s in pairs))
	t4 = sum(((pairs[s] ** 2 - mpairs[s]) * choose2[s] for s in pairs)) // 2
	CD = collections.Counter()
	for d in range(le):
		if counter[l[d]] >= 3:
			for c in range(le):
				if l[c] < l[d]:
					CD[l[d] - l[c]] += choose3[l[d]] * counter[l[c]]
	s1 = 0
	s2 = 0
	s4 = 0
	for a in range(le):
		for b in range(a + 1, le):
			s1 += 2 * CD[l[a] + l[b]] * counter[l[a]] * counter[l[b]]
			if counter[l[a] + 2 * l[b]] >= 3:
				s2 += 2 * choose3[l[a] + 2 * l[b]] * counter[l[a]] * counter[l[b]] ** 2
			if counter[2 * l[a] + l[b]] >= 3:
				s2 += 2 * choose3[2 * l[a] + l[b]] * counter[l[b]] * counter[l[a]] ** 2
			if counter[l[b]] >= 2 and counter[l[a] + 2 * l[b]] >= 3:
				s4 += counter[l[a]] * choose2[l[b]] * choose3[l[a] + 2 * l[b]]
			if counter[l[a]] >= 2 and counter[2 * l[a] + l[b]] >= 3:
				s4 += counter[l[b]] * choose2[l[a]] * choose3[2 * l[a] + l[b]]
	s = (s1 - s2) // 6
	s3 = 0
	for a in range(le):
		if counter[l[a]] >= 3 and counter[3 * l[a]] >= 3:
			s3 += choose3[l[a]] * choose3[3 * l[a]]
	return t1 + t2 + t3 + t4 + s + s3 + s4
n = int(input())
l = list(map(int, input().rstrip().split()))
print(squareCount(l))


import collections
import math
import os
import random
import re
import sys

def choose(n, k):
	if k > n:
		return 0
	k = min(k, n - k)
	(num, den) = (1, 1)
	for i in range(k):
		num *= n - i
		den *= i + 1
	return num // den

def squareCount(l):
	counter = collections.Counter(l)
	l = tuple(counter.keys())
	choose2 = collections.Counter()
	choose3 = collections.Counter()
	choose4 = collections.Counter()
	le = len(l)
	for n in counter:
		count = counter[n]
		if count >= 2:
			choose2[n] = choose(count, 2)
			if count >= 3:
				choose3[n] = choose(count, 3)
				if count >= 4:
					choose4[n] = choose(count, 4)
	t1 = 0
	t2 = 0
	for i in range(le):
		if counter[2 * l[i]] >= 2 and counter[l[i]] >= 4:
			t1 += choose4[l[i]] * choose2[2 * l[i]]
		if counter[l[i]] >= 2:
			for j in range(i + 1, le):
				if counter[l[j]] >= 2 and counter[l[i] + l[j]] >= 2:
					t2 += choose2[l[i]] * choose2[l[j]] * choose2[l[i] + l[j]]
	doubles = collections.Counter()
	for i in range(le):
		if counter[l[i]] >= 2 and counter[2 * l[i]] >= 2:
			doubles[2 * l[i]] = choose2[l[i]]
	pairs = collections.Counter()
	mpairs = collections.Counter()
	for i in range(le):
		for j in range(i + 1, le):
			if counter[l[i] + l[j]] >= 2:
				pairs[l[i] + l[j]] += counter[l[i]] * counter[l[j]]
				mpairs[l[i] + l[j]] += counter[l[i]] ** 2 * counter[l[j]] ** 2
	t3 = sum((pairs[s] * doubles[s] * choose2[s] for s in doubles if s in pairs))
	t4 = sum(((pairs[s] ** 2 - mpairs[s]) * choose2[s] for s in pairs)) // 2
	CD = collections.Counter()
	for d in range(le):
		if counter[l[d]] >= 3:
			for c in range(le):
				if l[c] < l[d]:
					CD[l[d] - l[c]] += choose3[l[d]] * counter[l[c]]
	s1 = 0
	s2 = 0
	s4 = 0
	for a in range(le):
		for b in range(a + 1, le):
			s1 += 2 * CD[l[a] + l[b]] * counter[l[a]] * counter[l[b]]
			if counter[l[a] + 2 * l[b]] >= 3:
				s2 += 2 * choose3[l[a] + 2 * l[b]] * counter[l[a]] * counter[l[b]] ** 2
			if counter[2 * l[a] + l[b]] >= 3:
				s2 += 2 * choose3[2 * l[a] + l[b]] * counter[l[b]] * counter[l[a]] ** 2
			if counter[l[b]] >= 2 and counter[l[a] + 2 * l[b]] >= 3:
				s4 += counter[l[a]] * choose2[l[b]] * choose3[l[a] + 2 * l[b]]
			if counter[l[a]] >= 2 and counter[2 * l[a] + l[b]] >= 3:
				s4 += counter[l[b]] * choose2[l[a]] * choose3[2 * l[a] + l[b]]
	s = (s1 - s2) // 6
	s3 = 0
	for a in range(le):
		if counter[l[a]] >= 3 and counter[3 * l[a]] >= 3:
			s3 += choose3[l[a]] * choose3[3 * l[a]]
	return t1 + t2 + t3 + t4 + s + s3 + s4
n = int(input())
l = list(map(int, input().rstrip().split()))
print(squareCount(l))


import collections
import math
import os
import random
import re
import sys

def choose(n, k):
	if k > n:
		return 0
	k = min(k, n - k)
	(num, den) = (1, 1)
	for i in range(k):
		num *= n - i
		den *= i + 1
	return num // den

def squareCount(l):
	counter = collections.Counter(l)
	l = tuple(counter.keys())
	choose2 = collections.Counter()
	choose3 = collections.Counter()
	choose4 = collections.Counter()
	le = len(l)
	for n in counter:
		count = counter[n]
		if count >= 2:
			choose2[n] = choose(count, 2)
			if count >= 3:
				choose3[n] = choose(count, 3)
				if count >= 4:
					choose4[n] = choose(count, 4)
	t1 = 0
	t2 = 0
	for i in range(le):
		if counter[2 * l[i]] >= 2 and counter[l[i]] >= 4:
			t1 += choose4[l[i]] * choose2[2 * l[i]]
		if counter[l[i]] >= 2:
			for j in range(i + 1, le):
				if counter[l[j]] >= 2 and counter[l[i] + l[j]] >= 2:
					t2 += choose2[l[i]] * choose2[l[j]] * choose2[l[i] + l[j]]
	doubles = collections.Counter()
	for i in range(le):
		if counter[l[i]] >= 2 and counter[2 * l[i]] >= 2:
			doubles[2 * l[i]] = choose2[l[i]]
	pairs = collections.Counter()
	mpairs = collections.Counter()
	for i in range(le):
		for j in range(i + 1, le):
			if counter[l[i] + l[j]] >= 2:
				pairs[l[i] + l[j]] += counter[l[i]] * counter[l[j]]
				mpairs[l[i] + l[j]] += counter[l[i]] ** 2 * counter[l[j]] ** 2
	t3 = sum((pairs[s] * doubles[s] * choose2[s] for s in doubles if s in pairs))
	t4 = sum(((pairs[s] ** 2 - mpairs[s]) * choose2[s] for s in pairs)) // 2
	CD = collections.Counter()
	for d in range(le):
		if counter[l[d]] >= 3:
			for c in range(le):
				if l[c] < l[d]:
					CD[l[d] - l[c]] += choose3[l[d]] * counter[l[c]]
	s1 = 0
	s2 = 0
	s4 = 0
	for a in range(le):
		for b in range(a + 1, le):
			s1 += 2 * CD[l[a] + l[b]] * counter[l[a]] * counter[l[b]]
			if counter[l[a] + 2 * l[b]] >= 3:
				s2 += 2 * choose3[l[a] + 2 * l[b]] * counter[l[a]] * counter[l[b]] ** 2
			if counter[2 * l[a] + l[b]] >= 3:
				s2 += 2 * choose3[2 * l[a] + l[b]] * counter[l[b]] * counter[l[a]] ** 2
			if counter[l[b]] >= 2 and counter[l[a] + 2 * l[b]] >= 3:
				s4 += counter[l[a]] * choose2[l[b]] * choose3[l[a] + 2 * l[b]]
			if counter[l[a]] >= 2 and counter[2 * l[a] + l[b]] >= 3:
				s4 += counter[l[b]] * choose2[l[a]] * choose3[2 * l[a] + l[b]]
	s = (s1 - s2) // 6
	s3 = 0
	for a in range(le):
		if counter[l[a]] >= 3 and counter[3 * l[a]] >= 3:
			s3 += choose3[l[a]] * choose3[3 * l[a]]
	return t1 + t2 + t3 + t4 + s + s3 + s4
n = int(input())
l = list(map(int, input().rstrip().split()))
print(squareCount(l))


import collections
import math
import os
import random
import re
import sys

def choose(n, k):
	if k > n:
		return 0
	k = min(k, n - k)
	(num, den) = (1, 1)
	for i in range(k):
		num *= n - i
		den *= i + 1
	return num // den

def squareCount(l):
	counter = collections.Counter(l)
	l = tuple(counter.keys())
	choose2 = collections.Counter()
	choose3 = collections.Counter()
	choose4 = collections.Counter()
	le = len(l)
	for n in counter:
		count = counter[n]
		if count >= 2:
			choose2[n] = choose(count, 2)
			if count >= 3:
				choose3[n] = choose(count, 3)
				if count >= 4:
					choose4[n] = choose(count, 4)
	t1 = 0
	t2 = 0
	for i in range(le):
		if counter[2 * l[i]] >= 2 and counter[l[i]] >= 4:
			t1 += choose4[l[i]] * choose2[2 * l[i]]
		if counter[l[i]] >= 2:
			for j in range(i + 1, le):
				if counter[l[j]] >= 2 and counter[l[i] + l[j]] >= 2:
					t2 += choose2[l[i]] * choose2[l[j]] * choose2[l[i] + l[j]]
	doubles = collections.Counter()
	for i in range(le):
		if counter[l[i]] >= 2 and counter[2 * l[i]] >= 2:
			doubles[2 * l[i]] = choose2[l[i]]
	pairs = collections.Counter()
	mpairs = collections.Counter()
	for i in range(le):
		for j in range(i + 1, le):
			if counter[l[i] + l[j]] >= 2:
				pairs[l[i] + l[j]] += counter[l[i]] * counter[l[j]]
				mpairs[l[i] + l[j]] += counter[l[i]] ** 2 * counter[l[j]] ** 2
	t3 = sum((pairs[s] * doubles[s] * choose2[s] for s in doubles if s in pairs))
	t4 = sum(((pairs[s] ** 2 - mpairs[s]) * choose2[s] for s in pairs)) // 2
	CD = collections.Counter()
	for d in range(le):
		if counter[l[d]] >= 3:
			for c in range(le):
				if l[c] < l[d]:
					CD[l[d] - l[c]] += choose3[l[d]] * counter[l[c]]
	s1 = 0
	s2 = 0
	s4 = 0
	for a in range(le):
		for b in range(a + 1, le):
			s1 += 2 * CD[l[a] + l[b]] * counter[l[a]] * counter[l[b]]
			if counter[l[a] + 2 * l[b]] >= 3:
				s2 += 2 * choose3[l[a] + 2 * l[b]] * counter[l[a]] * counter[l[b]] ** 2
			if counter[2 * l[a] + l[b]] >= 3:
				s2 += 2 * choose3[2 * l[a] + l[b]] * counter[l[b]] * counter[l[a]] ** 2
			if counter[l[b]] >= 2 and counter[l[a] + 2 * l[b]] >= 3:
				s4 += counter[l[a]] * choose2[l[b]] * choose3[l[a] + 2 * l[b]]
			if counter[l[a]] >= 2 and counter[2 * l[a] + l[b]] >= 3:
				s4 += counter[l[b]] * choose2[l[a]] * choose3[2 * l[a] + l[b]]
	s = (s1 - s2) // 6
	s3 = 0
	for a in range(le):
		if counter[l[a]] >= 3 and counter[3 * l[a]] >= 3:
			s3 += choose3[l[a]] * choose3[3 * l[a]]
	return t1 + t2 + t3 + t4 + s + s3 + s4
n = int(input())
l = list(map(int, input().rstrip().split()))
print(squareCount(l))


import collections
import math
import os
import random
import re
import sys

def choose(n, k):
	if k > n:
		return 0
	k = min(k, n - k)
	(num, den) = (1, 1)
	for i in range(k):
		num *= n - i
		den *= i + 1
	return num // den

def squareCount(l):
	counter = collections.Counter(l)
	l = tuple(counter.keys())
	choose2 = collections.Counter()
	choose3 = collections.Counter()
	choose4 = collections.Counter()
	le = len(l)
	for n in counter:
		count = counter[n]
		if count >= 2:
			choose2[n] = choose(count, 2)
			if count >= 3:
				choose3[n] = choose(count, 3)
				if count >= 4:
					choose4[n] = choose(count, 4)
	t1 = 0
	t2 = 0
	for i in range(le):
		if counter[2 * l[i]] >= 2 and counter[l[i]] >= 4:
			t1 += choose4[l[i]] * choose2[2 * l[i]]
		if counter[l[i]] >= 2:
			for j in range(i + 1, le):
				if counter[l[j]] >= 2 and counter[l[i] + l[j]] >= 2:
					t2 += choose2[l[i]] * choose2[l[j]] * choose2[l[i] + l[j]]
	doubles = collections.Counter()
	for i in range(le):
		if counter[l[i]] >= 2 and counter[2 * l[i]] >= 2:
			doubles[2 * l[i]] = choose2[l[i]]
	pairs = collections.Counter()
	mpairs = collections.Counter()
	for i in range(le):
		for j in range(i + 1, le):
			if counter[l[i] + l[j]] >= 2:
				pairs[l[i] + l[j]] += counter[l[i]] * counter[l[j]]
				mpairs[l[i] + l[j]] += counter[l[i]] ** 2 * counter[l[j]] ** 2
	t3 = sum((pairs[s] * doubles[s] * choose2[s] for s in doubles if s in pairs))
	t4 = sum(((pairs[s] ** 2 - mpairs[s]) * choose2[s] for s in pairs)) // 2
	CD = collections.Counter()
	for d in range(le):
		if counter[l[d]] >= 3:
			for c in range(le):
				if l[c] < l[d]:
					CD[l[d] - l[c]] += choose3[l[d]] * counter[l[c]]
	s1 = 0
	s2 = 0
	s4 = 0
	for a in range(le):
		for b in range(a + 1, le):
			s1 += 2 * CD[l[a] + l[b]] * counter[l[a]] * counter[l[b]]
			if counter[l[a] + 2 * l[b]] >= 3:
				s2 += 2 * choose3[l[a] + 2 * l[b]] * counter[l[a]] * counter[l[b]] ** 2
			if counter[2 * l[a] + l[b]] >= 3:
				s2 += 2 * choose3[2 * l[a] + l[b]] * counter[l[b]] * counter[l[a]] ** 2
			if counter[l[b]] >= 2 and counter[l[a] + 2 * l[b]] >= 3:
				s4 += counter[l[a]] * choose2[l[b]] * choose3[l[a] + 2 * l[b]]
			if counter[l[a]] >= 2 and counter[2 * l[a] + l[b]] >= 3:
				s4 += counter[l[b]] * choose2[l[a]] * choose3[2 * l[a] + l[b]]
	s = (s1 - s2) // 6
	s3 = 0
	for a in range(le):
		if counter[l[a]] >= 3 and counter[3 * l[a]] >= 3:
			s3 += choose3[l[a]] * choose3[3 * l[a]]
	return t1 + t2 + t3 + t4 + s + s3 + s4
n = int(input())
l = list(map(int, input().rstrip().split()))
print(squareCount(l))


import collections
import math
import os
import random
import re
import sys

def choose(n, k):
	if k > n:
		return 0
	k = min(k, n - k)
	(num, den) = (1, 1)
	for i in range(k):
		num *= n - i
		den *= i + 1
	return num // den

def squareCount(l):
	counter = collections.Counter(l)
	l = tuple(counter.keys())
	choose2 = collections.Counter()
	choose3 = collections.Counter()
	choose4 = collections.Counter()
	le = len(l)
	for n in counter:
		count = counter[n]
		if count >= 2:
			choose2[n] = choose(count, 2)
			if count >= 3:
				choose3[n] = choose(count, 3)
				if count >= 4:
					choose4[n] = choose(count, 4)
	t1 = 0
	t2 = 0
	for i in range(le):
		if counter[2 * l[i]] >= 2 and counter[l[i]] >= 4:
			t1 += choose4[l[i]] * choose2[2 * l[i]]
		if counter[l[i]] >= 2:
			for j in range(i + 1, le):
				if counter[l[j]] >= 2 and counter[l[i] + l[j]] >= 2:
					t2 += choose2[l[i]] * choose2[l[j]] * choose2[l[i] + l[j]]
	doubles = collections.Counter()
	for i in range(le):
		if counter[l[i]] >= 2 and counter[2 * l[i]] >= 2:
			doubles[2 * l[i]] = choose2[l[i]]
	pairs = collections.Counter()
	mpairs = collections.Counter()
	for i in range(le):
		for j in range(i + 1, le):
			if counter[l[i] + l[j]] >= 2:
				pairs[l[i] + l[j]] += counter[l[i]] * counter[l[j]]
				mpairs[l[i] + l[j]] += counter[l[i]] ** 2 * counter[l[j]] ** 2
	t3 = sum((pairs[s] * doubles[s] * choose2[s] for s in doubles if s in pairs))
	t4 = sum(((pairs[s] ** 2 - mpairs[s]) * choose2[s] for s in pairs)) // 2
	CD = collections.Counter()
	for d in range(le):
		if counter[l[d]] >= 3:
			for c in range(le):
				if l[c] < l[d]:
					CD[l[d] - l[c]] += choose3[l[d]] * counter[l[c]]
	s1 = 0
	s2 = 0
	s4 = 0
	for a in range(le):
		for b in range(a + 1, le):
			s1 += 2 * CD[l[a] + l[b]] * counter[l[a]] * counter[l[b]]
			if counter[l[a] + 2 * l[b]] >= 3:
				s2 += 2 * choose3[l[a] + 2 * l[b]] * counter[l[a]] * counter[l[b]] ** 2
			if counter[2 * l[a] + l[b]] >= 3:
				s2 += 2 * choose3[2 * l[a] + l[b]] * counter[l[b]] * counter[l[a]] ** 2
			if counter[l[b]] >= 2 and counter[l[a] + 2 * l[b]] >= 3:
				s4 += counter[l[a]] * choose2[l[b]] * choose3[l[a] + 2 * l[b]]
			if counter[l[a]] >= 2 and counter[2 * l[a] + l[b]] >= 3:
				s4 += counter[l[b]] * choose2[l[a]] * choose3[2 * l[a] + l[b]]
	s = (s1 - s2) // 6
	s3 = 0
	for a in range(le):
		if counter[l[a]] >= 3 and counter[3 * l[a]] >= 3:
			s3 += choose3[l[a]] * choose3[3 * l[a]]
	return t1 + t2 + t3 + t4 + s + s3 + s4
n = int(input())
l = list(map(int, input().rstrip().split()))
print(squareCount(l))


import collections
import math
import os
import random
import re
import sys

def choose(n, k):
	if k > n:
		return 0
	k = min(k, n - k)
	(num, den) = (1, 1)
	for i in range(k):
		num *= n - i
		den *= i + 1
	return num // den

def squareCount(l):
	counter = collections.Counter(l)
	l = tuple(counter.keys())
	choose2 = collections.Counter()
	choose3 = collections.Counter()
	choose4 = collections.Counter()
	le = len(l)
	for n in counter:
		count = counter[n]
		if count >= 2:
			choose2[n] = choose(count, 2)
			if count >= 3:
				choose3[n] = choose(count, 3)
				if count >= 4:
					choose4[n] = choose(count, 4)
	t1 = 0
	t2 = 0
	for i in range(le):
		if counter[2 * l[i]] >= 2 and counter[l[i]] >= 4:
			t1 += choose4[l[i]] * choose2[2 * l[i]]
		if counter[l[i]] >= 2:
			for j in range(i + 1, le):
				if counter[l[j]] >= 2 and counter[l[i] + l[j]] >= 2:
					t2 += choose2[l[i]] * choose2[l[j]] * choose2[l[i] + l[j]]
	doubles = collections.Counter()
	for i in range(le):
		if counter[l[i]] >= 2 and counter[2 * l[i]] >= 2:
			doubles[2 * l[i]] = choose2[l[i]]
	pairs = collections.Counter()
	mpairs = collections.Counter()
	for i in range(le):
		for j in range(i + 1, le):
			if counter[l[i] + l[j]] >= 2:
				pairs[l[i] + l[j]] += counter[l[i]] * counter[l[j]]
				mpairs[l[i] + l[j]] += counter[l[i]] ** 2 * counter[l[j]] ** 2
	t3 = sum((pairs[s] * doubles[s] * choose2[s] for s in doubles if s in pairs))
	t4 = sum(((pairs[s] ** 2 - mpairs[s]) * choose2[s] for s in pairs)) // 2
	CD = collections.Counter()
	for d in range(le):
		if counter[l[d]] >= 3:
			for c in range(le):
				if l[c] < l[d]:
					CD[l[d] - l[c]] += choose3[l[d]] * counter[l[c]]
	s1 = 0
	s2 = 0
	s4 = 0
	for a in range(le):
		for b in range(a + 1, le):
			s1 += 2 * CD[l[a] + l[b]] * counter[l[a]] * counter[l[b]]
			if counter[l[a] + 2 * l[b]] >= 3:
				s2 += 2 * choose3[l[a] + 2 * l[b]] * counter[l[a]] * counter[l[b]] ** 2
			if counter[2 * l[a] + l[b]] >= 3:
				s2 += 2 * choose3[2 * l[a] + l[b]] * counter[l[b]] * counter[l[a]] ** 2
			if counter[l[b]] >= 2 and counter[l[a] + 2 * l[b]] >= 3:
				s4 += counter[l[a]] * choose2[l[b]] * choose3[l[a] + 2 * l[b]]
			if counter[l[a]] >= 2 and counter[2 * l[a] + l[b]] >= 3:
				s4 += counter[l[b]] * choose2[l[a]] * choose3[2 * l[a] + l[b]]
	s = (s1 - s2) // 6
	s3 = 0
	for a in range(le):
		if counter[l[a]] >= 3 and counter[3 * l[a]] >= 3:
			s3 += choose3[l[a]] * choose3[3 * l[a]]
	return t1 + t2 + t3 + t4 + s + s3 + s4
n = int(input())
l = list(map(int, input().rstrip().split()))
print(squareCount(l))


import collections
import math
import os
import random
import re
import sys

def choose(n, k):
	if k > n:
		return 0
	k = min(k, n - k)
	(num, den) = (1, 1)
	for i in range(k):
		num *= n - i
		den *= i + 1
	return num // den

def squareCount(l):
	counter = collections.Counter(l)
	l = tuple(counter.keys())
	choose2 = collections.Counter()
	choose3 = collections.Counter()
	choose4 = collections.Counter()
	le = len(l)
	for n in counter:
		count = counter[n]
		if count >= 2:
			choose2[n] = choose(count, 2)
			if count >= 3:
				choose3[n] = choose(count, 3)
				if count >= 4:
					choose4[n] = choose(count, 4)
	t1 = 0
	t2 = 0
	for i in range(le):
		if counter[2 * l[i]] >= 2 and counter[l[i]] >= 4:
			t1 += choose4[l[i]] * choose2[2 * l[i]]
		if counter[l[i]] >= 2:
			for j in range(i + 1, le):
				if counter[l[j]] >= 2 and counter[l[i] + l[j]] >= 2:
					t2 += choose2[l[i]] * choose2[l[j]] * choose2[l[i] + l[j]]
	doubles = collections.Counter()
	for i in range(le):
		if counter[l[i]] >= 2 and counter[2 * l[i]] >= 2:
			doubles[2 * l[i]] = choose2[l[i]]
	pairs = collections.Counter()
	mpairs = collections.Counter()
	for i in range(le):
		for j in range(i + 1, le):
			if counter[l[i] + l[j]] >= 2:
				pairs[l[i] + l[j]] += counter[l[i]] * counter[l[j]]
				mpairs[l[i] + l[j]] += counter[l[i]] ** 2 * counter[l[j]] ** 2
	t3 = sum((pairs[s] * doubles[s] * choose2[s] for s in doubles if s in pairs))
	t4 = sum(((pairs[s] ** 2 - mpairs[s]) * choose2[s] for s in pairs)) // 2
	CD = collections.Counter()
	for d in range(le):
		if counter[l[d]] >= 3:
			for c in range(le):
				if l[c] < l[d]:
					CD[l[d] - l[c]] += choose3[l[d]] * counter[l[c]]
	s1 = 0
	s2 = 0
	s4 = 0
	for a in range(le):
		for b in range(a + 1, le):
			s1 += 2 * CD[l[a] + l[b]] * counter[l[a]] * counter[l[b]]
			if counter[l[a] + 2 * l[b]] >= 3:
				s2 += 2 * choose3[l[a] + 2 * l[b]] * counter[l[a]] * counter[l[b]] ** 2
			if counter[2 * l[a] + l[b]] >= 3:
				s2 += 2 * choose3[2 * l[a] + l[b]] * counter[l[b]] * counter[l[a]] ** 2
			if counter[l[b]] >= 2 and counter[l[a] + 2 * l[b]] >= 3:
				s4 += counter[l[a]] * choose2[l[b]] * choose3[l[a] + 2 * l[b]]
			if counter[l[a]] >= 2 and counter[2 * l[a] + l[b]] >= 3:
				s4 += counter[l[b]] * choose2[l[a]] * choose3[2 * l[a] + l[b]]
	s = (s1 - s2) // 6
	s3 = 0
	for a in range(le):
		if counter[l[a]] >= 3 and counter[3 * l[a]] >= 3:
			s3 += choose3[l[a]] * choose3[3 * l[a]]
	return t1 + t2 + t3 + t4 + s + s3 + s4
n = int(input())
l = list(map(int, input().rstrip().split()))
print(squareCount(l))


import collections
import math
import os
import random
import re
import sys

def choose(n, k):
	if k > n:
		return 0
	k = min(k, n - k)
	(num, den) = (1, 1)
	for i in range(k):
		num *= n - i
		den *= i + 1
	return num // den

def squareCount(l):
	counter = collections.Counter(l)
	l = tuple(counter.keys())
	choose2 = collections.Counter()
	choose3 = collections.Counter()
	choose4 = collections.Counter()
	le = len(l)
	for n in counter:
		count = counter[n]
		if count >= 2:
			choose2[n] = choose(count, 2)
			if count >= 3:
				choose3[n] = choose(count, 3)
				if count >= 4:
					choose4[n] = choose(count, 4)
	t1 = 0
	t2 = 0
	for i in range(le):
		if counter[2 * l[i]] >= 2 and counter[l[i]] >= 4:
			t1 += choose4[l[i]] * choose2[2 * l[i]]
		if counter[l[i]] >= 2:
			for j in range(i + 1, le):
				if counter[l[j]] >= 2 and counter[l[i] + l[j]] >= 2:
					t2 += choose2[l[i]] * choose2[l[j]] * choose2[l[i] + l[j]]
	doubles = collections.Counter()
	for i in range(le):
		if counter[l[i]] >= 2 and counter[2 * l[i]] >= 2:
			doubles[2 * l[i]] = choose2[l[i]]
	pairs = collections.Counter()
	mpairs = collections.Counter()
	for i in range(le):
		for j in range(i + 1, le):
			if counter[l[i] + l[j]] >= 2:
				pairs[l[i] + l[j]] += counter[l[i]] * counter[l[j]]
				mpairs[l[i] + l[j]] += counter[l[i]] ** 2 * counter[l[j]] ** 2
	t3 = sum((pairs[s] * doubles[s] * choose2[s] for s in doubles if s in pairs))
	t4 = sum(((pairs[s] ** 2 - mpairs[s]) * choose2[s] for s in pairs)) // 2
	CD = collections.Counter()
	for d in range(le):
		if counter[l[d]] >= 3:
			for c in range(le):
				if l[c] < l[d]:
					CD[l[d] - l[c]] += choose3[l[d]] * counter[l[c]]
	s1 = 0
	s2 = 0
	s4 = 0
	for a in range(le):
		for b in range(a + 1, le):
			s1 += 2 * CD[l[a] + l[b]] * counter[l[a]] * counter[l[b]]
			if counter[l[a] + 2 * l[b]] >= 3:
				s2 += 2 * choose3[l[a] + 2 * l[b]] * counter[l[a]] * counter[l[b]] ** 2
			if counter[2 * l[a] + l[b]] >= 3:
				s2 += 2 * choose3[2 * l[a] + l[b]] * counter[l[b]] * counter[l[a]] ** 2
			if counter[l[b]] >= 2 and counter[l[a] + 2 * l[b]] >= 3:
				s4 += counter[l[a]] * choose2[l[b]] * choose3[l[a] + 2 * l[b]]
			if counter[l[a]] >= 2 and counter[2 * l[a] + l[b]] >= 3:
				s4 += counter[l[b]] * choose2[l[a]] * choose3[2 * l[a] + l[b]]
	s = (s1 - s2) // 6
	s3 = 0
	for a in range(le):
		if counter[l[a]] >= 3 and counter[3 * l[a]] >= 3:
			s3 += choose3[l[a]] * choose3[3 * l[a]]
	return t1 + t2 + t3 + t4 + s + s3 + s4
n = int(input())
l = list(map(int, input().rstrip().split()))
print(squareCount(l))


import collections
import math
import os
import random
import re
import sys

def choose(n, k):
	if k > n:
		return 0
	k = min(k, n - k)
	(num, den) = (1, 1)
	for i in range(k):
		num *= n - i
		den *= i + 1
	return num // den

def squareCount(l):
	counter = collections.Counter(l)
	l = tuple(counter.keys())
	choose2 = collections.Counter()
	choose3 = collections.Counter()
	choose4 = collections.Counter()
	le = len(l)
	for n in counter:
		count = counter[n]
		if count >= 2:
			choose2[n] = choose(count, 2)
			if count >= 3:
				choose3[n] = choose(count, 3)
				if count >= 4:
					choose4[n] = choose(count, 4)
	t1 = 0
	t2 = 0
	for i in range(le):
		if counter[2 * l[i]] >= 2 and counter[l[i]] >= 4:
			t1 += choose4[l[i]] * choose2[2 * l[i]]
		if counter[l[i]] >= 2:
			for j in range(i + 1, le):
				if counter[l[j]] >= 2 and counter[l[i] + l[j]] >= 2:
					t2 += choose2[l[i]] * choose2[l[j]] * choose2[l[i] + l[j]]
	doubles = collections.Counter()
	for i in range(le):
		if counter[l[i]] >= 2 and counter[2 * l[i]] >= 2:
			doubles[2 * l[i]] = choose2[l[i]]
	pairs = collections.Counter()
	mpairs = collections.Counter()
	for i in range(le):
		for j in range(i + 1, le):
			if counter[l[i] + l[j]] >= 2:
				pairs[l[i] + l[j]] += counter[l[i]] * counter[l[j]]
				mpairs[l[i] + l[j]] += counter[l[i]] ** 2 * counter[l[j]] ** 2
	t3 = sum((pairs[s] * doubles[s] * choose2[s] for s in doubles if s in pairs))
	t4 = sum(((pairs[s] ** 2 - mpairs[s]) * choose2[s] for s in pairs)) // 2
	CD = collections.Counter()
	for d in range(le):
		if counter[l[d]] >= 3:
			for c in range(le):
				if l[c] < l[d]:
					CD[l[d] - l[c]] += choose3[l[d]] * counter[l[c]]
	s1 = 0
	s2 = 0
	s4 = 0
	for a in range(le):
		for b in range(a + 1, le):
			s1 += 2 * CD[l[a] + l[b]] * counter[l[a]] * counter[l[b]]
			if counter[l[a] + 2 * l[b]] >= 3:
				s2 += 2 * choose3[l[a] + 2 * l[b]] * counter[l[a]] * counter[l[b]] ** 2
			if counter[2 * l[a] + l[b]] >= 3:
				s2 += 2 * choose3[2 * l[a] + l[b]] * counter[l[b]] * counter[l[a]] ** 2
			if counter[l[b]] >= 2 and counter[l[a] + 2 * l[b]] >= 3:
				s4 += counter[l[a]] * choose2[l[b]] * choose3[l[a] + 2 * l[b]]
			if counter[l[a]] >= 2 and counter[2 * l[a] + l[b]] >= 3:
				s4 += counter[l[b]] * choose2[l[a]] * choose3[2 * l[a] + l[b]]
	s = (s1 - s2) // 6
	s3 = 0
	for a in range(le):
		if counter[l[a]] >= 3 and counter[3 * l[a]] >= 3:
			s3 += choose3[l[a]] * choose3[3 * l[a]]
	return t1 + t2 + t3 + t4 + s + s3 + s4
n = int(input())
l = list(map(int, input().rstrip().split()))
print(squareCount(l))


import collections
import math
import os
import random
import re
import sys

def choose(n, k):
	if k > n:
		return 0
	k = min(k, n - k)
	(num, den) = (1, 1)
	for i in range(k):
		num *= n - i
		den *= i + 1
	return num // den

def squareCount(l):
	counter = collections.Counter(l)
	l = tuple(counter.keys())
	choose2 = collections.Counter()
	choose3 = collections.Counter()
	choose4 = collections.Counter()
	le = len(l)
	for n in counter:
		count = counter[n]
		if count >= 2:
			choose2[n] = choose(count, 2)
			if count >= 3:
				choose3[n] = choose(count, 3)
				if count >= 4:
					choose4[n] = choose(count, 4)
	t1 = 0
	t2 = 0
	for i in range(le):
		if counter[2 * l[i]] >= 2 and counter[l[i]] >= 4:
			t1 += choose4[l[i]] * choose2[2 * l[i]]
		if counter[l[i]] >= 2:
			for j in range(i + 1, le):
				if counter[l[j]] >= 2 and counter[l[i] + l[j]] >= 2:
					t2 += choose2[l[i]] * choose2[l[j]] * choose2[l[i] + l[j]]
	doubles = collections.Counter()
	for i in range(le):
		if counter[l[i]] >= 2 and counter[2 * l[i]] >= 2:
			doubles[2 * l[i]] = choose2[l[i]]
	pairs = collections.Counter()
	mpairs = collections.Counter()
	for i in range(le):
		for j in range(i + 1, le):
			if counter[l[i] + l[j]] >= 2:
				pairs[l[i] + l[j]] += counter[l[i]] * counter[l[j]]
				mpairs[l[i] + l[j]] += counter[l[i]] ** 2 * counter[l[j]] ** 2
	t3 = sum((pairs[s] * doubles[s] * choose2[s] for s in doubles if s in pairs))
	t4 = sum(((pairs[s] ** 2 - mpairs[s]) * choose2[s] for s in pairs)) // 2
	CD = collections.Counter()
	for d in range(le):
		if counter[l[d]] >= 3:
			for c in range(le):
				if l[c] < l[d]:
					CD[l[d] - l[c]] += choose3[l[d]] * counter[l[c]]
	s1 = 0
	s2 = 0
	s4 = 0
	for a in range(le):
		for b in range(a + 1, le):
			s1 += 2 * CD[l[a] + l[b]] * counter[l[a]] * counter[l[b]]
			if counter[l[a] + 2 * l[b]] >= 3:
				s2 += 2 * choose3[l[a] + 2 * l[b]] * counter[l[a]] * counter[l[b]] ** 2
			if counter[2 * l[a] + l[b]] >= 3:
				s2 += 2 * choose3[2 * l[a] + l[b]] * counter[l[b]] * counter[l[a]] ** 2
			if counter[l[b]] >= 2 and counter[l[a] + 2 * l[b]] >= 3:
				s4 += counter[l[a]] * choose2[l[b]] * choose3[l[a] + 2 * l[b]]
			if counter[l[a]] >= 2 and counter[2 * l[a] + l[b]] >= 3:
				s4 += counter[l[b]] * choose2[l[a]] * choose3[2 * l[a] + l[b]]
	s = (s1 - s2) // 6
	s3 = 0
	for a in range(le):
		if counter[l[a]] >= 3 and counter[3 * l[a]] >= 3:
			s3 += choose3[l[a]] * choose3[3 * l[a]]
	return t1 + t2 + t3 + t4 + s + s3 + s4
n = int(input())
l = list(map(int, input().rstrip().split()))
print(squareCount(l))


import collections
import math
import os
import random
import re
import sys

def choose(n, k):
	if k > n:
		return 0
	k = min(k, n - k)
	(num, den) = (1, 1)
	for i in range(k):
		num *= n - i
		den *= i + 1
	return num // den

def squareCount(l):
	counter = collections.Counter(l)
	l = tuple(counter.keys())
	choose2 = collections.Counter()
	choose3 = collections.Counter()
	choose4 = collections.Counter()
	le = len(l)
	for n in counter:
		count = counter[n]
		if count >= 2:
			choose2[n] = choose(count, 2)
			if count >= 3:
				choose3[n] = choose(count, 3)
				if count >= 4:
					choose4[n] = choose(count, 4)
	t1 = 0
	t2 = 0
	for i in range(le):
		if counter[2 * l[i]] >= 2 and counter[l[i]] >= 4:
			t1 += choose4[l[i]] * choose2[2 * l[i]]
		if counter[l[i]] >= 2:
			for j in range(i + 1, le):
				if counter[l[j]] >= 2 and counter[l[i] + l[j]] >= 2:
					t2 += choose2[l[i]] * choose2[l[j]] * choose2[l[i] + l[j]]
	doubles = collections.Counter()
	for i in range(le):
		if counter[l[i]] >= 2 and counter[2 * l[i]] >= 2:
			doubles[2 * l[i]] = choose2[l[i]]
	pairs = collections.Counter()
	mpairs = collections.Counter()
	for i in range(le):
		for j in range(i + 1, le):
			if counter[l[i] + l[j]] >= 2:
				pairs[l[i] + l[j]] += counter[l[i]] * counter[l[j]]
				mpairs[l[i] + l[j]] += counter[l[i]] ** 2 * counter[l[j]] ** 2
	t3 = sum((pairs[s] * doubles[s] * choose2[s] for s in doubles if s in pairs))
	t4 = sum(((pairs[s] ** 2 - mpairs[s]) * choose2[s] for s in pairs)) // 2
	CD = collections.Counter()
	for d in range(le):
		if counter[l[d]] >= 3:
			for c in range(le):
				if l[c] < l[d]:
					CD[l[d] - l[c]] += choose3[l[d]] * counter[l[c]]
	s1 = 0
	s2 = 0
	s4 = 0
	for a in range(le):
		for b in range(a + 1, le):
			s1 += 2 * CD[l[a] + l[b]] * counter[l[a]] * counter[l[b]]
			if counter[l[a] + 2 * l[b]] >= 3:
				s2 += 2 * choose3[l[a] + 2 * l[b]] * counter[l[a]] * counter[l[b]] ** 2
			if counter[2 * l[a] + l[b]] >= 3:
				s2 += 2 * choose3[2 * l[a] + l[b]] * counter[l[b]] * counter[l[a]] ** 2
			if counter[l[b]] >= 2 and counter[l[a] + 2 * l[b]] >= 3:
				s4 += counter[l[a]] * choose2[l[b]] * choose3[l[a] + 2 * l[b]]
			if counter[l[a]] >= 2 and counter[2 * l[a] + l[b]] >= 3:
				s4 += counter[l[b]] * choose2[l[a]] * choose3[2 * l[a] + l[b]]
	s = (s1 - s2) // 6
	s3 = 0
	for a in range(le):
		if counter[l[a]] >= 3 and counter[3 * l[a]] >= 3:
			s3 += choose3[l[a]] * choose3[3 * l[a]]
	return t1 + t2 + t3 + t4 + s + s3 + s4
n = int(input())
l = list(map(int, input().rstrip().split()))
print(squareCount(l))


import collections
import math
import os
import random
import re
import sys

def choose(n, k):
	if k > n:
		return 0
	k = min(k, n - k)
	(num, den) = (1, 1)
	for i in range(k):
		num *= n - i
		den *= i + 1
	return num // den

def squareCount(l):
	counter = collections.Counter(l)
	l = tuple(counter.keys())
	choose2 = collections.Counter()
	choose3 = collections.Counter()
	choose4 = collections.Counter()
	le = len(l)
	for n in counter:
		count = counter[n]
		if count >= 2:
			choose2[n] = choose(count, 2)
			if count >= 3:
				choose3[n] = choose(count, 3)
				if count >= 4:
					choose4[n] = choose(count, 4)
	t1 = 0
	t2 = 0
	for i in range(le):
		if counter[2 * l[i]] >= 2 and counter[l[i]] >= 4:
			t1 += choose4[l[i]] * choose2[2 * l[i]]
		if counter[l[i]] >= 2:
			for j in range(i + 1, le):
				if counter[l[j]] >= 2 and counter[l[i] + l[j]] >= 2:
					t2 += choose2[l[i]] * choose2[l[j]] * choose2[l[i] + l[j]]
	doubles = collections.Counter()
	for i in range(le):
		if counter[l[i]] >= 2 and counter[2 * l[i]] >= 2:
			doubles[2 * l[i]] = choose2[l[i]]
	pairs = collections.Counter()
	mpairs = collections.Counter()
	for i in range(le):
		for j in range(i + 1, le):
			if counter[l[i] + l[j]] >= 2:
				pairs[l[i] + l[j]] += counter[l[i]] * counter[l[j]]
				mpairs[l[i] + l[j]] += counter[l[i]] ** 2 * counter[l[j]] ** 2
	t3 = sum((pairs[s] * doubles[s] * choose2[s] for s in doubles if s in pairs))
	t4 = sum(((pairs[s] ** 2 - mpairs[s]) * choose2[s] for s in pairs)) // 2
	CD = collections.Counter()
	for d in range(le):
		if counter[l[d]] >= 3:
			for c in range(le):
				if l[c] < l[d]:
					CD[l[d] - l[c]] += choose3[l[d]] * counter[l[c]]
	s1 = 0
	s2 = 0
	s4 = 0
	for a in range(le):
		for b in range(a + 1, le):
			s1 += 2 * CD[l[a] + l[b]] * counter[l[a]] * counter[l[b]]
			if counter[l[a] + 2 * l[b]] >= 3:
				s2 += 2 * choose3[l[a] + 2 * l[b]] * counter[l[a]] * counter[l[b]] ** 2
			if counter[2 * l[a] + l[b]] >= 3:
				s2 += 2 * choose3[2 * l[a] + l[b]] * counter[l[b]] * counter[l[a]] ** 2
			if counter[l[b]] >= 2 and counter[l[a] + 2 * l[b]] >= 3:
				s4 += counter[l[a]] * choose2[l[b]] * choose3[l[a] + 2 * l[b]]
			if counter[l[a]] >= 2 and counter[2 * l[a] + l[b]] >= 3:
				s4 += counter[l[b]] * choose2[l[a]] * choose3[2 * l[a] + l[b]]
	s = (s1 - s2) // 6
	s3 = 0
	for a in range(le):
		if counter[l[a]] >= 3 and counter[3 * l[a]] >= 3:
			s3 += choose3[l[a]] * choose3[3 * l[a]]
	return t1 + t2 + t3 + t4 + s + s3 + s4
n = int(input())
l = list(map(int, input().rstrip().split()))
print(squareCount(l))


import collections
import math
import os
import random
import re
import sys

def choose(n, k):
	if k > n:
		return 0
	k = min(k, n - k)
	(num, den) = (1, 1)
	for i in range(k):
		num *= n - i
		den *= i + 1
	return num // den

def squareCount(l):
	counter = collections.Counter(l)
	l = tuple(counter.keys())
	choose2 = collections.Counter()
	choose3 = collections.Counter()
	choose4 = collections.Counter()
	le = len(l)
	for n in counter:
		count = counter[n]
		if count >= 2:
			choose2[n] = choose(count, 2)
			if count >= 3:
				choose3[n] = choose(count, 3)
				if count >= 4:
					choose4[n] = choose(count, 4)
	t1 = 0
	t2 = 0
	for i in range(le):
		if counter[2 * l[i]] >= 2 and counter[l[i]] >= 4:
			t1 += choose4[l[i]] * choose2[2 * l[i]]
		if counter[l[i]] >= 2:
			for j in range(i + 1, le):
				if counter[l[j]] >= 2 and counter[l[i] + l[j]] >= 2:
					t2 += choose2[l[i]] * choose2[l[j]] * choose2[l[i] + l[j]]
	doubles = collections.Counter()
	for i in range(le):
		if counter[l[i]] >= 2 and counter[2 * l[i]] >= 2:
			doubles[2 * l[i]] = choose2[l[i]]
	pairs = collections.Counter()
	mpairs = collections.Counter()
	for i in range(le):
		for j in range(i + 1, le):
			if counter[l[i] + l[j]] >= 2:
				pairs[l[i] + l[j]] += counter[l[i]] * counter[l[j]]
				mpairs[l[i] + l[j]] += counter[l[i]] ** 2 * counter[l[j]] ** 2
	t3 = sum((pairs[s] * doubles[s] * choose2[s] for s in doubles if s in pairs))
	t4 = sum(((pairs[s] ** 2 - mpairs[s]) * choose2[s] for s in pairs)) // 2
	CD = collections.Counter()
	for d in range(le):
		if counter[l[d]] >= 3:
			for c in range(le):
				if l[c] < l[d]:
					CD[l[d] - l[c]] += choose3[l[d]] * counter[l[c]]
	s1 = 0
	s2 = 0
	s4 = 0
	for a in range(le):
		for b in range(a + 1, le):
			s1 += 2 * CD[l[a] + l[b]] * counter[l[a]] * counter[l[b]]
			if counter[l[a] + 2 * l[b]] >= 3:
				s2 += 2 * choose3[l[a] + 2 * l[b]] * counter[l[a]] * counter[l[b]] ** 2
			if counter[2 * l[a] + l[b]] >= 3:
				s2 += 2 * choose3[2 * l[a] + l[b]] * counter[l[b]] * counter[l[a]] ** 2
			if counter[l[b]] >= 2 and counter[l[a] + 2 * l[b]] >= 3:
				s4 += counter[l[a]] * choose2[l[b]] * choose3[l[a] + 2 * l[b]]
			if counter[l[a]] >= 2 and counter[2 * l[a] + l[b]] >= 3:
				s4 += counter[l[b]] * choose2[l[a]] * choose3[2 * l[a] + l[b]]
	s = (s1 - s2) // 6
	s3 = 0
	for a in range(le):
		if counter[l[a]] >= 3 and counter[3 * l[a]] >= 3:
			s3 += choose3[l[a]] * choose3[3 * l[a]]
	return t1 + t2 + t3 + t4 + s + s3 + s4
n = int(input())
l = list(map(int, input().rstrip().split()))
print(squareCount(l))


import collections
import math
import os
import random
import re
import sys

def choose(n, k):
	if k > n:
		return 0
	k = min(k, n - k)
	(num, den) = (1, 1)
	for i in range(k):
		num *= n - i
		den *= i + 1
	return num // den

def squareCount(l):
	counter = collections.Counter(l)
	l = tuple(counter.keys())
	choose2 = collections.Counter()
	choose3 = collections.Counter()
	choose4 = collections.Counter()
	le = len(l)
	for n in counter:
		count = counter[n]
		if count >= 2:
			choose2[n] = choose(count, 2)
			if count >= 3:
				choose3[n] = choose(count, 3)
				if count >= 4:
					choose4[n] = choose(count, 4)
	t1 = 0
	t2 = 0
	for i in range(le):
		if counter[2 * l[i]] >= 2 and counter[l[i]] >= 4:
			t1 += choose4[l[i]] * choose2[2 * l[i]]
		if counter[l[i]] >= 2:
			for j in range(i + 1, le):
				if counter[l[j]] >= 2 and counter[l[i] + l[j]] >= 2:
					t2 += choose2[l[i]] * choose2[l[j]] * choose2[l[i] + l[j]]
	doubles = collections.Counter()
	for i in range(le):
		if counter[l[i]] >= 2 and counter[2 * l[i]] >= 2:
			doubles[2 * l[i]] = choose2[l[i]]
	pairs = collections.Counter()
	mpairs = collections.Counter()
	for i in range(le):
		for j in range(i + 1, le):
			if counter[l[i] + l[j]] >= 2:
				pairs[l[i] + l[j]] += counter[l[i]] * counter[l[j]]
				mpairs[l[i] + l[j]] += counter[l[i]] ** 2 * counter[l[j]] ** 2
	t3 = sum((pairs[s] * doubles[s] * choose2[s] for s in doubles if s in pairs))
	t4 = sum(((pairs[s] ** 2 - mpairs[s]) * choose2[s] for s in pairs)) // 2
	CD = collections.Counter()
	for d in range(le):
		if counter[l[d]] >= 3:
			for c in range(le):
				if l[c] < l[d]:
					CD[l[d] - l[c]] += choose3[l[d]] * counter[l[c]]
	s1 = 0
	s2 = 0
	s4 = 0
	for a in range(le):
		for b in range(a + 1, le):
			s1 += 2 * CD[l[a] + l[b]] * counter[l[a]] * counter[l[b]]
			if counter[l[a] + 2 * l[b]] >= 3:
				s2 += 2 * choose3[l[a] + 2 * l[b]] * counter[l[a]] * counter[l[b]] ** 2
			if counter[2 * l[a] + l[b]] >= 3:
				s2 += 2 * choose3[2 * l[a] + l[b]] * counter[l[b]] * counter[l[a]] ** 2
			if counter[l[b]] >= 2 and counter[l[a] + 2 * l[b]] >= 3:
				s4 += counter[l[a]] * choose2[l[b]] * choose3[l[a] + 2 * l[b]]
			if counter[l[a]] >= 2 and counter[2 * l[a] + l[b]] >= 3:
				s4 += counter[l[b]] * choose2[l[a]] * choose3[2 * l[a] + l[b]]
	s = (s1 - s2) // 6
	s3 = 0
	for a in range(le):
		if counter[l[a]] >= 3 and counter[3 * l[a]] >= 3:
			s3 += choose3[l[a]] * choose3[3 * l[a]]
	return t1 + t2 + t3 + t4 + s + s3 + s4
n = int(input())
l = list(map(int, input().rstrip().split()))
print(squareCount(l))


import collections
import math
import os
import random
import re
import sys

def choose(n, k):
	if k > n:
		return 0
	k = min(k, n - k)
	(num, den) = (1, 1)
	for i in range(k):
		num *= n - i
		den *= i + 1
	return num // den

def squareCount(l):
	counter = collections.Counter(l)
	l = tuple(counter.keys())
	choose2 = collections.Counter()
	choose3 = collections.Counter()
	choose4 = collections.Counter()
	le = len(l)
	for n in counter:
		count = counter[n]
		if count >= 2:
			choose2[n] = choose(count, 2)
			if count >= 3:
				choose3[n] = choose(count, 3)
				if count >= 4:
					choose4[n] = choose(count, 4)
	t1 = 0
	t2 = 0
	for i in range(le):
		if counter[2 * l[i]] >= 2 and counter[l[i]] >= 4:
			t1 += choose4[l[i]] * choose2[2 * l[i]]
		if counter[l[i]] >= 2:
			for j in range(i + 1, le):
				if counter[l[j]] >= 2 and counter[l[i] + l[j]] >= 2:
					t2 += choose2[l[i]] * choose2[l[j]] * choose2[l[i] + l[j]]
	doubles = collections.Counter()
	for i in range(le):
		if counter[l[i]] >= 2 and counter[2 * l[i]] >= 2:
			doubles[2 * l[i]] = choose2[l[i]]
	pairs = collections.Counter()
	mpairs = collections.Counter()
	for i in range(le):
		for j in range(i + 1, le):
			if counter[l[i] + l[j]] >= 2:
				pairs[l[i] + l[j]] += counter[l[i]] * counter[l[j]]
				mpairs[l[i] + l[j]] += counter[l[i]] ** 2 * counter[l[j]] ** 2
	t3 = sum((pairs[s] * doubles[s] * choose2[s] for s in doubles if s in pairs))
	t4 = sum(((pairs[s] ** 2 - mpairs[s]) * choose2[s] for s in pairs)) // 2
	CD = collections.Counter()
	for d in range(le):
		if counter[l[d]] >= 3:
			for c in range(le):
				if l[c] < l[d]:
					CD[l[d] - l[c]] += choose3[l[d]] * counter[l[c]]
	s1 = 0
	s2 = 0
	s4 = 0
	for a in range(le):
		for b in range(a + 1, le):
			s1 += 2 * CD[l[a] + l[b]] * counter[l[a]] * counter[l[b]]
			if counter[l[a] + 2 * l[b]] >= 3:
				s2 += 2 * choose3[l[a] + 2 * l[b]] * counter[l[a]] * counter[l[b]] ** 2
			if counter[2 * l[a] + l[b]] >= 3:
				s2 += 2 * choose3[2 * l[a] + l[b]] * counter[l[b]] * counter[l[a]] ** 2
			if counter[l[b]] >= 2 and counter[l[a] + 2 * l[b]] >= 3:
				s4 += counter[l[a]] * choose2[l[b]] * choose3[l[a] + 2 * l[b]]
			if counter[l[a]] >= 2 and counter[2 * l[a] + l[b]] >= 3:
				s4 += counter[l[b]] * choose2[l[a]] * choose3[2 * l[a] + l[b]]
	s = (s1 - s2) // 6
	s3 = 0
	for a in range(le):
		if counter[l[a]] >= 3 and counter[3 * l[a]] >= 3:
			s3 += choose3[l[a]] * choose3[3 * l[a]]
	return t1 + t2 + t3 + t4 + s + s3 + s4
n = int(input())
l = list(map(int, input().rstrip().split()))
print(squareCount(l))


import collections
import math
import os
import random
import re
import sys

def choose(n, k):
	if k > n:
		return 0
	k = min(k, n - k)
	(num, den) = (1, 1)
	for i in range(k):
		num *= n - i
		den *= i + 1
	return num // den

def squareCount(l):
	counter = collections.Counter(l)
	l = tuple(counter.keys())
	choose2 = collections.Counter()
	choose3 = collections.Counter()
	choose4 = collections.Counter()
	le = len(l)
	for n in counter:
		count = counter[n]
		if count >= 2:
			choose2[n] = choose(count, 2)
			if count >= 3:
				choose3[n] = choose(count, 3)
				if count >= 4:
					choose4[n] = choose(count, 4)
	t1 = 0
	t2 = 0
	for i in range(le):
		if counter[2 * l[i]] >= 2 and counter[l[i]] >= 4:
			t1 += choose4[l[i]] * choose2[2 * l[i]]
		if counter[l[i]] >= 2:
			for j in range(i + 1, le):
				if counter[l[j]] >= 2 and counter[l[i] + l[j]] >= 2:
					t2 += choose2[l[i]] * choose2[l[j]] * choose2[l[i] + l[j]]
	doubles = collections.Counter()
	for i in range(le):
		if counter[l[i]] >= 2 and counter[2 * l[i]] >= 2:
			doubles[2 * l[i]] = choose2[l[i]]
	pairs = collections.Counter()
	mpairs = collections.Counter()
	for i in range(le):
		for j in range(i + 1, le):
			if counter[l[i] + l[j]] >= 2:
				pairs[l[i] + l[j]] += counter[l[i]] * counter[l[j]]
				mpairs[l[i] + l[j]] += counter[l[i]] ** 2 * counter[l[j]] ** 2
	t3 = sum((pairs[s] * doubles[s] * choose2[s] for s in doubles if s in pairs))
	t4 = sum(((pairs[s] ** 2 - mpairs[s]) * choose2[s] for s in pairs)) // 2
	CD = collections.Counter()
	for d in range(le):
		if counter[l[d]] >= 3:
			for c in range(le):
				if l[c] < l[d]:
					CD[l[d] - l[c]] += choose3[l[d]] * counter[l[c]]
	s1 = 0
	s2 = 0
	s4 = 0
	for a in range(le):
		for b in range(a + 1, le):
			s1 += 2 * CD[l[a] + l[b]] * counter[l[a]] * counter[l[b]]
			if counter[l[a] + 2 * l[b]] >= 3:
				s2 += 2 * choose3[l[a] + 2 * l[b]] * counter[l[a]] * counter[l[b]] ** 2
			if counter[2 * l[a] + l[b]] >= 3:
				s2 += 2 * choose3[2 * l[a] + l[b]] * counter[l[b]] * counter[l[a]] ** 2
			if counter[l[b]] >= 2 and counter[l[a] + 2 * l[b]] >= 3:
				s4 += counter[l[a]] * choose2[l[b]] * choose3[l[a] + 2 * l[b]]
			if counter[l[a]] >= 2 and counter[2 * l[a] + l[b]] >= 3:
				s4 += counter[l[b]] * choose2[l[a]] * choose3[2 * l[a] + l[b]]
	s = (s1 - s2) // 6
	s3 = 0
	for a in range(le):
		if counter[l[a]] >= 3 and counter[3 * l[a]] >= 3:
			s3 += choose3[l[a]] * choose3[3 * l[a]]
	return t1 + t2 + t3 + t4 + s + s3 + s4
n = int(input())
l = list(map(int, input().rstrip().split()))
print(squareCount(l))


import collections
import math
import os
import random
import re
import sys

def choose(n, k):
	if k > n:
		return 0
	k = min(k, n - k)
	(num, den) = (1, 1)
	for i in range(k):
		num *= n - i
		den *= i + 1
	return num // den

def squareCount(l):
	counter = collections.Counter(l)
	l = tuple(counter.keys())
	choose2 = collections.Counter()
	choose3 = collections.Counter()
	choose4 = collections.Counter()
	le = len(l)
	for n in counter:
		count = counter[n]
		if count >= 2:
			choose2[n] = choose(count, 2)
			if count >= 3:
				choose3[n] = choose(count, 3)
				if count >= 4:
					choose4[n] = choose(count, 4)
	t1 = 0
	t2 = 0
	for i in range(le):
		if counter[2 * l[i]] >= 2 and counter[l[i]] >= 4:
			t1 += choose4[l[i]] * choose2[2 * l[i]]
		if counter[l[i]] >= 2:
			for j in range(i + 1, le):
				if counter[l[j]] >= 2 and counter[l[i] + l[j]] >= 2:
					t2 += choose2[l[i]] * choose2[l[j]] * choose2[l[i] + l[j]]
	doubles = collections.Counter()
	for i in range(le):
		if counter[l[i]] >= 2 and counter[2 * l[i]] >= 2:
			doubles[2 * l[i]] = choose2[l[i]]
	pairs = collections.Counter()
	mpairs = collections.Counter()
	for i in range(le):
		for j in range(i + 1, le):
			if counter[l[i] + l[j]] >= 2:
				pairs[l[i] + l[j]] += counter[l[i]] * counter[l[j]]
				mpairs[l[i] + l[j]] += counter[l[i]] ** 2 * counter[l[j]] ** 2
	t3 = sum((pairs[s] * doubles[s] * choose2[s] for s in doubles if s in pairs))
	t4 = sum(((pairs[s] ** 2 - mpairs[s]) * choose2[s] for s in pairs)) // 2
	CD = collections.Counter()
	for d in range(le):
		if counter[l[d]] >= 3:
			for c in range(le):
				if l[c] < l[d]:
					CD[l[d] - l[c]] += choose3[l[d]] * counter[l[c]]
	s1 = 0
	s2 = 0
	s4 = 0
	for a in range(le):
		for b in range(a + 1, le):
			s1 += 2 * CD[l[a] + l[b]] * counter[l[a]] * counter[l[b]]
			if counter[l[a] + 2 * l[b]] >= 3:
				s2 += 2 * choose3[l[a] + 2 * l[b]] * counter[l[a]] * counter[l[b]] ** 2
			if counter[2 * l[a] + l[b]] >= 3:
				s2 += 2 * choose3[2 * l[a] + l[b]] * counter[l[b]] * counter[l[a]] ** 2
			if counter[l[b]] >= 2 and counter[l[a] + 2 * l[b]] >= 3:
				s4 += counter[l[a]] * choose2[l[b]] * choose3[l[a] + 2 * l[b]]
			if counter[l[a]] >= 2 and counter[2 * l[a] + l[b]] >= 3:
				s4 += counter[l[b]] * choose2[l[a]] * choose3[2 * l[a] + l[b]]
	s = (s1 - s2) // 6
	s3 = 0
	for a in range(le):
		if counter[l[a]] >= 3 and counter[3 * l[a]] >= 3:
			s3 += choose3[l[a]] * choose3[3 * l[a]]
	return t1 + t2 + t3 + t4 + s + s3 + s4
n = int(input())
l = list(map(int, input().rstrip().split()))
print(squareCount(l))


import collections
import math
import os
import random
import re
import sys

def choose(n, k):
	if k > n:
		return 0
	k = min(k, n - k)
	(num, den) = (1, 1)
	for i in range(k):
		num *= n - i
		den *= i + 1
	return num // den

def squareCount(l):
	counter = collections.Counter(l)
	l = tuple(counter.keys())
	choose2 = collections.Counter()
	choose3 = collections.Counter()
	choose4 = collections.Counter()
	le = len(l)
	for n in counter:
		count = counter[n]
		if count >= 2:
			choose2[n] = choose(count, 2)
			if count >= 3:
				choose3[n] = choose(count, 3)
				if count >= 4:
					choose4[n] = choose(count, 4)
	t1 = 0
	t2 = 0
	for i in range(le):
		if counter[2 * l[i]] >= 2 and counter[l[i]] >= 4:
			t1 += choose4[l[i]] * choose2[2 * l[i]]
		if counter[l[i]] >= 2:
			for j in range(i + 1, le):
				if counter[l[j]] >= 2 and counter[l[i] + l[j]] >= 2:
					t2 += choose2[l[i]] * choose2[l[j]] * choose2[l[i] + l[j]]
	doubles = collections.Counter()
	for i in range(le):
		if counter[l[i]] >= 2 and counter[2 * l[i]] >= 2:
			doubles[2 * l[i]] = choose2[l[i]]
	pairs = collections.Counter()
	mpairs = collections.Counter()
	for i in range(le):
		for j in range(i + 1, le):
			if counter[l[i] + l[j]] >= 2:
				pairs[l[i] + l[j]] += counter[l[i]] * counter[l[j]]
				mpairs[l[i] + l[j]] += counter[l[i]] ** 2 * counter[l[j]] ** 2
	t3 = sum((pairs[s] * doubles[s] * choose2[s] for s in doubles if s in pairs))
	t4 = sum(((pairs[s] ** 2 - mpairs[s]) * choose2[s] for s in pairs)) // 2
	CD = collections.Counter()
	for d in range(le):
		if counter[l[d]] >= 3:
			for c in range(le):
				if l[c] < l[d]:
					CD[l[d] - l[c]] += choose3[l[d]] * counter[l[c]]
	s1 = 0
	s2 = 0
	s4 = 0
	for a in range(le):
		for b in range(a + 1, le):
			s1 += 2 * CD[l[a] + l[b]] * counter[l[a]] * counter[l[b]]
			if counter[l[a] + 2 * l[b]] >= 3:
				s2 += 2 * choose3[l[a] + 2 * l[b]] * counter[l[a]] * counter[l[b]] ** 2
			if counter[2 * l[a] + l[b]] >= 3:
				s2 += 2 * choose3[2 * l[a] + l[b]] * counter[l[b]] * counter[l[a]] ** 2
			if counter[l[b]] >= 2 and counter[l[a] + 2 * l[b]] >= 3:
				s4 += counter[l[a]] * choose2[l[b]] * choose3[l[a] + 2 * l[b]]
			if counter[l[a]] >= 2 and counter[2 * l[a] + l[b]] >= 3:
				s4 += counter[l[b]] * choose2[l[a]] * choose3[2 * l[a] + l[b]]
	s = (s1 - s2) // 6
	s3 = 0
	for a in range(le):
		if counter[l[a]] >= 3 and counter[3 * l[a]] >= 3:
			s3 += choose3[l[a]] * choose3[3 * l[a]]
	return t1 + t2 + t3 + t4 + s + s3 + s4
n = int(input())
l = list(map(int, input().rstrip().split()))
print(squareCount(l))


import collections
import math
import os
import random
import re
import sys

def choose(n, k):
	if k > n:
		return 0
	k = min(k, n - k)
	(num, den) = (1, 1)
	for i in range(k):
		num *= n - i
		den *= i + 1
	return num // den

def squareCount(l):
	counter = collections.Counter(l)
	l = tuple(counter.keys())
	choose2 = collections.Counter()
	choose3 = collections.Counter()
	choose4 = collections.Counter()
	le = len(l)
	for n in counter:
		count = counter[n]
		if count >= 2:
			choose2[n] = choose(count, 2)
			if count >= 3:
				choose3[n] = choose(count, 3)
				if count >= 4:
					choose4[n] = choose(count, 4)
	t1 = 0
	t2 = 0
	for i in range(le):
		if counter[2 * l[i]] >= 2 and counter[l[i]] >= 4:
			t1 += choose4[l[i]] * choose2[2 * l[i]]
		if counter[l[i]] >= 2:
			for j in range(i + 1, le):
				if counter[l[j]] >= 2 and counter[l[i] + l[j]] >= 2:
					t2 += choose2[l[i]] * choose2[l[j]] * choose2[l[i] + l[j]]
	doubles = collections.Counter()
	for i in range(le):
		if counter[l[i]] >= 2 and counter[2 * l[i]] >= 2:
			doubles[2 * l[i]] = choose2[l[i]]
	pairs = collections.Counter()
	mpairs = collections.Counter()
	for i in range(le):
		for j in range(i + 1, le):
			if counter[l[i] + l[j]] >= 2:
				pairs[l[i] + l[j]] += counter[l[i]] * counter[l[j]]
				mpairs[l[i] + l[j]] += counter[l[i]] ** 2 * counter[l[j]] ** 2
	t3 = sum((pairs[s] * doubles[s] * choose2[s] for s in doubles if s in pairs))
	t4 = sum(((pairs[s] ** 2 - mpairs[s]) * choose2[s] for s in pairs)) // 2
	CD = collections.Counter()
	for d in range(le):
		if counter[l[d]] >= 3:
			for c in range(le):
				if l[c] < l[d]:
					CD[l[d] - l[c]] += choose3[l[d]] * counter[l[c]]
	s1 = 0
	s2 = 0
	s4 = 0
	for a in range(le):
		for b in range(a + 1, le):
			s1 += 2 * CD[l[a] + l[b]] * counter[l[a]] * counter[l[b]]
			if counter[l[a] + 2 * l[b]] >= 3:
				s2 += 2 * choose3[l[a] + 2 * l[b]] * counter[l[a]] * counter[l[b]] ** 2
			if counter[2 * l[a] + l[b]] >= 3:
				s2 += 2 * choose3[2 * l[a] + l[b]] * counter[l[b]] * counter[l[a]] ** 2
			if counter[l[b]] >= 2 and counter[l[a] + 2 * l[b]] >= 3:
				s4 += counter[l[a]] * choose2[l[b]] * choose3[l[a] + 2 * l[b]]
			if counter[l[a]] >= 2 and counter[2 * l[a] + l[b]] >= 3:
				s4 += counter[l[b]] * choose2[l[a]] * choose3[2 * l[a] + l[b]]
	s = (s1 - s2) // 6
	s3 = 0
	for a in range(le):
		if counter[l[a]] >= 3 and counter[3 * l[a]] >= 3:
			s3 += choose3[l[a]] * choose3[3 * l[a]]
	return t1 + t2 + t3 + t4 + s + s3 + s4
n = int(input())
l = list(map(int, input().rstrip().split()))
print(squareCount(l))


import collections
import math
import os
import random
import re
import sys

def choose(n, k):
	if k > n:
		return 0
	k = min(k, n - k)
	(num, den) = (1, 1)
	for i in range(k):
		num *= n - i
		den *= i + 1
	return num // den

def squareCount(l):
	counter = collections.Counter(l)
	l = tuple(counter.keys())
	choose2 = collections.Counter()
	choose3 = collections.Counter()
	choose4 = collections.Counter()
	le = len(l)
	for n in counter:
		count = counter[n]
		if count >= 2:
			choose2[n] = choose(count, 2)
			if count >= 3:
				choose3[n] = choose(count, 3)
				if count >= 4:
					choose4[n] = choose(count, 4)
	t1 = 0
	t2 = 0
	for i in range(le):
		if counter[2 * l[i]] >= 2 and counter[l[i]] >= 4:
			t1 += choose4[l[i]] * choose2[2 * l[i]]
		if counter[l[i]] >= 2:
			for j in range(i + 1, le):
				if counter[l[j]] >= 2 and counter[l[i] + l[j]] >= 2:
					t2 += choose2[l[i]] * choose2[l[j]] * choose2[l[i] + l[j]]
	doubles = collections.Counter()
	for i in range(le):
		if counter[l[i]] >= 2 and counter[2 * l[i]] >= 2:
			doubles[2 * l[i]] = choose2[l[i]]
	pairs = collections.Counter()
	mpairs = collections.Counter()
	for i in range(le):
		for j in range(i + 1, le):
			if counter[l[i] + l[j]] >= 2:
				pairs[l[i] + l[j]] += counter[l[i]] * counter[l[j]]
				mpairs[l[i] + l[j]] += counter[l[i]] ** 2 * counter[l[j]] ** 2
	t3 = sum((pairs[s] * doubles[s] * choose2[s] for s in doubles if s in pairs))
	t4 = sum(((pairs[s] ** 2 - mpairs[s]) * choose2[s] for s in pairs)) // 2
	CD = collections.Counter()
	for d in range(le):
		if counter[l[d]] >= 3:
			for c in range(le):
				if l[c] < l[d]:
					CD[l[d] - l[c]] += choose3[l[d]] * counter[l[c]]
	s1 = 0
	s2 = 0
	s4 = 0
	for a in range(le):
		for b in range(a + 1, le):
			s1 += 2 * CD[l[a] + l[b]] * counter[l[a]] * counter[l[b]]
			if counter[l[a] + 2 * l[b]] >= 3:
				s2 += 2 * choose3[l[a] + 2 * l[b]] * counter[l[a]] * counter[l[b]] ** 2
			if counter[2 * l[a] + l[b]] >= 3:
				s2 += 2 * choose3[2 * l[a] + l[b]] * counter[l[b]] * counter[l[a]] ** 2
			if counter[l[b]] >= 2 and counter[l[a] + 2 * l[b]] >= 3:
				s4 += counter[l[a]] * choose2[l[b]] * choose3[l[a] + 2 * l[b]]
			if counter[l[a]] >= 2 and counter[2 * l[a] + l[b]] >= 3:
				s4 += counter[l[b]] * choose2[l[a]] * choose3[2 * l[a] + l[b]]
	s = (s1 - s2) // 6
	s3 = 0
	for a in range(le):
		if counter[l[a]] >= 3 and counter[3 * l[a]] >= 3:
			s3 += choose3[l[a]] * choose3[3 * l[a]]
	return t1 + t2 + t3 + t4 + s + s3 + s4
n = int(input())
l = list(map(int, input().rstrip().split()))
print(squareCount(l))


import collections
import math
import os
import random
import re
import sys

def choose(n, k):
	if k > n:
		return 0
	k = min(k, n - k)
	(num, den) = (1, 1)
	for i in range(k):
		num *= n - i
		den *= i + 1
	return num // den

def squareCount(l):
	counter = collections.Counter(l)
	l = tuple(counter.keys())
	choose2 = collections.Counter()
	choose3 = collections.Counter()
	choose4 = collections.Counter()
	le = len(l)
	for n in counter:
		count = counter[n]
		if count >= 2:
			choose2[n] = choose(count, 2)
			if count >= 3:
				choose3[n] = choose(count, 3)
				if count >= 4:
					choose4[n] = choose(count, 4)
	t1 = 0
	t2 = 0
	for i in range(le):
		if counter[2 * l[i]] >= 2 and counter[l[i]] >= 4:
			t1 += choose4[l[i]] * choose2[2 * l[i]]
		if counter[l[i]] >= 2:
			for j in range(i + 1, le):
				if counter[l[j]] >= 2 and counter[l[i] + l[j]] >= 2:
					t2 += choose2[l[i]] * choose2[l[j]] * choose2[l[i] + l[j]]
	doubles = collections.Counter()
	for i in range(le):
		if counter[l[i]] >= 2 and counter[2 * l[i]] >= 2:
			doubles[2 * l[i]] = choose2[l[i]]
	pairs = collections.Counter()
	mpairs = collections.Counter()
	for i in range(le):
		for j in range(i + 1, le):
			if counter[l[i] + l[j]] >= 2:
				pairs[l[i] + l[j]] += counter[l[i]] * counter[l[j]]
				mpairs[l[i] + l[j]] += counter[l[i]] ** 2 * counter[l[j]] ** 2
	t3 = sum((pairs[s] * doubles[s] * choose2[s] for s in doubles if s in pairs))
	t4 = sum(((pairs[s] ** 2 - mpairs[s]) * choose2[s] for s in pairs)) // 2
	CD = collections.Counter()
	for d in range(le):
		if counter[l[d]] >= 3:
			for c in range(le):
				if l[c] < l[d]:
					CD[l[d] - l[c]] += choose3[l[d]] * counter[l[c]]
	s1 = 0
	s2 = 0
	s4 = 0
	for a in range(le):
		for b in range(a + 1, le):
			s1 += 2 * CD[l[a] + l[b]] * counter[l[a]] * counter[l[b]]
			if counter[l[a] + 2 * l[b]] >= 3:
				s2 += 2 * choose3[l[a] + 2 * l[b]] * counter[l[a]] * counter[l[b]] ** 2
			if counter[2 * l[a] + l[b]] >= 3:
				s2 += 2 * choose3[2 * l[a] + l[b]] * counter[l[b]] * counter[l[a]] ** 2
			if counter[l[b]] >= 2 and counter[l[a] + 2 * l[b]] >= 3:
				s4 += counter[l[a]] * choose2[l[b]] * choose3[l[a] + 2 * l[b]]
			if counter[l[a]] >= 2 and counter[2 * l[a] + l[b]] >= 3:
				s4 += counter[l[b]] * choose2[l[a]] * choose3[2 * l[a] + l[b]]
	s = (s1 - s2) // 6
	s3 = 0
	for a in range(le):
		if counter[l[a]] >= 3 and counter[3 * l[a]] >= 3:
			s3 += choose3[l[a]] * choose3[3 * l[a]]
	return t1 + t2 + t3 + t4 + s + s3 + s4
n = int(input())
l = list(map(int, input().rstrip().split()))
print(squareCount(l))


import collections
import math
import os
import random
import re
import sys

def choose(n, k):
	if k > n:
		return 0
	k = min(k, n - k)
	(num, den) = (1, 1)
	for i in range(k):
		num *= n - i
		den *= i + 1
	return num // den

def squareCount(l):
	counter = collections.Counter(l)
	l = tuple(counter.keys())
	choose2 = collections.Counter()
	choose3 = collections.Counter()
	choose4 = collections.Counter()
	le = len(l)
	for n in counter:
		count = counter[n]
		if count >= 2:
			choose2[n] = choose(count, 2)
			if count >= 3:
				choose3[n] = choose(count, 3)
				if count >= 4:
					choose4[n] = choose(count, 4)
	t1 = 0
	t2 = 0
	for i in range(le):
		if counter[2 * l[i]] >= 2 and counter[l[i]] >= 4:
			t1 += choose4[l[i]] * choose2[2 * l[i]]
		if counter[l[i]] >= 2:
			for j in range(i + 1, le):
				if counter[l[j]] >= 2 and counter[l[i] + l[j]] >= 2:
					t2 += choose2[l[i]] * choose2[l[j]] * choose2[l[i] + l[j]]
	doubles = collections.Counter()
	for i in range(le):
		if counter[l[i]] >= 2 and counter[2 * l[i]] >= 2:
			doubles[2 * l[i]] = choose2[l[i]]
	pairs = collections.Counter()
	mpairs = collections.Counter()
	for i in range(le):
		for j in range(i + 1, le):
			if counter[l[i] + l[j]] >= 2:
				pairs[l[i] + l[j]] += counter[l[i]] * counter[l[j]]
				mpairs[l[i] + l[j]] += counter[l[i]] ** 2 * counter[l[j]] ** 2
	t3 = sum((pairs[s] * doubles[s] * choose2[s] for s in doubles if s in pairs))
	t4 = sum(((pairs[s] ** 2 - mpairs[s]) * choose2[s] for s in pairs)) // 2
	CD = collections.Counter()
	for d in range(le):
		if counter[l[d]] >= 3:
			for c in range(le):
				if l[c] < l[d]:
					CD[l[d] - l[c]] += choose3[l[d]] * counter[l[c]]
	s1 = 0
	s2 = 0
	s4 = 0
	for a in range(le):
		for b in range(a + 1, le):
			s1 += 2 * CD[l[a] + l[b]] * counter[l[a]] * counter[l[b]]
			if counter[l[a] + 2 * l[b]] >= 3:
				s2 += 2 * choose3[l[a] + 2 * l[b]] * counter[l[a]] * counter[l[b]] ** 2
			if counter[2 * l[a] + l[b]] >= 3:
				s2 += 2 * choose3[2 * l[a] + l[b]] * counter[l[b]] * counter[l[a]] ** 2
			if counter[l[b]] >= 2 and counter[l[a] + 2 * l[b]] >= 3:
				s4 += counter[l[a]] * choose2[l[b]] * choose3[l[a] + 2 * l[b]]
			if counter[l[a]] >= 2 and counter[2 * l[a] + l[b]] >= 3:
				s4 += counter[l[b]] * choose2[l[a]] * choose3[2 * l[a] + l[b]]
	s = (s1 - s2) // 6
	s3 = 0
	for a in range(le):
		if counter[l[a]] >= 3 and counter[3 * l[a]] >= 3:
			s3 += choose3[l[a]] * choose3[3 * l[a]]
	return t1 + t2 + t3 + t4 + s + s3 + s4
n = int(input())
l = list(map(int, input().rstrip().split()))
print(squareCount(l))


import collections
import math
import os
import random
import re
import sys

def choose(n, k):
	if k > n:
		return 0
	k = min(k, n - k)
	(num, den) = (1, 1)
	for i in range(k):
		num *= n - i
		den *= i + 1
	return num // den

def squareCount(l):
	counter = collections.Counter(l)
	l = tuple(counter.keys())
	choose2 = collections.Counter()
	choose3 = collections.Counter()
	choose4 = collections.Counter()
	le = len(l)
	for n in counter:
		count = counter[n]
		if count >= 2:
			choose2[n] = choose(count, 2)
			if count >= 3:
				choose3[n] = choose(count, 3)
				if count >= 4:
					choose4[n] = choose(count, 4)
	t1 = 0
	t2 = 0
	for i in range(le):
		if counter[2 * l[i]] >= 2 and counter[l[i]] >= 4:
			t1 += choose4[l[i]] * choose2[2 * l[i]]
		if counter[l[i]] >= 2:
			for j in range(i + 1, le):
				if counter[l[j]] >= 2 and counter[l[i] + l[j]] >= 2:
					t2 += choose2[l[i]] * choose2[l[j]] * choose2[l[i] + l[j]]
	doubles = collections.Counter()
	for i in range(le):
		if counter[l[i]] >= 2 and counter[2 * l[i]] >= 2:
			doubles[2 * l[i]] = choose2[l[i]]
	pairs = collections.Counter()
	mpairs = collections.Counter()
	for i in range(le):
		for j in range(i + 1, le):
			if counter[l[i] + l[j]] >= 2:
				pairs[l[i] + l[j]] += counter[l[i]] * counter[l[j]]
				mpairs[l[i] + l[j]] += counter[l[i]] ** 2 * counter[l[j]] ** 2
	t3 = sum((pairs[s] * doubles[s] * choose2[s] for s in doubles if s in pairs))
	t4 = sum(((pairs[s] ** 2 - mpairs[s]) * choose2[s] for s in pairs)) // 2
	CD = collections.Counter()
	for d in range(le):
		if counter[l[d]] >= 3:
			for c in range(le):
				if l[c] < l[d]:
					CD[l[d] - l[c]] += choose3[l[d]] * counter[l[c]]
	s1 = 0
	s2 = 0
	s4 = 0
	for a in range(le):
		for b in range(a + 1, le):
			s1 += 2 * CD[l[a] + l[b]] * counter[l[a]] * counter[l[b]]
			if counter[l[a] + 2 * l[b]] >= 3:
				s2 += 2 * choose3[l[a] + 2 * l[b]] * counter[l[a]] * counter[l[b]] ** 2
			if counter[2 * l[a] + l[b]] >= 3:
				s2 += 2 * choose3[2 * l[a] + l[b]] * counter[l[b]] * counter[l[a]] ** 2
			if counter[l[b]] >= 2 and counter[l[a] + 2 * l[b]] >= 3:
				s4 += counter[l[a]] * choose2[l[b]] * choose3[l[a] + 2 * l[b]]
			if counter[l[a]] >= 2 and counter[2 * l[a] + l[b]] >= 3:
				s4 += counter[l[b]] * choose2[l[a]] * choose3[2 * l[a] + l[b]]
	s = (s1 - s2) // 6
	s3 = 0
	for a in range(le):
		if counter[l[a]] >= 3 and counter[3 * l[a]] >= 3:
			s3 += choose3[l[a]] * choose3[3 * l[a]]
	return t1 + t2 + t3 + t4 + s + s3 + s4
n = int(input())
l = list(map(int, input().rstrip().split()))
print(squareCount(l))


import collections
import math
import os
import random
import re
import sys

def choose(n, k):
	if k > n:
		return 0
	k = min(k, n - k)
	(num, den) = (1, 1)
	for i in range(k):
		num *= n - i
		den *= i + 1
	return num // den

def squareCount(l):
	counter = collections.Counter(l)
	l = tuple(counter.keys())
	choose2 = collections.Counter()
	choose3 = collections.Counter()
	choose4 = collections.Counter()
	le = len(l)
	for n in counter:
		count = counter[n]
		if count >= 2:
			choose2[n] = choose(count, 2)
			if count >= 3:
				choose3[n] = choose(count, 3)
				if count >= 4:
					choose4[n] = choose(count, 4)
	t1 = 0
	t2 = 0
	for i in range(le):
		if counter[2 * l[i]] >= 2 and counter[l[i]] >= 4:
			t1 += choose4[l[i]] * choose2[2 * l[i]]
		if counter[l[i]] >= 2:
			for j in range(i + 1, le):
				if counter[l[j]] >= 2 and counter[l[i] + l[j]] >= 2:
					t2 += choose2[l[i]] * choose2[l[j]] * choose2[l[i] + l[j]]
	doubles = collections.Counter()
	for i in range(le):
		if counter[l[i]] >= 2 and counter[2 * l[i]] >= 2:
			doubles[2 * l[i]] = choose2[l[i]]
	pairs = collections.Counter()
	mpairs = collections.Counter()
	for i in range(le):
		for j in range(i + 1, le):
			if counter[l[i] + l[j]] >= 2:
				pairs[l[i] + l[j]] += counter[l[i]] * counter[l[j]]
				mpairs[l[i] + l[j]] += counter[l[i]] ** 2 * counter[l[j]] ** 2
	t3 = sum((pairs[s] * doubles[s] * choose2[s] for s in doubles if s in pairs))
	t4 = sum(((pairs[s] ** 2 - mpairs[s]) * choose2[s] for s in pairs)) // 2
	CD = collections.Counter()
	for d in range(le):
		if counter[l[d]] >= 3:
			for c in range(le):
				if l[c] < l[d]:
					CD[l[d] - l[c]] += choose3[l[d]] * counter[l[c]]
	s1 = 0
	s2 = 0
	s4 = 0
	for a in range(le):
		for b in range(a + 1, le):
			s1 += 2 * CD[l[a] + l[b]] * counter[l[a]] * counter[l[b]]
			if counter[l[a] + 2 * l[b]] >= 3:
				s2 += 2 * choose3[l[a] + 2 * l[b]] * counter[l[a]] * counter[l[b]] ** 2
			if counter[2 * l[a] + l[b]] >= 3:
				s2 += 2 * choose3[2 * l[a] + l[b]] * counter[l[b]] * counter[l[a]] ** 2
			if counter[l[b]] >= 2 and counter[l[a] + 2 * l[b]] >= 3:
				s4 += counter[l[a]] * choose2[l[b]] * choose3[l[a] + 2 * l[b]]
			if counter[l[a]] >= 2 and counter[2 * l[a] + l[b]] >= 3:
				s4 += counter[l[b]] * choose2[l[a]] * choose3[2 * l[a] + l[b]]
	s = (s1 - s2) // 6
	s3 = 0
	for a in range(le):
		if counter[l[a]] >= 3 and counter[3 * l[a]] >= 3:
			s3 += choose3[l[a]] * choose3[3 * l[a]]
	return t1 + t2 + t3 + t4 + s + s3 + s4
n = int(input())
l = list(map(int, input().rstrip().split()))
print(squareCount(l))


import collections
import math
import os
import random
import re
import sys

def choose(n, k):
	if k > n:
		return 0
	k = min(k, n - k)
	(num, den) = (1, 1)
	for i in range(k):
		num *= n - i
		den *= i + 1
	return num // den

def squareCount(l):
	counter = collections.Counter(l)
	l = tuple(counter.keys())
	choose2 = collections.Counter()
	choose3 = collections.Counter()
	choose4 = collections.Counter()
	le = len(l)
	for n in counter:
		count = counter[n]
		if count >= 2:
			choose2[n] = choose(count, 2)
			if count >= 3:
				choose3[n] = choose(count, 3)
				if count >= 4:
					choose4[n] = choose(count, 4)
	t1 = 0
	t2 = 0
	for i in range(le):
		if counter[2 * l[i]] >= 2 and counter[l[i]] >= 4:
			t1 += choose4[l[i]] * choose2[2 * l[i]]
		if counter[l[i]] >= 2:
			for j in range(i + 1, le):
				if counter[l[j]] >= 2 and counter[l[i] + l[j]] >= 2:
					t2 += choose2[l[i]] * choose2[l[j]] * choose2[l[i] + l[j]]
	doubles = collections.Counter()
	for i in range(le):
		if counter[l[i]] >= 2 and counter[2 * l[i]] >= 2:
			doubles[2 * l[i]] = choose2[l[i]]
	pairs = collections.Counter()
	mpairs = collections.Counter()
	for i in range(le):
		for j in range(i + 1, le):
			if counter[l[i] + l[j]] >= 2:
				pairs[l[i] + l[j]] += counter[l[i]] * counter[l[j]]
				mpairs[l[i] + l[j]] += counter[l[i]] ** 2 * counter[l[j]] ** 2
	t3 = sum((pairs[s] * doubles[s] * choose2[s] for s in doubles if s in pairs))
	t4 = sum(((pairs[s] ** 2 - mpairs[s]) * choose2[s] for s in pairs)) // 2
	CD = collections.Counter()
	for d in range(le):
		if counter[l[d]] >= 3:
			for c in range(le):
				if l[c] < l[d]:
					CD[l[d] - l[c]] += choose3[l[d]] * counter[l[c]]
	s1 = 0
	s2 = 0
	s4 = 0
	for a in range(le):
		for b in range(a + 1, le):
			s1 += 2 * CD[l[a] + l[b]] * counter[l[a]] * counter[l[b]]
			if counter[l[a] + 2 * l[b]] >= 3:
				s2 += 2 * choose3[l[a] + 2 * l[b]] * counter[l[a]] * counter[l[b]] ** 2
			if counter[2 * l[a] + l[b]] >= 3:
				s2 += 2 * choose3[2 * l[a] + l[b]] * counter[l[b]] * counter[l[a]] ** 2
			if counter[l[b]] >= 2 and counter[l[a] + 2 * l[b]] >= 3:
				s4 += counter[l[a]] * choose2[l[b]] * choose3[l[a] + 2 * l[b]]
			if counter[l[a]] >= 2 and counter[2 * l[a] + l[b]] >= 3:
				s4 += counter[l[b]] * choose2[l[a]] * choose3[2 * l[a] + l[b]]
	s = (s1 - s2) // 6
	s3 = 0
	for a in range(le):
		if counter[l[a]] >= 3 and counter[3 * l[a]] >= 3:
			s3 += choose3[l[a]] * choose3[3 * l[a]]
	return t1 + t2 + t3 + t4 + s + s3 + s4
n = int(input())
l = list(map(int, input().rstrip().split()))
print(squareCount(l))


import collections
import math
import os
import random
import re
import sys

def choose(n, k):
	if k > n:
		return 0
	k = min(k, n - k)
	(num, den) = (1, 1)
	for i in range(k):
		num *= n - i
		den *= i + 1
	return num // den

def squareCount(l):
	counter = collections.Counter(l)
	l = tuple(counter.keys())
	choose2 = collections.Counter()
	choose3 = collections.Counter()
	choose4 = collections.Counter()
	le = len(l)
	for n in counter:
		count = counter[n]
		if count >= 2:
			choose2[n] = choose(count, 2)
			if count >= 3:
				choose3[n] = choose(count, 3)
				if count >= 4:
					choose4[n] = choose(count, 4)
	t1 = 0
	t2 = 0
	for i in range(le):
		if counter[2 * l[i]] >= 2 and counter[l[i]] >= 4:
			t1 += choose4[l[i]] * choose2[2 * l[i]]
		if counter[l[i]] >= 2:
			for j in range(i + 1, le):
				if counter[l[j]] >= 2 and counter[l[i] + l[j]] >= 2:
					t2 += choose2[l[i]] * choose2[l[j]] * choose2[l[i] + l[j]]
	doubles = collections.Counter()
	for i in range(le):
		if counter[l[i]] >= 2 and counter[2 * l[i]] >= 2:
			doubles[2 * l[i]] = choose2[l[i]]
	pairs = collections.Counter()
	mpairs = collections.Counter()
	for i in range(le):
		for j in range(i + 1, le):
			if counter[l[i] + l[j]] >= 2:
				pairs[l[i] + l[j]] += counter[l[i]] * counter[l[j]]
				mpairs[l[i] + l[j]] += counter[l[i]] ** 2 * counter[l[j]] ** 2
	t3 = sum((pairs[s] * doubles[s] * choose2[s] for s in doubles if s in pairs))
	t4 = sum(((pairs[s] ** 2 - mpairs[s]) * choose2[s] for s in pairs)) // 2
	CD = collections.Counter()
	for d in range(le):
		if counter[l[d]] >= 3:
			for c in range(le):
				if l[c] < l[d]:
					CD[l[d] - l[c]] += choose3[l[d]] * counter[l[c]]
	s1 = 0
	s2 = 0
	s4 = 0
	for a in range(le):
		for b in range(a + 1, le):
			s1 += 2 * CD[l[a] + l[b]] * counter[l[a]] * counter[l[b]]
			if counter[l[a] + 2 * l[b]] >= 3:
				s2 += 2 * choose3[l[a] + 2 * l[b]] * counter[l[a]] * counter[l[b]] ** 2
			if counter[2 * l[a] + l[b]] >= 3:
				s2 += 2 * choose3[2 * l[a] + l[b]] * counter[l[b]] * counter[l[a]] ** 2
			if counter[l[b]] >= 2 and counter[l[a] + 2 * l[b]] >= 3:
				s4 += counter[l[a]] * choose2[l[b]] * choose3[l[a] + 2 * l[b]]
			if counter[l[a]] >= 2 and counter[2 * l[a] + l[b]] >= 3:
				s4 += counter[l[b]] * choose2[l[a]] * choose3[2 * l[a] + l[b]]
	s = (s1 - s2) // 6
	s3 = 0
	for a in range(le):
		if counter[l[a]] >= 3 and counter[3 * l[a]] >= 3:
			s3 += choose3[l[a]] * choose3[3 * l[a]]
	return t1 + t2 + t3 + t4 + s + s3 + s4
n = int(input())
l = list(map(int, input().rstrip().split()))
print(squareCount(l))


import collections
import math
import os
import random
import re
import sys

def choose(n, k):
	if k > n:
		return 0
	k = min(k, n - k)
	(num, den) = (1, 1)
	for i in range(k):
		num *= n - i
		den *= i + 1
	return num // den

def squareCount(l):
	counter = collections.Counter(l)
	l = tuple(counter.keys())
	choose2 = collections.Counter()
	choose3 = collections.Counter()
	choose4 = collections.Counter()
	le = len(l)
	for n in counter:
		count = counter[n]
		if count >= 2:
			choose2[n] = choose(count, 2)
			if count >= 3:
				choose3[n] = choose(count, 3)
				if count >= 4:
					choose4[n] = choose(count, 4)
	t1 = 0
	t2 = 0
	for i in range(le):
		if counter[2 * l[i]] >= 2 and counter[l[i]] >= 4:
			t1 += choose4[l[i]] * choose2[2 * l[i]]
		if counter[l[i]] >= 2:
			for j in range(i + 1, le):
				if counter[l[j]] >= 2 and counter[l[i] + l[j]] >= 2:
					t2 += choose2[l[i]] * choose2[l[j]] * choose2[l[i] + l[j]]
	doubles = collections.Counter()
	for i in range(le):
		if counter[l[i]] >= 2 and counter[2 * l[i]] >= 2:
			doubles[2 * l[i]] = choose2[l[i]]
	pairs = collections.Counter()
	mpairs = collections.Counter()
	for i in range(le):
		for j in range(i + 1, le):
			if counter[l[i] + l[j]] >= 2:
				pairs[l[i] + l[j]] += counter[l[i]] * counter[l[j]]
				mpairs[l[i] + l[j]] += counter[l[i]] ** 2 * counter[l[j]] ** 2
	t3 = sum((pairs[s] * doubles[s] * choose2[s] for s in doubles if s in pairs))
	t4 = sum(((pairs[s] ** 2 - mpairs[s]) * choose2[s] for s in pairs)) // 2
	CD = collections.Counter()
	for d in range(le):
		if counter[l[d]] >= 3:
			for c in range(le):
				if l[c] < l[d]:
					CD[l[d] - l[c]] += choose3[l[d]] * counter[l[c]]
	s1 = 0
	s2 = 0
	s4 = 0
	for a in range(le):
		for b in range(a + 1, le):
			s1 += 2 * CD[l[a] + l[b]] * counter[l[a]] * counter[l[b]]
			if counter[l[a] + 2 * l[b]] >= 3:
				s2 += 2 * choose3[l[a] + 2 * l[b]] * counter[l[a]] * counter[l[b]] ** 2
			if counter[2 * l[a] + l[b]] >= 3:
				s2 += 2 * choose3[2 * l[a] + l[b]] * counter[l[b]] * counter[l[a]] ** 2
			if counter[l[b]] >= 2 and counter[l[a] + 2 * l[b]] >= 3:
				s4 += counter[l[a]] * choose2[l[b]] * choose3[l[a] + 2 * l[b]]
			if counter[l[a]] >= 2 and counter[2 * l[a] + l[b]] >= 3:
				s4 += counter[l[b]] * choose2[l[a]] * choose3[2 * l[a] + l[b]]
	s = (s1 - s2) // 6
	s3 = 0
	for a in range(le):
		if counter[l[a]] >= 3 and counter[3 * l[a]] >= 3:
			s3 += choose3[l[a]] * choose3[3 * l[a]]
	return t1 + t2 + t3 + t4 + s + s3 + s4
n = int(input())
l = list(map(int, input().rstrip().split()))
print(squareCount(l))


import collections
import math
import os
import random
import re
import sys

def choose(n, k):
	if k > n:
		return 0
	k = min(k, n - k)
	(num, den) = (1, 1)
	for i in range(k):
		num *= n - i
		den *= i + 1
	return num // den

def squareCount(l):
	counter = collections.Counter(l)
	l = tuple(counter.keys())
	choose2 = collections.Counter()
	choose3 = collections.Counter()
	choose4 = collections.Counter()
	le = len(l)
	for n in counter:
		count = counter[n]
		if count >= 2:
			choose2[n] = choose(count, 2)
			if count >= 3:
				choose3[n] = choose(count, 3)
				if count >= 4:
					choose4[n] = choose(count, 4)
	t1 = 0
	t2 = 0
	for i in range(le):
		if counter[2 * l[i]] >= 2 and counter[l[i]] >= 4:
			t1 += choose4[l[i]] * choose2[2 * l[i]]
		if counter[l[i]] >= 2:
			for j in range(i + 1, le):
				if counter[l[j]] >= 2 and counter[l[i] + l[j]] >= 2:
					t2 += choose2[l[i]] * choose2[l[j]] * choose2[l[i] + l[j]]
	doubles = collections.Counter()
	for i in range(le):
		if counter[l[i]] >= 2 and counter[2 * l[i]] >= 2:
			doubles[2 * l[i]] = choose2[l[i]]
	pairs = collections.Counter()
	mpairs = collections.Counter()
	for i in range(le):
		for j in range(i + 1, le):
			if counter[l[i] + l[j]] >= 2:
				pairs[l[i] + l[j]] += counter[l[i]] * counter[l[j]]
				mpairs[l[i] + l[j]] += counter[l[i]] ** 2 * counter[l[j]] ** 2
	t3 = sum((pairs[s] * doubles[s] * choose2[s] for s in doubles if s in pairs))
	t4 = sum(((pairs[s] ** 2 - mpairs[s]) * choose2[s] for s in pairs)) // 2
	CD = collections.Counter()
	for d in range(le):
		if counter[l[d]] >= 3:
			for c in range(le):
				if l[c] < l[d]:
					CD[l[d] - l[c]] += choose3[l[d]] * counter[l[c]]
	s1 = 0
	s2 = 0
	s4 = 0
	for a in range(le):
		for b in range(a + 1, le):
			s1 += 2 * CD[l[a] + l[b]] * counter[l[a]] * counter[l[b]]
			if counter[l[a] + 2 * l[b]] >= 3:
				s2 += 2 * choose3[l[a] + 2 * l[b]] * counter[l[a]] * counter[l[b]] ** 2
			if counter[2 * l[a] + l[b]] >= 3:
				s2 += 2 * choose3[2 * l[a] + l[b]] * counter[l[b]] * counter[l[a]] ** 2
			if counter[l[b]] >= 2 and counter[l[a] + 2 * l[b]] >= 3:
				s4 += counter[l[a]] * choose2[l[b]] * choose3[l[a] + 2 * l[b]]
			if counter[l[a]] >= 2 and counter[2 * l[a] + l[b]] >= 3:
				s4 += counter[l[b]] * choose2[l[a]] * choose3[2 * l[a] + l[b]]
	s = (s1 - s2) // 6
	s3 = 0
	for a in range(le):
		if counter[l[a]] >= 3 and counter[3 * l[a]] >= 3:
			s3 += choose3[l[a]] * choose3[3 * l[a]]
	return t1 + t2 + t3 + t4 + s + s3 + s4
n = int(input())
l = list(map(int, input().rstrip().split()))
print(squareCount(l))


import collections
import math
import os
import random
import re
import sys

def choose(n, k):
	if k > n:
		return 0
	k = min(k, n - k)
	(num, den) = (1, 1)
	for i in range(k):
		num *= n - i
		den *= i + 1
	return num // den

def squareCount(l):
	counter = collections.Counter(l)
	l = tuple(counter.keys())
	choose2 = collections.Counter()
	choose3 = collections.Counter()
	choose4 = collections.Counter()
	le = len(l)
	for n in counter:
		count = counter[n]
		if count >= 2:
			choose2[n] = choose(count, 2)
			if count >= 3:
				choose3[n] = choose(count, 3)
				if count >= 4:
					choose4[n] = choose(count, 4)
	t1 = 0
	t2 = 0
	for i in range(le):
		if counter[2 * l[i]] >= 2 and counter[l[i]] >= 4:
			t1 += choose4[l[i]] * choose2[2 * l[i]]
		if counter[l[i]] >= 2:
			for j in range(i + 1, le):
				if counter[l[j]] >= 2 and counter[l[i] + l[j]] >= 2:
					t2 += choose2[l[i]] * choose2[l[j]] * choose2[l[i] + l[j]]
	doubles = collections.Counter()
	for i in range(le):
		if counter[l[i]] >= 2 and counter[2 * l[i]] >= 2:
			doubles[2 * l[i]] = choose2[l[i]]
	pairs = collections.Counter()
	mpairs = collections.Counter()
	for i in range(le):
		for j in range(i + 1, le):
			if counter[l[i] + l[j]] >= 2:
				pairs[l[i] + l[j]] += counter[l[i]] * counter[l[j]]
				mpairs[l[i] + l[j]] += counter[l[i]] ** 2 * counter[l[j]] ** 2
	t3 = sum((pairs[s] * doubles[s] * choose2[s] for s in doubles if s in pairs))
	t4 = sum(((pairs[s] ** 2 - mpairs[s]) * choose2[s] for s in pairs)) // 2
	CD = collections.Counter()
	for d in range(le):
		if counter[l[d]] >= 3:
			for c in range(le):
				if l[c] < l[d]:
					CD[l[d] - l[c]] += choose3[l[d]] * counter[l[c]]
	s1 = 0
	s2 = 0
	s4 = 0
	for a in range(le):
		for b in range(a + 1, le):
			s1 += 2 * CD[l[a] + l[b]] * counter[l[a]] * counter[l[b]]
			if counter[l[a] + 2 * l[b]] >= 3:
				s2 += 2 * choose3[l[a] + 2 * l[b]] * counter[l[a]] * counter[l[b]] ** 2
			if counter[2 * l[a] + l[b]] >= 3:
				s2 += 2 * choose3[2 * l[a] + l[b]] * counter[l[b]] * counter[l[a]] ** 2
			if counter[l[b]] >= 2 and counter[l[a] + 2 * l[b]] >= 3:
				s4 += counter[l[a]] * choose2[l[b]] * choose3[l[a] + 2 * l[b]]
			if counter[l[a]] >= 2 and counter[2 * l[a] + l[b]] >= 3:
				s4 += counter[l[b]] * choose2[l[a]] * choose3[2 * l[a] + l[b]]
	s = (s1 - s2) // 6
	s3 = 0
	for a in range(le):
		if counter[l[a]] >= 3 and counter[3 * l[a]] >= 3:
			s3 += choose3[l[a]] * choose3[3 * l[a]]
	return t1 + t2 + t3 + t4 + s + s3 + s4
n = int(input())
l = list(map(int, input().rstrip().split()))
print(squareCount(l))


import collections
import math
import os
import random
import re
import sys

def choose(n, k):
	if k > n:
		return 0
	k = min(k, n - k)
	(num, den) = (1, 1)
	for i in range(k):
		num *= n - i
		den *= i + 1
	return num // den

def squareCount(l):
	counter = collections.Counter(l)
	l = tuple(counter.keys())
	choose2 = collections.Counter()
	choose3 = collections.Counter()
	choose4 = collections.Counter()
	le = len(l)
	for n in counter:
		count = counter[n]
		if count >= 2:
			choose2[n] = choose(count, 2)
			if count >= 3:
				choose3[n] = choose(count, 3)
				if count >= 4:
					choose4[n] = choose(count, 4)
	t1 = 0
	t2 = 0
	for i in range(le):
		if counter[2 * l[i]] >= 2 and counter[l[i]] >= 4:
			t1 += choose4[l[i]] * choose2[2 * l[i]]
		if counter[l[i]] >= 2:
			for j in range(i + 1, le):
				if counter[l[j]] >= 2 and counter[l[i] + l[j]] >= 2:
					t2 += choose2[l[i]] * choose2[l[j]] * choose2[l[i] + l[j]]
	doubles = collections.Counter()
	for i in range(le):
		if counter[l[i]] >= 2 and counter[2 * l[i]] >= 2:
			doubles[2 * l[i]] = choose2[l[i]]
	pairs = collections.Counter()
	mpairs = collections.Counter()
	for i in range(le):
		for j in range(i + 1, le):
			if counter[l[i] + l[j]] >= 2:
				pairs[l[i] + l[j]] += counter[l[i]] * counter[l[j]]
				mpairs[l[i] + l[j]] += counter[l[i]] ** 2 * counter[l[j]] ** 2
	t3 = sum((pairs[s] * doubles[s] * choose2[s] for s in doubles if s in pairs))
	t4 = sum(((pairs[s] ** 2 - mpairs[s]) * choose2[s] for s in pairs)) // 2
	CD = collections.Counter()
	for d in range(le):
		if counter[l[d]] >= 3:
			for c in range(le):
				if l[c] < l[d]:
					CD[l[d] - l[c]] += choose3[l[d]] * counter[l[c]]
	s1 = 0
	s2 = 0
	s4 = 0
	for a in range(le):
		for b in range(a + 1, le):
			s1 += 2 * CD[l[a] + l[b]] * counter[l[a]] * counter[l[b]]
			if counter[l[a] + 2 * l[b]] >= 3:
				s2 += 2 * choose3[l[a] + 2 * l[b]] * counter[l[a]] * counter[l[b]] ** 2
			if counter[2 * l[a] + l[b]] >= 3:
				s2 += 2 * choose3[2 * l[a] + l[b]] * counter[l[b]] * counter[l[a]] ** 2
			if counter[l[b]] >= 2 and counter[l[a] + 2 * l[b]] >= 3:
				s4 += counter[l[a]] * choose2[l[b]] * choose3[l[a] + 2 * l[b]]
			if counter[l[a]] >= 2 and counter[2 * l[a] + l[b]] >= 3:
				s4 += counter[l[b]] * choose2[l[a]] * choose3[2 * l[a] + l[b]]
	s = (s1 - s2) // 6
	s3 = 0
	for a in range(le):
		if counter[l[a]] >= 3 and counter[3 * l[a]] >= 3:
			s3 += choose3[l[a]] * choose3[3 * l[a]]
	return t1 + t2 + t3 + t4 + s + s3 + s4
n = int(input())
l = list(map(int, input().rstrip().split()))
print(squareCount(l))


import collections
import math
import os
import random
import re
import sys

def choose(n, k):
	if k > n:
		return 0
	k = min(k, n - k)
	(num, den) = (1, 1)
	for i in range(k):
		num *= n - i
		den *= i + 1
	return num // den

def squareCount(l):
	counter = collections.Counter(l)
	l = tuple(counter.keys())
	choose2 = collections.Counter()
	choose3 = collections.Counter()
	choose4 = collections.Counter()
	le = len(l)
	for n in counter:
		count = counter[n]
		if count >= 2:
			choose2[n] = choose(count, 2)
			if count >= 3:
				choose3[n] = choose(count, 3)
				if count >= 4:
					choose4[n] = choose(count, 4)
	t1 = 0
	t2 = 0
	for i in range(le):
		if counter[2 * l[i]] >= 2 and counter[l[i]] >= 4:
			t1 += choose4[l[i]] * choose2[2 * l[i]]
		if counter[l[i]] >= 2:
			for j in range(i + 1, le):
				if counter[l[j]] >= 2 and counter[l[i] + l[j]] >= 2:
					t2 += choose2[l[i]] * choose2[l[j]] * choose2[l[i] + l[j]]
	doubles = collections.Counter()
	for i in range(le):
		if counter[l[i]] >= 2 and counter[2 * l[i]] >= 2:
			doubles[2 * l[i]] = choose2[l[i]]
	pairs = collections.Counter()
	mpairs = collections.Counter()
	for i in range(le):
		for j in range(i + 1, le):
			if counter[l[i] + l[j]] >= 2:
				pairs[l[i] + l[j]] += counter[l[i]] * counter[l[j]]
				mpairs[l[i] + l[j]] += counter[l[i]] ** 2 * counter[l[j]] ** 2
	t3 = sum((pairs[s] * doubles[s] * choose2[s] for s in doubles if s in pairs))
	t4 = sum(((pairs[s] ** 2 - mpairs[s]) * choose2[s] for s in pairs)) // 2
	CD = collections.Counter()
	for d in range(le):
		if counter[l[d]] >= 3:
			for c in range(le):
				if l[c] < l[d]:
					CD[l[d] - l[c]] += choose3[l[d]] * counter[l[c]]
	s1 = 0
	s2 = 0
	s4 = 0
	for a in range(le):
		for b in range(a + 1, le):
			s1 += 2 * CD[l[a] + l[b]] * counter[l[a]] * counter[l[b]]
			if counter[l[a] + 2 * l[b]] >= 3:
				s2 += 2 * choose3[l[a] + 2 * l[b]] * counter[l[a]] * counter[l[b]] ** 2
			if counter[2 * l[a] + l[b]] >= 3:
				s2 += 2 * choose3[2 * l[a] + l[b]] * counter[l[b]] * counter[l[a]] ** 2
			if counter[l[b]] >= 2 and counter[l[a] + 2 * l[b]] >= 3:
				s4 += counter[l[a]] * choose2[l[b]] * choose3[l[a] + 2 * l[b]]
			if counter[l[a]] >= 2 and counter[2 * l[a] + l[b]] >= 3:
				s4 += counter[l[b]] * choose2[l[a]] * choose3[2 * l[a] + l[b]]
	s = (s1 - s2) // 6
	s3 = 0
	for a in range(le):
		if counter[l[a]] >= 3 and counter[3 * l[a]] >= 3:
			s3 += choose3[l[a]] * choose3[3 * l[a]]
	return t1 + t2 + t3 + t4 + s + s3 + s4
n = int(input())
l = list(map(int, input().rstrip().split()))
print(squareCount(l))


import collections
import math
import os
import random
import re
import sys

def choose(n, k):
	if k > n:
		return 0
	k = min(k, n - k)
	(num, den) = (1, 1)
	for i in range(k):
		num *= n - i
		den *= i + 1
	return num // den

def squareCount(l):
	counter = collections.Counter(l)
	l = tuple(counter.keys())
	choose2 = collections.Counter()
	choose3 = collections.Counter()
	choose4 = collections.Counter()
	le = len(l)
	for n in counter:
		count = counter[n]
		if count >= 2:
			choose2[n] = choose(count, 2)
			if count >= 3:
				choose3[n] = choose(count, 3)
				if count >= 4:
					choose4[n] = choose(count, 4)
	t1 = 0
	t2 = 0
	for i in range(le):
		if counter[2 * l[i]] >= 2 and counter[l[i]] >= 4:
			t1 += choose4[l[i]] * choose2[2 * l[i]]
		if counter[l[i]] >= 2:
			for j in range(i + 1, le):
				if counter[l[j]] >= 2 and counter[l[i] + l[j]] >= 2:
					t2 += choose2[l[i]] * choose2[l[j]] * choose2[l[i] + l[j]]
	doubles = collections.Counter()
	for i in range(le):
		if counter[l[i]] >= 2 and counter[2 * l[i]] >= 2:
			doubles[2 * l[i]] = choose2[l[i]]
	pairs = collections.Counter()
	mpairs = collections.Counter()
	for i in range(le):
		for j in range(i + 1, le):
			if counter[l[i] + l[j]] >= 2:
				pairs[l[i] + l[j]] += counter[l[i]] * counter[l[j]]
				mpairs[l[i] + l[j]] += counter[l[i]] ** 2 * counter[l[j]] ** 2
	t3 = sum((pairs[s] * doubles[s] * choose2[s] for s in doubles if s in pairs))
	t4 = sum(((pairs[s] ** 2 - mpairs[s]) * choose2[s] for s in pairs)) // 2
	CD = collections.Counter()
	for d in range(le):
		if counter[l[d]] >= 3:
			for c in range(le):
				if l[c] < l[d]:
					CD[l[d] - l[c]] += choose3[l[d]] * counter[l[c]]
	s1 = 0
	s2 = 0
	s4 = 0
	for a in range(le):
		for b in range(a + 1, le):
			s1 += 2 * CD[l[a] + l[b]] * counter[l[a]] * counter[l[b]]
			if counter[l[a] + 2 * l[b]] >= 3:
				s2 += 2 * choose3[l[a] + 2 * l[b]] * counter[l[a]] * counter[l[b]] ** 2
			if counter[2 * l[a] + l[b]] >= 3:
				s2 += 2 * choose3[2 * l[a] + l[b]] * counter[l[b]] * counter[l[a]] ** 2
			if counter[l[b]] >= 2 and counter[l[a] + 2 * l[b]] >= 3:
				s4 += counter[l[a]] * choose2[l[b]] * choose3[l[a] + 2 * l[b]]
			if counter[l[a]] >= 2 and counter[2 * l[a] + l[b]] >= 3:
				s4 += counter[l[b]] * choose2[l[a]] * choose3[2 * l[a] + l[b]]
	s = (s1 - s2) // 6
	s3 = 0
	for a in range(le):
		if counter[l[a]] >= 3 and counter[3 * l[a]] >= 3:
			s3 += choose3[l[a]] * choose3[3 * l[a]]
	return t1 + t2 + t3 + t4 + s + s3 + s4
n = int(input())
l = list(map(int, input().rstrip().split()))
print(squareCount(l))


import collections
import math
import os
import random
import re
import sys

def choose(n, k):
	if k > n:
		return 0
	k = min(k, n - k)
	(num, den) = (1, 1)
	for i in range(k):
		num *= n - i
		den *= i + 1
	return num // den

def squareCount(l):
	counter = collections.Counter(l)
	l = tuple(counter.keys())
	choose2 = collections.Counter()
	choose3 = collections.Counter()
	choose4 = collections.Counter()
	le = len(l)
	for n in counter:
		count = counter[n]
		if count >= 2:
			choose2[n] = choose(count, 2)
			if count >= 3:
				choose3[n] = choose(count, 3)
				if count >= 4:
					choose4[n] = choose(count, 4)
	t1 = 0
	t2 = 0
	for i in range(le):
		if counter[2 * l[i]] >= 2 and counter[l[i]] >= 4:
			t1 += choose4[l[i]] * choose2[2 * l[i]]
		if counter[l[i]] >= 2:
			for j in range(i + 1, le):
				if counter[l[j]] >= 2 and counter[l[i] + l[j]] >= 2:
					t2 += choose2[l[i]] * choose2[l[j]] * choose2[l[i] + l[j]]
	doubles = collections.Counter()
	for i in range(le):
		if counter[l[i]] >= 2 and counter[2 * l[i]] >= 2:
			doubles[2 * l[i]] = choose2[l[i]]
	pairs = collections.Counter()
	mpairs = collections.Counter()
	for i in range(le):
		for j in range(i + 1, le):
			if counter[l[i] + l[j]] >= 2:
				pairs[l[i] + l[j]] += counter[l[i]] * counter[l[j]]
				mpairs[l[i] + l[j]] += counter[l[i]] ** 2 * counter[l[j]] ** 2
	t3 = sum((pairs[s] * doubles[s] * choose2[s] for s in doubles if s in pairs))
	t4 = sum(((pairs[s] ** 2 - mpairs[s]) * choose2[s] for s in pairs)) // 2
	CD = collections.Counter()
	for d in range(le):
		if counter[l[d]] >= 3:
			for c in range(le):
				if l[c] < l[d]:
					CD[l[d] - l[c]] += choose3[l[d]] * counter[l[c]]
	s1 = 0
	s2 = 0
	s4 = 0
	for a in range(le):
		for b in range(a + 1, le):
			s1 += 2 * CD[l[a] + l[b]] * counter[l[a]] * counter[l[b]]
			if counter[l[a] + 2 * l[b]] >= 3:
				s2 += 2 * choose3[l[a] + 2 * l[b]] * counter[l[a]] * counter[l[b]] ** 2
			if counter[2 * l[a] + l[b]] >= 3:
				s2 += 2 * choose3[2 * l[a] + l[b]] * counter[l[b]] * counter[l[a]] ** 2
			if counter[l[b]] >= 2 and counter[l[a] + 2 * l[b]] >= 3:
				s4 += counter[l[a]] * choose2[l[b]] * choose3[l[a] + 2 * l[b]]
			if counter[l[a]] >= 2 and counter[2 * l[a] + l[b]] >= 3:
				s4 += counter[l[b]] * choose2[l[a]] * choose3[2 * l[a] + l[b]]
	s = (s1 - s2) // 6
	s3 = 0
	for a in range(le):
		if counter[l[a]] >= 3 and counter[3 * l[a]] >= 3:
			s3 += choose3[l[a]] * choose3[3 * l[a]]
	return t1 + t2 + t3 + t4 + s + s3 + s4
n = int(input())
l = list(map(int, input().rstrip().split()))
print(squareCount(l))


import collections
import math
import os
import random
import re
import sys

def choose(n, k):
	if k > n:
		return 0
	k = min(k, n - k)
	(num, den) = (1, 1)
	for i in range(k):
		num *= n - i
		den *= i + 1
	return num // den

def squareCount(l):
	counter = collections.Counter(l)
	l = tuple(counter.keys())
	choose2 = collections.Counter()
	choose3 = collections.Counter()
	choose4 = collections.Counter()
	le = len(l)
	for n in counter:
		count = counter[n]
		if count >= 2:
			choose2[n] = choose(count, 2)
			if count >= 3:
				choose3[n] = choose(count, 3)
				if count >= 4:
					choose4[n] = choose(count, 4)
	t1 = 0
	t2 = 0
	for i in range(le):
		if counter[2 * l[i]] >= 2 and counter[l[i]] >= 4:
			t1 += choose4[l[i]] * choose2[2 * l[i]]
		if counter[l[i]] >= 2:
			for j in range(i + 1, le):
				if counter[l[j]] >= 2 and counter[l[i] + l[j]] >= 2:
					t2 += choose2[l[i]] * choose2[l[j]] * choose2[l[i] + l[j]]
	doubles = collections.Counter()
	for i in range(le):
		if counter[l[i]] >= 2 and counter[2 * l[i]] >= 2:
			doubles[2 * l[i]] = choose2[l[i]]
	pairs = collections.Counter()
	mpairs = collections.Counter()
	for i in range(le):
		for j in range(i + 1, le):
			if counter[l[i] + l[j]] >= 2:
				pairs[l[i] + l[j]] += counter[l[i]] * counter[l[j]]
				mpairs[l[i] + l[j]] += counter[l[i]] ** 2 * counter[l[j]] ** 2
	t3 = sum((pairs[s] * doubles[s] * choose2[s] for s in doubles if s in pairs))
	t4 = sum(((pairs[s] ** 2 - mpairs[s]) * choose2[s] for s in pairs)) // 2
	CD = collections.Counter()
	for d in range(le):
		if counter[l[d]] >= 3:
			for c in range(le):
				if l[c] < l[d]:
					CD[l[d] - l[c]] += choose3[l[d]] * counter[l[c]]
	s1 = 0
	s2 = 0
	s4 = 0
	for a in range(le):
		for b in range(a + 1, le):
			s1 += 2 * CD[l[a] + l[b]] * counter[l[a]] * counter[l[b]]
			if counter[l[a] + 2 * l[b]] >= 3:
				s2 += 2 * choose3[l[a] + 2 * l[b]] * counter[l[a]] * counter[l[b]] ** 2
			if counter[2 * l[a] + l[b]] >= 3:
				s2 += 2 * choose3[2 * l[a] + l[b]] * counter[l[b]] * counter[l[a]] ** 2
			if counter[l[b]] >= 2 and counter[l[a] + 2 * l[b]] >= 3:
				s4 += counter[l[a]] * choose2[l[b]] * choose3[l[a] + 2 * l[b]]
			if counter[l[a]] >= 2 and counter[2 * l[a] + l[b]] >= 3:
				s4 += counter[l[b]] * choose2[l[a]] * choose3[2 * l[a] + l[b]]
	s = (s1 - s2) // 6
	s3 = 0
	for a in range(le):
		if counter[l[a]] >= 3 and counter[3 * l[a]] >= 3:
			s3 += choose3[l[a]] * choose3[3 * l[a]]
	return t1 + t2 + t3 + t4 + s + s3 + s4
n = int(input())
l = list(map(int, input().rstrip().split()))
print(squareCount(l))


import collections
import math
import os
import random
import re
import sys

def choose(n, k):
	if k > n:
		return 0
	k = min(k, n - k)
	(num, den) = (1, 1)
	for i in range(k):
		num *= n - i
		den *= i + 1
	return num // den

def squareCount(l):
	counter = collections.Counter(l)
	l = tuple(counter.keys())
	choose2 = collections.Counter()
	choose3 = collections.Counter()
	choose4 = collections.Counter()
	le = len(l)
	for n in counter:
		count = counter[n]
		if count >= 2:
			choose2[n] = choose(count, 2)
			if count >= 3:
				choose3[n] = choose(count, 3)
				if count >= 4:
					choose4[n] = choose(count, 4)
	t1 = 0
	t2 = 0
	for i in range(le):
		if counter[2 * l[i]] >= 2 and counter[l[i]] >= 4:
			t1 += choose4[l[i]] * choose2[2 * l[i]]
		if counter[l[i]] >= 2:
			for j in range(i + 1, le):
				if counter[l[j]] >= 2 and counter[l[i] + l[j]] >= 2:
					t2 += choose2[l[i]] * choose2[l[j]] * choose2[l[i] + l[j]]
	doubles = collections.Counter()
	for i in range(le):
		if counter[l[i]] >= 2 and counter[2 * l[i]] >= 2:
			doubles[2 * l[i]] = choose2[l[i]]
	pairs = collections.Counter()
	mpairs = collections.Counter()
	for i in range(le):
		for j in range(i + 1, le):
			if counter[l[i] + l[j]] >= 2:
				pairs[l[i] + l[j]] += counter[l[i]] * counter[l[j]]
				mpairs[l[i] + l[j]] += counter[l[i]] ** 2 * counter[l[j]] ** 2
	t3 = sum((pairs[s] * doubles[s] * choose2[s] for s in doubles if s in pairs))
	t4 = sum(((pairs[s] ** 2 - mpairs[s]) * choose2[s] for s in pairs)) // 2
	CD = collections.Counter()
	for d in range(le):
		if counter[l[d]] >= 3:
			for c in range(le):
				if l[c] < l[d]:
					CD[l[d] - l[c]] += choose3[l[d]] * counter[l[c]]
	s1 = 0
	s2 = 0
	s4 = 0
	for a in range(le):
		for b in range(a + 1, le):
			s1 += 2 * CD[l[a] + l[b]] * counter[l[a]] * counter[l[b]]
			if counter[l[a] + 2 * l[b]] >= 3:
				s2 += 2 * choose3[l[a] + 2 * l[b]] * counter[l[a]] * counter[l[b]] ** 2
			if counter[2 * l[a] + l[b]] >= 3:
				s2 += 2 * choose3[2 * l[a] + l[b]] * counter[l[b]] * counter[l[a]] ** 2
			if counter[l[b]] >= 2 and counter[l[a] + 2 * l[b]] >= 3:
				s4 += counter[l[a]] * choose2[l[b]] * choose3[l[a] + 2 * l[b]]
			if counter[l[a]] >= 2 and counter[2 * l[a] + l[b]] >= 3:
				s4 += counter[l[b]] * choose2[l[a]] * choose3[2 * l[a] + l[b]]
	s = (s1 - s2) // 6
	s3 = 0
	for a in range(le):
		if counter[l[a]] >= 3 and counter[3 * l[a]] >= 3:
			s3 += choose3[l[a]] * choose3[3 * l[a]]
	return t1 + t2 + t3 + t4 + s + s3 + s4
n = int(input())
l = list(map(int, input().rstrip().split()))
print(squareCount(l))


import collections
import math
import os
import random
import re
import sys

def choose(n, k):
	if k > n:
		return 0
	k = min(k, n - k)
	(num, den) = (1, 1)
	for i in range(k):
		num *= n - i
		den *= i + 1
	return num // den

def squareCount(l):
	counter = collections.Counter(l)
	l = tuple(counter.keys())
	choose2 = collections.Counter()
	choose3 = collections.Counter()
	choose4 = collections.Counter()
	le = len(l)
	for n in counter:
		count = counter[n]
		if count >= 2:
			choose2[n] = choose(count, 2)
			if count >= 3:
				choose3[n] = choose(count, 3)
				if count >= 4:
					choose4[n] = choose(count, 4)
	t1 = 0
	t2 = 0
	for i in range(le):
		if counter[2 * l[i]] >= 2 and counter[l[i]] >= 4:
			t1 += choose4[l[i]] * choose2[2 * l[i]]
		if counter[l[i]] >= 2:
			for j in range(i + 1, le):
				if counter[l[j]] >= 2 and counter[l[i] + l[j]] >= 2:
					t2 += choose2[l[i]] * choose2[l[j]] * choose2[l[i] + l[j]]
	doubles = collections.Counter()
	for i in range(le):
		if counter[l[i]] >= 2 and counter[2 * l[i]] >= 2:
			doubles[2 * l[i]] = choose2[l[i]]
	pairs = collections.Counter()
	mpairs = collections.Counter()
	for i in range(le):
		for j in range(i + 1, le):
			if counter[l[i] + l[j]] >= 2:
				pairs[l[i] + l[j]] += counter[l[i]] * counter[l[j]]
				mpairs[l[i] + l[j]] += counter[l[i]] ** 2 * counter[l[j]] ** 2
	t3 = sum((pairs[s] * doubles[s] * choose2[s] for s in doubles if s in pairs))
	t4 = sum(((pairs[s] ** 2 - mpairs[s]) * choose2[s] for s in pairs)) // 2
	CD = collections.Counter()
	for d in range(le):
		if counter[l[d]] >= 3:
			for c in range(le):
				if l[c] < l[d]:
					CD[l[d] - l[c]] += choose3[l[d]] * counter[l[c]]
	s1 = 0
	s2 = 0
	s4 = 0
	for a in range(le):
		for b in range(a + 1, le):
			s1 += 2 * CD[l[a] + l[b]] * counter[l[a]] * counter[l[b]]
			if counter[l[a] + 2 * l[b]] >= 3:
				s2 += 2 * choose3[l[a] + 2 * l[b]] * counter[l[a]] * counter[l[b]] ** 2
			if counter[2 * l[a] + l[b]] >= 3:
				s2 += 2 * choose3[2 * l[a] + l[b]] * counter[l[b]] * counter[l[a]] ** 2
			if counter[l[b]] >= 2 and counter[l[a] + 2 * l[b]] >= 3:
				s4 += counter[l[a]] * choose2[l[b]] * choose3[l[a] + 2 * l[b]]
			if counter[l[a]] >= 2 and counter[2 * l[a] + l[b]] >= 3:
				s4 += counter[l[b]] * choose2[l[a]] * choose3[2 * l[a] + l[b]]
	s = (s1 - s2) // 6
	s3 = 0
	for a in range(le):
		if counter[l[a]] >= 3 and counter[3 * l[a]] >= 3:
			s3 += choose3[l[a]] * choose3[3 * l[a]]
	return t1 + t2 + t3 + t4 + s + s3 + s4
n = int(input())
l = list(map(int, input().rstrip().split()))
print(squareCount(l))


import collections
import math
import os
import random
import re
import sys

def choose(n, k):
	if k > n:
		return 0
	k = min(k, n - k)
	(num, den) = (1, 1)
	for i in range(k):
		num *= n - i
		den *= i + 1
	return num // den

def squareCount(l):
	counter = collections.Counter(l)
	l = tuple(counter.keys())
	choose2 = collections.Counter()
	choose3 = collections.Counter()
	choose4 = collections.Counter()
	le = len(l)
	for n in counter:
		count = counter[n]
		if count >= 2:
			choose2[n] = choose(count, 2)
			if count >= 3:
				choose3[n] = choose(count, 3)
				if count >= 4:
					choose4[n] = choose(count, 4)
	t1 = 0
	t2 = 0
	for i in range(le):
		if counter[2 * l[i]] >= 2 and counter[l[i]] >= 4:
			t1 += choose4[l[i]] * choose2[2 * l[i]]
		if counter[l[i]] >= 2:
			for j in range(i + 1, le):
				if counter[l[j]] >= 2 and counter[l[i] + l[j]] >= 2:
					t2 += choose2[l[i]] * choose2[l[j]] * choose2[l[i] + l[j]]
	doubles = collections.Counter()
	for i in range(le):
		if counter[l[i]] >= 2 and counter[2 * l[i]] >= 2:
			doubles[2 * l[i]] = choose2[l[i]]
	pairs = collections.Counter()
	mpairs = collections.Counter()
	for i in range(le):
		for j in range(i + 1, le):
			if counter[l[i] + l[j]] >= 2:
				pairs[l[i] + l[j]] += counter[l[i]] * counter[l[j]]
				mpairs[l[i] + l[j]] += counter[l[i]] ** 2 * counter[l[j]] ** 2
	t3 = sum((pairs[s] * doubles[s] * choose2[s] for s in doubles if s in pairs))
	t4 = sum(((pairs[s] ** 2 - mpairs[s]) * choose2[s] for s in pairs)) // 2
	CD = collections.Counter()
	for d in range(le):
		if counter[l[d]] >= 3:
			for c in range(le):
				if l[c] < l[d]:
					CD[l[d] - l[c]] += choose3[l[d]] * counter[l[c]]
	s1 = 0
	s2 = 0
	s4 = 0
	for a in range(le):
		for b in range(a + 1, le):
			s1 += 2 * CD[l[a] + l[b]] * counter[l[a]] * counter[l[b]]
			if counter[l[a] + 2 * l[b]] >= 3:
				s2 += 2 * choose3[l[a] + 2 * l[b]] * counter[l[a]] * counter[l[b]] ** 2
			if counter[2 * l[a] + l[b]] >= 3:
				s2 += 2 * choose3[2 * l[a] + l[b]] * counter[l[b]] * counter[l[a]] ** 2
			if counter[l[b]] >= 2 and counter[l[a] + 2 * l[b]] >= 3:
				s4 += counter[l[a]] * choose2[l[b]] * choose3[l[a] + 2 * l[b]]
			if counter[l[a]] >= 2 and counter[2 * l[a] + l[b]] >= 3:
				s4 += counter[l[b]] * choose2[l[a]] * choose3[2 * l[a] + l[b]]
	s = (s1 - s2) // 6
	s3 = 0
	for a in range(le):
		if counter[l[a]] >= 3 and counter[3 * l[a]] >= 3:
			s3 += choose3[l[a]] * choose3[3 * l[a]]
	return t1 + t2 + t3 + t4 + s + s3 + s4
n = int(input())
l = list(map(int, input().rstrip().split()))
print(squareCount(l))


import collections
import math
import os
import random
import re
import sys

def choose(n, k):
	if k > n:
		return 0
	k = min(k, n - k)
	(num, den) = (1, 1)
	for i in range(k):
		num *= n - i
		den *= i + 1
	return num // den

def squareCount(l):
	counter = collections.Counter(l)
	l = tuple(counter.keys())
	choose2 = collections.Counter()
	choose3 = collections.Counter()
	choose4 = collections.Counter()
	le = len(l)
	for n in counter:
		count = counter[n]
		if count >= 2:
			choose2[n] = choose(count, 2)
			if count >= 3:
				choose3[n] = choose(count, 3)
				if count >= 4:
					choose4[n] = choose(count, 4)
	t1 = 0
	t2 = 0
	for i in range(le):
		if counter[2 * l[i]] >= 2 and counter[l[i]] >= 4:
			t1 += choose4[l[i]] * choose2[2 * l[i]]
		if counter[l[i]] >= 2:
			for j in range(i + 1, le):
				if counter[l[j]] >= 2 and counter[l[i] + l[j]] >= 2:
					t2 += choose2[l[i]] * choose2[l[j]] * choose2[l[i] + l[j]]
	doubles = collections.Counter()
	for i in range(le):
		if counter[l[i]] >= 2 and counter[2 * l[i]] >= 2:
			doubles[2 * l[i]] = choose2[l[i]]
	pairs = collections.Counter()
	mpairs = collections.Counter()
	for i in range(le):
		for j in range(i + 1, le):
			if counter[l[i] + l[j]] >= 2:
				pairs[l[i] + l[j]] += counter[l[i]] * counter[l[j]]
				mpairs[l[i] + l[j]] += counter[l[i]] ** 2 * counter[l[j]] ** 2
	t3 = sum((pairs[s] * doubles[s] * choose2[s] for s in doubles if s in pairs))
	t4 = sum(((pairs[s] ** 2 - mpairs[s]) * choose2[s] for s in pairs)) // 2
	CD = collections.Counter()
	for d in range(le):
		if counter[l[d]] >= 3:
			for c in range(le):
				if l[c] < l[d]:
					CD[l[d] - l[c]] += choose3[l[d]] * counter[l[c]]
	s1 = 0
	s2 = 0
	s4 = 0
	for a in range(le):
		for b in range(a + 1, le):
			s1 += 2 * CD[l[a] + l[b]] * counter[l[a]] * counter[l[b]]
			if counter[l[a] + 2 * l[b]] >= 3:
				s2 += 2 * choose3[l[a] + 2 * l[b]] * counter[l[a]] * counter[l[b]] ** 2
			if counter[2 * l[a] + l[b]] >= 3:
				s2 += 2 * choose3[2 * l[a] + l[b]] * counter[l[b]] * counter[l[a]] ** 2
			if counter[l[b]] >= 2 and counter[l[a] + 2 * l[b]] >= 3:
				s4 += counter[l[a]] * choose2[l[b]] * choose3[l[a] + 2 * l[b]]
			if counter[l[a]] >= 2 and counter[2 * l[a] + l[b]] >= 3:
				s4 += counter[l[b]] * choose2[l[a]] * choose3[2 * l[a] + l[b]]
	s = (s1 - s2) // 6
	s3 = 0
	for a in range(le):
		if counter[l[a]] >= 3 and counter[3 * l[a]] >= 3:
			s3 += choose3[l[a]] * choose3[3 * l[a]]
	return t1 + t2 + t3 + t4 + s + s3 + s4
n = int(input())
l = list(map(int, input().rstrip().split()))
print(squareCount(l))


import collections
import math
import os
import random
import re
import sys

def choose(n, k):
	if k > n:
		return 0
	k = min(k, n - k)
	(num, den) = (1, 1)
	for i in range(k):
		num *= n - i
		den *= i + 1
	return num // den

def squareCount(l):
	counter = collections.Counter(l)
	l = tuple(counter.keys())
	choose2 = collections.Counter()
	choose3 = collections.Counter()
	choose4 = collections.Counter()
	le = len(l)
	for n in counter:
		count = counter[n]
		if count >= 2:
			choose2[n] = choose(count, 2)
			if count >= 3:
				choose3[n] = choose(count, 3)
				if count >= 4:
					choose4[n] = choose(count, 4)
	t1 = 0
	t2 = 0
	for i in range(le):
		if counter[2 * l[i]] >= 2 and counter[l[i]] >= 4:
			t1 += choose4[l[i]] * choose2[2 * l[i]]
		if counter[l[i]] >= 2:
			for j in range(i + 1, le):
				if counter[l[j]] >= 2 and counter[l[i] + l[j]] >= 2:
					t2 += choose2[l[i]] * choose2[l[j]] * choose2[l[i] + l[j]]
	doubles = collections.Counter()
	for i in range(le):
		if counter[l[i]] >= 2 and counter[2 * l[i]] >= 2:
			doubles[2 * l[i]] = choose2[l[i]]
	pairs = collections.Counter()
	mpairs = collections.Counter()
	for i in range(le):
		for j in range(i + 1, le):
			if counter[l[i] + l[j]] >= 2:
				pairs[l[i] + l[j]] += counter[l[i]] * counter[l[j]]
				mpairs[l[i] + l[j]] += counter[l[i]] ** 2 * counter[l[j]] ** 2
	t3 = sum((pairs[s] * doubles[s] * choose2[s] for s in doubles if s in pairs))
	t4 = sum(((pairs[s] ** 2 - mpairs[s]) * choose2[s] for s in pairs)) // 2
	CD = collections.Counter()
	for d in range(le):
		if counter[l[d]] >= 3:
			for c in range(le):
				if l[c] < l[d]:
					CD[l[d] - l[c]] += choose3[l[d]] * counter[l[c]]
	s1 = 0
	s2 = 0
	s4 = 0
	for a in range(le):
		for b in range(a + 1, le):
			s1 += 2 * CD[l[a] + l[b]] * counter[l[a]] * counter[l[b]]
			if counter[l[a] + 2 * l[b]] >= 3:
				s2 += 2 * choose3[l[a] + 2 * l[b]] * counter[l[a]] * counter[l[b]] ** 2
			if counter[2 * l[a] + l[b]] >= 3:
				s2 += 2 * choose3[2 * l[a] + l[b]] * counter[l[b]] * counter[l[a]] ** 2
			if counter[l[b]] >= 2 and counter[l[a] + 2 * l[b]] >= 3:
				s4 += counter[l[a]] * choose2[l[b]] * choose3[l[a] + 2 * l[b]]
			if counter[l[a]] >= 2 and counter[2 * l[a] + l[b]] >= 3:
				s4 += counter[l[b]] * choose2[l[a]] * choose3[2 * l[a] + l[b]]
	s = (s1 - s2) // 6
	s3 = 0
	for a in range(le):
		if counter[l[a]] >= 3 and counter[3 * l[a]] >= 3:
			s3 += choose3[l[a]] * choose3[3 * l[a]]
	return t1 + t2 + t3 + t4 + s + s3 + s4
n = int(input())
l = list(map(int, input().rstrip().split()))
print(squareCount(l))


import collections
import math
import os
import random
import re
import sys

def choose(n, k):
	if k > n:
		return 0
	k = min(k, n - k)
	(num, den) = (1, 1)
	for i in range(k):
		num *= n - i
		den *= i + 1
	return num // den

def squareCount(l):
	counter = collections.Counter(l)
	l = tuple(counter.keys())
	choose2 = collections.Counter()
	choose3 = collections.Counter()
	choose4 = collections.Counter()
	le = len(l)
	for n in counter:
		count = counter[n]
		if count >= 2:
			choose2[n] = choose(count, 2)
			if count >= 3:
				choose3[n] = choose(count, 3)
				if count >= 4:
					choose4[n] = choose(count, 4)
	t1 = 0
	t2 = 0
	for i in range(le):
		if counter[2 * l[i]] >= 2 and counter[l[i]] >= 4:
			t1 += choose4[l[i]] * choose2[2 * l[i]]
		if counter[l[i]] >= 2:
			for j in range(i + 1, le):
				if counter[l[j]] >= 2 and counter[l[i] + l[j]] >= 2:
					t2 += choose2[l[i]] * choose2[l[j]] * choose2[l[i] + l[j]]
	doubles = collections.Counter()
	for i in range(le):
		if counter[l[i]] >= 2 and counter[2 * l[i]] >= 2:
			doubles[2 * l[i]] = choose2[l[i]]
	pairs = collections.Counter()
	mpairs = collections.Counter()
	for i in range(le):
		for j in range(i + 1, le):
			if counter[l[i] + l[j]] >= 2:
				pairs[l[i] + l[j]] += counter[l[i]] * counter[l[j]]
				mpairs[l[i] + l[j]] += counter[l[i]] ** 2 * counter[l[j]] ** 2
	t3 = sum((pairs[s] * doubles[s] * choose2[s] for s in doubles if s in pairs))
	t4 = sum(((pairs[s] ** 2 - mpairs[s]) * choose2[s] for s in pairs)) // 2
	CD = collections.Counter()
	for d in range(le):
		if counter[l[d]] >= 3:
			for c in range(le):
				if l[c] < l[d]:
					CD[l[d] - l[c]] += choose3[l[d]] * counter[l[c]]
	s1 = 0
	s2 = 0
	s4 = 0
	for a in range(le):
		for b in range(a + 1, le):
			s1 += 2 * CD[l[a] + l[b]] * counter[l[a]] * counter[l[b]]
			if counter[l[a] + 2 * l[b]] >= 3:
				s2 += 2 * choose3[l[a] + 2 * l[b]] * counter[l[a]] * counter[l[b]] ** 2
			if counter[2 * l[a] + l[b]] >= 3:
				s2 += 2 * choose3[2 * l[a] + l[b]] * counter[l[b]] * counter[l[a]] ** 2
			if counter[l[b]] >= 2 and counter[l[a] + 2 * l[b]] >= 3:
				s4 += counter[l[a]] * choose2[l[b]] * choose3[l[a] + 2 * l[b]]
			if counter[l[a]] >= 2 and counter[2 * l[a] + l[b]] >= 3:
				s4 += counter[l[b]] * choose2[l[a]] * choose3[2 * l[a] + l[b]]
	s = (s1 - s2) // 6
	s3 = 0
	for a in range(le):
		if counter[l[a]] >= 3 and counter[3 * l[a]] >= 3:
			s3 += choose3[l[a]] * choose3[3 * l[a]]
	return t1 + t2 + t3 + t4 + s + s3 + s4
n = int(input())
l = list(map(int, input().rstrip().split()))
print(squareCount(l))


import collections
import math
import os
import random
import re
import sys

def choose(n, k):
	if k > n:
		return 0
	k = min(k, n - k)
	(num, den) = (1, 1)
	for i in range(k):
		num *= n - i
		den *= i + 1
	return num // den

def squareCount(l):
	counter = collections.Counter(l)
	l = tuple(counter.keys())
	choose2 = collections.Counter()
	choose3 = collections.Counter()
	choose4 = collections.Counter()
	le = len(l)
	for n in counter:
		count = counter[n]
		if count >= 2:
			choose2[n] = choose(count, 2)
			if count >= 3:
				choose3[n] = choose(count, 3)
				if count >= 4:
					choose4[n] = choose(count, 4)
	t1 = 0
	t2 = 0
	for i in range(le):
		if counter[2 * l[i]] >= 2 and counter[l[i]] >= 4:
			t1 += choose4[l[i]] * choose2[2 * l[i]]
		if counter[l[i]] >= 2:
			for j in range(i + 1, le):
				if counter[l[j]] >= 2 and counter[l[i] + l[j]] >= 2:
					t2 += choose2[l[i]] * choose2[l[j]] * choose2[l[i] + l[j]]
	doubles = collections.Counter()
	for i in range(le):
		if counter[l[i]] >= 2 and counter[2 * l[i]] >= 2:
			doubles[2 * l[i]] = choose2[l[i]]
	pairs = collections.Counter()
	mpairs = collections.Counter()
	for i in range(le):
		for j in range(i + 1, le):
			if counter[l[i] + l[j]] >= 2:
				pairs[l[i] + l[j]] += counter[l[i]] * counter[l[j]]
				mpairs[l[i] + l[j]] += counter[l[i]] ** 2 * counter[l[j]] ** 2
	t3 = sum((pairs[s] * doubles[s] * choose2[s] for s in doubles if s in pairs))
	t4 = sum(((pairs[s] ** 2 - mpairs[s]) * choose2[s] for s in pairs)) // 2
	CD = collections.Counter()
	for d in range(le):
		if counter[l[d]] >= 3:
			for c in range(le):
				if l[c] < l[d]:
					CD[l[d] - l[c]] += choose3[l[d]] * counter[l[c]]
	s1 = 0
	s2 = 0
	s4 = 0
	for a in range(le):
		for b in range(a + 1, le):
			s1 += 2 * CD[l[a] + l[b]] * counter[l[a]] * counter[l[b]]
			if counter[l[a] + 2 * l[b]] >= 3:
				s2 += 2 * choose3[l[a] + 2 * l[b]] * counter[l[a]] * counter[l[b]] ** 2
			if counter[2 * l[a] + l[b]] >= 3:
				s2 += 2 * choose3[2 * l[a] + l[b]] * counter[l[b]] * counter[l[a]] ** 2
			if counter[l[b]] >= 2 and counter[l[a] + 2 * l[b]] >= 3:
				s4 += counter[l[a]] * choose2[l[b]] * choose3[l[a] + 2 * l[b]]
			if counter[l[a]] >= 2 and counter[2 * l[a] + l[b]] >= 3:
				s4 += counter[l[b]] * choose2[l[a]] * choose3[2 * l[a] + l[b]]
	s = (s1 - s2) // 6
	s3 = 0
	for a in range(le):
		if counter[l[a]] >= 3 and counter[3 * l[a]] >= 3:
			s3 += choose3[l[a]] * choose3[3 * l[a]]
	return t1 + t2 + t3 + t4 + s + s3 + s4
n = int(input())
l = list(map(int, input().rstrip().split()))
print(squareCount(l))


import collections
import math
import os
import random
import re
import sys

def choose(n, k):
	if k > n:
		return 0
	k = min(k, n - k)
	(num, den) = (1, 1)
	for i in range(k):
		num *= n - i
		den *= i + 1
	return num // den

def squareCount(l):
	counter = collections.Counter(l)
	l = tuple(counter.keys())
	choose2 = collections.Counter()
	choose3 = collections.Counter()
	choose4 = collections.Counter()
	le = len(l)
	for n in counter:
		count = counter[n]
		if count >= 2:
			choose2[n] = choose(count, 2)
			if count >= 3:
				choose3[n] = choose(count, 3)
				if count >= 4:
					choose4[n] = choose(count, 4)
	t1 = 0
	t2 = 0
	for i in range(le):
		if counter[2 * l[i]] >= 2 and counter[l[i]] >= 4:
			t1 += choose4[l[i]] * choose2[2 * l[i]]
		if counter[l[i]] >= 2:
			for j in range(i + 1, le):
				if counter[l[j]] >= 2 and counter[l[i] + l[j]] >= 2:
					t2 += choose2[l[i]] * choose2[l[j]] * choose2[l[i] + l[j]]
	doubles = collections.Counter()
	for i in range(le):
		if counter[l[i]] >= 2 and counter[2 * l[i]] >= 2:
			doubles[2 * l[i]] = choose2[l[i]]
	pairs = collections.Counter()
	mpairs = collections.Counter()
	for i in range(le):
		for j in range(i + 1, le):
			if counter[l[i] + l[j]] >= 2:
				pairs[l[i] + l[j]] += counter[l[i]] * counter[l[j]]
				mpairs[l[i] + l[j]] += counter[l[i]] ** 2 * counter[l[j]] ** 2
	t3 = sum((pairs[s] * doubles[s] * choose2[s] for s in doubles if s in pairs))
	t4 = sum(((pairs[s] ** 2 - mpairs[s]) * choose2[s] for s in pairs)) // 2
	CD = collections.Counter()
	for d in range(le):
		if counter[l[d]] >= 3:
			for c in range(le):
				if l[c] < l[d]:
					CD[l[d] - l[c]] += choose3[l[d]] * counter[l[c]]
	s1 = 0
	s2 = 0
	s4 = 0
	for a in range(le):
		for b in range(a + 1, le):
			s1 += 2 * CD[l[a] + l[b]] * counter[l[a]] * counter[l[b]]
			if counter[l[a] + 2 * l[b]] >= 3:
				s2 += 2 * choose3[l[a] + 2 * l[b]] * counter[l[a]] * counter[l[b]] ** 2
			if counter[2 * l[a] + l[b]] >= 3:
				s2 += 2 * choose3[2 * l[a] + l[b]] * counter[l[b]] * counter[l[a]] ** 2
			if counter[l[b]] >= 2 and counter[l[a] + 2 * l[b]] >= 3:
				s4 += counter[l[a]] * choose2[l[b]] * choose3[l[a] + 2 * l[b]]
			if counter[l[a]] >= 2 and counter[2 * l[a] + l[b]] >= 3:
				s4 += counter[l[b]] * choose2[l[a]] * choose3[2 * l[a] + l[b]]
	s = (s1 - s2) // 6
	s3 = 0
	for a in range(le):
		if counter[l[a]] >= 3 and counter[3 * l[a]] >= 3:
			s3 += choose3[l[a]] * choose3[3 * l[a]]
	return t1 + t2 + t3 + t4 + s + s3 + s4
n = int(input())
l = list(map(int, input().rstrip().split()))
print(squareCount(l))


import collections
import math
import os
import random
import re
import sys

def choose(n, k):
	if k > n:
		return 0
	k = min(k, n - k)
	(num, den) = (1, 1)
	for i in range(k):
		num *= n - i
		den *= i + 1
	return num // den

def squareCount(l):
	counter = collections.Counter(l)
	l = tuple(counter.keys())
	choose2 = collections.Counter()
	choose3 = collections.Counter()
	choose4 = collections.Counter()
	le = len(l)
	for n in counter:
		count = counter[n]
		if count >= 2:
			choose2[n] = choose(count, 2)
			if count >= 3:
				choose3[n] = choose(count, 3)
				if count >= 4:
					choose4[n] = choose(count, 4)
	t1 = 0
	t2 = 0
	for i in range(le):
		if counter[2 * l[i]] >= 2 and counter[l[i]] >= 4:
			t1 += choose4[l[i]] * choose2[2 * l[i]]
		if counter[l[i]] >= 2:
			for j in range(i + 1, le):
				if counter[l[j]] >= 2 and counter[l[i] + l[j]] >= 2:
					t2 += choose2[l[i]] * choose2[l[j]] * choose2[l[i] + l[j]]
	doubles = collections.Counter()
	for i in range(le):
		if counter[l[i]] >= 2 and counter[2 * l[i]] >= 2:
			doubles[2 * l[i]] = choose2[l[i]]
	pairs = collections.Counter()
	mpairs = collections.Counter()
	for i in range(le):
		for j in range(i + 1, le):
			if counter[l[i] + l[j]] >= 2:
				pairs[l[i] + l[j]] += counter[l[i]] * counter[l[j]]
				mpairs[l[i] + l[j]] += counter[l[i]] ** 2 * counter[l[j]] ** 2
	t3 = sum((pairs[s] * doubles[s] * choose2[s] for s in doubles if s in pairs))
	t4 = sum(((pairs[s] ** 2 - mpairs[s]) * choose2[s] for s in pairs)) // 2
	CD = collections.Counter()
	for d in range(le):
		if counter[l[d]] >= 3:
			for c in range(le):
				if l[c] < l[d]:
					CD[l[d] - l[c]] += choose3[l[d]] * counter[l[c]]
	s1 = 0
	s2 = 0
	s4 = 0
	for a in range(le):
		for b in range(a + 1, le):
			s1 += 2 * CD[l[a] + l[b]] * counter[l[a]] * counter[l[b]]
			if counter[l[a] + 2 * l[b]] >= 3:
				s2 += 2 * choose3[l[a] + 2 * l[b]] * counter[l[a]] * counter[l[b]] ** 2
			if counter[2 * l[a] + l[b]] >= 3:
				s2 += 2 * choose3[2 * l[a] + l[b]] * counter[l[b]] * counter[l[a]] ** 2
			if counter[l[b]] >= 2 and counter[l[a] + 2 * l[b]] >= 3:
				s4 += counter[l[a]] * choose2[l[b]] * choose3[l[a] + 2 * l[b]]
			if counter[l[a]] >= 2 and counter[2 * l[a] + l[b]] >= 3:
				s4 += counter[l[b]] * choose2[l[a]] * choose3[2 * l[a] + l[b]]
	s = (s1 - s2) // 6
	s3 = 0
	for a in range(le):
		if counter[l[a]] >= 3 and counter[3 * l[a]] >= 3:
			s3 += choose3[l[a]] * choose3[3 * l[a]]
	return t1 + t2 + t3 + t4 + s + s3 + s4
n = int(input())
l = list(map(int, input().rstrip().split()))
print(squareCount(l))


import collections
import math
import os
import random
import re
import sys

def choose(n, k):
	if k > n:
		return 0
	k = min(k, n - k)
	(num, den) = (1, 1)
	for i in range(k):
		num *= n - i
		den *= i + 1
	return num // den

def squareCount(l):
	counter = collections.Counter(l)
	l = tuple(counter.keys())
	choose2 = collections.Counter()
	choose3 = collections.Counter()
	choose4 = collections.Counter()
	le = len(l)
	for n in counter:
		count = counter[n]
		if count >= 2:
			choose2[n] = choose(count, 2)
			if count >= 3:
				choose3[n] = choose(count, 3)
				if count >= 4:
					choose4[n] = choose(count, 4)
	t1 = 0
	t2 = 0
	for i in range(le):
		if counter[2 * l[i]] >= 2 and counter[l[i]] >= 4:
			t1 += choose4[l[i]] * choose2[2 * l[i]]
		if counter[l[i]] >= 2:
			for j in range(i + 1, le):
				if counter[l[j]] >= 2 and counter[l[i] + l[j]] >= 2:
					t2 += choose2[l[i]] * choose2[l[j]] * choose2[l[i] + l[j]]
	doubles = collections.Counter()
	for i in range(le):
		if counter[l[i]] >= 2 and counter[2 * l[i]] >= 2:
			doubles[2 * l[i]] = choose2[l[i]]
	pairs = collections.Counter()
	mpairs = collections.Counter()
	for i in range(le):
		for j in range(i + 1, le):
			if counter[l[i] + l[j]] >= 2:
				pairs[l[i] + l[j]] += counter[l[i]] * counter[l[j]]
				mpairs[l[i] + l[j]] += counter[l[i]] ** 2 * counter[l[j]] ** 2
	t3 = sum((pairs[s] * doubles[s] * choose2[s] for s in doubles if s in pairs))
	t4 = sum(((pairs[s] ** 2 - mpairs[s]) * choose2[s] for s in pairs)) // 2
	CD = collections.Counter()
	for d in range(le):
		if counter[l[d]] >= 3:
			for c in range(le):
				if l[c] < l[d]:
					CD[l[d] - l[c]] += choose3[l[d]] * counter[l[c]]
	s1 = 0
	s2 = 0
	s4 = 0
	for a in range(le):
		for b in range(a + 1, le):
			s1 += 2 * CD[l[a] + l[b]] * counter[l[a]] * counter[l[b]]
			if counter[l[a] + 2 * l[b]] >= 3:
				s2 += 2 * choose3[l[a] + 2 * l[b]] * counter[l[a]] * counter[l[b]] ** 2
			if counter[2 * l[a] + l[b]] >= 3:
				s2 += 2 * choose3[2 * l[a] + l[b]] * counter[l[b]] * counter[l[a]] ** 2
			if counter[l[b]] >= 2 and counter[l[a] + 2 * l[b]] >= 3:
				s4 += counter[l[a]] * choose2[l[b]] * choose3[l[a] + 2 * l[b]]
			if counter[l[a]] >= 2 and counter[2 * l[a] + l[b]] >= 3:
				s4 += counter[l[b]] * choose2[l[a]] * choose3[2 * l[a] + l[b]]
	s = (s1 - s2) // 6
	s3 = 0
	for a in range(le):
		if counter[l[a]] >= 3 and counter[3 * l[a]] >= 3:
			s3 += choose3[l[a]] * choose3[3 * l[a]]
	return t1 + t2 + t3 + t4 + s + s3 + s4
n = int(input())
l = list(map(int, input().rstrip().split()))
print(squareCount(l))


import collections
import math
import os
import random
import re
import sys

def choose(n, k):
	if k > n:
		return 0
	k = min(k, n - k)
	(num, den) = (1, 1)
	for i in range(k):
		num *= n - i
		den *= i + 1
	return num // den

def squareCount(l):
	counter = collections.Counter(l)
	l = tuple(counter.keys())
	choose2 = collections.Counter()
	choose3 = collections.Counter()
	choose4 = collections.Counter()
	le = len(l)
	for n in counter:
		count = counter[n]
		if count >= 2:
			choose2[n] = choose(count, 2)
			if count >= 3:
				choose3[n] = choose(count, 3)
				if count >= 4:
					choose4[n] = choose(count, 4)
	t1 = 0
	t2 = 0
	for i in range(le):
		if counter[2 * l[i]] >= 2 and counter[l[i]] >= 4:
			t1 += choose4[l[i]] * choose2[2 * l[i]]
		if counter[l[i]] >= 2:
			for j in range(i + 1, le):
				if counter[l[j]] >= 2 and counter[l[i] + l[j]] >= 2:
					t2 += choose2[l[i]] * choose2[l[j]] * choose2[l[i] + l[j]]
	doubles = collections.Counter()
	for i in range(le):
		if counter[l[i]] >= 2 and counter[2 * l[i]] >= 2:
			doubles[2 * l[i]] = choose2[l[i]]
	pairs = collections.Counter()
	mpairs = collections.Counter()
	for i in range(le):
		for j in range(i + 1, le):
			if counter[l[i] + l[j]] >= 2:
				pairs[l[i] + l[j]] += counter[l[i]] * counter[l[j]]
				mpairs[l[i] + l[j]] += counter[l[i]] ** 2 * counter[l[j]] ** 2
	t3 = sum((pairs[s] * doubles[s] * choose2[s] for s in doubles if s in pairs))
	t4 = sum(((pairs[s] ** 2 - mpairs[s]) * choose2[s] for s in pairs)) // 2
	CD = collections.Counter()
	for d in range(le):
		if counter[l[d]] >= 3:
			for c in range(le):
				if l[c] < l[d]:
					CD[l[d] - l[c]] += choose3[l[d]] * counter[l[c]]
	s1 = 0
	s2 = 0
	s4 = 0
	for a in range(le):
		for b in range(a + 1, le):
			s1 += 2 * CD[l[a] + l[b]] * counter[l[a]] * counter[l[b]]
			if counter[l[a] + 2 * l[b]] >= 3:
				s2 += 2 * choose3[l[a] + 2 * l[b]] * counter[l[a]] * counter[l[b]] ** 2
			if counter[2 * l[a] + l[b]] >= 3:
				s2 += 2 * choose3[2 * l[a] + l[b]] * counter[l[b]] * counter[l[a]] ** 2
			if counter[l[b]] >= 2 and counter[l[a] + 2 * l[b]] >= 3:
				s4 += counter[l[a]] * choose2[l[b]] * choose3[l[a] + 2 * l[b]]
			if counter[l[a]] >= 2 and counter[2 * l[a] + l[b]] >= 3:
				s4 += counter[l[b]] * choose2[l[a]] * choose3[2 * l[a] + l[b]]
	s = (s1 - s2) // 6
	s3 = 0
	for a in range(le):
		if counter[l[a]] >= 3 and counter[3 * l[a]] >= 3:
			s3 += choose3[l[a]] * choose3[3 * l[a]]
	return t1 + t2 + t3 + t4 + s + s3 + s4
n = int(input())
l = list(map(int, input().rstrip().split()))
print(squareCount(l))


import collections
import math
import os
import random
import re
import sys

def choose(n, k):
	if k > n:
		return 0
	k = min(k, n - k)
	(num, den) = (1, 1)
	for i in range(k):
		num *= n - i
		den *= i + 1
	return num // den

def squareCount(l):
	counter = collections.Counter(l)
	l = tuple(counter.keys())
	choose2 = collections.Counter()
	choose3 = collections.Counter()
	choose4 = collections.Counter()
	le = len(l)
	for n in counter:
		count = counter[n]
		if count >= 2:
			choose2[n] = choose(count, 2)
			if count >= 3:
				choose3[n] = choose(count, 3)
				if count >= 4:
					choose4[n] = choose(count, 4)
	t1 = 0
	t2 = 0
	for i in range(le):
		if counter[2 * l[i]] >= 2 and counter[l[i]] >= 4:
			t1 += choose4[l[i]] * choose2[2 * l[i]]
		if counter[l[i]] >= 2:
			for j in range(i + 1, le):
				if counter[l[j]] >= 2 and counter[l[i] + l[j]] >= 2:
					t2 += choose2[l[i]] * choose2[l[j]] * choose2[l[i] + l[j]]
	doubles = collections.Counter()
	for i in range(le):
		if counter[l[i]] >= 2 and counter[2 * l[i]] >= 2:
			doubles[2 * l[i]] = choose2[l[i]]
	pairs = collections.Counter()
	mpairs = collections.Counter()
	for i in range(le):
		for j in range(i + 1, le):
			if counter[l[i] + l[j]] >= 2:
				pairs[l[i] + l[j]] += counter[l[i]] * counter[l[j]]
				mpairs[l[i] + l[j]] += counter[l[i]] ** 2 * counter[l[j]] ** 2
	t3 = sum((pairs[s] * doubles[s] * choose2[s] for s in doubles if s in pairs))
	t4 = sum(((pairs[s] ** 2 - mpairs[s]) * choose2[s] for s in pairs)) // 2
	CD = collections.Counter()
	for d in range(le):
		if counter[l[d]] >= 3:
			for c in range(le):
				if l[c] < l[d]:
					CD[l[d] - l[c]] += choose3[l[d]] * counter[l[c]]
	s1 = 0
	s2 = 0
	s4 = 0
	for a in range(le):
		for b in range(a + 1, le):
			s1 += 2 * CD[l[a] + l[b]] * counter[l[a]] * counter[l[b]]
			if counter[l[a] + 2 * l[b]] >= 3:
				s2 += 2 * choose3[l[a] + 2 * l[b]] * counter[l[a]] * counter[l[b]] ** 2
			if counter[2 * l[a] + l[b]] >= 3:
				s2 += 2 * choose3[2 * l[a] + l[b]] * counter[l[b]] * counter[l[a]] ** 2
			if counter[l[b]] >= 2 and counter[l[a] + 2 * l[b]] >= 3:
				s4 += counter[l[a]] * choose2[l[b]] * choose3[l[a] + 2 * l[b]]
			if counter[l[a]] >= 2 and counter[2 * l[a] + l[b]] >= 3:
				s4 += counter[l[b]] * choose2[l[a]] * choose3[2 * l[a] + l[b]]
	s = (s1 - s2) // 6
	s3 = 0
	for a in range(le):
		if counter[l[a]] >= 3 and counter[3 * l[a]] >= 3:
			s3 += choose3[l[a]] * choose3[3 * l[a]]
	return t1 + t2 + t3 + t4 + s + s3 + s4
n = int(input())
l = list(map(int, input().rstrip().split()))
print(squareCount(l))


import collections
import math
import os
import random
import re
import sys

def choose(n, k):
	if k > n:
		return 0
	k = min(k, n - k)
	(num, den) = (1, 1)
	for i in range(k):
		num *= n - i
		den *= i + 1
	return num // den

def squareCount(l):
	counter = collections.Counter(l)
	l = tuple(counter.keys())
	choose2 = collections.Counter()
	choose3 = collections.Counter()
	choose4 = collections.Counter()
	le = len(l)
	for n in counter:
		count = counter[n]
		if count >= 2:
			choose2[n] = choose(count, 2)
			if count >= 3:
				choose3[n] = choose(count, 3)
				if count >= 4:
					choose4[n] = choose(count, 4)
	t1 = 0
	t2 = 0
	for i in range(le):
		if counter[2 * l[i]] >= 2 and counter[l[i]] >= 4:
			t1 += choose4[l[i]] * choose2[2 * l[i]]
		if counter[l[i]] >= 2:
			for j in range(i + 1, le):
				if counter[l[j]] >= 2 and counter[l[i] + l[j]] >= 2:
					t2 += choose2[l[i]] * choose2[l[j]] * choose2[l[i] + l[j]]
	doubles = collections.Counter()
	for i in range(le):
		if counter[l[i]] >= 2 and counter[2 * l[i]] >= 2:
			doubles[2 * l[i]] = choose2[l[i]]
	pairs = collections.Counter()
	mpairs = collections.Counter()
	for i in range(le):
		for j in range(i + 1, le):
			if counter[l[i] + l[j]] >= 2:
				pairs[l[i] + l[j]] += counter[l[i]] * counter[l[j]]
				mpairs[l[i] + l[j]] += counter[l[i]] ** 2 * counter[l[j]] ** 2
	t3 = sum((pairs[s] * doubles[s] * choose2[s] for s in doubles if s in pairs))
	t4 = sum(((pairs[s] ** 2 - mpairs[s]) * choose2[s] for s in pairs)) // 2
	CD = collections.Counter()
	for d in range(le):
		if counter[l[d]] >= 3:
			for c in range(le):
				if l[c] < l[d]:
					CD[l[d] - l[c]] += choose3[l[d]] * counter[l[c]]
	s1 = 0
	s2 = 0
	s4 = 0
	for a in range(le):
		for b in range(a + 1, le):
			s1 += 2 * CD[l[a] + l[b]] * counter[l[a]] * counter[l[b]]
			if counter[l[a] + 2 * l[b]] >= 3:
				s2 += 2 * choose3[l[a] + 2 * l[b]] * counter[l[a]] * counter[l[b]] ** 2
			if counter[2 * l[a] + l[b]] >= 3:
				s2 += 2 * choose3[2 * l[a] + l[b]] * counter[l[b]] * counter[l[a]] ** 2
			if counter[l[b]] >= 2 and counter[l[a] + 2 * l[b]] >= 3:
				s4 += counter[l[a]] * choose2[l[b]] * choose3[l[a] + 2 * l[b]]
			if counter[l[a]] >= 2 and counter[2 * l[a] + l[b]] >= 3:
				s4 += counter[l[b]] * choose2[l[a]] * choose3[2 * l[a] + l[b]]
	s = (s1 - s2) // 6
	s3 = 0
	for a in range(le):
		if counter[l[a]] >= 3 and counter[3 * l[a]] >= 3:
			s3 += choose3[l[a]] * choose3[3 * l[a]]
	return t1 + t2 + t3 + t4 + s + s3 + s4
n = int(input())
l = list(map(int, input().rstrip().split()))
print(squareCount(l))


import collections
import math
import os
import random
import re
import sys

def choose(n, k):
	if k > n:
		return 0
	k = min(k, n - k)
	(num, den) = (1, 1)
	for i in range(k):
		num *= n - i
		den *= i + 1
	return num // den

def squareCount(l):
	counter = collections.Counter(l)
	l = tuple(counter.keys())
	choose2 = collections.Counter()
	choose3 = collections.Counter()
	choose4 = collections.Counter()
	le = len(l)
	for n in counter:
		count = counter[n]
		if count >= 2:
			choose2[n] = choose(count, 2)
			if count >= 3:
				choose3[n] = choose(count, 3)
				if count >= 4:
					choose4[n] = choose(count, 4)
	t1 = 0
	t2 = 0
	for i in range(le):
		if counter[2 * l[i]] >= 2 and counter[l[i]] >= 4:
			t1 += choose4[l[i]] * choose2[2 * l[i]]
		if counter[l[i]] >= 2:
			for j in range(i + 1, le):
				if counter[l[j]] >= 2 and counter[l[i] + l[j]] >= 2:
					t2 += choose2[l[i]] * choose2[l[j]] * choose2[l[i] + l[j]]
	doubles = collections.Counter()
	for i in range(le):
		if counter[l[i]] >= 2 and counter[2 * l[i]] >= 2:
			doubles[2 * l[i]] = choose2[l[i]]
	pairs = collections.Counter()
	mpairs = collections.Counter()
	for i in range(le):
		for j in range(i + 1, le):
			if counter[l[i] + l[j]] >= 2:
				pairs[l[i] + l[j]] += counter[l[i]] * counter[l[j]]
				mpairs[l[i] + l[j]] += counter[l[i]] ** 2 * counter[l[j]] ** 2
	t3 = sum((pairs[s] * doubles[s] * choose2[s] for s in doubles if s in pairs))
	t4 = sum(((pairs[s] ** 2 - mpairs[s]) * choose2[s] for s in pairs)) // 2
	CD = collections.Counter()
	for d in range(le):
		if counter[l[d]] >= 3:
			for c in range(le):
				if l[c] < l[d]:
					CD[l[d] - l[c]] += choose3[l[d]] * counter[l[c]]
	s1 = 0
	s2 = 0
	s4 = 0
	for a in range(le):
		for b in range(a + 1, le):
			s1 += 2 * CD[l[a] + l[b]] * counter[l[a]] * counter[l[b]]
			if counter[l[a] + 2 * l[b]] >= 3:
				s2 += 2 * choose3[l[a] + 2 * l[b]] * counter[l[a]] * counter[l[b]] ** 2
			if counter[2 * l[a] + l[b]] >= 3:
				s2 += 2 * choose3[2 * l[a] + l[b]] * counter[l[b]] * counter[l[a]] ** 2
			if counter[l[b]] >= 2 and counter[l[a] + 2 * l[b]] >= 3:
				s4 += counter[l[a]] * choose2[l[b]] * choose3[l[a] + 2 * l[b]]
			if counter[l[a]] >= 2 and counter[2 * l[a] + l[b]] >= 3:
				s4 += counter[l[b]] * choose2[l[a]] * choose3[2 * l[a] + l[b]]
	s = (s1 - s2) // 6
	s3 = 0
	for a in range(le):
		if counter[l[a]] >= 3 and counter[3 * l[a]] >= 3:
			s3 += choose3[l[a]] * choose3[3 * l[a]]
	return t1 + t2 + t3 + t4 + s + s3 + s4
n = int(input())
l = list(map(int, input().rstrip().split()))
print(squareCount(l))


import collections
import math
import os
import random
import re
import sys

def choose(n, k):
	if k > n:
		return 0
	k = min(k, n - k)
	(num, den) = (1, 1)
	for i in range(k):
		num *= n - i
		den *= i + 1
	return num // den

def squareCount(l):
	counter = collections.Counter(l)
	l = tuple(counter.keys())
	choose2 = collections.Counter()
	choose3 = collections.Counter()
	choose4 = collections.Counter()
	le = len(l)
	for n in counter:
		count = counter[n]
		if count >= 2:
			choose2[n] = choose(count, 2)
			if count >= 3:
				choose3[n] = choose(count, 3)
				if count >= 4:
					choose4[n] = choose(count, 4)
	t1 = 0
	t2 = 0
	for i in range(le):
		if counter[2 * l[i]] >= 2 and counter[l[i]] >= 4:
			t1 += choose4[l[i]] * choose2[2 * l[i]]
		if counter[l[i]] >= 2:
			for j in range(i + 1, le):
				if counter[l[j]] >= 2 and counter[l[i] + l[j]] >= 2:
					t2 += choose2[l[i]] * choose2[l[j]] * choose2[l[i] + l[j]]
	doubles = collections.Counter()
	for i in range(le):
		if counter[l[i]] >= 2 and counter[2 * l[i]] >= 2:
			doubles[2 * l[i]] = choose2[l[i]]
	pairs = collections.Counter()
	mpairs = collections.Counter()
	for i in range(le):
		for j in range(i + 1, le):
			if counter[l[i] + l[j]] >= 2:
				pairs[l[i] + l[j]] += counter[l[i]] * counter[l[j]]
				mpairs[l[i] + l[j]] += counter[l[i]] ** 2 * counter[l[j]] ** 2
	t3 = sum((pairs[s] * doubles[s] * choose2[s] for s in doubles if s in pairs))
	t4 = sum(((pairs[s] ** 2 - mpairs[s]) * choose2[s] for s in pairs)) // 2
	CD = collections.Counter()
	for d in range(le):
		if counter[l[d]] >= 3:
			for c in range(le):
				if l[c] < l[d]:
					CD[l[d] - l[c]] += choose3[l[d]] * counter[l[c]]
	s1 = 0
	s2 = 0
	s4 = 0
	for a in range(le):
		for b in range(a + 1, le):
			s1 += 2 * CD[l[a] + l[b]] * counter[l[a]] * counter[l[b]]
			if counter[l[a] + 2 * l[b]] >= 3:
				s2 += 2 * choose3[l[a] + 2 * l[b]] * counter[l[a]] * counter[l[b]] ** 2
			if counter[2 * l[a] + l[b]] >= 3:
				s2 += 2 * choose3[2 * l[a] + l[b]] * counter[l[b]] * counter[l[a]] ** 2
			if counter[l[b]] >= 2 and counter[l[a] + 2 * l[b]] >= 3:
				s4 += counter[l[a]] * choose2[l[b]] * choose3[l[a] + 2 * l[b]]
			if counter[l[a]] >= 2 and counter[2 * l[a] + l[b]] >= 3:
				s4 += counter[l[b]] * choose2[l[a]] * choose3[2 * l[a] + l[b]]
	s = (s1 - s2) // 6
	s3 = 0
	for a in range(le):
		if counter[l[a]] >= 3 and counter[3 * l[a]] >= 3:
			s3 += choose3[l[a]] * choose3[3 * l[a]]
	return t1 + t2 + t3 + t4 + s + s3 + s4
n = int(input())
l = list(map(int, input().rstrip().split()))
print(squareCount(l))