#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define all(a)  (a).begin(),(a).end()
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define pb push_back
 
 
const double INF = (1E20);
#define EPS (1e-10)
class P{
public:
    double x,y;
     
    P(double _x=0,double _y=0):x(_x),y(_y){};
    P operator - (const P &p ) const { return P(x-p.x,y-p.y);}
};
 
struct S{P p1,p2;};
 
 
typedef vector<P> Polygon;
typedef P Vector;
 
double abs(P p)                 {return sqrt(p.x*p.x + p.y*p.y);}
double dot(Vector a, Vector b)  {return a.x*b.x+a.y*b.y;}
 
     
double cross(Vector a,Vector b){return a.x*b.y-a.y*b.x;}
 
bool cmp_x(const P& p,const P& q){
    if(p.x!=q.x)return p.x<q.x;
    return p.y<q.y;
}
 
vector<P> convex_hull(vector<P> ps){
    int n = ps.size();
    sort(all(ps),cmp_x);
    int k=0;
    vector<P> qs(n*2);
    rep(i,n){
        while(k>1 && cross((qs[k-1]-qs[k-2]),(ps[i]-qs[k-1]))<=0)k--;
         
        qs[k++] = ps[i];
    }
    for(int i=n-2,t=k;i>=0;i--){
        while(k>t && cross((qs[k-1]-qs[k-2]),(ps[i]-qs[k-1]))<=0 )k--;
        qs[k++]=ps[i];
    }
    qs.resize(k-1);
    return qs;
}
 
 
int px[1000005];
int py[1000005];
 
double getLR(S edge,vector<P> &tpol){
    double l=INF,r=-INF;
     
    rep(i,tpol.size()){
        P cur = tpol[i];
        Vector a,b;
        a = edge.p2 - edge.p1;
        b = cur - edge.p1;
        double tt = dot(a,b);
        tt /= abs(a);
       // cout<< tt <<endl;
        l=min(l,tt);
        r=max(r,tt);
    }
  //  cout<<endl;
    return r-l;
}
 
double getU(S edge,vector<P> &tpol){
    double res=-INF;
     
    rep(i,tpol.size()){
        P cur = tpol[i];
        Vector a,b;
        a = edge.p2 - edge.p1;
        b = cur - edge.p1;
        double tt = cross(a,b);
        tt /= abs(a);
         
        res=max(res, abs(tt ));
    }
    return res;
}
 
int main(){
    int n;
    cin>>n;
     
     
    vector<P> points;
    px[0]=py[0]=0;
     
    for(int i=1;i<n;i++){
        int id,dir;
        cin>>id>>dir;
        if(dir==0){
            px[i]=px[id]-1;
            py[i]=py[id];
        }else if(dir==1){
            px[i]=px[id];
            py[i]=py[id]-1;
        }else if(dir==2){
            px[i]=px[id]+1;
            py[i]=py[id];
        }else if(dir==3){
            px[i]=px[id];
            py[i]=py[id]+1;
        }
    }
    set< pair<int,int> > st;
    for(int i=0;i<n;i++){
        for(int dy=0;dy<2;dy++)
            for(int dx=0;dx<2;dx++)
                st.insert( make_pair( px[i]+dx ,py[i]+dy) );
         
    }
     
    for( pair<int,int> sp : st ){
         
        //cout<< sp.first << ' ' <<sp.second <<endl;
         
        points.emplace_back( sp.first , sp.second );
    }
     
    vector<P> tpol = convex_hull(points);
     
    double ans=INF;
     
    rep(i,tpol.size()){
        S edge = S{tpol[i],tpol[(i+1)%tpol.size()]};
         
        double width = getLR(edge,tpol);
        double height = getU(edge,tpol);
         
//        cout<<edge.p1.x<<" "<<edge.p1.y<<" "<<edge.p2.x<<" "<<edge.p2.y<<endl;
//        cout<<width<<" "<<height<<endl;
         
        ans=min(ans, width * height );
    }
    printf("%.10f\n",ans);
     
}

Measured memory_bytes: 25604