Problem:
Problem E: Symmetry

Open Binary and Object Group organizes a programming contest every year. Mr. Hex belongs to this
group and joins the judge team of the contest. This year, he created a geometric problem with its solution
for the contest. The problem required a set of points forming a line-symmetric polygon for the input.
Preparing the input for this problem was also his task. The input was expected to cover all edge cases, so
he spent much time and attention to make them satisfactory.

However, since he worked with lots of care and for a long time, he got tired before he finished. So He
might have made mistakes - there might be polygons not meeting the condition. It was not reasonable to
prepare the input again from scratch. The judge team thus decided to find all line-asymmetric polygons
in his input and fix them as soon as possible. They asked a programmer, just you, to write a program to
find incorrect polygons.

You can assume the following:

Edges of the polygon must not cross or touch each other except for the end points of adjacent
edges.

It is acceptable for the polygon to have adjacent three vertexes on a line, but in such a case, there
must be the vertex symmetric to each of them.

Input

The input consists of a set of points in the following format.

N

x1 y1

x2 y2

...

xN yN

The first line of the input contains an integer N (3 ≤ N ≤ 1000), which denotes the number of points.
The following N lines describe each point. The i-th line contains two integers x1, y1 (-10000 ≤ xi, yi ≤ 10000), which denote the coordinates of the i-th point.

Note that, although the points are the vertexes of a polygon, they are given in an artibrary order, not
necessarily clockwise or counterclockwise.

Output

Output "Yes" in a line if the points can form a line-symmetric polygon, otherwise output "No".

Sample Input 1

4
0 1
1 0
0 0
1 1

Sample Output 1

Yes

Sample Input 2

4
0 1
1 -1
0 0
1 1

Sample Output 2

No

Sample Input 3

9
-1 1
0 1
1 1
-1 0
0 0
1 0
-1 -1
0 -1
1 -1

Sample Output 3

No

Sample Input 4

3
-1 -1
0 0
1 1

Sample Output 4

No

Sample Input 5

4
0 2
0 0
-1 0
1 0

Sample Output 5

Yes

Solution in C++14 (judge verdict: Wrong Answer)

#include <bits/stdc++.h>
using namespace std;

typedef pair<int,int> PI;

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

typedef double D;
typedef complex<D> P;
#define X real()
#define Y imag()

const D eps=1e-8;
const D inf=1e12;

struct L : public vector<P> { // line and segment
  L(const P& a,const P &b){
    push_back(a);
    push_back(b);
  }
};

bool cmp_x(const P& a,const P& b){ return a.X==b.X?a.Y<b.Y:a.X<b.X; }
D dot(P a,P b){ return (conj(a)*b).X; }
D cross(P a,P b){ return (conj(a)*b).Y; }
vector<P> convex_hull(vector<P>& ps){
  sort(ps.begin(),ps.end(),[](const P& a,const P& b){ return a.X==b.X?a.Y<b.Y:a.X<b.X; });
  int n=ps.size();
  int k=0;
  vector<P> qs(n*2);
  for(int i=0;i<n;i++){
    while(k>1&&cross(qs[k-1]-qs[k-2],ps[i]-qs[k-1])<0)k--;
    qs[k++]=ps[i];
  }
  for(int i=n-2,t=k;i>=0;i--){
    while(k>t&&cross(qs[k-1]-qs[k-2],ps[i]-qs[k-1])<0)k--;
    qs[k++]=ps[i];
  }
  qs.resize(k-1);
  return qs;
}

bool intersectLP(L l,P p){
  return abs(cross(l[1]-p,l[0]-p))<eps;
}
P projection(L l,P p){
  P b=l[1]-l[0],c=p-l[0];
  return l[0]+b*(c/b).X;
}
P reflection(L l,P p) {
  return p+2.0*(projection(l,p)-p);
}

int N;
vector<P> ps;

int main(){
  cin>>N;
  rep(i,N){
    int x,y;
    cin>>x>>y;
    ps.push_back(P(x,y));
  }
  vector<P> cs=convex_hull(ps);
  int M=cs.size();
  vector<P> ds;
  rep(i,M){
    ds.push_back(cs[i]);
    ds.push_back((cs[i]+cs[(i+1)%M])*0.5);
  }
  vector<L> cand;
  rep(i,M){
    bool ok=true;
    P p1=ds[i],p2=ds[i+M];
    for(int l=(i-1+2*M)%(2*M),r=i+1;l!=r;l=(l-1+2*M)%(2*M),r=(r+1)%(2*M)){
      P m=(ds[l]+ds[r])*0.5;
      if(!intersectLP(L(p1,p2),m)||abs(dot(ds[l]-ds[r],p1-p2))>eps)ok=false;
    }
    if(ok){
      cand.push_back(L(p1,p2));
    }
  }

  bool is_sym=false;
  sort(all(ps),cmp_x);
  rep(i,cand.size()){
    vector<P> sps;
    rep(j,N){
      sps.push_back(reflection(cand[i],ps[j]));
    }
    sort(all(sps),cmp_x);
    bool ok=true;
    int cnt=0;
    rep(j,N){
      if(abs(sps[j]-ps[j])>eps)ok=false;
      if(intersectLP(cand[i],ps[j]))cnt++;
    }
    if(ok&&cnt<3)is_sym=true;
  }

  if(is_sym)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  return 0;
}