Go: package main

import (
	"fmt"
	"math"
	"math/cmplx"
)

func main() {
	for {
		var n int
		fmt.Scan(&n)

		if n == 0 {
			return
		}

		arr := make([]complex128, n)

		for i := 0; i < n; i++ {
			var x, y float64

			fmt.Scanf("%f%f", &x, &y)

			arr[i] = complex(x, y)
		}

		max := 1
		for i := 0; i < n; i++ {
			for j := i + 1; j < n; j++ {
				sub := arr[j] - arr[i]

				if cmplx.Abs(sub) >= 2 {
					continue
				}
				sum := arr[j] + arr[i]

				v := 1
				{
					halfd := cmplx.Abs(sub / 2)

					center := sum/2 + sub*cmplx.Rect(math.Sqrt(1-halfd*halfd)/cmplx.Abs(sub), float64(v)*math.Pi/2)

					counter := 0
					for k := 0; k < n; k++ {
						if i == k || j == k || cmplx.Abs(arr[k]-center) <= 1 {
							counter++
						}
					}
					if max < counter {
						max = counter
					}
				}

				v = -1
				{
					halfd := cmplx.Abs(sub / 2)

					center := sum/2 + sub*cmplx.Rect(math.Sqrt(1-halfd*halfd)/cmplx.Abs(sub), float64(v)*math.Pi/2)

					counter := 0
					for k := 0; k < n; k++ {
						if i == k || j == k || cmplx.Abs(arr[k]-center) <= 1 {
							counter++
						}
					}
					if max < counter {
						max = counter
					}
				}

			}
		}

		fmt.Println(max)
	}
}

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


typedef pair<double,double> Point;
#define F first
#define S second
#define MK make_pair

Point pls(Point a,Point b){
  return MK(a.F+b.F,a.S+b.S);
}

Point mns(Point a,Point b){
  return MK(a.F-b.F,a.S-b.S);
}

Point T(Point t){
  return MK(t.S,-1.0*t.F);
}

double abs(Point a){
  return sqrt(a.F*a.F+a.S*a.S);
}

Point mid(Point a,Point b){
  return MK(a.F/2+b.F/2,a.S/2+b.S/2);
}

bool in(Point c,Point t){
  if(abs(mns(t,c))<=1){return true;}
  return false;
}


int main(){
  while(1){
  int n;
  cin>>n;
  if(n==0){break;}
  vector<Point> vp;
  int mx=0;
  for(int i=0;i<n;i++){
    double a,b;
    cin>>a>>b;
    vp.push_back(MK(a,b));
  }
  sort(vp.begin(),vp.end());
  for(int i=0;i<vp.size();i++){
    for(int t=i+1;t<vp.size() && vp[t].F-vp[i].F<=2;t++){
      if(abs(mns(vp[t],vp[i]))>2){continue;}
      Point m=mid(vp[i],vp[t]);
      Point l=mns(vp[t],vp[i]);
      Point lt=T(l);
      double h=sqrt(1-abs(l)*abs(l)/4);
      lt.F=h*lt.F/abs(l);
      lt.S=h*lt.S/abs(l);
      Point c=pls(m,lt);
      int count=2;
      for(int k=0;k<vp.size();k++){
	if(k!=i && k!=t && in(c,vp[k])){count++;}
      }
      mx=max(mx,count);
    }
  }
  cout<<mx<<endl;
  }
  return 0;
}

C++: #include <iostream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <map>
#define LP(i,n) for(int i = 0; i < n; i++)

using namespace std;
typedef pair<double,double> P;

double Dist(double x1[], double x2[]){
	return pow((x1[0]-x2[0])*(x1[0]-x2[0])+(x1[1]-x2[1])*(x1[1]-x2[1]),0.5);

}

int main(){
	int n;
	cin >> n;
	while(n){
		int mx = 0;
		P p[300];
		LP(i,n){
			cin >> p[i].first >> p[i].second;
		}
		sort(p,p+n);
		double x[300][2];
		LP(i,n){
			x[i][0] = p[i].first;
			x[i][1] = p[i].second;
		}
		double dist[300][300];
		LP(i,n){
			LP(j,n){
				dist[i][j] = Dist(x[i],x[j]);
			}
		}
		LP(i,n){
			for(int j = i+1; j < n; j++){
				if(x[j][0]-x[i][0] > 2){
					break;
				}else{
					if(dist[i][j] < 2){
						double m[] = {(x[j][0]+x[i][0])/2,(x[j][1]+x[i][1])/2};
						double d[] = {x[j][1]-x[i][1],-x[j][0]+x[i][0]};
						double O[] = {0,0};
						double _d = Dist(d,O);
						LP(k,2){
							d[k] *= (pow(_d,-2)-0.25);
						}
						double o[2][2];
						LP(k,2){
							LP(l,2){
								o[k][l] = m[l];
								if(k) o[k][l] += d[l];
								else o[k][l] -= d[l];
							}
						}
						LP(k,2){
							int s = 2;
							for(int l = i+1; l < j; l++){
								if(Dist(x[l],o[k]) < 1) s++;
							}
							for(int l = i-1; 0<=l && x[i][0]-x[l][0] < 1;l--){
								if(Dist(x[l],o[k]) < 1) s++;
							}
							for(int l = j+1; l < n && x[l][0]-x[j][0] < 1; l++){
								if(Dist(x[l],o[k]) < 1) s++;
							}
							mx = max(mx,s);
						}
					}
				}
			}
		}
		if(mx == 0) mx = 1;
		cout << mx << endl;
		cin >> n;
	}
}

C++: #include<bits/stdc++.h>
#define N 300
using namespace std;
typedef complex<double> P;
const double EPS = 1e-9;

struct Circle{
  P c;
  double r;
  Circle(P c=P(0,0),double r=0):c(c),r(r){}
};

vector<P> getIntersectCC(Circle c1, Circle c2){
  vector<P> res;
  double r1=c1.r,r2=c2.r,d;
  P p1=c1.c,p2=c2.c;
  d=abs(p1-p2);
  if(d<EPS&&abs(r1-r2)<EPS) return res;
  if(r1+r2<d-EPS||d+EPS<abs(r1-r2)) return res; 
  double a=(r1*r1-r2*r2+d*d)/(2*d);
  double h=sqrt(max(r1*r1-a*a,0.0));
  P tmp1=p1+a/d*(p2-p1);
  P tmp2=h/d*(p2-p1);
  if(abs(tmp2)<EPS)res.push_back(tmp1);
  else{
    res.push_back(P(real(tmp1)-imag(tmp2),imag(tmp1)+real(tmp2)));
    res.push_back(P(real(tmp1)+imag(tmp2),imag(tmp1)-real(tmp2)));
  }
  return res;
}

double getdistancepp(P a,P b){
  return sqrt((a.real()-b.real())*(a.real()-b.real())+(a.imag()-b.imag())*(a.imag()-b.imag()));
}

int main(){
  int n,ans=0;
  double a,b;
  P p[N];
  while(1){
    cin>>n;
    if(!n)break;
    for(int i=0;i<n;i++){
      cin>>a>>b;
      p[i]=P(a,b);
    }
    for(int i=0;i<n;i++){
      for(int j=i+1;j<n;j++){
	Circle c1,c2;
	c1.c=p[i];
	c2.c=p[j];
	c1.r=c2.r=1;
	vector<P> r=getIntersectCC(c1,c2);
	if(!r.size())continue;
	for(int k=0;k<r.size();k++){
	  int cnt=0;
	  for(int l=0;l<n;l++)
	    if(getdistancepp(r[k],p[l])<=1+EPS)cnt++;	    
	  ans=max(ans,cnt);
	}
      }
    }
    cout<<ans<<endl;
  }
  return 0;
}

C++: #include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <set>

using namespace std;


int main(){
	int n;
	double x1,y1,xc,yc,dis,vx,vy,ex,ey;
	while(1){
		cin >> n;
		if(n==0)break;
		vector<double> x(n);
		vector<double> y(n);
		for(int i=0;i<n;i++){
			cin >> x[i] >> y[i];
		}
		int ans =1;
		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++){
				if(i==j)continue;
				xc = (x[i]+x[j])/2;
				yc = (y[i]+y[j])/2;
				if((xc-x[i])*(xc-x[i])+(yc-y[i])*(yc-y[i])>1.0001)continue;
				dis = sqrt(1.0-(xc-x[i])*(xc-x[i])-(yc-y[i])*(yc-y[i]));
				vx = x[i]-x[j];
				vy = y[i]-y[j];
				ex = dis * vy / sqrt(vx*vx+vy*vy);
				ey = -dis* vx / sqrt(vx*vx+vy*vy);
				x1 = xc + ex;
				y1 = yc + ey;
				int count=0;
				for(int k=0;k<n;k++){
					if(k==i||k==j)count +=1;
					else{
						if((x1-x[k])*(x1-x[k])+(y1-y[k])*(y1-y[k])<=1.0001){
							count +=1;
						}
					}
				}
				ans = max(ans,count);
				x1 = xc - ex;
				y1 = yc - ey;
				count = 0;
				for(int k=0;k<n;k++){
					if(k==i||k==j)count +=1;
					else{
						if((x1-x[k])*(x1-x[k])+(y1-y[k])*(y1-y[k])<=1.0001){
							count +=1;
						}
					}
				}
				ans = max(ans,count);
			}
		}
		cout << ans << endl;
	}
	return 0;
}