Problem:
Problem A: Approximate Circle
Consider a set of
n
points (
x
1
,
y
1
),
..., (
x
n
,
y
n
) on a Cartesian space.
Your task is to write a program for regression to a circle
x
2
+
y
2
+
a
x
+
b
y
+
c
= 0. In other words, your program should find a circle that
minimizes the error. Here the error is measured by the sum over square distances
between each point and the circle, which is given by:
Input
The input begins with a line containing one integer
n
(3 <=
n
<= 40,000). Then
n
lines follow. The
i
-th line contains
two integers
x
i
and
y
i
(0 <=
x
i
,
y
i
<= 1,000), which denote the coordinates of the
i
-th
point.
You can assume there are no cases in which all the points lie on a
straight line.
Output
Print three integers
a
,
b
and
c
,
separated by space, to show the regressed function. The output values should be
in a decimal fraction and should not contain an
error greater than 0.001.
Sample Input 1
4
0 0
100 0
100 100
0 100
Output for the Sample Input 1
-100.000 -100.000 0.000
Sample Input 2
3
0 0
10 0
5 100
Output for the Sample Input 2
-10.000 -99.750 0.000

Submitted solutions:

code_snippet: #include <cstdio>
#pragma warning(disable : 4996)
int n, x[40009], y[40009]; long double p1, p2, p3, mat[4][4], vec[4];
long double solve(long double a, long double b, long double c) {
	vec[0] = 1;
	vec[1] = a;
	vec[2] = b;
	vec[3] = c;
	long double ret = 0.0;
	for (int i = 0; i < 4; i++) {
		for (int j = 0; j < 4; j++) {
			ret += mat[i][j] * vec[i] * vec[j];
		}
	}
	return ret;
}
long double solve1(long double a, long double b) {
	long double l = -1.0e-9, r = 1.0e+9;
	for (int i = 0; i < 120; i++) {
		long double m1 = (l * 2.0 + r) / 3.0;
		long double m2 = (l + r * 2.0) / 3.0;
		if (solve(a, b, m1) > solve(a, b, m2)) l = m1;
		else r = m2;
	}
	p3 = l;
	return solve(a, b, l);
}
long double solve2(long double a) {
	long double l = -1.0e+9, r = 1.0e+9;
	for (int i = 0; i < 120; i++) {
		long double m1 = (l * 2.0 + r) / 3.0;
		long double m2 = (l + r * 2.0) / 3.0;
		if (solve1(a, m1) > solve1(a, m2)) l = m1;
		else r = m2;
	}
	p2 = l;
	return solve1(a, l);
}
long double solve3() {
	long double l = -1.0e+9, r = 1.0e+9;
	for (int i = 0; i < 120; i++) {
		long double m1 = (l * 2.0 + r) / 3.0;
		long double m2 = (l + r * 2.0) / 3.0;
		if (solve2(m1) > solve2(m2)) l = m1;
		else r = m2;
	}
	p1 = l;
	return solve2(l);
}
int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; i++) scanf("%d%d", &x[i], &y[i]);
	for (int i = 0; i < n; i++) {
		vec[0] = x[i] * x[i] + y[i] * y[i];
		vec[1] = x[i];
		vec[2] = y[i];
		vec[3] = 1;
		for (int j = 0; j < 4; j++) {
			for (int k = 0; k < 4; k++) {
				mat[j][k] += vec[j] * vec[k];
			}
		}
	}
	long double ret = solve3();
	printf("%.9Lf %.9Lf %.9Lf\n", p1, p2, p3);
	return 0;
}
accuracy: 0.02857142857142857
time_ms: 380
memory_kb: 2612
final_rank: 14

code_snippet: #include <cstdio>
int n, x[40009], y[40009]; long double p1, p2, p3, mat[4][4], vec[4];
long double solve(long double a, long double b, long double c) {
	vec[0] = 1;
	vec[1] = a;
	vec[2] = b;
	vec[3] = c;
	long double ret = 0.0;
	for (int i = 0; i < 4; i++) {
		for (int j = 0; j < 4; j++) {
			ret += mat[i][j] * vec[i] * vec[j];
		}
	}
	return ret;
}
long double solve1(long double a, long double b) {
	long double l = -1.0e-9, r = 1.0e+9;
	for (int i = 0; i < 100; i++) {
		long double m1 = (l * 2.0 + r) / 3.0;
		long double m2 = (l + r * 2.0) / 3.0;
		if (solve(a, b, m1) > solve(a, b, m2)) l = m1;
		else r = m2;
	}
	p3 = l;
	return solve(a, b, l);
}
long double solve2(long double a) {
	long double l = -1.0e+9, r = 1.0e+9;
	for (int i = 0; i < 100; i++) {
		long double m1 = (l * 2.0 + r) / 3.0;
		long double m2 = (l + r * 2.0) / 3.0;
		if (solve1(a, m1) > solve1(a, m2)) l = m1;
		else r = m2;
	}
	p2 = l;
	return solve1(a, l);
}
long double solve3() {
	long double l = -1.0e+9, r = 1.0e+9;
	for (int i = 0; i < 100; i++) {
		long double m1 = (l * 2.0 + r) / 3.0;
		long double m2 = (l + r * 2.0) / 3.0;
		if (solve2(m1) > solve2(m2)) l = m1;
		else r = m2;
	}
	p1 = l;
	return solve2(l);
}
int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; i++) scanf("%d%d", &x[i], &y[i]);
	for (int i = 0; i < n; i++) {
		vec[0] = x[i] * x[i] + y[i] * y[i];
		vec[1] = x[i];
		vec[2] = y[i];
		vec[3] = 1;
		for (int j = 0; j < 4; j++) {
			for (int k = 0; k < 4; k++) {
				mat[j][k] += vec[j] * vec[k];
			}
		}
	}
	long double ret = solve3();
	printf("%.9Lf %.9Lf %.9Lf\n", p1, p2, p3);
	return 0;
}
accuracy: 0.02857142857142857
time_ms: 220
memory_kb: 2596
final_rank: 13

code_snippet: #include <cstdio>
#pragma warning(disable : 4996)
int n, x[40009], y[40009]; double p1, p2, p3, mat[4][4], vec[4];
double solve(double a, double b, double c) {
	vec[0] = 1;
	vec[1] = a;
	vec[2] = b;
	vec[3] = c;
	double ret = 0.0;
	for (int i = 0; i < 4; i++) {
		for (int j = 0; j < 4; j++) {
			ret += mat[i][j] * vec[i] * vec[j];
		}
	}
	return ret;
}
double solve1(double a, double b) {
	double l = -1.0e-9, r = 1.0e+9;
	for (int i = 0; i < 100; i++) {
		double m1 = (l * 2.0 + r) / 3.0;
		double m2 = (l + r * 2.0) / 3.0;
		if (solve(a, b, m1) > solve(a, b, m2)) l = m1;
		else r = m2;
	}
	p3 = l;
	return solve(a, b, l);
}
double solve2(double a) {
	double l = -1.0e+9, r = 1.0e+9;
	for (int i = 0; i < 100; i++) {
		double m1 = (l * 2.0 + r) / 3.0;
		double m2 = (l + r * 2.0) / 3.0;
		if (solve1(a, m1) > solve1(a, m2)) l = m1;
		else r = m2;
	}
	p2 = l;
	return solve1(a, l);
}
double solve3() {
	double l = -1.0e+9, r = 1.0e+9;
	for (int i = 0; i < 100; i++) {
		double m1 = (l * 2.0 + r) / 3.0;
		double m2 = (l + r * 2.0) / 3.0;
		if (solve2(m1) > solve2(m2)) l = m1;
		else r = m2;
	}
	p1 = l;
	return solve2(l);
}
int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; i++) scanf("%d%d", &x[i], &y[i]);
	for (int i = 0; i < n; i++) {
		vec[0] = x[i] * x[i] + y[i] * y[i];
		vec[1] = x[i];
		vec[2] = y[i];
		vec[3] = 1;
		for (int j = 0; j < 4; j++) {
			for (int k = 0; k < 4; k++) {
				mat[j][k] += vec[j] * vec[k];
			}
		}
	}
	double ret = solve3();
	printf("%.9lf %.9lf %.9lf\n", p1, p2, p3);
	return 0;
}
accuracy: 0.02857142857142857
time_ms: 120
memory_kb: 2628
final_rank: 12

code_snippet: #include <cstdio>
#pragma warning(disable : 4996)
int n, x[40009], y[40009]; double p1, p2, p3, mat[4][4], vec[4];
double solve(double a, double b, double c) {
	vec[0] = 1;
	vec[1] = a;
	vec[2] = b;
	vec[3] = c;
	double ret = 0.0;
	for (int i = 0; i < 4; i++) {
		for (int j = 0; j < 4; j++) {
			ret += mat[i][j] * vec[i] * vec[j];
		}
	}
	return ret;
}
double solve1(double a, double b) {
	double l = -1.0e+3, r = 1.0e+3;
	for (int i = 0; i < 60; i++) {
		double m1 = (l * 2.0 + r) / 3.0;
		double m2 = (l + r * 2.0) / 3.0;
		if (solve(a, b, m1) > solve(a, b, m2)) l = m1;
		else r = m2;
	}
	p3 = l;
	return solve(a, b, l);
}
double solve2(double a) {
	double l = -1.0e+3, r = 1.0e+3;
	for (int i = 0; i < 60; i++) {
		double m1 = (l * 2.0 + r) / 3.0;
		double m2 = (l + r * 2.0) / 3.0;
		if (solve1(a, m1) > solve1(a, m2)) l = m1;
		else r = m2;
	}
	p2 = l;
	return solve1(a, l);
}
double solve3() {
	double l = -1.0e+3, r = 1.0e+3;
	for (int i = 0; i < 50; i++) {
		double m1 = (l * 2.0 + r) / 3.0;
		double m2 = (l + r * 2.0) / 3.0;
		if (solve2(m1) > solve2(m2)) l = m1;
		else r = m2;
	}
	p1 = l;
	return solve2(l);
}
int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; i++) scanf("%d%d", &x[i], &y[i]);
	for (int i = 0; i < n; i++) {
		vec[0] = x[i] * x[i] + y[i] * y[i];
		vec[1] = x[i];
		vec[2] = y[i];
		vec[3] = 1;
		for (int j = 0; j < 4; j++) {
			for (int k = 0; k < 4; k++) {
				mat[j][k] += vec[j] * vec[k];
			}
		}
	}
	double ret = solve3();
	printf("%.9lf %.9lf %.9lf\n", p1, p2, p3);
	return 0;
}
accuracy: 0.02857142857142857
time_ms: 20
memory_kb: 2600
final_rank: 11

code_snippet: #include<iostream>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<ctime>
#include<algorithm>
#include<list>
#include<queue>
#include<stack>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<string>
#define sgn(v) (abs((v))<eps?0:((v)<0?-1:1))
#define sqr(v) ((v)*(v))
#define MP make_pair
#define PB push_back
#define FI first
#define SE second
#define debug 0
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<double,int> PDI;
typedef pair<double,double> PDD;
typedef pair<int,int> PII;
typedef pair<int,LL> PIL;
typedef pair<LL,int> PLI;
typedef pair<LL,LL> PLL;
typedef long double Double;
const Double eps=1e-8;
const Double pi=acos(-1);
using namespace std;
const int maxn=4e4+100;
Double x[maxn],y[maxn];
Double a[3][3],c[3][3],b[3];
Double replace(int ix)
{
    int i,j;
    double res=0;
    for(i=0;i<3;++i)
        for(j=0;j<3;++j)c[i][j]=a[i][j];
    for(j=0;j<3;++j)c[ix][j]=b[j];
    for(i=0;i<3;++i)
    {
        res+=c[0][i]*c[1][(i+1)%3]*c[2][(i+2)%3];
        res-=c[0][i]*c[1][(i+2)%3]*c[2][(i+1)%3];
    }
    return res;
}
int main()
{
    int n,i;
	//cout <<sizeof(double)<<" "<<sizeof(long double)<<" "<<sizeof(float)<<" "<<sizeof(int)<<endl;
    scanf("%d",&n);
    memset(a,0,sizeof(a));
    memset(b,0,sizeof(b));
    for(i=0;i<n;++i)
    {
        scanf("%Lf%Lf",&x[i],&y[i]);
        b[0]+=(sqr(x[i])+sqr(y[i]))*x[i];
        b[1]+=(sqr(x[i])+sqr(y[i]))*y[i];
        b[2]+=(sqr(x[i])+sqr(y[i]));
        a[0][0]+=sqr(x[i]);a[0][1]+=x[i]*y[i];a[0][2]+=x[i];
        a[1][0]+=x[i]*y[i];a[1][1]+=sqr(y[i]);a[1][2]+=y[i];
        a[2][0]+=x[i];a[2][1]+=y[i];a[2][2]+=1;
    }
    for(i=0;i<3;++i)b[i]=-b[i];
    Double delta=0;
    for(i=0;i<3;++i)
    {
        delta+=a[0][i]*a[1][(i+1)%3]*a[2][(i+2)%3];
        delta-=a[0][i]*a[1][(i+2)%3]*a[2][(i+1)%3];
    }
    //cout <<delta<<endl;
    Double A=replace(0)/delta;
    Double B=replace(1)/delta;
    Double C=replace(2)/delta;
    printf("%.3Lf %.3Lf %.3Lf\n",A,B,C);
    //printf("%.9f %.9f %.9f\n",A,B,C);
    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 2508
final_rank: 4

code_snippet: #include<cmath>
#include<cstdio>
#include<algorithm>
 
#define rep(i,n) for(int i=0;i<(n);i++)
 
using namespace std;
 
const double EPS=1e-8;
 
const int N_MAX=3;
bool Gauss_Jordan(int n,const double A[N_MAX][N_MAX],const double *b,double *x){
    static double B[N_MAX][N_MAX+1];
    rep(i,n){
        rep(j,n) B[i][j]=A[i][j];
        B[i][n]=b[i];
    }
 
    rep(i,n){
        int piv=i;
        for(int j=i;j<n;j++) if(abs(B[j][i])>abs(B[piv][i])) piv=j;
        rep(j,n+1) swap(B[i][j],B[piv][j]);
 
        if(abs(B[i][i])<EPS) return false;
 
        for(int j=i+1;j<=n;j++) B[i][j]/=B[i][i];
        rep(j,n) if(i!=j) for(int k=i+1;k<=n;k++) B[j][k]-=B[j][i]*B[i][k];
    }
 
    rep(i,n) x[i]=B[i][n];
    return true;
}
 
int main(){
    int n; scanf("%d",&n);
    double sx=0,sy=0,sxx=0,sxy=0,syy=0,sxxx=0,sxxy=0,sxyy=0,syyy=0;
    rep(i,n){
        int x,y; scanf("%d%d",&x,&y);
        sx+=x;
        sy+=y;
        sxx+=x*x;
        sxy+=x*y;
        syy+=y*y;
        sxxx+=x*x*x;
        sxxy+=x*x*y;
        sxyy+=x*y*y;
        syyy+=y*y*y;
    }
 
double A[3][3]={
	{sxx,sxy,sx},
	{sxy,syy,sy},
	{sx,sy,double(n)}
};
    double b[3]={-sxxx-sxyy,-sxxy-syyy,-sxx-syy},x[3];
 
    Gauss_Jordan(3,A,b,x);
 
    printf("%.9f %.9f %.9f\n",x[0],x[1],x[2]);
    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 1052
final_rank: 1

code_snippet: #include<stdio.h>
#include<algorithm>
using namespace std;
double x[41000];
double y[41000];
double al,ar,bl,br,cl,cr;
int n;
double sc(double a,double b){
	double sum=0;
	for(int i=0;i<n;i++){
		sum+=x[i]*x[i]+y[i]*y[i]+a*x[i]+b*y[i];
	}
	cl=-sum/n;
	double ret=0;
	for(int i=0;i<n;i++){
		double t=x[i]*x[i]+y[i]*y[i]+a*x[i]+b*y[i]-cl;
		ret+=t*t;
	}
	return ret;
}
double sb(double a){
	bl=-10000;
	br=10000;
	for(int i=0;i<50;i++){
		double b1=(bl*2+br)/3;
		double b2=(bl+br*2)/3;
		if(sc(a,b1)<sc(a,b2))br=b2;
		else bl=b1;
	}
	return sc(a,bl);
}
int main(){
	int a;
	scanf("%d",&a);
	n=a;
	for(int i=0;i<a;i++)scanf("%lf%lf",x+i,y+i);
	al=-10000;
	ar=10000;
	bl=-10000;
	br=10000;
	cl=-1000000000;
	cr=1000000000;
	for(int i=0;i<50;i++){
		double a1=(al*2+ar)/3;
		double a2=(al+ar*2)/3;
		if(sb(a1)<sb(a2))ar=a2;
		else al=a1;
	}
	printf("%f %f %f\n",al,bl,cl);
}
accuracy: 0.02857142857142857
time_ms: 30
memory_kb: 1108
final_rank: 6

code_snippet: #include <iostream>
#include <sstream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>

using namespace std;

const int N = 40005;
const double eps = 1e-8;

struct Point {
	double x, y;
	
	void read() {
		scanf("%lf%lf", &x, &y);
	}
};
double mat[25][25];

int n;
Point p[N];

double sqr(double x) {
	return x * x;
}

void init() {
	cin >> n;
	for (int i = 1; i <= n; i ++) {
		p[i].read();
	}
}

void gauss() {
	for (int i = 1; i <= 3; i ++) {
		int best;
		double cc = -5.0;
		
		for (int j = i; j <= 3; j ++) {
			if (abs(mat[j][i]) > cc) {
				cc = abs(mat[j][i]);
				best = j;
			}
		}
		for (int j = 1; j <= 4; j ++) {
			swap(mat[i][j], mat[best][j]);
		}
		
		for (int j = i + 1; j <= 3; j ++) {
			if (abs(mat[j][i]) > eps) {
				double t = mat[i][i] / mat[j][i];
				for (int k = 1; k <= 4; k ++) {
					mat[j][k] *= t;
				}
				for (int k = 1; k <= 4; k ++) {
					mat[j][k] -= mat[i][k];
				}
			}
		}
	}
	
	double ans[5];
	for (int i = 3; i >= 1; i --) {
		if (abs(mat[i][i]) > eps) {
			ans[i] = mat[i][4] / mat[i][i];
		} else {
			ans[i] = 0.0;
		}
		for (int j = i - 1; j >= 1; j --) {
			mat[j][4] -= mat[j][i] * ans[i];
		}
	}
	
	for (int i = 1; i <= 3; i ++) {
		printf("%.3f%c", ans[i], i == 3 ? '\n' : ' ');
	}
}

void work() {
	for (int i = 1; i <= n; i ++) {
		double tmp[6];
		tmp[1] = p[i].x, tmp[2] = p[i].y;
		tmp[3] = 1.0, tmp[4] = p[i].x * p[i].x + p[i].y * p[i].y;
		
		for (int j = 1; j <= 4; j ++) {
			mat[1][j] += tmp[j] * p[i].x;
		}
		for (int j = 1; j <= 4; j ++) {
			mat[2][j] += tmp[j] * p[i].y;
		}
		for (int j = 1; j <= 4; j ++) {
			mat[3][j] += tmp[j];
		}
	}
	for (int i = 1; i <= 3; i ++) {
		mat[i][4] *= -1.0;
	}
	
	gauss();
}

int main() {
	//freopen("A.in", "r", stdin);
	//ios::sync_with_stdio(false);
	
	init(), work();
	
	return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 1904
final_rank: 2

code_snippet: #include <iostream>
#include <sstream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>

using namespace std;

const int N = 40005;
const long double eps = 1e-8;

struct Point {
	long double x, y;
	
	void read() {
		cin >> x >> y;
		//scanf("%lf%lf", &x, &y);
	}
};
long double mat[25][25];

int n;
Point p[N];

long double sqr(long double x) {
	return x * x;
}

void init() {
	cin >> n;
	for (int i = 1; i <= n; i ++) {
		p[i].read();
	}
}

void gauss() {
	for (int i = 1; i <= 3; i ++) {
		int best;
		long double cc = -5.0;
		
		for (int j = i; j <= 3; j ++) {
			if (abs(mat[j][i]) > cc) {
				cc = abs(mat[j][i]);
				best = j;
			}
		}
		for (int j = 1; j <= 4; j ++) {
			swap(mat[i][j], mat[best][j]);
		}
		
		for (int j = i + 1; j <= 3; j ++) {
			if (abs(mat[j][i]) > eps) {
				long double t = mat[i][i] / mat[j][i];
				for (int k = 1; k <= 4; k ++) {
					mat[j][k] *= t;
				}
				for (int k = 1; k <= 4; k ++) {
					mat[j][k] -= mat[i][k];
				}
			}
		}
	}
	
	long double ans[5];
	for (int i = 3; i >= 1; i --) {
		if (abs(mat[i][i]) > eps) {
			ans[i] = mat[i][4] / mat[i][i];
		} else {
			ans[i] = 0.0;
		}
		for (int j = i - 1; j >= 1; j --) {
			mat[j][4] -= mat[j][i] * ans[i];
		}
	}
	
	for (int i = 1; i <= 3; i ++) {
		printf("%.6f%c", (double)ans[i], i == 3 ? '\n' : ' ');
	}
}

void work() {
	for (int i = 1; i <= n; i ++) {
		long double tmp[6];
		tmp[1] = p[i].x, tmp[2] = p[i].y;
		tmp[3] = 1.0, tmp[4] = p[i].x * p[i].x + p[i].y * p[i].y;
		
		for (int j = 1; j <= 4; j ++) {
			mat[1][j] += tmp[j] * p[i].x;
		}
		for (int j = 1; j <= 4; j ++) {
			mat[2][j] += tmp[j] * p[i].y;
		}
		for (int j = 1; j <= 4; j ++) {
			mat[3][j] += tmp[j];
		}
	}
	for (int i = 1; i <= 3; i ++) {
		mat[i][4] *= -1.0;
	}
	
	gauss();
}

int main() {
	//freopen("A.in", "r", stdin);
	//ios::sync_with_stdio(false);
	
	init(), work();
	
	return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 2504
final_rank: 5

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

const int maxn=(int)4e4+5;

double x[maxn],y[maxn],A,B,C;
int n;

double solve(double a,double b){
    static int i;
    static double sum,ans;
    sum=0.0,A=-2.0*a,B=-2.0*b;
    for(i=0;i<n;i++)
        sum+=(x[i]-a)*(x[i]-a)+(y[i]-b)*(y[i]-b);
    sum=sum/n;
    ans=0.0;
    for(i=0;i<n;i++)
        ans+=((x[i]-a)*(x[i]-a)+(y[i]-b)*(y[i]-b)-sum)*((x[i]-a)*(x[i]-a)+(y[i]-b)*(y[i]-b)-sum);
    C=-sum+a*a+b*b;
    return ans;
}

double work(double a){
    static double l,r,m1,m2;
    static int i;
    l=0.0,r=1000.0;
    for(i=0;i<100;i++){
        m1=(r-l)/3.0;
        m2=r-m1;
        m1+=l;
        if(solve(a,m1)<solve(a,m2))r=m2;
        else l=m1;
    }
    return solve(a,(l+r)/2.0);
}

int main(){
    static int i;
    static double l,r,m1,m2;
    scanf("%d",&n);
    for(i=0;i<n;i++)
        scanf("%lf%lf",&x[i],&y[i]);
    l=0.0,r=1000.0;
    for(i=0;i<100;i++){
        m1=(r-l)/3.0;
        m2=r-m1;
        m1+=l;
        if(work(m1)<work(m2))r=m2;
        else l=m1;
    }
    work((l+r)/2.0);
    printf("%f %f %f\n",A,B,C);
    return 0;
}
accuracy: 0.02857142857142857
time_ms: 100
memory_kb: 1112
final_rank: 8

code_snippet: #include<iostream>
#include<vector>
#include<cstdio>
#include<cstdlib>
#include<cmath>

using namespace std;

#define rep(i, n) for (int i = 0; i < int(n); ++i)
#define REP(i,b,n) for(int i=b;i<n;i++)

typedef long double D;
typedef pair<D, D> P;

#define sq(x) ((x) * (x))
typedef vector<D> Vector;
typedef vector<Vector> Matrix;
 
const D EPS = 1e-8;

Vector gauss_jordan(const Matrix &A, const Vector &b){
  int n = A.size();
  Matrix B(n, Vector(n+1));
  rep(i, n){
    rep(j, n){
      B[i][j] = A[i][j];
    }
  }
 
  rep(i, n){
    B[i][n] = b[i];
  }
 
  rep(i, n){
    int pivot = i;
    REP(j, i, n){
      if(abs(B[j][i]) > abs(B[pivot][i])){
	pivot = j;
      }
    }
 
    swap(B[i], B[pivot]);
 
    if(abs(B[i][i]) < EPS)return Vector();
 
    REP(j, i+1, n+1)B[i][j] /= B[i][i];
    rep(j, n){
      if(i != j){
	REP(k, i+1, n+1){
	  B[j][k] -= B[j][i] * B[i][k];
	}
      }
    }
  }
 
  Vector x(n);
  rep(i, n)x[i] = B[i][n];
  return x;
}

int main() {
  int n;
  cin >> n;
  vector<P> vp(n);
  rep (i, n) cin >> vp[i].first >> vp[i].second;
  Matrix M;
  rep (i, 3) {
    Vector V(3);
    M.push_back(V);
  }
  Vector V(3);
  rep (i, n) {
    M[0][0] += 2 * vp[i].first * vp[i].first;
    M[0][1] += 2 * vp[i].first * vp[i].second;
    M[0][2] += 2 * vp[i].first;
    V[0] -= 2 * vp[i].first * (sq(vp[i].first) + sq(vp[i].second));
    M[1][0] += 2 * vp[i].second * vp[i].first;
    M[1][1] += 2 * vp[i].second * vp[i].second;
    M[1][2] += 2 * vp[i].second;
    V[1] -= 2 * vp[i].second * (sq(vp[i].first) + sq(vp[i].second));
    M[2][0] += 2 * vp[i].first;
    M[2][1] += 2 * vp[i].second;
    M[2][2] += 2;
    V[2] -= 2 * (sq(vp[i].first) + sq(vp[i].second));
  }
  V = gauss_jordan(M, V);
  printf("%.12Lf %.12Lf %.12Lf\n", V[0], V[1], V[2]);
  return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 2324
final_rank: 3

code_snippet: #include<iostream>
#include<vector>
#include<cstdio>
#include<cstdlib>

using namespace std;

#define rep(i, n) for (int i = 0; i < int(n); ++i)

typedef long double D;
typedef pair<D, D> P;

#define sq(x) ((x) * (x))

int main() {
  int n;
  cin >> n;
  vector<P> vp(n);
  rep (i, n) cin >> vp[i].first >> vp[i].second;
  D a = 0, b = 0, c = 0;
  D d =  10000;
  while (d > 1e-8) {
    D da = 0, db = 0, dc = 0;
    rep (i, n) {
      da += 2 * vp[i].first * (sq(vp[i].first) + sq(vp[i].second) + a * vp[i].first + b * vp[i].second + c);
      db += 2 * vp[i].second * (sq(vp[i].first) + sq(vp[i].second) + a * vp[i].first + b * vp[i].second + c);
      dc += 2 * (sq(vp[i].first) + sq(vp[i].second) + a * vp[i].first + b * vp[i].second + c);
    }
    a += d * (da > 0 ? -1 : 1);
    b += d * (db > 0 ? -1 : 1);
    c += d * (dc > 0 ? -1 : 1);
    d *= 0.999;
  }
  printf("%.12Lf %.12Lf %.12Lf\n", a, b, c);
  return 0;
}
accuracy: 0.02857142857142857
time_ms: 100
memory_kb: 1276
final_rank: 9

code_snippet: #include<iostream>
#include<vector>
#include<cstdio>
#include<cstdlib>

using namespace std;

#define rep(i, n) for (int i = 0; i < int(n); ++i)

typedef long double D;
typedef pair<D, D> P;

#define sq(x) ((x) * (x))

int main() {
  int n;
  cin >> n;
  vector<P> vp(n);
  rep (i, n) cin >> vp[i].first >> vp[i].second;
  D a = 0, b = 0, c = 0;
  D d =  1000;
  while (d > 1e-8) {
    D da = 0, db = 0, dc = 0;
    rep (i, n) {
      da += 2 * vp[i].first * (sq(vp[i].first) + sq(vp[i].second) + a * vp[i].first + b * vp[i].second + c);
      db += 2 * vp[i].second * (sq(vp[i].first) + sq(vp[i].second) + a * vp[i].first + b * vp[i].second + c);
      dc += 2 * (sq(vp[i].first) + sq(vp[i].second) + a * vp[i].first + b * vp[i].second + c);
    }
    a += d * (da > 0 ? -1 : 1);
    b += d * (db > 0 ? -1 : 1);
    c += d * (dc > 0 ? -1 : 1);
    d *= 0.999;
  }
  printf("%.12Lf %.12Lf %.12Lf\n", a, b, c);
  return 0;
}
accuracy: 0.02857142857142857
time_ms: 100
memory_kb: 1280
final_rank: 10

code_snippet: #include<iostream>
#include<vector>
#include<cstdio>
#include<cstdlib>

using namespace std;

#define rep(i, n) for (int i = 0; i < int(n); ++i)

typedef long double D;
typedef pair<D, D> P;

#define sq(x) ((x) * (x))

int main() {
  int n;
  cin >> n;
  vector<P> vp(n);
  rep (i, n) cin >> vp[i].first >> vp[i].second;
  D a = 0, b = 0, c = 0;
  D d =  1000;
  while (d > 1e-8) {
    D da = 0, db = 0, dc = 0;
    rep (i, n) {
      da += 2 * vp[i].first * (sq(vp[i].first) + sq(vp[i].second) + a * vp[i].first + b * vp[i].second + c);
      db += 2 * vp[i].second * (sq(vp[i].first) + sq(vp[i].second) + a * vp[i].first + b * vp[i].second + c);
      dc += 2 * (sq(vp[i].first) + sq(vp[i].second) + a * vp[i].first + b * vp[i].second + c);
    }
    a += d * (da > 0 ? -1 : 1);
    b += d * (db > 0 ? -1 : 1);
    c += d * (dc > 0 ? -1 : 1);
    d *= 0.99;
  }
  printf("%.12Lf %.12Lf %.12Lf\n", a, b, c);
  return 0;
}
accuracy: 0.02857142857142857
time_ms: 10
memory_kb: 1276
final_rank: 7