Problem:
Problem C: Satake likes straight
Problem
Satake君は曲がったことが嫌いです。
例えば、鉛筆や箸、家が曲がった形をしているのは嫌いですし、右折や左折などの行動をとることも嫌いです。
さて、XY 平面上で暮らすSatake君は $N$ 個のお店 $(X_{1},Y_{1}),(X_{2},Y_{2}), \ldots , (X_{N},Y_{N})$ で買い物をするようお使いを頼まれました。座標 $(0, 0)$ にある家から $(1, 0)$ の方向を向いた状態で出発し、すべてのお店で買い物をしたあと、家に帰ります。お店を回る順番は自由です。Satake君はお使いとして次に示す任意の行動を何度でも行うことができます。
向いている方向に好きなだけ進む
お店か家と同じ座標のとき時計回りか反時計回りに好きな角度だけその場で回転する
お店と同じ座標のとき座標や向いている方向の状態を維持したまま買い物をする
先程も言ったようにSatake君は曲がることが嫌いです。心の準備ができるように、Satake君が行動2.で回転する角度の和の最小値を求めてください。例として、時計回りに $90^{\circ}$ 回転した後、反時計回りに $90^{\circ}$ 回転した場合、角度の和は $180^{\circ}$ となります。
Input
入力は以下の形式で与えられます。
$N$
$X_{1}$ $Y_{1}$
$\vdots$
$X_{N}$ $Y_{N}$
入力は $N+1$ 行からなります。
$1$ 行目には買い物をする店の個数を表す $N$ が与えられます。
$2$ 行目から続く $N$ 行には、買い物をするお店の座標 $X_{i}, Y_{i}$ が空白区切りで与えられます。
Constraints
入力は以下の条件を満たします。
$2 \le N \le 8$
$-1000 \le X_{i}, Y_{i} \le 1000  \quad (1 \le i \le N)$
$(X_{i}, Y_{i}) \ne (0, 0)        \quad (1 \le i \le N)$
$(X_{i}, Y_{i}) \ne (X_{j}, Y_{j}) \quad (i \ne j)$
入力はすべて整数
Output
Satake君が回転する角度の和の最小値を度数法で出力してください。ただし想定解との絶対誤差が $10^{-4}$ 以下のときのみ正解とします。
Sample Input 1
2
0 1
0 -1
Sample Output 1
450.00000000
Satake君は最初 $(1, 0)$ 方向を向いて出発することに注意してください。
Sample Input 2
3
1 0
0 1
-2 -1
Sample Output 2
386.565051

Submitted solutions:

code_snippet: // AOJ #3066
// Satake likes straight 2025.2.3

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

const double PI = acos(-1);

// 2つのベクトル (ax,ay) と (bx,by) のなす角（度）を返す
double angleBetween(double ax, double ay, double bx, double by) {
    double dot = ax * bx + ay * by;
    double magA = sqrt(ax * ax + ay * ay);
    double magB = sqrt(bx * bx + by * by);
    double cosval = dot / (magA * magB);
    // 浮動小数点誤差対策：範囲 [-1,1] に収める
    if(cosval > 1) cosval = 1;
    if(cosval < -1) cosval = -1;
    double angle = acos(cosval); // [rad]
    return angle * 180.0 / PI;
}
 
struct Point { int x, y; };
 
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    
    int N;
    cin >> N;
    vector<Point> shops(N);
    for (int i = 0; i < N; i++){
        cin >> shops[i].x >> shops[i].y;
    }
    
    vector<int> perm(N);
    for (int i = 0; i < N; i++) perm[i] = i;
    
    double best = 1e18;
    
    // 全順列を試す
    do {
        double totalCost = 0.0;
        
        double sx = shops[perm[0]].x - 0;
        double sy = shops[perm[0]].y - 0;

        totalCost += angleBetween(1.0, 0.0, sx, sy);
 
        double prev_dx = sx, prev_dy = sy;
        
        for (int i = 1; i <= N; i++){
            double curr_dx, curr_dy;
            if(i < N) {
                curr_dx = shops[perm[i]].x - shops[perm[i-1]].x;
                curr_dy = shops[perm[i]].y - shops[perm[i-1]].y;
            } else {
                curr_dx = 0 - shops[perm[N-1]].x;
                curr_dy = 0 - shops[perm[N-1]].y;
            }
            totalCost += angleBetween(prev_dx, prev_dy, curr_dx, curr_dy);
            prev_dx = curr_dx;
            prev_dy = curr_dy;
        }
        best = min(best, totalCost);
    } while(next_permutation(perm.begin(), perm.end()));
    cout << fixed << setprecision(8) << best << endl;
    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3916
final_rank: 14

code_snippet: #include<bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
#define rep(i,n) for(ll i=0;i<n;i++)
#define all(A) A.begin(),A.end()
int main() {
    ll N;
    cin >> N;
    vector<double> X(N), Y(N);
    vll P(N);
    rep(i, N) {
        cin >> X[i] >> Y[i];
        P[i] = i;
    }
    double an = 1e18;
    double PI = atan2(1.0, 1.0) * 4.0;
    do {
        double res = 0.0;
        double x = 0, y = 0, t = 0;
        rep(i, N) {
            double dx = X[P[i]]-x;
            double dy = Y[P[i]]-y;
            double nt = atan2(dy, dx);
            double nr = 1e18;
            for (ll i = -2; i <= 2; i++) {
                nr = min(nr, abs(t - nt + double(2 * i) * PI));
                nr = min(nr, abs(nt - t + double(2 * i) * PI));
            }
            res += nr;
            x = X[P[i]];
            y = Y[P[i]];
            t = nt;
        }
        double nr = 1e18;
        for (ll i = -2; i <= 2; i++) {
            nr = min(nr, abs(t - atan2(-y, -x) + double(2 * i) * PI));
        }
        res += nr;
        an = min(an, res / PI * 180.0);
    } while (next_permutation(all(P)));
    cout << fixed << setprecision(15);
    cout << an << endl;
}
accuracy: 1
time_ms: 10
memory_kb: 3860
final_rank: 13

code_snippet: #include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>
#include<limits>

using namespace std;

#define int long long
#define endl "\n"

const long long INF = (long long)1e18;
const long long MOD = (long long)1e9 + 7; 

string yn(bool f){return f?"Yes":"No";}
string YN(bool f){return f?"YES":"NO";}

#define x first
#define y second

long double angle(pair<int,int> a, pair<int,int> b){
	static long double PI = acos(-1);
	long double inner_product = a.x*b.x + a.y*b.y, absa = sqrt(a.x*a.x + a.y*a.y), absb = sqrt(b.x*b.x + b.y*b.y);
	long double c = inner_product/(absa*absb);
	return fabs(acos(c)/PI)*180;
}

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	
	int n;
	vector<int>  per;
	vector<pair<long double, long double>> shop;
	long double ans = numeric_limits<long double>::max();
	
	cin>>n;
	
	shop.resize(n+1);
	per.resize(n+2);
	
	for(int i = 1; i <= n; per[i] = i, i++)
		cin>>shop[i].x>>shop[i].y;
	
	do{
		long double sum = 0;
		pair<long long, long long> nd, d = {1,0};
		
		for(int i = 0; i <= n; d = nd, i++){
			nd = make_pair(shop[per[i+1]].x - shop[per[i]].x, shop[per[i+1]].y - shop[per[i]].y);
			sum += angle(d,nd);
		}
		
		ans = min(ans, sum);
		
	} while(next_permutation(per.begin()+1, per.end()-1));
	
	cout<<ans<<endl;
	
	return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 3360
final_rank: 5

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

using CP = complex<long double>;
#define X real()
#define Y imag()
const long double PI = acos(-1);
const long double EPS = 1e10;
// conj(x) : complex conjugate,(0,1)->(0,-1)
// abs(x) : dist between(0,0) and x
// norm(x) : abs(x) * abs(x)
// arg(x) : argment
long double dot(CP a, CP b) { return (a * conj(b)).X; }
long double cross(CP a, CP b) { return (a * conj(b)).Y; }
long double corner(CP a, CP b) {
  //[0,pi]
  return acos(dot(a, b) / (abs(a) * abs(b)));
}

int n;
vector<CP> v;

long double solve();
long double calc(CP &nowv, CP &nowp, CP nextp);

int main() {
  cin >> n;
  for(int i = 0; i < n; ++i) {
    int x, y;
    cin >> x >> y;
    v.push_back(CP(x, y));
  }
  cout << fixed << setprecision(10);
  cout << solve() << endl;
  return 0;
}
long double solve() {
  vector<int> perm;
  long double ans = 1e10;
  for(int i = 0; i < n; ++i) perm.push_back(i);
  do {
    long double nowans = 0;
    CP nowv(1, 0), nowp(0, 0);
    for(int i = 0; i < n; ++i)
      nowans += calc(nowv, nowp, v[perm[i]]);
    nowans += calc(nowv, nowp, CP(0, 0));
    ans = min(nowans, ans);
  } while(next_permutation(perm.begin(), perm.end()));
  return ans / (2 * PI) * 360.0;
}

long double calc(CP &nowv, CP &nowp, CP nextp) {
  long double ans = corner(nowv, nextp - nowp);
  if(ans != 0) nowv = nextp - nowp;
  nowp = nextp;
  return ans;
}
accuracy: 1
time_ms: 60
memory_kb: 3336
final_rank: 15

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

using CP = complex<long double>;
#define X real()
#define Y imag()
const long double PI = acos(-1);
const long double EPS = 1e10;
// conj(x) : complex conjugate,(0,1)->(0,-1)
// abs(x) : dist between(0,0) and x
// norm(x) : abs(x) * abs(x)
// arg(x) : argment
long double dot(CP a, CP b) { return (a * conj(b)).X; }
long double cross(CP a, CP b) { return (a * conj(b)).Y; }
long double corner(CP a, CP b) {
  //[0,pi]
  return acos(dot(a, b) / (abs(a) * abs(b)));
}

int n;
vector<CP> v;

long double solve();
long double calc(CP &nowv, CP &nowp, CP nextp);

int main() {
  cin >> n;
  for(int i = 0; i < n; ++i) {
    int x, y;
    cin >> x >> y;
    v.push_back(CP(x, y));
  }
  cout << fixed << setprecision(10);
  cout << solve() << endl;
  return 0;
}
long double solve() {
  vector<int> perm;
  long double ans = 1e10;
  for(int i = 0; i < n; ++i) perm.push_back(i);
  do {
    long double nowans = 0;
    CP nowv(1, 0), nowp(0, 0);
    for(int i = 0; i < n; ++i)
      if(nowv != v[perm[i]] - nowp)
        nowans += calc(nowv, nowp, v[perm[i]]);
    nowans += calc(nowv, nowp, CP(0, 0));
    ans = min(nowans, ans);
  } while(next_permutation(perm.begin(), perm.end()));
  return ans / (2 * PI) * 360.0;
}

long double calc(CP &nowv, CP &nowp, CP nextp) {
  long double ans = corner(nowv, nextp - nowp);
  nowv = nextp - nowp;
  nowp = nextp;
  return ans;
}
accuracy: 0.35
time_ms: 40
memory_kb: 3332
final_rank: 16

code_snippet: #include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}


template<typename F>
struct FixPoint : F{
  FixPoint(F&& f):F(forward<F>(f)){}
  template<typename... Args>
  decltype(auto) operator()(Args&&... args) const{
    return F::operator()(*this,forward<Args>(args)...);
  }
};
template<typename F>
inline decltype(auto) MFP(F&& f){
  return FixPoint<F>{forward<F>(f)};
}


struct FastIO{
  FastIO(){
    cin.tie(0);
    ios::sync_with_stdio(0);
  }
}fastio_beet;


struct Precision{
  Precision(){
    cout<<fixed<<setprecision(12);
  }
}precision_beet;

//INSERT ABOVE HERE

using D = double;
const D PI = asin(1)*2;
D dot(D x1,D y1,D x2,D y2){
  return x1*x2+y1*y2;
}

signed main(){
  int n;
  cin>>n;
  vector<D> xs(n),ys(n);
  for(int i=0;i<n;i++) cin>>xs[i]>>ys[i];
  xs.emplace_back(0);
  ys.emplace_back(0);
  xs.emplace_back(-1);
  ys.emplace_back(0);

  vector<int> vs(n+3,n),used(n,0);
  vs[0]=n+1;

  D ans=1e9;
  auto check=
    [&](){
      D res=0;
      for(int i=0;i+2<n+3;i++){
        D dx=xs[vs[i+1]]-xs[vs[i+0]],dy=ys[vs[i+1]]-ys[vs[i+0]];
        D nx=xs[vs[i+2]]-xs[vs[i+1]],ny=ys[vs[i+2]]-ys[vs[i+1]];
        D th=acos(min(1.0,max(dot(dx,dy,nx,ny)/hypot(dx,dy)/hypot(nx,ny),
                          -1.0)));
        //cout<<dx<<" "<<dy<<":"<<nx<<" "<<ny<<":"<<th<<endl;
        res+=abs(th)/PI*180;
      }
      chmin(ans,res);
    };

  MFP([&](auto dfs,int d)->void{
        if(d==n+2){
          check();
          return;
        }
        for(int i=0;i<n;i++){
          if(used[i]) continue;
          used[i]=1;
          vs[d]=i;
          dfs(d+1);
          used[i]=0;
        }
      })(2);

  cout<<ans<<endl;
  return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 3456
final_rank: 9

code_snippet: #pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

using ll = long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;

template <class T> inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;}
template <class T> inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;}

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;
constexpr double pi = acos(-1);
constexpr double EPS = 1e-10;

int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};

double todeg(double ang){
    return ang * 180 / pi;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n; cin>>n;
    vector<int> x(n), y(n);
    for(int i=0; i<n; i++) cin>>x[i]>>y[i];
    vector<int> perm(n);
    iota(perm.begin(), perm.end(), 0);

    double ans = inf;
    do{
        vector<P> points;
        points.emplace_back(0, 0);
        for(auto i : perm) points.emplace_back(x[i], y[i]);
        points.emplace_back(0, 0);

        double theta = 0, sum = 0;
        for(int i=0; i<=n; i++){
            int dx = points[i+1].first - points[i].first;
            int dy = points[i+1].second - points[i].second;

            double cur_theta = atan2(dy, dx);

            sum += todeg(min(abs(theta - cur_theta), 2 * pi - abs(theta - cur_theta)));
            theta = cur_theta;
        }

        chmin(ans, sum);
    }while(next_permutation(perm.begin(), perm.end()));

    printf("%.10f\n", ans);

    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3408
final_rank: 2

code_snippet: #pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

using ll = long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;

template <class T> inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;}
template <class T> inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;}

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;
constexpr double pi = acos(-1);
constexpr double EPS = 1e-10;

int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};

typedef complex<double> Point, Vector;
#define X real()
#define Y imag()

double todeg(double ang){
    return ang * 180 / pi;
}

double dot(Vector a, Vector b){
    return a.X * b.X + a.Y * b.Y;
}

double norm(Vector a){
    return a.X * a.X + a.Y * a.Y;
}

double abs(Vector a){
    return sqrt(norm(a));
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n; cin>>n;
    vector<double> x(n), y(n);
    for(int i=0; i<n; i++) cin>>x[i]>>y[i];
    vector<int> v(n);
    iota(v.begin(), v.end(), 0);

    double ans = inf;
    do{
        double sum = 0, tmpcos;
        Point cp = Point(0, 0), pp = Point(1, 0), np = Point(x[v[0]], y[v[0]]);
        Vector v1 = pp - cp, v2 = np - cp;
        tmpcos = dot(v1, v2) / (abs(v1) * abs(v2));
        sum += todeg(acos(tmpcos));
        pp = cp, cp = np;
        for(int i=1; i<n; i++){
            np = Point(x[v[i]], y[v[i]]);
            v1 = cp - pp, v2 = np - cp;
            tmpcos = dot(v1, v2) / (abs(v1) * abs(v2));
            sum += todeg(acos(tmpcos));
            pp = cp, cp = np;
        }
        np = Point(0, 0);
        v1 = cp - pp, v2 = np - cp;
        tmpcos = dot(v1, v2) / (abs(v1) * abs(v2));
        sum += todeg(acos(tmpcos));

        chmin(ans, sum);

    }while(next_permutation(v.begin(), v.end()));

    printf("%.10f\n", ans);

    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3464
final_rank: 3

code_snippet: #include <bits/stdc++.h>

using namespace std;

#define PI acos(-1.0)

int main(){
  int n; cin >> n;
  vector<pair<int, int> > xy(n);
  for (int i = 0; i < n; ++i) cin >> xy[i].first >> xy[i].second;
  sort(xy.begin(), xy.end());
  double alpha = 0, ans = 1e18;
  do {
    alpha = atan2(xy[0].second, xy[0].first);
    if (alpha < 0) alpha += 2 * PI;
    double tmp = min(alpha, 2 * PI - alpha);
    for (int i = 1; i < n; ++i) {
      double t = atan2(xy[i].second - xy[i - 1].second, xy[i].first - xy[i - 1].first);
      if (t < 0) t += 2 * PI;
      tmp += min(abs(alpha - t),2 * PI- abs(alpha - t));
      alpha = t;
    }
    double t = atan2(-xy[n - 1].second, -xy[n - 1].first);
    if (t < 0) t += 2 * PI;
    tmp += min(abs(alpha - t), 2 * PI - abs(alpha - t));
    ans = min(ans, tmp);
  } while (next_permutation(xy.begin(), xy.end()));
  printf("%.10f\n", ans * 180.0 / PI);
  
  return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3376
final_rank: 1

code_snippet: #include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;



struct Point{
	Point(double arg_x,double arg_y){
		x = arg_x;
		y = arg_y;
	}

	Point(){
		x = y = 0.0;
	}

	Point operator + (Point p){ return Point(x+p.x,y+p.y); }
	Point operator - (Point p){ return Point(x-p.x,y-p.y);}
	Point operator * (double a){ return Point(a*x,a*y); }
	Point operator / (double a){ return Point(x/a,y/a); }

	double abs(){ return sqrt(norm()); }
	double norm(){ return x*x + y*y; }

	bool operator<(const Point &p) const{
		return x != p.x? x < p.x: y < p.y;
	}

	bool operator == (const Point &p) const{
		return fabs(x-p.x) < EPS && fabs(y-p.y) < EPS;
	}

	double x,y;
};

typedef Point Vector;
int N;
Point point[8];

double norm(Vector a){
	return a.x*a.x+a.y*a.y;
}

double abs(Vector a){
	return sqrt(norm(a));
}

double cross(Vector a,Vector b){
    return a.x*b.y-a.y*b.x;
}

double dot(Vector a,Vector b){
    return a.x*b.x + a.y*b.y;
}


int main(){

	scanf("%d",&N);

	for(int i = 0; i < N; i++){

		scanf("%lf %lf",&point[i].x,&point[i].y);
	}

	int table[N];
	for(int i = 0; i < N; i++){

		table[i] = i;
	}

	double ans = BIG_NUM;

	do{

		Point pre;
		pre.x = 0;
		pre.y = 0;

		double tmp = 0;

		Vector vec,next_vec;
		vec.x = 1;
		vec.y = 0;

		for(int i = 0; i < N; i++){

			next_vec = point[table[i]]-pre;

			tmp += fabs(acos(dot(next_vec,vec)/(abs(next_vec)*abs(vec))));

			pre = point[table[i]];
			vec = next_vec;
		}

		//家に帰る
		double x = 0;
		double y = 0;

		next_vec.x = x-pre.x;
		next_vec.y = y-pre.y;

		tmp += fabs(acos(dot(next_vec,vec)/(abs(next_vec)*abs(vec))));

		ans = min(ans,tmp);

	}while(next_permutation(table,table+N));

	printf("%.10lf\n",(ans*180)/M_PI);

	return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3532
final_rank: 8

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

double PI2 = acos(-1) * 2;
double normal(double a){
    while(a >= PI2) a -= PI2;
    while(a < 0) a += PI2;
    return a;
}

int main() {
    int N;
    int X[9], Y[9];
    cin >> N;
    for(int i=0; i<N; i++) cin >> X[i] >> Y[i];
    X[N] = Y[N] = 0;

    double ans = 1e18;
    vector<int> order(N+1);
    for(int i=0; i<=N; i++) order[i] = i;

    do{
        double res = 0;
        int x = 0, y = 0;
        double ang = 0;
        for(int i : order){
            double a = atan2(Y[i]-y, X[i]-x);
            res += min(normal(a-ang), normal(ang-a));
            x = X[i];
            y = Y[i];
            ang = a;
        }
        ans = min(ans, res);
    }while(next_permutation(order.begin(), order.end()-1));
    ans *= 360 / PI2;
    cout << fixed << setprecision(10) << ans << endl;
    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3600
final_rank: 10

code_snippet: #include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#ifndef LOCAL
#define debug(x) ;
#else
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

template <typename T1, typename T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &p) {
  out << "{" << p.first << ", " << p.second << "}";
  return out;
}

template <typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << '{';
  for (const T &item : v) out << item << ", ";
  out << "\b\b}";
  return out;
}
#endif

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 200010

typedef double P_type; //座標(integer or real)
typedef double G_real; //実数の戻り値(float or double or long double)
typedef complex<P_type> P;
const G_real P_eps = 1e-8; //整数の時はゼロ

namespace std{
  template<class T> bool operator<(const complex<T> &a, const complex<T> &b){
    return abs(a.real() - b.real()) < P_eps ? a.imag() + P_eps < b.imag() : a.real() + P_eps < b.real();
  }
};

P rotate(P p, double theta){
  return p * P(cos(theta), sin(theta));
}

//内積
P_type dot(P a, P b) {
  return (a * conj(b)).real();
}

//外積
P_type cross(P a, P b) {
  return (conj(a) * b).imag();
}

//反時計回り
int ccw(P a, P b, P c){
  if(cross(b-a, c-a) > P_eps) return 1; //COUNTER_CLOCKWISE(center:a)
  if(cross(b-a, c-a) < -P_eps) return -1; //CLOCKWISE(center:a)
  if(dot(b-a, c-a) < -P_eps) return -2; //c -> a -> b
  if(dot(a-b, c-b) < -P_eps) return 2; //a -> b -> c
  return 0; //a -> c -> b
}

// a -> b -> c
P_type degree(P a, P b, P c) {
  c = c - b;
  a = b - a;
  return atan2(cross(c, a), dot(c, a)) / M_PI * 180;
}

int main(){
  int N, x[8], y[8];
  P points[11];

  cin >> N;

  for(int i=0; i<N; i++) {
    cin >> x[i] >> y[i];
    points[i+1] = P(x[i], y[i]);
  }

  int p[N+3];
  iota(p, p+N+3, 0);
  points[0] = P(0, 0);
  points[N+1] = P(0, 0);
  points[N+2] = P(-1, 0);

  double ans = 1e18;

  do{
    double sum = 0;

    for(int i=N+1; i>=1; i--) {
      sum += abs(degree(points[p[i+1]], points[p[i]], points[p[i-1]]));
    }

    ans = min(ans, sum);

  }while(next_permutation(p+1, p+N+1));

  printf("%.10lf\n", ans);

  return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3472
final_rank: 4

code_snippet: #include <bits/stdc++.h>
using namespace std;
using int64 = long long;
#define int int64
#define debug(x) cerr<<#x<<":"<<x<<endl;

using Pos = pair<int,int>;

long double getLen(Pos a, Pos b) {
  return sqrt(pow(a.first-b.first, 2) + pow(a.second-b.second,2));
}

signed main() {
  int n;cin>>n;
  vector<long double> x(n),y(n);
  for(int i=0;i<n;++i){
    cin>>x[i]>>y[i];
  }

  long double ans = 1e9+1;
  
  vector<int> par(n);
  iota(par.begin(), par.end(), 0);
  do {
    vector<long double> angles(n);
    
    long double bx=0.0, by=0.0;
    for(int i=0;i<=n;++i){
      long double nx, ny;
      if (i==n) nx=0.0, ny=0.0;
      else nx = x[par[i]], ny = y[par[i]];
      // get angle A
      long double x = nx - bx;
      long double y = ny - by;
      long double angle;

      if(x==0 && y==0) {
        if (angles.empty()) angle = 0.0;
        else angle = angles.back();
      } else if(x==0) {
        if(y>0) angle = 90.0;
        else angle = 270.0;
      } else if(y==0) {
        if(x>0) angle = 0.0;
        else angle = 180.0;
      } else {
        angle = 180.0 * atan(y/x) / (atan(1.0)*4.0);
        if(x<0) angle -= 180.0;
      }
      
      while(angle<0) angle += 360.0;
      angles.emplace_back(angle);

      bx = nx;
      by = ny;
    }
    
    long double tmp = 0.0;
    for(int i=0;i<angles.size()-1;++i){
      long double diff = angles[i+1]-angles[i];
      while(diff<0) diff += 360.0;
      tmp += diff;
    }
    //debug(tmp);
    ans = min(ans, tmp);
  } while(next_permutation(par.begin(), par.end()));

  cout<<fixed<<setprecision(10)<<ans<<endl;
  return 0;
}
accuracy: 0.25
time_ms: 10
memory_kb: 3300
final_rank: 19

code_snippet: #include <iomanip>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <complex>

using Real = long double;
using std::complex;
using std::vector;
using Complex = complex<Real>;

struct Fout {
    int precision;
    Fout(int precision) : precision(precision) {}
};
std::ostream& operator<<(std::ostream& os, const Fout& fio) {
    os << std::fixed << std::setprecision(fio.precision);
    return os;
}

const Real PI = acos(-1);

int fact(int n) {
    return n == 0 ? 1 : n * fact(n - 1);
}

int main() {
    int n;
    std::cin >> n;

    vector<Complex> xs(n);
    for (auto& x : xs) {
        Real a, b;
        std::cin >> a >> b;
        x = Complex(a, b);
    }
    xs.emplace(xs.begin(), 0);
    xs.emplace_back(0);

    Real ans = 1e100;
    for (int q = 0; q < fact(n); ++q) {
        Real theta = 0, sum = 0;
        for (int i = 0; i <= n; ++i) {
            Real phi = std::arg(xs[i + 1] - xs[i]);
            Real delta = std::abs(theta - phi);
            sum += std::min(delta, 2 * PI - delta) * 180 / PI;
            theta = phi;
        }
        ans = std::min(ans, sum);
        std::next_permutation(xs.begin() + 1, xs.end() - 1,
                              [](Complex a, Complex b) { return a.real() < b.real(); });
    }

    std::cout << Fout(10) << ans << std::endl;
    return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 3360
final_rank: 5

code_snippet: #include <bits/stdc++.h>
using namespace std;
using int64 = long long;
#define int int64
#define debug(x) cerr<<#x<<":"<<x<<endl;

using Pos = pair<int,int>;

long double getLen(Pos a, Pos b) {
  return sqrt(pow(a.first-b.first, 2) + pow(a.second-b.second,2));
}

signed main() {
  int n;cin>>n;
  vector<long double> x(n),y(n);
  for(int i=0;i<n;++i){
    cin>>x[i]>>y[i];
  }

  long double ans = 1e9+1;
  
  vector<int> par(n);
  iota(par.begin(), par.end(), 0);
  do {
    vector<long double> angles(n);
    
    long double bx=0.0, by=0.0;
    for(int i=0;i<=n;++i){
      long double nx, ny;
      if (i==n) nx=0.0, ny=0.0;
      else nx = x[par[i]], ny = y[par[i]];
      // get angle A
      long double x = nx - bx;
      long double y = ny - by;
      long double angle;

      if(x==0 && y==0) {
        if (angles.empty()) angle = 0.0;
        else angle = angles.back();
      } else if(x==0) {
        if(y>0) angle = 90.0;
        else angle = 270.0;
      } else if(y==0) {
        if(x>0) angle = 0.0;
        else angle = 180.0;
      } else {
        angle = 180.0 * atan(y/x) / (atan(1.0)*4.0);
        if(x<0) angle -= 180.0;
      }
      
      while(angle<0) angle += 360.0;
      angles.emplace_back(angle);

      bx = nx;
      by = ny;
    }
    
    long double tmp = 0.0;
    for(int i=0;i<angles.size()-1;++i){
      long double diff = angles[i+1]-angles[i];
      while(diff<0) diff += 360.0;
      tmp += diff;
    }
    //debug(tmp);
    ans = min(ans, tmp);
  } while(next_permutation(par.begin(), par.end()));

  cout<<fixed<<setprecision(5)<<ans<<endl;
  return 0;
}
accuracy: 0.25
time_ms: 10
memory_kb: 3360
final_rank: 20

code_snippet: #include <bits/stdc++.h>
using namespace std;
using int64 = long long;
#define int int64
#define debug(x) cerr<<#x<<":"<<x<<endl;

using Pos = pair<int,int>;

long double getLen(Pos a, Pos b) {
  return sqrt(pow(a.first-b.first, 2) + pow(a.second-b.second,2));
}

signed main() {
  int n;cin>>n;
  vector<long double> x(n),y(n);
  for(int i=0;i<n;++i){
    cin>>x[i]>>y[i];
  }

  long double ans = 1e9+1;
  
  vector<int> par(n);
  iota(par.begin(), par.end(), 0);
  do {
    vector<long double> angles(n);
    
    long double bx=0.0, by=0.0;
    for(int i=0;i<=n;++i){
      long double nx, ny;
      if (i==n) nx=0.0, ny=0.0;
      else nx = x[par[i]], ny = y[par[i]];
      // get angle A
      long double x = nx - bx;
      long double y = ny - by;
      long double angle;

      if(x==0 && y==0) {
        if (angles.empty()) angle = 0.0;
        else angle = angles.back();
      } else if(x==0) {
        if(y>0) angle = 90.0;
        else angle = 270.0;
      } else if(y==0) {
        if(x>0) angle = 0.0;
        else angle = 180.0;
      } else {
        angle = 180.0 * atan(y/x) / (atan(1.0)*4.0);
        if(y<0) angle -= 180.0;
      }
      
      while(angle<0) angle += 360.0;
      angles.emplace_back(angle);

      bx = nx;
      by = ny;
    }
    
    long double tmp = 0.0;
    for(int i=0;i<angles.size()-1;++i){
      long double diff = angles[i+1]-angles[i];
      while(diff<0) diff += 360.0;
      tmp += diff;
    }
    //debug(tmp);
    ans = min(ans, tmp);
  } while(next_permutation(par.begin(), par.end()));

  cout<<fixed<<setprecision(5)<<ans<<endl;
  return 0;
}
accuracy: 0.25
time_ms: 10
memory_kb: 3288
final_rank: 17

code_snippet: #include <bits/stdc++.h>
using namespace std;
using int64 = long long;
#define int int64
#define debug(x) cerr<<#x<<":"<<x<<endl;

using Pos = pair<int,int>;

long double getLen(Pos a, Pos b) {
  return sqrt(pow(a.first-b.first, 2) + pow(a.second-b.second,2));
}

signed main() {
  int n;cin>>n;
  vector< Pos > pos(n);
  for(int i=0;i<n;++i){
    int x,y;cin>>x>>y;
    pos[i] = make_pair(x,y);
  }

  long double ans = 1e9+1;
  
  vector<int> par(n);
  iota(par.begin(), par.end(), 0);
  do {
    vector<long double> angles(n);
    
    Pos A = make_pair(0.0, 0.0);
    Pos B;
    for(int i=0;i<=n;++i){
      B = pos[par[i]];
      if (i==n) B = make_pair(0.0, 0.0);

      // get angle A
      long double x = B.first - A.first;
      long double y = B.second - A.second;
      long double angle;

      if(x==0 && y==0) {
        angle = angles.back();
      } else if(x==0) {
        if(y>0) angle = 90.0;
        else angle = 270.0;
      } else if(y==0) {
        if(x>0) angle = 0.0;
        else angle = 180.0;
      } else {
        angle = 180.0 * atan(y/x) / (atan(1.0)*4.0);
        if(y<0) angle -= 180.0;
      }
      
      while(angle<0) angle += 360.0;
      angles.emplace_back(angle);

      A = B;
    }
    
    long double tmp = 0.0;
    for(int i=0;i<angles.size()-1;++i){
      long double diff = angles[i+1]-angles[i];
      while(diff<0) diff += 360.0;
      tmp += diff;
    }
    ans = min(ans, tmp);
  } while(next_permutation(par.begin(), par.end()));

  cout<<fixed<<setprecision(5)<<ans<<endl;
  return 0;
}
accuracy: 0.25
time_ms: 10
memory_kb: 3296
final_rank: 18

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

#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define lfs <<fixed<<setprecision(10)<<
#define test cout<<"test"<<endl;
#define fi first
#define se second
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define rep(i,n,m) for(ll i = n; i < (ll)(m); i++)
#define rrep(i,n,m) for(ll i = n - 1; i >= (ll)(m); i--)
typedef long long ll;
typedef long double ld;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
template<typename T>
void chmin(T &a,T b){if(a>b)a=b;}
template<typename T>
void chmax(T &a,T b){if(a<b)a=b;}
void pmod(ll &a,ll b){a=(a+b)%MOD;}
void pmod(ll &a,ll b,ll c){a=(b+c)%MOD;}
void qmod(ll &a,ll b){a=(a*b)%MOD;}
void qmod(ll &a,ll b,ll c){a=(b*c)%MOD;}
ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
template<typename T1,typename T2>
void ans(bool x,T1 y,T2 z){if(x)cout<<y<<endl;else cout<<z<<endl;}  
template<typename T>
void debug(vector<vector<T>>v,ll h,ll w){for(ll i=0;i<h;i++)
{cout<<v[i][0];for(ll j=1;j<w;j++)cout spa v[i][j];cout<<endl;}};
void debug(vector<string>v,ll h,ll w){for(ll i=0;i<h;i++)
{for(ll j=0;j<w;j++)cout<<v[i][j];cout<<endl;}};
template<typename T>
void debug(vector<T>v,ll n){cout<<v[0];
for(ll i=1;i<n;i++)cout spa v[i];cout<<endl;};
template<typename T>
vector<vector<T>>vec(ll x, ll y, T w){
  vector<vector<T>>v(x,vector<T>(y,w));return v;}
ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;}
template<typename T>
void emp(map<T,ll>&m, T x){m.emplace(x,0).first->second++;}
vector<ll>dx={1,0,-1,0,1,1,-1,-1};
vector<ll>dy={0,1,0,-1,1,-1,1,-1};
template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}
using Real = long double;
using Point = complex< Real >;
const Real EPS = 1e-9, PI = acos(-1);

inline bool eq(Real a, Real b) { return fabs(b - a) < EPS; }

Point operator*(const Point &p, const Real &d) {
  return Point(real(p) * d, imag(p) * d);
}

istream &operator>>(istream &is, Point &p) {
  Real a, b;
  is >> a >> b;
  p = Point(a, b);
  return is;
}

ostream &operator<<(ostream &os, Point &p) {
  os << fixed << setprecision(10) << p.real() << " " << p.imag();
}

Point rotate(Real theta, const Point &p) {
  return Point(cos(theta) * p.real() - sin(theta) * p.imag(), sin(theta) * p.real() + cos(theta) * p.imag());
}

Real radian_to_degree(Real r) {
  return (r * 180.0 / PI);
}

Real degree_to_radian(Real d) {
  return (d * PI / 180.0);
}

Real get_angle(const Point &a, const Point &b, const Point &c) {
  const Point v(a - b), w(c - b);
  Real alpha = atan2(v.imag(), v.real()), beta = atan2(w.imag(), w.real());
  if(alpha > beta) swap(alpha, beta);
  Real theta = (beta - alpha);
  return min(theta, 2 * acos(-1) - theta);
}

Real get_angle2(const Point &a, const Point &b, const Point &c) {
  const Point v(b - a), w(c - b);
  Real alpha = atan2(v.imag(), v.real()), beta = atan2(w.imag(), w.real());
  if(alpha > beta) swap(alpha, beta);
  Real theta = (beta - alpha);
  return min(theta, 2 * acos(-1) - theta);
}

namespace std {
  bool operator<(const Point &a, const Point &b) {
    return a.real() != b.real() ? a.real() < b.real() : a.imag() < b.imag();
  }
}


struct Line {
  Point a, b;

  Line() = default;

  Line(Point a, Point b) : a(a), b(b) {}

  Line(Real A, Real B, Real C) // Ax + By = C
  {
    if(eq(A, 0)) a = Point(0, C / B), b = Point(1, C / B);
    else if(eq(B, 0)) b = Point(C / A, 0), b = Point(C / A, 1);
    else a = Point(0, C / B), b = Point(C / A, 0);
  }

  friend ostream &operator<<(ostream &os, Line &p) {
    return os << p.a << " to " << p.b;
  }

  friend istream &operator>>(istream &is, Line &a) {
    return is >> a.a >> a.b;
  }
};

struct Segment : Line {
  Segment() = default;

  Segment(Point a, Point b) : Line(a, b) {}
};

struct Circle {
  Point p;
  Real r;

  Circle() = default;

  Circle(Point p, Real r) : p(p), r(r) {}
};

using Points = vector< Point >;
using Polygon = vector< Point >;
using Segments = vector< Segment >;
using Lines = vector< Line >;
using Circles = vector< Circle >;

Real cross(const Point &a, const Point &b) {
  return real(a) * imag(b) - imag(a) * real(b);
}

Real dot(const Point &a, const Point &b) {
  return real(a) * real(b) + imag(a) * imag(b);
}

// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_1_C
// 3点の位置関係を出力
int ccw(const Point &a, Point b, Point c) {
  b = b - a, c = c - a;
  if(cross(b, c) > EPS) return +1;  // "COUNTER_CLOCKWISE"
  if(cross(b, c) < -EPS) return -1; // "CLOCKWISE"
  if(dot(b, c) < 0) return +2;      // "ONLINE_BACK"
  if(norm(b) < norm(c)) return -2;  // "ONLINE_FRONT"
  return 0;                         // "ON_SEGMENT"
}

// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_2_A
// 平行ならtrue
bool parallel(const Line &a, const Line &b) {
  return eq(cross(a.b - a.a, b.b - b.a), 0.0);
}

// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_2_A
bool orthogonal(const Line &a, const Line &b) {
  return eq(dot(a.a - a.b, b.a - b.b), 0.0);
}

// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_1_A
Point projection(const Line &l, const Point &p) {
  double t = dot(p - l.a, l.a - l.b) / norm(l.a - l.b);
  return l.a + (l.a - l.b) * t;
}

Point projection(const Segment &l, const Point &p) {
  double t = dot(p - l.a, l.a - l.b) / norm(l.a - l.b);
  return l.a + (l.a - l.b) * t;
}

// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_1_B
Point reflection(const Line &l, const Point &p) {
  return p + (projection(l, p) - p) * 2.0;
}

bool intersect(const Line &l, const Point &p) {
  return abs(ccw(l.a, l.b, p)) != 1;
}

bool intersect(const Line &l, const Line &m) {
  return abs(cross(l.b - l.a, m.b - m.a)) > EPS || abs(cross(l.b - l.a, m.b - l.a)) < EPS;
}

bool intersect(const Segment &s, const Point &p) {
  return ccw(s.a, s.b, p) == 0;
}

bool intersect(const Line &l, const Segment &s) {
  return cross(l.b - l.a, s.a - l.a) * cross(l.b - l.a, s.b - l.a) < EPS;
}

Real distance(const Line &l, const Point &p);

bool intersect(const Circle &c, const Line &l) {
  return distance(l, c.p) <= c.r + EPS;
}

bool intersect(const Circle &c, const Point &p) {
  return abs(abs(p - c.p) - c.r) < EPS;
}

// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_2_B
bool intersect(const Segment &s, const Segment &t) {
  return ccw(s.a, s.b, t.a) * ccw(s.a, s.b, t.b) <= 0 && ccw(t.a, t.b, s.a) * ccw(t.a, t.b, s.b) <= 0;
}

int intersect(const Circle &c, const Segment &l) {
  if(norm(projection(l, c.p) - c.p) - c.r * c.r > EPS) return 0;
  auto d1 = abs(c.p - l.a), d2 = abs(c.p - l.b);
  if(d1 < c.r + EPS && d2 < c.r + EPS) return 0;
  if(d1 < c.r - EPS && d2 > c.r + EPS || d1 > c.r + EPS && d2 < c.r - EPS) return 1;
  const Point h = projection(l, c.p);
  if(dot(l.a - h, l.b - h) < 0) return 2;
  return 0;
}

// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_7_A&lang=jp
int intersect(Circle c1, Circle c2) {
  if(c1.r < c2.r) swap(c1, c2);
  Real d = abs(c1.p - c2.p);
  if(c1.r + c2.r < d) return 4;
  if(eq(c1.r + c2.r, d)) return 3;
  if(c1.r - c2.r < d) return 2;
  if(eq(c1.r - c2.r, d)) return 1;
  return 0;
}

Real distance(const Point &a, const Point &b) {
  return abs(a - b);
}

Real distance(const Line &l, const Point &p) {
  return abs(p - projection(l, p));
}

Real distance(const Line &l, const Line &m) {
  return intersect(l, m) ? 0 : distance(l, m.a);
}

Real distance(const Segment &s, const Point &p) {
  Point r = projection(s, p);
  if(intersect(s, r)) return abs(r - p);
  return min(abs(s.a - p), abs(s.b - p));
}

// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_2_D
Real distance(const Segment &a, const Segment &b) {
  if(intersect(a, b)) return 0;
  return min({distance(a, b.a), distance(a, b.b), distance(b, a.a), distance(b, a.b)});
}

Real distance(const Line &l, const Segment &s) {
  if(intersect(l, s)) return 0;
  return min(distance(l, s.a), distance(l, s.b));
}

Point crosspoint(const Line &l, const Line &m) {
  Real A = cross(l.b - l.a, m.b - m.a);
  Real B = cross(l.b - l.a, l.b - m.a);
  if(eq(abs(A), 0.0) && eq(abs(B), 0.0)) return m.a;
  return m.a + (m.b - m.a) * B / A;
}

// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_2_C
Point crosspoint(const Segment &l, const Segment &m) {
  return crosspoint(Line(l), Line(m));
}

// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_7_D
pair< Point, Point > crosspoint(const Circle &c, const Line l) {
  Point pr = projection(l, c.p);
  Point e = (l.b - l.a) / abs(l.b - l.a);
  if(eq(distance(l, c.p), c.r)) return {pr, pr};
  double base = sqrt(c.r * c.r - norm(pr - c.p));
  return {pr - e * base, pr + e * base};
}

pair< Point, Point > crosspoint(const Circle &c, const Segment &l) {
  Line aa = Line(l.a, l.b);
  if(intersect(c, l) == 2) return crosspoint(c, aa);
  auto ret = crosspoint(c, aa);
  if(dot(l.a - ret.first, l.b - ret.first) < 0) ret.second = ret.first;
  else ret.first = ret.second;
  return ret;
}

// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_7_E
pair< Point, Point > crosspoint(const Circle &c1, const Circle &c2) {
  Real d = abs(c1.p - c2.p);
  Real a = acos((c1.r * c1.r + d * d - c2.r * c2.r) / (2 * c1.r * d));
  Real t = atan2(c2.p.imag() - c1.p.imag(), c2.p.real() - c1.p.real());
  Point p1 = c1.p + Point(cos(t + a) * c1.r, sin(t + a) * c1.r);
  Point p2 = c1.p + Point(cos(t - a) * c1.r, sin(t - a) * c1.r);
  return {p1, p2};
}

// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_7_F
pair< Point, Point > tangent(const Circle &c1, const Point &p2) {
  return crosspoint(c1, Circle(p2, sqrt(norm(c1.p - p2) - c1.r * c1.r)));
}

// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_7_G
Lines tangent(Circle c1, Circle c2) {
  Lines ret;
  if(c1.r < c2.r) swap(c1, c2);
  Real g = norm(c1.p - c2.p);
  if(eq(g, 0)) return ret;
  Point u = (c2.p - c1.p) / sqrt(g);
  Point v = rotate(PI * 0.5, u);
  for(int s : {-1, 1}) {
    Real h = (c1.r + s * c2.r) / sqrt(g);
    if(eq(1 - h * h, 0)) {
      ret.emplace_back(c1.p + u * c1.r, c1.p + (u + v) * c1.r);
    } else if(1 - h * h > 0) {
      Point uu = u * h, vv = v * sqrt(1 - h * h);
      ret.emplace_back(c1.p + (uu + vv) * c1.r, c2.p - (uu + vv) * c2.r * s);
      ret.emplace_back(c1.p + (uu - vv) * c1.r, c2.p - (uu - vv) * c2.r * s);
    }
  }
  return ret;
}

// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_3_B
bool is_convex(const Polygon &p) {
  int n = (int) p.size();
  for(int i = 0; i < n; i++) {
    if(ccw(p[(i + n - 1) % n], p[i], p[(i + 1) % n]) == -1) return false;
  }
  return true;
}

// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_4_A
Polygon convex_hull(Polygon &p) {
  int n = (int) p.size(), k = 0;
  if(n <= 2) return p;
  sort(p.begin(), p.end());
  vector< Point > ch(2 * n);
  for(int i = 0; i < n; ch[k++] = p[i++]) {
    while(k >= 2 && cross(ch[k - 1] - ch[k - 2], p[i] - ch[k - 1]) < 0) --k;
  }
  for(int i = n - 2, t = k + 1; i >= 0; ch[k++] = p[i--]) {
    while(k >= t && cross(ch[k - 1] - ch[k - 2], p[i] - ch[k - 1]) < 0) --k;
  }
  ch.resize(k - 1);
  return ch;
}

// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_3_C
enum {
  OUT, ON, IN
};
int contains(const Polygon &Q, const Point &p) {
  bool in = false;
  for(int i = 0; i < Q.size(); i++) {
    Point a = Q[i] - p, b = Q[(i + 1) % Q.size()] - p;
    if(a.imag() > b.imag()) swap(a, b);
    if(a.imag() <= 0 && 0 < b.imag() && cross(a, b) < 0) in = !in;
    if(cross(a, b) == 0 && dot(a, b) <= 0) return ON;
  }
  return in ? IN : OUT;
}


// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1033
void merge_segments(vector< Segment > &segs) {

  auto merge_if_able = [](Segment &s1, const Segment &s2) {
    if(abs(cross(s1.b - s1.a, s2.b - s2.a)) > EPS) return false;
    if(ccw(s1.a, s2.a, s1.b) == 1 || ccw(s1.a, s2.a, s1.b) == -1) return false;
    if(ccw(s1.a, s1.b, s2.a) == -2 || ccw(s2.a, s2.b, s1.a) == -2) return false;
    s1 = Segment(min(s1.a, s2.a), max(s1.b, s2.b));
    return true;
  };

  for(int i = 0; i < segs.size(); i++) {
    if(segs[i].b < segs[i].a) swap(segs[i].a, segs[i].b);
  }
  for(int i = 0; i < segs.size(); i++) {
    for(int j = i + 1; j < segs.size(); j++) {
      if(merge_if_able(segs[i], segs[j])) {
        segs[j--] = segs.back(), segs.pop_back();
      }
    }
  }
}

// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1033
vector< vector< int > > segment_arrangement(vector< Segment > &segs, vector< Point > &ps) {
  vector< vector< int > > g;
  int N = (int) segs.size();
  for(int i = 0; i < N; i++) {
    ps.emplace_back(segs[i].a);
    ps.emplace_back(segs[i].b);
    for(int j = i + 1; j < N; j++) {
      const Point p1 = segs[i].b - segs[i].a;
      const Point p2 = segs[j].b - segs[j].a;
      if(cross(p1, p2) == 0) continue;
      if(intersect(segs[i], segs[j])) {
        ps.emplace_back(crosspoint(segs[i], segs[j]));
      }
    }
  }
  sort(begin(ps), end(ps));
  ps.erase(unique(begin(ps), end(ps)), end(ps));

  int M = (int) ps.size();
  g.resize(M);
  for(int i = 0; i < N; i++) {
    vector< int > vec;
    for(int j = 0; j < M; j++) {
      if(intersect(segs[i], ps[j])) {
        vec.emplace_back(j);
      }
    }
    for(int j = 1; j < vec.size(); j++) {
      g[vec[j - 1]].push_back(vec[j]);
      g[vec[j]].push_back(vec[j - 1]);
    }
  }
  return (g);
}

// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_4_C
Polygon convex_cut(const Polygon &U, Line l) {
  Polygon ret;
  for(int i = 0; i < U.size(); i++) {
    Point now = U[i], nxt = U[(i + 1) % U.size()];
    if(ccw(l.a, l.b, now) != -1) ret.push_back(now);
    if(ccw(l.a, l.b, now) * ccw(l.a, l.b, nxt) < 0) {
      ret.push_back(crosspoint(Line(now, nxt), l));
    }
  }
  return (ret);
}

// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_3_A
Real area2(const Polygon &p) {
  Real A = 0;
  for(int i = 0; i < p.size(); ++i) {
    A += cross(p[i], p[(i + 1) % p.size()]);
  }
  return A;
}

// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_7_H
Real area2(const Polygon &p, const Circle &c) {
  if(p.size() < 3) return 0.0;
  function< Real(Circle, Point, Point) > cross_area = [&](const Circle &c, const Point &a, const Point &b) {
    Point va = c.p - a, vb = c.p - b;
    Real f = cross(va, vb), ret = 0.0;
    if(eq(f, 0.0)) return ret;
    if(max(abs(va), abs(vb)) < c.r + EPS) return f;
    if(distance(Segment(a, b), c.p) > c.r - EPS) return c.r * c.r * arg(vb * conj(va));
    auto u = crosspoint(c, Segment(a, b));
    vector< Point > tot{a, u.first, u.second, b};
    for(int i = 0; i + 1 < tot.size(); i++) {
      ret += cross_area(c, tot[i], tot[i + 1]);
    }
    return ret;
  };
  Real A = 0;
  for(int i = 0; i < p.size(); i++) {
    A += cross_area(c, p[i], p[(i + 1) % p.size()]);
  }
  return A;
}

// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_4_B
Real convex_diameter(const Polygon &p) {
  int N = (int) p.size();
  int is = 0, js = 0;
  for(int i = 1; i < N; i++) {
    if(p[i].imag() > p[is].imag()) is = i;
    if(p[i].imag() < p[js].imag()) js = i;
  }
  Real maxdis = norm(p[is] - p[js]);

  int maxi, maxj, i, j;
  i = maxi = is;
  j = maxj = js;
  do {
    if(cross(p[(i + 1) % N] - p[i], p[(j + 1) % N] - p[j]) >= 0) {
      j = (j + 1) % N;
    } else {
      i = (i + 1) % N;
    }
    if(norm(p[i] - p[j]) > maxdis) {
      maxdis = norm(p[i] - p[j]);
      maxi = i;
      maxj = j;
    }
  } while(i != is || j != js);
  return sqrt(maxdis);
}

// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_5_A
Real closest_pair(Points ps) {
  if(ps.size() <= 1) throw (0);
  sort(begin(ps), end(ps));

  auto compare_y = [&](const Point &a, const Point &b) {
    return imag(a) < imag(b);
  };
  vector< Point > beet(ps.size());
  const Real INF = 1e18;

  function< Real(int, int) > rec = [&](int left, int right) {
    if(right - left <= 1) return INF;
    int mid = (left + right) >> 1;
    auto x = real(ps[mid]);
    auto ret = min(rec(left, mid), rec(mid, right));
    inplace_merge(begin(ps) + left, begin(ps) + mid, begin(ps) + right, compare_y);
    int ptr = 0;
    for(int i = left; i < right; i++) {
      if(abs(real(ps[i]) - x) >= ret) continue;
      for(int j = 0; j < ptr; j++) {
        auto luz = ps[i] - beet[ptr - j - 1];
        if(imag(luz) >= ret) break;
        ret = min(ret, abs(luz));
      }
      beet[ptr++] = ps[i];
    }
    return ret;
  };
  return rec(0, (int) ps.size());
};
int main(){
  cin.tie(NULL);
  ios_base::sync_with_stdio(false);
  ll res=0,res1=INF,res2=-INF,buf=0;
  bool judge = true;
  ll n;cin>>n;
  vector<Point>x(n);
  ld ret=1e18;
  vector<ll>a(n);
  rep(i,0,n)a[i]=i;
  Point k(1,0);
  Point o(0,0);
  rep(i,0,n)cin>>x[i];
  ld eps=1e9;
  do{
    //debug(a,n);
    ld sumbuf=get_angle(k,o,x[a[0]]);
    sumbuf+=get_angle2(o,x[a[0]],x[a[1]]);
    rep(i,0,n-2){
      sumbuf+=get_angle2(x[a[i]],x[a[i+1]],x[a[i+2]]);
    }
    sumbuf+=get_angle2(x[a[n-2]],x[a[n-1]],o);
    //cout<<radian_to_degree(sumbuf)<<endl;
    chmin(ret,radian_to_degree(sumbuf));
  }while(next_permutation(ALL(a)));
  cout lfs ret<<endl;

  return 0;
}
accuracy: 1
time_ms: 40
memory_kb: 3404
final_rank: 12

code_snippet: #include <bits/stdc++.h>

using namespace std;
using ll = long long;
// #define int ll
using PII = pair<ll, ll>;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()

template<typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }

template<typename T> vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts) {
    return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type
fill_v(T &t, const V &v) { t=v; }
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t, const V &v ) { for(auto &e:t) fill_v(e,v); }

template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a) {
    out<<'('<<a.first<<','<<a.second<<')'; return out;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
    out<<'[';
    for(const T &i: a) out<<i<<',';
    out<<']';
    return out;
}
template<class T>
ostream &operator <<(ostream& out, const set<T>& a) {
    out<<'{';
    for(const T &i: a) out<<i<<',';
    out<<'}';
    return out;
}
template<class T, class S>
ostream &operator <<(ostream& out, const map<T,S>& a) {
    out<<'{';
    for(auto &i: a) out<<i<<',';
    out<<'}';
    return out;
}

int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0}; // DRUL
const int INF = 1<<30;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    ll n;
    cin >> n;
    vector<ll> x(n), y(n);
    REP(i, n) cin >> x[i] >> y[i];

    const double PI = acos(-1);

    vector<ll> ord(n);
    iota(ALL(ord), 0);
    double ret = LLINF;
    do {
        // cout << ord << endl;
        ll mx = 0, my = 0;
        double dir = 0, arg = 0;
        for(auto i: ord) {
            double t = atan2(y[i]-my, x[i]-mx);
            arg += min(2*PI-abs(t-dir), abs(t-dir));
            // cout << "i=" << i << " t=" << t << " " << min(2*PI-abs(t-dir), abs(t-dir)) << endl;
            dir = t;
            mx = x[i], my = y[i];
        }
        double t = atan2(0-my, 0-mx);
        arg += min(2*PI-abs(t-dir), abs(t-dir));
        // cout << "i=" << n << " t=" << t << " " << min(2*PI-abs(t-dir), abs(t-dir)) << endl;
        // cout << arg << endl;
        chmin(ret, arg);
    } while(next_permutation(ALL(ord)));

    cout << fixed << setprecision(9) << ret * 180.0 / PI << endl;

    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3516
final_rank: 7

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define rep(i, m, n) for (int i = m; i < n; ++i)

int main() {
    int N; cin >> N;
    using P = pair<int, int>;
    vector<P> S(N);
    rep(i, 0, N) {
        int x, y;
        cin >> x >> y;
        S[i] = make_pair(x, y);
    }
    function<double(double)> f = [&](double r) {
        double res = r * 180 / M_PI;
        return res;
    };
    function<int(int, int)> pos = [&](int x, int y) {
        if(x >= 0) {
            if(y >= 0) return 1;
            else return 4;
        } else {
            if(y >= 0) return 2;
            else return 3;
        }
    };
    function<double()> solve = [&]() {
        int x = 0, y = 0;
        vector<double> T = {0};
        S.push_back(make_pair(0, 0));
        rep(i, 0, N + 1) {
            int vx = S[i].first - x, vy = S[i].second - y;
            double t = atan((double)vy / vx);
            t = f(t);
            if(pos(vx, vy) != 1) t += 180;
            if(pos(vx, vy) == 4) t += 180;
            T.push_back(t);
            x = S[i].first;
            y = S[i].second;
        }
        S.pop_back();
        double res = 0;
        rep(i, 0, N + 1) {
            double add = abs(T[i + 1] - T[i]);
            if(add > 180) add = 360 - add;
            res += add;
        }
        return res;
    };
    double ans = 1e9;
    sort(S.begin(), S.end());
    do {
        ans = min(ans, solve());
    } while(next_permutation(S.begin(), S.end()));
    printf("%.10lf\n", ans);
    return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 3548
final_rank: 11