class Solution:
    def threeSumMulti(self, A, target):
        """
        :type A: List[int]
        :type target: int
        :rtype: int
        """
        count,dict1=0,{}
        n=len(A)
        for i in range(n):
            if A[i] not in dict1:
                dict1[A[i]]=1
            else:
                dict1[A[i]]+=1
        for key1,val1 in dict1.items():
            for key2,val2 in dict1.items():
                key3=target-key1-key2
                if key3 in dict1:
                    if key1==key2==key3:
                        count+=val1*(val1-1)*(val2-2)/6
                    if key1==key2 and key1!=key3:
                        count+=val1*(val1-1)/2*dict1[key3]
                    if key1<key2<key3:
                        count+=val1*val2*dict1[key3]
        return int(count)%(10**9+7)
s=Solution()
A = [0,0,0]
target = 0
print(s.threeSumMulti(A,target))