fq.cpp
#include <algorithm>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#define DEBUG(x) cout << ">>> " << #x << " : " << x << endl;
#define REP(i,a) for (int i = 0; i < (a); ++i)
#define FOR(i,a,b) for (int i = (a); i <= (b); ++i)
#define FORD(i,a,b) for (int i = (a); i >= (b); --i)
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
const int INF = 1<<29;
typedef long long ll;
///////////////////////////////////////////////////////////////////////////
const int MAX = 1024, MOD = 1000000;
char in[MAX];
int N;
int dp[MAX][MAX];
int go(int n, int s)
{
int & res = dp[n][s];
if (res != -1) return res;
res = 0;
if (n == N)
{
return res = s==0;
}
if (in[n] == '.')
{
if (s < N/2)
{
res += go(n+1, s+1);
}
if (s > 0)
{
res += go(n+1, s-1);
}
}
else if (in[n] == '(')
{
if (s < N/2)
{
res += go(n+1, s+1);
}
}
else
{
if (s > 0)
{
res += go(n+1, s-1);
}
}
res %= MOD;
return res;
}
int main()
{
while (gets(in))
{
N = strlen(in);
REP(i, N+1) REP(j, N+1) dp[i][j] = -1;
printf("%d\n", go(0, 0));
}
return 0;
}