human
Write me a the Python program you requested given the following:
I found an interesting problem on https://leetcode.com/problems/number-of-squareful-arrays/:
Given an array A of non-negative integers, the array is squareful if for every pair of adjacent elements, their sum is a perfect square.
Return the number of permutations of A that are squareful.  Two permutations A1 and A2 differ if and only if there is some index i such that A1[i] != A2[i].
 
Example 1:
Input: [1,17,8]
Output: 2
Explanation: 
[1,8,17] and [17,8,1] are the valid permutations.

Example 2:
Input: [2,2,2]
Output: 1

 
Note:

1 <= A.length <= 12
0 <= A[i] <= 1e9

I tried it in Python, but could not do it. Can you solve it?
assistant
#Here is the Python program you requested.

import numpy as np
class Solution:
    graph = {}
    count = {}
    def numSquarefulPerms(self, A: List[int]) -> int:
        self.graph = {}
        self.count = {}
        for i in A:
            if i in self.count:
                self.count[i] += 1
            else:
                self.count[i] = 1
            self.graph[i] = []
            
        for i in self.count:
            for j in self.count:
                r = int(np.sqrt(i + j))
                if r * r == i + j:
                    self.graph[i].append(j)
        ans = 0
        L = len(A)
        for i in self.graph:
            ans += self.dfs(i, L-1)
        return ans
    
    def dfs(self, i, L):
        self.count[i] -= 1
        ans = 1
        if L != 0:
            ans = 0
            for j in self.graph[i]:
                if self.count[j] != 0:
                    ans += self.dfs(j, L - 1)
        self.count[i] += 1
        return ans