Problem:
Score : 2718 points

Problem Statement

There is a very long bench.
The bench is divided into M sections, where M is a very large integer.

Initially, the bench is vacant.
Then, M people come to the bench one by one, and perform the following action:

We call a section comfortable if the section is currently unoccupied and is not adjacent to any occupied sections.
If there is no comfortable section, the person leaves the bench.
Otherwise, the person chooses one of comfortable sections uniformly at random, and sits there.
(The choices are independent from each other).

After all M people perform actions, Snuke chooses an interval of N consecutive sections uniformly at random (from M-N+1 possible intervals), and takes a photo.
His photo can be described by a string of length N consisting of X and -: the i-th character of the string is X if the i-th section from the left in the interval is occupied, and - otherwise.
Note that the photo is directed.
For example, -X--X and X--X- are different photos.

What is the probability that the photo matches a given string s?
This probability depends on M.
You need to compute the limit of this probability when M goes infinity.

Here, we can prove that the limit can be uniquely written in the following format using three rational numbers p, q, r and e = 2.718 \ldots (the base of natural logarithm):

p + \frac{q}{e} + \frac{r}{e^2}

Your task is to compute these three rational numbers, and print them modulo 10^9 + 7, as described in Notes section.

Notes

When you print a rational number, first write it as a fraction \frac{y}{x}, where x, y are integers and x is not divisible by 10^9 + 7
(under the constraints of the problem, such representation is always possible).
Then, you need to print the only integer z between 0 and 10^9 + 6, inclusive, that satisfies xz \equiv y \pmod{10^9 + 7}.

Constraints

1 \leq N \leq 1000

|s| = N

s consists of X and -.

Input

Input is given from Standard Input in the following format:

N
s

Output

Print three rational numbers p, q, r, separated by spaces.

Sample Input 1

1
X

Sample Output 1

500000004 0 500000003

The probability that a randomly chosen section is occupied converge to \frac{1}{2} - \frac{1}{2e^2}.

Sample Input 2

3
---

Sample Output 2

0 0 0

After the actions, no three consecutive unoccupied sections can be left.

Sample Input 3

5
X--X-

Sample Output 3

0 0 1

The limit is \frac{1}{e^2}.

Sample Input 4

5
X-X-X

Sample Output 4

500000004 0 833333337

The limit is \frac{1}{2} - \frac{13}{6e^2}.

Sample Input 5

20
-X--X--X-X--X--X-X-X

Sample Output 5

0 0 183703705

The limit is \frac{7}{675e^2}.

Sample Input 6

100
X-X-X-X-X-X-X-X-X-X--X-X-X-X-X-X-X-X-X-X-X-X-X-X-X--X--X-X-X-X--X--X-X-X--X-X-X--X-X--X--X-X--X-X-X-

Sample Output 6

0 0 435664291

Solution in C++14 (GCC 5.4.1) (judge verdict: Wrong Answer)

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
#define pb push_back
#define fr(i,n) for(int i=0;i<n;i++)
#define Fr(i,n) for(int i=0;i++<n;)
#define ifr(i,n) for(int i=n-1;i>=0;i--)
#define iFr(i,n) for(int i=n;i>0;i--)

const ll MOD=1e9+7;

ll ad(ll x,ll y=0){
  return (x+y)%MOD;
}

ll mlt(ll x,ll y=1){
  return (x*y)%MOD;
}

ll pwr(ll x,ll y){
  ll pw[32]={},w=1;
  pw[0]=x;
  fr(i,31) pw[i+1]=mlt(pw[i],pw[i]);
  fr(i,32){
    w=mlt(w,1+(y%2)*(pw[i]-1));
    y/=2;
  }
  return w;
}

ll inv(ll x){
  return pwr(x,MOD-2);
}

ll fc[1010]={1};
ll fct(ll x){
  if(fc[x]==0) fc[x]=mlt(x,fct(x-1));
  return fc[x];
}

ll ifc[1010]={1};
ll ifct(ll x){
  if(ifc[x]==0) ifc[x]=inv(fct(x));
  return ifc[x];
}

ll Bn[1010]={0};
ll bn(ll x){
  if(x>0&&Bn[x]==0) Bn[x]=ad(1,mlt(x,bn(x-1)));
  return Bn[x];
}

int main(){
  ll n,num=1,dp[1010][2][1010]={},dpc[1010]={},kari;
  bool f[1010];
  string s;
  cin>>n>>s;
  int q=0,r=n;
  n=-1;
  if(s[q]=='-') q++;
  if(s[q]=='-'){q++;n++;num++;}
  if(s[q]=='-'){cout<<"0 0 0"<<endl;return 0;}
  for(int i=q;i<r;i++){
    if(s[i]=='X'){
      if(num==0){cout<<"0 0 0"<<endl;return 0;}
      if(n>=0) f[n]=num-1;
      n++;num=0;
    }
    else{
      if(num>1){cout<<"0 0 0"<<endl;return 0;}
      num++;
    }
  }
  if(num==2) f[n++]=1;
  dpc[0]=1;
  fr(i,n){
    if(f[i]){
      fr(j,2){
        fr(k,2*n+2){
          kari=inv(k*k+3*k+2);
          dp[i+1][j][0]=ad(dp[i+1][j][0],mlt(dp[i][j][k],kari));
          dp[i+1][j][1]=ad(dp[i+1][j][1],mlt(dp[i][j][k],MOD-kari));
        }
      }
      dp[i+1][1][0]=ad(dp[i+1][1][0],dpc[i]);
      dp[i+1][1][1]=ad(dp[i+1][1][1],MOD-dpc[i]);
    }
    else{
      fr(j,2){
        fr(k,2*n+2){
          kari=inv(k+1);
          dp[i+1][j][0]=ad(dp[i+1][j][0],mlt(dp[i][j][k],kari));
          dp[i+1][j][1]=ad(dp[i+1][j][1],mlt(dp[i][j][k],MOD-kari));
          dp[i+1][j][k+2]=ad(dp[i+1][j][k+2],mlt(dp[i][j][k],inv(k*k+3*k+2)));
        }
      }
      dp[i+1][1][1]=ad(dp[i+1][1][1],dpc[i]);
      dp[i+1][1][0]=ad(dp[i+1][1][0],MOD-dpc[i]);
      dpc[i+1]=ad(dpc[i+1],dpc[i]);
    }
  }
  ll ans[3]={};
  fr(j,2){
    fr(k,2*n+2){
      ans[j]=ad(ans[j],mlt(dp[n][j][k],fct(k)));
      ans[j+1]=ad(ans[j+1],mlt(dp[n][j][k],MOD-ad(fct(k),bn(k))));
    }
  }
  kari=(MOD+1)/2;
  ans[0]=ad(ans[0],mlt(dpc[n],kari));
  ans[2]=ad(ans[2],mlt(dpc[n],MOD-kari));
  cout<<ans[0]<<" "<<ans[1]<<" "<<ans[2]<<endl;
}