#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mkp make_pair
#define vi vector<int>
#define pii pair<int,int>
#define FI(n) FastIO::read(n)
#define FO(n) FastIO::write(n)
#define ull unsigned long long
#define mst(a,b) memset(a,b,sizeof(a))
#define foR(i,k,j) for(int i=(k);i>=(j);i--)
#define For(i,k,j) for(int i=(k);i<=(j);i++)
#define Foe(i,u) for(int i=lst[u],v=e[i].v;i;i=e[i].nxt,v=e[i].v)
#define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define Fin(s) freopen(s,"r",stdin)
#define Fout(s) freopen(s,"w",stdout)
#define file(s) Fin(s".in"),Fout(s".out")
#define INF ((1<<30)-1)
//#define int long long
const int P=3; //
using namespace std;
template<typename T>inline void ckmax(T &a,T b) {(a<b)&&(a=b);}
template<typename T>inline void ckmin(T &a,T b) {(a>b)&&(a=b);}
inline int mul(int a,int b) {return 1ull*a*b%P;}
inline int add(int a,int b) {return a+b>=P?a+b-P:a+b;}
inline int sub(int a,int b) {return a-b>=0?a-b:a-b+P;}
inline void mulmod(int &a,int b) {a=mul(a, b);}
inline void addmod(int &a,int b) {((a+=b)>=P)&&(a-=P);}
inline void submod(int &a,int b) {((a-=b)<0)&&(a+=P);}
inline int ksm(int a,int b) {int ans=1; for(;b;b>>=1) {if(b&1) ans=1ll*ans*a%P;a=1ll*a*a%P;}return ans;}
inline void fprint(const int &x,char c=' ') {fprintf(stderr,"%d%c",x,c);}
inline void fprint(const pii &x,char c='\n') {fprintf(stderr,"%d %d%c",x.first,x.second,c);}
inline void fprint(const int *f,const int &n,char c='\n') {for(int i=1;i<=n;i++) fprint(f[i]); fprintf(stderr,"%c",c);}
inline void fprint(const vector<int> &f,char c='\n') {for(int i=0;i<(int)f.size();i++) fprint(f[i]); fprintf(stderr,"%c",c);}
inline int inv(int a) {return ksm(a,P-2);}
namespace FastIO {
  const int SIZE=1<<16; char buf[SIZE],obuf[SIZE],str[64]; int bi=SIZE,bn=SIZE,opt;
  int read(char *s) {
    while (bn) {for (;bi<bn&&buf[bi]<=' ';bi++);if (bi<bn) break; bn=fread(buf,1,SIZE,stdin),bi=0;}
    int sn=0;while (bn) {for (;bi<bn&&buf[bi]>' ';bi++) s[sn++]=buf[bi];if (bi<bn) break; bn=fread(buf,1,SIZE,stdin),bi=0;}s[sn]=0;return sn;
  }
  bool read(int& x) {if(x)x=0;int bf=0,n=read(str); if(!n) return 0; int i=0; if (str[i]=='-') bf=1,i=1; for(x=0;i<n;i++) x=x*10+str[i]-'0'; if(bf) x=-x; return 1;}
  void write(int x) {
    if(!x) obuf[opt++]='0'; else {if(x<0) obuf[opt++]='-',x=-x;int sn=0; while(x)str[sn++]=x%10+'0',x/=10;for (int i=sn-1;i>=0;i--) obuf[opt++]=str[i];}
    if (opt>=(SIZE>>1)){fwrite(obuf,1,opt,stdout); opt=0;}
  }
  void write(char x) {obuf[opt++]=x;if (opt>=(SIZE>>1)){fwrite(obuf,1,opt,stdout); opt=0;}}
	void Fflush() {if (opt) fwrite(obuf,1,opt,stdout); opt=0;}
};
inline int read() {int x; FI(x); return x;}
const int MN=2e5+5;
int a[MN],n,dep[MN],rt,vrt,f[MN],ban[MN],X,Y;
vi e[MN];
void dfs1(int u,int fa) {
	dep[u]=dep[fa]+1,f[u]=fa;
	if(dep[u]>vrt) vrt=dep[u],rt=u;
	for(auto v:e[u]) {
		if(v==fa) continue;
		dfs1(v,u);
	}
}
int now=1,ans[MN];
void dfs2(int u,int fa) {
	int bv=0; ans[u]=now;
//	cerr<<u<<endl;
	for(auto v:e[u]) {
		if(v!=fa&&ban[v]) bv=v;
		if(v==fa||ban[v]) continue;
		now++; dfs2(v,u); now++;
	}
	if(bv) now++,dfs2(bv,u),now++;
}
signed main() {
	#ifndef ONLINE_JUDGE
		freopen("pro.in","r",stdin);
		freopen("pro.out","w",stdout);
	#endif
	n=read();
	For(i,1,n-1) {
		int u=read(),v=read();
		e[u].pb(v),e[v].pb(u);
	}
	dfs1(1,0); X=rt; rt=0,vrt=0; dfs1(X,0); Y=rt;
//	cerr<<X<<' '<<Y<<endl;
	int t=Y; do {
		ban[t]=1; t=f[t];
	} while(t);
	dfs2(X,0);
	For(i,1,n) {
		printf("%d ",ans[i]);
	}
	printf("\n");
	return FastIO::Fflush(),0; 
}
/*

*/
#include <iostream>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <tuple>
using namespace std;

void yes(){ cout << "yes" << endl; }
void Yes(){ cout << "Yes" << endl; }
void YES(){ cout << "YES" << endl; }
void no(){ cout << "no" << endl; }
void No(){ cout << "No" << endl; }
void NO(){ cout << "NO" << endl; }
#define rep(i, n)for(int i=0; i<n; i++)
#define ll long long

ll inf = 1000000007;
ll INF = 1000000000000000007;


int main(){
  ll N; string S;
  cin >> N >> S;
  //

  // fofoxxfofox
  stack<char> s;
  rep(i, N){
    // xでなければスタックに突っ込む
    if(S[i] != 'x'){
      s.push(S[i]);
    }
    // xならばfoxを取り除けるかも
    else{
      if(s.empty()){
	s.push('x');
      }
      // oxを発見
      else if(s.top() == 'o'){
	s.pop();
	// foxを発見
	if(s.top() == 'f'){
	  s.pop();
	}
	// さっきpopしたoは間違いだった
	// xもpush
	else{
	  s.push('o');
	  s.push('x');
	}
      }
      // oxを含まないためxをpush
      else{
	s.push('x');
      }
    }
  }

  ll num = s.size();
  /* while(!s.empty()){
    cout << s.top();
    s.pop();
  }
  cout<<endl;*/
  
  // 解答
  cout << num << endl;
  
  return 0;
}
