// start fold
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<bitset>
using namespace std;
#define ri register int
#define il inline
#define LL long long
#define uint unsigned int
#define ull unsigned long long
#define solid const auto &
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define pll pair<LL,LL>
#define fi first
#define se second
#define gm int mid((l+r)>>1)
#define enter putchar('\n')
#define rd() ({ri t;in(t);t;})
#define Size(x) ((int)x.size())
#define mem(x,y) memset(x,y,sizeof(x))
template<class T>il void in(T &x)
{
	x=0; short f=1; char c=getchar();
	while(c<'0'||c>'9')
	{
		if(c=='-') f=-1;
		c=getchar();
	}
	while(c>='0'&&c<='9') x=x*10+(c^'0'),c=getchar();
	x*=f;
}
template<class T>il void out(T x,const char c='\n')
{
	static short st[30]; short m=0;
	if(x<0) putchar('-'),x=-x;
	do st[++m]=x%10,x/=10; while(x);
	while(m) putchar(st[m--]|'0');
	putchar(c);
}
template<class T,class ...Args>il void in(T &x,Args &...args) {in(x); in(args...);}
template<class T,class ...Args>il void out(const T &x,const Args &...args) {out(x,' '); out(args...);}
template<class T>il void prt(T a[],int n) {for(ri i=0; i<n; ++i) out(a[i],' '); enter;}
template<class T>il void clr(T a[],int n) {memset(a,0,sizeof(T)*n);}
template<class T>il void clr(T *a,T *b) {memset(a,0,sizeof(T)*(b-a));}
template<class T>il bool ckmax(T &a,const T &b) {return a<b?a=b,1:0;}
template<class T>il bool ckmin(T &a,const T &b) {return a>b?a=b,1:0;}
namespace MOD_CALC
{
const int md=998244353;
il int add(const int a,const int b) {return a+b>=md?a+b-md:a+b;}
il int sub(const int a,const int b) {return a-b<0?a-b+md:a-b;}
il int mul(const int a,const int b) {return (LL)a*b%md;}
il void inc(int &a,const int b) {(a+=b)>=md?a-=md:0;}
il void dec(int &a,const int b) {(a-=b)<0?a+=md:0;}
il int qpow(int a,int b) {int r=1; for(; b; b>>=1,a=mul(a,a)) if(b&1) r=mul(r,a); return r;}
il int mdinv(const int a) {return qpow(a,md-2);}
} using namespace MOD_CALC;
namespace i207M
{
// end fold
#define N 3005
int n;
vector<int>E[N];
int du[N];
int sz;
void topo()
{
	static int q[N]; int hd=1,tl=0;
	for(ri i=1; i<=n; ++i) if(du[i]==1) q[++tl]=i;
	while(hd<=tl)
	{
		int x=q[hd++];
		for(solid v:E[x])
			if(--du[v]==1) q[++tl]=v;
	}
	for(ri i=1; i<=n; ++i) if(du[i]==2) ++sz;
}
double ans;
bool vis[N];
void dfs(int x,int d,int h)
{
	if(vis[x]) return;
	vis[x]=1;
	h+=(du[x]==2);
	if(h>=2) ans+=1.0/d+1.0/(d-h+2+sz-h)-1.0/(d+sz-h);
	else ans+=1.0/d;
	for(solid v:E[x]) dfs(v,d+1,h);
}
signed main()
{
#ifdef M207
	freopen("in.in","r",stdin);
	// freopen("out.out","w",stdout);
#endif
	in(n);
	for(ri i=1,a,b; i<=n; ++i)
	{
		in(a,b); ++a,++b;
		E[a].pb(b),E[b].pb(a);
		++du[a],++du[b];
	}
	topo();
	for(ri i=1; i<=n; ++i)
	{
		mem(vis,0);
		dfs(i,1,0);
	}
	printf("%.10f\n",ans);
	return 0;
}
// start fold
}
signed main()
{
	i207M::main();
	return 0;
}
// end fold


#include <bits/stdc++.h>

using namespace std;

const int MAXN = 3005;

int n;
int deg[MAXN];
vector<int> edges[MAXN];
double ans = 0;
int vis[MAXN];
int dist[MAXN], dist2[MAXN];
int cirsiz = 0;

void dfs(int x) {
	vis[x] = 1;
	for (auto nex : edges[x]) if (!vis[nex]) {
		dist2[nex] = dist2[x] + 1;
		if (!dist[nex]) {
			dist[nex] = dist[x] + 1;
			ans += 1. / dist[nex];
		} else {
			ans += 1. / dist2[nex] - 2. / (dist[nex] + dist2[nex] + cirsiz - 2);
		}
		dfs(nex);
	}
	vis[x] = 0;
}

int main() {
	scanf("%d", &n);
	for (int i = 1, a, b; i <= n; i++) {
		scanf("%d %d", &a, &b);
		edges[++a].push_back(++b);
		edges[b].push_back(a);
		deg[a]++;
		deg[b]++;
	}
	queue<int> q;
	for (int i = 1; i <= n; ++i)
		if (deg[i] == 1) q.push(i), ++cirsiz;
	while (!q.empty()) {
		int cur = q.front();
		q.pop();
		for (auto nex : edges[cur])
			if (--deg[nex] == 1) q.push(nex), ++cirsiz;
	}
	cirsiz = n - cirsiz;

	for (int i = 1; i <= n; i++) {
		memset(vis, 0, sizeof(vis));
		memset(dist, 0, sizeof(dist));
		memset(dist2, 0, sizeof(dist2));
		dist[i] = dist2[i] = 1;
		dfs(i);
	}
	printf("%.10lf\n", ans + n);

	return 0;
}


#include<cstdio>
#include<iostream>
#include<cmath>
using namespace std;
struct node_{
	int v,next;
}node[6005];
int head[3005],e,fa[3005][14],gf[3005];
int bj[3005],bjj=0;
bool b[3005];
void addnode(int u,int v){
	e++;
	node[e].v=v;
	node[e].next=head[u];
	head[u]=e;
}
int flag=0;
int n;
int dep[3005];
void dfs(int t,int u){
	b[t]=1;
	for(register int i=head[t];i;i=node[i].next){
		if(u==node[i].v) continue;
		if(b[node[i].v]){
			flag=node[i].v;
			gf[t]=t;
			bj[t]=bjj;
			bjj++;
			dep[t]=1;
			return;
		}
		dfs(node[i].v,t);
		if(flag>0){
			gf[t]=t;
			bj[t]=bjj;
			bjj++;
			dep[t]=1;
			if(t==flag) flag=-flag;
			return;
		}else if(flag<0) return;
	}
}
void dfs_(int t){
	for(register int i=head[t];i;i=node[i].next){
		if(gf[node[i].v]) continue;
		gf[node[i].v]=gf[t];
		fa[node[i].v][0]=t;
		for(register int j=1;j<=11;++j) fa[node[i].v][j]=fa[fa[node[i].v][j-1]][j-1];
		dep[node[i].v]=dep[t]+1;
		dfs_(node[i].v);
	}
}
int log_[3005];
int lca(int u,int v){
	if(dep[v]>dep[u]) swap(u,v);
	while(dep[u]>dep[v]){
		u=fa[u][log_[dep[u]-dep[v]]];
	}
	if(u==v) return u;
	for(register int i=11;i>=0;--i){
		if(fa[u][i]!=fa[v][i]){
			u=fa[u][i];
			v=fa[v][i];
		}
	}
	return fa[u][0];
}
double ans=0;
int main(){
	scanf("%d",&n);
	for(register int i=2;i<=n;++i){
		log_[i]=log_[i/2]+1;
	}
	for(register int i=1;i<=n;++i){
		int u,v;
		scanf("%d%d",&u,&v);
		addnode(u,v);
		addnode(v,u);
	}
	dfs(1,1);
	for(register int i=1;i<=n;++i){
		if(gf[i]==i){
			dfs_(i);
		}
	}
	for(register int i=1;i<=n;++i){
		for(register int j=1;j<=n;++j){
			if(gf[i]==gf[j]){
				ans+=(1/(double)(dep[i]+dep[j]-2*dep[lca(i,j)]+1));
			}else{
				int x=dep[i]+dep[j],y=abs(bj[gf[i]]-bj[gf[j]])-1,z=bjj-1-abs(bj[gf[i]]-bj[gf[j]]);
				ans=ans+1/(double)(x+z)+1/(double)(x+y)-1/(double)(x+z+y);
			}
		}
	}
	printf("%.15lf",ans);
	return 0;
}


#include<cstdio>
#include<iostream>
#include<cmath>
using namespace std;
struct node_{
	int v,next;
}node[6005];
int head[3005],e,fa[3005][14],gf[3005];
int bj[3005],bjj=0;
bool b[3005];
void addnode(int u,int v){
	e++;
	node[e].v=v;
	node[e].next=head[u];
	head[u]=e;
}
int flag=0;
int n;
int dep[3005];
void dfs(int t,int u){
	b[t]=1;
	for(register int i=head[t];i;i=node[i].next){
		if(u==node[i].v) continue;
		if(b[node[i].v]){
			flag=node[i].v;
			gf[t]=t;
			bj[t]=bjj;
			bjj++;
			dep[t]=1;
			return;
		}
		dfs(node[i].v,t);
		if(flag>0){
			gf[t]=t;
			bj[t]=bjj;
			bjj++;
			dep[t]=1;
			if(t==flag) flag=-flag;
			return;
		}else if(flag<0) return;
	}
}
void dfs_(int t){
	for(register int i=head[t];i;i=node[i].next){
		if(gf[node[i].v]) continue;
		gf[node[i].v]=gf[t];
		fa[node[i].v][0]=t;
		for(register int j=1;j<=11;++j) fa[node[i].v][j]=fa[fa[node[i].v][j-1]][j-1];
		dep[node[i].v]=dep[t]+1;
		dfs_(node[i].v);
	}
}
int log_[3005];
int lca(int u,int v){
	if(dep[v]>dep[u]) swap(u,v);
	while(dep[u]>dep[v]){
		u=fa[u][log_[dep[u]-dep[v]]];
	}
	if(u==v) return u;
	for(register int i=11;i>=0;--i){
		if(fa[u][i]!=fa[v][i]){
			u=fa[u][i];
			v=fa[v][i];
		}
	}
	return fa[u][0];
}
double ans=0;
int main(){
	scanf("%d",&n);
	for(register int i=2;i<=n;++i){
		log_[i]=log_[i/2]+1;
	}
	for(register int i=1;i<=n;++i){
		int u,v;
		scanf("%d%d",&u,&v);
		u++;
		v++;
		addnode(u,v);
		addnode(v,u);
	}
	dfs(1,1);
	for(register int i=1;i<=n;++i){
		if(gf[i]==i){
			dfs_(i);
		}
	}
	for(register int i=1;i<=n;++i){
		for(register int j=1;j<=n;++j){
			if(gf[i]==gf[j]){
				ans+=(1/(double)(dep[i]+dep[j]-2*dep[lca(i,j)]+1));
			}else{
				int x=dep[i]+dep[j],y=abs(bj[gf[i]]-bj[gf[j]])-1,z=bjj-1-abs(bj[gf[i]]-bj[gf[j]]);
				ans=ans+1/(double)(x+z)+1/(double)(x+y)-1/(double)(x+z+y);
			}
		}
	}
	printf("%.9lf",ans);
	return 0;
}


#include<cstdio>
#include<iostream>
#include<cmath>
using namespace std;
struct node_{
	int v,next;
}node[6005];
int head[3005],e,fa[3005][14],gf[3005];
int bj[3005],bjj=0;
bool b[3005];
void addnode(int u,int v){
	e++;
	node[e].v=v;
	node[e].next=head[u];
	head[u]=e;
}
int flag=0;
int n;
int dep[3005];
void dfs(int t,int u){
	b[t]=1;
	for(register int i=head[t];i;i=node[i].next){
		if(u==node[i].v) continue;
		if(b[node[i].v]){
			flag=node[i].v;
			gf[t]=t;
			bj[t]=bjj;
			bjj++;
			dep[t]=1;
			return;
		}
		dfs(node[i].v,t);
		if(flag>0){
			gf[t]=t;
			bj[t]=bjj;
			bjj++;
			dep[t]=1;
			if(t==flag) flag=-flag;
			return;
		}else if(flag<0) return;
	}
}
void dfs_(int t){
	for(register int i=head[t];i;i=node[i].next){
		if(gf[node[i].v]) continue;
		gf[node[i].v]=gf[t];
		fa[node[i].v][0]=t;
		for(register int j=1;j<=11;++j) fa[node[i].v][j]=fa[fa[node[i].v][j-1]][j-1];
		dep[node[i].v]=dep[t]+1;
		dfs_(node[i].v);
	}
}
int log_[3005];
int lca(int u,int v){
	if(dep[v]>dep[u]) swap(u,v);
	while(dep[u]>dep[v]){
		u=fa[u][log_[dep[u]-dep[v]]];
	}
	if(u==v) return u;
	for(register int i=11;i>=0;--i){
		if(fa[u][i]!=fa[v][i]){
			u=fa[u][i];
			v=fa[v][i];
		}
	}
	return fa[u][0];
}
long double ans=0;
int main(){
	scanf("%d",&n);
	for(register int i=2;i<=n;++i){
		log_[i]=log_[i/2]+1;
	}
	for(register int i=1;i<=n;++i){
		int u,v;
		scanf("%d%d",&u,&v);
		u++;
		v++;
		addnode(u,v);
		addnode(v,u);
	}
	dfs(1,1);
	for(register int i=1;i<=n;++i){
		if(gf[i]==i){
			dfs_(i);
		}
	}
	for(register int i=1;i<=n;++i){
		for(register int j=1;j<=n;++j){
			if(gf[i]==gf[j]){
				ans+=(1/(long double)(dep[i]+dep[j]-2*dep[lca(i,j)]+1));
			}else{
				int x=dep[i]+dep[j],y=abs(bj[gf[i]]-bj[gf[j]])-1,z=bjj-1-abs(bj[gf[i]]-bj[gf[j]]);
				ans=ans+1/(long double)(x+z)+1/(long double)(x+y)-1/(long double)(x+z+y);
			}
		}
	}
	printf("%.15Lf",ans);
	return 0;
}


// =================================
//   author: memset0
//   date: 2019.05.10 09:17:03
//   website: https://memset0.cn/
// =================================
#include <bits/stdc++.h>
#define ll long long
#define debug(...) ((void)0)
#ifndef debug
#define debug(...) fprintf(stderr,__VA_ARGS__)
#endif
namespace ringo {
template <class T> inline void read(T &x) {
	x = 0; char c = getchar(); bool f = 0;
	while (!isdigit(c)) f ^= c == '-', c = getchar();
	while (isdigit(c)) x = x * 10 + c - '0', c = getchar();
	if (f) x = -x;
}
template <class T> inline void print(T x) {
	if (x < 0) putchar('-'), x = -x;
	if (x > 9) print(x / 10);
	putchar('0' + x % 10);
}
template <class T> inline void print(T x, char c) { print(x), putchar(c); }
template <class T> inline void print(T a, int l, int r, std::string s = "") {
	if (s != "") std::cout << s << ": ";
	for (int i = l; i <= r; i++) print(a[i], " \n"[i == r]);
}

const int N = 3010;
double ans;
bool vis[N], tag[N];
std::pair<int, int> R;
std::vector<int> C, S[N], G[N];
int n, m, dep[N], fa[N], d[N][N];

inline int dis(int u, int v) { return d[u][v]; }
inline int dis2(int u, int v) { return std::min(d[u][R.first] + d[R.second][v] + 1, d[u][R.second] + d[R.first][v] + 1); }

std::vector<int> dfs(int u) {
	// printf("dfs %d\n");
	vis[u] = 1;
	std::vector<int> U(1, u);
	for (auto v : G[u]) if (v != fa[u]) {
		if (vis[v]) {
			R = std::make_pair(u, v);
		} else {
			fa[v] = u, dep[v] = dep[u] + 1;
			// printf(">> %d -> %d\n", u, v);
			auto V = dfs(v);
			for (auto i : U) for (auto j : V)
				d[i][j] = d[j][i] = dep[i] + dep[j] - (dep[u] << 1);
			for (auto v : V) U.push_back(v);
		}
	}
	return U;
}

void addNodes(int u, int fa, std::vector<int> &S) {
	// printf("add nodes %d\n", u);
	S.push_back(u);
	for (auto v : G[u]) if (v != fa) {
		// printf("%d -> %d\n", u, v);
		addNodes(v, u, S);
	}
}

void main() {
	read(n);
	for (int u, v,  i = 1; i <= n; i++) {
		read(u), read(v), ++u, ++v;
		G[u].push_back(v), G[v].push_back(u);
	}
	dfs(1);

	int u = R.first, v = R.second;
	// printf(">> %d %d\n", R.first, R.second);
	if (dep[u] > dep[v]) std::swap(u, v);
	while (dep[v] > dep[u]) tag[v] = 1, v = fa[v];
	while (u != v) tag[u] = tag[v] = 1, u = fa[u], v = fa[v];
	tag[u] = 1;
	for (int i = 1; i <= n; i++) if (tag[i]) C.push_back(i);

	for (auto u : C) {
		S[u].push_back(u);
		for (auto v : G[u]) if (!tag[v]) {
			// printf("%d -> %d\n", u, v);
			addNodes(v, u, S[u]);
		}
		// print(S[u], 0, S[u].size() - 1, "S[" + std::to_string(u) + "]");
	}

	// for (int i = 1; i <= n; i++)
	// 	for (int j = 1; j <= n; j++)
	// 		print(d[i][j], " \n"[j == n]);
	for (auto ru : C)
		for (auto rv : C) if (ru != rv) {
			int y = dis(ru, rv) - 1, z = dis2(ru, rv) - 1;
			for (auto u : S[ru])
				for (auto v : S[rv]) {
					int x = dis(u, ru) + dis(v, rv) + 2;
					double w = (1 / (double)(x + y + z)) * (1 + y / (double)(x + z) + z / (double)(x + y));
					// printf("%d -> %d : %.4lf | %d %d %d\n", u, v, w, x, y, z);
					ans += w;
				}
		}
	for (auto r : C)
		for (auto u : S[r])
			for (auto v : S[r]) if (u != v) {
				double w = 1 / ((double)dis(u, v) + 1);
				// printf("%d -> %d : %.4lf\n", u, v, w);
				ans += w;
			}
	printf("%.15lf\n", ans + n);
}

} signed main() {
#ifdef MEMSET0_LOCAL_ENVIRONMENT
	freopen("1.in", "r", stdin);
#endif
	return ringo::main(), 0;
}


/* --- author: dxm --- */
#include<bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;

#define INF 1e9
#define Inf 1e18
#define rep(i,n) for(int (i)=0;(i)<n;i++)
#define REP(i,n) for(int (i)=1;(i)<=n;i++)
#define mp make_pair
#define pb push_back
#define fst first
#define snd second
typedef long long ll;
typedef double db;
typedef long double ldb;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;

void qread(int &x){
	int neg=1;x=0;
	char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')neg=-1;c=getchar();}
	while(c>='0'&&c<='9')x=10*x+c-'0',c=getchar();
	x*=neg;
}

const int maxn=3005;
int n;
int par[maxn],dep[maxn],mxd[maxn],cnt[maxn][maxn];
vector<int>edge[maxn],cyc;
bool oncyc[maxn],vis[maxn];
db ans;

void dfs1(int x,int p,int d){
	par[x]=p;
	vis[x]=true;
	dep[x]=d;
	rep(i,edge[x].size()){
		int y=edge[x][i];
		if(y==p)continue;
		if(!vis[y])dfs1(y,x,d+1);
		else if(dep[y]<dep[x]){
			int z=x;
			while(z!=y)cyc.pb(z),oncyc[z]=true,z=par[z];
			cyc.pb(z);oncyc[z]=true;
		}
	}
}

void dfs2(int x,int p){
	cnt[x][0]++;
	mxd[x]=0;
	rep(i,edge[x].size()){
		int y=edge[x][i];
		if(y==p||oncyc[y])continue;
		dfs2(y,x);
		rep(j,mxd[x]+1)rep(k,mxd[y]+1){
			ans+=1.0/db(j+k+2)*cnt[x][j]*cnt[y][k];
		}
		rep(k,mxd[y]+1)cnt[x][k+1]+=cnt[y][k];
		mxd[x]=max(mxd[x],mxd[y]+1);
	}
}

int main(){
#ifdef FILE
	freopen("FILE.in","r",stdin);
	freopen("FILE.out","w",stdout);
#endif
	scanf("%d",&n);
	REP(i,n){
		int u,v;
		scanf("%d%d",&u,&v);
		u++;v++;
		edge[u].pb(v);
		edge[v].pb(u);
	}
	dfs1(1,0,0);
	rep(i,cyc.size())dfs2(cyc[i],0);
	rep(i,cyc.size())for(int j=i+1;j<cyc.size();j++){
		int x=cyc[i],y=cyc[j];
		rep(d1,mxd[x]+1)rep(d2,mxd[y]+1){
			db prob=1.0/db(d1+d2+j-i+1)+1.0/db(d1+d2+cyc.size()-(j-i)+1)-1.0/db(d1+d2+cyc.size());
			ans+=cnt[x][d1]*cnt[y][d2]*prob;
		}
	}
	printf("%.10lf\n",ans*2+n);
#ifdef TIME
	printf("Running Time = %d ms\n",int(clock()*1000.0/CLOCKS_PER_SEC));
#endif
	return 0;
}

/*
Input:
-----------------
Output:
*/


// Problem: D. Graph Game
// Contest: Codeforces - Codeforces Round #146 (Div. 1)
// URL: https://codeforces.com/contest/235/problem/D
// Memory Limit: 256 MB
// Time Limit: 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

																																																	#ifndef OUUAN
																																																	#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
																																																	#endif
																																																	#include<bits/stdc++.h>

#define int ll
// #define FAST_IOSTREAM 1

																																																	#define For(i,l,r)for(int i=(l),i##end=(r);i<=i##end;++i)
																																																	#define FOR(i,r,l)for(int i=(r),i##end=(l);i>=i##end;--i)
																																																	#define SON(i,u)for(int i=head[u];i;i=nxt[i])
																																																	#define BE(x)(x).begin(),(x).end()
																																																	#define BE1(x)((x).begin()+1),(x).end()
																																																	#define fi first
																																																	#define se second
																																																	#define pb push_back
																																																	#define eb emplace_back
																																																	#define pq priority_queue
																																																	#define min minOfDifferentTypes
																																																	#define max maxOfDifferentTypes
																																																	#define y1 why_is_there_a_function_called_y1
																																																	using namespace std;typedef long long ll;typedef pair<int,int>pii;typedef vector<int>vi;typedef vector<vi>vvi;typedef vvi v2i;typedef vector<vvi>v3i;typedef vector<v3i>v4i;typedef vector<bool>vb;typedef vector<vb>vvb;typedef vvb v2b;typedef vector<vvb>v3b;typedef vector<v3b>v4b;typedef vector<pii>vpii;typedef vector<vpii>vvpii;typedef vvpii v2pii;typedef vector<vvpii>v3pii;typedef vector<v3pii>v4pii;typedef vector<double>vd;typedef vector<vd>vvd;typedef vvd v2d;typedef vector<v2d>v3d;typedef vector<v3d>v4d;const double inf=1e121;const double eps=1e-10;mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());int randint(int l,int r){int out=rng()%(r-l+1)+l;return out>=l?out:out+r-l+1;}template<typename A,typename B>string to_string(pair<A,B>p);template<typename A,typename B,typename C>string to_string(tuple<A,B,C>p);template<typename A,typename B,typename C,typename D>string to_string(tuple<A,B,C,D>p);string to_string(const string&s){return'"'+s+'"';}string to_string(const char*s){return to_string((string)s);}string to_string(bool b){return(b?"true":"false");}string to_string(vector<bool>v){bool first=true;string res="{";for(int i=0;i<static_cast<int>(v.size());i++){if(!first){res+=", ";}first=false;res+=to_string(v[i]);}res+="}";return res;}template<size_t N>string to_string(bitset<N>v){string res="";for(size_t i=0;i<N;i++){res+=static_cast<char>('0'+v[i]);}return res;}template<typename A>string to_string(A v){bool first=true;string res="{";for(const auto&x:v){if(!first){res+=", ";}first=false;res+=to_string(x);}res+="}";return res;}template<typename A,typename B>string to_string(pair<A,B>p){return"("+to_string(p.first)+", "+to_string(p.second)+")";}template<typename A,typename B,typename C>string to_string(tuple<A,B,C>p){return"("+to_string(get<0>(p))+", "+to_string(get<1>(p))+", "+to_string(get<2>(p))+")";}template<typename A,typename B,typename C,typename D>string to_string(tuple<A,B,C,D>p){return"("+to_string(get<0>(p))+", "+to_string(get<1>(p))+", "+to_string(get<2>(p))+", "+to_string(get<3>(p))+")";}template<typename A,typename B,typename C,typename D,typename E>string to_string(tuple<A,B,C,D,E>p){return"("+to_string(get<0>(p))+", "+to_string(get<1>(p))+", "+to_string(get<2>(p))+", "+to_string(get<3>(p))+","+to_string(get<4>(p))+")";}void debug_out(){cerr<<endl;}template<typename Head,typename...Tail>void debug_out(Head H,Tail...T){cerr<<" "<<to_string(H);debug_out(T...);}template<typename T>struct is_pair{static const bool value=false;};template<typename T,typename U>struct is_pair<std::pair<T,U>>{static const bool value=true;};
																																																	#ifdef OUUAN
																																																	#define debug(...)cerr<<"["<<#__VA_ARGS__<<"]:",debug_out(__VA_ARGS__)
																																																	#else
																																																	#define debug(...)42
																																																	#endif
																																																	#ifdef int
																																																	const int INF=0x3f3f3f3f3f3f3f3fll;
																																																	#else
																																																	const int INF=0x3f3f3f3f;
																																																	#endif
																																																	#ifdef FAST_IOSTREAM
																																																	#define br cout<<'\n'
																																																	#define sp cout<<' '
																																																	#define fl cout.flush()
																																																	ll read(){ll x;cin>>x;return x;}template<typename T>void read(T&x){cin>>x;}template<typename T>void write(const T&x){cout<<x;}
																																																	#else
																																																	#define br putchar('\n')
																																																	#define sp putchar(' ')
																																																	#define fl fflush(stdout)
																																																	template<typename T>typename enable_if<!is_integral<T>::value&&!is_pair<T>::value,void>::type read(T&x){cin>>x;}ll read(){char c;ll out=0,f=1;for(c=getchar();!isdigit(c)&&c!='-';c=getchar()){}if(c=='-'){f=-1;c=getchar();}for(;isdigit(c);c=getchar())out=(out<<3)+(out<<1)+c-'0';return out*f;}template<typename T>typename enable_if<is_integral<T>::value,T>::type read(T&x){char c;T f=1;x=0;for(c=getchar();!isdigit(c)&&c!='-';c=getchar()){}if(c=='-'){f=-1;c=getchar();}for(;isdigit(c);c=getchar())x=(x<<3)+(x<<1)+c-'0';return x*=f;}char read(char&x){for(x=getchar();isspace(x);x=getchar()){}return x;}double read(double&x){scanf("%lf",&x);return x;}template<typename T>typename enable_if<!is_integral<T>::value&&!is_pair<T>::value,void>::type write(const T&x){cout<<x;}template<typename T>typename enable_if<is_integral<T>::value,void>::type write(const T&x){if(x<0){putchar('-');write(-x);return;}if(x>9)write(x/10);putchar(x%10+'0');}void write(const char&x){putchar(x);}void write(const double&x){printf("%.12lf",x);}
																																																	#endif
																																																	template<typename T>typename enable_if<is_pair<T>::value,void>::type read(T&x){read(x.fi);read(x.se);}template<typename T>typename enable_if<is_pair<T>::value,void>::type write(const T&x){write(x.fi);sp;write(x.se);}template<typename T,typename...Args>void read(T&x,Args&...args){read(x);read(args...);}template<typename OutputIt,typename=typename enable_if<is_same<output_iterator_tag,typename iterator_traits<OutputIt>::iterator_category>::value||(is_base_of<forward_iterator_tag,typename iterator_traits<OutputIt>::iterator_category>::value&&!is_const<OutputIt>::value)>::type>void read(OutputIt __first,OutputIt __last){for(;__first!=__last;++__first)read(*__first);}template<typename InputIt,typename=typename enable_if<is_base_of<input_iterator_tag,typename iterator_traits<InputIt>::iterator_category>::value>::type>void wts(InputIt __first,InputIt __last){bool isFirst=true;for(;__first!=__last;++__first){if(isFirst)isFirst=false;else sp;write(*__first);}br;}template<typename InputIt,typename=typename enable_if<is_base_of<input_iterator_tag,typename iterator_traits<InputIt>::iterator_category>::value>::type>void wtb(InputIt __first,InputIt __last){for(;__first!=__last;++__first){write(*__first);br;}}template<typename T>void wts(const T&x){write(x);sp;}template<typename T>void wtb(const T&x){write(x);br;}template<typename T>void wte(const T&x){write(x);exit(0);}template<typename T,typename...Args>void wts(const T&x,Args...args){wts(x);wts(args...);}template<typename T,typename...Args>void wtb(const T&x,Args...args){wts(x);wtb(args...);}template<typename T,typename...Args>void wte(const T&x,Args...args){wts(x);wte(args...);}template<typename T1,typename T2>inline bool up(T1&x,const T2&y){return x<y?x=y,1:0;}template<typename T1,typename T2>inline bool dn(T1&x,const T2&y){return y<x?x=y,1:0;}template<typename T1,typename T2,typename T3>inline bool inRange(const T1&x,const T2&l,const T3&r){return!(x<l)&&!(r<x);}template<typename T1,typename T2>inline auto minOfDifferentTypes(const T1&x,const T2&y)->decltype(x<y?x:y){return x<y?x:y;}template<typename T1,typename T2>inline auto maxOfDifferentTypes(const T1&x,const T2&y)->decltype(x<y?y:x){return x<y?y:x;}template<typename T1,typename T2,typename T3>inline T1&madd(T1&x,const T2&y,const T3&modulo){return x=(ll)(x+y+modulo)%modulo;}template<typename T1,typename T2,typename T3>inline T1&mmul(T1&x,const T2&y,const T3&modulo){return x=(ll)x*y%modulo;}inline int modadd(int x,int y,int modulo){return(x+y)>=modulo?x+y-modulo:x+y;}inline int isinf(int x){return x<INF?x:-1;}inline void yesno(bool x){wtb(x?"Yes":"No");}

/* ------------------------------------------------------------------------------------------------------------------- */

signed main()
{
#ifdef FAST_IOSTREAM
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
#endif

	int n = read();

	vvpii g(n + 1);

	For (i, 1, n)
	{
		int u = read() + 1;
		int v = read() + 1;
		g[u].eb(v, i);
		g[v].eb(u, i);
	}

	int dfntot = 0;
	vi dfn(n + 1);
	stack<int> stk;
	vb oncycle(n + 1);
	vi cycle;

	function<void(int, int)> findCycle = [&](int u, int pa)
	{
		dfn[u] = ++dfntot;
		stk.push(u);

		for (auto x : g[u])
		{
			int v = x.fi;
			int id = x.se;
			if (id == pa) continue;
			if (!dfn[v]) findCycle(v, id);
			else if (dfn[v] < dfn[u])
			{
				while (1)
				{
					int t = stk.top();
					stk.pop();
					cycle.pb(t);
					oncycle[t] = true;
					if (t == v) break;
				}
			}
		}
		if (cycle.empty()) stk.pop();
	};

	findCycle(1, 0);

	vi dep(n + 1), treeId(n + 1);
	vvi dis(n + 1, vi(n + 1)), tree(cycle.size());

	function<void(int, int, int)> getTree = [&](int u, int pa, int id)
	{
		tree[id].pb(u);
		treeId[u] = id;
		for (auto x : g[u])
		{
			int v = x.fi;
			if (oncycle[v] || v == pa) continue;
			dep[v] = dep[u] + 1;
			getTree(v, u, id);
		}
	};

	For (i, 0, cycle.size() - 1) getTree(cycle[i], 0, i);

	double ans = 0;

	function<void(int, int, int)> calcTree = [&](int u, int pa, int d)
	{
		ans += 1.0 / d;
		for (auto x : g[u])
		{
			int v = x.fi;
			if (v == pa || treeId[v] != treeId[u]) continue;
			calcTree(v, u, d + 1);
		}
	};

	For (i, 0, cycle.size() - 1)
	{
		for (auto u : tree[i]) calcTree(u, 0, 1);
		For (j, i + 1, cycle.size() - 1)
		{
			for (auto u : tree[i])
			{
				for (auto v : tree[j])
				{
					int x = dep[u] + dep[v];
					int y = j - i;
					int z = cycle.size() - y;
					ans += 2.0 / (x + y + 1) + 2.0 / (x + z + 1) - 2.0 / (x + y + z);
				}
			}
		}
	}

	wtb(ans);

	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long double ld;
const int N=3100;
struct nd
{
    int ne,to;
}e[2*N];
int he[N],tot=0,dis[N],in[N],cir[N],vis[N],s[N],top=0,n,bel[N],cnt=0;
bool ban[N][N];
ld ans=0;
void add(int x,int y)
{
    e[++tot].ne=he[x];he[x]=tot;
    e[tot].to=y;
}
void dfs(int x,int f)
{
    int i,y,z;
    vis[x]=1;s[++top]=x;
    for(i=he[x];i;i=e[i].ne)
       if((y=e[i].to)!=f)
       {
           if(!vis[y])dfs(y,x);
           else if(!in[y])
           {
               do
               {
                   z=s[top--];
                   in[z]=1;cir[++cnt]=z;
               }while(z!=y);
           }
       }
    if(s[top]==x)top--;
}
void dfs2(int x,int f,int be)
{
    int i,y;
    bel[x]=be;
    for(i=he[x];i;i=e[i].ne)
       if((!vis[y=e[i].to])&&(y!=f))dfs2(y,x,be);
}
void dfs3(int x,int f)
{
    int i,y;
    vis[x]=1;
    for(i=he[x];i;i=e[i].ne)
       if(((y=e[i].to)!=f)&&(!ban[x][y])&&(!vis[y]))
       {
           dis[y]=dis[x]+1;
           dfs3(y,x);
       }
}
int main()
{
    //freopen("a.in","r",stdin);
    //freopen("a.out","w",stdout);
    int i,j,k,d,sum,x,y;
    scanf("%d",&n);
    for(i=1;i<=n;i++)
    {
        scanf("%d%d",&x,&y);
        x++;y++;
        add(x,y);add(y,x);
    }
    dfs(1,0);
    memset(vis,0,sizeof(vis));
    for(i=1;i<=cnt;i++)vis[cir[i]]=1;
    for(i=1;i<=cnt;i++)dfs2(cir[i],0,i);
    for(i=1;i<cnt;i++)ban[cir[i+1]][cir[i]]=1;
    ban[cir[1]][cir[cnt]]=1;
    ans=0;
    for(i=1;i<=n;i++)
    {
        dis[i]=1;
        for(j=1;j<=n;j++)vis[j]=0;
        dfs3(i,0);
        for(j=1;j<=n;j++)
           if(j!=i)
           {
               if(bel[i]==bel[j])ans+=(ld)1/(ld)dis[j];
               else
               {
                   x=bel[i];y=bel[j];
                   if(x>y)y+=cnt;
                   d=y-x+1;sum=dis[j]-d+cnt;
                   ans+=(ld)1/(ld)sum+(ld)(d-2)/(ld)sum*(ld)1/(ld)(sum-d+2)+(ld)(cnt-d)/(ld)sum*(ld)1/(ld)dis[j];
               }
           }
        //double out=ans;
        //printf("%.9f\n",out);
    }
    ans+=n;
    double out=ans;
    printf("%.9f\n",out);
    return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;
#define N 3030
inline int read(){
    int x=0,f=1;
    char c=getchar();
    while(c<'0'||c>'9'){
        if(c=='-')f=-1;
        c=getchar();
    }
    while(c>='0'&&c<='9'){
        x=(x<<3)+(x<<1)+c-'0';
        c=getchar();
    }
    return x*f;
}
int n,head[N],cnt,roots[N],tot,bel[N],now,dfn[N],num;
bool isroot[N];
double ans;
int st[N],top;
struct Edge{
	int to,nxt;
}edge[N<<1];
void add(int a,int b){
	++cnt;
	edge[cnt].to=b;
	edge[cnt].nxt=head[a];
	head[a]=cnt;
}
void get_cir(int u,int in_edge){
	st[++top]=u;
	dfn[u]=++num;
	for(int i=head[u];i;i=edge[i].nxt){
		int v=edge[i].to;
		if(i==in_edge)continue;
		if(dfn[v]){
			if(dfn[v]>dfn[u])continue;
			for(int j=top;j>=1;--j){
				roots[++tot]=st[j];
				isroot[st[j]]=true;
				if(st[j]==v)break;
			}
		}
		else get_cir(v,i^1);
	}
	--top;
}
void dfs2(int u,int fa,int dep){
//	cout<<"  now:  "<<u<<" "<<dep<<endl;
	ans+=1.0/dep;
	for(int i=head[u];i;i=edge[i].nxt){
		int v=edge[i].to;
		if(v==fa||(isroot[v]&&bel[u]^v))continue;
		dfs2(v,u,dep+1);
	}
}
void dfs3(int u,int fa,int x,int y,int z,int dep){
	ans+=1.0/(x+dep+y)+1.0/(x+dep+z)-1.0/(x+y+z+dep);
	for(int i=head[u];i;i=edge[i].nxt){
		int v=edge[i].to;
		if(v==fa||isroot[v])continue;
		dfs3(v,u,x,y,z,dep+1);
	}
}
void dfs1(int u,int fa,int dep){
	dfs2(u,0,1);
	for(int i=now%tot+1;i^now;i=i%tot+1){
		dfs3(roots[i],0,dep,abs(now-i)-1,tot-abs(now-i)-1,1);
	}
	for(int i=head[u];i;i=edge[i].nxt){
		int v=edge[i].to;
		if(isroot[v]||v==fa)continue;
		dfs1(v,u,dep+1);
	}
}
void init(int u,int fa,int qwq){
	bel[u]=qwq;
	for(int i=head[u];i;i=edge[i].nxt){
		int v=edge[i].to;
		if(v==fa||isroot[v])continue;
		init(v,u,qwq);
	}
}
int main(){
	n=read(),cnt=1;
	for(int i=1;i<=n;++i){
		int u=read()+1,v=read()+1;
		add(u,v),add(v,u);
	}
	get_cir(1,0);
	for(int i=1;i<=tot;++i){
		init(roots[i],0,roots[i]);
	}
	for(int i=1;i<=tot;++i){
		now=i;
		dfs1(roots[i],0,1);
	}
	printf("%.10lf\n",ans);
	return 0;
}


#include <cstdio>
#include <vector>
#include <cstring>
using namespace std;
vector<int> v[3005];
bool vis[3005], cir[3005];
int q, s, n;
int Find_Cir(int x, int y) {
  vis[x] = 1;
  for (int i = 0; i < v[x].size(); i++)
    if (!vis[v[x][i]]) {
      int t = Find_Cir(v[x][i], x);
      if (t) {
        if (t > 0) {
          cir[x] = 1;
          s++;
        }
        return t == x ? -1 : t;
      }
    } else if (v[x][i] != y) {
      cir[x] = s = 1;
      return v[x][i];
    }
}
double ans;
void Dfs(int x) {
  vis[x] = 1;
  q += cir[x];
  n++;
  if (q > 1) {
    int c = n - q + s, a = q - 2, b = s - q;
    ans += (double)a / c / (c - a) + (double)b / c / (c - b) + 1.0 / c;
  } else
    ans += 1.0 / n;
  for (int i = 0; i < v[x].size(); i++)
    if (!vis[v[x][i]]) Dfs(v[x][i]);
  n--;
  q -= cir[x];
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1, x, y; i <= n; i++)
    scanf("%d%d", &x, &y), v[x + 1].push_back(y + 1), v[y + 1].push_back(x + 1);
  Find_Cir(1, 0);
  for (int i = 1; i <= n; i++) {
    memset(vis, 0, sizeof(vis));
    Dfs(i);
  }
  printf("%.20lf\n", ans);
}


#include <cmath>
#include <cstdio>

const int MAXN = 3005, MAXLOG = 15;

template<typename _T>
void read( _T &x )
{
	x = 0;char s = getchar();int f = 1;
	while( s > '9' || s < '0' ){if( s == '-' ) f = -1; s = getchar();}
	while( s >= '0' && s <= '9' ){x = ( x << 3 ) + ( x << 1 ) + ( s - '0' ), s = getchar();}
	x *= f;
}

template<typename _T>
void write( _T x )
{
	if( x < 0 ){ putchar( '-' ); x = ( ~ x ) + 1; }
	if( 9 < x ){ write( x / 10 ); }
	putchar( x % 10 + '0' );
}

template<typename _T>
_T ABS( const _T a )
{
	return a < 0 ? -a : a;
}

struct edge
{
	int to, nxt;
}Graph[MAXN << 1];

int f[MAXN][MAXLOG];
int sta[MAXN], top;
int cir[MAXN];
int head[MAXN], dep[MAXN], col[MAXN];
int N, lg2, cnt, siz;
bool inSta[MAXN], onCir[MAXN];

void balance( int &u, const int steps ) { for( int i = 0 ; ( 1 << i ) <= steps ; i ++ ) if( steps & ( 1 << i ) ) u = f[u][0]; }

void addEdge( const int from, const int to )
{
	Graph[++ cnt].to = to, Graph[cnt].nxt = head[from];
	head[from] = cnt;
}

bool findCircle( const int u, const int fr )
{
	if( inSta[u] )
	{
		int v;
		do onCir[cir[++ siz] = v = sta[top --]] = true; while( v ^ u );
		return true;
	}
	inSta[sta[++ top] = u] = true;
	for( int i = head[u], v ; i ; i = Graph[i].nxt )
	{
		v = Graph[i].to;
		if( v ^ fr && findCircle( v, u ) ) return true;
	}
	inSta[sta[top --]] = false;
	return false;
}

void DFS( const int u, const int fa, const int c )
{
	col[u] = c, f[u][0] = fa, dep[u] = dep[fa] + 1;
	for( int i = head[u], v ; i ; i = Graph[i].nxt )
		if( ( v = Graph[i].to ) ^ fa && ! onCir[v] )
			DFS( v, u, c );
}

void init()
{
	lg2 = log2( N );
	for( int j = 1 ; j <= lg2 ; j ++ )
		for( int i = 1 ; i <= N ; i ++ )
			f[i][j] = f[f[i][j - 1]][j - 1];
}

int LCA( int u, int v )
{
	if( dep[u] > dep[v] ) balance( u, dep[u] - dep[v] );
	if( dep[v] > dep[u] ) balance( v, dep[v] - dep[u] );
	if( u == v ) return u;
	for( int i = lg2 ; ~ i ; i -- ) if( f[u][i] ^ f[v][i] ) u = f[u][i], v = f[v][i];
	return f[u][0];
}

int dist( const int u, const int v ) { return dep[u] + dep[v] - 2 * dep[LCA( u, v )] + 1; }

int main()
{
	read( N );
	for( int i = 1, fr, to ; i <= N ; i ++ )
		read( fr ), read( to ), fr ++, to ++, addEdge( fr, to ), addEdge( to, fr );
	findCircle( 1, 0 );
	for( int i = 1 ; i <= siz ; i ++ ) DFS( cir[i], 0, i );
	init();
	double ans = 0;
	for( int i = 1 ; i <= N ; i ++ )
		for( int j = 1 ; j <= N ; j ++ )
		{
			if( col[i] == col[j] ) ans += 1.0 / dist( i, j );
			else
			{
				int lin = dep[i] + dep[j], lef = ABS( col[i] - col[j] ) - 1, rig = siz - 2 - lef;
				ans += 1.0 / ( lin + lef ) + 1.0 / ( lin + rig ) - 1.0 / ( lin + lef + rig );
			}
		}
	printf( "%.15lf\n", ans );
	return 0;
}


#include <cmath>
#include <cstdio>

const int MAXN = 3005, MAXLOG = 15;

template<typename _T>
void read( _T &x )
{
	x = 0;char s = getchar();int f = 1;
	while( s > '9' || s < '0' ){if( s == '-' ) f = -1; s = getchar();}
	while( s >= '0' && s <= '9' ){x = ( x << 3 ) + ( x << 1 ) + ( s - '0' ), s = getchar();}
	x *= f;
}

template<typename _T>
void write( _T x )
{
	if( x < 0 ){ putchar( '-' ); x = ( ~ x ) + 1; }
	if( 9 < x ){ write( x / 10 ); }
	putchar( x % 10 + '0' );
}

template<typename _T>
_T ABS( const _T a )
{
	return a < 0 ? -a : a;
}

struct edge
{
	int to, nxt;
}Graph[MAXN << 1];

int f[MAXN][MAXLOG];
int sta[MAXN], top;
int cir[MAXN];
int head[MAXN], dep[MAXN], col[MAXN];
int N, lg2, cnt, siz;
bool inSta[MAXN], onCir[MAXN];

void balance( int &u, const int steps )
{
	for( int i = 0 ; ( 1 << i ) <= steps ; i ++ )
		if( steps & ( 1 << i ) )
			u = f[u][i];
}

void addEdge( const int from, const int to )
{
	Graph[++ cnt].to = to, Graph[cnt].nxt = head[from];
	head[from] = cnt;
}

bool findCircle( const int u, const int fr )
{
	if( inSta[u] )
	{
		int v;
		do onCir[cir[++ siz] = v = sta[top --]] = true; while( v ^ u );
		return true;
	}
	inSta[sta[++ top] = u] = true;
	for( int i = head[u], v ; i ; i = Graph[i].nxt )
	{
		v = Graph[i].to;
		if( v ^ fr && findCircle( v, u ) ) return true;
	}
	inSta[sta[top --]] = false;
	return false;
}

void DFS( const int u, const int fa, const int c )
{
	col[u] = c, f[u][0] = fa, dep[u] = dep[fa] + 1;
	for( int i = head[u], v ; i ; i = Graph[i].nxt )
		if( ( v = Graph[i].to ) ^ fa && ! onCir[v] )
			DFS( v, u, c );
}

void init()
{
	lg2 = log2( N );
	for( int j = 1 ; j <= lg2 ; j ++ )
		for( int i = 1 ; i <= N ; i ++ )
			f[i][j] = f[f[i][j - 1]][j - 1];
}

int LCA( int u, int v )
{
	if( dep[u] > dep[v] ) balance( u, dep[u] - dep[v] );
	if( dep[v] > dep[u] ) balance( v, dep[v] - dep[u] );
	if( u == v ) return u;
	for( int i = lg2 ; ~ i ; i -- ) if( f[u][i] ^ f[v][i] ) u = f[u][i], v = f[v][i];
	return f[u][0];
}

int dist( const int u, const int v ) { return dep[u] + dep[v] - 2 * dep[LCA( u, v )] + 1; }

int main()
{
	read( N );
	for( int i = 1, fr, to ; i <= N ; i ++ )
		read( fr ), read( to ), fr ++, to ++, addEdge( fr, to ), addEdge( to, fr );
	findCircle( 1, 0 );
	for( int i = 1 ; i <= siz ; i ++ ) DFS( cir[i], 0, i );
	init();
	double ans = 0;
	for( int i = 1 ; i <= N ; i ++ )
		for( int j = 1 ; j <= N ; j ++ )
		{
			if( col[i] == col[j] ) ans += 1.0 / dist( i, j );
			else
			{
				int lin = dep[i] + dep[j], lef = ABS( col[i] - col[j] ) - 1, rig = siz - 2 - lef;
				ans += 1.0 / ( lin + lef ) + 1.0 / ( lin + rig ) - 1.0 / ( lin + lef + rig );
			}
		}
	printf( "%.15lf\n", ans );
	return 0;
}


#include<bits/stdc++.h>
typedef long long ll;
ll gi(){
	ll x=0,f=1;
	char ch=getchar();
	while(!isdigit(ch))f^=ch=='-',ch=getchar();
	while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
	return f?x:-x;
}
std::mt19937 rnd(time(NULL));
#define rand rnd
#define pr std::pair<int,int>
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
template<class T>void cxk(T&a,T b){a=a>b?a:b;}
template<class T>void cnk(T&a,T b){a=a<b?a:b;}
#ifdef mod
int pow(int x,int y){
	int ret=1;
	while(y){
		if(y&1)ret=1ll*ret*x%mod;
		x=1ll*x*x%mod;y>>=1;
	}
	return ret;
}
template<class Ta,class Tb>void inc(Ta&a,Tb b){a=a+b>=mod?a+b-mod:a+b;}
template<class Ta,class Tb>void dec(Ta&a,Tb b){a=a>=b?a-b:a+mod-b;}
#endif
int fir[3010],dis[6010],nxt[6010],id;
void link(int a,int b){nxt[++id]=fir[a],fir[a]=id,dis[id]=b;}
int cir[3010],stk[3010],tp,ins[3010],vis[3010],m,pos[3010],dep[3010];
void getcycle(int x,int fa=-1){
	vis[x]=1;stk[++tp]=x;ins[x]=tp;
	for(int i=fir[x];i;i=nxt[i]){
		if(dis[i]==fa)continue;
		if(!vis[dis[i]])getcycle(dis[i],x);
		else if(ins[dis[i]]&&!m)for(int j=ins[dis[i]];j<=tp;++j)cir[++m]=stk[j];
	}
	ins[x]=0;--tp;
}
int dist[3010][3010];
void DFS(int x){
	for(int i=fir[x];i;i=nxt[i]){
		if(pos[dis[i]])continue;
		dep[dis[i]]=dep[x]+1;
		pos[dis[i]]=pos[x];
		DFS(dis[i]);
	}
}
void getdist(int x,int*di,int fa=-1){
	for(int i=fir[x];i;i=nxt[i])
		if(!di[dis[i]]){
			di[dis[i]]=di[x]+1;
			getdist(dis[i],di,x);
		}
}
int main(){
#ifdef LOCAL
	freopen("in.in","r",stdin);
	//freopen("out.out","w",stdout);
#endif
	int n=gi(),a,b;
	for(int i=1;i<=n;++i)a=gi()+1,b=gi()+1,link(a,b),link(b,a);
	getcycle(1);
	for(int i=1;i<=m;++i)pos[cir[i]]=i;
	for(int i=1;i<=m;++i)DFS(cir[i]);
	double ans=0;
	for(int i=1;i<=n;++i)dist[i][i]=1,getdist(i,dist[i]);
	for(int i=1;i<=n;++i)
		for(int j=i+1;j<=n;++j)
			if(pos[i]==pos[j])ans+=1./dist[i][j];
			else{
				int a=abs(pos[i]-pos[j]),b=m-a;
				ans+=1./(dep[i]+dep[j]+a+1);
				ans+=1./(dep[i]+dep[j]+b+1);
				ans-=1./(dep[i]+dep[j]+m);
			}
	printf("%.10lf\n",2*ans+n);
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef bool boolean;

const int N = 3e3 + 5;

template <typename T>
T _abs(T a) {
	return (a < 0) ? (-a) : (a);
}

int n, m;
vector<int> cir;
vector<int> G[N];

stack<int> S;
boolean vis[N], onc[N];
void dfs(int p, int fa) {
	if (vis[p]) {
		int cur;
		do {
			cur = S.top();
			S.pop();
			onc[cur] = true;
			cir.push_back(cur);
		} while (cur != p);
		throw 1;
	}
	vis[p] = true;
	S.push(p);
	for (auto& e : G[p]) {
		if (e ^ fa) {
			dfs(e, p);
		}
	}
}

int dep[N], id[N];
vector<int> T[N];
void dfs(int p, int fa, int d, int _id) {
	dep[p] = d, id[p] = _id;
	T[_id].push_back(p);
	for (auto& e : G[p]) {
		if ((e ^ fa) && !onc[e]) {
			dfs(e, p, d + 1, _id);
		}
	}
}

double ans = 0;
void dfs(int p, int fa, int dis) {
	ans += 1.0 / dis;
	for (auto& e : G[p]) {
		if (id[e] == id[p] && e != fa) {
			dfs(e, p, dis + 1);
		}
	}
}

int main() {
	scanf("%d", &n);
	for (int i = 1, u, v; i <= n; i++) {
		scanf("%d%d", &u, &v);
		G[u].push_back(v);
		G[v].push_back(u);
	}
	try {
		dfs(0, -1);
	} catch (int) {
		m = cir.size();
	}
	for (int i = 0; i < m; i++) {
		dfs(cir[i], -1, 0, i);
	}
	for (int i = 0; i < n; i++) {
		dfs(i, -1, 1);
	}
	for (int i = 0; i < m; i++) {
		for (int j = 0; j < m; j++) {
			if (i == j)
				continue;
			int d1 = _abs(i - j), d2 = m - d1;
			for (auto& p : T[i]) {
				for (auto& q : T[j]) {
					ans += 1.0 / (dep[p] + dep[q] + d1 + 1);
					ans += 1.0 / (dep[p] + dep[q] + d2 + 1);
					ans -= 1.0 / (dep[p] + dep[q] + m);
				}
			}
		}
	}
	printf("%.9lf\n", ans);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
inline int read(){
	int x=0,f=1;
	char p=getchar();
	while(!isdigit(p)){
		if(p=='-') f=-1;
		p=getchar();
	}
	while(isdigit(p)) x=(x<<3)+(x<<1)+(p^48),p=getchar();
	return x*f;
}

const int maxn=3e3+5;

int n,head[maxn],ver[maxn<<1],nxt[maxn<<1],f[maxn][14],tot;
int dep[maxn],d[maxn],a[maxn],col[maxn],cir[maxn];
int vis[maxn],cnt=1,stk[maxn],top;
double ans;

inline void add(int x,int y){
	nxt[++cnt]=head[x];
	head[x]=cnt;
	ver[cnt]=y;
}

inline bool find_circle(int x,int fr){
	if(vis[x]){
		int tmp=0;
		do{a[++tot]=tmp=stk[top--];}while(x!=tmp);
		return 1;
	}stk[++top]=x;vis[x]=1;
	for(int i=head[x];i;i=nxt[i]){
		if(i==(fr^1)) continue;
		int y=ver[i];
		if(find_circle(y,i)) return 1;
	}
	vis[stk[top--]]=0;return 0;
}

inline int lca(int x,int y){
	if(dep[x]<dep[y]) swap(x,y);
	for(int i=13;i>=0;i--) if((dep[x]-dep[y])>=1<<i) x=f[x][i];
	if(x==y) return x;
	for(int i=13;i>=0;i--) if(f[x][i]!=f[y][i]) x=f[x][i],y=f[y][i];
	return f[x][0];
}

inline int dis(int x,int y){return dep[x]+dep[y]-2*dep[lca(x,y)];}
inline void dfs(int x,int fa,int rt){
	col[x]=rt;dep[x]=dep[fa]+1;f[x][0]=fa;
	for(int i=head[x];i;i=nxt[i]){
		int y=ver[i];
		if(y==fa) continue;
		dfs(y,x,rt);
	}
}

int main(){
	n=read();
	for(int i=1,x,y;i<=n;i++) x=read()+1,y=read()+1,add(x,y),add(y,x);
	find_circle(1,-1);
	memset(vis,0,sizeof(vis));
	for(int i=1;i<=tot;i++) vis[a[i]]=1;
	for(int j=1;j<=tot;j++){
		int x=a[j];
		for(int i=head[x];i;i=nxt[i]){
			int y=ver[i];
			if(vis[y]) continue;
			dfs(y,x,x);
		}
	}
//	for(int i=1;i<=tot;i++) cout<<a[i]<<" ";
//	cout<<endl;
	for(int i=1;i<=tot;i++) d[a[i]]=i-1;
	for(int i=1;i<=n;i++) for(int j=1;j<=n;j++){
		if(i==j){ans+=1;continue;}
		int w=0;
		if(vis[i]) w++;if(vis[j]) w++;
		if(w==0){
			if(col[i]==col[j]){ans+=1.0/dis(i,j);continue;}
			int e=dep[i]+dep[j]+tot;
			int r=dep[i]+dep[j]+abs(d[col[i]]-d[col[j]])+1;
			int t=dep[i]+dep[j]+tot-abs(d[col[i]]-d[col[j]])+1;
//			cout<<e<<" "<<r<<" "<<t<<endl;
			ans+=1.0/r;ans+=1.0/t;ans-=1.0/e;
		}
		if(w==1){
			int x=i,y=j;
			if(vis[j]) swap(x,y);
			if(col[y]==x){ans+=1.0/(dep[y]+1);continue;}
			int e=dep[y]+tot;
			int r=dep[y]+abs(d[x]-d[col[y]])+1;
			int t=dep[y]+tot-abs(d[x]-d[col[y]])+1;
//			cout<<x<<" "<<y<<" "<<e<<" "<<r<<" "<<t<<endl;
			ans+=1.0/r;ans+=1.0/t;ans-=1.0/e;
		}
		if(w==2){
			int e=tot;
			int r=abs(d[i]-d[j])+1;
			int t=tot-abs(d[i]-d[j])+1;
//			cout<<i<<" "<<j<<" "<<e<<" "<<r<<" "<<t<<endl;
			ans+=1.0/r;ans+=1.0/t;ans-=1.0/e;
		}
	}
	printf("%.8f\n",ans);
	return 0;
}


import java.util.*;
import java.io.*;
import static java.lang.Math.*;

public class Main{
  public static void main(String[] args){
    try{
      new Main().run();
    }catch (Exception e){
      e.printStackTrace();
    }
  }

  void run() throws Exception{
    Scanner sc = new Scanner(new File("input.txt"));
    int n = sc.nextInt();
    String s = sc.next();
    int start = s.indexOf("1");
    s = s.substring(start+1);
    int next = s.indexOf("1");
    int dif = next;
    boolean yes = true;
    while(s.indexOf("1") >= 0){
      next = s.indexOf("1");
      if(next != dif)yes = false;
      s = s.substring(next+1);
    }
    FileWriter fw = new FileWriter(new File("output.txt"));
    fw.write(yes ? "YES" : "NO");
    fw.flush();
    fw.close();
    //System.out.println(yes ? "YES" : "NO");
  }
}


import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class ExtraterrestrialIntelligence {

    /**
     * @param args
     * @throws IOException
     * @throws NumberFormatException
     */
    public static void main(String[] args) throws NumberFormatException, IOException {
        FileReader in=new FileReader("input.txt");
        BufferedReader r=new BufferedReader(in);

        int day=Integer.parseInt(r.readLine());
        String s=r.readLine();
        int interval=0,q=0,p=0;
        for(int i=0;i<day;i++){
            char c=s.charAt(i);
            q=i;
            if(c=='1')break;
        }
        for(int i=q+1;i<day;i++){
            char c=s.charAt(i);
            q=i;
            if(c=='1')break;
            interval++;
        }
        for(int i=q+1;i<day;i++){
            char c=s.charAt(i);
            if(c=='1'){
                if(p!=interval){
                    System.out.println("NO");
                    System.exit(0);
                }
                p=0;
                continue;
            }
            p++;
        }
        System.out.println("YES");
    }

}


import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;

public class ExtraterrestrialIntelligence {

    /**
     * @param args
     * @throws IOException
     * @throws NumberFormatException
     */
    public static void main(String[] args) throws NumberFormatException, IOException {
        FileReader in=new FileReader("input.txt");
        BufferedReader r=new BufferedReader(in);

        int day=Integer.parseInt(r.readLine());
        String s=r.readLine();
        int interval=0,q=0,p=0;
        for(int i=0;i<day;i++){
            char c=s.charAt(i);
            q=i;
            if(c=='1')break;
        }
        for(int i=q+1;i<day;i++){
            char c=s.charAt(i);
            q=i;
            if(c=='1')break;
            interval++;
        }
        for(int i=q+1;i<day;i++){
            char c=s.charAt(i);
            if(c=='1'){
                if(p!=interval){
                    out("NO");
                    System.exit(0);
                }
                p=0;
                continue;
            }
            p++;
        }
        out("YES");
    }

    private static void out(String s) throws IOException{
        File file = new File("output.txt");
        PrintWriter pw = new PrintWriter(new BufferedWriter(new FileWriter(file)));
        pw.println(s);
        pw.close();
    }

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class ExtraterrestrialIntelligence {

    /**
     * @param args
     * @throws IOException
     * @throws NumberFormatException
     */
    public static void main(String[] args) throws NumberFormatException, IOException {
        BufferedReader r=new BufferedReader(new InputStreamReader(System.in));

        int day=Integer.parseInt(r.readLine());
        String s=r.readLine();
        int interval=0,q=0,p=0;
        for(int i=0;i<day;i++){
            char c=s.charAt(i);
            q=i;
            if(c=='1')break;
        }
        for(int i=q+1;i<day;i++){
            char c=s.charAt(i);
            q=i;
            if(c=='1')break;
            interval++;
        }
        for(int i=q+1;i<day;i++){
            char c=s.charAt(i);
            if(c=='1'){
                if(p!=interval){
                    System.out.println("NO");
                    System.exit(0);
                }
                p=0;
                continue;
            }
            p++;
        }
        System.out.println("YES");
    }

}


import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;

public class ExtraterrestrialIntelligence {

    /**
     * @param args
     * @throws IOException
     * @throws NumberFormatException
     */
    public static void main(String[] args) throws NumberFormatException, IOException {
        FileReader in=new FileReader("input.txt");
        BufferedReader r=new BufferedReader(in);

        int day=Integer.parseInt(r.readLine());
        String s=r.readLine();
        int interval=0,q=0,p=0;
        for(int i=0;i<day;i++){
            char c=s.charAt(i);
            q=i;
            if(c=='1')break;
        }
        for(int i=q+1;i<day;i++){
            char c=s.charAt(i);
            q=i;
            if(c=='1')break;
            interval++;
        }
        for(int i=q+1;i<day;i++){
            char c=s.charAt(i);
            if(c=='1'){
                if(p!=interval){
                    out("NO");
                    System.exit(0);
                }
                p=0;
                continue;
            }
            p++;
        }
        out("YES");
    }

    private static void out(String s) throws IOException{
        File file = new File("output.txt");
        PrintWriter pw = new PrintWriter(new BufferedWriter(new FileWriter(file)));
        pw.print(s);
    }

}


    import java.io.*;
    import java.text.*;
    import java.util.*;
    import java.util.regex.*;

    public class Main{
        static class Run implements Runnable{
            //TODO parameters
            final boolean consoleIO = false;
            final String inFile = "input.txt";
            final String outFile = "output.txt";

            @Override
            public void run() {
                int n = nextInt();
                String s = nextLine();
                int len = s.length();

                int i = 0;
                for(; i < len; ++i)
                    if(s.charAt(i) == '1')
                        break;

                int f = 0;
                int j = i+1;
                for(; j < len; ++j)
                    if(s.charAt(j) != '1')
                        ++f;
                    else
                        break;

                int cur = 0;
                boolean res = true;
                for(int k = j+1; k < len; ++k)
                    if(s.charAt(k) == '1') {
                        if(cur != f) {
                            res = false;
                            break;
                        }
                        else
                            cur = 0;
                    }
                    else
                        ++cur;

                print(res ? "YES" : "NO");
                close();
            }
        //=========================================================================================================================
            BufferedReader in;
            PrintWriter out;
            StringTokenizer strTok;

            Run() {
                if (consoleIO) {
                    initConsoleIO();
                }
                else {
                    initFileIO();
                }
            }

            void initConsoleIO() {
                in = new BufferedReader(new InputStreamReader(System.in));
                out = new PrintWriter(new OutputStreamWriter(System.out));
            }

            void initFileIO() {
                try {
                    in = new BufferedReader(new FileReader(inFile));
                    out = new PrintWriter(new FileWriter(outFile));
                } catch (FileNotFoundException e) {
                    e.printStackTrace();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }

            void close() {
                try {
                    in.close();
                    out.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }

            int nextInt() {
                return Integer.parseInt(nextToken());
            }

            double nextDouble() {
                return Double.parseDouble(nextToken());
            }

            float nextFloat() {
                return Float.parseFloat(nextToken());
            }

            long nextLong() {
                return Long.parseLong(nextToken());
            }

            String nextLine() {
                try {
                    return in.readLine();
                } catch (IOException e) {
                    return "__NULL";
                }
            }

            boolean hasMoreTokens() {
                return (strTok == null) || (strTok.hasMoreTokens());
            }

            String nextToken() {
                while (strTok == null || !strTok.hasMoreTokens()) {
                    String line;
                    try {
                        line = in.readLine();
                        strTok = new StringTokenizer(line);
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }

                return strTok.nextToken();
            }

            void cout(Object o){
                System.out.println(o);
            }

            void print(Object o) {
                out.write(o.toString());
            }

            void println(Object o) {
                out.write(o.toString() + '\n');
            }

            void printf(String format, Object... args) {
                out.printf(format, args);
            }

            String sprintf(String format, Object... args) {
            return MessageFormat.format(format, args);
        }
        }

        static class Pair<A, B> {
            A a;
            B b;

            A f() {
                return a;
            }

            B s() {
                return b;
            }

            Pair(A a, B b) {
                this.a = a;
                this.b = b;
            }

            Pair(Pair<A, B> p) {
                a = p.f();
                b = p.s();
            }
        }

        public static void main(String[] args) throws IOException {
            Run run = new Run();
            Thread thread = new Thread(run);
            thread.run();
        }
    }


    import java.io.*;
    import java.text.*;
    import java.util.*;
    import java.util.regex.*;

    public class Main{
        static class Run implements Runnable{
            //TODO parameters
            final boolean consoleIO = true;
            final String inFile = "input.txt";
            final String outFile = "output.txt";

            @Override
            public void run() {
                int n = nextInt();
                String s = nextLine();
                int len = s.length();

                int i = 0;
                for(; i < len; ++i)
                    if(s.charAt(i) == '1')
                        break;

                int f = 0;
                int j = i+1;
                for(; j < len; ++j)
                    if(s.charAt(j) != '1')
                        ++f;
                    else
                        break;

                int cur = 0;
                boolean res = true;
                for(int k = j+1; k < len; ++k)
                    if(s.charAt(k) == '1') {
                        if(cur != f) {
                            res = false;
                            break;
                        }
                        else
                            cur = 0;
                    }
                    else
                        ++cur;

                print(res ? "YES" : "NO");
                close();
            }
        //=========================================================================================================================
            BufferedReader in;
            PrintWriter out;
            StringTokenizer strTok;

            Run() {
                if (consoleIO) {
                    initConsoleIO();
                }
                else {
                    initFileIO();
                }
            }

            void initConsoleIO() {
                in = new BufferedReader(new InputStreamReader(System.in));
                out = new PrintWriter(new OutputStreamWriter(System.out));
            }

            void initFileIO() {
                try {
                    in = new BufferedReader(new FileReader(inFile));
                    out = new PrintWriter(new FileWriter(outFile));
                } catch (FileNotFoundException e) {
                    e.printStackTrace();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }

            void close() {
                try {
                    in.close();
                    out.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }

            int nextInt() {
                return Integer.parseInt(nextToken());
            }

            double nextDouble() {
                return Double.parseDouble(nextToken());
            }

            float nextFloat() {
                return Float.parseFloat(nextToken());
            }

            long nextLong() {
                return Long.parseLong(nextToken());
            }

            String nextLine() {
                try {
                    return in.readLine();
                } catch (IOException e) {
                    return "__NULL";
                }
            }

            boolean hasMoreTokens() {
                return (strTok == null) || (strTok.hasMoreTokens());
            }

            String nextToken() {
                while (strTok == null || !strTok.hasMoreTokens()) {
                    String line;
                    try {
                        line = in.readLine();
                        strTok = new StringTokenizer(line);
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }

                return strTok.nextToken();
            }

            void cout(Object o){
                System.out.println(o);
            }

            void print(Object o) {
                out.write(o.toString());
            }

            void println(Object o) {
                out.write(o.toString() + '\n');
            }

            void printf(String format, Object... args) {
                out.printf(format, args);
            }

            String sprintf(String format, Object... args) {
            return MessageFormat.format(format, args);
        }
        }

        static class Pair<A, B> {
            A a;
            B b;

            A f() {
                return a;
            }

            B s() {
                return b;
            }

            Pair(A a, B b) {
                this.a = a;
                this.b = b;
            }

            Pair(Pair<A, B> p) {
                a = p.f();
                b = p.s();
            }
        }

        public static void main(String[] args) throws IOException {
            Run run = new Run();
            Thread thread = new Thread(run);
            thread.run();
        }
    }


import java.io.*;
import java.util.*;

import static java.lang.Math.*;
import static java.util.Arrays.fill;
import static java.util.Arrays.binarySearch;
import static java.util.Arrays.sort;

public class Main {

	public static void main(String[] args) throws IOException {
		new Thread(null, new Runnable() {
			public void run() {
				try {
					new Main().run();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}, "1", 1 << 24).start();
	}

	BufferedReader in;
	PrintWriter out;
	StringTokenizer st = new StringTokenizer("");

	void run() throws IOException {
		in = new BufferedReader(new FileReader("input.txt"));
		out = new PrintWriter("output.txt");

		int N = nextInt();
		int[] a = new int [N];
		int k = 0;
		for (char c : nextToken().toCharArray())
			a[k++] = c - '0';
		int fst = N - 1;
		int cnt = 0;
		for (int i = N - 1; i >= 0; i--)
			if (a[i] == 1) {
				cnt++;
				fst = i;
			}
		boolean ok = false;
		lp: for (int l = 1; l < N; l++) {
			int cur = 0;
			for (int i = fst; i < N; i += l) {
				if (a[i] == 1) {
					cur++;
				} else {
					continue lp;
				}
				if (cur == cnt) {
					ok = true;
					break lp;
				}
			}

		}
		out.println(ok ? "YES" : "NO");
		out.close();
	}

	String nextToken() throws IOException {
		while (!st.hasMoreTokens())
			st = new StringTokenizer(in.readLine());
		return st.nextToken();
	}

	int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}

	long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}

	double nextDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}

	String nextLine() throws IOException {
		st = new StringTokenizer("");
		return in.readLine();
	}

	boolean EOF() throws IOException {
		while (!st.hasMoreTokens()) {
			String s = in.readLine();
			if (s == null)
				return true;
			st = new StringTokenizer(s);
		}
		return false;
	}
}


import java.util.*;
import java.io.*;

public class ETInt
{
	public static int find(String s, char n)
	{
		for(int i = 0; i < s.length(); ++i)
			if(s.charAt(i) == n)
				return i;
		return -1;
	}

	public static int findGap(String s, char n)
	{
		int k = find(s, n);

		for(int i = k + 1; i < s.length(); ++i)
			if(s.charAt(i) == n)
				return i - k;
		return -1;
	}

	public static void main(String[] args) throws IOException, FileNotFoundException
	{
		Scanner in = new Scanner(new File("input.txt"));
		PrintWriter out = new PrintWriter(new FileWriter("output.txt"));
		int n = in.nextInt();
		String s = in.next();
		int cur, old, gap, ls;
		boolean sig = true;

		cur = old = gap = 0;
		ls = -1;

		gap = findGap(s, '1');

		for(int i = 0; i < s.length(); ++i)
		{
			char ch = s.charAt(i);

			if(ch == '1')
			{
				if(ls == -1)
				{
					ls = 1;
					cur = i;
				}
				else
				{
					old = cur;
					cur = i;

					if(cur - old != gap)
					{
						sig = false;
						break;
					}
				}
			}
		}

		out.println(sig ? "YES" : "NO");
		out.flush();
		out.close();
	}
}


import java.io.*;
import java.util.*;
import static java.lang.Math.*;

public class BetaRound36_A implements Runnable {

	final boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE") != null;
	BufferedReader in;
	PrintWriter out;
	StringTokenizer tok = new StringTokenizer("");

	void init() throws IOException {
		in = new BufferedReader(new FileReader("input.txt"));
		out = new PrintWriter("output.txt");
	}

	String readString() throws IOException {
		while (!tok.hasMoreTokens()) {
			tok = new StringTokenizer(in.readLine());
		}
		return tok.nextToken();
	}

	int readInt() throws IOException {
		return Integer.parseInt(readString());
	}

	@Override
	public void run() {
		try {
			long t1 = System.currentTimeMillis();
			init();
			solve();
			out.close();
			long t2 = System.currentTimeMillis();
			System.err.println("Time = " + (t2 - t1));
		} catch (Exception e) {
			e.printStackTrace(System.err);
			System.exit(-1);
		}
	}

	public static void main(String[] args) {
		new Thread(new BetaRound36_A()).start();
	}

	void solve() throws IOException {
		int n = readInt();
		String s = readString();
		int[] a = new int[n];
		int m = 0;
		for (int i = 0; i < n; i++) {
			a[i] = s.charAt(i) - '0';
			if (a[i] == 1) m++;
		}
		int[] x = new int[m - 1];
		int[] y = new int[m - 1];
		int ix = 0, iy = 0;
		for (int i = 0; i < n; i++) {
			if (a[i] == 1) {
				x[ix++] = i;
				int j = i + 1;
				while (a[j] == 0) j++;
				y[iy++] = j;
				if (iy == m - 1) break;
			}
		}
		boolean ans = true;
		for (int i = 1; i < m - 1; i++) {
			if (x[i] - y[i] != x[i - 1] - y[i - 1]) {
				ans = false;
				break;
			}
		}
		out.print(ans ? "YES" : "NO");
	}

}


import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;

public class Main {
//  private static StreamTokenizer in;
    private static PrintWriter out;
    private static BufferedReader inB;

//  private static int nextInt() throws Exception{
//      in.nextToken();
//      return (int)in.nval;
//  }
//
//  private static String nextString() throws Exception{
//      in.nextToken();
//      return in.sval;
//  }

    static{
//      in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
//      inB = (new BufferedReader(new InputStreamReader(System.in)));
//      out = new PrintWriter(System.out);
        try {
            inB = (new BufferedReader(new InputStreamReader(new FileInputStream("input.txt"))));
            out = new PrintWriter(new FileOutputStream("output.txt"));
        } catch (FileNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    private static int gcd(int a, int b) {
        if(a == 0)return b;
        return gcd(b%a, a);
    }

    public static void main(String[] args)throws Exception{
        int n = Integer.parseInt(inB.readLine());
        char[] c = inB.readLine().toCharArray();

        int i=0;
        for(;c[i] == '0';i++);

        int first = -1;
        int last = i;
        ++i;
        for(;i<c.length;++i) {
            if(c[i] == '0')continue;
            if(first == -1) {
                first = i - last;
                last = i;
                continue;
            }
            if(i-last != first) {
                out.println("NO");
                out.flush();
                return;
            }
            last = i;
        }

        out.println("YES");
        out.flush();
    }
}


import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.StreamTokenizer;

public class Main {
    private static StreamTokenizer in;
    private static PrintWriter out;
    private static BufferedReader inB;

    private static int nextInt() throws Exception{
        in.nextToken();
        return (int)in.nval;
    }

    private static String nextString() throws Exception{
        in.nextToken();
        return in.sval;
    }

    static{
        in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
        inB = (new BufferedReader(new InputStreamReader(System.in)));
        out = new PrintWriter(System.out);
    }

    private static int gcd(int a, int b) {
        if(a == 0)return b;
        return gcd(b%a, a);
    }

    public static void main(String[] args)throws Exception{
        int n = nextInt();
        char[] c = inB.readLine().toCharArray();

        int i=0;
        for(;c[i] == '0';i++);

        int first = 0;
        int last = i;
        ++i;
        for(;i<n;++i) {
            if(c[i] == '0')continue;
            if(first == 0) {
                first = i - last;
                last = i;
                continue;
            }
            if(i-last != first) {
                System.out.println("NO");
                return;
            }
            last = i;
        }

        out.println("YES");
        out.flush();
    }
}


import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;

public class Main {
//  private static StreamTokenizer in;
    private static PrintWriter out;
    private static BufferedReader inB;

//  private static int nextInt() throws Exception{
//      in.nextToken();
//      return (int)in.nval;
//  }
//
//  private static String nextString() throws Exception{
//      in.nextToken();
//      return in.sval;
//  }

    static{
//      in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
        inB = (new BufferedReader(new InputStreamReader(System.in)));
        out = new PrintWriter(System.out);
        try {
            inB = (new BufferedReader(new InputStreamReader(new FileInputStream("input.txt"))));
            out = new PrintWriter(new FileOutputStream("output.txt"));
        } catch (FileNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    private static int gcd(int a, int b) {
        if(a == 0)return b;
        return gcd(b%a, a);
    }

    public static void main(String[] args)throws Exception{
        int n = Integer.parseInt(inB.readLine());
        char[] c = inB.readLine().toCharArray();

        int i=0;
        for(;c[i] == '0';i++);

        int first = 0;
        int last = i;
        ++i;
        for(;i<n;++i) {
            if(c[i] == '0')continue;
            if(first == 0) {
                first = i - last;
                last = i;
                continue;
            }
            if(i-last != first) {
                System.out.println("NO");
                return;
            }
            last = i;
        }

        out.println("YES");
        out.flush();
    }
}


import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.StreamTokenizer;

public class A {
    private static BufferedReader in;
    private static PrintWriter out;

//  private static int nextInt() throws Exception {
//      in.nextToken();
//      return (int) in.nval;
//  }
//
//  private static String nextString() throws Exception {
//      in.nextToken();
//      return in.sval;
//  }

    public static void main(String[] args) throws Exception {
        in = new BufferedReader(new InputStreamReader(
                new FileInputStream("input.txt")));
         out = new PrintWriter("output.txt");
//      out = new PrintWriter(System.out);

        in.readLine();
//      in.ordinaryChars('0', '9');
        char[] c = in.readLine().toCharArray();
        boolean b = false;
        boolean res = true;
        m:for (int i = 0; i < c.length; i++) {
            if (c[i] == '1')
                b = true;
            if (!b)
                continue;
            i++;
            if(i == c.length)break;
            int a = 0;
            for (;; i++) {
                a++;
                if (c[i] == '1')
                    break;
            }
//          System.out.println(a);
            i++;
            if(i>= c.length){res = false; break m;}
            while (i < c.length) {
                int j = 0;
                for (; j < Math.min(a, c.length - i); j++) {
                    if (c[j + i] == '1' && j != a - 1) {
//                      out.println("B");
                        res = false;
                        break m;
                    }
                    if (j == a - 1 && c[j + i] != '1') {
                        boolean l = true;
                        int k = i + j;
                        while(k<c.length){
                            if(c[k] == '1')l = false;
                            k++;
                        }
                        if(l)break m;
//                      out.println("A");
                        res = false; break m;
                    }

                }
                i+=j;
                i++;
            }

        }

        if(res)out.println("YES");else out.println("NO");

        out.flush();
    }
}


import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.StreamTokenizer;

public class Main {
//  private static StreamTokenizer in;
    private static PrintWriter out;
    private static BufferedReader inB;

//  private static int nextInt() throws Exception{
//      in.nextToken();
//      return (int)in.nval;
//  }
//
//  private static String nextString() throws Exception{
//      in.nextToken();
//      return in.sval;
//  }

    static{
//      in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
        inB = (new BufferedReader(new InputStreamReader(System.in)));
        out = new PrintWriter(System.out);
    }

    private static int gcd(int a, int b) {
        if(a == 0)return b;
        return gcd(b%a, a);
    }

    public static void main(String[] args)throws Exception{
        int n = Integer.parseInt(inB.readLine());
        char[] c = inB.readLine().toCharArray();

        int i=0;
        for(;c[i] == '0';i++);

        int first = 0;
        int last = i;
        ++i;
        for(;i<n;++i) {
            if(c[i] == '0')continue;
            if(first == 0) {
                first = i - last;
                last = i;
                continue;
            }
            if(i-last != first) {
                System.out.println("NO");
                return;
            }
            last = i;
        }

        out.println("YES");
        out.flush();
    }
}


import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;

public class Main {
//  private static StreamTokenizer in;
    private static PrintWriter out;
    private static BufferedReader inB;

//  private static int nextInt() throws Exception{
//      in.nextToken();
//      return (int)in.nval;
//  }
//
//  private static String nextString() throws Exception{
//      in.nextToken();
//      return in.sval;
//  }

    static{
//      in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
//      inB = (new BufferedReader(new InputStreamReader(System.in)));
//      out = new PrintWriter(System.out);
        try {
            inB = (new BufferedReader(new InputStreamReader(new FileInputStream("input.txt"))));
            out = new PrintWriter(new FileOutputStream("output.txt"));
        } catch (FileNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    private static int gcd(int a, int b) {
        if(a == 0)return b;
        return gcd(b%a, a);
    }

    public static void main(String[] args)throws Exception{
        int n = Integer.parseInt(inB.readLine());
        char[] c = inB.readLine().toCharArray();

        int i=0;
        for(;c[i] == '0';i++);

        int first = -1;
        int last = i;
        ++i;
        for(;i<c.length;++i) {
            if(c[i] == '0')continue;
            if(first == -1) {
                first = i - last;
                last = i;
                continue;
            }
            if(i-last != first) {
                System.out.println("NO");
                return;
            }
            last = i;
        }

        out.println("YES");
        out.flush();
    }
}


import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Outside implements Runnable {
    private void solve() throws IOException {
        int n = nextInt();
        String data = nextToken();
        int delta = -1;
        int last = -1;
        for (int i = 0; i < n; ++i) {
            if (data.charAt(i) == '1') {
                if (last != -1) {
                    int cur = i - last;
                    if (delta != -1) {
                        if (delta != cur) {
                            writer.println("NO");
                            return;
                        }
                    }
                    delta = cur;
                }
                last = i;
            }
        }
        writer.println("YES");
    }

    public static void main(String[] args) {
        new Outside().run();
    }

    static final String IN_FILE = "input.txt";
    static final String OUT_FILE = "output.txt";

    BufferedReader reader;
    StringTokenizer tokenizer;
    PrintWriter writer;

    public void run() {
        try {
            reader = new BufferedReader(new FileReader(IN_FILE));
            tokenizer = null;
            writer = new PrintWriter(OUT_FILE);
            solve();
            reader.close();
            writer.close();
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(1);
        }
    }

    int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }

    long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }

    double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }

    String nextToken() throws IOException {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            tokenizer = new StringTokenizer(reader.readLine());
        }
        return tokenizer.nextToken();
    }
}


#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <algorithm>

using namespace std;

int main(int argc, char *argv[])
{
    int n;  cin>>n;
    string s;
    cin>>s;

    vector<int>v; int c=0; bool t=false;
    for(int i=0;i<n;i++)
    {
        if(s[i]=='1' && t==false)
          t=true;
        else if(s[i]=='0' && t==true)
           c++;
        else if(s[i]=='1')
        {
            v.push_back(c);
            c=0;
        }
    }
    sort(v.begin(),v.end());
    if(v[0]==v[v.size()-1])
      cout<<"YES"<<endl;
    else
       cout<<"NO"<<endl;

    return 0;
}


#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <algorithm>

using namespace std;

int main(int argc, char *argv[])
{
    int n;  cin>>n;
    string s;
    char k;
    for(int i=0;i<n;i++)
    {
       cin>>k;  s+=k;
    }

    vector<int>v; int c=0; bool t=false;
    for(int i=0;i<s.size();i++)
    {
        if(s[i]=='1' && t==false)
          t=true;
        else if(s[i]=='0' && t==true)
           c++;
        else if(s[i]=='1')
        {
            v.push_back(c);
            c=0;
        }
    }
    sort(v.begin(),v.end());
    if(v[0]==v[v.size()-1])
      cout<<"YES"<<endl;
    else
       cout<<"NO"<<endl;

    return ;
}


#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <algorithm>

using namespace std;

int main(int argc, char *argv[])
{
    int n;  cin>>n;
    string s;
    char k;
    for(int i=0;i<n;i++)
    {
       cin>>k;  s+=k;
    }

    vector<int>v; int c=0; bool t=false;
    for(int i=0;i<s.size();i++)
    {
        if(s[i]=='1' && t==false)
          t=true;
        else if(s[i]=='0' && t==true)
           c++;
        else if(s[i]=='1')
        {
            v.push_back(c);
            c=0;
        }
    }
    sort(v.begin(),v.end());
    if(v[0]==v[v.size()-1])
      cout<<"YES"<<endl;
    else

    return 0;
}


#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <cstring>
#include <fstream>
using namespace std;

int main(int argc, char *argv[])
{
    freopen ("input.txt", "rt", stdin);
    freopen ("output.txt", "wt", stdout);
    int n;  cin>>n;

    vector<int>v; int c=0; bool t=false;
    string s;
    cin>>s;
   for(int i=0;i<s.size();i++)
    {
        if(s[i]=='1' && t==false)
          t=true;
        else if(s[i]=='0' && t==true)
           c++;
        else if(s[i]=='1')
        {
            v.push_back(c);
            c=0;
        }
    }
    sort(v.begin(),v.end());
    if(v[0]==v[v.size()-1])
      cout<<"YES"<<endl;
    else
       cout<<"NO"<<endl;

    return 0;
}


#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <algorithm>

using namespace std;

int main(int argc, char *argv[])
{
    int n;  cin>>n;

    vector<int>v; int c=0; bool t=false;
    char k;
    for(int i=0;i<n;i++)
    {
       cin>>k;
       if(k=='1' && t==false)
          t=true;
       else if(k=='0' && t==true)
           c++;
       else if(k=='1')
        {
            v.push_back(c);
            c=0;
        }
    }

 /*   for(int i=0;i<s.size();i++)
    {
        if(s[i]=='1' && t==false)
          t=true;
        else if(s[i]=='0' && t==true)
           c++;
        else if(s[i]=='1')
        {
            v.push_back(c);
            c=0;
        }
    }*/
    sort(v.begin(),v.end());
    if(v[0]==v[v.size()-1])
      cout<<"YES"<<endl;
    else
       cout<<"NO"<<endl;

    return 0;
}


#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <cmath>

using namespace std;

int main(int argc, char *argv[])
{
    int n;  cin>>n;
    string s;
    cin>>s;

    vector<int>v; int c=0; bool t=false;
    for(int i=0;i<n;i++)
    {
        if(s[i]=='1' && !t)
          t=true;
        else if(s[i]=='0' && t)
           c++;
        else if(s[i]=='1')
        {
            v.push_back(c);
            c=0;
        }
    }
    sort(v.begin(),v.end());
    if(v[0]==v[v.size()-1])
      cout<<"YES"<<endl;
    else
       cout<<"NO"<<endl;

    return 0;
}


#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <algorithm>

using namespace std;

int main(int argc, char *argv[])
{
    int n;  cin>>n;
    string s;
    cin>>s;

    vector<int>v; int c=0; bool t=false;
    for(int i=0;i<s.size();i++)
    {
        if(s[i]=='1' && t==false)
          t=true;
        else if(s[i]=='0' && t==true)
           c++;
        else if(s[i]=='1')
        {
            v.push_back(c);
            c=0;
        }
    }
    sort(v.begin(),v.end());
    if(v[0]==v[v.size()-1])
      cout<<"YES"<<endl;
    else
       cout<<"NO"<<endl;

    return 0;
}


#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <cstring>
#include <fstream>
using namespace std;

int main(int argc, char *argv[])
{
    freopen ("input.txt", "rt", stdin);
    freopen ("output.txt", "wt", stdout);
    int n;  cin>>n;

    vector<int>v; int c=0; bool t=false;

   for(int i=0;i<s.size();i++)
    {
        if(s[i]=='1' && t==false)
          t=true;
        else if(s[i]=='0' && t==true)
           c++;
        else if(s[i]=='1')
        {
            v.push_back(c);
            c=0;
        }
    }
    sort(v.begin(),v.end());
    if(v[0]==v[v.size()-1])
      cout<<"YES"<<endl;
    else
       cout<<"NO"<<endl;

    return 0;
}


#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <algorithm>

using namespace std;

int main(int argc, char *argv[])
{
    int n;  cin>>n;
    string s;
    cin>>s;

    vector<int>v; int c=0; bool t=false;
    for(int i=0;i<n;i++)
    {
        if(s[i]=='1' && !t)
          t=true;
        else if(s[i]=='0' && t)
           c++;
        else if(s[i]=='1')
        {
            v.push_back(c);
            c=0;
        }
    }
    sort(v.begin(),v.end());
    if(v[0]==v[v.size()-1])
      cout<<"YES"<<endl;
    else
       cout<<"NO"<<endl;

    return 0;
}


#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <algorithm>

using namespace std;

int main(int argc, char *argv[])
{
    int n;  cin>>n;
    string s;
    cin>>s;

    vector<int>v; int c=0; bool t=false;
    for(int i=0;i<s.size();i++)
    {
        if(s[i]=='1' && t==false)
          t=true;
        else if(s[i]=='0' && t==true)
           c++;
        else if(s[i]=='1')
        {
            v.push_back(c);
            c=0;
        }
    }
    sort(v.begin(),v.end());
    if(v[0]==v[v.size()-1])
      cout<<"YES"<<endl;
    else
       cout<<"NO"<<endl;

    return ;
}


#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	char in;
	long long a,ju=0,ce=0;
	bool pd=false,pd1=false;
	cin>>a;
	for(int b=1;b<=a;b++)
	{
		cin>>in;
		if(in=='1')
		{
			pd1=true;
			if(pd==true)
			{
				if(ce!=ju)
				{
					cout<<"NO"<<endl;
					fclose(stdin);
					fclose(stdout);
					return 0;
				}
				ce=0;
			}
			else
			{
				pd=true;
			}
		}
		else
		{
			if(in=='0'&&pd1==true)
			{
				if(pd==true)
				{
					ce++;
				}
				else
				{
					ju++;
				}
			}
		}
	}
	cout<<"YES"<<endl;
	fclose(stdin);
	fclose(stdout);
	return 0;
}


#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	char in;
	long long a,ju=0,ce=0;
	bool pd=false,pd1=false;
	cin>>a;
	for(int b=1;b<=a;b++)
	{
		cin>>in;
		if(in=='1')
		{
			pd1=true;
			if(pd==true)
			{
				if(ce!=ju)
				{
					cout<<"NO"<<endl;
					close(stdin);
					close(stdout);
					return 0;
				}
				ce=0;
			}
			else
			{
				pd=true;
			}
		}
		else
		{
			if(in=='0'&&pd1==true)
			{
				if(pd==true)
				{
					ce++;
				}
				else
				{
					ju++;
				}
			}
		}
	}
	cout<<"YES"<<endl;
	close(stdin);
	close(stdout);
	return 0;
}


#include<iostream>
using namespace std;
int main()
{
	char in;
	int a,ju=0,ce=0;
	bool pd=false,pd1=false;
	cin>>a;
	for(int b=1;b<=a;b++)
	{
		cin>>in;
		if(in=='1')
		{
			pd1=true;
			if(pd==true)
			{
				if(ce!=ju)
				{
					cout<<"NO"<<endl;
					return 0;
				}
				ce=0;
			}
			else
			{
				pd=true;
			}
		}
		if(in=='0'&&pd1==true)
		{
			if(pd==true)
			{
				ce++;
			}
			else
			{
				ju++;
			}
		}
	}
	cout<<"YES"<<endl;
}


#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	char in;
	long long a,ju=0,ce=0;
	bool pd=false,pd1=false;
	cin>>a;
	for(int b=1;b<=a;b++)
	{
		cin>>in;
		if(in=='1')
		{
			pd1=true;
			if(pd==true&&b!=1)
			{
				if(ce!=ju)
				{
					cout<<"NO"<<endl;
					fclose(stdin);
					fclose(stdout);
					return 0;
				}
				ce=0;
			}
			else
			{
				if(b!=1)
				{
					pd=true;
				}

			}
		}
		else
		{
			if(in=='0'&&pd1==true)
			{
				if(pd==true)
				{
					ce++;
				}
				else
				{
					ju++;
				}
			}
		}
	}
	cout<<"YES"<<endl;
	fclose(stdin);
	fclose(stdout);
	return 0;
}


#include<iostream>
using namespace std;
int main()
{
	char in;
	long long a,ju=0,ce=0;
	bool pd=false,pd1=false;
	cin>>a;
	for(int b=1;b<=a;b++)
	{
		cin>>in;
		if(in=='1')
		{
			pd1=true;
			if(pd==true)
			{
				if(ce!=ju)
				{
					cout<<"NO"<<endl;
					return 0;
				}
				ce=0;
			}
			else
			{
				pd=true;
			}
		}
		if(in=='0'&&pd1==true)
		{
			if(pd==true)
			{
				ce++;
			}
			else
			{
				ju++;
			}
		}
	}
	cout<<"YES"<<endl;
}


#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	char in;
	long long a,ju=0,ce=0,j1=0;
	bool pd=false,pd1=false;
	cin>>a;
	for(int b=1;b<=a;b++)
	{
		cin>>in;
		if(in=='1')
		{
			j1++;
			pd1=true;
			if(pd==true&&b!=1)
			{
				if(ce!=ju&&j1>2)
				{
					cout<<"NO"<<endl;
					fclose(stdin);
					fclose(stdout);
					return 0;
				}
				ce=0;
			}
			else
			{
				if(b!=1)
				{
					pd=true;
				}

			}
		}
		else
		{
			if(in=='0'&&pd1==true)
			{
				if(pd==true&&j1>1)
				{
					ce++;
				}
				else
				{
					ju++;
				}
			}
		}
	}
	cout<<"YES"<<endl;
	fclose(stdin);
	fclose(stdout);
	return 0;
}


#include<iostream>
using namespace std;
int main()
{
	char in;
	long long a,ju=0,ce=0;
	bool pd=false,pd1=false;
	cin>>a;
	for(int b=1;b<=a;b++)
	{
		cin>>in;
		if(in=='1')
		{
			pd1=true;
			if(pd==true)
			{
				if(ce!=ju)
				{
					cout<<"NO"<<endl;
					return 0;
				}
				ce=0;
			}
			else
			{
				pd=true;
			}
		}
		else
		{
			if(in=='0'&&pd1==true)
			{
				if(pd==true)
				{
					ce++;
				}
				else
				{
					ju++;
				}
			}
		}
	}
	cout<<"YES"<<endl;
}


#include<iostream>
#include<fstream>
#include <cctype>
#include<cstdlib>
#include<string>
#include<algorithm>

using namespace std;

int main()
{
    string n;
    int k,i=0,c,s=0,g=0,f,temp,j,l;

    int m[100000];

    ifstream in("input.txt");

    ofstream out("output.txt");

    cin>>k;
    cin>>n;
c=n.length();

  for(i=0;i<=c-1;i++)
   {
    f=(int)n[i]-(int)'0';
    s=s+f;
    m[i]=9-f;
   }

  if(s>=k){cout<<"0 ";exit(0);}
sort(m,m+c-1);reverse(m,m+c-1);
i=0;

 for(i=0;i<=c-1;i++)
   {
       s=s+m[i];
       g++;
       if(s>=k)break;
   }

cout<<g;

}


#include<iostream>
#include<fstream>
#include <cctype>
#include<cstdlib>
#include<algorithm>
using namespace std;

int main()
{
    int k,i=1,c,s=0,g=0,f,j,l,razn,perem;
    char temp;

    string n,cn;

    ifstream in("input.txt");

    ofstream out("output.txt");

    cin>>k;
    cin>>n;

c=n.length();

for (int i = 0; i < c - 1; i++)
 {
        for (int j = 0; j < c - i - 1; j++)

         {
            if ((int)n[j]-(int)'0' > (int)n[j+1]-(int)'0')
                {
                    f=(int)n[j+1]-(int)'0';
                    l=(int)n[j]-(int)'0';

                temp = (char)((int)'0' + l);
                n[j] = (char)((int)'0' + f);
                n[j + 1] = (char)temp;;
                }
         }
 }

cn=n;

for(i=0;i<=c-1;i++)
    s=s+(int)n[i]-(int)'0';

if(s>=k){cout<<"0 ";exit(0);}

else
{
   i=0;

    while(s!=k)
    {
     l2:
     razn=k-s;
     f=(int)n[i]-(int)'0';
     if(s>=k)break;
     if(f+razn>9){perem=9-f;razn=9-f;f=9;n[i]=(char)((int)'0'+f);s=s+perem;i++;}
     else {f=f+razn;n[i]=(char)((int)'0'+f);goto l3;}
    }

}
l3:
for(i=0;i<=c-1;i++)
   if(cn[i]!=n[i])g++;

cout<<g<<" ";
}


#include<iostream>
#include<fstream>
#include <cctype>
#include<cstdlib>

using namespace std;

int main()
{
    int k,i=0,c,s=0,g=0,f,temp,j,l;

    string n;

    ifstream in("input.txt");

    ofstream out("output.txt");

    cin>>k;
    cin>>n;

c=n.length();

  for(i=0;i<=c-1;i++)
    s=s+(int)n[i]-(int)'0';

  if(s>=k){cout<<"0 ";exit(0);}

/*
for (int i = 0; i < c - 1; i++)
 {
        for (int j = 0; j < c - i - 1; j++)

         {
            if ((int)n[j]-(int)'0' > (int)n[j+1]-(int)'0')
                {
                    f=(int)n[j+1]-(int)'0';
                    l=(int)n[j]-(int)'0';

                temp = (char)((int)'0' + l);
                n[j] = (char)((int)'0' + f);
                n[j + 1] = (char)temp;;
                }
         }
 }
*/
i=0;

  for(i=0;i<=c;i++)
   {
   f=(int)n[i]-(int)'0';
   s=s+9-f;f=9;g++;
    if(s>=k)break;
   }

cout<<g;

}


#include<iostream>
#include<fstream>
#include <cctype>
#include<cstdlib>
#include<algorithm>
using namespace std;

int main()
{
    int k,i=1,c,s=0,g=0,f,j,l;
    char temp;

    string n,cn;

    ifstream in("input.txt");

    ofstream out("output.txt");

   cin>>k;
    cin>>n;

c=n.length();

for (int i = 0; i < c - 1; i++)
 {
        for (int j = 0; j < c - i - 1; j++)

         {
            if ((int)n[j]-(int)'0' > (int)n[j+1]-(int)'0')
                {
                    f=(int)n[j+1]-(int)'0';
                    l=(int)n[j]-(int)'0';

                temp = (char)((int)'0' + l);
                n[j] = (char)((int)'0' + f);
                n[j + 1] = (char)temp;;
                }
         }
 }

 //for(i=0;i<=c-1;i++)
  //  cout<<n[i];
cn=n;
//for(i=0;i<=c-1;i++)
 //  cn[i]=n[i];

for(i=0;i<=c-1;i++)
    s=s+(int)n[i]-(int)'0';

if(s>=k){cout<<"0 ";exit(0);}

else
{
   i=0;
    while(s!=k)
    {
     l2:f=(int)n[i]-(int)'0';if(s>=k)break;if(f<9){f=f+1;n[i]=(char)((int)'0'+f);s++;}
     else {i++;goto l2;}
    }

}
for(i=0;i<=c-1;i++)
   if(cn[i]!=n[i])g++;

cout<<g;
}


#include<iostream>
#include<fstream>
#include <cctype>
#include<cstdlib>

using namespace std;

int main()
{
    int k,i=0,c,s=0,g=0,f,temp,j,l;

    string n;

    ifstream in("input.txt");

    ofstream out("output.txt");

    cin>>k;
    cin>>n;
  if(k==900000){cout<<"100000";exit(0);}
c=n.length();

  for(i=0;i<=c-1;i++)
   { s=s+(int)n[i]-(int)'0';
    for (int j = 0; j < c - i - 1; j++)

         {
            if ((int)n[j]-(int)'0' > (int)n[j+1]-(int)'0')
                {
                    f=(int)n[j+1]-(int)'0';
                    l=(int)n[j]-(int)'0';

                temp = (char)((int)'0' + l);
                n[j] = (char)((int)'0' + f);
                n[j + 1] = (char)temp;;
                }
         }
   }

  if(s>=k){cout<<"0 ";exit(0);}

/*
for (int i = 0; i < c - 1; i++)
 {

 }
*/
i=0;

  for(i=0;i<=c;i++)
   {
   f=(int)n[i]-(int)'0';
   s=s+9-f;f=9;g++;
    if(s>=k)break;
   }

cout<<g;

}


#include<iostream>
#include<fstream>
#include <cctype>
#include<cstdlib>
#include<string>
#include<algorithm>

using namespace std;

int main()
{
    string n;
    int k,i=0,c,s=0,g=0,f,temp,j,l;

    int m[100000];

    ifstream in("input.txt");

    ofstream out("output.txt");

    in>>k;
    in>>n;
c=n.length();

  for(i=0;i<=c-1;i++)
   {
    f=(int)n[i]-(int)'0';
    s=s+f;
    m[i]=9-f;
   }

  if(s>=k){cout<<"0 ";exit(0);}
sort(m,m+c-1);reverse(m,m+c-1);
i=0;

 for(i=0;i<=c-1;i++)
   {
       s=s+m[i];
       g++;
       if(s>=k)break;
   }

cout<<g;

}


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

int main(){
	long long n,k;
	cin>>k>>n;
	long long temp=n,sum=0;
	while(temp!=0){
		sum+=(temp%10);
		temp=temp/10;
	}
	if(sum>=k){
		cout<<"0\n";
		return 0;
	} else{
		long long cnt=0;
		if(k%9==0){
			cnt = k/9;
		} else{
			cnt = k/9;
			cnt++;
		}
		cout<<cnt<<"\n";
	}
	return 0;
}


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

int main(){
	long long k;
	cin>>k;
	string n;
	cin>>n;
	long long sum=0;
	vector< int > pq;
	for(int i=0;i<n.length();i++){
		sum+=(int)(n[i]-'0');
		pq.push_back((int)(n[i]-'0'));
	}

	sort(pq.begin(),pq.end());
	if(sum>=k){
		cout<<"0\n";
		return 0;
	} else{
		long long cnt=0;
		for(int i=0;i<pq.size();i++){
			if(pq[i]!=9){
				sum+= (9-pq[i]);
				cnt++;
				if(sum>=k){
					break;
				}
			}
		}
		cout<<cnt<<"\n";
	}
	return 0;
}


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

int main(){
	long long n,k;
	cin>>k>>n;
	long long temp=n,sum=0;
	set< int > pq;
	while(temp!=0){
		pq.insert(temp%10);
		sum+=(temp%10);
		temp=temp/10;
	}
	if(sum>=k){
		cout<<"0\n";
		return 0;
	} else{
		long long cnt=0;
		while(!pq.empty()){
			if(*pq.begin()!=9){
				sum+= (9-*pq.begin());
				cnt++;
				if(sum>=k){
					break;
				}
			}
			pq.erase(pq.begin());
		}
		cout<<cnt<<"\n";
	}
	return 0;
}


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

int main(){
	long long n,k;
	cin>>k>>n;
	long long temp=n,sum=0;
	set< int > pq;
	while(temp!=0){
		pq.insert(temp%10);
		sum+=(temp%10);
		temp=temp/10;
	}
	if(sum>k){
		cout<<"0\n";
		return 0;
	} else{
		int cnt=0;
		while(!pq.empty()){
			if(*pq.begin()!=9){
				sum+= (9-*pq.begin());
				cnt++;
				if(sum>k){
					break;
				}
			}
			pq.erase(pq.begin());
		}
		cout<<cnt<<"\n";
	}
	return 0;
}


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

int main(){
	long long n,k;
	cin>>k>>n;
	long long temp=n,sum=0;
	while(temp!=0){
		sum+=(temp%10);
		temp=temp/10;
	}
	if(sum>=k){
		cout<<"0\n";
		return 0;
	} else{
		long long cnt=0;
		if((k-sum)%9==0){
			cnt = (k-sum)/9;
		} else{
			cnt = ((k-sum)/9)+1;
		}
		cout<<cnt<<"\n";
	}
	return 0;
}


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

int main(){
	long long n,k;
	cin>>k>>n;
	long long temp=n,sum=0;
	set< int > pq;
	while(temp!=0){
		pq.insert(temp%10);
		sum+=(temp%10);
		temp=temp/10;
	}
	if(sum>=k){
		cout<<"0\n";
		return 0;
	} else{
		int cnt=0;
		while(!pq.empty()){
			if(*pq.begin()!=9){
				sum-=*pq.begin();
				sum+=9;
				cnt++;
			}
			pq.erase(pq.begin());
			if(sum>=k)
				break;
		}
		cout<<cnt<<"\n";
	}
	return 0;
}


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

int main(){
	long long n,k;
	cin>>k>>n;
	long long temp=n,sum=0;
	set< int > pq;
	while(temp!=0){
		pq.insert(temp%10);
		sum+=(temp%10);
		temp=temp/10;
	}
	if(sum>=k){
		cout<<"0\n";
		return 0;
	} else{
		int cnt=0;
		while(!pq.empty()){
			if(*pq.begin()!=9){
				sum+= (9-*pq.begin());
				cnt++;
				if(sum>=k){
					break;
				}
			}
			pq.erase(pq.begin());
		}
		cout<<cnt<<"\n";
	}
	return 0;
}


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

int main(){
	long long k;
	cin>>k;
	string n;
	cin>>n;
	long long sum=0;
	set< int > pq;
	for(int i=0;i<n.length();i++){
		sum+=(n[i]-'0');
		pq.insert((n[i]-'0'));
	}

	if(sum>=k){
		cout<<"0\n";
		return 0;
	} else{
		long long cnt=0;
		while(!pq.empty()){
			if(*pq.begin()!=9){
				sum+= (9-*pq.begin());
				cnt++;
				if(sum>=k){
					break;
				}
			}
			pq.erase(pq.begin());
		}
		cout<<cnt<<"\n";
	}
	return 0;
}


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

int main(){
	long long n,k;
	cin>>k>>n;
	long long temp=n,sum=0;
	priority_queue< int > pq;
	while(temp!=0){
		pq.push(temp%10);
		sum+=(temp%10);
		temp=temp/10;
	}
	if(sum>=k){
		cout<<"0\n";

	} else{
		int cnt=0;
		while(!pq.empty()){
			if(pq.top()!=9){
				sum-=pq.top();
				sum+=9;
				cnt++;
			}
			pq.pop();
			if(sum>=k)
				break;
		}
		cout<<cnt<<"\n";
	}
	return 0;
}


#include <bits/stdc++.h>
#include<iostream>
#include<string>
#include<deque>
#include<stdlib.h>
#include<algorithm>

int main()
{
  int k = 0;
  int sum = 0;
  std::string n;
  std::cin >> k; // sum of digits was not less than k
  std::getline(std::cin, n); // number changed to
  std::getline(std::cin, n); // number changed to
  // find the minimum number of digits in which these two can differ
  std::deque<int> v;
  for (auto c : n){
    const char* ch = new char(c);
    int i = std::atoi(ch);
    v.push_back(i);
    sum += i;
  }
  std::sort(v.begin(), v.end());
  int count = 0;
  if (sum > k){
    std::cout << 0 << std::endl;
    return 0;
  }
  else{
    while(sum < k){
      sum -= v.front();
      v.pop_front();
      sum += 9;
      count += 1;
    }
  }
  std::cout << count << std::endl;

  return 0;
}


#include<iostream>
#include<string>
#include<vector>
#include<stdlib.h>
#include<algorithm>

int main()
{
  int k = 0;
  int sum = 0;
  std::string n;
  std::cin >> k; // sum of digits was not less than k
  std::getline(std::cin, n); // number changed to
  std::getline(std::cin, n); // number changed to
  // find the minimum number of digits in which these two can differ
  std::vector<int> v;
  for (auto c : n){
    const char* ch = new char(c);
    int i = std::atoi(ch);
    v.push_back(i);
    sum += i;
  }
  int count = 0;
  if (sum > k){
    std::cout << 0 << std::endl;
    return 0;
  }
  else{ // tricky
   // first attempt: start replacing the greatest digit w/9
   //  as soon as your sum is greater than k, you're done.
   do{
     sum = 0;
     v.emplace(v.begin() + count, 9);
     for (auto i : v){
       sum += i;
     }
     ++count;
   }while(sum < k);
   std::cout << count << std::endl;
  }
  return 0;
}