public class BearCries {
public int count
(String message
) { int n = message.length();
final int mod = 1000 * 1000 * 1000 + 7;
long[][] dp = new long[n][n];
long[][] old = new long[n][n];
dp[0][0] = 1L;
for(int i = 0; i < n; ++i) {
for(int single = 0; single < n; ++single)
for(int ready = 0; ready < n; ++ready) {
old[single][ready] = dp[single][ready] % mod;
dp[single][ready] = 0L;
}
for(int single = 0; single < n; ++single)
for(int ready = 0; ready < n; ++ready) {
long x = old[single][ready];
if(message.charAt(i) == ';') {
if(single+1 < n)
dp[single+1][ready] += x;
if(ready > 0)
dp[single][ready-1] += ready * x;
}
else {
dp[single][ready] += ready * x;
if(single > 0 && ready+1 < n)
dp[single-1][ready+1] += single * x;
}
}
}
return (int) (dp[0][0] % mod);
}
}