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;

#define rep(i,N) for(int i=0;i<(int)(N);i++)
#define REP(i,k,N) for(int i=k;i<(int)(N);i++)

#define vi vector<int>
#define pb push_back

#define pdd pair<double,double>
#define fi first
#define se second
const double  EPS = 1e-9;

double dist(double x,double y){
    return x*x+y*y;
};

int main(){

    int n;
    while(cin >> n,n){
        int ma = 0;
        pdd p[330];
        rep(i,n) cin >> p[i].fi >> p[i].se;
        rep(i,n-1){
            REP(j,i+1,n){
                int cnt1 = 0,cnt2=0;
                double x1,y1,x2,y2,x3,y3;
                tie(x1,y1) = p[i];
                tie(x2,y2) = p[j];
                double cx1,cy1,cx2,cy2;
                if(dist(x1-x2,y1-y2)-4 > EPS  ) continue;

                //はりまコーナー
//                double ax,ay,bx1,by1,bx2,by2,mx,my,dx,dy;
//                ax=x1-x2;ay=y1-y2;
//                mx=(x1+x2)/2;my=(y1+y2)/2;
//                by1 = (-0.5)*pow(ax,4)+pow(ax,2)+(-0.5)*pow(ax,2)*pow(ay,2)
//                        /dist(ax,ay);
//                by1 = sqrt(abs(by1));
//                by2 = -1*by1;
//                cy1= my+by1;
//                cy2= my+by2;
//                bx1= -1*(ay*by1)/ax;
//                bx2= -1*(ay*by2)/ax;
//                cx1=bx1+mx;
//                cx2=bx2+mx;


                //あじのりコーナー
                double mx=(x1+x2)/2,my=(y1+y2)/2;

                double ld = 1-dist((x1-x2)/2,(y1-y2)/2);
                ld = sqrt(ld);
                cx1 = mx - sin(atan((y2-y1)/(x2-x1)))*ld;
                cy1 = my + cos(atan((y2-y1)/(x2-x1)))*ld;
                cx2 = mx + sin(atan((y2-y1)/(x2-x1)))*ld;
                cy2 = my - cos(atan((y2-y1)/(x2-x1)))*ld;

                for(int k = 0;k<n;k++) {
                    tie(x3, y3) = p[k];
                    if (EPS > dist((cx1 - x3), (cy1 - y3))-1) cnt1++;
                    if (EPS > dist((cx2 - x3), (cy2 - y3))-1) cnt2++;
                }
                ma = max({cnt1,cnt2,ma});
            }
        }
        cout<< ma << endl;
    }
    return 0;
}

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

#define EPS (1e-10)
#define EQ(a,b) (abs((a)-(b)) < EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )

using namespace std;

typedef complex<double> P;

P center1(P a ,P b ,double r){
  return (a+b)/(P)2+(b-a)*P(0,1)*(P)(sqrt(r*r-norm((b-a)/(P)2))/abs(b-a));
}

P center2(P a ,P b ,double r){
  return (a+b)/(P)2+(b-a)*P(0,-1)*(P)(sqrt(r*r-norm((b-a)/(P)2))/abs(b-a));
}

int main(){
  int n;
  while(true){
    cin >>n;
    if (!n)
      break;
    P dot[n];
    double x,y;
    for(int i=0;i<n;i++){
      cin >>x >>y;
      dot[i] = P(x,y);
    }
    set<int> near_dot[n];
    for(int i=0;i<n;i++){
      for(int j=i+1;j<n;j++){
	if (abs(dot[i]-dot[j])<2)
	  near_dot[i].insert(j);
      }
    }
    
    set<int>::iterator it;
    int cnt,max=2;
    P c;
    for(int i=0;i<n;i++){
      it = near_dot[i].begin();
      while(it != near_dot[i].end()){
	c = center1(dot[i],dot[*it],1);
	cnt=2;
	for(int j=0;j<n;j++)
	  if (abs(dot[j]-c)<1 && j!=i && j!=*it)
	    cnt++;
	if (max<cnt){
	  max=cnt;
	}

	c = center2(dot[i],dot[*it],1);
	cnt=2;
	for(int j=0;j<n;j++)
	  if (abs(dot[j]-c)<1 && j!=i && j!=*it)
	    cnt++;
	if (max<cnt){
	  max=cnt;
	}
	it++;
      }
    }
    cout << max << endl;
  }
  return 0;
}

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

typedef complex<double> C;

const double EPS = 1e-9;

int solve(int N, vector<double>& x, vector<double>& y) {
    vector<C> point(N);

    for (int j = 0; j < N; ++j) {
        point[j] = C(x[j], y[j]);
    }

    int ret = 1;

    for (int j = 0; j < N; ++j) {
        for (int k = j+1; k < N; ++k) {
            C mid = (point[j] + point[k]) * 0.5;

            C normal = (point[j] - point[k]) * C(0, 1);
            normal /= abs(point[j] - point[k]);

            double a = sqrt(1 - norm(mid - point[j]));

            C centre1 = mid + a * normal;
            int count = 0;
            for (int l = 0; l < N; ++l) {
                if (abs(centre1 - point[l]) < 1.0+EPS) {
                    ++count;
                }
            }
            ret = max(ret, count);

            C centre2 = mid - a * normal;
            count = 0;
            for (int l = 0; l < N; ++l) {
                if (abs(centre2 - point[l]) < 1.0+EPS) {
                    ++count;
                }
            }
            ret = max(ret, count);

        }
    }

    return ret;
}

int main () {
    int N;
    vector<double> x, y;

    while (true) {
        cin >> N;
        if (N == 0) break;

        x.resize(N);
        y.resize(N);

        for (int j = 0; j < N; ++j) {
            cin >> x[j] >> y[j];
        }

        cout << solve(N, x, y) << endl;
    }

    return 0;
}

C++: #include <string>
#include <vector>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <map>
#include <list>
#include <set>
#include <numeric>
#include <queue>
#include <stack>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <climits>
#include <cfloat>
#include <ctime>
#include <complex>
#include <cassert>
#include <tuple>
using namespace std;
typedef long long LL;
typedef pair<int,int> P;

int N;
double x[300];
double y[300];
inline double dist2(double a, double b)
{
	return a*a+b*b;
}
void exec()
{
	cin >> N;
	if(N==0){
		exit(0);
	}
	for(int i=0;i<N;i++){
		cin >> x[i] >> y[i];
	}
	int ret=1;
	for(int i=0;i<N;i++){
		for(int j=i+1;j<N;j++){
			double dx=(x[i]-x[j])/2;
			double dy=(y[i]-y[j])/2;
			double r2=dx*dx+dy*dy;
			double R=sqrt(1/r2-1);
			double px=x[j]+dx-R*dy;
			double py=y[j]+dy+R*dx;
			double qx=x[j]+dx+R*dy;
			double qy=y[j]+dy-R*dx;
			int sp=0,sq=0;
			for(int k=0;k<N;k++){
				if(k==i||k==j){
					sp++;sq++;
					continue;
				}
				if(dist2(x[k]-px,y[k]-py)<=1){
					sp++;
				}
				if(dist2(x[k]-qx,y[k]-qy)<=1){
					sq++;
				}
			}
			ret=max(ret,sp);
			ret=max(ret,sq);
		}
	}
	cout << ret << endl;
}
int main() {
	while(1)
		exec();
}