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]

Source: codeforces | Difficulty: HARD
Tags: Mathematics

Geometry

Data structures

Implementation


Solutions:
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 collections import defaultdict
from math import gcd
inf = 10 ** 20
t = 1
for _ in range(t):
	n = int(input())
	arr = []
	for i in range(n):
		(x, y) = map(int, input().split())
		arr += [[x, y]]
	d = defaultdict(set)
	infslope = defaultdict(int)
	for i in range(n):
		for j in range(i + 1, n):
			dy = arr[i][1] - arr[j][1]
			dx = arr[i][0] - arr[j][0]
			g = gcd(abs(dx), abs(dy))
			dx //= g
			dy //= g
			if dx == 0:
				infslope[arr[i][0]] += 1
				continue
			if dy < 0:
				dy *= -1
				dx *= -1
			elif dy == 0:
				dx = 1
			m = (dy, dx)
			one = m[1]
			two = m[1] * arr[i][1] - m[0] * arr[i][0]
			g = gcd(abs(one), abs(two))
			one //= g
			two //= g
			if one < 0:
				one *= -1
				two *= -1
			d[dy, dx].add((one, two))
	curr = 0
	ans = 0
	for x in d:
		ans += len(d[x]) * curr
		curr += len(d[x])
	ans += len(infslope) * curr
	print(ans)


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
print(res // 2)


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 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))


from sys import stdin, stdout
from math import atan, pi, tan
import itertools
n = int(input())
pts = []
for i in range(n):
	(x, y) = map(int, stdin.readline().split())
	pts.append((x, y))
eps = 10 ** (-10)

def slope(p1, p2):
	if p1[0] == p2[0]:
		return pi / 2
	return atan((p2[1] - p1[1]) / (p2[0] - p1[0]))
slopes = []
for (p1, p2) in itertools.combinations(pts, 2):
	slopes.append((slope(p1, p2), p1))
slopes.sort()
counts = []
idx = 0
while idx < len(slopes):
	cur_slope = slopes[idx][0]
	slp = tan(cur_slope)
	y_ints = []
	while idx < len(slopes) and abs(slopes[idx][0] - cur_slope) < eps:
		p = slopes[idx][1]
		if abs(cur_slope) < pi / 4:
			y_ints.append(p[1] - p[0] * slp)
		else:
			y_ints.append(p[0] - p[1] / slp)
		idx += 1
	ct = 0
	y_ints.sort()
	prev = -100000
	for x_int in y_ints:
		if abs(x_int - prev) > eps:
			ct += 1
		prev = x_int
	counts.append(ct)
ans = 0
s = sum(counts)
for ct in counts:
	ans += ct * (s - ct)
ans //= 2
print(ans)


import sys
lines = set()
points = []
num = int(input())
for i in range(num):
	points.append([int(j) for j in sys.stdin.readline().split()])
for i in range(num):
	for j in range(i):
		dx = points[j][0] - points[i][0]
		if dx == 0:
			lines.add((11932912953213, points[i][0]))
		else:
			m = (points[j][1] - points[i][1]) / dx
			lines.add((int(2 ** 33 * m), int(2 ** 33 * (points[i][1] - m * points[i][0]))))
ms = {}
for l in lines:
	if l[0] in ms:
		ms[l[0]] += 1
	else:
		ms[l[0]] = 1
total = 0
t = list(ms.values())
s = sum(t)
for a in t:
	total += a * (s - a)
print(total // 2)


import sys
from array import array
from typing import List, Tuple, TypeVar, Generic, Sequence, Union

def input():
	return sys.stdin.buffer.readline().decode('utf-8')

def main():
	from collections import Counter
	from math import gcd
	n = int(input())
	point = [tuple(map(int, input().split())) for _ in range(n)]
	line = set()
	delta = Counter()
	for (i, (x1, y1)) in enumerate(point):
		for (x2, y2) in point[i + 1:]:
			(a, b, c) = (y2 - y1, x1 - x2, x2 * y1 - x1 * y2)
			g = gcd(gcd(a, b), c)
			(a, b, c) = (a // g, b // g, c // g)
			if a < 0:
				(a, b, c) = (-a, -b, -c)
			elif a == 0 and b < 0:
				(b, c) = (-b, -c)
			if (a, b, c) not in line:
				line.add((a, b, c))
				(dx, dy) = (x1 - x2, y1 - y2)
				g = gcd(dx, dy)
				(dx, dy) = (dx // g, dy // g)
				if dx < 0:
					(dx, dy) = (-dx, -dy)
				elif dx == 0:
					dy = 1
				delta[dx, dy] += 1
	ans = len(line) * (len(line) - 1) // 2 - sum((v * (v - 1) >> 1 for v in delta.values()))
	print(ans)
main()


from math import gcd
from collections import defaultdict

def go():
	n = int(input())
	pairs = []
	for _ in range(n):
		pairs.append([int(i) for i in input().split(' ')])
	total = 0
	result = 0
	wires = defaultdict(set)
	for i in range(n):
		for j in range(i + 1, n):
			(x1, y1) = pairs[i]
			(x2, y2) = pairs[j]
			a = y1 - y2
			b = x1 - x2
			g = gcd(a, b)
			if a < 0 or (a == 0 and b < 0):
				a = -a
				b = -b
			a //= g
			b //= g
			wires[a, b]
			c = a * x1 - b * y1
			pair = (a, b)
			if c not in wires[pair]:
				wires[pair].add(c)
				total += 1
				result += total - len(wires[pair])
	return result
print(go())


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from math import gcd, ceil

def pre(s):
	n = len(s)
	pi = [0] * n
	for i in range(1, n):
		j = pi[i - 1]
		while j and s[i] != s[j]:
			j = pi[j - 1]
		if s[i] == s[j]:
			j += 1
		pi[i] = j
	return pi

def prod(a):
	ans = 1
	for each in a:
		ans = ans * each
	return ans

def lcm(a, b):
	return a * b // gcd(a, b)

def binary(x, length=16):
	y = bin(x)[2:]
	return y if len(y) >= length else '0' * (length - len(y)) + y
pts = []
for _ in range(int(input()) if True else 1):
	(x, y) = map(int, input().split())
	pts += [[x, y]]
ps = []
pss = set()
from fractions import Fraction
for i in range(len(pts) - 1):
	for j in range(i + 1, len(pts)):
		(x1, y1, x2, y2) = (pts[i][0], pts[i][1], pts[j][0], pts[j][1])
		(a, b, c) = (y1 - y2, x2 - x1, x1 * y2 - x2 * y1)
		g = gcd(a, b)
		(a, b) = (a // g, b // g)
		if a < 0 or (a == 0 and b < 0):
			a *= -1
			b *= -1
			c *= -1
		c = round(c / g, 3)
		xx = str(a) + ',' + str(b) + ',' + str(c)
		if xx not in pss:
			pss.add(xx)
			ps += [[a, b, c]]
ans = len(ps) * (len(ps) - 1) // 2
di = {}
for i in ps:
	xx = str(i[0]) + ',' + str(i[1])
	if xx in di:
		di[xx] += 1
	else:
		di[xx] = 1
for i in di:
	ans -= di[i] * (di[i] - 1) // 2
print(ans)


import sys
input = lambda : sys.stdin.readline().strip()
from math import gcd
n = int(input())
points = []
for i in range(n):
	points.append(tuple(map(int, input().split())))
lines = []
for i in range(n):
	for j in range(i + 1, n):
		x1 = points[i][0]
		y1 = points[i][1]
		x2 = points[j][0]
		y2 = points[j][1]
		a = y1 - y2
		b = x2 - x1
		c = x1 * y2 - x2 * y1
		GCD = gcd(gcd(a, b), c)
		(a, b, c) = (a / GCD, b / GCD, c / GCD)
		if a != 0:
			check = 0
		else:
			check = 1
		if [a, b, c][check] < 0:
			(a, b, c) = (-a, -b, -c)
		lines.append((a, b, c))
lines = list(set(lines))
d = {}
for line in lines:
	try:
		d[line[0], line[1]] += 1
	except:
		d[line[0], line[1]] = 1
d = list(d.values())
ans = len(lines) * (len(lines) - 1) // 2
for i in d:
	ans -= i * (i - 1) // 2
print(ans)


import itertools
import math
from functools import reduce
from math import gcd
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(*filter(lambda x: x != 0, (_p2[1] - _p1[1], _p1[0] - _p2[0], _p1[1] * _p2[0] - _p1[0] * _p2[1])))
	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: 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 ax_bx.values():
		out += (k - x) * x
	write(out // 2)
main()


import sys, math, queue
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)


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 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)


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)


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))


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 collections import *

def li():
	return [int(i) for i in input().split()]

def val():
	return int(input())
n = val()
l = []
for i in range(n):
	l.append(li())
d = defaultdict(int)
visited = set()
for i in range(n):
	for j in range(i):
		try:
			slope = (l[i][1] - l[j][1]) / (l[i][0] - l[j][0])
		except:
			slope = 'inf'
		if slope == 'inf':
			intercept = l[j][0]
		else:
			intercept = (l[j][1] * l[i][0] - l[i][1] * l[j][0]) / (l[i][0] - l[j][0])
		if tuple([slope, intercept]) not in visited:
			d[slope] += 1
			visited.add(tuple([slope, intercept]))
tot = sum(d.values())
ans = 0
for i in list(d):
	tot -= d[i]
	ans += tot * d[i]
	d.pop(i)
print(ans)


from __future__ import division, print_function
import bisect
import math
import itertools
import sys
from atexit import register
from fractions import Fraction
if sys.version_info[0] < 3:
	from io import BytesIO as stream
else:
	from io import StringIO as stream
if sys.version_info[0] < 3:

	class dict(dict):

		def items(self):
			return dict.iteritems(self)

		def keys(self):
			return dict.iterkeys(self)

		def values(self):
			return dict.itervalues(self)
	input = raw_input
	range = xrange
	filter = itertools.ifilter
	map = itertools.imap
	zip = itertools.izip

def sync_with_stdio(sync=True):
	global input, flush
	if sync:
		flush = sys.stdout.flush
	else:
		sys.stdin = stream(sys.stdin.read())
		input = lambda : sys.stdin.readline().rstrip('\r\n')
		sys.stdout = stream()
		register(lambda : sys.__stdout__.write(sys.stdout.getvalue()))

def main():
	n = int(input())
	l1 = []
	d2 = {}
	for i in range(0, n):
		(x, y) = map(int, input().split())
		for item in l1:
			if x == item[0]:
				if 'inf' not in d2:
					temp = {}
					temp[x] = 1
					d2['inf'] = temp
				elif x not in d2['inf']:
					temp = d2['inf']
					temp[x] = 1
			else:
				flag = 0
				(a, b) = (y - item[1], x - item[0])
				if a * b < 0:
					flag = 1
				f = math.gcd(abs(a), abs(b))
				a = a // f
				b = b // f
				if flag == 1:
					a = -1 * abs(a)
					b = abs(b)
				else:
					a = abs(a)
					b = abs(b)
				d = b * y - a * x
				flag = 0
				if d * b < 0:
					flag = 1
				if flag == 1:
					d = -1 * abs(d)
					b = abs(b)
				else:
					d = abs(d)
					b = abs(b)
				e = math.gcd(abs(d), abs(b))
				c = (d // e, b // e)
				if (a, b) not in d2:
					temp = {}
					temp[c] = 1
					d2[a, b] = temp
				elif c not in d2[a, b]:
					temp = d2[a, b]
					temp[c] = 1
		l1.append((x, y))
	z = 0
	ans = 0
	f = 0
	for k in d2:
		z += len(d2[k])
	for k in d2:
		x = len(d2[k])
		f = f + x
		ans += x * (z - f)
	print(ans)
sync_with_stdio(False)
main()


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())

def gcd(a, b):
	if a == 0:
		return b
	return gcd(b % a, a)
points = []
lines = set()
counter = 0
for i in range(n):
	a = [int(x) for x in input().split()]
	points.append(a)
for item in points:
	for elem in points:
		if item != elem:
			g = gcd(item[1] - elem[1], item[0] - elem[0])
			k = ((item[1] - elem[1]) // g, (item[0] - elem[0]) // g, (item[1] * elem[0] - elem[1] * item[0]) // g)
			if k[0] < 0 or (k[0] == 0 and k[1] < 0):
				k = (-k[0], -k[1])
			lines.add(k)
lines = sorted(lines)
lines.append((10 ** 100, 10 ** 100))
x = len(lines)
counter = 1
answer = (x - 1) * (x - 2) // 2
for i in range(1, x):
	if lines[i][0] == lines[i - 1][0] and lines[i][1] == lines[i - 1][1]:
		counter += 1
	else:
		answer -= counter * (counter - 1) // 2
		counter = 1
print(answer)


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)


import math
from collections import defaultdict
import sys
input = sys.stdin.readline
import math
n = int(input())
points = []
lines1 = defaultdict(set)
for i in range(n):
	(x, y) = map(int, input().split())
	points.append([x, y])
points.sort()
count = 0
for i in range(n):
	for j in range(i + 1, n):
		if points[i][0] == points[j][0]:
			lines1[math.inf].add(points[j][0])
		else:
			slope = (points[i][1] - points[j][1]) / (points[i][0] - points[j][0])
			lines1[slope].add((points[i][0] * points[j][1] - points[j][0] * points[i][1]) / (points[i][0] - points[j][0]))
s = 0
for v in lines1:
	s += len(lines1[v])
lines2 = s * (s - 1) // 2
for (i, value) in lines1.items():
	s = len(value)
	lines2 -= s * (s - 1) // 2
print(lines2)


from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
from math import gcd, factorial, floor, ceil
from copy import deepcopy
from collections import deque
from bisect import bisect_left as bl
from bisect import bisect_right as br
from bisect import bisect
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
from types import GeneratorType

def iterative(f, stack=[]):

	def wrapped_func(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		to = f(*args, **kwargs)
		while True:
			if type(to) is GeneratorType:
				stack.append(to)
				to = next(to)
				continue
			stack.pop()
			if not stack:
				break
			to = stack[-1].send(to)
		return to
	return wrapped_func
mod = 10 ** 9 + 7

def inp():
	return sys.stdin.readline().rstrip('\r\n')

def out(var):
	sys.stdout.write(str(var))

def lis():
	return list(map(int, inp().split()))

def stringlis():
	return list(map(str, inp().split()))

def sep():
	return map(int, inp().split())

def strsep():
	return map(str, inp().split())

def zerolist(n):
	return [0] * n

def nextline():
	out('\n')

def testcase(t):
	for pp in range(t):
		solve(pp)

def printlist(a):
	for p in range(0, len(a)):
		out(str(a[p]) + ' ')

def google(p):
	print('Case #' + str(p) + ': ', end='')

def lcm(a, b):
	return a * b // gcd(a, b)

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def ncr(n, r):
	return factorial(n) // (factorial(r) * factorial(max(n - r, 1)))

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True

def slope(a, b):
	if a[0] - b[0] == 0:
		return 'inf'
	return (a[1] - b[1]) / (a[0] - b[0])

def line(aa, bb):
	(x1, y1, x2, y2) = (aa[0], aa[1], bb[0], bb[1])
	(a, b, c) = (y1 - y2, x2 - x1, x1 * y2 - x2 * y1)
	g = gcd(a, b)
	(a, b) = (a // g, b // g)
	if a < 0 or (a == 0 and b < 0):
		a *= -1
		b *= -1
		c *= -1
	c = round(c / g, 3)
	return str(a) + 'x ' + str(b) + 'y =' + str(c)

def solve(case):
	n = int(inp())
	ll = 0
	coor = []
	for i in range(n):
		(a, b) = sep()
		coor.append((a, b))
	have = set()
	help = []
	for i in range(n):
		for j in range(i + 1, n):
			curr = line(coor[i], coor[j])
			if curr not in have:
				ll += 1
				have.add(curr)
				help.append(curr)
	slopecnt = {}
	for j in help:
		j = list(j)
		ind = j.index('=')
		tochck = j[:ind]
		tochck = ''.join(tochck)
		if tochck not in slopecnt:
			slopecnt[tochck] = 1
		else:
			slopecnt[tochck] += 1
	ans = ll * (ll - 1) // 2
	for i in slopecnt:
		if slopecnt[i] > 1:
			ans -= slopecnt[i] * (slopecnt[i] - 1) // 2
	print(ans)
testcase(1)


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)


n = int(input())
x = [0 for i in range(0, n + 1)]
y = [0 for i in range(0, n + 1)]
for i in range(1, n + 1):
	(x[i], y[i]) = map(int, input().split())
di = {}
for i in range(1, n + 1):
	a = {}
	for j in range(i + 1, n + 1):
		if x[j] - x[i] == 0:
			if '0' not in a:
				a['0'] = 1
			else:
				a['0'] = a['0'] + 1
		else:
			k = (y[j] - y[i]) / (x[j] - x[i])
			if k not in a:
				a[k] = 1
			else:
				a[k] = a[k] + 1
	for (key, value) in a.items():
		if value > 1:
			continue
		if key in di:
			di[key] = di[key] + 1
		else:
			di[key] = 1
b = []
for v in di.values():
	b.append(v)
b.sort()
sum = 0
for i in b:
	sum += i
ans = 0
for i in b:
	ans += i * (sum - i)
	sum -= i
print(ans)


def gcd(x, y):
	if y == 0:
		return x
	else:
		return gcd(y, x % y)
from collections import *
n = int(input())
ps = []
for i in range(n):
	ps.append([int(i) for i in input().split(' ')])
xs = 0
ys = 0
lines = defaultdict(int)
cache = set()
xcache = set()
ycache = set()
for i in range(n):
	for j in range(i + 1, n):
		if ps[i][0] == ps[j][0]:
			if ps[i][0] in xcache:
				continue
			xcache.add(ps[i][0])
			xs += 1
			continue
		if ps[i][1] == ps[j][1]:
			if ps[i][1] in ycache:
				continue
			ycache.add(ps[i][1])
			ys += 1
			continue
		tmpp = sorted([ps[i], ps[j]])
		tmppp = (tmpp[1][0] - tmpp[0][0], tmpp[1][1] - tmpp[0][1])
		gcdd = gcd(abs(tmpp[1][0] - tmpp[0][0]), abs(tmpp[1][1] - tmpp[0][1]))
		tmppp = (tmppp[0] // gcdd, tmppp[1] // gcdd)
		kkk = (tmppp[1], tmppp[0])
		if tmppp[1] < 0:
			kkk = (-tmppp[1], -tmppp[0])
		qqq = (tmppp[1] * -ps[i][0] + tmppp[0] * ps[i][1], tmppp[0])
		if qqq[0] < 0:
			qqq = (-qqq[0], -qqq[1])
		line = (kkk, qqq)
		if line in cache:
			continue
		cache.add(line)
		lines[kkk] += 1
tmp = xs + ys + sum(lines.values())
print((tmp * (tmp - 1) - sum((v * (v - 1) for v in lines.values())) - xs * (xs - 1) - ys * (ys - 1)) // 2)


import sys
input = sys.stdin.readline
from math import gcd
n = int(input())
p = [list(map(int, input().split())) for i in range(n)]
lines = []
for i in range(n):
	(x1, y1) = p[i]
	for j in range(i + 1, n):
		(x2, y2) = p[j]
		a = y1 - y2
		b = x1 - x2
		c = y1 * x2 - x1 * y2
		if a < 0 or (a == 0 and b < 0):
			a = -a
			b = -b
			c = -c
		g = gcd(a, gcd(b, c))
		a //= g
		b //= g
		c //= g
		lines.append((a, b, c))
lines = list(set(lines))
m = len(lines)
lines.sort(key=lambda x: x[1] / max(x[0], 10 ** (-10)))
cnt = 1
ans = m * (m - 1) // 2
for i in range(m - 1):
	(a1, b1, c1) = lines[i]
	(a2, b2, c2) = lines[i + 1]
	if a1 * b2 - a2 * b1 == 0:
		cnt += 1
	else:
		ans -= cnt * (cnt - 1) // 2
		cnt = 1
ans -= cnt * (cnt - 1) // 2
print(ans)


from math import *
from itertools import *
n = int(input())
map = {}
l = []
r = []
now = 0
tot = 0
lth = []
for _ in range(n):
	s = input().split(' ')
	l.append(int(s[0]))
	r.append(int(s[1]))
for i in range(n):
	for j in range(i + 1, n):
		if l[i] == l[j]:
			y = 9999999999999999999
			x = l[i]
		else:
			y = (r[i] - r[j]) / (l[i] - l[j])
			x = (r[j] * l[i] - l[j] * r[i]) / (l[i] - l[j])
		if not y in map:
			map[y] = {x: 1}
		elif x in map[y]:
			map[y][x] += 1
		else:
			map[y][x] = 1
for i in map:
	lth.append(len(map[i]))
	now += lth[len(lth) - 1]
for i in lth:
	tot += (now - i) * i
	now -= i
print(tot)


from math import *

class slopeC:

	def __init__(self):
		self.chil = set()
n = int(input())
slopes = {}
L = []
for i in range(n):
	(x, y) = 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)


import math
import itertools
from collections import Counter
n = int(input())
coords = [[int(t) for t in input().split(' ')] for _ in range(n)]
lines = set()
for pair in itertools.combinations(coords, 2):
	l = min(pair)
	r = max(pair)
	a = r[1] - l[1]
	b = r[0] - l[0]
	c = r[1] * l[0] - l[1] * r[0]
	gcd = math.gcd(math.gcd(a, b), c)
	a /= gcd
	b /= gcd
	c /= gcd
	lines.add((a, b, c))
num_lines = len(lines)
count = Counter(((a, b) for (a, b, c) in lines))
result = num_lines * (num_lines - 1) // 2
for (_, c) in count.items():
	result -= c * (c - 1) // 2
print(result)


import sys, math, itertools
from collections import Counter, deque, defaultdict
from bisect import bisect_left, bisect_right
from heapq import heappop, heappush, heapify, nlargest
mod = 10 ** 9 + 7
INF = float('inf')

def inp():
	return int(sys.stdin.readline())

def inpl():
	return list(map(int, sys.stdin.readline().split()))
n = inp()
a = [tuple(map(int, sys.stdin.readline().split())) for _ in range(n)]
d = defaultdict(int)
z = set()
yp = set()
xp = set()
for i in range(n):
	for j in range(i + 1, n):
		(x1, y1) = a[i]
		(x2, y2) = a[j]
		Y = y2 - y1
		X = x2 - x1
		if X < 0:
			Y *= -1
			X *= -1
		if X == 0:
			xp.add(x1)
		elif Y == 0:
			yp.add(y1)
		else:
			g = math.gcd(X, abs(Y))
			X //= g
			Y //= g
			c = x1 * Y - y1 * X
			if (X, Y, c) in z:
				continue
			d[X, Y] += 1
			z.add((X, Y, c))
m = len(z) + len(yp) + len(xp)
res = 0
for (x, y, c) in list(z):
	res += m - d[x, y]
for YY in list(yp):
	res += m - len(yp)
for XX in list(xp):
	res += m - len(xp)
print(res // 2)


coord = []
coef = {}
a = b = 0
v = {}
coef_a = {}
n = int(input())
for i in range(n):
	coord.append(list(map(float, input().split())))
for i in range(n):
	(x1, y1) = coord[i]
	for j in range(i + 1, n):
		(x2, y2) = coord[j]
		if x2 - x1:
			a = (y2 - y1) / (x2 - x1)
			b = (y1 * x2 - y2 * x1) / (x2 - x1)
			coef[a, b] = coef.get((a, b), 0) + 1
			coef_a[a] = coef_a.get(a, 0) + 1
			if coef[a, b] > 1:
				coef[a, b] -= 1
				coef_a[a] -= 1
		else:
			v[x2] = 1
v_nmbr = sum(v.values())
coe = list(coef_a.values())
for i in range(len(coe)):
	coe[i] = coe[i] * (coe[i] - 1) // 2
l_par = sum(coe)
l_nmbr = len(coef) + v_nmbr
ans = l_nmbr * (l_nmbr - 1) // 2 - v_nmbr * (v_nmbr - 1) // 2 - l_par
print(ans)


import os
import sys
import math
from io import BytesIO, IOBase
from fractions import Fraction
from collections import defaultdict
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
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)


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]
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')


def gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def frac(a, b):
	x = gcd(a, b)
	return (a // x, b // x)
n = int(input())
coords = []
for i in range(n):
	coords.append(tuple(map(int, input().split())))
slopes = {}
for i in range(n):
	for j in range(i + 1, n):
		(x1, y1) = (coords[i][0], coords[i][1])
		(x2, y2) = (coords[j][0], coords[j][1])
		if x1 == x2:
			slope = 'inf'
			mark = x1
		else:
			slope = frac(y2 - y1, x2 - x1)
			mark = frac(y1 * x2 - y2 * x1, x2 - x1)
		if slope in slopes:
			slopes[slope].add(mark)
		else:
			slopes[slope] = {mark}
tot = sum((len(slopes[guy]) for guy in slopes))
sumi = 0
for guy in slopes:
	a = len(slopes[guy])
	sumi += a * (tot - a)
print(sumi // 2)


from fractions import Fraction
VERT = object()
n = int(input())
points = [tuple(map(int, input().split())) for _ in range(n)]
d = {}
for (i, p) in enumerate(points):
	(x1, y1) = p
	for (x2, y2) in points[i + 1:]:
		if x1 < x2:
			f = Fraction(y2 - y1, x2 - x1)
		elif x1 > x2:
			f = Fraction(y1 - y2, x1 - x2)
		else:
			f = VERT
		if f == VERT:
			x_inter = x1
		else:
			x_inter = y1 - x1 * f
		if f == VERT:
			key = VERT
			value = x_inter
		else:
			key = f.numerator / f.denominator
			value = x_inter.numerator / x_inter.denominator
		if key in d:
			d[key].add(x_inter)
		else:
			d[key] = {x_inter}
total = sum((len(s) for s in d.values()))
total_inter = 0
for s in d.values():
	total_inter += len(s) * (total - len(s))
print(total_inter // 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)


def pos_gcd(a, b):
	if a == 0 and b == 0:
		return 1
	if b == 0:
		return a
	return pos_gcd(b, a % b)

def gcd2(a, b):
	return pos_gcd(abs(a), abs(b))

def gcd(a, b, c):
	return gcd2(gcd2(a, b), c)

def make_line(p1, p2):
	a = p2[1] - p1[1]
	b = p1[0] - p2[0]
	c = -a * p1[0] - b * p1[1]
	d = gcd(a, b, c)
	a //= d
	b //= d
	c //= d
	if a < 0:
		a = -a
		b = -b
		c = -c
	elif a == 0 and b < 0:
		b = -b
		c = -c
	return (a, b, c)

def parallel(l1, l2):
	return l1[0] == l2[0] and l1[1] == l2[1]
n = int(input())
pointlist = []
lineset = set()
for i in range(n):
	p = tuple(map(int, input().split(' ')))
	for q in pointlist:
		lineset.add(make_line(p, q))
	pointlist.append(p)
linedict = {}
for l in lineset:
	l1 = (l[0], l[1])
	if l1 not in linedict:
		linedict[l1] = 1
	else:
		linedict[l1] += 1
linecount = 0
ans = 0
for l in linedict.keys():
	linecount += linedict[l]
for l in linedict.keys():
	linecount -= linedict[l]
	ans += linedict[l] * linecount
print(ans)


def gcd(a, b):
	while b:
		(a, b) = (b, a % b)
	return a
n = int(input())
p = [0] * n
for i in range(n):
	p[i] = [int(item) for item in input().split()]
wires = set()
for i in range(n):
	for j in range(i + 1, n):
		(x0, y0) = p[i]
		(x1, y1) = p[j]
		a = -(y1 - y0)
		b = x1 - x0
		c = x0 * (y1 - y0) - y0 * (x1 - x0)
		k = gcd(a, gcd(b, c))
		a //= k
		b //= k
		c //= k
		if a < 0:
			a *= -1
			b *= -1
			c *= -1
		wires.add((a, b, c))
wires = list(wires)
para_x = []
para_y = []
others = {}
for i in range(len(wires)):
	(a, b, c) = wires[i]
	if b == 0:
		para_y.append(i)
	elif a == 0:
		para_x.append(i)
	else:
		k = gcd(a, b)
		if (a // k, b // k) in others:
			others[a // k, b // k] += 1
		else:
			others[a // k, b // k] = 1
px = len(para_x)
py = len(para_y)
o = sum((others[x] for x in others))
ans = px * py + px * o + py * o
others_list = [others[x] for x in others]
pre = [0] * (len(others_list) + 1)
for i in range(len(others_list)):
	pre[i] = pre[i - 1] + others_list[i]
for i in range(len(others_list) - 1, 0, -1):
	ans += others_list[i] * pre[i - 1]
print(ans)