n,*c=`dd`.split.map &:to_i b=c.pop n i=0.0 p c.permutation.count{|a|i+=1;s=0;a.zip(b){|x,y|s+=x<=>y};s>0}/i