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]

Difficulty: interview

Starter code:

Solutions:
#Bhargey Mehta (Sophomore)
#DA-IICT, Gandhinagar
import sys, math, queue
#sys.stdin = open("input.txt", "r")
MOD = 10**9+7

n = int(input())
p = []
for i in range(n):
    x, y = map(int, input().split())
    p.append((x, y))

d = {}

for i in range(n):
    x1, y1 = p[i]
    for j in range(i+1, n):
        x2, y2 = p[j]
        if x1 != x2:  
            m = (y2-y1)/(x2-x1)
            c = (y1*x2-x1*y2)/(x2-x1)
        else:
            m = 10**10
            c = x1
        if m in d:
            if c in d[m]:
                d[m][c] += 1
            else:
                d[m][c] = 1
        else:
            d[m] = {c: 1}

p = []
for m in d:
    p.append(len(d[m]))
s = sum(p)
ans = 0
for x in p:
    ans += x*(s-x)
print(ans//2)

import itertools
import math
from functools import reduce
from math import gcd

# 2d line: ax + by + c = 0  is  (a, b, c)

#          ax + by + c = 0     ((a, b, c),
# 3d line: dx + ez + f = 0  is  (d, e, f),
#          gy + hz + i = 0      (g, h, i))

gcdm = lambda *args: reduce(gcd, args, 0)


def pointsToLine2d(p1, p2):
    if p1 == p2:
        return (0, 0, 0)
    _p1, _p2 = sorted((p1, p2))

    g = gcdm(*[x for x in (_p2[1] - _p1[1], _p1[0] - _p2[0], _p1[1] * _p2[0] - _p1[0] * _p2[1]) if x != 0])

    return ((_p2[1] - _p1[1]) // g, (_p1[0] - _p2[0]) // g, (_p1[1] * _p2[0] - _p1[0] * _p2[1]) // g)


dist = lambda p1, p2: sum((a - b) * (a - b) for a, b in zip(p1, p2))**0.5

pointsToLines = lambda p1, p2: list(map(pointsToLine2d, itertools.combinations(p1, 2), itertools.combinations(p2, 2)))

areParallel = lambda l1, l2: l1[0] * l2[1] == l2[0] * l1[1]

areSame = lambda l1, l2: areParallel(l1, l2) and (l1[1] * l2[2] == l2[1] * l1[2])

collinear = lambda p1, p2, p3: areSame(pointsToLine2d(p1, p2), pointsToLine2d(p2, p3))

intersect = lambda l1, l2: None if areParallel(l1, l2) else ((l2[1] * l1[2] - l1[1] * l2[2]) / (l2[0] * l1[1] - l1[
    0] * l2[1]), (l1[0] * l2[2] - l1[2] * l2[0]) / (l2[0] * l1[1] - l1[0] * l2[1]))

rotate = lambda p, theta, origin=(0, 0): (origin[0] + (p[0] - origin[0]) * math.cos(theta) - (p[1] - origin[
    1]) * math.sin(theta), origin[1] + (p[0] - origin[0]) * math.sin(theta) + (p[1] - origin[1]) * math.cos(theta))


def main():
    from sys import stdin, stdout

    def read():
        return stdin.readline().rstrip('\n')

    def read_array(sep=None, maxsplit=-1):
        return read().split(sep, maxsplit)

    def read_int():
        return int(read())

    def read_int_array(sep=None, maxsplit=-1):
        return [int(a) for a in read_array(sep, maxsplit)]

    def write(*args, **kwargs):
        sep = kwargs.get('sep', ' ')
        end = kwargs.get('end', '\n')
        stdout.write(sep.join(str(a) for a in args) + end)

    def write_array(array, **kwargs):
        sep = kwargs.get('sep', ' ')
        end = kwargs.get('end', '\n')
        stdout.write(sep.join(str(a) for a in array) + end)

    n = read_int()
    p = []
    for _ in range(n):
        p.append(read_int_array())

    lines = set()
    for i in range(n):
        for j in range(i+1, n):
            lines.add(pointsToLine2d(p[i], p[j]))

    k = len(lines)
    import collections
    ax_bx = collections.defaultdict(int)
    out = 0
    for a, b, _ in lines:
        ax_bx[a, b] += 1
    for x in list(ax_bx.values()):
        out += (k - x) * x
    write(out // 2)

main()


from collections import defaultdict as dd
from itertools import combinations
import math
import heapq
def nn():
	return int(input())

def li():
	return list(input())

def mi():
	return list(map(int, input().split()))

def lm():
	return list(map(int, input().split()))



n=nn()

points=[]

for i in range(n):
	points.append(lm())



slopedict=dd(set)
lines=0

for p1, p2 in combinations(points,2):
	x1,y1=p1
	x2,y2=p2


	g=math.gcd(y2-y1,x2-x1)
	if y2-y1<0:
		sign=-1

	elif y2-y1==0:
		if x2-x1<0:
			sign=-1
		else:

			sign=1

	else:
		sign=1
	slope=(sign*(y2-y1)//g,sign*(x2-x1)//g) 
	

	if not slope[1]==0:
		ceptn=slope[1]*y1-slope[0]*x1
		ceptd=slope[1]

		if ceptn<0:
			sign=-1
		
		elif ceptn==0:
			if ceptd<0:
				sign=-1
			else:

				sign=1

		else:
			sign=1
		
		g=math.gcd(ceptn,ceptd)
		cept=(sign*ceptn/g,sign*ceptd/g)
	else:
		cept=x1



	if not cept in slopedict[slope]:
		slopedict[slope].add(cept)
		lines+=1

total=0


for slope in slopedict:

	total=total+(lines-len(slopedict[slope]))*len(slopedict[slope])


print(total//2)	

pos=math.gcd(-4,2)
neg=math.gcd(4,-2)
#print(pos,neg)

#print(-4//pos,2//pos)

#print(4//neg,-2//neg)
	



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)


    


from collections import Counter
N = int(input())
if N == 2:
    print(0)
    return
inf = 10**9+7
inf2 = 10**18
def gcdl(A):
    if len(A) == 0:
        return -1
    if len(A) == 1:
        return 0
    g = gcd(A[0], A[1])
    for a in A[2:]:
        g = gcd(a, g)
    return g
def gcd(a,b):
    if b == 0:
        return a
    return gcd(b,a%b)
Point = []
ans = 0
for _ in range(N):
    Point.append(list(map(int, input().split())))
S = Counter()
T = set()
for i in range(N):
    x1 , y1 = Point[i]
    for j in range(N):
        if i == j:
            continue
        x2 , y2 = Point[j]
        a = y1 - y2
        b = -(x1 - x2)
        c = x2*y1 - x1*y2
        g = gcdl([a, b, c])
        a //= g
        b //= g
        c //= g
        if a < 0:
            a *= -1
            b *= -1
            c *= -1
        k = a*inf+b*inf2+c
        if k not in T:
            T.add(a*inf+b*inf2+c)
            if x1 == x2:
                S[-1] += 1
            else:
                y = y1 - y2
                x = x1 - x2
                g = gcd(y, x)
                y //= g
                x //= g
                if y < 0:
                    y *= -1
                    x *= -1
                S[y*inf+x] += 1
L = len(T)
ans = L*(L-1)//2
for s in S.values():
    ans -= s*(s-1)//2
print(ans)

from math import gcd

n = int(input())
P = [[int(x) for x in input().split()] for _ in range(n)]

L = []
def addLine(x,y,dx,dy):
    if dx < 0:
        dx *= -1
        dy *= -1
    elif dx == 0:
        if dy < 0:
            dy *= -1
    g = gcd(dx,dy)
    dx //= g
    dy //= g

    x += dx * (10**9)
    y += dy * (10**9)
    if dx:
        k = x//dx
    else:
        k = y//dy
    x -= k*dx
    y -= k*dy
    L.append((x,y,dx,dy))


for i in range(n):
    for j in range(i+1,n):
        xi,yi = P[i]
        xj,yj = P[j]
        dx,dy = xi-xj,yi-yj
        addLine(xi,yi,dx,dy)

from collections import defaultdict as dd, deque

L = list(set(L))
res = 0

C = dd(int)
for x,y,dx,dy in L:
    C[dx,dy] += 1

ss = sum(C.values())

for x in list(C.values()):
    res += (ss-x)*x

#for i in range(len(L)):
#    for j in range(i+1, len(L)):
#        x1,y1,dx1,dy1 = L[i]
#        x2,y2,dx2,dy2 = L[j]
#        if dx1 != dx2 or dy1 != dy2:
#            #print(L[i])
#            #print(L[j])
#            #print('---')
#            res += 1

print(res//2)








n = int(input())
l = set()
s = [list(map(int, input().split())) for _ in range(n)]
for i in range(n):
        for j in range(i+1, n):
                x1, y1 = s[i]
                x2, y2 = s[j]
                if x1==x2: 
                        l.add((float('INF'), x1))
                else:
                        a = (y1-y2)/(x1-x2)
                        b = (x1*y2-x2*y1)/(x1-x2)
                        l.add((a, b))
lis = [i[0] for i in l]
from collections import Counter
dic = Counter(lis)
r = len(l)**2 - len(l)
for i in dic:
        r -= dic[i]**2-dic[i]
print(r//2)


n=int(input().strip())
num=[]
for k in range(n):
    num.append(list(map(int,input().strip().split())))
d={}
import math
for k in range(n):
    for kk in range(k+1,n):
        a=num[k]
        b=num[kk]
        if(a[0]==b[0]):
            if((100000,100000) in d.keys()):
                d[(100000,100000)].add(a[0])
            else:
                d[(100000, 100000)]={a[0]}
        elif(a[1]==b[1]):
            if(0,1) in d.keys():
                d[(0,1)].add(a[1])
            else:
                d[(0,1)]={a[1]}
        else:
            c=b[1]-a[1]
            dd=b[0]-a[0]
            q=math.gcd(c,dd)
            c1=c//q
            d1=dd//q
            r=(a[0]*b[1])-(a[1]*b[0])
            if(r!=0):
                rr=math.gcd(r,dd)
                r=r//rr
                d2=dd//rr
                if(d2<0):
                    d2=-d2
                    r=-r
                if(d1<0):
                    d1=-d1
                    c1=-c1
                if((c1,d1) in d.keys() ):
                    d[(c1,d1)].add((r,d2))
                else:
                    d[(c1,d1)]={(r,d2)}
            else:
                if (d1 < 0):
                    d1 = -d1
                    c1 = -c1
                if ((c1, d1) in d.keys()):
                    d[(c1, d1)].add((0,1))
                else:
                    d[(c1, d1)] = {(0,1)}
s=0
for i in d.keys():
    s=s+(len(d[i]))
ss=0
for i in d.keys():
    s=s-(len(d[i]))
    ss=ss+(s*len(d[i]))
print(ss)

n = int(input())
T = []
P = []
for i in range(n):
    x, y = map(int, input().split())
    T.append([x, y])
for i in range(n):
    for j in range(i + 1, n):
        x1, y1 = T[i]
        x2, y2 = T[j]
        a = y2 - y1
        b = x1 - x2
        c = -(a * x1 + b * y1)
        if a != 0:
            b /= a
            c /= a
            a = 1
        else:
            a = 0
            c /= b
            b = 1
        P.append([a, b, c])
P.sort()
newp = [P[0]]
for i in range(len(P) - 1):
    if P[i] != P[i + 1]:
        newp.append(P[i + 1])
P = newp
was = []
sos = dict()
for a, b, c in P:
    if b != 0 and a != 0:
        z = a / b
    elif a == 0:
        z = 'kek'
    else:
        z = 'lol'
    if z not in sos:
        sos[z] = 1
    else:
        sos[z] += 1
sus = 0
sussqua = 0
for i in sos:
    sus += sos[i]
    sussqua += sos[i] ** 2
print((sus ** 2 - sussqua) // 2)

n = int(input())
T = []
P = []
for i in range(n):
    x, y = map(int, input().split())
    T.append([x, y])
for i in range(n):
    for j in range(i + 1, n):
        x1, y1 = T[i]
        x2, y2 = T[j]
        a = y2 - y1
        b = x1 - x2
        c = -(a * x1 + b * y1)
        if a != 0:
            b /= a
            c /= a
            a = 1
        else:
            a = 0
            c /= b
            b = 1
        P.append([a, b, c])
P.sort()
newp = [P[0]]
for i in range(len(P) - 1):
    if P[i] != P[i + 1]:
        newp.append(P[i + 1])
P = newp
sos = dict()
for a, b, c in P:
    if b != 0 and a != 0:
        z = a / b
    elif a == 0:
        z = 'kek'
    else:
        z = 'lol'
    if z not in sos:
        sos[z] = 1
    else:
        sos[z] += 1
sus = 0
sussqua = 0
for i in sos:
    sus += sos[i]
    sussqua += sos[i] ** 2
print((sus ** 2 - sussqua) // 2)

import sys
import math
from pprint import pprint

n = int(input())
p = [list(map(int, input().split())) for i in range(n)]
p.sort()
s = {}
for i in range(n):
    x1, y1 = p[i]
    for j in range(i + 1, n):
        x2, y2 = p[j]
        slope = 0
        cons = 0
        if x1 - x2 == 0:
            slope = sys.maxsize
            cons = x1
        else:
            slope = (y2 - y1) / (x2 - x1)
            cons = (y1 * x2 - x1 * y2) / (x2 - x1)
        if slope in s:
            if cons in s[slope]:
                s[slope][cons] += 1
            else:
                s[slope][cons] = 1
        else:
            s[slope] = {cons: 1}
ans = 0
cnt = 0

for x in s:
    ans += cnt * len(s[x])
    cnt += len(s[x])
print(ans)


import sys
import collections
import math
import heapq
from operator import itemgetter

def getint():
    return int(input())

def getints():
    return [int(x) for x in input().split(' ')]

n = getint()
points = [tuple(getints()) for _ in range(n)]
result = total = 0

slopes = collections.defaultdict(set)
for i in range(n - 1):
    for j in range(i + 1, n):
        x1, y1, x2, y2 = points[i][0], points[i][1], points[j][0], points[j][1]
        a, b = y1 - y2, x1 - x2

        d = math.gcd(a, b)
        a, b = a // d, b // d
        if a < 0 or (a == 0 and b < 0):
            a, b = -a, -b
        
        c = a * x1 - b * y1
        slope = (a, b)
        if c not in slopes[slope]:
            total += 1
            slopes[slope].add(c)
            result += total - len(slopes[slope])

print(str(result))

# AC
import sys
from math import gcd


class Main:
    def __init__(self):
        self.buff = None
        self.index = 0

    def __next__(self):
        if self.buff is None or self.index == len(self.buff):
            self.buff = self.next_line()
            self.index = 0
        val = self.buff[self.index]
        self.index += 1
        return val

    def next_line(self):
        return sys.stdin.readline().split()

    def next_ints(self):
        return [int(x) for x in sys.stdin.readline().split()]

    def next_int(self):
        return int(next(self))

    def solve(self):
        n = self.next_int()
        pr = [(self.next_int(), self.next_int()) for _ in range(0, n)]
        ks = {}
        ct = 0
        res = 0
        ls = set()
        for i in range(0, n):
            for j in range(i + 1, n):
                dy = pr[j][1] - pr[i][1]
                dx = pr[j][0] - pr[i][0]
                if dx < 0:
                    dx *= -1
                    dy *= -1
                elif dx == 0:
                    dy = abs(dy)
                g = gcd(abs(dx), abs(dy))
                k = (dx // g, dy // g)
                x, y = pr[i][0], pr[i][1]
                if dx == 0:
                    a = (pr[i][0], 0)
                else:
                    cl = abs(x) // k[0]
                    if x >= 0:
                        x -= cl * k[0]
                        y -= cl * k[1]
                    else:
                        x += cl * k[0]
                        y += cl * k[1]
                        while x < 0:
                            x += k[0]
                            y += k[1]
                    a = (x, y)
                if (k, a) in ls:
                    continue
                else:
                    ls.add((k, a))
                ct += 1
                if k not in ks:
                    ks[k] = 1
                else:
                    ks[k] += 1
                res += ct - ks[k]
        print(res)


def __starting_point():
    Main().solve()

__starting_point()

from functools import reduce
from math import gcd
import collections

gcdm = lambda *args: reduce(gcd, args, 0)


def pointsToLine2d(p1, p2):
    if p1 == p2:
        return (0, 0, 0)
    _p1, _p2 = sorted((p1, p2))
    g = gcdm(*[x for x in (_p2[1] - _p1[1], _p1[0] - _p2[0], _p1[1] * _p2[0] - _p1[0] * _p2[1]) if x != 0])
    return ((_p2[1] - _p1[1]) // g, (_p1[0] - _p2[0]) // g, (_p1[1] * _p2[0] - _p1[0] * _p2[1]) // g)


def main():
    from sys import stdin, stdout

    def read():
        return stdin.readline().rstrip('\n')

    def read_array(sep=None, maxsplit=-1):
        return read().split(sep, maxsplit)

    def read_int():
        return int(read())

    def read_int_array(sep=None, maxsplit=-1):
        return [int(a) for a in read_array(sep, maxsplit)]

    def write(*args, **kwargs):
        sep = kwargs.get('sep', ' ')
        end = kwargs.get('end', '\n')
        stdout.write(sep.join(str(a) for a in args) + end)

    def write_array(array, **kwargs):
        sep = kwargs.get('sep', ' ')
        end = kwargs.get('end', '\n')
        stdout.write(sep.join(str(a) for a in array) + end)

    n = read_int()
    p = []
    for _ in range(n):
        p.append(read_int_array())

    lines = set()
    for i in range(n):
        for j in range(i+1, n):
            lines.add(pointsToLine2d(p[i], p[j]))

    k = len(lines)
    ax_bx = collections.defaultdict(int)
    out = 0
    for a, b, _ in lines:
        ax_bx[a, b] += 1
    for x in list(ax_bx.values()):
        out += (k - x) * x
    write(out // 2)

main()


from functools import reduce
from math import gcd
import collections

gcdm = lambda *args: reduce(gcd, args, 0)


def pointsToLine2d(p1, p2):
    if p1 == p2:
        return 0, 0, 0
    p1, p2 = sorted((p1, p2))
    a, b, c = p2[1] - p1[1], p1[0] - p2[0], p1[1] * p2[0] - p1[0] * p2[1]
    g = gcdm(*[x for x in (a, b, c) if x != 0])
    return a // g, b // g, c // g


def main():
    from sys import stdin, stdout

    def read():
        return stdin.readline().rstrip('\n')

    def read_array(sep=None, maxsplit=-1):
        return read().split(sep, maxsplit)

    def read_int():
        return int(read())

    def read_int_array(sep=None, maxsplit=-1):
        return [int(a) for a in read_array(sep, maxsplit)]

    def write(*args, **kwargs):
        sep = kwargs.get('sep', ' ')
        end = kwargs.get('end', '\n')
        stdout.write(sep.join(str(a) for a in args) + end)

    def write_array(array, **kwargs):
        sep = kwargs.get('sep', ' ')
        end = kwargs.get('end', '\n')
        stdout.write(sep.join(str(a) for a in array) + end)

    n = read_int()
    p = []
    for _ in range(n):
        p.append(read_int_array())

    lines = set()
    for i in range(n):
        for j in range(i+1, n):
            lines.add(pointsToLine2d(p[i], p[j]))

    k = len(lines)
    ax_bx = collections.defaultdict(int)
    out = 0
    for a, b, _ in lines:
        ax_bx[a, b] += 1
    for x in list(ax_bx.values()):
        out += (k - x) * x
    write(out // 2)

main()


from sys import stdin,stdout
import math
from itertools import accumulate


def getabc(x1,y1,x2,y2):
	t1=x2-x1;t2=y2-y1;t3=y1*x2-y2*x1
	if t1<0:
		t1=t1*(-1);t2=t2*(-1);t3=t3*(-1)
	t4=math.gcd(math.gcd(t1,t2),t3)
	return t1//t4,t2//t4,t3//t4

n=int(stdin.readline())
x=[];y=[]
for i in range(n):
	xi,yi=stdin.readline().strip().split(' ')
	x.append(int(xi));y.append(int(yi))

d={}
there={}
for i in range(len(x)):
	for j in range(i+1,len(x)):
		num=y[i]-y[j]
		den=x[i]-x[j]
		if num==0:
			key='yintercept'+str(y[i])
			if key not in d:
				d[key]=1
		elif den==0:
			key='xintercept'+str(x[i])
			if key not in d:
				d[key]=1
		else:
			a,b,c=getabc(x[i],y[i],x[j],y[j])
			key=str(a)+' '+str(b)+' '+str(c)
			keys=str(a)+' '+str(b)
			if key not in there:
				if keys in d:
					d[keys]+=1
				else:
					d[keys]=1
				there[key]=1


ansarr=[0,0] # [lines parallel to y-axis , lines parallel to x axis]
for i in d:
	if i[0]=='x':
		ansarr[0]+=1
	elif i[0]=='y':
		ansarr[1]+=1
	else:
		ansarr.append(d[i])

ans=0;
tarr=sum(ansarr)
for i in range(len(ansarr)):
	ans+=(tarr-ansarr[i])*ansarr[i]
stdout.write(str(ans//2)+'\n')










from collections import defaultdict
import math

n = int(input().lstrip())
numbers = []

for _ in range(n):
    numbers.append(list(map(int, input().lstrip().split())))


def gcd(a, b):
    if not a:
        return b
    return gcd(b % a, a)


slope_map = defaultdict(set)
total = 0
res = 0
for i in range(n):
    for j in range(i + 1, n):
        x1, y1 = numbers[i]
        x2, y2 = numbers[j]
        a = y1 - y2
        b = x1 - x2
        d = gcd(a, b)
        a //= d
        b //= d
        if a < 0 or (not a and b < 0):
            a *= -1
            b *= -1
        slope = (a, b)
        c = a * x1 - b * y1
        if c not in slope_map[slope]:
            total += 1
            slope_map[slope].add(c)
            res += total - len(slope_map[slope])
print(res)


from itertools import combinations

n = int(input())

points = []
for _ in range(n):
    x, y = list(map(int, input().split(' ')))
    points.append((x, y))

directions = {}
for pair in combinations(points, 2):
    (x1, y1), (x2, y2) = pair
    if x1 == x2:
        dir = (0, 1)
        b = x1
    else:
        dir = (1, (y2 - y1) / (x2 - x1))
        b = (y2 * x1 - x2 * y1) / (x1 - x2)

    if dir in directions:
        directions[dir].add(b)
    else:
        directions[dir] = set([b])

total_lines = sum(len(value) for key, value in list(directions.items()))

result = 0
for key, value in list(directions.items()):
    current = len(value)
    result += (total_lines - current) * current

print(int(result / 2))


def gcd(a,b):
    while b:
        a, b = b, a%b
    return a

n = int(input())
P = [[int(x) for x in input().split()] for _ in range(n)]

L = []
def addLine(x,y,dx,dy):
    if dx < 0:
        dx *= -1
        dy *= -1
    elif dx == 0:
        if dy < 0:
            dy *= -1
    g = gcd(dx,dy)
    dx //= g
    dy //= g

    x += dx * (10**9)
    y += dy * (10**9)
    if dx:
        k = x//dx
    else:
        k = y//dy
    x -= k*dx
    y -= k*dy
    L.append((x,y,dx,dy))


for i in range(n):
    for j in range(i+1,n):
        xi,yi = P[i]
        xj,yj = P[j]
        dx,dy = xi-xj,yi-yj
        addLine(xi,yi,dx,dy)

from collections import defaultdict as dd, deque

L = list(set(L))
res = 0

C = dd(int)
for x,y,dx,dy in L:
    C[dx,dy] += 1

ss = sum(C.values())

for x in C.values():
    res += (ss-x)*x

#for i in range(len(L)):
#    for j in range(i+1, len(L)):
#        x1,y1,dx1,dy1 = L[i]
#        x2,y2,dx2,dy2 = L[j]
#        if dx1 != dx2 or dy1 != dy2:
#            #print(L[i])
#            #print(L[j])
#            #print('---')
#            res += 1

print(res//2)

def gcd(a,b):
    if not b: return a
    return gcd(b, a%b)

n = int(input())
P = [[int(x) for x in input().split()] for _ in range(n)]

L = []
def addLine(x,y,dx,dy):
    if dx < 0:
        dx *= -1
        dy *= -1
    elif dx == 0:
        if dy < 0:
            dy *= -1
    g = gcd(dx,dy)
    dx //= g
    dy //= g

    x += dx * (10**9)
    y += dy * (10**9)
    if dx:
        k = x//dx
    else:
        k = y//dy
    x -= k*dx
    y -= k*dy
    L.append((x,y,dx,dy))


for i in range(n):
    for j in range(i+1,n):
        xi,yi = P[i]
        xj,yj = P[j]
        dx,dy = xi-xj,yi-yj
        addLine(xi,yi,dx,dy)

from collections import defaultdict as dd, deque

L = list(set(L))
res = 0

C = dd(int)
for x,y,dx,dy in L:
    C[dx,dy] += 1

ss = sum(C.values())

for x in C.values():
    res += (ss-x)*x

#for i in range(len(L)):
#    for j in range(i+1, len(L)):
#        x1,y1,dx1,dy1 = L[i]
#        x2,y2,dx2,dy2 = L[j]
#        if dx1 != dx2 or dy1 != dy2:
#            #print(L[i])
#            #print(L[j])
#            #print('---')
#            res += 1

print(res//2)

def gcd(a,b):
    if not b: return a
    return gcd(b, a%b)

n = int(input())
P = [[int(x) for x in input().split()] for _ in range(n)]

L = []
def addLine(x,y,dx,dy):
    if dx < 0:
        dx *= -1
        dy *= -1
    elif dx == 0:
        if dy < 0:
            dy *= -1
    g = gcd(dx,dy)
    dx //= g
    dy //= g

    if dx:
        k = x//dx
    else:
        k = y//dy
    x -= k*dx
    y -= k*dy
    L.append((x,y,dx,dy))


for i in range(n):
    for j in range(i+1,n):
        xi,yi = P[i]
        xj,yj = P[j]
        dx,dy = xi-xj,yi-yj
        addLine(xi,yi,dx,dy)

from collections import defaultdict as dd, deque

L = list(set(L))
res = 0

C = dd(int)
for x,y,dx,dy in L:
    C[dx,dy] += 1

ss = sum(C.values())

for x in C.values():
    res += (ss-x)*x

#for i in range(len(L)):
#    for j in range(i+1, len(L)):
#        x1,y1,dx1,dy1 = L[i]
#        x2,y2,dx2,dy2 = L[j]
#        if dx1 != dx2 or dy1 != dy2:
#            #print(L[i])
#            #print(L[j])
#            #print('---')
#            res += 1

print(res//2)

from math import gcd

n = int(input())
P = [[int(x) for x in input().split()] for _ in range(n)]

L = []
def addLine(x,y,dx,dy):
    if dx < 0:
        dx *= -1
        dy *= -1
    elif dx == 0:
        if dy < 0:
            dy *= -1
    g = gcd(dx,dy)
    dx //= g
    dy //= g

    if dx:
        k = x//dx
    else:
        k = y//dy
    x -= k*dx
    y -= k*dy
    L.append((x,y,dx,dy))


for i in range(n):
    for j in range(i+1,n):
        xi,yi = P[i]
        xj,yj = P[j]
        dx,dy = xi-xj,yi-yj
        addLine(xi,yi,dx,dy)

from collections import defaultdict as dd, deque

L = list(set(L))
res = 0

C = dd(int)
for x,y,dx,dy in L:
    C[dx,dy] += 1

ss = sum(C.values())

for x in C.values():
    res += (ss-x)*x

#for i in range(len(L)):
#    for j in range(i+1, len(L)):
#        x1,y1,dx1,dy1 = L[i]
#        x2,y2,dx2,dy2 = L[j]
#        if dx1 != dx2 or dy1 != dy2:
#            #print(L[i])
#            #print(L[j])
#            #print('---')
#            res += 1

print(res//2)