#include using namespace std; double dp1[200200],dp2[200200],dp3[200200],dp4[200200]; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int N; string S; cin >> N >> S; dp1[N-1] = 0; dp2[N-1] = 0; dp3[N-1] = 0; dp4[N-1] = 0; for(int i = N-2; i >= 0; i--) { if(S[i] == '#') continue; double rep = 1.0/3,cnt = 1.0/3,suc = 0; for(int j = 1; j <= 2; j++) { if(i+j < N && S[i+j] == '.') { rep += 1.0/3*dp3[i+j]; cnt += 1.0/3*dp4[i+j]; suc += (1.0/3)*(1.0-dp3[i+j]); } else { rep += 1.0/3; cnt += 1.0/3; } } dp1[i] = (1.0/3)/rep*(1.0/suc-1); for(int j = 1; j <= 2; j++) { if(i+j < N && S[i+j] == '.') { dp1[i] += (1.0/3*dp3[i+j])/rep*(dp4[i+j]+1)*(1.0/suc-1); dp1[i] += ((1.0/3)*(1.0-dp3[i+j]))/suc*(dp2[i+j]+1); } else { dp1[i] += (1.0/3)/rep*(1.0/suc-1); } } suc = 1.0; for(int j = 1; j <= 2; j++) { if(i+j < N && S[i+j] == '.') { suc += 1.0-dp3[i+j]; } } dp2[i] = 1.0/suc*(dp1[i]+1); for(int j = 1; j <= 2; j++) { if(i+j < N && S[i+j] == '.') { dp2[i] += (1.0-dp3[i+j])/suc*(dp2[i+j]+1); dp3[i] += 1.0/3*dp3[i+j]; } else { dp3[i] += 1.0/3; } } suc = 0; for(int j = 1; j <= 2; j++) { if(i+j < N && S[i+j] == '.') { suc += 1.0/3*dp3[i+j]; } else { suc += 1.0/3; } } for(int j = 1; j <= 2; j++) { if(i+j < N && S[i+j] == '.') { dp4[i] += (1.0/3*dp3[i+j])/suc*(dp4[i+j]+1); } else { dp4[i] += (1.0/3)/suc; } } } cout << fixed << setprecision(18) << endl; cout << dp1[0] << "\n"; }