You are given an integer sequence $A_1, A_2, \ldots, A_N$ and an integer $X$. Consider a $N \times N$ matrix $B$, where $B_{i,j} = A_i + A_j$ for each valid $i$ and $j$.
You need to find the number of square submatrices of $B$ such that the sum of their elements is $X$. Formally, find the number of quartets $(x_1, y_1, x_2, y_2)$ such that $1 \le x_1 \le x_2 \le N$, $1 \le y_1 \le y_2 \le N$, $x_2-x_1 = y_2-y_1$ and $\sum_{i=x_1}^{x_2}\sum_{j=y_1}^{y_2} B_{i,j} = X$.

-----Input-----
- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
- The first line of each test case contains two space-separated integers $N$ and $X$.
- The second line contains $N$ space-separated integers $A_1, A_2, \ldots, A_N$.

-----Output-----
For each test case, print a single line containing one integer ― the number of square submatrices with sum $X$.

-----Constraints-----
- $1 \le T \le 100$
- $1 \le X \le 10^6$
- $1 \le N \le 10^5$
- $1 \le A_i \le 10^6$ for each valid $i$
- the sum of $N$ over all test cases does not exceed $10^6$

-----Subtasks-----
Subtask #1 (50 points): the sum of $N$ over all test cases does not exceed $1,000$
Subtask #2 (50 points): original constraints

-----Example Input-----
2
5 36
1 2 3 1 12
4 54
3 3 3 3

-----Example Output-----
6
4

```python

USER_FILENAME = "<user_code>"
import sys, json, builtins
import math, heapq, bisect, itertools, functools, collections, statistics, fractions, decimal, operator, array, random, re, string, os, pathlib
try:
    import resource as _res
except Exception:
    _res = None
from collections import Counter, defaultdict, deque, OrderedDict
from functools import lru_cache, reduce
from itertools import accumulate, permutations, combinations, product
from math import gcd, ceil, floor, sqrt
from decimal import Decimal
try:
    from typing import *
except Exception:
    pass
try:
    sys.setrecursionlimit(1_000_000)
except Exception:
    pass
try:
    import site as _site
    try:
        _sys_sites = _site.getsitepackages() if hasattr(_site, "getsitepackages") else []
        for _p in _sys_sites:
            if _p and _p not in sys.path:
                sys.path.append(_p)
    except Exception:
        pass
    try:
        _usp = _site.getusersitepackages()
        if isinstance(_usp, str):
            _usp = [_usp]
        for _p in _usp:
            if _p and _p not in sys.path:
                sys.path.append(_p)
    except Exception:
        pass
except Exception:
    pass

ns = {"__name__": "__main__"}
for _k, _v in list(globals().items()):
    if not _k.startswith("_"):
        ns[_k] = _v
_CODE = "from datetime import datetime\n\n# -----------------------------------------------------------------------------\nSTART_TIME = datetime.now()\n\ndef debug(*args, **kwargs):\n # print(datetime.now() - START_TIME, *args, dict(**kwargs))\n return\n\n# -----------------------------------------------------------------------------\ndef printResult(result):\n if isinstance(result, list):\n  print(*result)\n else:\n  print(result)\n\n# -----------------------------------------------------------------------------\ndef main():\n debug('started')\n noOfTests = int(input())\n\n for i in range(noOfTests):\n  result = runATest(i)\n  if isinstance(result, tuple):\n   for line in result:\n    printResult(line)\n  else:\n   printResult(result)\n debug('finished')\n\n# -----------------------------------------------------------------------------\n# def runATest(_testIndex):\n\n#     [count, refTotal] = [int(x) for x in input().split()]\n\n#     aList = [int(x) for x in input().split()]\n#     matrix = [None] * count\n\n#     debug(low=min(aList), high=max(aList), average=sum(aList)/count, len=len\xa0\xa0\xa0\xa0(aList))\n\n#     for i in range(count):\n#         matrix[i] = tuple((lambda xi, xj: xi + xj)(aList[i], xj) for xj in \xa0\xa0\xa0\xa0aList)\n#     matrix = tuple(matrix)\n\n#     # for i in range(count):\n#     #     debug(*matrix[i])\n\n#     return countSquares(matrix, refTotal, count)\n\n# def countSquares(matrix, refTotal, count):\n\n#     total = 0\n#     for i in range(count):\n#         for j in range(count):\n#             if countSquaresAtPoint(matrix, refTotal, count, i, j):\n#                 total += 1\n#         debug('completed col', i=i, j=j)\n\n#     return total\n\n# def countSquaresAtPoint(matrix, refTotal, count, x, y):\n\n#     maxLimit = min(count - x, count - y)\n\n#     totalSoFar = 0\n#     for limit in range(maxLimit):\n\n#         xLimit = x + limit\n#         yLimit = y + limit\n#         totalSoFar += matrix[xLimit][yLimit]\n\n#         for i in range(x, x + limit):\n#             totalSoFar += matrix[i][yLimit]\n\n#         for j in range(y, y + limit):\n#             totalSoFar += matrix[xLimit][j]\n\n#         # debug(x=x, y=y, limit=limit, totalSoFar=totalSoFar)\n\n#         if totalSoFar == refTotal:\n#             return True\n\n#         if totalSoFar > refTotal:\n#             return False\n\n#     return False\n\ndef runATest(_testIndex):\n\n [count, refTotal] = [int(x) for x in input().split()]\n\n aList = [int(x) for x in input().split()]\n factors = findFactors(refTotal, count)\n debug(factors=factors)\n\n total = 0\n for factor in factors:\n  total += countSquaresOfSize(aList, refTotal, count, factor)\n return total\n\ndef findFactors(refTotal, maxFactor):\n\n outList = [1]\n\n for i in range(2, int(refTotal/2)+1):\n  if i > maxFactor:\n   break\n  if refTotal % i == 0:\n   outList.append(i)\n\n if refTotal <= maxFactor:\n  outList.append(refTotal)\n\n return outList\n\ndef countSquaresOfSize(aList, refTotal, count, size):\n\n reqTotal = int(refTotal / size)\n maxLen = count + 1 - size\n total = 0\n\n for i in range(maxLen):\n  for j in range(maxLen):\n   if countSquaresAtPointOfSize(aList, reqTotal, size, i, j):\n    total += 1\n\n debug('completed size', size=size, total=total)\n return total\n\ndef countSquaresAtPointOfSize(aList, reqTotal, size, i, j):\n\n total = 0\n\n for k in range(size):\n  total += aList[i + k] + aList[j + k]\n\n debug(i=i, j=j, size=size, total=total, reqTotal=reqTotal)\n return total == reqTotal\n\nmain()\n"
_co = compile(_CODE, USER_FILENAME, "exec")
exec(_co, ns, ns)

```

Measured memory_bytes: 365811