<p>Given an array of <code>points</code> where <code>points[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> represents a point on the <strong>X-Y</strong> plane, return <em>the maximum number of points that lie on the same straight line</em>.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2021/02/25/plane1.jpg" style="width: 300px; height: 294px;" />
<pre>
<strong>Input:</strong> points = [[1,1],[2,2],[3,3]]
<strong>Output:</strong> 3
</pre>

<p><strong class="example">Example 2:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2021/02/25/plane2.jpg" style="width: 300px; height: 294px;" />
<pre>
<strong>Input:</strong> points = [[1,1],[3,2],[5,3],[4,1],[2,3],[1,4]]
<strong>Output:</strong> 4
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>1 &lt;= points.length &lt;= 300</code></li>
	<li><code>points[i].length == 2</code></li>
	<li><code>-10<sup>4</sup> &lt;= x<sub>i</sub>, y<sub>i</sub> &lt;= 10<sup>4</sup></code></li>
	<li>All the <code>points</code> are <strong>unique</strong>.</li>
</ul>

from math import gcd
class Solution:
    def maxPoints(self, points: List[List[int]]) -> int:
        if len(points)==1: return 1
        d,d2,dv = set(),set(),set()
        points.sort(key=lambda x:x[0])
        for i,c1 in enumerate(points):
            for j,c2 in enumerate(points[i+1:]):
                x1,y1 = c1
                x2,y2 = c2
                if x1==x2: d.add(x1)
                if y1==y2: d2.add(y1)
                if x1!=x2 and y1!=y2:

                    dx,dy = (x2-x1)//gcd(x2-x1,y2-y1), (y2-y1)//gcd(x2-x1,y2-y1)
                    if dx<0 and dy<0: dx *= -1; dy *= -1
                    fac = x1//dx
                    dv.add((dx,dy,x1-dx*fac,y1-dy*fac))
        d3 = {}
        for x,y in points:
            if x in d: d3[(x,"x")] = d3.get((x,"x"),0)+1
            if y in d2: d3[(y,"y")] = d3.get((y,"y"),0)+1
            for dx,dy,ix,iy in dv:
                if x==ix and y==iy: d3[(dx,dy,ix,iy)] = d3.get((dx,dy,ix,iy),0)+1
                else:
                    cx,cy = (x-ix)/gcd(x-ix,y-iy), (y-iy)/gcd(x-ix,y-iy)
                    if cx<0: cx *= -1; cy *= -1
                    if cx==dx and cy==dy: d3[(dx,dy,ix,iy)] = d3.get((dx,dy,ix,iy),0)+1
        print(d3)
        return max(d3.values())
30865