#python -m pdb a.py R=range I=input J=lambda:list(map(int,I().split())) N=sum(J())+1 S=I() A=[0]+J() s=[0] p=[0]*N l=1 for c in S: if c<')':p[l]=s[-1];s+=[l];l+=1 else:s.pop() import heapq as h s=[0]*N q=[] P=list(R(N)) H=[0]*N def r(i): m=P[i] while i!=m:P[i]=i=P[m];m=P[i] return i w=[1]*N def f(w,a):return w/a if a else 9**6 for i in R(1,N):s[i]=f(1,A[i]);h.heappush(q,[s[i],i]) a=0 while q: t,v=h.heappop(q);v=r(v) if t!=s[v]:continue s[v]=0;u=r(p[v]);a+=w[u]*A[v];p[v]=p[u] if H[u]