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<deque>
#include<list>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<vector>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<cmath>
#include<cstdio>
#include<cstring>
using namespace std;
#define dis(p,q) ((p)*(p)+(q)*(q))
int main(){
  int i,j,k;
  int n;
  while(cin>>n,n){
    double x[300],y[300];
    for(i=0;i<n;++i)
      cin>>x[i]>>y[i];    
    int mx=1;
    for(i=0;i<n-1;++i){
      for(j=i+1;j<n;++j){
	double d=dis(x[i]-x[j],y[i]-y[j]);
	if(d<=4){
	  double cx[2],cy[2],a=atan2(y[i]-y[j],x[i]-x[j]);
	  int sm[2]={2,2};
	  d=sqrt(1-d/4);
	  cx[0]=(x[i]+x[j])/2+cos(a+M_PI/2)*d;
	  cy[0]=(y[i]+y[j])/2+sin(a+M_PI/2)*d;
	  cx[1]=(x[i]+x[j])/2+cos(a-M_PI/2)*d;
	  cy[1]=(y[i]+y[j])/2+sin(a-M_PI/2)*d;
	  for(k=0;k<n;++k){
	    if(k!=i&&k!=j){
	      if(dis(x[k]-cx[0],y[k]-cy[0])<=1)
		++sm[0];
	      if(dis(x[k]-cx[1],y[k]-cy[1])<=1)
		++sm[1];
	    }
	  }
	  mx=max(max(mx,sm[0]),sm[1]);
	}
      }
    }
    cout<<mx<<endl;
  }
  return 0;
}

C++: #include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)n; ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
typedef pair<double,double> P;

inline double dist(P p,P q){
  return ( (p.first-q.first)*(p.first-q.first) + (p.second-q.second)*(p.second-q.second));
}

int main(){
  int N;
  double sign[2] = {+1, -1};
  P p[301];
  while(scanf("%d",&N) == EOF){
    if(N == 0)break;
    REP(i,N)scanf("%lf %lf",&p[i].first,&p[i].second);
    int ans = 1;
    REP(i,N){
      FOR(j,i+1,N){
        double dst = dist(p[i],p[j]);
        if(dst > 4.0) continue;
        P v((p[j].first-p[i].first)/dst, (p[j].second-p[i].second)/dst);
        P m((p[j].first+p[i].first)/2.0, (p[j].second+p[i].second)/2.0);
        double lth = sqrt(1.0-dst*dst/4.0);
        REP(k,2){
          double cx = m.first + sign[k] * v.first * lth;
          double cy = m.second - sign[k] * v.second * lth;
          P center(cx,cy);
          int count = 0;
          REP(l,N){
            if(l == i || l == j || dist(center,p[l]) < 1){
              count++;
            }
            if(N-l-1 + count < ans)break;
          }
          if(ans < count) ans = count;
        }
      }
    }
    printf("%d\n",ans);
  }
  return 0;
}

C++: #include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;
static const int MAX_N = 300;

#define EPS (1e-10)

class Point{
	public:
		double x, y;

		Point(double x = 0, double y = 0): x(x), y(y) {}

		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;
		}
};

class Circle{
	public:
		Point c;
		double r;
		Circle(Point c = Point(), double r = 0.0): c(c), r(r) {}
};

typedef Point Vector;

int N;
Point p[MAX_N];

double arg(Vector p){return atan2(p.y, p.x);}
Vector polar(double a, double r){return Point(cos(r) * a, sin(r) * a);}

double getDistance(Point a, Point b){
	return (a - b).abs();
}

pair<Point, Point> getCrossPoints(Circle c1, Circle c2){
	double d = (c1.c - c2.c).abs();
	double a = acos((c1.r * c1.r + d * d - c2.r * c2.r) / (2 * c1.r * d));
	double t = arg(c2.c - c1.c);
	return make_pair(c1.c + polar(c1.r, t + a), c1.c + polar(c1.r, t - a));
}

bool comp(const Point &a, const Point &b){
	return a.x < b.x;
}

int main(){
	for(;;){
		scanf("%d", &N);
		if(N == 0) break;
		for(int i = 0; i < N; i++){
			scanf("%lf %lf", &p[i].x, &p[i].y);
		}
		sort(p, p + N, comp);
		int res = 1;
		for(int i = 0; i < N; i++){
			for(int j = i + 1; j < N; j++){
				if(p[j].x - p[i].x > 2.0) break;
				else if(getDistance(p[i], p[j]) > 2.0) continue;
				pair<Point, Point> pp = getCrossPoints((Circle){p[i], 1.0}, (Circle){p[j], 1.0});
				Point p1 = pp.first, p2 = pp.second;
				int cnt1 = 2, cnt2 = 2;
				for(int k = 0; k < N; k++){
					if(k == i || k == j) continue;
					if(p[k].x - p[j].x > 1.0) break;
					if(getDistance(p1, p[k]) < 1.0) cnt1++;
					if(getDistance(p2, p[k]) < 1.0) cnt2++;
				}
				res = max(res, max(cnt1, cnt2));
			}
		}
		printf("%d\n", res);
	}
	return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()

typedef complex<double> P;
const double EPS = 1e-8;

int main() {
  int n;
  while(cin>>n,n) {
    vector<P> v;
    REP(i,n) {
      double x,y;
      cin >> x >> y;
      v.push_back(P(x,y));
    }
    int ans = 0;
    REP(i,n-1) {
      for (int j=i+1;j<n;j++) {
        P m = (v[i]+v[2])*P(0.5,0);
        P a = v[i]-v[j];
        double dis = abs(a);
        double d = sqrt(1-dis*dis/4);
        int hoge[]={1,-1};
        REP(k,2) {
          P un = (a * P(0, hoge[k])) / dis;
          P o1 = m + un*d;
          int sum = 0;
          REP(l,n) {
            if (norm(v[l]-o1)<1+EPS) sum++;
          }
          ans = max(ans,sum);
        }
      }
    }
    cout << ans << endl;
    
  }
}