A point belongs to a triangle if it lies inside the triangle or on one of its sides. Two triangles are disjoint if there is no point on the plane that belongs to both triangles.

You are given nn points on the plane. No two points coincide and no three points are collinear.

Find the number of different ways to choose two disjoint triangles with vertices in the given points. Two ways which differ only in order of triangles or in order of vertices inside triangles are considered equal.

Input

The first line of the input contains an integer nn (6≤n≤20006≤n≤2000) – the number of points.

Each of the next nn lines contains two integers xixi and yiyi (|xi|,|yi|≤109|xi|,|yi|≤109) – the coordinates of a point.

No two points coincide and no three points are collinear.

Output

Print one integer – the number of ways to choose two disjoint triangles.

Examples

Input
6
1 1
2 2
4 6
4 5
7 2
5 3
Output
6
Input
7
0 -1000000000
-5 -5
5 -5
-5 0
5 0
-2 2
2 2
Output
21

题意:现在有N个点,满足没有三点共线,问有对少对三角形,满足没有公共部分。

思路:如果两个三角形A,B不相交,则有两种方式满足:A选择一个点a,B选择一个点b,三角形AB被直线ab隔开。那么我们枚举直线,然后直线两侧的点数分别是x,y,则其贡献是C(x,2)*C(y,2)*2,*2是因为有a可以和x部分组合,也可以和y部分组合,但最后要/2,因为没对三角形有两种直线满足。

具体的,我们用到了atan2(y1-y2,x1-x2),在一二象限为正,三四象限为负。

#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define pdd pair<double,double>
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define F first
#define S second
using namespace std;
const double pi=acos(-1.0);
const int maxn=;
pdd a[maxn]; double w[maxn];
int main()
{
int N; ll ans=;
scanf("%d",&N);
rep(i,,N) scanf("%lf%lf",&a[i].F,&a[i].S);
rep(i,,N){
int tot=;
rep(j,,N) if(j!=i) w[++tot]=atan2(a[j].S-a[i].S,a[j].F-a[i].F); //纵坐标在前,横在后
sort(w+,w++tot);
for(int j=,k=;j<=tot&&w[j]<=;j++){
while(k<=tot&&w[k]-w[j]<pi) k++;
ans+=(ll)(k-j-)*(k-j-)/*(tot-k+j)*(tot-k+j-)/;
}
}
printf("%I64d\n",ans);
return ;
}

最新文章

  1. python 基础之数据类型
  2. ARCGIS进行地理配准并加载到谷歌地球中查看
  3. 10分钟使用纯css实现完整的响应式导航菜单栏的效果
  4. js this的使用举例
  5. poj1502 spfa最短路
  6. Unity 5 中的全局光照技术详解(建议收藏)
  7. Function模式 -- 深入理解javascript
  8. C之算法
  9. Codelab for Android Design Support Library used in I/O Rewind Bangkok session
  10. Delphi 调用系统中的计算器、记事本、画图软件方法
  11. Android Weekly Notes Issue #249
  12. Java NIO (五) 管道 (Pipe)
  13. 防盗链[referer]
  14. Spring Boot实现文件下载功能
  15. js获取url传递得参数
  16. C++之输出100-200内的素数
  17. Django之views视图函数
  18. 设置模式之单例模式(附上一个Objective-C编写的播放音乐的单例类)
  19. segment_object_model_3d
  20. 【Java】编程技术经典书籍列表

热门文章

  1. 异动K线2--600532做一个分析时再给大家一只个股和近日大盘的分析
  2. python删除列表中所有的空元素
  3. LeetCode:二叉树的层次遍历||【107】
  4. Java基础教程:泛型基础
  5. 建议42:使用pandas处理大型CSV文件
  6. 【CodeChef】Turbo Sort
  7. dfs的返回条件
  8. [RK3288][Android6.0] TS-ADC驱动流程小结【转】
  9. java深入探究09-Filter,Listener,国际化
  10. tp3.2关联模型 BELONGS_TO