Given an array of integers, return the number of distinct permutations such that for every pair of adjacent elements, their sum is a perfect square. The array may contain duplicates. Input: sorted integer array.
Input: An integer array (sorted).
Output: Integer count.
Input: [1,17,8]
Output: 2
Explanation: [1,8,17] and [17,8,1]; 1+8=9, 8+17=25.Input: [2,2,2]
Output: 0
Explanation: 2+2=4 is square, but need 3 adjacent pairs; only 2 pairs exist for 3 elements. [2,2,2]: 2+2=4 ✓, 2+2=4 ✓ -> count=1. Wait, let me recheck.1 <= nums.length <= 120 <= nums[i] <= 10^9