After failing to clear his school mathematics examination, infinitepro decided to prepare very hard for his upcoming re-exam, starting with the topic he is weakest at ― computational geometry.
Being an artist, infinitepro has C$C$ pencils (numbered 1$1$ through C$C$); each of them draws with one of C$C$ distinct colours. He draws N$N$ lines (numbered 1$1$ through N$N$) in a 2D Cartesian coordinate system; for each valid i$i$, the i$i$-th line is drawn with the ci$c_i$-th pencil and it is described by the equation y=ai⋅x+bi$y = a_i \cdot x + b_i$.
Now, infinitepro calls a triangle truly-geometric if each of its sides is part of some line he drew and all three sides have the same colour. He wants to count these triangles, but there are too many of them! After a lot of consideration, he decided to erase a subset of the N$N$ lines he drew. He wants to do it with his eraser, which has length K$K$.
Whenever erasing a line with a colour i$i$, the length of the eraser decreases by Vi$V_i$. In other words, when the eraser has length k$k$ and we use it to erase a line with a colour i$i$, the length of the eraser decreases to k−Vi$k-V_i$; if k<Vi$k < V_i$, it is impossible to erase such a line.
Since infinitepro has to study for the re-exam, he wants to minimise the number of truly-geometric triangles. Can you help him find the minimum possible number of truly-geometric triangles which can be obtained by erasing a subset of the N$N$ lines in an optimal way? He promised a grand treat for you if he passes the examination!

-----Input-----
- The first line of the input contains a single integer T$T$ denoting the number of test cases. The description of T$T$ test cases follows.
- The first line of the input contains three space-separated integers N$N$, C$C$ and K$K$.
- N$N$ lines follow. For each i$i$ (1≤i≤N$1 \le i \le N$), the i$i$-th of these lines contains three space-separated integers ai$a_i$, bi$b_i$ and ci$c_i$.
- The last line contains C$C$ space-separated integers V1,V2,…,VC$V_1, V_2, \ldots, V_C$.

-----Output-----
For each test case, print a single line containing one integer ― the smallest possible number of truly-geometric triangles after erasing lines.

-----Constraints-----
- 1≤T≤10$1 \le T \le 10$
- 1≤C≤N≤3,000$1 \le C \le N \le 3,000$
- 0≤K≤3,000$0 \le K \le 3,000$
- 0≤ai,bi≤109$0 \le a_i, b_i \le 10^9$ for each valid i$i$
- 1≤ci≤C$1 \le c_i \le C$ for each valid i$i$
- 0≤Vi≤K$0 \le V_i \le K$ for each valid i$i$
- no two lines coincide, regardless of their colours
- no three lines are concurrent

-----Subtasks-----
Subtask #1 (10 points):
- N≤10$N \le 10$
- K≤100$K \le 100$
Subtask 2 (15 points):
- V1=V2=…=VC$V_1 = V_2 = \ldots = V_C$
- no two lines are parallel
Subtask #3 (25 points): no two lines are parallel
Subtask #4 (50 points): original constraints

-----Example Input-----
2
7 2 13
1 10 1
1 14 2
6 4 1
2 2 1
0 12 2
2 11 2
0 6 1
8 10
6 1 20
1 5 1
2 11 1
4 0 1
6 8 1
0 11 1
3 3 1
9

-----Example Output-----
2
4

-----Explanation-----
Example case 1: We can remove exactly one line. Initially, we have 5$5$ truly geometric triangles (see the image below; red is colour 1$1$ and green is colour 2$2$).
- Removing any line with colour 2$2$ brings the total number of truly-geometric triangles down to 4+0=4$4+0=4$.
- Removing any line with colour 1$1$ brings the total number of truly-geometric triangles down to 1+1=2$1+1=2$.
Thus, the smallest number of truly-geometric triangles we can obtain is 2$2$.

Example case 2: We can remove at most 2$2$ lines and removing any 2$2$ lines gives us a total of 4$4$ truly-geometric triangles.

```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 = 'import copy\r\ndef calprofit(lines_removed,j ):\r\n    \r\n    lines_set=copy.deepcopy(differentline[j])\r\n    #print("chk", lines_set)\r\n    iterator=0\r\n    \r\n    while(iterator<len(lines_set) and lines_removed>0):\r\n        \r\n        possible=min(lines_set[iterator],lines_removed)\r\n        lines_set[iterator]=lines_set[iterator]-possible\r\n        lines_removed=lines_removed-possible\r\n        iterator=iterator+1\r\n                \r\n                \r\n        ## if lines_removed still remains after deleting all  the lines then no triangle possible\r\n                \r\n    if(lines_removed>0):\r\n        return 0\r\n    sum1=0\r\n    for iterator1 in range(len(lines_set)):\r\n        sum1=sum1+lines_set[iterator1]\r\n    sum2=0\r\n    temp=[0]*(len(lines_set)+1)\r\n    for iterator2 in range(len(lines_set)):\r\n        temp[iterator2] = lines_set[iterator2]*(sum1-lines_set[iterator2])\r\n        sum2=sum2+temp[iterator2]\r\n    sum2=sum2//2\r\n    sum3=0\r\n    for iterator3 in range(len(lines_set)):\r\n        sum3 =sum3+ lines_set[iterator3]*(sum2-temp[iterator3])\r\n    sum3=sum3//3\r\n    #print(sum3)\r\n    return sum3\r\n\r\nfor i in range(int(input())):\r\n    n,c,k=[int(i) for i in input().split()]\r\n    color=[]\r\n    for i in range(c+1):\r\n        color.append(dict())\r\n    for i in range(n):\r\n        a,b,co=[int(i) for i in input().split()]\r\n        if(color[co].get(a,0)):\r\n            color[co][a]=color[co][a]+1\r\n        else:\r\n            color[co][a]=1\r\n    differentline=[]\r\n    for i in color:\r\n        chk=list(i.values())\r\n        chk.sort()\r\n        differentline.append(chk)\r\n    \r\n    \r\n    #print(differentline)\r\n    \r\n    \r\n    weight=[0]+[int(i) for i in input().split()]\r\n    \r\n    ##  KNAPSACK   ##\r\n    profit=[]\r\n    dp=[]\r\n    \r\n    for i in range(k+1):\r\n        profitdemo=[]\r\n        dpdemo=[]\r\n        for j in range(c+1):\r\n            profitdemo.append(-1)\r\n            \r\n            if(j==0):\r\n                dpdemo.append(0)\r\n            else:\r\n                dpdemo.append((10**20)+7)\r\n        profit.append(profitdemo)    \r\n        dp.append(dpdemo)\r\n \r\n    \r\n    for i in range(k+1):\r\n        for j in range(1,c+1):\r\n            removable_item=i//weight[j]\r\n            for lines_removed in range(removable_item+1):\r\n                demo=lines_removed*weight[j]\r\n                \r\n                ##    calculting profit  ## after removing lines_removed number of lines from color of j\r\n                if(profit[lines_removed][j]==-1):\r\n                    profit[lines_removed][j] = calprofit(lines_removed,j)\r\n                \r\n                dp[i][j] = min(dp[i][j] , dp[i-demo][j-1] + profit[lines_removed][j] )\r\n    print(dp[k][c])\r\n                \r\n                \r\n                \r\n                \r\n                \r\n                \r\n                \r\n                \r\n                \r\n                \r\n                \r\n                \r\n                \r\n                \r\n                \r\n                \r\n                \r\n                \r\n                \r\n                '
_co = compile(_CODE, USER_FILENAME, "exec")
exec(_co, ns, ns)

```

Measured memory_bytes: 178559