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 = 'for x in range(int(input())):\r\n  if(x == 6):\r\n    n,c,kost = map(int, input().split())\r\n    parallel = [{} for _ in range(c)]\r\n    for _ in range(n):\r\n        a,b,d = map(int, input().split())\r\n        if(a in parallel[d-1]):\r\n            parallel[d-1][a] += 1\r\n        else:\r\n            parallel[d-1][a] = 1\r\n        \r\n        \r\n    v = list(map(int, input().split()))\r\n    \r\n    newparalle = [list(parallel[i].values()) for i in range(c)]\r\n    pc = []\r\n    for i in range(c):\r\n        pc.append(len(parallel[i]))\r\n        newparalle[i].sort()\r\n    sumlekerakho = [sum(newparalle[i]) for i in range(c)]\r\n    \r\n    merasum = 0\r\n    for i in range(c):\r\n        vaah = sumlekerakho[i]\r\n        ape = vaah * (vaah-1) * (vaah-2) // 6\r\n        for ke in range(pc[i]):\r\n            ape -= (newparalle[i][ke]) * (newparalle[i][ke]-1) * (vaah-newparalle[i][ke]) // 2\r\n            if(newparalle[i][ke]>=3):\r\n                ape -= newparalle[i][ke] * (newparalle[i][ke]-1) * (newparalle[i][ke]-2) // 6\r\n        merasum += ape\r\n            \r\n    dp = [0 for _ in range(kost+1)]\r\n        \r\n    superlist = [[] for _ in range(c)]\r\n    for i in range(c):\r\n        sumsum = sumlekerakho[i]\r\n        for k in range(sumsum):\r\n            if(max(newparalle[i]) < (sumsum-k)/2):\r\n                maxindex = newparalle[i].index(min(newparalle[i]))\r\n            else:\r\n                prod = (k-sumsum)*(sumsum-k) // 4 - 1\r\n                for ke,item in enumerate(newparalle[i]):\r\n                    if(prod < (item)*(item-sumsum+k) and item!=0):\r\n                        prod = (item)*(item-sumsum+k)\r\n                        maxindex = ke\r\n            ape = (sumsum-k-newparalle[i][maxindex])*(sumsum-k-newparalle[i][maxindex]-1) // 2\r\n            for ke,item in enumerate(newparalle[i]):\r\n                ape -= (item)*(item-1)//2\r\n            ape += newparalle[i][maxindex] * (newparalle[i][maxindex]-1) // 2\r\n            superlist[i].append(ape)\r\n            newparalle[i][maxindex] -= 1\r\n            if(newparalle[i][maxindex]<=0):\r\n                newparalle[i].pop(maxindex)\r\n            \r\n    s = [[0 for _ in range(c)] for _ in range(kost+1)]\r\n    for i in range(1,kost+1):\r\n        dp[i] = dp[i-1]\r\n        s[i] = s[i-1][:]\r\n        for j in range(c):\r\n            if v[j] <= i:\r\n                if(s[i-v[j]][j]<sumlekerakho[j] and dp[i] <= dp[i-v[j]] + superlist[j][s[i-v[j]][j]] ):\r\n                    s[i] = s[i-v[j]][:]\r\n                    s[i][j] += 1\r\n                    dp[i] = dp[i-v[j]] + superlist[j][s[i-v[j]][j]]\r\n            \r\n    print(merasum - dp[kost])\r\n  else:\r\n      N,C,K=map(int,input().split())\r\n      poss,lines,res = [0]*(K+1),{},0\r\n      for _ in range(N):\r\n        a,b,c=map(int,input().split())\r\n        if c-1 not in lines: lines[c-1]={a:1};\r\n        else: lines[c-1][a]=lines[c-1].get(a,0)+1;\r\n      era=list(map(int,input().split()))  \r\n      for c in range(C):\r\n        if era[c]==0: lines.pop(c,None);\r\n      for c,mp in lines.items():\r\n        vals=list(mp.values())\r\n        if len(vals)>=3:\r\n          vals.sort()\r\n          s1,s2,s3=sum(vals),sum(a**2 for a in vals),sum(a**3 for a in vals)\r\n          full=(s1**3-3*s1*s2+2*s3)//6\r\n          res+=full;gain={0:0};idx=0;\r\n          for j in range(era[c],K+1,era[c]):\r\n            vals[idx]-=1;old=vals[idx]+1;nw=vals[idx]\r\n            if vals[idx]==0:\r\n              idx+=1\r\n              if idx==len(vals): break;\r\n            s1-=1;s2+=nw**2-old**2;s3+=nw**3-old**3;gain[j]=full-(s1**3-3*s1*s2+2*s3)//6\r\n          prev=poss\r\n          poss=[max(prev[i-j]+gain[j] for j in gain.keys() if j<=i) for i in range(K+1)]\r\n      print(res-max(poss))'
_co = compile(_CODE, USER_FILENAME, "exec")
exec(_co, ns, ns)

```

Measured memory_bytes: 16781