human
Write me a Python program to print a single integer — the number of pairs of wires that are intersecting given the following:
Solve in Python:
This problem is same as the previous one, but has larger constraints.

It was a Sunday morning when the three friends Selena, Shiro and Katie decided to have a trip to the nearby power station (do not try this at home). After arriving at the power station, the cats got impressed with a large power transmission system consisting of many chimneys, electric poles, and wires. Since they are cats, they found those things gigantic.

At the entrance of the station, there is a map describing the complicated wiring system. Selena is the best at math among three friends. He decided to draw the map on the Cartesian plane. Each pole is now a point at some coordinates $(x_i, y_i)$. Since every pole is different, all of the points representing these poles are distinct. Also, every two poles are connected with each other by wires. A wire is a straight line on the plane infinite in both directions. If there are more than two poles lying on the same line, they are connected by a single common wire.

Selena thinks, that whenever two different electric wires intersect, they may interfere with each other and cause damage. So he wonders, how many pairs are intersecting? Could you help him with this problem?

-----Input-----

The first line contains a single integer $n$ ($2 \le n \le 1000$) — the number of electric poles.

Each of the following $n$ lines contains two integers $x_i$, $y_i$ ($-10^4 \le x_i, y_i \le 10^4$) — the coordinates of the poles.

It is guaranteed that all of these $n$ points are distinct.

-----Output-----

Print a single integer — the number of pairs of wires that are intersecting.

-----Examples-----
Input
4
0 0
1 1
0 3
1 2

Output
14

Input
4
0 0
0 2
0 4
2 0

Output
6

Input
3
-1 -1
1 0
3 1

Output
0


-----Note-----

In the first example:

 [Image] 

In the second example:

 [Image] 

Note that the three poles $(0, 0)$, $(0, 2)$ and $(0, 4)$ are connected by a single wire.

In the third example:

 [Image]
assistant
#Here is Python program to print a single integer — the number of pairs of wires that are intersecting.

from math import *

class slopeC:
    def __init__(self):        
        self.chil = set()
n = int(input())

slopes = {}
L = []
for i in range(n):
    x, y = list(map(int, input().split()))
    
    for l in L:
        if x != l[0]:
            slope = (y - l[1]) / (x - l[0])
        else:
            slope = inf
            
        s1 = str(l[0]) + '-' + str(l[1])
        s2 = str(x) + '-' + str(y)
        if slope not in slopes:
            slopes[slope] = [slopeC()]
            slopes[slope][0].chil.add(s1)
            slopes[slope][0].chil.add(s2)
        else:
            f = 0
            for child in slopes[slope]:
                if s1 in child.chil:
                    f = 1
                    child.chil.add(s2)
                    break
            if f == 0:
                slopes[slope] += [slopeC()]
                slopes[slope][0].chil.add(s1)
                slopes[slope][0].chil.add(s2)
        
    L += [[x, y]]
A = []
P = [0]
for s in slopes:
    A += [(len(slopes[s]))]
    P += [P[-1] + A[-1]]
    
ans = 0

for i, v in enumerate(A):
    ans += A[i] * (P[-1] - P[i+1])
print(ans)