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<iostream>
#include<cstdio>
#include<cmath>
#include<vector>
#include<map>
using namespace std;
#define INF 1e+10
#define EPS 1e-10
#define EQ(a,b) (abs(a-b)<EPS)

//誤差を考慮して足し算
double add(double a,double b){
	if(abs(a+b) < EPS*(abs(a)+abs(b)))return 0;
	return a+b;
}
struct P{//2次元ベクトル
	double x,y;
	P(){}
	P(double x,double y):x(x),y(y){}
	P operator + (P p){
		return P(add(x,p.x),add(y,p.y));
	}
	P operator - (P p){
		return P(add(x,-p.x),add(y,-p.y));
	}
	P operator * (double d){
		return P(x*d,y*d);
	}
	bool operator ==(P p){
		return x==p.x && y==p.y;
	}
	bool equal(P p){
		return (x-p.x)*(x-p.x)+(y-p.y)*(y-p.y) < EPS*EPS;
	}	
	double dot(P p){//内積
		return add(x*p.x,y*p.y);
	}
	double det(P p){//外積
		return add(x*p.y,-y*p.x);
	}
};
//線分p1-p2上に点qがあるか判定
bool on_seg(P p1,P p2,P q){
	return (p1-q).det(p2-q)==0 && (p1-q).dot(p2-q)<=0;
}
//直線p1-p2と直線q1-q2の交点
P intersection(P p1,P p2,P q1,P q2){
	return p1+(p2-p1)*( (q2-q1).det(q1-p1)/(q2-q1).det(p2-p1) );
}
//線分p1-p2と線分q1-q2が交差するか
bool intersecting(P p1,P p2,P q1,P q2){
	if(on_seg(p1,p2,q1)||on_seg(p1,p2,q2)||on_seg(q1,q2,p1)||on_seg(q1,q2,p2))return true;
	if((p1-p2).det(q1-q2)==0 )return false;//平行
	P a=intersection(p1,p2,q1,q2);
	return on_seg(p1,p2,a) && on_seg(q1,q2,a);
}
P rotate(P p,double rad){
	double s=sin(rad),c=cos(rad);
	return P(c*p.x-s*p.y, s*p.x+c*p.y);
}
double dist(P p,P q){
	p = p-q;
	return sqrt(p.x*p.x+p.y*p.y);
}

//円同士の交点を計算
pair<P,P> circle_intersection(double x1,double y1,double r1,double x2,double y2,double r2){
	x2 -= x1;
	y2 -= y1;
	double rad = atan2(y2,x2);
	P tmp = rotate(P(x2,y2),-rad);
	x2 = tmp.x;
	y2 = tmp.y;
	double x = (r1*r1-r2*r2+x2*x2)/(2*x2);
	if(abs(r1) < abs(x))return make_pair(P(0,0),P(0,0));//交点なし
	double y = sqrt(r1*r1-x*x);
	return make_pair( P(x1,y1)+rotate(P(x,y),rad) ,  P(x1,y1)+rotate(P(x,-y),rad) );
}
//2点を通る円の中心座標
pair<P,P> circle_on_2P(P p,P q,double r){
	if(2*r < dist(p,q))return make_pair(P(0,0),P(0,0));//解なし
	if(q.x < p.x)swap(p,q);
	q = q - p;
	double rad = atan2(q.y,q.x);
	P tmp = rotate(q,-rad);
	double x = tmp.x/2;
	double y = sqrt(4*r*r-tmp.x*tmp.x)/2;
	return make_pair( p+rotate(P(x,y),rad) ,  p+rotate(P(x,-y),rad) );
}

int n;
P c[300];
int calc(P p,P q){
	if (2 < dist(p,q))return 1;
	pair<P,P> pa = circle_on_2P(p,q,1.0);
	int res=0,t=0;
	for(int i=0;i<n;i++){
		if(dist(pa.first,c[i]) <= 1+1e-4)t++;
	}
	res = t;
	t=0;
	for(int i=0;i<n;i++){
		if(dist(pa.second,c[i]) <= 1+1e-4)t++;
	}
	res = max(res,t);
	return res;
}
int main(){
	while(cin>>n&&n){
		for(int i=0;i<n;i++){
			double x,y;
			cin>>x>>y;
			c[i] = P(x,y);
		}
		int ans=1;
		for(int i=0;i<n;i++){
			for(int j=i+1;j<n;j++){
				ans = max(ans,calc(c[i],c[j]));
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}

C++: #include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <numeric>
using namespace std;

#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<((x))<<endl
#define fi first
#define se second

#define INF 2147483600
#define long long long
#define EPS 1e-8

// ???????°???°???????????????
inline double add(double a, double b){
  if(abs(a+b) < EPS*(abs(a) + abs(b))) return 0;
  return a+b;
}

struct Point{
  double x,y;
  Point() {}
  Point(double nx, double ny) : x(nx), y(ny) {}
  inline Point operator + (const Point & p){ return Point(add(x, p.x), add(y, p.y)); }
  inline Point operator - (const Point & p){ return Point(add(x,-p.x), add(y,-p.y)); }
  inline Point operator * (double d){ return Point(x*d, y*d); }
  inline double dot(const Point & p){ return add(x * p.x, y*p.y); }  //??????
  inline double det(const Point & p){ return add(x * p.y, -y*p.x); } //??????
  inline double dist(const Point & p){ return sqrt((x-p.x)*(x-p.x) + (y-p.y)*(y-p.y)); }
  inline bool operator < (const Point & p) const {
    if(x != p.x) return x < p.x;
    else return y < p.y;
  }
  inline bool operator == (const Point & p) const {
    return (add(x, -p.x)==0) && (add(y, -p.y)==0);
  }
  friend ostream& operator<<(ostream& os, const Point& p) {
    os << "[" << p.x << "," << p.y << "]";
    return os;
  }
};

pair<Point, Point> calcCenter(Point &p1, Point &p2){
  if(add(p1.x, -p2.x)==0){
    double y = (p1.y + p2.y)/2;
    double dx = sqrt(1 - (p1.y - y)*(p1.y - y));
    return mp(Point(p1.x+dx, y), Point(p1.x-dx,y));
  }
  // 2???????????´???????????? Ax + By + C = 0 , A != 0
  double A = 2*(p1.x - p2.x);
  double B = 2*(p1.y - p2.y);
  double C = - p1.x*p1.x + p2.x*p2.x - p1.y*p1.y + p2.y*p2.y;
  // x = py+q
  double p = -B/A; double q = -C/A;

  // p1, p2 ??¨????????¢???1?????? ay^2 + 2by + c = 0
  double a = 1 + p*p;
  double b = p*q - p1.x*p - p1.y;
  double c = q*q - 2*p1.x*q + p1.x*p1.x + p1.y*p1.y - 1;

  double rt = sqrt(b*b-a*c);
  double y1 = (-b+rt)/a;
  double y2 = (-b-rt)/a;

  return mp(Point(p*y1+q, y1), Point(p*y2+q, y2));
}

Point vec[300];

int main(){
  int n;
  while(scanf("%d", &n), n){
    rep(i,n){
      scanf("%lf %lf", &vec[i].x, &vec[i].y);
    }

    int res=1;
    rep(i,n) repl(j,i+1,n) if(vec[i].dist(vec[j]) <= 2+EPS){
      pair<Point, Point> pr = calcCenter(vec[i], vec[j]);
      int cnt=0;
      rep(k,n) if(pr.fi.dist(vec[k]) <= 1+EPS) cnt++;
      res = max(res, cnt);
      cnt=0;
      rep(k,n) if(pr.se.dist(vec[k]) <= 1+EPS) cnt++;
      res = max(res, cnt);
    }

    printf("%d\n", res);
  }
  return 0;
}