import java.util.*;
class Point implements Comparable<Point> {
long x, y;
public Point(long x, long y)
{
this.x = x;
this.y = y;
}
@Override public int compareTo(Point p)
{
return Long.compare(x, p.x) != 0
? Long.compare(x, p.x)
: Long.compare(y, p.y);
}
}
public class ConvexHull {
static long crossProduct(Point O, Point A, Point B)
{
return (A.x - O.x) * (B.y - O.y)
- (A.y - O.y) * (B.x - O.x);
}
static List<Point> convexHull(List<Point> A)
{
int n = A.size(), k = 0;
if (n <= 3)
return A;
List<Point> ans = new ArrayList<>(2 * n);
Collections.sort(A);
for (int i = 0; i < n; ++i) {
while (k >= 2
&& crossProduct(ans.get(k - 2),
ans.get(k - 1), A.get(i))
<= 0)
ans.remove(--k);
ans.add(A.get(i));
k++;
}
for (int i = n - 2, t = k; i >= 0; --i) {
while (k > t
&& crossProduct(ans.get(k - 2),
ans.get(k - 1), A.get(i))
<= 0)
ans.remove(--k);
ans.add(A.get(i));
k++;
}
ans.remove(ans.size() - 1);
return ans;
}
public static void main(String[] args)
{
List<Point> points = new ArrayList<>();
points.add(new Point(0, 3));
points.add(new Point(2, 2));
points.add(new Point(1, 1));
points.add(new Point(2, 1));
points.add(new Point(3, 0));
points.add(new Point(0, 0));
points.add(new Point(3, 3));
List<Point> ans = convexHull(points);
for (Point p : ans)
System.out.println("(" + p.x + ", " + p.y
+ ")");
}
}